starpu_lp2paje.c 4.3 KB

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