sched_policy.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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 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(!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->cl->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->cl->where == STARPU_CPU && config->cpus_nodeid >= 0)
  463. starpu_prefetch_task_input_on_node(task, config->cpus_nodeid);
  464. else if (task->cl->where == STARPU_CUDA && config->cuda_nodeid >= 0)
  465. starpu_prefetch_task_input_on_node(task, config->cuda_nodeid);
  466. else if (task->cl->where == STARPU_OPENCL && config->opencl_nodeid >= 0)
  467. starpu_prefetch_task_input_on_node(task, config->opencl_nodeid);
  468. else if (task->cl->where == STARPU_MIC && config->mic_nodeid >= 0)
  469. starpu_prefetch_task_input_on_node(task, config->mic_nodeid);
  470. else if (task->cl->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. _STARPU_TASK_BREAK_ON(task, push);
  518. _STARPU_SCHED_BEGIN;
  519. ret = sched_ctx->sched_policy->push_task(task);
  520. _STARPU_SCHED_END;
  521. }
  522. }
  523. if(ret == -1)
  524. {
  525. _STARPU_MSG("repush task \n");
  526. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  527. ret = _starpu_push_task_to_workers(task);
  528. }
  529. }
  530. /* Note: from here, the task might have been destroyed already! */
  531. _STARPU_LOG_OUT();
  532. return ret;
  533. }
  534. /* This is called right after the scheduler has pushed a task to a queue
  535. * but just before releasing mutexes: we need the task to still be alive!
  536. */
  537. int starpu_push_task_end(struct starpu_task *task)
  538. {
  539. _starpu_profiling_set_task_push_end_time(task);
  540. task->scheduled = 1;
  541. return 0;
  542. }
  543. /* This is called right after the scheduler has pushed a task to a queue
  544. * but just before releasing mutexes: we need the task to still be alive!
  545. */
  546. int _starpu_pop_task_end(struct starpu_task *task)
  547. {
  548. if (!task)
  549. return 0;
  550. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  551. return 0;
  552. }
  553. /*
  554. * Given a handle that needs to be converted in order to be used on the given
  555. * node, returns a task that takes care of the conversion.
  556. */
  557. struct starpu_task *_starpu_create_conversion_task(starpu_data_handle_t handle,
  558. unsigned int node)
  559. {
  560. return _starpu_create_conversion_task_for_arch(handle, starpu_node_get_kind(node));
  561. }
  562. struct starpu_task *_starpu_create_conversion_task_for_arch(starpu_data_handle_t handle,
  563. enum starpu_node_kind node_kind)
  564. {
  565. struct starpu_task *conversion_task;
  566. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  567. struct starpu_multiformat_interface *format_interface;
  568. #endif
  569. conversion_task = starpu_task_create();
  570. conversion_task->name = "conversion_task";
  571. conversion_task->synchronous = 0;
  572. STARPU_TASK_SET_HANDLE(conversion_task, handle, 0);
  573. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  574. /* The node does not really matter here */
  575. format_interface = (struct starpu_multiformat_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  576. #endif
  577. _starpu_spin_lock(&handle->header_lock);
  578. handle->refcnt++;
  579. handle->busy_count++;
  580. _starpu_spin_unlock(&handle->header_lock);
  581. switch(node_kind)
  582. {
  583. case STARPU_CPU_RAM:
  584. case STARPU_SCC_RAM:
  585. case STARPU_SCC_SHM:
  586. switch (starpu_node_get_kind(handle->mf_node))
  587. {
  588. case STARPU_CPU_RAM:
  589. case STARPU_SCC_RAM:
  590. case STARPU_SCC_SHM:
  591. STARPU_ABORT();
  592. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  593. case STARPU_CUDA_RAM:
  594. {
  595. struct starpu_multiformat_data_interface_ops *mf_ops;
  596. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  597. conversion_task->cl = mf_ops->cuda_to_cpu_cl;
  598. break;
  599. }
  600. #endif
  601. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  602. case STARPU_OPENCL_RAM:
  603. {
  604. struct starpu_multiformat_data_interface_ops *mf_ops;
  605. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  606. conversion_task->cl = mf_ops->opencl_to_cpu_cl;
  607. break;
  608. }
  609. #endif
  610. #ifdef STARPU_USE_MIC
  611. case STARPU_MIC_RAM:
  612. {
  613. struct starpu_multiformat_data_interface_ops *mf_ops;
  614. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  615. conversion_task->cl = mf_ops->mic_to_cpu_cl;
  616. break;
  617. }
  618. #endif
  619. default:
  620. _STARPU_ERROR("Oops : %u\n", handle->mf_node);
  621. }
  622. break;
  623. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  624. case STARPU_CUDA_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->cpu_to_cuda_cl;
  629. break;
  630. }
  631. #endif
  632. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  633. case STARPU_OPENCL_RAM:
  634. {
  635. struct starpu_multiformat_data_interface_ops *mf_ops;
  636. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  637. conversion_task->cl = mf_ops->cpu_to_opencl_cl;
  638. break;
  639. }
  640. #endif
  641. #ifdef STARPU_USE_MIC
  642. case STARPU_MIC_RAM:
  643. {
  644. struct starpu_multiformat_data_interface_ops *mf_ops;
  645. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  646. conversion_task->cl = mf_ops->cpu_to_mic_cl;
  647. break;
  648. }
  649. #endif
  650. default:
  651. STARPU_ABORT();
  652. }
  653. STARPU_TASK_SET_MODE(conversion_task, STARPU_RW, 0);
  654. return conversion_task;
  655. }
  656. static
  657. struct _starpu_sched_ctx* _get_next_sched_ctx_to_pop_into(struct _starpu_worker *worker)
  658. {
  659. struct _starpu_sched_ctx_elt *e = NULL;
  660. struct _starpu_sched_ctx_list_iterator list_it;
  661. int found = 0;
  662. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  663. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  664. {
  665. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  666. if (e->task_number > 0)
  667. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  668. }
  669. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  670. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  671. {
  672. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  673. if (e->last_poped)
  674. {
  675. e->last_poped = 0;
  676. if (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  677. {
  678. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  679. found = 1;
  680. }
  681. break;
  682. }
  683. }
  684. if (!found)
  685. e = worker->sched_ctx_list->head;
  686. e->last_poped = 1;
  687. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  688. }
  689. struct starpu_task *_starpu_pop_task(struct _starpu_worker *worker)
  690. {
  691. struct starpu_task *task;
  692. int worker_id;
  693. unsigned node;
  694. /* We can't tell in advance which task will be picked up, so we measure
  695. * a timestamp, and will attribute it afterwards to the task. */
  696. int profiling = starpu_profiling_status_get();
  697. struct timespec pop_start_time;
  698. if (profiling)
  699. _starpu_clock_gettime(&pop_start_time);
  700. pick:
  701. /* perhaps there is some local task to be executed first */
  702. task = _starpu_pop_local_task(worker);
  703. if (task)
  704. _STARPU_TASK_BREAK_ON(task, pop);
  705. /* get tasks from the stacks of the strategy */
  706. if(!task)
  707. {
  708. struct _starpu_sched_ctx *sched_ctx ;
  709. #ifndef STARPU_NON_BLOCKING_DRIVERS
  710. int been_here[STARPU_NMAX_SCHED_CTXS];
  711. int i;
  712. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  713. been_here[i] = 0;
  714. while(!task)
  715. #endif
  716. {
  717. if(worker->nsched_ctxs == 1)
  718. sched_ctx = _starpu_get_initial_sched_ctx();
  719. else
  720. {
  721. while(1)
  722. {
  723. /** Caution
  724. * If you use multiple contexts your scheduler *needs*
  725. * to update the variable task_number of the ctx list.
  726. * In order to get the best performances.
  727. * This is done using functions :
  728. * starpu_sched_ctx_list_task_counters_increment...(...)
  729. * starpu_sched_ctx_list_task_counters_decrement...(...)
  730. **/
  731. sched_ctx = _get_next_sched_ctx_to_pop_into(worker);
  732. if(worker->removed_from_ctx[sched_ctx->id] == 1 && worker->shares_tasks_lists[sched_ctx->id] == 1)
  733. {
  734. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  735. worker->removed_from_ctx[sched_ctx->id] = 0;
  736. sched_ctx = NULL;
  737. }
  738. else
  739. break;
  740. }
  741. }
  742. if(sched_ctx && sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  743. {
  744. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pop_task)
  745. {
  746. /* Note: we do not push the scheduling state here, because
  747. * otherwise when a worker is idle, we'd keep
  748. * pushing/popping a scheduling state here, while what we
  749. * want to see in the trace is a permanent idle state. */
  750. task = sched_ctx->sched_policy->pop_task(sched_ctx->id);
  751. if (task)
  752. _STARPU_TASK_BREAK_ON(task, pop);
  753. _starpu_pop_task_end(task);
  754. }
  755. }
  756. if(!task)
  757. {
  758. /* it doesn't matter if it shares tasks list or not in the scheduler,
  759. if it does not have any task to pop just get it out of here */
  760. /* however if it shares a task list it will be removed as soon as he
  761. finishes this job (in handle_job_termination) */
  762. if(worker->removed_from_ctx[sched_ctx->id])
  763. {
  764. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  765. worker->removed_from_ctx[sched_ctx->id] = 0;
  766. }
  767. #ifdef STARPU_USE_SC_HYPERVISOR
  768. if(worker->pop_ctx_priority)
  769. {
  770. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  771. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_idle_cycle && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  772. {
  773. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  774. perf_counters->notify_idle_cycle(sched_ctx->id, worker->workerid, 1.0);
  775. // _STARPU_TRACE_HYPERVISOR_END();
  776. }
  777. }
  778. #endif //STARPU_USE_SC_HYPERVISOR
  779. #ifndef STARPU_NON_BLOCKING_DRIVERS
  780. if(been_here[sched_ctx->id] || worker->nsched_ctxs == 1)
  781. break;
  782. been_here[sched_ctx->id] = 1;
  783. #endif
  784. }
  785. }
  786. }
  787. if (!task)
  788. {
  789. if (starpu_idle_file)
  790. idle_start[worker->workerid] = starpu_timing_now();
  791. return NULL;
  792. }
  793. if(starpu_idle_file && idle_start[worker->workerid] != 0.0)
  794. {
  795. double idle_end = starpu_timing_now();
  796. idle[worker->workerid] += (idle_end - idle_start[worker->workerid]);
  797. idle_start[worker->workerid] = 0.0;
  798. }
  799. #ifdef STARPU_USE_SC_HYPERVISOR
  800. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  801. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  802. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_poped_task && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  803. {
  804. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  805. perf_counters->notify_poped_task(task->sched_ctx, worker->workerid);
  806. // _STARPU_TRACE_HYPERVISOR_END();
  807. }
  808. #endif //STARPU_USE_SC_HYPERVISOR
  809. /* Make sure we do not bother with all the multiformat-specific code if
  810. * it is not necessary. */
  811. if (!_starpu_task_uses_multiformat_handles(task))
  812. goto profiling;
  813. /* This is either a conversion task, or a regular task for which the
  814. * conversion tasks have already been created and submitted */
  815. if (task->mf_skip)
  816. goto profiling;
  817. /*
  818. * This worker may not be able to execute this task. In this case, we
  819. * should return the task anyway. It will be pushed back almost immediatly.
  820. * This way, we avoid computing and executing the conversions tasks.
  821. * Here, we do not care about what implementation is used.
  822. */
  823. worker_id = starpu_worker_get_id_check();
  824. if (!starpu_worker_can_execute_task_first_impl(worker_id, task, NULL))
  825. return task;
  826. node = starpu_worker_get_memory_node(worker_id);
  827. /*
  828. * We do have a task that uses multiformat handles. Let's create the
  829. * required conversion tasks.
  830. */
  831. _starpu_worker_relax_on();
  832. unsigned i;
  833. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  834. for (i = 0; i < nbuffers; i++)
  835. {
  836. struct starpu_task *conversion_task;
  837. starpu_data_handle_t handle;
  838. handle = STARPU_TASK_GET_HANDLE(task, i);
  839. if (!_starpu_handle_needs_conversion_task(handle, node))
  840. continue;
  841. conversion_task = _starpu_create_conversion_task(handle, node);
  842. conversion_task->mf_skip = 1;
  843. conversion_task->execute_on_a_specific_worker = 1;
  844. conversion_task->workerid = worker_id;
  845. /*
  846. * Next tasks will need to know where these handles have gone.
  847. */
  848. handle->mf_node = node;
  849. _starpu_task_submit_conversion_task(conversion_task, worker_id);
  850. }
  851. task->mf_skip = 1;
  852. starpu_task_list_push_back(&worker->local_tasks, task);
  853. _starpu_worker_relax_off();
  854. goto pick;
  855. profiling:
  856. if (profiling)
  857. {
  858. struct starpu_profiling_task_info *profiling_info;
  859. profiling_info = task->profiling_info;
  860. /* The task may have been created before profiling was enabled,
  861. * so we check if the profiling_info structure is available
  862. * even though we already tested if profiling is enabled. */
  863. if (profiling_info)
  864. {
  865. memcpy(&profiling_info->pop_start_time,
  866. &pop_start_time, sizeof(struct timespec));
  867. _starpu_clock_gettime(&profiling_info->pop_end_time);
  868. }
  869. }
  870. if(task->prologue_callback_pop_func)
  871. {
  872. _starpu_set_current_task(task);
  873. task->prologue_callback_pop_func(task->prologue_callback_pop_arg);
  874. _starpu_set_current_task(NULL);
  875. }
  876. return task;
  877. }
  878. struct starpu_task *_starpu_pop_every_task(struct _starpu_sched_ctx *sched_ctx)
  879. {
  880. struct starpu_task *task = NULL;
  881. if(sched_ctx->sched_policy)
  882. {
  883. STARPU_ASSERT(sched_ctx->sched_policy->pop_every_task);
  884. /* TODO set profiling info */
  885. if(sched_ctx->sched_policy->pop_every_task)
  886. {
  887. _STARPU_SCHED_BEGIN;
  888. task = sched_ctx->sched_policy->pop_every_task(sched_ctx->id);
  889. _STARPU_SCHED_END;
  890. }
  891. }
  892. return task;
  893. }
  894. void _starpu_sched_pre_exec_hook(struct starpu_task *task)
  895. {
  896. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  897. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  898. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pre_exec_hook)
  899. {
  900. _STARPU_SCHED_BEGIN;
  901. sched_ctx->sched_policy->pre_exec_hook(task, sched_ctx_id);
  902. _STARPU_SCHED_END;
  903. }
  904. if(!sched_ctx->sched_policy)
  905. {
  906. int workerid = starpu_worker_get_id();
  907. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  908. struct _starpu_sched_ctx *other_sched_ctx;
  909. struct _starpu_sched_ctx_elt *e = NULL;
  910. struct _starpu_sched_ctx_list_iterator list_it;
  911. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  912. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  913. {
  914. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  915. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  916. if (other_sched_ctx != sched_ctx &&
  917. other_sched_ctx->sched_policy != NULL &&
  918. other_sched_ctx->sched_policy->pre_exec_hook)
  919. {
  920. _STARPU_SCHED_BEGIN;
  921. other_sched_ctx->sched_policy->pre_exec_hook(task, other_sched_ctx->id);
  922. _STARPU_SCHED_END;
  923. }
  924. }
  925. }
  926. }
  927. void _starpu_sched_post_exec_hook(struct starpu_task *task)
  928. {
  929. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  930. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  931. if (sched_ctx->sched_policy && sched_ctx->sched_policy->post_exec_hook)
  932. {
  933. _STARPU_SCHED_BEGIN;
  934. sched_ctx->sched_policy->post_exec_hook(task, sched_ctx_id);
  935. _STARPU_SCHED_END;
  936. }
  937. if(!sched_ctx->sched_policy)
  938. {
  939. int workerid = starpu_worker_get_id();
  940. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  941. struct _starpu_sched_ctx *other_sched_ctx;
  942. struct _starpu_sched_ctx_elt *e = NULL;
  943. struct _starpu_sched_ctx_list_iterator list_it;
  944. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  945. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  946. {
  947. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  948. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  949. if (other_sched_ctx != sched_ctx &&
  950. other_sched_ctx->sched_policy != NULL &&
  951. other_sched_ctx->sched_policy->post_exec_hook)
  952. {
  953. _STARPU_SCHED_BEGIN;
  954. other_sched_ctx->sched_policy->post_exec_hook(task, other_sched_ctx->id);
  955. _STARPU_SCHED_END;
  956. }
  957. }
  958. }
  959. }
  960. void _starpu_wait_on_sched_event(void)
  961. {
  962. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  963. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  964. _starpu_handle_all_pending_node_data_requests(worker->memory_node);
  965. if (_starpu_machine_is_running())
  966. {
  967. #ifndef STARPU_NON_BLOCKING_DRIVERS
  968. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond,
  969. &worker->sched_mutex);
  970. #endif
  971. }
  972. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  973. }
  974. /* The scheduling policy may put tasks directly into a worker's local queue so
  975. * that it is not always necessary to create its own queue when the local queue
  976. * is sufficient. If "back" not null, the task is put at the back of the queue
  977. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  978. * a FIFO ordering. */
  979. int starpu_push_local_task(int workerid, struct starpu_task *task, int prio)
  980. {
  981. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  982. return _starpu_push_local_task(worker, task, prio);
  983. }
  984. void _starpu_print_idle_time()
  985. {
  986. if(!starpu_idle_file)
  987. return;
  988. double all_idle = 0.0;
  989. int i = 0;
  990. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  991. all_idle += idle[i];
  992. FILE *f;
  993. f = fopen(starpu_idle_file, "a");
  994. if (!f)
  995. {
  996. _STARPU_MSG("couldn't open %s: %s\n", starpu_idle_file, strerror(errno));
  997. }
  998. else
  999. {
  1000. fprintf(f, "%lf \n", all_idle);
  1001. fclose(f);
  1002. }
  1003. }