sched_policy.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2017 Université de Bordeaux
  4. * Copyright (C) 2010-2017 CNRS
  5. * Copyright (C) 2011, 2016-2017 INRIA
  6. * Copyright (C) 2016 Uppsala University
  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. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <common/utils.h>
  22. #include <core/sched_policy.h>
  23. #include <profiling/profiling.h>
  24. #include <common/barrier.h>
  25. #include <core/debug.h>
  26. #include <core/task.h>
  27. static int use_prefetch = 0;
  28. static double idle[STARPU_NMAXWORKERS];
  29. static double idle_start[STARPU_NMAXWORKERS];
  30. long _starpu_task_break_on_push = -1;
  31. long _starpu_task_break_on_sched = -1;
  32. long _starpu_task_break_on_pop = -1;
  33. long _starpu_task_break_on_exec = -1;
  34. static const char *starpu_idle_file;
  35. void _starpu_sched_init(void)
  36. {
  37. _starpu_task_break_on_push = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_PUSH", -1);
  38. _starpu_task_break_on_sched = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_SCHED", -1);
  39. _starpu_task_break_on_pop = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_POP", -1);
  40. _starpu_task_break_on_exec = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_EXEC", -1);
  41. starpu_idle_file = starpu_getenv("STARPU_IDLE_FILE");
  42. }
  43. int starpu_get_prefetch_flag(void)
  44. {
  45. return use_prefetch;
  46. }
  47. static struct starpu_sched_policy *predefined_policies[] =
  48. {
  49. &_starpu_sched_modular_eager_policy,
  50. &_starpu_sched_modular_eager_prefetching_policy,
  51. &_starpu_sched_modular_prio_policy,
  52. &_starpu_sched_modular_prio_prefetching_policy,
  53. &_starpu_sched_modular_random_policy,
  54. &_starpu_sched_modular_random_prio_policy,
  55. &_starpu_sched_modular_random_prefetching_policy,
  56. &_starpu_sched_modular_random_prio_prefetching_policy,
  57. &_starpu_sched_modular_ws_policy,
  58. &_starpu_sched_modular_heft_policy,
  59. &_starpu_sched_modular_heft_prio_policy,
  60. &_starpu_sched_modular_heft2_policy,
  61. &_starpu_sched_eager_policy,
  62. &_starpu_sched_prio_policy,
  63. &_starpu_sched_random_policy,
  64. &_starpu_sched_lws_policy,
  65. &_starpu_sched_ws_policy,
  66. &_starpu_sched_dm_policy,
  67. &_starpu_sched_dmda_policy,
  68. &_starpu_sched_dmda_ready_policy,
  69. &_starpu_sched_dmda_sorted_policy,
  70. &_starpu_sched_dmda_sorted_decision_policy,
  71. &_starpu_sched_parallel_heft_policy,
  72. &_starpu_sched_peager_policy,
  73. &_starpu_sched_heteroprio_policy,
  74. &_starpu_sched_graph_test_policy,
  75. NULL
  76. };
  77. struct starpu_sched_policy **starpu_sched_get_predefined_policies()
  78. {
  79. return predefined_policies;
  80. }
  81. struct starpu_sched_policy *_starpu_get_sched_policy(struct _starpu_sched_ctx *sched_ctx)
  82. {
  83. return sched_ctx->sched_policy;
  84. }
  85. /*
  86. * Methods to initialize the scheduling policy
  87. */
  88. static void load_sched_policy(struct starpu_sched_policy *sched_policy, struct _starpu_sched_ctx *sched_ctx)
  89. {
  90. STARPU_ASSERT(sched_policy);
  91. #ifdef STARPU_VERBOSE
  92. if (sched_policy->policy_name)
  93. {
  94. if (sched_policy->policy_description)
  95. _STARPU_DEBUG("Use %s scheduler (%s)\n", sched_policy->policy_name, sched_policy->policy_description);
  96. else
  97. _STARPU_DEBUG("Use %s scheduler \n", sched_policy->policy_name);
  98. }
  99. #endif
  100. struct starpu_sched_policy *policy = sched_ctx->sched_policy;
  101. memcpy(policy, sched_policy, sizeof(*policy));
  102. }
  103. static struct starpu_sched_policy *find_sched_policy_from_name(const char *policy_name)
  104. {
  105. if (!policy_name)
  106. return NULL;
  107. if (strcmp(policy_name, "") == 0)
  108. return NULL;
  109. if (strncmp(policy_name, "heft", 4) == 0)
  110. {
  111. _STARPU_MSG("Warning: heft is now called \"dmda\".\n");
  112. return &_starpu_sched_dmda_policy;
  113. }
  114. struct starpu_sched_policy **policy;
  115. for(policy=predefined_policies ; *policy!=NULL ; policy++)
  116. {
  117. struct starpu_sched_policy *p = *policy;
  118. if (p->policy_name)
  119. {
  120. if (strcmp(policy_name, p->policy_name) == 0)
  121. {
  122. /* we found a policy with the requested name */
  123. return p;
  124. }
  125. }
  126. }
  127. if (strcmp(policy_name, "help") != 0)
  128. _STARPU_MSG("Warning: scheduling policy '%s' was not found, try 'help' to get a list\n", policy_name);
  129. /* nothing was found */
  130. return NULL;
  131. }
  132. static void display_sched_help_message(FILE *stream)
  133. {
  134. const char *sched_env = starpu_getenv("STARPU_SCHED");
  135. if (sched_env && (strcmp(sched_env, "help") == 0))
  136. {
  137. /* display the description of all predefined policies */
  138. struct starpu_sched_policy **policy;
  139. fprintf(stream, "\nThe variable STARPU_SCHED can be set to one of the following strings:\n");
  140. for(policy=predefined_policies ; *policy!=NULL ; policy++)
  141. {
  142. struct starpu_sched_policy *p = *policy;
  143. fprintf(stream, "%-30s\t-> %s\n", p->policy_name, p->policy_description);
  144. }
  145. fprintf(stream, "\n");
  146. }
  147. }
  148. struct starpu_sched_policy *_starpu_select_sched_policy(struct _starpu_machine_config *config, const char *required_policy)
  149. {
  150. struct starpu_sched_policy *selected_policy = NULL;
  151. struct starpu_conf *user_conf = &config->conf;
  152. if(required_policy)
  153. selected_policy = find_sched_policy_from_name(required_policy);
  154. /* If there is a policy that matches the required name, return it */
  155. if (selected_policy)
  156. return selected_policy;
  157. /* First, we check whether the application explicitely gave a scheduling policy or not */
  158. if (user_conf && (user_conf->sched_policy))
  159. return user_conf->sched_policy;
  160. /* Otherwise, we look if the application specified the name of a policy to load */
  161. const char *sched_pol_name;
  162. sched_pol_name = starpu_getenv("STARPU_SCHED");
  163. if (sched_pol_name == NULL && user_conf && user_conf->sched_policy_name)
  164. sched_pol_name = user_conf->sched_policy_name;
  165. if (sched_pol_name)
  166. selected_policy = find_sched_policy_from_name(sched_pol_name);
  167. /* If there is a policy that matches the name, return it */
  168. if (selected_policy)
  169. return selected_policy;
  170. /* If no policy was specified, we use the eager policy by default */
  171. return &_starpu_sched_eager_policy;
  172. }
  173. void _starpu_init_sched_policy(struct _starpu_machine_config *config, struct _starpu_sched_ctx *sched_ctx, struct starpu_sched_policy *selected_policy)
  174. {
  175. /* Perhaps we have to display some help */
  176. display_sched_help_message(stderr);
  177. /* Prefetch is activated by default */
  178. use_prefetch = starpu_get_env_number("STARPU_PREFETCH");
  179. if (use_prefetch == -1)
  180. use_prefetch = 1;
  181. /* Set calibrate flag */
  182. _starpu_set_calibrate_flag(config->conf.calibrate);
  183. load_sched_policy(selected_policy, sched_ctx);
  184. if (starpu_get_env_number_default("STARPU_WORKER_TREE", 0))
  185. {
  186. #ifdef STARPU_HAVE_HWLOC
  187. sched_ctx->sched_policy->worker_type = STARPU_WORKER_TREE;
  188. #else
  189. _STARPU_DISP("STARPU_WORKER_TREE ignored, please rebuild StarPU with hwloc support to enable it.");
  190. #endif
  191. }
  192. starpu_sched_ctx_create_worker_collection(sched_ctx->id,
  193. sched_ctx->sched_policy->worker_type);
  194. _STARPU_SCHED_BEGIN;
  195. sched_ctx->sched_policy->init_sched(sched_ctx->id);
  196. _STARPU_SCHED_END;
  197. }
  198. void _starpu_deinit_sched_policy(struct _starpu_sched_ctx *sched_ctx)
  199. {
  200. struct starpu_sched_policy *policy = sched_ctx->sched_policy;
  201. if (policy->deinit_sched)
  202. {
  203. _STARPU_SCHED_BEGIN;
  204. policy->deinit_sched(sched_ctx->id);
  205. _STARPU_SCHED_END;
  206. }
  207. starpu_sched_ctx_delete_worker_collection(sched_ctx->id);
  208. }
  209. void _starpu_sched_task_submit(struct starpu_task *task)
  210. {
  211. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  212. if (!sched_ctx->sched_policy)
  213. return;
  214. if (!sched_ctx->sched_policy->submit_hook)
  215. return;
  216. _STARPU_SCHED_BEGIN;
  217. sched_ctx->sched_policy->submit_hook(task);
  218. _STARPU_SCHED_END;
  219. }
  220. void _starpu_sched_do_schedule(unsigned sched_ctx_id)
  221. {
  222. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  223. if (!sched_ctx->sched_policy)
  224. return;
  225. if (!sched_ctx->sched_policy->do_schedule)
  226. return;
  227. _STARPU_SCHED_BEGIN;
  228. sched_ctx->sched_policy->do_schedule(sched_ctx_id);
  229. _STARPU_SCHED_END;
  230. }
  231. static void _starpu_push_task_on_specific_worker_notify_sched(struct starpu_task *task, struct _starpu_worker *worker, int workerid, int perf_workerid)
  232. {
  233. /* if we push a task on a specific worker, notify all the sched_ctxs the worker belongs to */
  234. struct _starpu_sched_ctx_list_iterator list_it;
  235. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  236. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  237. {
  238. struct _starpu_sched_ctx_elt *e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  239. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  240. if (sched_ctx->sched_policy != NULL && sched_ctx->sched_policy->push_task_notify)
  241. {
  242. _STARPU_SCHED_BEGIN;
  243. sched_ctx->sched_policy->push_task_notify(task, workerid, perf_workerid, sched_ctx->id);
  244. _STARPU_SCHED_END;
  245. }
  246. }
  247. }
  248. /* Enqueue a task into the list of tasks explicitely attached to a worker. In
  249. * case workerid identifies a combined worker, a task will be enqueued into
  250. * each worker of the combination. */
  251. static int _starpu_push_task_on_specific_worker(struct starpu_task *task, int workerid)
  252. {
  253. int nbasic_workers = (int)starpu_worker_get_count();
  254. /* Is this a basic worker or a combined worker ? */
  255. int is_basic_worker = (workerid < nbasic_workers);
  256. unsigned memory_node;
  257. struct _starpu_worker *worker = NULL;
  258. struct _starpu_combined_worker *combined_worker = NULL;
  259. if (is_basic_worker)
  260. {
  261. worker = _starpu_get_worker_struct(workerid);
  262. memory_node = worker->memory_node;
  263. }
  264. else
  265. {
  266. combined_worker = _starpu_get_combined_worker_struct(workerid);
  267. memory_node = combined_worker->memory_node;
  268. }
  269. if (use_prefetch)
  270. starpu_prefetch_task_input_on_node(task, memory_node);
  271. if (is_basic_worker)
  272. _starpu_push_task_on_specific_worker_notify_sched(task, worker, workerid, workerid);
  273. else
  274. {
  275. /* Notify all workers of the combined worker */
  276. int worker_size = combined_worker->worker_size;
  277. int *combined_workerid = combined_worker->combined_workerid;
  278. int j;
  279. for (j = 0; j < worker_size; j++)
  280. {
  281. int subworkerid = combined_workerid[j];
  282. _starpu_push_task_on_specific_worker_notify_sched(task, _starpu_get_worker_struct(subworkerid), subworkerid, workerid);
  283. }
  284. }
  285. #ifdef STARPU_USE_SC_HYPERVISOR
  286. starpu_sched_ctx_call_pushed_task_cb(workerid, task->sched_ctx);
  287. #endif //STARPU_USE_SC_HYPERVISOR
  288. if (is_basic_worker)
  289. {
  290. unsigned node = starpu_worker_get_memory_node(workerid);
  291. if (_starpu_task_uses_multiformat_handles(task))
  292. {
  293. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  294. unsigned i;
  295. for (i = 0; i < nbuffers; i++)
  296. {
  297. struct starpu_task *conversion_task;
  298. starpu_data_handle_t handle;
  299. handle = STARPU_TASK_GET_HANDLE(task, i);
  300. if (!_starpu_handle_needs_conversion_task(handle, node))
  301. continue;
  302. conversion_task = _starpu_create_conversion_task(handle, node);
  303. conversion_task->mf_skip = 1;
  304. conversion_task->execute_on_a_specific_worker = 1;
  305. conversion_task->workerid = workerid;
  306. _starpu_task_submit_conversion_task(conversion_task, workerid);
  307. //_STARPU_DEBUG("Pushing a conversion task\n");
  308. }
  309. for (i = 0; i < nbuffers; i++)
  310. {
  311. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  312. handle->mf_node = node;
  313. }
  314. }
  315. // if(task->sched_ctx != _starpu_get_initial_sched_ctx()->id)
  316. if(task->priority > 0)
  317. return _starpu_push_local_task(worker, task, 1);
  318. else
  319. return _starpu_push_local_task(worker, task, 0);
  320. }
  321. else
  322. {
  323. /* This is a combined worker so we create task aliases */
  324. int worker_size = combined_worker->worker_size;
  325. int *combined_workerid = combined_worker->combined_workerid;
  326. int ret = 0;
  327. struct _starpu_job *job = _starpu_get_job_associated_to_task(task);
  328. job->task_size = worker_size;
  329. job->combined_workerid = workerid;
  330. job->active_task_alias_count = 0;
  331. STARPU_PTHREAD_BARRIER_INIT(&job->before_work_barrier, NULL, worker_size);
  332. STARPU_PTHREAD_BARRIER_INIT(&job->after_work_barrier, NULL, worker_size);
  333. job->after_work_busy_barrier = worker_size;
  334. /* Note: we have to call that early, or else the task may have
  335. * disappeared already */
  336. starpu_push_task_end(task);
  337. int j;
  338. for (j = 0; j < worker_size; j++)
  339. {
  340. struct starpu_task *alias = starpu_task_dup(task);
  341. alias->destroy = 1;
  342. worker = _starpu_get_worker_struct(combined_workerid[j]);
  343. ret |= _starpu_push_local_task(worker, alias, 0);
  344. }
  345. return ret;
  346. }
  347. }
  348. /* the generic interface that call the proper underlying implementation */
  349. int _starpu_push_task(struct _starpu_job *j)
  350. {
  351. if(j->task->prologue_callback_func)
  352. j->task->prologue_callback_func(j->task->prologue_callback_arg);
  353. return _starpu_repush_task(j);
  354. }
  355. int _starpu_repush_task(struct _starpu_job *j)
  356. {
  357. struct starpu_task *task = j->task;
  358. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  359. int ret;
  360. _STARPU_LOG_IN();
  361. unsigned can_push = _starpu_increment_nready_tasks_of_sched_ctx(task->sched_ctx, task->flops, task);
  362. task->status = STARPU_TASK_READY;
  363. STARPU_AYU_ADDTOTASKQUEUE(j->job_id, -1);
  364. /* if the context does not have any workers save the tasks in a temp list */
  365. if ((task->cl != NULL && task->where != STARPU_NOWHERE) && (!sched_ctx->is_initial_sched))
  366. {
  367. /*if there are workers in the ctx that are not able to execute tasks
  368. we consider the ctx empty */
  369. unsigned nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
  370. if(nworkers == 0)
  371. {
  372. _starpu_sched_ctx_lock_write(sched_ctx->id);
  373. starpu_task_list_push_front(&sched_ctx->empty_ctx_tasks, task);
  374. _starpu_sched_ctx_unlock_write(sched_ctx->id);
  375. #ifdef STARPU_USE_SC_HYPERVISOR
  376. if(sched_ctx->id != 0 && sched_ctx->perf_counters != NULL
  377. && sched_ctx->perf_counters->notify_empty_ctx)
  378. {
  379. _STARPU_TRACE_HYPERVISOR_BEGIN();
  380. sched_ctx->perf_counters->notify_empty_ctx(sched_ctx->id, task);
  381. _STARPU_TRACE_HYPERVISOR_END();
  382. }
  383. #endif
  384. return 0;
  385. }
  386. }
  387. if(!can_push)
  388. return 0;
  389. /* in case there is no codelet associated to the task (that's a control
  390. * task), we directly execute its callback and enforce the
  391. * corresponding dependencies */
  392. if (task->cl == NULL || task->where == STARPU_NOWHERE)
  393. {
  394. if (task->prologue_callback_pop_func)
  395. task->prologue_callback_pop_func(task->prologue_callback_pop_arg);
  396. if (task->cl && task->cl->specific_nodes)
  397. {
  398. /* Nothing to do, but we are asked to fetch data on some memory nodes */
  399. _starpu_fetch_nowhere_task_input(j);
  400. }
  401. else
  402. {
  403. if (task->cl)
  404. __starpu_push_task_output(j);
  405. _starpu_handle_job_termination(j);
  406. _STARPU_LOG_OUT_TAG("handle_job_termination");
  407. }
  408. return 0;
  409. }
  410. ret = _starpu_push_task_to_workers(task);
  411. if (ret == -EAGAIN)
  412. /* pushed to empty context, that's fine */
  413. ret = 0;
  414. return ret;
  415. }
  416. int _starpu_push_task_to_workers(struct starpu_task *task)
  417. {
  418. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  419. unsigned nworkers = 0;
  420. _STARPU_TRACE_JOB_PUSH(task, task->priority > 0);
  421. /* if the contexts still does not have workers put the task back to its place in
  422. the empty ctx list */
  423. if(!sched_ctx->is_initial_sched)
  424. {
  425. /*if there are workers in the ctx that are not able to execute tasks
  426. we consider the ctx empty */
  427. nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
  428. if (nworkers == 0)
  429. {
  430. _starpu_sched_ctx_lock_write(sched_ctx->id);
  431. starpu_task_list_push_back(&sched_ctx->empty_ctx_tasks, task);
  432. _starpu_sched_ctx_unlock_write(sched_ctx->id);
  433. #ifdef STARPU_USE_SC_HYPERVISOR
  434. if(sched_ctx->id != 0 && sched_ctx->perf_counters != NULL
  435. && sched_ctx->perf_counters->notify_empty_ctx)
  436. {
  437. _STARPU_TRACE_HYPERVISOR_BEGIN();
  438. sched_ctx->perf_counters->notify_empty_ctx(sched_ctx->id, task);
  439. _STARPU_TRACE_HYPERVISOR_END();
  440. }
  441. #endif
  442. return -EAGAIN;
  443. }
  444. }
  445. _starpu_profiling_set_task_push_start_time(task);
  446. int ret = 0;
  447. if (STARPU_UNLIKELY(task->execute_on_a_specific_worker))
  448. {
  449. unsigned node = starpu_worker_get_memory_node(task->workerid);
  450. if (starpu_get_prefetch_flag())
  451. starpu_prefetch_task_input_on_node(task, node);
  452. ret = _starpu_push_task_on_specific_worker(task, task->workerid);
  453. }
  454. else
  455. {
  456. struct _starpu_machine_config *config = _starpu_get_machine_config();
  457. /* When a task can only be executed on a given arch and we have
  458. * only one memory node for that arch, we can systematically
  459. * prefetch before the scheduling decision. */
  460. if (starpu_get_prefetch_flag())
  461. {
  462. if (task->where == STARPU_CPU && config->cpus_nodeid >= 0)
  463. starpu_prefetch_task_input_on_node(task, config->cpus_nodeid);
  464. else if (task->where == STARPU_CUDA && config->cuda_nodeid >= 0)
  465. starpu_prefetch_task_input_on_node(task, config->cuda_nodeid);
  466. else if (task->where == STARPU_OPENCL && config->opencl_nodeid >= 0)
  467. starpu_prefetch_task_input_on_node(task, config->opencl_nodeid);
  468. else if (task->where == STARPU_MIC && config->mic_nodeid >= 0)
  469. starpu_prefetch_task_input_on_node(task, config->mic_nodeid);
  470. else if (task->where == STARPU_SCC && config->scc_nodeid >= 0)
  471. starpu_prefetch_task_input_on_node(task, config->scc_nodeid);
  472. }
  473. if(!sched_ctx->sched_policy)
  474. {
  475. /* Note: we have to call that early, or else the task may have
  476. * disappeared already */
  477. starpu_push_task_end(task);
  478. if(!sched_ctx->awake_workers)
  479. ret = _starpu_push_task_on_specific_worker(task, sched_ctx->main_master);
  480. else
  481. {
  482. struct starpu_worker_collection *workers = sched_ctx->workers;
  483. struct _starpu_job *job = _starpu_get_job_associated_to_task(task);
  484. job->task_size = workers->nworkers;
  485. job->combined_workerid = -1; // workerid; its a ctx not combined worker
  486. job->active_task_alias_count = 0;
  487. STARPU_PTHREAD_BARRIER_INIT(&job->before_work_barrier, NULL, workers->nworkers);
  488. STARPU_PTHREAD_BARRIER_INIT(&job->after_work_barrier, NULL, workers->nworkers);
  489. job->after_work_busy_barrier = workers->nworkers;
  490. struct starpu_sched_ctx_iterator it;
  491. if(workers->init_iterator)
  492. workers->init_iterator(workers, &it);
  493. while(workers->has_next(workers, &it))
  494. {
  495. unsigned workerid = workers->get_next(workers, &it);
  496. struct starpu_task *alias;
  497. if (job->task_size > 1)
  498. {
  499. alias = starpu_task_dup(task);
  500. alias->destroy = 1;
  501. }
  502. else
  503. alias = task;
  504. ret |= _starpu_push_task_on_specific_worker(alias, workerid);
  505. }
  506. }
  507. }
  508. else
  509. {
  510. STARPU_ASSERT(sched_ctx->sched_policy->push_task);
  511. /* check out if there are any workers in the context */
  512. nworkers = starpu_sched_ctx_get_nworkers(sched_ctx->id);
  513. if (nworkers == 0)
  514. ret = -1;
  515. else
  516. {
  517. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  518. if (worker)
  519. {
  520. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  521. _starpu_worker_enter_sched_op(worker);
  522. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  523. }
  524. _STARPU_TASK_BREAK_ON(task, push);
  525. _STARPU_SCHED_BEGIN;
  526. ret = sched_ctx->sched_policy->push_task(task);
  527. _STARPU_SCHED_END;
  528. if (worker)
  529. {
  530. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  531. _starpu_worker_leave_sched_op(worker);
  532. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  533. }
  534. }
  535. }
  536. if(ret == -1)
  537. {
  538. _STARPU_MSG("repush task \n");
  539. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  540. ret = _starpu_push_task_to_workers(task);
  541. }
  542. }
  543. /* Note: from here, the task might have been destroyed already! */
  544. _STARPU_LOG_OUT();
  545. return ret;
  546. }
  547. /* This is called right after the scheduler has pushed a task to a queue
  548. * but just before releasing mutexes: we need the task to still be alive!
  549. */
  550. int starpu_push_task_end(struct starpu_task *task)
  551. {
  552. _starpu_profiling_set_task_push_end_time(task);
  553. task->scheduled = 1;
  554. return 0;
  555. }
  556. /* This is called right after the scheduler has pushed a task to a queue
  557. * but just before releasing mutexes: we need the task to still be alive!
  558. */
  559. int _starpu_pop_task_end(struct starpu_task *task)
  560. {
  561. if (!task)
  562. return 0;
  563. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  564. return 0;
  565. }
  566. /*
  567. * Given a handle that needs to be converted in order to be used on the given
  568. * node, returns a task that takes care of the conversion.
  569. */
  570. struct starpu_task *_starpu_create_conversion_task(starpu_data_handle_t handle,
  571. unsigned int node)
  572. {
  573. return _starpu_create_conversion_task_for_arch(handle, starpu_node_get_kind(node));
  574. }
  575. struct starpu_task *_starpu_create_conversion_task_for_arch(starpu_data_handle_t handle,
  576. enum starpu_node_kind node_kind)
  577. {
  578. struct starpu_task *conversion_task;
  579. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  580. struct starpu_multiformat_interface *format_interface;
  581. #endif
  582. conversion_task = starpu_task_create();
  583. conversion_task->name = "conversion_task";
  584. conversion_task->synchronous = 0;
  585. STARPU_TASK_SET_HANDLE(conversion_task, handle, 0);
  586. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  587. /* The node does not really matter here */
  588. format_interface = (struct starpu_multiformat_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  589. #endif
  590. _starpu_spin_lock(&handle->header_lock);
  591. handle->refcnt++;
  592. handle->busy_count++;
  593. _starpu_spin_unlock(&handle->header_lock);
  594. switch(node_kind)
  595. {
  596. case STARPU_CPU_RAM:
  597. case STARPU_SCC_RAM:
  598. case STARPU_SCC_SHM:
  599. switch (starpu_node_get_kind(handle->mf_node))
  600. {
  601. case STARPU_CPU_RAM:
  602. case STARPU_SCC_RAM:
  603. case STARPU_SCC_SHM:
  604. STARPU_ABORT();
  605. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  606. case STARPU_CUDA_RAM:
  607. {
  608. struct starpu_multiformat_data_interface_ops *mf_ops;
  609. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  610. conversion_task->cl = mf_ops->cuda_to_cpu_cl;
  611. break;
  612. }
  613. #endif
  614. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  615. case STARPU_OPENCL_RAM:
  616. {
  617. struct starpu_multiformat_data_interface_ops *mf_ops;
  618. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  619. conversion_task->cl = mf_ops->opencl_to_cpu_cl;
  620. break;
  621. }
  622. #endif
  623. #ifdef STARPU_USE_MIC
  624. case STARPU_MIC_RAM:
  625. {
  626. struct starpu_multiformat_data_interface_ops *mf_ops;
  627. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  628. conversion_task->cl = mf_ops->mic_to_cpu_cl;
  629. break;
  630. }
  631. #endif
  632. default:
  633. _STARPU_ERROR("Oops : %u\n", handle->mf_node);
  634. }
  635. break;
  636. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  637. case STARPU_CUDA_RAM:
  638. {
  639. struct starpu_multiformat_data_interface_ops *mf_ops;
  640. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  641. conversion_task->cl = mf_ops->cpu_to_cuda_cl;
  642. break;
  643. }
  644. #endif
  645. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  646. case STARPU_OPENCL_RAM:
  647. {
  648. struct starpu_multiformat_data_interface_ops *mf_ops;
  649. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  650. conversion_task->cl = mf_ops->cpu_to_opencl_cl;
  651. break;
  652. }
  653. #endif
  654. #ifdef STARPU_USE_MIC
  655. case STARPU_MIC_RAM:
  656. {
  657. struct starpu_multiformat_data_interface_ops *mf_ops;
  658. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  659. conversion_task->cl = mf_ops->cpu_to_mic_cl;
  660. break;
  661. }
  662. #endif
  663. default:
  664. STARPU_ABORT();
  665. }
  666. STARPU_TASK_SET_MODE(conversion_task, STARPU_RW, 0);
  667. return conversion_task;
  668. }
  669. static
  670. struct _starpu_sched_ctx* _get_next_sched_ctx_to_pop_into(struct _starpu_worker *worker)
  671. {
  672. struct _starpu_sched_ctx_elt *e = NULL;
  673. struct _starpu_sched_ctx_list_iterator list_it;
  674. int found = 0;
  675. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  676. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  677. {
  678. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  679. if (e->task_number > 0)
  680. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  681. }
  682. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  683. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  684. {
  685. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  686. if (e->last_poped)
  687. {
  688. e->last_poped = 0;
  689. if (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  690. {
  691. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  692. found = 1;
  693. }
  694. break;
  695. }
  696. }
  697. if (!found)
  698. e = worker->sched_ctx_list->head;
  699. e->last_poped = 1;
  700. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  701. }
  702. struct starpu_task *_starpu_pop_task(struct _starpu_worker *worker)
  703. {
  704. struct starpu_task *task;
  705. int worker_id;
  706. unsigned node;
  707. /* We can't tell in advance which task will be picked up, so we measure
  708. * a timestamp, and will attribute it afterwards to the task. */
  709. int profiling = starpu_profiling_status_get();
  710. struct timespec pop_start_time;
  711. if (profiling)
  712. _starpu_clock_gettime(&pop_start_time);
  713. pick:
  714. /* perhaps there is some local task to be executed first */
  715. task = _starpu_pop_local_task(worker);
  716. if (task)
  717. _STARPU_TASK_BREAK_ON(task, pop);
  718. /* get tasks from the stacks of the strategy */
  719. if(!task)
  720. {
  721. struct _starpu_sched_ctx *sched_ctx ;
  722. #ifndef STARPU_NON_BLOCKING_DRIVERS
  723. int been_here[STARPU_NMAX_SCHED_CTXS];
  724. int i;
  725. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  726. been_here[i] = 0;
  727. while(!task)
  728. #endif
  729. {
  730. if(worker->nsched_ctxs == 1)
  731. sched_ctx = _starpu_get_initial_sched_ctx();
  732. else
  733. {
  734. while(1)
  735. {
  736. /** Caution
  737. * If you use multiple contexts your scheduler *needs*
  738. * to update the variable task_number of the ctx list.
  739. * In order to get the best performances.
  740. * This is done using functions :
  741. * starpu_sched_ctx_list_task_counters_increment...(...)
  742. * starpu_sched_ctx_list_task_counters_decrement...(...)
  743. **/
  744. sched_ctx = _get_next_sched_ctx_to_pop_into(worker);
  745. if(worker->removed_from_ctx[sched_ctx->id] == 1 && worker->shares_tasks_lists[sched_ctx->id] == 1)
  746. {
  747. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  748. worker->removed_from_ctx[sched_ctx->id] = 0;
  749. sched_ctx = NULL;
  750. }
  751. else
  752. break;
  753. }
  754. }
  755. if(sched_ctx && sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  756. {
  757. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pop_task)
  758. {
  759. /* Note: we do not push the scheduling state here, because
  760. * otherwise when a worker is idle, we'd keep
  761. * pushing/popping a scheduling state here, while what we
  762. * want to see in the trace is a permanent idle state. */
  763. task = sched_ctx->sched_policy->pop_task(sched_ctx->id);
  764. if (task)
  765. _STARPU_TASK_BREAK_ON(task, pop);
  766. _starpu_pop_task_end(task);
  767. }
  768. }
  769. if(!task)
  770. {
  771. /* it doesn't matter if it shares tasks list or not in the scheduler,
  772. if it does not have any task to pop just get it out of here */
  773. /* however if it shares a task list it will be removed as soon as he
  774. finishes this job (in handle_job_termination) */
  775. if(worker->removed_from_ctx[sched_ctx->id])
  776. {
  777. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  778. worker->removed_from_ctx[sched_ctx->id] = 0;
  779. }
  780. #ifdef STARPU_USE_SC_HYPERVISOR
  781. if(worker->pop_ctx_priority)
  782. {
  783. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  784. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_idle_cycle && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  785. {
  786. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  787. perf_counters->notify_idle_cycle(sched_ctx->id, worker->workerid, 1.0);
  788. // _STARPU_TRACE_HYPERVISOR_END();
  789. }
  790. }
  791. #endif //STARPU_USE_SC_HYPERVISOR
  792. #ifndef STARPU_NON_BLOCKING_DRIVERS
  793. if(been_here[sched_ctx->id] || worker->nsched_ctxs == 1)
  794. break;
  795. been_here[sched_ctx->id] = 1;
  796. #endif
  797. }
  798. }
  799. }
  800. if (!task)
  801. {
  802. if (starpu_idle_file)
  803. idle_start[worker->workerid] = starpu_timing_now();
  804. return NULL;
  805. }
  806. if(starpu_idle_file && idle_start[worker->workerid] != 0.0)
  807. {
  808. double idle_end = starpu_timing_now();
  809. idle[worker->workerid] += (idle_end - idle_start[worker->workerid]);
  810. idle_start[worker->workerid] = 0.0;
  811. }
  812. #ifdef STARPU_USE_SC_HYPERVISOR
  813. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  814. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  815. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_poped_task && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  816. {
  817. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  818. perf_counters->notify_poped_task(task->sched_ctx, worker->workerid);
  819. // _STARPU_TRACE_HYPERVISOR_END();
  820. }
  821. #endif //STARPU_USE_SC_HYPERVISOR
  822. /* Make sure we do not bother with all the multiformat-specific code if
  823. * it is not necessary. */
  824. if (!_starpu_task_uses_multiformat_handles(task))
  825. goto profiling;
  826. /* This is either a conversion task, or a regular task for which the
  827. * conversion tasks have already been created and submitted */
  828. if (task->mf_skip)
  829. goto profiling;
  830. /*
  831. * This worker may not be able to execute this task. In this case, we
  832. * should return the task anyway. It will be pushed back almost immediatly.
  833. * This way, we avoid computing and executing the conversions tasks.
  834. * Here, we do not care about what implementation is used.
  835. */
  836. worker_id = starpu_worker_get_id_check();
  837. if (!starpu_worker_can_execute_task_first_impl(worker_id, task, NULL))
  838. return task;
  839. node = starpu_worker_get_memory_node(worker_id);
  840. /*
  841. * We do have a task that uses multiformat handles. Let's create the
  842. * required conversion tasks.
  843. */
  844. unsigned i;
  845. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  846. for (i = 0; i < nbuffers; i++)
  847. {
  848. struct starpu_task *conversion_task;
  849. starpu_data_handle_t handle;
  850. handle = STARPU_TASK_GET_HANDLE(task, i);
  851. if (!_starpu_handle_needs_conversion_task(handle, node))
  852. continue;
  853. conversion_task = _starpu_create_conversion_task(handle, node);
  854. conversion_task->mf_skip = 1;
  855. conversion_task->execute_on_a_specific_worker = 1;
  856. conversion_task->workerid = worker_id;
  857. /*
  858. * Next tasks will need to know where these handles have gone.
  859. */
  860. handle->mf_node = node;
  861. _starpu_task_submit_conversion_task(conversion_task, worker_id);
  862. }
  863. task->mf_skip = 1;
  864. starpu_task_list_push_back(&worker->local_tasks, task);
  865. goto pick;
  866. profiling:
  867. if (profiling)
  868. {
  869. struct starpu_profiling_task_info *profiling_info;
  870. profiling_info = task->profiling_info;
  871. /* The task may have been created before profiling was enabled,
  872. * so we check if the profiling_info structure is available
  873. * even though we already tested if profiling is enabled. */
  874. if (profiling_info)
  875. {
  876. memcpy(&profiling_info->pop_start_time,
  877. &pop_start_time, sizeof(struct timespec));
  878. _starpu_clock_gettime(&profiling_info->pop_end_time);
  879. }
  880. }
  881. if(task->prologue_callback_pop_func)
  882. {
  883. _starpu_set_current_task(task);
  884. task->prologue_callback_pop_func(task->prologue_callback_pop_arg);
  885. _starpu_set_current_task(NULL);
  886. }
  887. return task;
  888. }
  889. struct starpu_task *_starpu_pop_every_task(struct _starpu_sched_ctx *sched_ctx)
  890. {
  891. struct starpu_task *task = NULL;
  892. if(sched_ctx->sched_policy)
  893. {
  894. STARPU_ASSERT(sched_ctx->sched_policy->pop_every_task);
  895. /* TODO set profiling info */
  896. if(sched_ctx->sched_policy->pop_every_task)
  897. {
  898. _STARPU_SCHED_BEGIN;
  899. task = sched_ctx->sched_policy->pop_every_task(sched_ctx->id);
  900. _STARPU_SCHED_END;
  901. }
  902. }
  903. return task;
  904. }
  905. void _starpu_sched_pre_exec_hook(struct starpu_task *task)
  906. {
  907. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  908. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  909. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pre_exec_hook)
  910. {
  911. _STARPU_SCHED_BEGIN;
  912. sched_ctx->sched_policy->pre_exec_hook(task, sched_ctx_id);
  913. _STARPU_SCHED_END;
  914. }
  915. if(!sched_ctx->sched_policy)
  916. {
  917. int workerid = starpu_worker_get_id();
  918. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  919. struct _starpu_sched_ctx_list_iterator list_it;
  920. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  921. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  922. {
  923. struct _starpu_sched_ctx *other_sched_ctx;
  924. struct _starpu_sched_ctx_elt *e = NULL;
  925. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  926. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  927. if (other_sched_ctx != sched_ctx &&
  928. other_sched_ctx->sched_policy != NULL &&
  929. other_sched_ctx->sched_policy->pre_exec_hook)
  930. {
  931. _STARPU_SCHED_BEGIN;
  932. other_sched_ctx->sched_policy->pre_exec_hook(task, other_sched_ctx->id);
  933. _STARPU_SCHED_END;
  934. }
  935. }
  936. }
  937. }
  938. void _starpu_sched_post_exec_hook(struct starpu_task *task)
  939. {
  940. STARPU_ASSERT(task->cl != NULL && task->cl->where != STARPU_NOWHERE);
  941. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  942. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  943. if (sched_ctx->sched_policy && sched_ctx->sched_policy->post_exec_hook)
  944. {
  945. _STARPU_SCHED_BEGIN;
  946. sched_ctx->sched_policy->post_exec_hook(task, sched_ctx_id);
  947. _STARPU_SCHED_END;
  948. }
  949. if(!sched_ctx->sched_policy)
  950. {
  951. int workerid = starpu_worker_get_id();
  952. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  953. struct _starpu_sched_ctx_list_iterator list_it;
  954. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  955. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  956. {
  957. struct _starpu_sched_ctx *other_sched_ctx;
  958. struct _starpu_sched_ctx_elt *e = NULL;
  959. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  960. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  961. if (other_sched_ctx != sched_ctx &&
  962. other_sched_ctx->sched_policy != NULL &&
  963. other_sched_ctx->sched_policy->post_exec_hook)
  964. {
  965. _STARPU_SCHED_BEGIN;
  966. other_sched_ctx->sched_policy->post_exec_hook(task, other_sched_ctx->id);
  967. _STARPU_SCHED_END;
  968. }
  969. }
  970. }
  971. }
  972. void _starpu_wait_on_sched_event(void)
  973. {
  974. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  975. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  976. _starpu_handle_all_pending_node_data_requests(worker->memory_node);
  977. if (_starpu_machine_is_running())
  978. {
  979. #ifndef STARPU_NON_BLOCKING_DRIVERS
  980. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond,
  981. &worker->sched_mutex);
  982. #endif
  983. }
  984. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  985. }
  986. /* The scheduling policy may put tasks directly into a worker's local queue so
  987. * that it is not always necessary to create its own queue when the local queue
  988. * is sufficient. If "back" not null, the task is put at the back of the queue
  989. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  990. * a FIFO ordering. */
  991. int starpu_push_local_task(int workerid, struct starpu_task *task, int prio)
  992. {
  993. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  994. return _starpu_push_local_task(worker, task, prio);
  995. }
  996. void _starpu_print_idle_time()
  997. {
  998. if(!starpu_idle_file)
  999. return;
  1000. double all_idle = 0.0;
  1001. int i = 0;
  1002. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  1003. all_idle += idle[i];
  1004. FILE *f;
  1005. f = fopen(starpu_idle_file, "a");
  1006. if (!f)
  1007. {
  1008. _STARPU_MSG("couldn't open %s: %s\n", starpu_idle_file, strerror(errno));
  1009. }
  1010. else
  1011. {
  1012. fprintf(f, "%lf \n", all_idle);
  1013. fclose(f);
  1014. }
  1015. }