starpu_lp2paje.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011, 2013 Université de Bordeaux 1
  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 <config.h>
  17. #include <assert.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #define PROGNAME "starpu_lp2paje"
  22. struct task {
  23. double start;
  24. double stop;
  25. int num;
  26. int worker;
  27. };
  28. int main(int argc, char *argv[]) {
  29. int nw, nt;
  30. double tmax;
  31. int i, w, ww, t, tt, t2;
  32. int foo;
  33. double bar;
  34. if (argc != 1) {
  35. if (strcmp(argv[1], "-v") == 0
  36. || strcmp(argv[1], "--version") == 0)
  37. {
  38. fprintf(stderr, PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
  39. exit(EXIT_SUCCESS);
  40. }
  41. fprintf(stderr, "Convert schedule optimized by lp into the Paje format\n\n");
  42. fprintf(stderr, "Usage: lp_solve file.lp | %s > paje.trace\n", PROGNAME);
  43. fprintf(stderr, "Reports bugs to <"PACKAGE_BUGREPORT">.");
  44. fprintf(stderr, "\n");
  45. exit(EXIT_SUCCESS);
  46. }
  47. scanf("Suboptimal solution\n");
  48. assert(scanf("\nValue of objective function: %lf\n", &tmax) == 1);
  49. assert(scanf("Actual values of the variables:\n") == 0);
  50. assert(scanf("tmax %lf\n", &tmax) == 1);
  51. assert(scanf("nt %d\n", &nt) == 1);
  52. assert(scanf("nw %d\n", &nw) == 1);
  53. printf(
  54. "%%EventDef PajeDefineContainerType 1\n"
  55. "%% Alias string\n"
  56. "%% ContainerType string\n"
  57. "%% Name string\n"
  58. "%%EndEventDef\n"
  59. "%%EventDef PajeCreateContainer 2\n"
  60. "%% Time date\n"
  61. "%% Alias string\n"
  62. "%% Type string\n"
  63. "%% Container string\n"
  64. "%% Name string\n"
  65. "%%EndEventDef\n"
  66. "%%EventDef PajeDefineStateType 3\n"
  67. "%% Alias string\n"
  68. "%% ContainerType string\n"
  69. "%% Name string\n"
  70. "%%EndEventDef\n"
  71. "%%EventDef PajeDestroyContainer 4\n"
  72. "%% Time date\n"
  73. "%% Name string\n"
  74. "%% Type string\n"
  75. "%%EndEventDef\n"
  76. "%%EventDef PajeDefineEntityValue 5\n"
  77. "%% Alias string\n"
  78. "%% EntityType string\n"
  79. "%% Name string\n"
  80. "%% Color color\n"
  81. "%%EndEventDef\n"
  82. "%%EventDef PajeSetState 6\n"
  83. "%% Time date\n"
  84. "%% Type string\n"
  85. "%% Container string\n"
  86. "%% Value string\n"
  87. "%%EndEventDef\n"
  88. "1 W 0 Worker\n"
  89. );
  90. printf("3 S W \"Worker State\"\n");
  91. for (t = 0; t < nt; t++)
  92. printf("5 R%d S Running_%d \"0.0 1.0 0.0\"\n", t, t);
  93. printf("5 F S Idle \"1.0 0.0 0.0\"\n");
  94. for (i = 0; i < nw; i++)
  95. printf("2 0 W%d W 0 \"%d\"\n", i, i);
  96. for (w = 0; w < nw; w++)
  97. printf("4 %f W%d W\n", tmax, w);
  98. fprintf(stderr,"%d workers, %d tasks\n", nw, nt);
  99. {
  100. struct task task[nt];
  101. memset(&task, 0, sizeof(task));
  102. for (t = nt-1; t >= 0; t--) {
  103. assert(scanf("c%d %lf\n", &foo, &task[t].stop) == 2);
  104. }
  105. for (t = nt-1; t >= 0; t--)
  106. for (w = 0; w < nw; w++) {
  107. assert(scanf("t%dw%d %lf\n", &tt, &ww, &bar) == 3);
  108. assert(ww == w);
  109. if (bar > 0.5) {
  110. task[t].num = tt;
  111. task[t].worker = w;
  112. }
  113. }
  114. for (t = nt-1; t >= 0; t--) {
  115. assert(scanf("s%d %lf\n", &tt, &task[t].start) == 2);
  116. fprintf(stderr,"%d: task %d on %d: %f - %f\n", nt-1-t, tt, task[t].worker, task[t].start, task[t].stop);
  117. assert(tt == task[t].num);
  118. }
  119. for (t = 0; t < nt; t++) {
  120. printf("6 %f S W%d R%d\n", task[t].start, task[t].worker, t);
  121. printf("6 %f S W%d F\n", task[t].stop, task[t].worker);
  122. }
  123. for (t = 0; t < nt; t++) {
  124. for (t2 = 0; t2 < nt; t2++) {
  125. if (t != t2 && task[t].worker == task[t2].worker) {
  126. if (!(task[t].start >= task[t2].stop
  127. || task[t2].start >= task[t].stop)) {
  128. fprintf(stderr,"oops, %d and %d sharing worker %d !!\n", task[t].num, task[t2].num, task[t].worker);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. return 0;
  135. }