parallel_heft.c 20 KB

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