sched_policy.c 35 KB

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