parallel_heft.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 inria
  4. * Copyright (C) 2010-2012 Université de Bordeaux 1
  5. * Copyright (C) 2011 Télécom-SudParis
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /* Distributed queues using performance modeling to assign tasks */
  19. #include <float.h>
  20. #include <limits.h>
  21. #include <core/workers.h>
  22. #include <core/perfmodel/perfmodel.h>
  23. #include <starpu_parameters.h>
  24. #include <common/barrier.h>
  25. #include <sched_policies/detect_combined_workers.h>
  26. #ifndef DBL_MIN
  27. #define DBL_MIN __DBL_MIN__
  28. #endif
  29. #ifndef DBL_MAX
  30. #define DBL_MAX __DBL_MAX__
  31. #endif
  32. //static unsigned ncombinedworkers;
  33. //static enum starpu_perf_archtype applicable_perf_archtypes[STARPU_NARCH_VARIATIONS];
  34. //static unsigned napplicable_perf_archtypes = 0;
  35. struct _starpu_pheft_data
  36. {
  37. double alpha;
  38. double beta;
  39. double _gamma;
  40. double idle_power;
  41. /* When we push a task on a combined worker we need all the cpu workers it contains
  42. * to be locked at once */
  43. _starpu_pthread_mutex_t global_push_mutex;
  44. };
  45. static double worker_exp_start[STARPU_NMAXWORKERS];
  46. static double worker_exp_end[STARPU_NMAXWORKERS];
  47. static double worker_exp_len[STARPU_NMAXWORKERS];
  48. static int ntasks[STARPU_NMAXWORKERS];
  49. /*!!!!!!! It doesn't work with several contexts because the combined workers are constructed
  50. from the workers available to the program, and not to the context !!!!!!!!!!!!!!!!!!!!!!!
  51. */
  52. static void parallel_heft_pre_exec_hook(struct starpu_task *task)
  53. {
  54. if (!task->cl || task->execute_on_a_specific_worker)
  55. return;
  56. int workerid = starpu_worker_get_id();
  57. double model = task->predicted;
  58. unsigned sched_ctx_id = task->sched_ctx;
  59. double transfer_model = task->predicted_transfer;
  60. if (isnan(model))
  61. model = 0.0;
  62. _starpu_pthread_mutex_t *sched_mutex;
  63. _starpu_pthread_cond_t *sched_cond;
  64. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  65. /* Once we have executed the task, we can update the predicted amount
  66. * of work. */
  67. _STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  68. worker_exp_len[workerid] -= model + transfer_model;
  69. worker_exp_start[workerid] = starpu_timing_now() + model;
  70. worker_exp_end[workerid] = worker_exp_start[workerid] + worker_exp_len[workerid];
  71. ntasks[workerid]--;
  72. _STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  73. }
  74. static int push_task_on_best_worker(struct starpu_task *task, int best_workerid, double exp_end_predicted, int prio, unsigned sched_ctx_id)
  75. {
  76. /* make sure someone coule execute that task ! */
  77. STARPU_ASSERT(best_workerid != -1);
  78. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  79. /* Is this a basic worker or a combined worker ? */
  80. unsigned memory_node;
  81. memory_node = starpu_worker_get_memory_node(best_workerid);
  82. if (starpu_get_prefetch_flag())
  83. starpu_prefetch_task_input_on_node(task, memory_node);
  84. int ret = 0;
  85. if (!starpu_worker_is_combined_worker(best_workerid))
  86. {
  87. task->predicted = exp_end_predicted - worker_exp_end[best_workerid];
  88. /* TODO */
  89. task->predicted_transfer = 0;
  90. _starpu_pthread_mutex_t *sched_mutex;
  91. _starpu_pthread_cond_t *sched_cond;
  92. starpu_worker_get_sched_condition(best_workerid, &sched_mutex, &sched_cond);
  93. _STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  94. worker_exp_len[best_workerid] += task->predicted;
  95. worker_exp_end[best_workerid] = exp_end_predicted;
  96. worker_exp_start[best_workerid] = exp_end_predicted - worker_exp_len[best_workerid];
  97. ntasks[best_workerid]++;
  98. _STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  99. /* We don't want it to interlace its task with a combined
  100. * worker's one */
  101. _STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  102. ret = starpu_push_local_task(best_workerid, task, prio);
  103. _STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  104. }
  105. else
  106. {
  107. /* This is a combined worker so we create task aliases */
  108. struct _starpu_combined_worker *combined_worker;
  109. combined_worker = _starpu_get_combined_worker_struct(best_workerid);
  110. int worker_size = combined_worker->worker_size;
  111. int *combined_workerid = combined_worker->combined_workerid;
  112. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  113. j->task_size = worker_size;
  114. j->combined_workerid = best_workerid;
  115. j->active_task_alias_count = 0;
  116. /* This task doesn't belong to an actual worker, it belongs
  117. * to a combined worker and thus the scheduler doesn't care
  118. * of its predicted values which are insignificant */
  119. task->predicted = 0;
  120. task->predicted_transfer = 0;
  121. _STARPU_PTHREAD_BARRIER_INIT(&j->before_work_barrier, NULL, worker_size);
  122. _STARPU_PTHREAD_BARRIER_INIT(&j->after_work_barrier, NULL, worker_size);
  123. /* All cpu workers must be locked at once */
  124. _STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  125. int i;
  126. for (i = 0; i < worker_size; i++)
  127. {
  128. struct starpu_task *alias = _starpu_create_task_alias(task);
  129. int local_worker = combined_workerid[i];
  130. alias->predicted = exp_end_predicted - worker_exp_end[local_worker];
  131. /* TODO */
  132. alias->predicted_transfer = 0;
  133. _starpu_pthread_mutex_t *sched_mutex;
  134. _starpu_pthread_cond_t *sched_cond;
  135. starpu_worker_get_sched_condition(local_worker, &sched_mutex, &sched_cond);
  136. _STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  137. worker_exp_len[local_worker] += alias->predicted;
  138. worker_exp_end[local_worker] = exp_end_predicted;
  139. worker_exp_start[local_worker] = exp_end_predicted - worker_exp_len[local_worker];
  140. ntasks[local_worker]++;
  141. _STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  142. ret |= starpu_push_local_task(local_worker, alias, prio);
  143. }
  144. _STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  145. //TODO : free task
  146. }
  147. return ret;
  148. }
  149. static double compute_expected_end(int workerid, double length)
  150. {
  151. if (!starpu_worker_is_combined_worker(workerid))
  152. {
  153. /* This is a basic worker */
  154. return worker_exp_start[workerid] + worker_exp_len[workerid] + length;
  155. }
  156. else
  157. {
  158. /* This is a combined worker, the expected end is the end for the latest worker */
  159. int worker_size;
  160. int *combined_workerid;
  161. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  162. double exp_end = DBL_MIN;
  163. int i;
  164. for (i = 0; i < worker_size; i++)
  165. {
  166. double local_exp_start = worker_exp_start[combined_workerid[i]];
  167. double local_exp_len = worker_exp_len[combined_workerid[i]];
  168. double local_exp_end = local_exp_start + local_exp_len + length;
  169. exp_end = STARPU_MAX(exp_end, local_exp_end);
  170. }
  171. return exp_end;
  172. }
  173. }
  174. static double compute_ntasks_end(int workerid)
  175. {
  176. enum starpu_perf_archtype perf_arch = starpu_worker_get_perf_archtype(workerid);
  177. if (!starpu_worker_is_combined_worker(workerid))
  178. {
  179. /* This is a basic worker */
  180. return ntasks[workerid] / starpu_worker_get_relative_speedup(perf_arch);
  181. }
  182. else
  183. {
  184. /* This is a combined worker, the expected end is the end for the latest worker */
  185. int worker_size;
  186. int *combined_workerid;
  187. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  188. int ntasks_end=0;
  189. int i;
  190. for (i = 0; i < worker_size; i++)
  191. {
  192. /* XXX: this is actually bogus: not all pushed tasks are necessarily parallel... */
  193. ntasks_end = STARPU_MAX(ntasks_end, (int) ((double) ntasks[combined_workerid[i]] / starpu_worker_get_relative_speedup(perf_arch)));
  194. }
  195. return ntasks_end;
  196. }
  197. }
  198. static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, unsigned sched_ctx_id)
  199. {
  200. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  201. struct starpu_sched_ctx_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  202. unsigned nworkers_ctx = workers->nworkers;
  203. unsigned worker, worker_ctx = 0;
  204. int best = -1, best_id_ctx = -1;
  205. /* this flag is set if the corresponding worker is selected because
  206. there is no performance prediction available yet */
  207. int forced_best = -1, forced_best_ctx = -1, forced_nimpl = -1;
  208. double local_task_length[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  209. double local_data_penalty[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  210. double local_power[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  211. double local_exp_end[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  212. double fitness[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  213. double max_exp_end = 0.0;
  214. int skip_worker[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  215. double best_exp_end = DBL_MAX;
  216. //double penality_best = 0.0;
  217. int ntasks_best = -1, ntasks_best_ctx = -1, nimpl_best = -1;
  218. double ntasks_best_end = 0.0;
  219. int calibrating = 0;
  220. /* A priori, we know all estimations */
  221. int unknown = 0;
  222. struct starpu_iterator it;
  223. if(workers->init_iterator)
  224. workers->init_iterator(workers, &it);
  225. while(workers->has_next(workers, &it))
  226. {
  227. worker = workers->get_next(workers, &it);
  228. if(!starpu_worker_is_combined_worker(worker))
  229. {
  230. _starpu_pthread_mutex_t *sched_mutex;
  231. _starpu_pthread_cond_t *sched_cond;
  232. starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
  233. /* Sometimes workers didn't take the tasks as early as we expected */
  234. _STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  235. worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], starpu_timing_now());
  236. worker_exp_end[worker] = worker_exp_start[worker] + worker_exp_len[worker];
  237. if (worker_exp_end[worker] > max_exp_end)
  238. max_exp_end = worker_exp_end[worker];
  239. _STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  240. }
  241. }
  242. unsigned nimpl;
  243. worker_ctx = 0;
  244. while(workers->has_next(workers, &it))
  245. {
  246. worker = workers->get_next(workers, &it);
  247. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  248. {
  249. if (!starpu_combined_worker_can_execute_task(worker, task, nimpl))
  250. {
  251. /* no one on that queue may execute this task */
  252. skip_worker[worker_ctx][nimpl] = 1;
  253. continue;
  254. }
  255. else
  256. {
  257. skip_worker[worker_ctx][nimpl] = 0;
  258. }
  259. enum starpu_perf_archtype perf_arch = starpu_worker_get_perf_archtype(worker);
  260. local_task_length[worker_ctx][nimpl] = starpu_task_expected_length(task, perf_arch,nimpl);
  261. unsigned memory_node = starpu_worker_get_memory_node(worker);
  262. local_data_penalty[worker_ctx][nimpl] = starpu_task_expected_data_transfer_time(memory_node, task);
  263. double ntasks_end = compute_ntasks_end(worker);
  264. if (ntasks_best == -1
  265. || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
  266. || (!calibrating && isnan(local_task_length[worker_ctx][nimpl])) /* Not calibrating but this worker is being calibrated */
  267. || (calibrating && isnan(local_task_length[worker_ctx][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
  268. )
  269. {
  270. ntasks_best_end = ntasks_end;
  271. ntasks_best = worker;
  272. ntasks_best_ctx = worker_ctx;
  273. nimpl_best = nimpl;
  274. }
  275. if (isnan(local_task_length[worker_ctx][nimpl]))
  276. /* we are calibrating, we want to speed-up calibration time
  277. * so we privilege non-calibrated tasks (but still
  278. * greedily distribute them to avoid dumb schedules) */
  279. calibrating = 1;
  280. if (isnan(local_task_length[worker_ctx][nimpl])
  281. || _STARPU_IS_ZERO(local_task_length[worker_ctx][nimpl]))
  282. /* there is no prediction available for that task
  283. * with that arch yet, so switch to a greedy strategy */
  284. unknown = 1;
  285. if (unknown)
  286. continue;
  287. local_exp_end[worker_ctx][nimpl] = compute_expected_end(worker, local_task_length[worker_ctx][nimpl]);
  288. //fprintf(stderr, "WORKER %d -> length %e end %e\n", worker, local_task_length[worker_ctx][nimpl], local_exp_end[worker][nimpl]);
  289. if (local_exp_end[worker_ctx][nimpl] < best_exp_end)
  290. {
  291. /* a better solution was found */
  292. best_exp_end = local_exp_end[worker_ctx][nimpl];
  293. nimpl_best = nimpl;
  294. }
  295. local_power[worker_ctx][nimpl] = starpu_task_expected_power(task, perf_arch,nimpl);
  296. //_STARPU_DEBUG("Scheduler parallel heft: task length (%lf) local power (%lf) worker (%u) kernel (%u) \n", local_task_length[worker],local_power[worker],worker,nimpl);
  297. if (isnan(local_power[worker_ctx][nimpl]))
  298. local_power[worker_ctx][nimpl] = 0.;
  299. }
  300. worker_ctx++;
  301. }
  302. if (unknown)
  303. {
  304. forced_best = ntasks_best;
  305. forced_best_ctx = ntasks_best_ctx;
  306. forced_nimpl = nimpl_best;
  307. }
  308. double best_fitness = -1;
  309. if (forced_best == -1)
  310. {
  311. worker_ctx = 0;
  312. while(workers->has_next(workers, &it))
  313. {
  314. worker = workers->get_next(workers, &it);
  315. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  316. {
  317. if (skip_worker[worker_ctx][nimpl])
  318. {
  319. /* no one on that queue may execute this task */
  320. continue;
  321. }
  322. fitness[worker_ctx][nimpl] = hd->alpha*(local_exp_end[worker_ctx][nimpl] - best_exp_end)
  323. + hd->beta*(local_data_penalty[worker_ctx][nimpl])
  324. + hd->_gamma*(local_power[worker_ctx][nimpl]);
  325. if (local_exp_end[worker_ctx][nimpl] > max_exp_end)
  326. /* This placement will make the computation
  327. * longer, take into account the idle
  328. * consumption of other cpus */
  329. fitness[worker_ctx][nimpl] += hd->_gamma * hd->idle_power * (local_exp_end[worker_ctx][nimpl] - max_exp_end) / 1000000.0;
  330. if (best == -1 || fitness[worker_ctx][nimpl] < best_fitness)
  331. {
  332. /* we found a better solution */
  333. best_fitness = fitness[worker_ctx][nimpl];
  334. best = worker;
  335. best_id_ctx = worker_ctx;
  336. nimpl_best = nimpl;
  337. }
  338. // fprintf(stderr, "FITNESS worker %d -> %e local_exp_end %e - local_data_penalty %e\n", worker, fitness[worker][nimpl], local_exp_end[worker][nimpl] - best_exp_end, local_data_penalty[worker][nimpl]);
  339. }
  340. worker_ctx++;
  341. }
  342. }
  343. STARPU_ASSERT(forced_best != -1 || best != -1);
  344. if (forced_best != -1)
  345. {
  346. /* there is no prediction available for that task
  347. * with that arch we want to speed-up calibration time
  348. * so we force this measurement */
  349. best = forced_best;
  350. best_id_ctx = forced_best_ctx;
  351. nimpl_best = forced_nimpl;
  352. //penality_best = 0.0;
  353. best_exp_end = compute_expected_end(best, 0);
  354. }
  355. else
  356. {
  357. //penality_best = local_data_penalty[best_id_ctx][nimpl_best];
  358. best_exp_end = local_exp_end[best_id_ctx][nimpl_best];
  359. }
  360. //_STARPU_DEBUG("Scheduler parallel heft: kernel (%u)\n", nimpl_best);
  361. _starpu_get_job_associated_to_task(task)->nimpl = nimpl_best;
  362. /* we should now have the best worker in variable "best" */
  363. return push_task_on_best_worker(task, best, best_exp_end, prio, sched_ctx_id);
  364. }
  365. static int parallel_heft_push_task(struct starpu_task *task)
  366. {
  367. unsigned sched_ctx_id = task->sched_ctx;
  368. _starpu_pthread_mutex_t *changing_ctx_mutex = starpu_get_changing_ctx_mutex(sched_ctx_id);
  369. unsigned nworkers;
  370. int ret_val = -1;
  371. if (task->priority == STARPU_MAX_PRIO)
  372. {
  373. _STARPU_PTHREAD_MUTEX_LOCK(changing_ctx_mutex);
  374. nworkers = starpu_sched_ctx_get_nworkers(sched_ctx_id);
  375. if(nworkers == 0)
  376. {
  377. _STARPU_PTHREAD_MUTEX_UNLOCK(changing_ctx_mutex);
  378. return ret_val;
  379. }
  380. ret_val = _parallel_heft_push_task(task, 1, sched_ctx_id);
  381. _STARPU_PTHREAD_MUTEX_UNLOCK(changing_ctx_mutex);
  382. return ret_val;
  383. }
  384. _STARPU_PTHREAD_MUTEX_LOCK(changing_ctx_mutex);
  385. nworkers = starpu_sched_ctx_get_nworkers(sched_ctx_id);
  386. if(nworkers == 0)
  387. {
  388. _STARPU_PTHREAD_MUTEX_UNLOCK(changing_ctx_mutex);
  389. return ret_val;
  390. }
  391. ret_val = _parallel_heft_push_task(task, 0, sched_ctx_id);
  392. _STARPU_PTHREAD_MUTEX_UNLOCK(changing_ctx_mutex);
  393. return ret_val;
  394. }
  395. static void parallel_heft_add_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  396. {
  397. int workerid;
  398. unsigned i;
  399. for (i = 0; i < nworkers; i++)
  400. {
  401. workerid = workerids[i];
  402. struct _starpu_worker *workerarg = _starpu_get_worker_struct(workerid);
  403. /* init these structures only once for each worker */
  404. if(!workerarg->has_prev_init)
  405. {
  406. worker_exp_start[workerid] = starpu_timing_now();
  407. worker_exp_len[workerid] = 0.0;
  408. worker_exp_end[workerid] = worker_exp_start[workerid];
  409. ntasks[workerid] = 0;
  410. workerarg->has_prev_init = 1;
  411. }
  412. }
  413. _starpu_sched_find_worker_combinations(workerids, nworkers);
  414. // start_unclear_part: not very clear where this is used
  415. /* struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config(); */
  416. /* ncombinedworkers = config->topology.ncombinedworkers; */
  417. /* /\* We pre-compute an array of all the perfmodel archs that are applicable *\/ */
  418. /* unsigned total_worker_count = nworkers + ncombinedworkers; */
  419. /* unsigned used_perf_archtypes[STARPU_NARCH_VARIATIONS]; */
  420. /* memset(used_perf_archtypes, 0, sizeof(used_perf_archtypes)); */
  421. /* for (workerid = 0; workerid < total_worker_count; workerid++) */
  422. /* { */
  423. /* enum starpu_perf_archtype perf_archtype = starpu_worker_get_perf_archtype(workerid); */
  424. /* used_perf_archtypes[perf_archtype] = 1; */
  425. /* } */
  426. // end_unclear_part
  427. // napplicable_perf_archtypes = 0;
  428. // int arch;
  429. // for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
  430. // {
  431. // if (used_perf_archtypes[arch])
  432. // applicable_perf_archtypes[napplicable_perf_archtypes++] = arch;
  433. // }
  434. }
  435. static void initialize_parallel_heft_policy(unsigned sched_ctx_id)
  436. {
  437. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  438. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)malloc(sizeof(struct _starpu_pheft_data));
  439. hd->alpha = _STARPU_DEFAULT_ALPHA;
  440. hd->beta = _STARPU_DEFAULT_BETA;
  441. hd->_gamma = _STARPU_DEFAULT_GAMMA;
  442. hd->idle_power = 0.0;
  443. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hd);
  444. const char *strval_alpha = getenv("STARPU_SCHED_ALPHA");
  445. if (strval_alpha)
  446. hd->alpha = atof(strval_alpha);
  447. const char *strval_beta = getenv("STARPU_SCHED_BETA");
  448. if (strval_beta)
  449. hd->beta = atof(strval_beta);
  450. const char *strval_gamma = getenv("STARPU_SCHED_GAMMA");
  451. if (strval_gamma)
  452. hd->_gamma = atof(strval_gamma);
  453. const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
  454. if (strval_idle_power)
  455. hd->idle_power = atof(strval_idle_power);
  456. _STARPU_PTHREAD_MUTEX_INIT(&hd->global_push_mutex, NULL);
  457. }
  458. static void parallel_heft_deinit(unsigned sched_ctx_id)
  459. {
  460. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  461. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  462. _STARPU_PTHREAD_MUTEX_DESTROY(&hd->global_push_mutex);
  463. free(hd);
  464. }
  465. /* TODO: use post_exec_hook to fix the expected start */
  466. struct starpu_sched_policy _starpu_sched_parallel_heft_policy =
  467. {
  468. .init_sched = initialize_parallel_heft_policy,
  469. .deinit_sched = parallel_heft_deinit,
  470. .add_workers = parallel_heft_add_workers,
  471. .remove_workers = NULL,
  472. .push_task = parallel_heft_push_task,
  473. .pop_task = NULL,
  474. .pre_exec_hook = parallel_heft_pre_exec_hook,
  475. .post_exec_hook = NULL,
  476. .pop_every_task = NULL,
  477. .policy_name = "pheft",
  478. .policy_description = "parallel HEFT"
  479. };