starpu_lp2paje.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011, 2013-2014 Université de Bordeaux
  4. * Copyright (C) 2014, 2015, 2016 CNRS
  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 <config.h>
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.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, t2;
  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, PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
  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 <"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(scanf("nw %d\n", &nw) == 1);
  56. printf(
  57. "%%EventDef PajeDefineContainerType 1\n"
  58. "%% Alias string\n"
  59. "%% ContainerType string\n"
  60. "%% Name string\n"
  61. "%%EndEventDef\n"
  62. "%%EventDef PajeCreateContainer 2\n"
  63. "%% Time date\n"
  64. "%% Alias string\n"
  65. "%% Type string\n"
  66. "%% Container string\n"
  67. "%% Name string\n"
  68. "%%EndEventDef\n"
  69. "%%EventDef PajeDefineStateType 3\n"
  70. "%% Alias string\n"
  71. "%% ContainerType string\n"
  72. "%% Name string\n"
  73. "%%EndEventDef\n"
  74. "%%EventDef PajeDestroyContainer 4\n"
  75. "%% Time date\n"
  76. "%% Name string\n"
  77. "%% Type string\n"
  78. "%%EndEventDef\n"
  79. "%%EventDef PajeDefineEntityValue 5\n"
  80. "%% Alias string\n"
  81. "%% EntityType string\n"
  82. "%% Name string\n"
  83. "%% Color color\n"
  84. "%%EndEventDef\n"
  85. "%%EventDef PajeSetState 6\n"
  86. "%% Time date\n"
  87. "%% Type string\n"
  88. "%% Container string\n"
  89. "%% Value string\n"
  90. "%%EndEventDef\n"
  91. "1 W 0 Worker\n"
  92. );
  93. printf("3 S W \"Worker State\"\n");
  94. for (t = 0; t < nt; t++)
  95. printf("5 R%d S Running_%d \"0.0 1.0 0.0\"\n", t, t);
  96. printf("5 F S Idle \"1.0 0.0 0.0\"\n");
  97. for (i = 0; i < nw; i++)
  98. printf("2 0 W%d W 0 \"%d\"\n", i, i);
  99. for (w = 0; w < nw; w++)
  100. printf("4 %f W%d W\n", tmax, w);
  101. fprintf(stderr,"%d workers, %d tasks\n", nw, nt);
  102. {
  103. struct task task[nt];
  104. memset(&task, 0, sizeof(task));
  105. for (t = nt-1; t >= 0; t--)
  106. {
  107. assert(scanf("c%d %lf\n", &foo, &task[t].stop) == 2);
  108. }
  109. for (t = nt-1; t >= 0; t--)
  110. for (w = 0; w < nw; w++)
  111. {
  112. assert(scanf("t%dw%d %lf\n", &tt, &ww, &bar) == 3);
  113. assert(ww == w);
  114. if (bar > 0.5)
  115. {
  116. task[t].num = tt;
  117. task[t].worker = w;
  118. }
  119. }
  120. for (t = nt-1; t >= 0; t--)
  121. {
  122. assert(scanf("s%d %lf\n", &tt, &task[t].start) == 2);
  123. fprintf(stderr,"%d: task %d on %d: %f - %f\n", nt-1-t, tt, task[t].worker, task[t].start, task[t].stop);
  124. assert(tt == task[t].num);
  125. }
  126. for (t = 0; t < nt; t++)
  127. {
  128. printf("6 %f S W%d R%d\n", task[t].start, task[t].worker, t);
  129. printf("6 %f S W%d F\n", task[t].stop, task[t].worker);
  130. }
  131. for (t = 0; t < nt; t++)
  132. {
  133. for (t2 = 0; t2 < nt; t2++)
  134. {
  135. if (t != t2 && task[t].worker == task[t2].worker)
  136. {
  137. if (!(task[t].start >= task[t2].stop
  138. || task[t2].start >= task[t].stop))
  139. {
  140. fprintf(stderr,"oops, %d and %d sharing worker %d !!\n", task[t].num, task[t2].num, task[t].worker);
  141. }
  142. }
  143. }
  144. }
  145. }
  146. return 0;
  147. }