parallel_heft.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. //static unsigned ncombinedworkers;
  32. //static enum starpu_perfmodel_archtype applicable_perf_archtypes[STARPU_NARCH_VARIATIONS];
  33. //static unsigned napplicable_perf_archtypes = 0;
  34. /*
  35. * Here are the default values of alpha, beta, gamma
  36. */
  37. #define _STARPU_SCHED_ALPHA_DEFAULT 1.0
  38. #define _STARPU_SCHED_BETA_DEFAULT 1.0
  39. #define _STARPU_SCHED_GAMMA_DEFAULT 1000.0
  40. struct _starpu_pheft_data
  41. {
  42. double alpha;
  43. double beta;
  44. double _gamma;
  45. double idle_power;
  46. /* When we push a task on a combined worker we need all the cpu workers it contains
  47. * to be locked at once */
  48. starpu_pthread_mutex_t global_push_mutex;
  49. };
  50. static double worker_exp_start[STARPU_NMAXWORKERS];
  51. static double worker_exp_end[STARPU_NMAXWORKERS];
  52. static double worker_exp_len[STARPU_NMAXWORKERS];
  53. static int ntasks[STARPU_NMAXWORKERS];
  54. /*!!!!!!! It doesn't work with several contexts because the combined workers are constructed
  55. from the workers available to the program, and not to the context !!!!!!!!!!!!!!!!!!!!!!!
  56. */
  57. static void parallel_heft_pre_exec_hook(struct starpu_task *task)
  58. {
  59. if (!task->cl || task->execute_on_a_specific_worker)
  60. return;
  61. int workerid = starpu_worker_get_id();
  62. double model = task->predicted;
  63. double transfer_model = task->predicted_transfer;
  64. if (isnan(model))
  65. model = 0.0;
  66. if (isnan(transfer_model))
  67. transfer_model = 0.0;
  68. starpu_pthread_mutex_t *sched_mutex;
  69. starpu_pthread_cond_t *sched_cond;
  70. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  71. /* Once we have executed the task, we can update the predicted amount
  72. * of work. */
  73. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  74. worker_exp_len[workerid] -= model + transfer_model;
  75. worker_exp_start[workerid] = starpu_timing_now() + model;
  76. worker_exp_end[workerid] = worker_exp_start[workerid] + worker_exp_len[workerid];
  77. ntasks[workerid]--;
  78. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  79. }
  80. static int push_task_on_best_worker(struct starpu_task *task, int best_workerid, double exp_end_predicted, int prio, unsigned sched_ctx_id)
  81. {
  82. /* make sure someone coule execute that task ! */
  83. STARPU_ASSERT(best_workerid != -1);
  84. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  85. /* Is this a basic worker or a combined worker ? */
  86. unsigned memory_node;
  87. memory_node = starpu_worker_get_memory_node(best_workerid);
  88. if (starpu_get_prefetch_flag())
  89. starpu_prefetch_task_input_on_node(task, memory_node);
  90. int ret = 0;
  91. if (!starpu_worker_is_combined_worker(best_workerid))
  92. {
  93. task->predicted = exp_end_predicted - worker_exp_end[best_workerid];
  94. /* TODO */
  95. task->predicted_transfer = 0;
  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. 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_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  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_worker = combined_workerid[i];
  130. alias->predicted = exp_end_predicted - worker_exp_end[local_worker];
  131. /* TODO */
  132. alias->predicted_transfer = 0;
  133. starpu_pthread_mutex_t *sched_mutex;
  134. starpu_pthread_cond_t *sched_cond;
  135. starpu_worker_get_sched_condition(local_worker, &sched_mutex, &sched_cond);
  136. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  137. worker_exp_len[local_worker] += alias->predicted;
  138. worker_exp_end[local_worker] = exp_end_predicted;
  139. worker_exp_start[local_worker] = exp_end_predicted - worker_exp_len[local_worker];
  140. ntasks[local_worker]++;
  141. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  142. ret |= starpu_push_local_task(local_worker, alias, prio);
  143. }
  144. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  145. //TODO : free task
  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. VALGRIND_HG_MUTEX_LOCK_PRE(sched_mutex, 0);
  159. VALGRIND_HG_MUTEX_LOCK_POST(sched_mutex);
  160. res = worker_exp_start[workerid] + worker_exp_len[workerid] + length;
  161. VALGRIND_HG_MUTEX_UNLOCK_PRE(sched_mutex);
  162. VALGRIND_HG_MUTEX_UNLOCK_POST(sched_mutex);
  163. return res;
  164. }
  165. else
  166. {
  167. /* This is a combined worker, the expected end is the end for the latest worker */
  168. int worker_size;
  169. int *combined_workerid;
  170. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  171. double exp_end = DBL_MIN;
  172. VALGRIND_HG_MUTEX_LOCK_PRE(sched_mutex, 0);
  173. VALGRIND_HG_MUTEX_LOCK_POST(sched_mutex);
  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. VALGRIND_HG_MUTEX_UNLOCK_PRE(sched_mutex);
  183. VALGRIND_HG_MUTEX_UNLOCK_POST(sched_mutex);
  184. return exp_end;
  185. }
  186. }
  187. static double compute_ntasks_end(int workerid)
  188. {
  189. enum starpu_perfmodel_archtype perf_arch = starpu_worker_get_perf_archtype(workerid);
  190. starpu_pthread_mutex_t *sched_mutex;
  191. starpu_pthread_cond_t *sched_cond;
  192. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  193. if (!starpu_worker_is_combined_worker(workerid))
  194. {
  195. double res;
  196. /* This is a basic worker */
  197. VALGRIND_HG_MUTEX_LOCK_PRE(sched_mutex, 0);
  198. VALGRIND_HG_MUTEX_LOCK_POST(sched_mutex);
  199. res = ntasks[workerid] / starpu_worker_get_relative_speedup(perf_arch);
  200. VALGRIND_HG_MUTEX_UNLOCK_PRE(sched_mutex);
  201. VALGRIND_HG_MUTEX_UNLOCK_POST(sched_mutex);
  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. VALGRIND_HG_MUTEX_LOCK_PRE(sched_mutex, 0);
  212. VALGRIND_HG_MUTEX_LOCK_POST(sched_mutex);
  213. int i;
  214. for (i = 0; i < worker_size; i++)
  215. {
  216. /* XXX: this is actually bogus: not all pushed tasks are necessarily parallel... */
  217. ntasks_end = STARPU_MAX(ntasks_end, (int) ((double) ntasks[combined_workerid[i]] / starpu_worker_get_relative_speedup(perf_arch)));
  218. }
  219. VALGRIND_HG_MUTEX_UNLOCK_PRE(sched_mutex);
  220. VALGRIND_HG_MUTEX_UNLOCK_POST(sched_mutex);
  221. return ntasks_end;
  222. }
  223. }
  224. static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, unsigned sched_ctx_id)
  225. {
  226. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  227. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  228. unsigned nworkers_ctx = workers->nworkers;
  229. unsigned worker, worker_ctx = 0;
  230. int best = -1, best_id_ctx = -1;
  231. /* this flag is set if the corresponding worker is selected because
  232. there is no performance prediction available yet */
  233. int forced_best = -1, forced_best_ctx = -1, forced_nimpl = -1;
  234. double local_task_length[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  235. double local_data_penalty[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  236. double local_power[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  237. double local_exp_end[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  238. double fitness[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  239. double max_exp_end = 0.0;
  240. int skip_worker[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  241. double best_exp_end = DBL_MAX;
  242. //double penality_best = 0.0;
  243. int ntasks_best = -1, ntasks_best_ctx = -1, nimpl_best = -1;
  244. double ntasks_best_end = 0.0;
  245. int calibrating = 0;
  246. /* A priori, we know all estimations */
  247. int unknown = 0;
  248. struct starpu_sched_ctx_iterator it;
  249. if(workers->init_iterator)
  250. workers->init_iterator(workers, &it);
  251. while(workers->has_next(workers, &it))
  252. {
  253. worker = workers->get_next(workers, &it);
  254. if(!starpu_worker_is_combined_worker(worker))
  255. {
  256. starpu_pthread_mutex_t *sched_mutex;
  257. starpu_pthread_cond_t *sched_cond;
  258. starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
  259. /* Sometimes workers didn't take the tasks as early as we expected */
  260. STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
  261. worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], starpu_timing_now());
  262. worker_exp_end[worker] = worker_exp_start[worker] + worker_exp_len[worker];
  263. if (worker_exp_end[worker] > max_exp_end)
  264. max_exp_end = worker_exp_end[worker];
  265. STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
  266. }
  267. }
  268. unsigned nimpl;
  269. worker_ctx = 0;
  270. while(workers->has_next(workers, &it))
  271. {
  272. worker = workers->get_next(workers, &it);
  273. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  274. {
  275. if (!starpu_combined_worker_can_execute_task(worker, task, nimpl))
  276. {
  277. /* no one on that queue may execute this task */
  278. skip_worker[worker_ctx][nimpl] = 1;
  279. continue;
  280. }
  281. else
  282. {
  283. skip_worker[worker_ctx][nimpl] = 0;
  284. }
  285. enum starpu_perfmodel_archtype perf_arch = starpu_worker_get_perf_archtype(worker);
  286. local_task_length[worker_ctx][nimpl] = starpu_task_expected_length(task, perf_arch,nimpl);
  287. unsigned memory_node = starpu_worker_get_memory_node(worker);
  288. local_data_penalty[worker_ctx][nimpl] = starpu_task_expected_data_transfer_time(memory_node, task);
  289. double ntasks_end = compute_ntasks_end(worker);
  290. if (ntasks_best == -1
  291. || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
  292. || (!calibrating && isnan(local_task_length[worker_ctx][nimpl])) /* Not calibrating but this worker is being calibrated */
  293. || (calibrating && isnan(local_task_length[worker_ctx][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
  294. )
  295. {
  296. ntasks_best_end = ntasks_end;
  297. ntasks_best = worker;
  298. ntasks_best_ctx = worker_ctx;
  299. nimpl_best = nimpl;
  300. }
  301. if (isnan(local_task_length[worker_ctx][nimpl]))
  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. if (isnan(local_task_length[worker_ctx][nimpl])
  307. || _STARPU_IS_ZERO(local_task_length[worker_ctx][nimpl]))
  308. /* there is no prediction available for that task
  309. * with that arch yet, so switch to a greedy strategy */
  310. unknown = 1;
  311. if (unknown)
  312. continue;
  313. local_exp_end[worker_ctx][nimpl] = compute_expected_end(worker, local_task_length[worker_ctx][nimpl]);
  314. //fprintf(stderr, "WORKER %d -> length %e end %e\n", worker, local_task_length[worker_ctx][nimpl], local_exp_end[worker][nimpl]);
  315. if (local_exp_end[worker_ctx][nimpl] < best_exp_end)
  316. {
  317. /* a better solution was found */
  318. best_exp_end = local_exp_end[worker_ctx][nimpl];
  319. nimpl_best = nimpl;
  320. }
  321. local_power[worker_ctx][nimpl] = starpu_task_expected_power(task, perf_arch,nimpl);
  322. //_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);
  323. if (isnan(local_power[worker_ctx][nimpl]))
  324. local_power[worker_ctx][nimpl] = 0.;
  325. }
  326. worker_ctx++;
  327. }
  328. if (unknown)
  329. {
  330. forced_best = ntasks_best;
  331. forced_best_ctx = ntasks_best_ctx;
  332. forced_nimpl = nimpl_best;
  333. }
  334. double best_fitness = -1;
  335. if (forced_best == -1)
  336. {
  337. worker_ctx = 0;
  338. while(workers->has_next(workers, &it))
  339. {
  340. worker = workers->get_next(workers, &it);
  341. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  342. {
  343. if (skip_worker[worker_ctx][nimpl])
  344. {
  345. /* no one on that queue may execute this task */
  346. continue;
  347. }
  348. fitness[worker_ctx][nimpl] = hd->alpha*(local_exp_end[worker_ctx][nimpl] - best_exp_end)
  349. + hd->beta*(local_data_penalty[worker_ctx][nimpl])
  350. + hd->_gamma*(local_power[worker_ctx][nimpl]);
  351. if (local_exp_end[worker_ctx][nimpl] > max_exp_end)
  352. /* This placement will make the computation
  353. * longer, take into account the idle
  354. * consumption of other cpus */
  355. fitness[worker_ctx][nimpl] += hd->_gamma * hd->idle_power * (local_exp_end[worker_ctx][nimpl] - max_exp_end) / 1000000.0;
  356. if (best == -1 || fitness[worker_ctx][nimpl] < best_fitness)
  357. {
  358. /* we found a better solution */
  359. best_fitness = fitness[worker_ctx][nimpl];
  360. best = worker;
  361. best_id_ctx = worker_ctx;
  362. nimpl_best = nimpl;
  363. }
  364. // 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]);
  365. }
  366. worker_ctx++;
  367. }
  368. }
  369. STARPU_ASSERT(forced_best != -1 || best != -1);
  370. if (forced_best != -1)
  371. {
  372. /* there is no prediction available for that task
  373. * with that arch we want to speed-up calibration time
  374. * so we force this measurement */
  375. best = forced_best;
  376. best_id_ctx = forced_best_ctx;
  377. nimpl_best = forced_nimpl;
  378. //penality_best = 0.0;
  379. best_exp_end = compute_expected_end(best, 0);
  380. }
  381. else
  382. {
  383. //penality_best = local_data_penalty[best_id_ctx][nimpl_best];
  384. best_exp_end = local_exp_end[best_id_ctx][nimpl_best];
  385. }
  386. //_STARPU_DEBUG("Scheduler parallel heft: kernel (%u)\n", nimpl_best);
  387. _starpu_get_job_associated_to_task(task)->nimpl = nimpl_best;
  388. /* we should now have the best worker in variable "best" */
  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. int workerid;
  406. unsigned i;
  407. for (i = 0; i < nworkers; i++)
  408. {
  409. 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] = starpu_timing_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 = (struct _starpu_machine_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. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  446. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)malloc(sizeof(struct _starpu_pheft_data));
  447. hd->alpha = _STARPU_SCHED_ALPHA_DEFAULT;
  448. hd->beta = _STARPU_SCHED_BETA_DEFAULT;
  449. hd->_gamma = _STARPU_SCHED_GAMMA_DEFAULT;
  450. hd->idle_power = 0.0;
  451. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hd);
  452. const char *strval_alpha = getenv("STARPU_SCHED_ALPHA");
  453. if (strval_alpha)
  454. hd->alpha = atof(strval_alpha);
  455. const char *strval_beta = getenv("STARPU_SCHED_BETA");
  456. if (strval_beta)
  457. hd->beta = atof(strval_beta);
  458. const char *strval_gamma = getenv("STARPU_SCHED_GAMMA");
  459. if (strval_gamma)
  460. hd->_gamma = atof(strval_gamma);
  461. const char *strval_idle_power = getenv("STARPU_IDLE_POWER");
  462. if (strval_idle_power)
  463. hd->idle_power = atof(strval_idle_power);
  464. STARPU_PTHREAD_MUTEX_INIT(&hd->global_push_mutex, NULL);
  465. }
  466. static void parallel_heft_deinit(unsigned sched_ctx_id)
  467. {
  468. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  469. starpu_sched_ctx_delete_worker_collection(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. };