starpu_lp2paje.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <assert.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <common/config.h>
  21. #define PROGNAME "starpu_lp2paje"
  22. struct task
  23. {
  24. double start;
  25. double stop;
  26. int num;
  27. int worker;
  28. };
  29. int main(int argc, char *argv[])
  30. {
  31. int nw, nt;
  32. double tmax;
  33. int i, w, ww, t, tt;
  34. int foo;
  35. double bar;
  36. if (argc != 1)
  37. {
  38. if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)
  39. {
  40. fprintf(stderr, "%s (%s) %s\n", PROGNAME, PACKAGE_NAME, PACKAGE_VERSION);
  41. exit(EXIT_SUCCESS);
  42. }
  43. fprintf(stderr, "Convert schedule optimized by lp into the Paje format\n\n");
  44. fprintf(stderr, "Usage: lp_solve file.lp | %s > paje.trace\n", PROGNAME);
  45. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  46. fprintf(stderr, "\n");
  47. exit(EXIT_SUCCESS);
  48. }
  49. assert(scanf("Suboptimal solution\n") == 0);
  50. assert(scanf("\nValue of objective function: %lf\n", &tmax) == 1);
  51. assert(scanf("Actual values of the variables:\n") == 0);
  52. assert(scanf("tmax %lf\n", &tmax) == 1);
  53. assert(scanf("nt %d\n", &nt) == 1);
  54. assert(nt >= 0);
  55. assert(scanf("nw %d\n", &nw) == 1);
  56. assert(nw >= 0);
  57. printf(
  58. "%%EventDef PajeDefineContainerType 1\n"
  59. "%% Alias string\n"
  60. "%% ContainerType string\n"
  61. "%% Name string\n"
  62. "%%EndEventDef\n"
  63. "%%EventDef PajeCreateContainer 2\n"
  64. "%% Time date\n"
  65. "%% Alias string\n"
  66. "%% Type string\n"
  67. "%% Container string\n"
  68. "%% Name string\n"
  69. "%%EndEventDef\n"
  70. "%%EventDef PajeDefineStateType 3\n"
  71. "%% Alias string\n"
  72. "%% ContainerType string\n"
  73. "%% Name string\n"
  74. "%%EndEventDef\n"
  75. "%%EventDef PajeDestroyContainer 4\n"
  76. "%% Time date\n"
  77. "%% Name string\n"
  78. "%% Type string\n"
  79. "%%EndEventDef\n"
  80. "%%EventDef PajeDefineEntityValue 5\n"
  81. "%% Alias string\n"
  82. "%% EntityType string\n"
  83. "%% Name string\n"
  84. "%% Color color\n"
  85. "%%EndEventDef\n"
  86. "%%EventDef PajeSetState 6\n"
  87. "%% Time date\n"
  88. "%% Type string\n"
  89. "%% Container string\n"
  90. "%% Value string\n"
  91. "%%EndEventDef\n"
  92. "1 W 0 Worker\n"
  93. );
  94. printf("3 S W \"Worker State\"\n");
  95. for (t = 0; t < nt; t++)
  96. printf("5 R%d S Running_%d \"0.0 1.0 0.0\"\n", t, t);
  97. printf("5 F S Idle \"1.0 0.0 0.0\"\n");
  98. for (i = 0; i < nw; i++)
  99. printf("2 0 W%d W 0 \"%d\"\n", i, i);
  100. for (w = 0; w < nw; w++)
  101. printf("4 %f W%d W\n", tmax, w);
  102. fprintf(stderr,"%d workers, %d tasks\n", nw, nt);
  103. {
  104. struct task task[nt];
  105. memset(&task, 0, sizeof(task));
  106. for (t = nt-1; t >= 0; t--)
  107. {
  108. assert(scanf("c%d %lf\n", &foo, &task[t].stop) == 2);
  109. }
  110. for (t = nt-1; t >= 0; t--)
  111. for (w = 0; w < nw; w++)
  112. {
  113. assert(scanf("t%dw%d %lf\n", &tt, &ww, &bar) == 3);
  114. assert(ww == w);
  115. if (bar > 0.5)
  116. {
  117. task[t].num = tt;
  118. task[t].worker = w;
  119. }
  120. }
  121. for (t = nt-1; t >= 0; t--)
  122. {
  123. assert(scanf("s%d %lf\n", &tt, &task[t].start) == 2);
  124. fprintf(stderr,"%d: task %d on %d: %f - %f\n", nt-1-t, tt, task[t].worker, task[t].start, task[t].stop);
  125. assert(tt == task[t].num);
  126. }
  127. for (t = 0; t < nt; t++)
  128. {
  129. printf("6 %f S W%d R%d\n", task[t].start, task[t].worker, t);
  130. printf("6 %f S W%d F\n", task[t].stop, task[t].worker);
  131. }
  132. for (t = 0; t < nt; t++)
  133. {
  134. int t2;
  135. for (t2 = 0; t2 < nt; t2++)
  136. {
  137. if (t != t2 && task[t].worker == task[t2].worker)
  138. {
  139. if (!(task[t].start >= task[t2].stop
  140. || task[t2].start >= task[t].stop))
  141. {
  142. fprintf(stderr,"oops, %d and %d sharing worker %d !!\n", task[t].num, task[t2].num, task[t].worker);
  143. }
  144. }
  145. }
  146. }
  147. }
  148. return 0;
  149. }