starpu_replay.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016-2017 Université de Bordeaux
  4. * Copyright (C) 2017 Erwan Leria
  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. /*
  18. * This reads a tasks.rec file and replays the recorded task graph.
  19. * Currently, this version is done to run with simgrid.
  20. *
  21. * For further information, contact erwan.leria@inria.fr
  22. */
  23. #include <starpu.h>
  24. #include <unistd.h>
  25. #include <stdio.h>
  26. #include <math.h>
  27. #include <common/uthash.h>
  28. #include <common/utils.h>
  29. #include <starpu_scheduler.h>
  30. #include <common/rbtree.h>
  31. #define REPLAY_NMAX_DEPENDENCIES 8
  32. #define ARRAY_DUP(in, out, n) memcpy(out, in, n * sizeof(*out))
  33. #define ARRAY_INIT(array, n) memset(array, 0, n * sizeof(*array))
  34. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  35. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  36. * Declarations of global variables, structures, pointers, ... *
  37. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  38. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  39. /* Enum for normal and "wontuse" tasks */
  40. enum task_type {NormalTask, WontUseTask};
  41. typedef unsigned long jobid_t;
  42. enum task_type control;
  43. static char *name = NULL;
  44. static char *model = NULL;
  45. static jobid_t jobid;
  46. static jobid_t *dependson;
  47. static long submitorder = -1;
  48. static starpu_tag_t tag;
  49. static int workerid;
  50. static uint32_t footprint;
  51. static double flops;
  52. static double startTime; //start time (The instant when the task starts)
  53. static double endTime; //end time (The instant when the task ends)
  54. static int iteration = -1;
  55. static starpu_data_handle_t handles[STARPU_NMAXBUFS];
  56. static enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  57. static char normal_reg_signal[STARPU_NMAXBUFS];
  58. /* Use the following arrays when the number of data is greater than STARPU_NMAXBUFS */
  59. starpu_data_handle_t * handles_ptr;
  60. enum starpu_data_access_mode * modes_ptr;
  61. size_t * sizes_set;
  62. static size_t dependson_size;
  63. static size_t ndependson;
  64. static int nb_parameters = 0; /* Number of parameters */
  65. static int alloc_mode; /* If alloc_mode value is 1, then the handles are stored in dyn_handles, else they are in handles */
  66. static int priority = 0;
  67. char * reg_signal = NULL; /* The register signal (0 or 1 coded on 8 bit) is used to know which handle of the task has to be registered in StarPU (in fact to avoid handle twice)*/
  68. static int device;
  69. /* Record all tasks, hashed by jobid. */
  70. static struct task
  71. {
  72. struct starpu_rbtree_node node;
  73. UT_hash_handle hh;
  74. jobid_t jobid;
  75. int iteration;
  76. unsigned long submit_order;
  77. jobid_t *deps;
  78. size_t ndependson;
  79. struct starpu_task task;
  80. enum task_type type;
  81. } *tasks;
  82. /* Record handles */
  83. static struct handle
  84. {
  85. UT_hash_handle hh;
  86. starpu_data_handle_t mem_ptr; /* This value should be the registered handle */
  87. starpu_data_handle_t handle; /* The key is the original value of the handle in the file */
  88. } * handles_hash;
  89. /* Record models */
  90. static struct perfmodel
  91. {
  92. UT_hash_handle hh;
  93. struct starpu_perfmodel perfmodel;
  94. char * model_name;
  95. } * model_hash;
  96. /* [SUBMITORDER] The tree of the submit order */
  97. static struct starpu_rbtree tree = STARPU_RBTREE_INITIALIZER;
  98. /* the cmp_fn arg for rb_tree_insert() */
  99. unsigned int diff(struct starpu_rbtree_node * left_elm, struct starpu_rbtree_node * right_elm)
  100. {
  101. return ((struct task *) left_elm)->submit_order - ((struct task *) right_elm)->submit_order;
  102. }
  103. /* Settings for the perfmodel */
  104. struct task_arg
  105. {
  106. uint32_t footprint;
  107. double perf[];
  108. };
  109. uint32_t get_footprint(struct starpu_task * task)
  110. {
  111. return ((struct task_arg*) (task->cl_arg))->footprint;
  112. }
  113. double arch_cost_function(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  114. {
  115. device = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
  116. STARPU_ASSERT(device != -1);
  117. /* Then, get the pointer to the value of the expected time */
  118. double * val = (double *) ((struct task_arg *) (task->cl_arg))->perf+device;
  119. if (!(*val == 0 || isnan(*val)))
  120. return *val;
  121. fprintf(stderr, "[starpu] Error, expected_time is 0 or lower (replay.c line : %d)", __LINE__- 6);
  122. return 0.0;
  123. }
  124. /* End of settings */
  125. void dumb_kernel(void) {}
  126. /* [CODELET] Initialization of an unique codelet for all the tasks*/
  127. static int can_execute(unsigned worker_id, struct starpu_task *task, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  128. {
  129. struct starpu_perfmodel_arch * arch = starpu_worker_get_perf_archtype(worker_id, STARPU_NMAX_SCHED_CTXS);
  130. double expected_time = ((struct task_arg *) (task->cl_arg))->perf[(starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices))];
  131. if (!(expected_time == 0 || isnan(expected_time)))
  132. {
  133. return 1;
  134. }
  135. return 0;
  136. }
  137. static struct starpu_perfmodel myperfmodel =
  138. {
  139. .type = STARPU_PER_ARCH,
  140. .arch_cost_function = arch_cost_function,
  141. .footprint = get_footprint,
  142. };
  143. static struct starpu_codelet cl =
  144. {
  145. .cpu_funcs = { (void*) 1 },
  146. .cpu_funcs_name = { "dumb_kernel" },
  147. .cuda_funcs = { (void*) 1 },
  148. .opencl_funcs = { (void*) 1 },
  149. .nbuffers = STARPU_VARIABLE_NBUFFERS,
  150. .can_execute = can_execute,
  151. .model = &myperfmodel,
  152. };
  153. /* * * * * * * * * * * * * *
  154. * * * * * Functions * * * * *
  155. * * * * * * * * * * * * * * */
  156. /* The following function checks if the program has to use static or dynamic arrays*/
  157. static int set_alloc_mode(int total_parameters)
  158. {
  159. return (total_parameters <= STARPU_NMAXBUFS);
  160. }
  161. /* According to the allocation mode, modify handles_ptr and modes_ptr in static or dynamic */
  162. static void arrays_managing(int mode)
  163. {
  164. if (mode)
  165. {
  166. handles_ptr = &handles[0];
  167. modes_ptr = &modes[0];
  168. reg_signal = &normal_reg_signal[0];
  169. }
  170. else
  171. {
  172. _STARPU_MALLOC(handles_ptr, sizeof(*handles_ptr) * nb_parameters);
  173. _STARPU_MALLOC(modes_ptr, sizeof(*modes_ptr) * nb_parameters);
  174. _STARPU_CALLOC(reg_signal, nb_parameters, sizeof(char *));
  175. }
  176. }
  177. /* Check if a handle hasn't been registered yet */
  178. static void variable_data_register_check(size_t * array_of_size, int nb_handles)
  179. {
  180. int h;
  181. for (h = 0 ; h < nb_handles ; h++)
  182. {
  183. if(reg_signal[h]) /* Get the register signal, if it's 1 do ... */
  184. {
  185. struct handle * handles_cell;
  186. _STARPU_MALLOC(handles_cell, sizeof(*handles_cell));
  187. STARPU_ASSERT(handles_cell != NULL);
  188. handles_cell->handle = handles_ptr[h]; /* Get the hidden key (initial handle from the file) to store it as a key*/
  189. starpu_variable_data_register(handles_ptr+h, STARPU_MAIN_RAM, (uintptr_t) 1, array_of_size[h]);
  190. handles_cell->mem_ptr = handles_ptr[h]; /* Store the new value of the handle into the hash table */
  191. HASH_ADD(hh, handles_hash, handle, sizeof(handles_ptr[h]), handles_cell);
  192. }
  193. }
  194. }
  195. void reset(void)
  196. {
  197. control = NormalTask;
  198. if (name != NULL)
  199. {
  200. free(name);
  201. name = NULL;
  202. }
  203. if (model != NULL)
  204. {
  205. free(model);
  206. model = NULL;
  207. }
  208. if (sizes_set != NULL)
  209. {
  210. free(sizes_set);
  211. sizes_set = NULL;
  212. }
  213. if (reg_signal != NULL)
  214. {
  215. if (!alloc_mode)
  216. {
  217. free(reg_signal);
  218. reg_signal = NULL;
  219. }
  220. else
  221. {
  222. ARRAY_INIT(reg_signal, nb_parameters);
  223. }
  224. }
  225. jobid = 0;
  226. ndependson = 0;
  227. tag = -1;
  228. workerid = -1;
  229. footprint = 0;
  230. startTime = 0.0;
  231. endTime = 0.0;
  232. if (submitorder != -1)
  233. submitorder = -1;
  234. iteration = -1;
  235. nb_parameters = 0;
  236. alloc_mode = 1;
  237. }
  238. void fix_wontuse_handle(struct task * wontuseTask)
  239. {
  240. struct handle * handle_tmp;
  241. HASH_FIND(hh, handles_hash, &wontuseTask->task.handles[0], sizeof(wontuseTask->task.handles[0]), handle_tmp);
  242. STARPU_ASSERT(wontuseTask);
  243. wontuseTask->task.handles[0] = handle_tmp->mem_ptr;
  244. }
  245. /* Function that submits all the tasks (used when the program reaches EOF) */
  246. int submit_tasks(void)
  247. {
  248. /* Add dependencies */
  249. const struct starpu_rbtree * tmptree = &tree;
  250. struct starpu_rbtree_node * currentNode = starpu_rbtree_first(tmptree);
  251. while (currentNode != NULL)
  252. {
  253. struct task * currentTask = (struct task *) currentNode;
  254. if (currentTask->type == NormalTask)
  255. {
  256. if (currentTask->ndependson > 0)
  257. {
  258. struct starpu_task * taskdeps[currentTask->ndependson];
  259. unsigned i;
  260. for (i = 0; i < currentTask->ndependson; i++)
  261. {
  262. struct task * taskdep;
  263. /* Get the ith jobid of deps_jobid */
  264. HASH_FIND(hh, tasks, &currentTask->deps[i], sizeof(jobid), taskdep);
  265. STARPU_ASSERT(taskdep);
  266. taskdeps[i] = &taskdep->task;
  267. }
  268. starpu_task_declare_deps_array(&currentTask->task, currentTask->ndependson, taskdeps);
  269. }
  270. if (!(currentTask->iteration == -1))
  271. starpu_iteration_push(currentTask->iteration);
  272. //applySchedRec(&currentTask->task, currentTask->submit)
  273. int ret_val = starpu_task_submit(&currentTask->task);
  274. if (!(currentTask->iteration == -1))
  275. starpu_iteration_pop();
  276. if (ret_val != 0)
  277. return -1;
  278. //printf("submitting task %s (%lu, %llu)\n", currentTask->task.name?currentTask->task.name:"anonymous", currentTask->jobid, (unsigned long long) currentTask->task.tag_id);
  279. printf("\rsubmitting task %lu", currentTask->submit_order);
  280. }
  281. else
  282. {
  283. fix_wontuse_handle(currentTask); /* Add the handle in the wontuse task */
  284. /* FIXME: can not actually work properly since we have
  285. * disabled sequential consistency, so we don't have any
  286. * easy way to make this wait for the last task that
  287. * wrote to the handle. */
  288. starpu_data_wont_use(currentTask->task.handles[0]);
  289. }
  290. currentNode = starpu_rbtree_next(currentNode);
  291. }
  292. printf("\n");
  293. return 1;
  294. }
  295. /* * * * * * * * * * * * * * * */
  296. /* * * * * * MAIN * * * * * * */
  297. /* * * * * * * * * * * * * * */
  298. int main(int argc, char **argv)
  299. {
  300. starpu_data_set_default_sequential_consistency_flag(0);
  301. FILE *rec;
  302. char *s;
  303. size_t s_allocated = 128;
  304. _STARPU_MALLOC(s, s_allocated);
  305. dependson_size = REPLAY_NMAX_DEPENDENCIES; /* Change the value of REPLAY_NMAX_DEPENCIES to modify the number of dependencies */
  306. _STARPU_MALLOC(dependson, dependson_size * sizeof (* dependson));
  307. alloc_mode = 1;
  308. if (argc <= 1)
  309. {
  310. fprintf(stderr,"Usage: %s tasks.rec [sched.rec]\n", argv[0]);
  311. exit(EXIT_FAILURE);
  312. }
  313. /*
  314. if (schedRecInit(argv[2]) == NULL)
  315. {
  316. fprintf(stderr,"unable to open file %s: %s\n", argv[2], strerror(errno));
  317. exit(EXIT_FAILURE);
  318. }
  319. */
  320. rec = fopen(argv[1], "r");
  321. if (!rec)
  322. {
  323. fprintf(stderr,"unable to open file %s: %s\n", argv[1], strerror(errno));
  324. exit(EXIT_FAILURE);
  325. }
  326. int ret = starpu_init(NULL);
  327. if (ret == -ENODEV) goto enodev;
  328. /* Read line by line, and on empty line submit the task with the accumulated information */
  329. reset();
  330. while(1)
  331. {
  332. char *ln;
  333. if (!fgets(s, s_allocated, rec))
  334. {
  335. int submitted = submit_tasks();
  336. if (submitted == -1)
  337. {
  338. goto enodev;
  339. }
  340. goto eof;
  341. }
  342. while (!(ln = strchr(s, '\n')))
  343. {
  344. /* fprintf(stderr,"buffer size %d too small, doubling it\n", s_allocated); */
  345. _STARPU_REALLOC(s, s_allocated * 2);
  346. if (!fgets(s + s_allocated-1, s_allocated+1, rec))
  347. {
  348. int submitted = submit_tasks();
  349. if (submitted == -1)
  350. {
  351. goto enodev;
  352. }
  353. goto eof;
  354. }
  355. s_allocated *= 2;
  356. }
  357. if (ln == s)
  358. {
  359. /* Empty line, do task */
  360. struct task * task;
  361. _STARPU_MALLOC(task, sizeof(*task));
  362. starpu_task_init(&task->task);
  363. task->deps = NULL;
  364. if (submitorder != -1)
  365. {
  366. task->submit_order = submitorder;
  367. starpu_rbtree_node_init(&task->node);
  368. starpu_rbtree_insert(&tree, &task->node, diff);
  369. }
  370. task->jobid = jobid;
  371. task->iteration = iteration;
  372. if (name != NULL)
  373. task->task.name = strdup(name);
  374. task->type = control;
  375. if (control == NormalTask)
  376. {
  377. if (workerid >= 0)
  378. {
  379. task->task.priority = priority;
  380. task->task.cl = &cl;
  381. task->task.workerid = workerid;
  382. if (alloc_mode)
  383. {
  384. /* Duplicating the handles stored (and registered in the current context) into the task */
  385. ARRAY_DUP(modes_ptr, task->task.modes, nb_parameters);
  386. ARRAY_DUP(modes_ptr, task->task.cl->modes, nb_parameters);
  387. variable_data_register_check(sizes_set, nb_parameters);
  388. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  389. }
  390. else
  391. {
  392. task->task.dyn_modes = modes_ptr;
  393. _STARPU_MALLOC(task->task.cl->dyn_modes, (sizeof(*task->task.cl->dyn_modes) * nb_parameters));
  394. ARRAY_DUP(modes_ptr, task->task.cl->dyn_modes, nb_parameters);
  395. variable_data_register_check(sizes_set, nb_parameters);
  396. task->task.dyn_handles = handles_ptr;
  397. }
  398. task->task.nbuffers = nb_parameters;
  399. struct perfmodel * realmodel;
  400. HASH_FIND_STR(model_hash, model, realmodel);
  401. if (realmodel == NULL)
  402. {
  403. int len = strlen(model);
  404. _STARPU_CALLOC(realmodel, 1, sizeof(struct perfmodel));
  405. _STARPU_MALLOC(realmodel->model_name, sizeof(char) * (len+1));
  406. realmodel->model_name = strcpy(realmodel->model_name, model);
  407. starpu_perfmodel_init(&realmodel->perfmodel);
  408. HASH_ADD_STR(model_hash, model_name, realmodel);
  409. int error = starpu_perfmodel_load_symbol(model, &realmodel->perfmodel);
  410. if (error)
  411. {
  412. fprintf(stderr, "[starpu][Warning] Error loading perfmodel symbol %s\n", model);
  413. exit(EXIT_FAILURE);
  414. }
  415. }
  416. int narch = starpu_perfmodel_get_narch_combs();
  417. struct task_arg *arg;
  418. _STARPU_MALLOC(arg, sizeof(struct task_arg) + sizeof(double) * narch);
  419. arg->footprint = footprint;
  420. double * perfTime = arg->perf;
  421. int i;
  422. for (i = 0; i < narch ; i++)
  423. {
  424. struct starpu_perfmodel_arch *arch = starpu_perfmodel_arch_comb_fetch(i);
  425. perfTime[i] = starpu_perfmodel_history_based_expected_perf(&realmodel->perfmodel, arch, footprint);
  426. }
  427. task->task.cl_arg = arg;
  428. task->task.flops = flops;
  429. }
  430. task->task.cl_arg_size = 0;
  431. task->task.tag_id = tag;
  432. task->task.use_tag = 1;
  433. task->ndependson = ndependson;
  434. if (ndependson > 0)
  435. {
  436. _STARPU_MALLOC(task->deps, ndependson * sizeof (* task->deps));
  437. ARRAY_DUP(dependson, task->deps, ndependson);
  438. }
  439. }
  440. else
  441. {
  442. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  443. }
  444. /* Add this task to task hash */
  445. HASH_ADD(hh, tasks, jobid, sizeof(jobid), task);
  446. reset();
  447. }
  448. /* Record various information */
  449. #define TEST(field) (!strncmp(s, field": ", strlen(field) + 2))
  450. else if(TEST("Control"))
  451. {
  452. char * c = s+9;
  453. if(!strncmp(c, "WontUse", 7))
  454. {
  455. control = WontUseTask;
  456. nb_parameters = 1;
  457. alloc_mode = set_alloc_mode(nb_parameters);
  458. arrays_managing(alloc_mode);
  459. }
  460. else
  461. control = NormalTask;
  462. }
  463. else if (TEST("Name"))
  464. {
  465. *ln = 0;
  466. name = strdup(s+6);
  467. }
  468. else if (TEST("Model"))
  469. {
  470. *ln = 0;
  471. model = strdup(s+7);
  472. }
  473. else if (TEST("JobId"))
  474. jobid = atol(s+7);
  475. else if(TEST("SubmitOrder"))
  476. submitorder = atoi(s+13);
  477. else if (TEST("DependsOn"))
  478. {
  479. char *c = s + 11;
  480. for (ndependson = 0; *c != '\n'; ndependson++)
  481. {
  482. if (ndependson >= dependson_size)
  483. {
  484. dependson_size *= 2;
  485. _STARPU_REALLOC(dependson, dependson_size * sizeof(*dependson));
  486. }
  487. dependson[ndependson] = strtol(c, &c, 10);
  488. }
  489. }
  490. else if (TEST("Tag"))
  491. tag = strtol(s+5, NULL, 16);
  492. else if (TEST("WorkerId"))
  493. workerid = atoi(s+10);
  494. else if (TEST("Footprint"))
  495. {
  496. footprint = strtoul(s+11, NULL, 16);
  497. }
  498. else if (TEST("Parameters"))
  499. {
  500. /* Parameters line format is PARAM1_PARAM2_(...)PARAMi_(...)PARAMn */
  501. char * param_str = s + 12;
  502. unsigned i;
  503. int count = 0;
  504. for (i = 0 ; param_str[i] != '\n'; i++)
  505. {
  506. if (param_str[i] == '_') /* Checking the number of '_' (underscore), assuming that the file is not corrupted */
  507. {
  508. count++;
  509. }
  510. }
  511. nb_parameters = count + 1; /* There is one underscore per paramater execept for the last one, that's why we have to add +1 (dirty programming) */
  512. /* This part of the algorithm will determine if it needs static or dynamic arrays */
  513. alloc_mode = set_alloc_mode(nb_parameters);
  514. arrays_managing(alloc_mode);
  515. }
  516. else if (TEST("Handles"))
  517. {
  518. char *buffer = s + 9;
  519. const char *delim = " ";
  520. char *token = strtok(buffer, delim);
  521. while (token != NULL)
  522. {
  523. int i;
  524. for (i = 0 ; i < nb_parameters ; i++)
  525. {
  526. struct handle *handles_cell; /* A cell of the hash table for the handles */
  527. starpu_data_handle_t handle_value = (starpu_data_handle_t) strtol(token, NULL, 16); /* Get the ith handle on the line (in the file) */
  528. HASH_FIND(hh, handles_hash, &handle_value, sizeof(handle_value), handles_cell); /* Find if the handle_value was already registered as a key in the hash table */
  529. /* If it wasn't, then add it to the hash table */
  530. if (handles_cell == NULL)
  531. {
  532. /* Hide the initial handle from the file into the handles array to find it when necessary */
  533. handles_ptr[i] = handle_value;
  534. reg_signal[i] = 1;
  535. }
  536. else
  537. {
  538. handles_ptr[i] = handles_cell->mem_ptr;
  539. }
  540. token = strtok(NULL, delim);
  541. }
  542. }
  543. }
  544. else if (TEST("Modes"))
  545. {
  546. char * buffer = s + 7;
  547. int mode_i = 0;
  548. int i = 0;
  549. const char * delim = " ";
  550. char * token = strtok(buffer, delim);
  551. while (token != NULL)
  552. {
  553. /* Subject to the names of starpu modes enumerator are not modified */
  554. if (!strncmp(token, "RW", 2))
  555. {
  556. *(modes_ptr+mode_i) = STARPU_RW;
  557. mode_i++;
  558. i++;
  559. }
  560. else if (!strncmp(token, "R", 1))
  561. {
  562. *(modes_ptr+mode_i) = STARPU_R;
  563. mode_i++;
  564. }
  565. else if (!strncmp(token, "W", 1))
  566. {
  567. *(modes_ptr+mode_i) = STARPU_W;
  568. mode_i++;
  569. }
  570. /* Other cases produce a warning*/
  571. else
  572. {
  573. fprintf(stderr, "[Warning] A mode is different from R/W (jobid task : %lu)", jobid);
  574. }
  575. token = strtok(NULL, delim);
  576. }
  577. }
  578. else if (TEST("Sizes"))
  579. {
  580. char * buffer = s + 7;
  581. const char * delim = " ";
  582. char * token = strtok(buffer, delim);
  583. int k = 0;
  584. _STARPU_MALLOC(sizes_set, nb_parameters * sizeof(size_t));
  585. while (token != NULL)
  586. {
  587. sizes_set[k] = strtol(token, NULL, 10);
  588. token = strtok(NULL, delim);
  589. k++;
  590. }
  591. }
  592. else if (TEST("StartTime"))
  593. {
  594. startTime = strtod(s+11, NULL);
  595. }
  596. else if (TEST("EndTime"))
  597. {
  598. endTime = strtod(s+9, NULL);
  599. }
  600. else if (TEST("GFlop"))
  601. {
  602. flops = 1000000000 * strtod(s+7, NULL);
  603. }
  604. else if (TEST("Iteration"))
  605. {
  606. iteration = (unsigned) strtol(s+11, NULL, 10);
  607. }
  608. else if (TEST("Priority"))
  609. {
  610. priority = strtol(s + 10, NULL, 10);
  611. }
  612. }
  613. eof:
  614. starpu_task_wait_for_all();
  615. /* FREE allocated memory */
  616. free(dependson);
  617. free(s);
  618. /* End of FREE */
  619. struct handle * handle,* handletmp;
  620. HASH_ITER(hh, handles_hash, handle, handletmp)
  621. {
  622. starpu_data_unregister(handle->mem_ptr);
  623. HASH_DEL(handles_hash, handle);
  624. free(handle);
  625. }
  626. struct perfmodel * model_s, * modeltmp;
  627. HASH_ITER(hh, model_hash, model_s, modeltmp)
  628. {
  629. starpu_perfmodel_unload_model(&model_s->perfmodel);
  630. HASH_DEL(model_hash, model_s);
  631. free(model_s->model_name);
  632. free(model_s);
  633. }
  634. struct task * task, *tasktmp;
  635. HASH_ITER(hh, tasks, task, tasktmp)
  636. {
  637. free(task->task.cl_arg);
  638. free((char*)task->task.name);
  639. if (task->task.dyn_handles != NULL)
  640. {
  641. free(task->task.dyn_handles);
  642. free(task->task.dyn_modes);
  643. }
  644. HASH_DEL(tasks, task);
  645. starpu_task_clean(&task->task);
  646. free(task->deps);
  647. starpu_rbtree_remove(&tree, &task->node);
  648. free(task);
  649. }
  650. starpu_shutdown();
  651. return 0;
  652. enodev:
  653. return 77;
  654. }