parallel_heft.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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 <core/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. /* if no priority is set when creating the scheduling context, we use the following ones */
  32. #define DEFAULT_MIN_PRIORITY 0
  33. #define DEFAULT_MAX_PRIORITY 1
  34. //static unsigned ncombinedworkers;
  35. //static enum starpu_perfmodel_archtype applicable_perf_archtypes[STARPU_NARCH_VARIATIONS];
  36. //static unsigned napplicable_perf_archtypes = 0;
  37. /*
  38. * Here are the default values of alpha, beta, gamma
  39. */
  40. #define _STARPU_SCHED_ALPHA_DEFAULT 1.0
  41. #define _STARPU_SCHED_BETA_DEFAULT 1.0
  42. #define _STARPU_SCHED_GAMMA_DEFAULT 1000.0
  43. struct _starpu_pheft_data
  44. {
  45. double alpha;
  46. double beta;
  47. double _gamma;
  48. double idle_power;
  49. /* When we push a task on a combined worker we need all the cpu workers it contains
  50. * to be locked at once */
  51. starpu_pthread_mutex_t global_push_mutex;
  52. };
  53. static double worker_exp_start[STARPU_NMAXWORKERS];
  54. static double worker_exp_end[STARPU_NMAXWORKERS];
  55. static double worker_exp_len[STARPU_NMAXWORKERS];
  56. static int ntasks[STARPU_NMAXWORKERS];
  57. /*!!!!!!! It doesn't work with several contexts because the combined workers are constructed
  58. from the workers available to the program, and not to the context !!!!!!!!!!!!!!!!!!!!!!!
  59. */
  60. static void parallel_heft_pre_exec_hook(struct starpu_task *task)
  61. {
  62. if (!task->cl || task->execute_on_a_specific_worker)
  63. return;
  64. int workerid = starpu_worker_get_id();
  65. double model = task->predicted;
  66. double transfer_model = task->predicted_transfer;
  67. if (isnan(model))
  68. model = 0.0;
  69. if (isnan(transfer_model))
  70. transfer_model = 0.0;
  71. starpu_pthread_mutex_t *sched_mutex;
  72. starpu_pthread_cond_t *sched_cond;
  73. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  74. /* Once we have executed the task, we can update the predicted amount
  75. * of work. */
  76. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  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_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  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_pthread_mutex_t *sched_mutex;
  97. starpu_pthread_cond_t *sched_cond;
  98. starpu_worker_get_sched_condition(best_workerid, &sched_mutex, &sched_cond);
  99. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  100. task->predicted = exp_end_predicted - worker_exp_end[best_workerid];
  101. /* TODO */
  102. task->predicted_transfer = 0;
  103. worker_exp_len[best_workerid] += task->predicted;
  104. worker_exp_end[best_workerid] = exp_end_predicted;
  105. worker_exp_start[best_workerid] = exp_end_predicted - worker_exp_len[best_workerid];
  106. ntasks[best_workerid]++;
  107. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  108. /* We don't want it to interlace its task with a combined
  109. * worker's one */
  110. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  111. ret = starpu_push_local_task(best_workerid, task, prio);
  112. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  113. }
  114. else
  115. {
  116. /* This task doesn't belong to an actual worker, it belongs
  117. * to a combined worker and thus the scheduler doesn't care
  118. * of its predicted values which are insignificant */
  119. task->predicted = 0;
  120. task->predicted_transfer = 0;
  121. starpu_parallel_task_barrier_init(task, best_workerid);
  122. int worker_size = 0;
  123. int *combined_workerid;
  124. starpu_combined_worker_get_description(best_workerid, &worker_size, &combined_workerid);
  125. /* All cpu workers must be locked at once */
  126. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  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_worker = combined_workerid[i];
  133. alias->predicted = exp_end_predicted - worker_exp_end[local_worker];
  134. /* TODO */
  135. alias->predicted_transfer = 0;
  136. starpu_pthread_mutex_t *sched_mutex;
  137. starpu_pthread_cond_t *sched_cond;
  138. starpu_worker_get_sched_condition(local_worker, &sched_mutex, &sched_cond);
  139. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  140. worker_exp_len[local_worker] += alias->predicted;
  141. worker_exp_end[local_worker] = exp_end_predicted;
  142. worker_exp_start[local_worker] = exp_end_predicted - worker_exp_len[local_worker];
  143. ntasks[local_worker]++;
  144. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  145. ret |= starpu_push_local_task(local_worker, alias, prio);
  146. }
  147. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  148. //TODO : free task
  149. }
  150. return ret;
  151. }
  152. static double compute_expected_end(int workerid, double length)
  153. {
  154. starpu_pthread_mutex_t *sched_mutex;
  155. starpu_pthread_cond_t *sched_cond;
  156. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  157. if (!starpu_worker_is_combined_worker(workerid))
  158. {
  159. double res;
  160. /* This is a basic worker */
  161. /* Here helgrind would shout that this is unprotected, but we
  162. * are fine with getting outdated values, this is just an
  163. * estimation */
  164. res = worker_exp_start[workerid] + worker_exp_len[workerid] + length;
  165. return res;
  166. }
  167. else
  168. {
  169. /* This is a combined worker, the expected end is the end for the latest worker */
  170. int worker_size;
  171. int *combined_workerid;
  172. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  173. double exp_end = DBL_MIN;
  174. /* Here helgrind would shout that this is unprotected, but we
  175. * are fine with getting outdated values, this is just an
  176. * estimation */
  177. int i;
  178. for (i = 0; i < worker_size; i++)
  179. {
  180. double local_exp_start = worker_exp_start[combined_workerid[i]];
  181. double local_exp_len = worker_exp_len[combined_workerid[i]];
  182. double local_exp_end = local_exp_start + local_exp_len + length;
  183. exp_end = STARPU_MAX(exp_end, local_exp_end);
  184. }
  185. return exp_end;
  186. }
  187. }
  188. static double compute_ntasks_end(int workerid, unsigned sched_ctx_id)
  189. {
  190. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  191. starpu_pthread_mutex_t *sched_mutex;
  192. starpu_pthread_cond_t *sched_cond;
  193. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  194. if (!starpu_worker_is_combined_worker(workerid))
  195. {
  196. double res;
  197. /* This is a basic worker */
  198. /* Here helgrind would shout that this is unprotected, but we
  199. * are fine with getting outdated values, this is just an
  200. * estimation */
  201. res = ntasks[workerid] / starpu_worker_get_relative_speedup(perf_arch);
  202. return res;
  203. }
  204. else
  205. {
  206. /* This is a combined worker, the expected end is the end for the latest worker */
  207. int worker_size;
  208. int *combined_workerid;
  209. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  210. int ntasks_end=0;
  211. /* Here helgrind would shout that this is unprotected, but we
  212. * are fine with getting outdated values, this is just an
  213. * estimation */
  214. int i;
  215. for (i = 0; i < worker_size; i++)
  216. {
  217. /* XXX: this is actually bogus: not all pushed tasks are necessarily parallel... */
  218. ntasks_end = STARPU_MAX(ntasks_end, (int) ((double) ntasks[combined_workerid[i]] / starpu_worker_get_relative_speedup(perf_arch)));
  219. }
  220. return ntasks_end;
  221. }
  222. }
  223. static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, unsigned sched_ctx_id)
  224. {
  225. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  226. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  227. unsigned nworkers_ctx = workers->nworkers;
  228. unsigned worker, worker_ctx = 0;
  229. int best = -1, best_id_ctx = -1;
  230. /* this flag is set if the corresponding worker is selected because
  231. there is no performance prediction available yet */
  232. int forced_best = -1, forced_best_ctx = -1, forced_nimpl = -1;
  233. double local_task_length[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  234. double local_data_penalty[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  235. double local_power[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  236. double local_exp_end[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  237. double fitness[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  238. double max_exp_end = 0.0;
  239. int skip_worker[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  240. double best_exp_end = DBL_MAX;
  241. //double penality_best = 0.0;
  242. int ntasks_best = -1, ntasks_best_ctx = -1, nimpl_best = -1;
  243. double ntasks_best_end = 0.0;
  244. int calibrating = 0;
  245. /* A priori, we know all estimations */
  246. int unknown = 0;
  247. struct starpu_sched_ctx_iterator it;
  248. if(workers->init_iterator)
  249. workers->init_iterator(workers, &it);
  250. while(workers->has_next(workers, &it))
  251. {
  252. worker = workers->get_next(workers, &it);
  253. if(!starpu_worker_is_combined_worker(worker))
  254. {
  255. starpu_pthread_mutex_t *sched_mutex;
  256. starpu_pthread_cond_t *sched_cond;
  257. starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
  258. /* Sometimes workers didn't take the tasks as early as we expected */
  259. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  260. worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], starpu_timing_now());
  261. worker_exp_end[worker] = worker_exp_start[worker] + worker_exp_len[worker];
  262. if (worker_exp_end[worker] > max_exp_end)
  263. max_exp_end = worker_exp_end[worker];
  264. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  265. }
  266. }
  267. unsigned nimpl;
  268. worker_ctx = 0;
  269. while(workers->has_next(workers, &it))
  270. {
  271. worker = workers->get_next(workers, &it);
  272. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  273. {
  274. if (!starpu_combined_worker_can_execute_task(worker, task, nimpl))
  275. {
  276. /* no one on that queue may execute this task */
  277. skip_worker[worker_ctx][nimpl] = 1;
  278. continue;
  279. }
  280. else
  281. {
  282. skip_worker[worker_ctx][nimpl] = 0;
  283. }
  284. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(worker, sched_ctx_id);
  285. local_task_length[worker_ctx][nimpl] = starpu_task_expected_length(task, perf_arch,nimpl);
  286. unsigned memory_node = starpu_worker_get_memory_node(worker);
  287. local_data_penalty[worker_ctx][nimpl] = starpu_task_expected_data_transfer_time(memory_node, task);
  288. double ntasks_end = compute_ntasks_end(worker, sched_ctx_id);
  289. if (ntasks_best == -1
  290. || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
  291. || (!calibrating && isnan(local_task_length[worker_ctx][nimpl])) /* Not calibrating but this worker is being calibrated */
  292. || (calibrating && isnan(local_task_length[worker_ctx][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
  293. )
  294. {
  295. ntasks_best_end = ntasks_end;
  296. ntasks_best = worker;
  297. ntasks_best_ctx = worker_ctx;
  298. nimpl_best = nimpl;
  299. }
  300. if (isnan(local_task_length[worker_ctx][nimpl]))
  301. /* we are calibrating, we want to speed-up calibration time
  302. * so we privilege non-calibrated tasks (but still
  303. * greedily distribute them to avoid dumb schedules) */
  304. calibrating = 1;
  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(worker, local_task_length[worker_ctx][nimpl]);
  313. //fprintf(stderr, "WORKER %d -> length %e end %e\n", worker, local_task_length[worker_ctx][nimpl], local_exp_end[worker][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_power[worker_ctx][nimpl] = starpu_task_expected_power(task, perf_arch,nimpl);
  321. //_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);
  322. if (isnan(local_power[worker_ctx][nimpl]))
  323. local_power[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. double best_fitness = -1;
  334. if (forced_best == -1)
  335. {
  336. worker_ctx = 0;
  337. while(workers->has_next(workers, &it))
  338. {
  339. worker = 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_power[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 = worker;
  360. best_id_ctx = worker_ctx;
  361. nimpl_best = nimpl;
  362. }
  363. // 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]);
  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_get_job_associated_to_task(task)->nimpl = nimpl_best;
  387. /* we should now have the best worker in variable "best" */
  388. return push_task_on_best_worker(task, best, best_exp_end, prio, sched_ctx_id);
  389. }
  390. static int parallel_heft_push_task(struct starpu_task *task)
  391. {
  392. unsigned sched_ctx_id = task->sched_ctx;
  393. int ret_val = -1;
  394. if (task->priority == STARPU_MAX_PRIO)
  395. {
  396. ret_val = _parallel_heft_push_task(task, 1, sched_ctx_id);
  397. return ret_val;
  398. }
  399. ret_val = _parallel_heft_push_task(task, 0, sched_ctx_id);
  400. return ret_val;
  401. }
  402. static void parallel_heft_add_workers(__attribute__((unused)) unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  403. {
  404. int workerid;
  405. unsigned i;
  406. for (i = 0; i < nworkers; i++)
  407. {
  408. workerid = workerids[i];
  409. struct _starpu_worker *workerarg = _starpu_get_worker_struct(workerid);
  410. /* init these structures only once for each worker */
  411. if(!workerarg->has_prev_init)
  412. {
  413. worker_exp_start[workerid] = starpu_timing_now();
  414. worker_exp_len[workerid] = 0.0;
  415. worker_exp_end[workerid] = worker_exp_start[workerid];
  416. ntasks[workerid] = 0;
  417. workerarg->has_prev_init = 1;
  418. }
  419. }
  420. _starpu_sched_find_worker_combinations(workerids, nworkers);
  421. // start_unclear_part: not very clear where this is used
  422. /* struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config(); */
  423. /* ncombinedworkers = config->topology.ncombinedworkers; */
  424. /* /\* We pre-compute an array of all the perfmodel archs that are applicable *\/ */
  425. /* unsigned total_worker_count = nworkers + ncombinedworkers; */
  426. /* unsigned used_perf_archtypes[STARPU_NARCH_VARIATIONS]; */
  427. /* memset(used_perf_archtypes, 0, sizeof(used_perf_archtypes)); */
  428. /* for (workerid = 0; workerid < total_worker_count; workerid++) */
  429. /* { */
  430. /* enum starpu_perfmodel_archtype perf_archtype = starpu_worker_get_perf_archtype(workerid); */
  431. /* used_perf_archtypes[perf_archtype] = 1; */
  432. /* } */
  433. // end_unclear_part
  434. // napplicable_perf_archtypes = 0;
  435. // int arch;
  436. // for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
  437. // {
  438. // if (used_perf_archtypes[arch])
  439. // applicable_perf_archtypes[napplicable_perf_archtypes++] = arch;
  440. // }
  441. }
  442. static void initialize_parallel_heft_policy(unsigned sched_ctx_id)
  443. {
  444. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  445. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)malloc(sizeof(struct _starpu_pheft_data));
  446. hd->alpha = _STARPU_SCHED_ALPHA_DEFAULT;
  447. hd->beta = _STARPU_SCHED_BETA_DEFAULT;
  448. hd->_gamma = _STARPU_SCHED_GAMMA_DEFAULT;
  449. hd->idle_power = 0.0;
  450. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  451. starpu_sched_ctx_set_min_priority(sched_ctx_id, DEFAULT_MIN_PRIORITY);
  452. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  453. starpu_sched_ctx_set_max_priority(sched_ctx_id, DEFAULT_MAX_PRIORITY);
  454. STARPU_ASSERT_MSG(starpu_sched_ctx_get_min_priority(sched_ctx_id) < starpu_sched_ctx_get_max_priority(sched_ctx_id),
  455. "Priority min %d should be lower than priority max %d\n",
  456. starpu_sched_ctx_get_min_priority(sched_ctx_id), starpu_sched_ctx_get_max_priority(sched_ctx_id));
  457. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hd);
  458. const char *strval_alpha = getenv("STARPU_SCHED_ALPHA");
  459. if (strval_alpha)
  460. hd->alpha = atof(strval_alpha);
  461. const char *strval_beta = getenv("STARPU_SCHED_BETA");
  462. if (strval_beta)
  463. hd->beta = atof(strval_beta);
  464. const char *strval_gamma = getenv("STARPU_SCHED_GAMMA");
  465. if (strval_gamma)
  466. hd->_gamma = atof(strval_gamma);
  467. const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
  468. if (strval_idle_power)
  469. hd->idle_power = atof(strval_idle_power);
  470. STARPU_PTHREAD_MUTEX_INIT(&hd->global_push_mutex, NULL);
  471. /* Tell helgrind that we are fine with getting outdated values when
  472. * estimating schedules */
  473. STARPU_HG_DISABLE_CHECKING(worker_exp_start);
  474. STARPU_HG_DISABLE_CHECKING(worker_exp_len);
  475. STARPU_HG_DISABLE_CHECKING(ntasks);
  476. }
  477. static void parallel_heft_deinit(unsigned sched_ctx_id)
  478. {
  479. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  480. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  481. STARPU_PTHREAD_MUTEX_DESTROY(&hd->global_push_mutex);
  482. free(hd);
  483. }
  484. /* TODO: use post_exec_hook to fix the expected start */
  485. struct starpu_sched_policy _starpu_sched_parallel_heft_policy =
  486. {
  487. .init_sched = initialize_parallel_heft_policy,
  488. .deinit_sched = parallel_heft_deinit,
  489. .add_workers = parallel_heft_add_workers,
  490. .remove_workers = NULL,
  491. .push_task = parallel_heft_push_task,
  492. .pop_task = NULL,
  493. .pre_exec_hook = parallel_heft_pre_exec_hook,
  494. .post_exec_hook = NULL,
  495. .pop_every_task = NULL,
  496. .policy_name = "pheft",
  497. .policy_description = "parallel HEFT"
  498. };