lp2paje.c 3.8 KB

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