parallel_heft.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2015,2017 Inria
  4. * Copyright (C) 2010-2018 Université de Bordeaux
  5. * Copyright (C) 2011-2017 CNRS
  6. * Copyright (C) 2011 Télécom-SudParis
  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. const double now = starpu_timing_now();
  71. if (isnan(model))
  72. model = 0.0;
  73. if (isnan(transfer_model))
  74. transfer_model = 0.0;
  75. /* Once we have executed the task, we can update the predicted amount
  76. * of work. */
  77. _starpu_worker_lock_self();
  78. worker_exp_len[workerid] -= model + transfer_model;
  79. worker_exp_start[workerid] = now + model;
  80. worker_exp_end[workerid] = worker_exp_start[workerid] + worker_exp_len[workerid];
  81. ntasks[workerid]--;
  82. _starpu_worker_unlock_self();
  83. }
  84. static int push_task_on_best_worker(struct starpu_task *task, int best_workerid, double exp_end_predicted, int prio, unsigned sched_ctx_id)
  85. {
  86. /* make sure someone coule execute that task ! */
  87. STARPU_ASSERT(best_workerid != -1);
  88. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  89. if (starpu_get_prefetch_flag())
  90. starpu_prefetch_task_input_for(task, best_workerid);
  91. int ret = 0;
  92. if (!starpu_worker_is_combined_worker(best_workerid))
  93. {
  94. _starpu_worker_lock(best_workerid);
  95. task->predicted = exp_end_predicted - worker_exp_end[best_workerid];
  96. /* TODO */
  97. task->predicted_transfer = 0;
  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_worker_unlock(best_workerid);
  103. /* We don't want it to interlace its task with a combined
  104. * worker's one */
  105. _starpu_worker_relax_on();
  106. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  107. _starpu_worker_relax_off();
  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_worker_relax_on();
  124. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  125. _starpu_worker_relax_off();
  126. /* This is a combined worker so we create task aliases */
  127. int i;
  128. for (i = 0; i < worker_size; i++)
  129. {
  130. struct starpu_task *alias = starpu_task_dup(task);
  131. int local_combined_workerid = combined_workerid[i];
  132. alias->predicted = exp_end_predicted - worker_exp_end[local_combined_workerid];
  133. /* TODO */
  134. alias->predicted_transfer = 0;
  135. alias->destroy = 1;
  136. _starpu_worker_lock(local_combined_workerid);
  137. worker_exp_len[local_combined_workerid] += alias->predicted;
  138. worker_exp_end[local_combined_workerid] = exp_end_predicted;
  139. worker_exp_start[local_combined_workerid] = exp_end_predicted - worker_exp_len[local_combined_workerid];
  140. ntasks[local_combined_workerid]++;
  141. _starpu_worker_unlock(local_combined_workerid);
  142. _STARPU_TRACE_JOB_PUSH(alias, alias->priority > 0);
  143. ret |= starpu_push_local_task(local_combined_workerid, alias, prio);
  144. }
  145. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  146. }
  147. return ret;
  148. }
  149. static double compute_expected_end(int workerid, double length)
  150. {
  151. starpu_pthread_mutex_t *sched_mutex;
  152. starpu_pthread_cond_t *sched_cond;
  153. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  154. if (!starpu_worker_is_combined_worker(workerid))
  155. {
  156. double res;
  157. /* This is a basic worker */
  158. /* Here helgrind would shout that this is unprotected, but we
  159. * are fine with getting outdated values, this is just an
  160. * estimation */
  161. res = worker_exp_start[workerid] + worker_exp_len[workerid] + length;
  162. return res;
  163. }
  164. else
  165. {
  166. /* This is a combined worker, the expected end is the end for the latest worker */
  167. int worker_size;
  168. int *combined_workerid;
  169. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  170. double exp_end = DBL_MIN;
  171. /* Here helgrind would shout that this is unprotected, but we
  172. * are fine with getting outdated values, this is just an
  173. * estimation */
  174. int i;
  175. for (i = 0; i < worker_size; i++)
  176. {
  177. double local_exp_start = worker_exp_start[combined_workerid[i]];
  178. double local_exp_len = worker_exp_len[combined_workerid[i]];
  179. double local_exp_end = local_exp_start + local_exp_len + length;
  180. exp_end = STARPU_MAX(exp_end, local_exp_end);
  181. }
  182. return exp_end;
  183. }
  184. }
  185. static double compute_ntasks_end(int workerid, unsigned sched_ctx_id)
  186. {
  187. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  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. /* Here helgrind would shout that this is unprotected, but we
  196. * are fine with getting outdated values, this is just an
  197. * estimation */
  198. res = ntasks[workerid] / starpu_worker_get_relative_speedup(perf_arch);
  199. return res;
  200. }
  201. else
  202. {
  203. /* This is a combined worker, the expected end is the end for the latest worker */
  204. int worker_size;
  205. int *combined_workerid;
  206. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  207. int ntasks_end=0;
  208. /* Here helgrind would shout that this is unprotected, but we
  209. * are fine with getting outdated values, this is just an
  210. * estimation */
  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. return ntasks_end;
  218. }
  219. }
  220. static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, unsigned sched_ctx_id)
  221. {
  222. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  223. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  224. unsigned nworkers_ctx = workers->nworkers;
  225. unsigned workerid, worker_ctx = 0;
  226. int best = -1, best_id_ctx = -1;
  227. /* this flag is set if the corresponding workerid is selected because
  228. there is no performance prediction available yet */
  229. int forced_best = -1, forced_best_ctx = -1, forced_nimpl = -1;
  230. double local_task_length[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  231. double local_data_penalty[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  232. double local_energy[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  233. double local_exp_end[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  234. double fitness[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  235. double max_exp_end = 0.0;
  236. int skip_worker[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  237. double best_exp_end = DBL_MAX;
  238. //double penality_best = 0.0;
  239. int ntasks_best = -1, ntasks_best_ctx = -1, nimpl_best = -1;
  240. double ntasks_best_end = 0.0;
  241. int calibrating = 0;
  242. /* A priori, we know all estimations */
  243. int unknown = 0;
  244. struct starpu_sched_ctx_iterator it;
  245. double now = starpu_timing_now();
  246. memset(skip_worker, 0, nworkers_ctx*STARPU_MAXIMPLEMENTATIONS*sizeof(int));
  247. workers->init_iterator(workers, &it);
  248. while(workers->has_next(workers, &it))
  249. {
  250. workerid = workers->get_next(workers, &it);
  251. if(!starpu_worker_is_combined_worker(workerid))
  252. {
  253. /* Sometimes workers didn't take the tasks as early as we expected */
  254. _starpu_worker_lock(workerid);
  255. worker_exp_start[workerid] = STARPU_MAX(worker_exp_start[workerid], now);
  256. worker_exp_end[workerid] = worker_exp_start[workerid] + worker_exp_len[workerid];
  257. if (worker_exp_end[workerid] > max_exp_end)
  258. max_exp_end = worker_exp_end[workerid];
  259. _starpu_worker_unlock(workerid);
  260. }
  261. }
  262. unsigned nimpl;
  263. worker_ctx = 0;
  264. while(workers->has_next(workers, &it))
  265. {
  266. workerid = workers->get_next(workers, &it);
  267. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  268. {
  269. if (!starpu_combined_worker_can_execute_task(workerid, task, nimpl))
  270. {
  271. /* no one on that queue may execute this task */
  272. skip_worker[worker_ctx][nimpl] = 1;
  273. continue;
  274. }
  275. else
  276. {
  277. skip_worker[worker_ctx][nimpl] = 0;
  278. }
  279. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  280. local_task_length[worker_ctx][nimpl] = starpu_task_expected_length(task, perf_arch,nimpl);
  281. local_data_penalty[worker_ctx][nimpl] = starpu_task_expected_data_transfer_time_for(task, workerid);
  282. double ntasks_end = compute_ntasks_end(workerid, sched_ctx_id);
  283. if (ntasks_best == -1
  284. || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
  285. || (!calibrating && isnan(local_task_length[worker_ctx][nimpl])) /* Not calibrating but this workerid is being calibrated */
  286. || (calibrating && isnan(local_task_length[worker_ctx][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this workerid with other non-calibrated */
  287. )
  288. {
  289. ntasks_best_end = ntasks_end;
  290. ntasks_best = workerid;
  291. ntasks_best_ctx = worker_ctx;
  292. nimpl_best = nimpl;
  293. }
  294. if (isnan(local_task_length[worker_ctx][nimpl]))
  295. {
  296. static int warned;
  297. if (!warned)
  298. {
  299. warned = 1;
  300. _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);
  301. }
  302. /* we are calibrating, we want to speed-up calibration time
  303. * so we privilege non-calibrated tasks (but still
  304. * greedily distribute them to avoid dumb schedules) */
  305. calibrating = 1;
  306. }
  307. if (isnan(local_task_length[worker_ctx][nimpl])
  308. || _STARPU_IS_ZERO(local_task_length[worker_ctx][nimpl]))
  309. /* there is no prediction available for that task
  310. * with that arch yet, so switch to a greedy strategy */
  311. unknown = 1;
  312. if (unknown)
  313. continue;
  314. local_exp_end[worker_ctx][nimpl] = compute_expected_end(workerid, local_task_length[worker_ctx][nimpl]);
  315. //fprintf(stderr, "WORKER %d -> length %e end %e\n", workerid, local_task_length[worker_ctx][nimpl], local_exp_end[workerid][nimpl]);
  316. if (local_exp_end[worker_ctx][nimpl] < best_exp_end)
  317. {
  318. /* a better solution was found */
  319. best_exp_end = local_exp_end[worker_ctx][nimpl];
  320. nimpl_best = nimpl;
  321. }
  322. local_energy[worker_ctx][nimpl] = starpu_task_expected_energy(task, perf_arch,nimpl);
  323. //_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);
  324. if (isnan(local_energy[worker_ctx][nimpl]))
  325. local_energy[worker_ctx][nimpl] = 0.;
  326. }
  327. worker_ctx++;
  328. }
  329. if (unknown)
  330. {
  331. forced_best = ntasks_best;
  332. forced_best_ctx = ntasks_best_ctx;
  333. forced_nimpl = nimpl_best;
  334. }
  335. if (forced_best == -1)
  336. {
  337. double best_fitness = -1;
  338. worker_ctx = 0;
  339. while(workers->has_next(workers, &it))
  340. {
  341. workerid = workers->get_next(workers, &it);
  342. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  343. {
  344. if (skip_worker[worker_ctx][nimpl])
  345. {
  346. /* no one on that queue may execute this task */
  347. continue;
  348. }
  349. fitness[worker_ctx][nimpl] = hd->alpha*(local_exp_end[worker_ctx][nimpl] - best_exp_end)
  350. + hd->beta*(local_data_penalty[worker_ctx][nimpl])
  351. + hd->_gamma*(local_energy[worker_ctx][nimpl]);
  352. if (local_exp_end[worker_ctx][nimpl] > max_exp_end)
  353. /* This placement will make the computation
  354. * longer, take into account the idle
  355. * consumption of other cpus */
  356. fitness[worker_ctx][nimpl] += hd->_gamma * hd->idle_power * (local_exp_end[worker_ctx][nimpl] - max_exp_end) / 1000000.0;
  357. if (best == -1 || fitness[worker_ctx][nimpl] < best_fitness)
  358. {
  359. /* we found a better solution */
  360. best_fitness = fitness[worker_ctx][nimpl];
  361. best = workerid;
  362. best_id_ctx = worker_ctx;
  363. nimpl_best = nimpl;
  364. }
  365. // 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]);
  366. }
  367. worker_ctx++;
  368. }
  369. }
  370. STARPU_ASSERT(forced_best != -1 || best != -1);
  371. if (forced_best != -1)
  372. {
  373. /* there is no prediction available for that task
  374. * with that arch we want to speed-up calibration time
  375. * so we force this measurement */
  376. best = forced_best;
  377. best_id_ctx = forced_best_ctx;
  378. nimpl_best = forced_nimpl;
  379. //penality_best = 0.0;
  380. best_exp_end = compute_expected_end(best, 0);
  381. }
  382. else
  383. {
  384. //penality_best = local_data_penalty[best_id_ctx][nimpl_best];
  385. best_exp_end = local_exp_end[best_id_ctx][nimpl_best];
  386. }
  387. //_STARPU_DEBUG("Scheduler parallel heft: kernel (%u)\n", nimpl_best);
  388. starpu_task_set_implementation(task, nimpl_best);
  389. /* we should now have the best workerid in variable "best" */
  390. starpu_sched_task_break(task);
  391. return push_task_on_best_worker(task, best, best_exp_end, prio, sched_ctx_id);
  392. }
  393. static int parallel_heft_push_task(struct starpu_task *task)
  394. {
  395. unsigned sched_ctx_id = task->sched_ctx;
  396. int ret_val = -1;
  397. if (task->priority == STARPU_MAX_PRIO)
  398. {
  399. ret_val = _parallel_heft_push_task(task, 1, sched_ctx_id);
  400. return ret_val;
  401. }
  402. ret_val = _parallel_heft_push_task(task, 0, sched_ctx_id);
  403. return ret_val;
  404. }
  405. static void parallel_heft_add_workers(__attribute__((unused)) unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  406. {
  407. unsigned i;
  408. double now = starpu_timing_now();
  409. for (i = 0; i < nworkers; i++)
  410. {
  411. int workerid = workerids[i];
  412. struct _starpu_worker *workerarg = _starpu_get_worker_struct(workerid);
  413. /* init these structures only once for each worker */
  414. if(!workerarg->has_prev_init)
  415. {
  416. worker_exp_start[workerid] = now;
  417. worker_exp_len[workerid] = 0.0;
  418. worker_exp_end[workerid] = worker_exp_start[workerid];
  419. ntasks[workerid] = 0;
  420. workerarg->has_prev_init = 1;
  421. }
  422. }
  423. _starpu_sched_find_worker_combinations(workerids, nworkers);
  424. // start_unclear_part: not very clear where this is used
  425. /* struct _starpu_machine_config *config = _starpu_get_machine_config(); */
  426. /* ncombinedworkers = config->topology.ncombinedworkers; */
  427. /* /\* We pre-compute an array of all the perfmodel archs that are applicable *\/ */
  428. /* unsigned total_worker_count = nworkers + ncombinedworkers; */
  429. /* unsigned used_perf_archtypes[STARPU_NARCH_VARIATIONS]; */
  430. /* memset(used_perf_archtypes, 0, sizeof(used_perf_archtypes)); */
  431. /* for (workerid = 0; workerid < total_worker_count; workerid++) */
  432. /* { */
  433. /* enum starpu_perfmodel_archtype perf_archtype = starpu_worker_get_perf_archtype(workerid); */
  434. /* used_perf_archtypes[perf_archtype] = 1; */
  435. /* } */
  436. // end_unclear_part
  437. // napplicable_perf_archtypes = 0;
  438. // int arch;
  439. // for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
  440. // {
  441. // if (used_perf_archtypes[arch])
  442. // applicable_perf_archtypes[napplicable_perf_archtypes++] = arch;
  443. // }
  444. }
  445. static void initialize_parallel_heft_policy(unsigned sched_ctx_id)
  446. {
  447. struct _starpu_pheft_data *hd;
  448. _STARPU_MALLOC(hd, sizeof(struct _starpu_pheft_data));
  449. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  450. starpu_sched_ctx_set_min_priority(sched_ctx_id, DEFAULT_MIN_PRIORITY);
  451. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  452. starpu_sched_ctx_set_max_priority(sched_ctx_id, DEFAULT_MAX_PRIORITY);
  453. STARPU_ASSERT_MSG(starpu_sched_ctx_get_min_priority(sched_ctx_id) < starpu_sched_ctx_get_max_priority(sched_ctx_id),
  454. "Priority min %d should be lower than priority max %d\n",
  455. starpu_sched_ctx_get_min_priority(sched_ctx_id), starpu_sched_ctx_get_max_priority(sched_ctx_id));
  456. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hd);
  457. hd->alpha = starpu_get_env_float_default("STARPU_SCHED_ALPHA", _STARPU_SCHED_ALPHA_DEFAULT);
  458. hd->beta = starpu_get_env_float_default("STARPU_SCHED_BETA", _STARPU_SCHED_BETA_DEFAULT);
  459. hd->_gamma = starpu_get_env_float_default("STARPU_SCHED_GAMMA", _STARPU_SCHED_GAMMA_DEFAULT);
  460. hd->idle_power = starpu_get_env_float_default("STARPU_IDLE_POWER", 0.0);
  461. STARPU_PTHREAD_MUTEX_INIT(&hd->global_push_mutex, NULL);
  462. /* Tell helgrind that we are fine with getting outdated values when
  463. * estimating schedules */
  464. STARPU_HG_DISABLE_CHECKING(worker_exp_start);
  465. STARPU_HG_DISABLE_CHECKING(worker_exp_end);
  466. STARPU_HG_DISABLE_CHECKING(worker_exp_len);
  467. STARPU_HG_DISABLE_CHECKING(ntasks);
  468. }
  469. static void parallel_heft_deinit(unsigned sched_ctx_id)
  470. {
  471. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  472. STARPU_PTHREAD_MUTEX_DESTROY(&hd->global_push_mutex);
  473. free(hd);
  474. }
  475. /* TODO: use post_exec_hook to fix the expected start */
  476. struct starpu_sched_policy _starpu_sched_parallel_heft_policy =
  477. {
  478. .init_sched = initialize_parallel_heft_policy,
  479. .deinit_sched = parallel_heft_deinit,
  480. .add_workers = parallel_heft_add_workers,
  481. .remove_workers = NULL,
  482. .push_task = parallel_heft_push_task,
  483. .pop_task = NULL,
  484. .pre_exec_hook = parallel_heft_pre_exec_hook,
  485. .post_exec_hook = NULL,
  486. .pop_every_task = NULL,
  487. .policy_name = "pheft",
  488. .policy_description = "parallel HEFT",
  489. .worker_type = STARPU_WORKER_LIST,
  490. };