parallel_heft.c 19 KB

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