parallel_heft.c 19 KB

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