lp2paje.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. struct task {
  21. double start;
  22. double stop;
  23. int worker;
  24. };
  25. int main(int argc, char *argv[]) {
  26. int nw, nt;
  27. double tmax;
  28. int i, w, t, t2;
  29. int foo;
  30. double bar;
  31. unsigned long num;
  32. int b;
  33. unsigned long next = 1;
  34. if (argc != 3) {
  35. fprintf(stderr,"usage: %s nb_workers nb_tasks\n", argv[0]);
  36. exit(1);
  37. }
  38. nw = atoi(argv[1]);
  39. nt = atoi(argv[2]);
  40. fprintf(stderr,"%d workers, %d tasks\n", nw, nt);
  41. assert(scanf("\nValue of objective function: %lf\n", &tmax) == 1);
  42. printf(
  43. "%%EventDef PajeDefineContainerType 1\n"
  44. "%% Alias string\n"
  45. "%% ContainerType string\n"
  46. "%% Name string\n"
  47. "%%EndEventDef\n"
  48. "%%EventDef PajeCreateContainer 2\n"
  49. "%% Time date\n"
  50. "%% Alias string\n"
  51. "%% Type string\n"
  52. "%% Container string\n"
  53. "%% Name string\n"
  54. "%%EndEventDef\n"
  55. "%%EventDef PajeDefineStateType 3\n"
  56. "%% Alias string\n"
  57. "%% ContainerType string\n"
  58. "%% Name string\n"
  59. "%%EndEventDef\n"
  60. "%%EventDef PajeDestroyContainer 4\n"
  61. "%% Time date\n"
  62. "%% Name string\n"
  63. "%% Type string\n"
  64. "%%EndEventDef\n"
  65. "%%EventDef PajeDefineEntityValue 5\n"
  66. "%% Alias string\n"
  67. "%% EntityType string\n"
  68. "%% Name string\n"
  69. "%% Color color\n"
  70. "%%EndEventDef\n"
  71. "%%EventDef PajeSetState 6\n"
  72. "%% Time date\n"
  73. "%% Type string\n"
  74. "%% Container string\n"
  75. "%% Value string\n"
  76. "%%EndEventDef\n"
  77. "1 W 0 Worker\n"
  78. );
  79. printf("3 S W \"Worker State\"\n");
  80. printf("5 S S Running \"0.0 1.0 0.0\"\n");
  81. printf("5 F S Idle \"1.0 0.0 0.0\"\n");
  82. for (i = 0; i < nw; i++)
  83. printf("2 0 W%d W 0 \"%d\"\n", i, i);
  84. for (w = 0; w < nw; w++)
  85. printf("4 %f W%d W\n", tmax, w);
  86. assert(scanf("Actual values of the variables:\n") == 0);
  87. assert(scanf("tmax %f\n", &tmax) == 1);
  88. next++;
  89. {
  90. struct task task[nt];
  91. memset(&task, 0, sizeof(task));
  92. for (t = 0; t < nt; t++) {
  93. assert(scanf("c%d %lf\n", &foo, &task[t].stop) == 2);
  94. next++;
  95. }
  96. num = next;
  97. while (1) {
  98. if (num >= next +
  99. /* FIXME */
  100. //nw*nt
  101. 8*84 + 5*49
  102. ) {
  103. next+= 8*84+5*49;
  104. break;
  105. }
  106. assert(scanf("t%dw%d %lf\n", &foo, &foo, &bar) == 3);
  107. /* FIXME */
  108. if (num-next < 8*84) {
  109. t = (num - next) / nw;
  110. w = (num - next) % nw;
  111. } else {
  112. unsigned long nnum = (num-next)-8*84;
  113. t = (nnum / 5) + 84;
  114. w = (nnum % 5)+3;
  115. }
  116. if (bar > 0.5) {
  117. task[t].worker = w;
  118. fprintf(stderr,"%lu: task %d on %d: %f\n", num, t, w, task[t].stop);
  119. }
  120. num++;
  121. }
  122. for (t = 0; t < nt; t++) {
  123. assert(scanf("s%d %lf\n", &foo, &task[t].start) == 2);
  124. }
  125. for (t = 0; t < nt; t++) {
  126. printf("6 %f S W%d S\n", task[t].start, task[t].worker);
  127. printf("6 %f S W%d F\n", task[t].stop, task[t].worker);
  128. }
  129. for (t = 0; t < nt; t++) {
  130. for (t2 = 0; t2 < nt; t2++) {
  131. if (t != t2 && task[t].worker == task[t2].worker) {
  132. if (!(task[t].start >= task[t2].stop
  133. || task[t2].start >= task[t].stop)) {
  134. fprintf(stderr,"oops, %d and %d sharing worker %d !!\n", t, t2, task[t].worker);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. return 0;
  141. }