301_tasks.doxy 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2018 CNRS
  4. * Copyright (C) 2009-2011,2014-2016 Université de Bordeaux
  5. * Copyright (C) 2011-2012,2018 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*! \page TasksInStarPU Tasks In StarPU
  19. \section TaskGranularity Task Granularity
  20. Like any other runtime, StarPU has some overhead to manage tasks. Since
  21. it does smart scheduling and data management, this overhead is not always
  22. neglectable. The order of magnitude of the overhead is typically a couple of
  23. microseconds, which is actually quite smaller than the CUDA overhead itself. The
  24. amount of work that a task should do should thus be somewhat
  25. bigger, to make sure that the overhead becomes neglectible. The offline
  26. performance feedback can provide a measure of task length, which should thus be
  27. checked if bad performance are observed. To get a grasp at the scalability
  28. possibility according to task size, one can run
  29. <c>tests/microbenchs/tasks_size_overhead.sh</c> which draws curves of the
  30. speedup of independent tasks of very small sizes.
  31. The choice of scheduler also has impact over the overhead: for instance, the
  32. scheduler <c>dmda</c> takes time to make a decision, while <c>eager</c> does
  33. not. <c>tasks_size_overhead.sh</c> can again be used to get a grasp at how much
  34. impact that has on the target machine.
  35. \section TaskSubmission Task Submission
  36. To let StarPU make online optimizations, tasks should be submitted
  37. asynchronously as much as possible. Ideally, all the tasks should be
  38. submitted, and mere calls to starpu_task_wait_for_all() or
  39. starpu_data_unregister() be done to wait for
  40. termination. StarPU will then be able to rework the whole schedule, overlap
  41. computation with communication, manage accelerator local memory usage, etc.
  42. \section TaskPriorities Task Priorities
  43. By default, StarPU will consider the tasks in the order they are submitted by
  44. the application. If the application programmer knows that some tasks should
  45. be performed in priority (for instance because their output is needed by many
  46. other tasks and may thus be a bottleneck if not executed early
  47. enough), the field starpu_task::priority should be set to transmit the
  48. priority information to StarPU.
  49. \section TaskDependencies Task Dependencies
  50. \subsection SequentialConsistency Sequential Consistency
  51. By default, task dependencies are inferred from data dependency (sequential
  52. coherency) by StarPU. The application can however disable sequential coherency
  53. for some data, and dependencies can be specifically expressed.
  54. Setting (or unsetting) sequential consistency can be done at the data
  55. level by calling starpu_data_set_sequential_consistency_flag() for a
  56. specific data or starpu_data_set_default_sequential_consistency_flag()
  57. for all datas.
  58. Setting (or unsetting) sequential consistency can also be done at task
  59. level by setting the field starpu_task::sequential_consistency to 0.
  60. Sequential consistency can also be set (or unset) for each handle of a
  61. specific task, this is done by using the field
  62. starpu_task::handles_sequential_consistency. When set, its value
  63. should be a array with the number of elements being the number of
  64. handles for the task, each element of the array being the sequential
  65. consistency for the i-th handle of the task. The field can easily be
  66. set when calling starpu_task_insert() with the flag
  67. ::STARPU_HANDLES_SEQUENTIAL_CONSISTENCY
  68. \code{.c}
  69. char *seq_consistency = malloc(cl.nbuffers * sizeof(char));
  70. seq_consistency[0] = 1;
  71. seq_consistency[1] = 1;
  72. seq_consistency[2] = 0;
  73. ret = starpu_task_insert(&cl,
  74. STARPU_RW, handleA, STARPU_RW, handleB, STARPU_RW, handleC,
  75. STARPU_HANDLES_SEQUENTIAL_CONSISTENCY, seq_consistency,
  76. 0);
  77. free(seq_consistency);
  78. \endcode
  79. The internal algorithm used by StarPU to set up implicit dependency is
  80. as follows:
  81. \code{.c}
  82. if (sequential_consistency(task) == 1)
  83. for(i=0 ; i<STARPU_TASK_GET_NBUFFERS(task) ; i++)
  84. if (sequential_consistency(i-th data, task) == 1)
  85. if (sequential_consistency(i-th data) == 1)
  86. create_implicit_dependency(...)
  87. \endcode
  88. \subsection TasksAndTagsDependencies Tasks And Tags Dependencies
  89. One can explicitely set dependencies between tasks using
  90. starpu_task_declare_deps_array(). Dependencies between tasks can be
  91. expressed through tags associated to a tag with the field
  92. starpu_task::tag_id and using the function starpu_tag_declare_deps()
  93. or starpu_tag_declare_deps_array().
  94. The termination of a task can be delayed through the function
  95. starpu_task_end_dep_add() which specifies the number of calls to the
  96. function starpu_task_end_dep_release() needed to trigger the task
  97. termination.
  98. \section SettingManyDataHandlesForATask Setting Many Data Handles For a Task
  99. The maximum number of data a task can manage is fixed by the environment variable
  100. \ref STARPU_NMAXBUFS which has a default value which can be changed
  101. through the configure option \ref enable-maxbuffers "--enable-maxbuffers".
  102. However, it is possible to define tasks managing more data by using
  103. the field starpu_task::dyn_handles when defining a task and the field
  104. starpu_codelet::dyn_modes when defining the corresponding codelet.
  105. \code{.c}
  106. enum starpu_data_access_mode modes[STARPU_NMAXBUFS+1] =
  107. {
  108. STARPU_R, STARPU_R, ...
  109. };
  110. struct starpu_codelet dummy_big_cl =
  111. {
  112. .cuda_funcs = { dummy_big_kernel },
  113. .opencl_funcs = { dummy_big_kernel },
  114. .cpu_funcs = { dummy_big_kernel },
  115. .cpu_funcs_name = { "dummy_big_kernel" },
  116. .nbuffers = STARPU_NMAXBUFS+1,
  117. .dyn_modes = modes
  118. };
  119. task = starpu_task_create();
  120. task->cl = &dummy_big_cl;
  121. task->dyn_handles = malloc(task->cl->nbuffers * sizeof(starpu_data_handle_t));
  122. for(i=0 ; i<task->cl->nbuffers ; i++)
  123. {
  124. task->dyn_handles[i] = handle;
  125. }
  126. starpu_task_submit(task);
  127. \endcode
  128. \code{.c}
  129. starpu_data_handle_t *handles = malloc(dummy_big_cl.nbuffers * sizeof(starpu_data_handle_t));
  130. for(i=0 ; i<dummy_big_cl.nbuffers ; i++)
  131. {
  132. handles[i] = handle;
  133. }
  134. starpu_task_insert(&dummy_big_cl,
  135. STARPU_VALUE, &dummy_big_cl.nbuffers, sizeof(dummy_big_cl.nbuffers),
  136. STARPU_DATA_ARRAY, handles, dummy_big_cl.nbuffers,
  137. 0);
  138. \endcode
  139. The whole code for this complex data interface is available in the
  140. directory <c>examples/basic_examples/dynamic_handles.c</c>.
  141. \section SettingVariableDataHandlesForATask Setting a Variable Number Of Data Handles For a Task
  142. Normally, the number of data handles given to a task is fixed in the
  143. starpu_codelet::nbuffers codelet field. This field can however be set to
  144. \ref STARPU_VARIABLE_NBUFFERS, in which case the starpu_task::nbuffers task field
  145. must be set, and the starpu_task::modes field (or starpu_task::dyn_modes field,
  146. see \ref SettingManyDataHandlesForATask) should be used to specify the modes for
  147. the handles.
  148. \section UsingMultipleImplementationsOfACodelet Using Multiple Implementations Of A Codelet
  149. One may want to write multiple implementations of a codelet for a single type of
  150. device and let StarPU choose which one to run. As an example, we will show how
  151. to use SSE to scale a vector. The codelet can be written as follows:
  152. \code{.c}
  153. #include <xmmintrin.h>
  154. void scal_sse_func(void *buffers[], void *cl_arg)
  155. {
  156. float *vector = (float *) STARPU_VECTOR_GET_PTR(buffers[0]);
  157. unsigned int n = STARPU_VECTOR_GET_NX(buffers[0]);
  158. unsigned int n_iterations = n/4;
  159. if (n % 4 != 0)
  160. n_iterations++;
  161. __m128 *VECTOR = (__m128*) vector;
  162. __m128 factor __attribute__((aligned(16)));
  163. factor = _mm_set1_ps(*(float *) cl_arg);
  164. unsigned int i;
  165. for (i = 0; i < n_iterations; i++)
  166. VECTOR[i] = _mm_mul_ps(factor, VECTOR[i]);
  167. }
  168. \endcode
  169. \code{.c}
  170. struct starpu_codelet cl =
  171. {
  172. .cpu_funcs = { scal_cpu_func, scal_sse_func },
  173. .cpu_funcs_name = { "scal_cpu_func", "scal_sse_func" },
  174. .nbuffers = 1,
  175. .modes = { STARPU_RW }
  176. };
  177. \endcode
  178. Schedulers which are multi-implementation aware (only <c>dmda</c> and
  179. <c>pheft</c> for now) will use the performance models of all the
  180. implementations it was given, and pick the one which seems to be the fastest.
  181. \section EnablingImplementationAccordingToCapabilities Enabling Implementation According To Capabilities
  182. Some implementations may not run on some devices. For instance, some CUDA
  183. devices do not support double floating point precision, and thus the kernel
  184. execution would just fail; or the device may not have enough shared memory for
  185. the implementation being used. The field starpu_codelet::can_execute
  186. permits to express this. For instance:
  187. \code{.c}
  188. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  189. {
  190. const struct cudaDeviceProp *props;
  191. if (starpu_worker_get_type(workerid) == STARPU_CPU_WORKER)
  192. return 1;
  193. /* Cuda device */
  194. props = starpu_cuda_get_device_properties(workerid);
  195. if (props->major >= 2 || props->minor >= 3)
  196. /* At least compute capability 1.3, supports doubles */
  197. return 1;
  198. /* Old card, does not support doubles */
  199. return 0;
  200. }
  201. struct starpu_codelet cl =
  202. {
  203. .can_execute = can_execute,
  204. .cpu_funcs = { cpu_func },
  205. .cpu_funcs_name = { "cpu_func" },
  206. .cuda_funcs = { gpu_func }
  207. .nbuffers = 1,
  208. .modes = { STARPU_RW }
  209. };
  210. \endcode
  211. This can be essential e.g. when running on a machine which mixes various models
  212. of CUDA devices, to take benefit from the new models without crashing on old models.
  213. Note: the function starpu_codelet::can_execute is called by the
  214. scheduler each time it tries to match a task with a worker, and should
  215. thus be very fast. The function starpu_cuda_get_device_properties()
  216. provides a quick access to CUDA properties of CUDA devices to achieve
  217. such efficiency.
  218. Another example is to compile CUDA code for various compute capabilities,
  219. resulting with two CUDA functions, e.g. <c>scal_gpu_13</c> for compute capability
  220. 1.3, and <c>scal_gpu_20</c> for compute capability 2.0. Both functions can be
  221. provided to StarPU by using starpu_codelet::cuda_funcs, and
  222. starpu_codelet::can_execute can then be used to rule out the
  223. <c>scal_gpu_20</c> variant on a CUDA device which will not be able to execute it:
  224. \code{.c}
  225. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  226. {
  227. const struct cudaDeviceProp *props;
  228. if (starpu_worker_get_type(workerid) == STARPU_CPU_WORKER)
  229. return 1;
  230. /* Cuda device */
  231. if (nimpl == 0)
  232. /* Trying to execute the 1.3 capability variant, we assume it is ok in all cases. */
  233. return 1;
  234. /* Trying to execute the 2.0 capability variant, check that the card can do it. */
  235. props = starpu_cuda_get_device_properties(workerid);
  236. if (props->major >= 2 || props->minor >= 0)
  237. /* At least compute capability 2.0, can run it */
  238. return 1;
  239. /* Old card, does not support 2.0, will not be able to execute the 2.0 variant. */
  240. return 0;
  241. }
  242. struct starpu_codelet cl =
  243. {
  244. .can_execute = can_execute,
  245. .cpu_funcs = { cpu_func },
  246. .cpu_funcs_name = { "cpu_func" },
  247. .cuda_funcs = { scal_gpu_13, scal_gpu_20 },
  248. .nbuffers = 1,
  249. .modes = { STARPU_RW }
  250. };
  251. \endcode
  252. Another example is having specialized implementations for some given common
  253. sizes, for instance here we have a specialized implementation for 1024x1024
  254. matrices:
  255. \code{.c}
  256. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  257. {
  258. const struct cudaDeviceProp *props;
  259. if (starpu_worker_get_type(workerid) == STARPU_CPU_WORKER)
  260. return 1;
  261. /* Cuda device */
  262. switch (nimpl)
  263. {
  264. case 0:
  265. /* Trying to execute the generic capability variant. */
  266. return 1;
  267. case 1:
  268. {
  269. /* Trying to execute the size == 1024 specific variant. */
  270. struct starpu_matrix_interface *interface = starpu_data_get_interface_on_node(task->handles[0]);
  271. return STARPU_MATRIX_GET_NX(interface) == 1024 && STARPU_MATRIX_GET_NY(interface == 1024);
  272. }
  273. }
  274. }
  275. struct starpu_codelet cl =
  276. {
  277. .can_execute = can_execute,
  278. .cpu_funcs = { cpu_func },
  279. .cpu_funcs_name = { "cpu_func" },
  280. .cuda_funcs = { potrf_gpu_generic, potrf_gpu_1024 },
  281. .nbuffers = 1,
  282. .modes = { STARPU_RW }
  283. };
  284. \endcode
  285. Note: the most generic variant should be provided first, as some schedulers are
  286. not able to try the different variants.
  287. \section InsertTaskUtility Insert Task Utility
  288. StarPU provides the wrapper function starpu_task_insert() to ease
  289. the creation and submission of tasks.
  290. Here the implementation of the codelet:
  291. \code{.c}
  292. void func_cpu(void *descr[], void *_args)
  293. {
  294. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  295. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  296. int ifactor;
  297. float ffactor;
  298. starpu_codelet_unpack_args(_args, &ifactor, &ffactor);
  299. *x0 = *x0 * ifactor;
  300. *x1 = *x1 * ffactor;
  301. }
  302. struct starpu_codelet mycodelet =
  303. {
  304. .cpu_funcs = { func_cpu },
  305. .cpu_funcs_name = { "func_cpu" },
  306. .nbuffers = 2,
  307. .modes = { STARPU_RW, STARPU_RW }
  308. };
  309. \endcode
  310. And the call to the function starpu_task_insert():
  311. \code{.c}
  312. starpu_task_insert(&mycodelet,
  313. STARPU_VALUE, &ifactor, sizeof(ifactor),
  314. STARPU_VALUE, &ffactor, sizeof(ffactor),
  315. STARPU_RW, data_handles[0],
  316. STARPU_RW, data_handles[1],
  317. 0);
  318. \endcode
  319. The call to starpu_task_insert() is equivalent to the following
  320. code:
  321. \code{.c}
  322. struct starpu_task *task = starpu_task_create();
  323. task->cl = &mycodelet;
  324. task->handles[0] = data_handles[0];
  325. task->handles[1] = data_handles[1];
  326. char *arg_buffer;
  327. size_t arg_buffer_size;
  328. starpu_codelet_pack_args(&arg_buffer, &arg_buffer_size,
  329. STARPU_VALUE, &ifactor, sizeof(ifactor),
  330. STARPU_VALUE, &ffactor, sizeof(ffactor),
  331. 0);
  332. task->cl_arg = arg_buffer;
  333. task->cl_arg_size = arg_buffer_size;
  334. int ret = starpu_task_submit(task);
  335. \endcode
  336. Here a similar call using ::STARPU_DATA_ARRAY.
  337. \code{.c}
  338. starpu_task_insert(&mycodelet,
  339. STARPU_DATA_ARRAY, data_handles, 2,
  340. STARPU_VALUE, &ifactor, sizeof(ifactor),
  341. STARPU_VALUE, &ffactor, sizeof(ffactor),
  342. 0);
  343. \endcode
  344. If some part of the task insertion depends on the value of some computation,
  345. the macro ::STARPU_DATA_ACQUIRE_CB can be very convenient. For
  346. instance, assuming that the index variable <c>i</c> was registered as handle
  347. <c>A_handle[i]</c>:
  348. \code{.c}
  349. /* Compute which portion we will work on, e.g. pivot */
  350. starpu_task_insert(&which_index, STARPU_W, i_handle, 0);
  351. /* And submit the corresponding task */
  352. STARPU_DATA_ACQUIRE_CB(i_handle, STARPU_R,
  353. starpu_task_insert(&work, STARPU_RW, A_handle[i], 0));
  354. \endcode
  355. The macro ::STARPU_DATA_ACQUIRE_CB submits an asynchronous request for
  356. acquiring data <c>i</c> for the main application, and will execute the code
  357. given as third parameter when it is acquired. In other words, as soon as the
  358. value of <c>i</c> computed by the codelet <c>which_index</c> can be read, the
  359. portion of code passed as third parameter of ::STARPU_DATA_ACQUIRE_CB will
  360. be executed, and is allowed to read from <c>i</c> to use it e.g. as an
  361. index. Note that this macro is only avaible when compiling StarPU with
  362. the compiler <c>gcc</c>.
  363. There is several ways of calling the function starpu_codelet_unpack_args().
  364. \code{.c}
  365. void func_cpu(void *descr[], void *_args)
  366. {
  367. int ifactor;
  368. float ffactor;
  369. starpu_codelet_unpack_args(_args, &ifactor, &ffactor);
  370. }
  371. \endcode
  372. \code{.c}
  373. void func_cpu(void *descr[], void *_args)
  374. {
  375. int ifactor;
  376. float ffactor;
  377. starpu_codelet_unpack_args(_args, &ifactor, 0);
  378. starpu_codelet_unpack_args(_args, &ifactor, &ffactor);
  379. }
  380. \endcode
  381. \code{.c}
  382. void func_cpu(void *descr[], void *_args)
  383. {
  384. int ifactor;
  385. float ffactor;
  386. char buffer[100];
  387. starpu_codelet_unpack_args_and_copyleft(_args, buffer, 100, &ifactor, 0);
  388. starpu_codelet_unpack_args(buffer, &ffactor);
  389. }
  390. \endcode
  391. \section GettingTaskChildren Getting Task Children
  392. It may be interesting to get the list of tasks which depend on a given task,
  393. notably when using implicit dependencies, since this list is computed by StarPU.
  394. starpu_task_get_task_succs() provides it. For instance:
  395. \code{.c}
  396. struct starpu_task *tasks[4];
  397. ret = starpu_task_get_task_succs(task, sizeof(tasks)/sizeof(*tasks), tasks);
  398. \endcode
  399. \section ParallelTasks Parallel Tasks
  400. StarPU can leverage existing parallel computation libraries by the means of
  401. parallel tasks. A parallel task is a task which gets worked on by a set of CPUs
  402. (called a parallel or combined worker) at the same time, by using an existing
  403. parallel CPU implementation of the computation to be achieved. This can also be
  404. useful to improve the load balance between slow CPUs and fast GPUs: since CPUs
  405. work collectively on a single task, the completion time of tasks on CPUs become
  406. comparable to the completion time on GPUs, thus relieving from granularity
  407. discrepancy concerns. <c>hwloc</c> support needs to be enabled to get
  408. good performance, otherwise StarPU will not know how to better group
  409. cores.
  410. Two modes of execution exist to accomodate with existing usages.
  411. \subsection Fork-modeParallelTasks Fork-mode Parallel Tasks
  412. In the Fork mode, StarPU will call the codelet function on one
  413. of the CPUs of the combined worker. The codelet function can use
  414. starpu_combined_worker_get_size() to get the number of threads it is
  415. allowed to start to achieve the computation. The CPU binding mask for the whole
  416. set of CPUs is already enforced, so that threads created by the function will
  417. inherit the mask, and thus execute where StarPU expected, the OS being in charge
  418. of choosing how to schedule threads on the corresponding CPUs. The application
  419. can also choose to bind threads by hand, using e.g. <c>sched_getaffinity</c> to know
  420. the CPU binding mask that StarPU chose.
  421. For instance, using OpenMP (full source is available in
  422. <c>examples/openmp/vector_scal.c</c>):
  423. \snippet forkmode.c To be included. You should update doxygen if you see this text.
  424. Other examples include for instance calling a BLAS parallel CPU implementation
  425. (see <c>examples/mult/xgemm.c</c>).
  426. \subsection SPMD-modeParallelTasks SPMD-mode Parallel Tasks
  427. In the SPMD mode, StarPU will call the codelet function on
  428. each CPU of the combined worker. The codelet function can use
  429. starpu_combined_worker_get_size() to get the total number of CPUs
  430. involved in the combined worker, and thus the number of calls that are made in
  431. parallel to the function, and starpu_combined_worker_get_rank() to get
  432. the rank of the current CPU within the combined worker. For instance:
  433. \code{.c}
  434. static void func(void *buffers[], void *args)
  435. {
  436. unsigned i;
  437. float *factor = _args;
  438. struct starpu_vector_interface *vector = buffers[0];
  439. unsigned n = STARPU_VECTOR_GET_NX(vector);
  440. float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
  441. /* Compute slice to compute */
  442. unsigned m = starpu_combined_worker_get_size();
  443. unsigned j = starpu_combined_worker_get_rank();
  444. unsigned slice = (n+m-1)/m;
  445. for (i = j * slice; i < (j+1) * slice && i < n; i++)
  446. val[i] *= *factor;
  447. }
  448. static struct starpu_codelet cl =
  449. {
  450. .modes = { STARPU_RW },
  451. .type = STARPU_SPMD,
  452. .max_parallelism = INT_MAX,
  453. .cpu_funcs = { func },
  454. .cpu_funcs_name = { "func" },
  455. .nbuffers = 1,
  456. }
  457. \endcode
  458. Of course, this trivial example will not really benefit from parallel task
  459. execution, and was only meant to be simple to understand. The benefit comes
  460. when the computation to be done is so that threads have to e.g. exchange
  461. intermediate results, or write to the data in a complex but safe way in the same
  462. buffer.
  463. \subsection ParallelTasksPerformance Parallel Tasks Performance
  464. To benefit from parallel tasks, a parallel-task-aware StarPU scheduler has to
  465. be used. When exposed to codelets with a flag ::STARPU_FORKJOIN or
  466. ::STARPU_SPMD, the schedulers <c>pheft</c> (parallel-heft) and <c>peager</c>
  467. (parallel eager) will indeed also try to execute tasks with
  468. several CPUs. It will automatically try the various available combined
  469. worker sizes (making several measurements for each worker size) and
  470. thus be able to avoid choosing a large combined worker if the codelet
  471. does not actually scale so much.
  472. \subsection CombinedWorkers Combined Workers
  473. By default, StarPU creates combined workers according to the architecture
  474. structure as detected by <c>hwloc</c>. It means that for each object of the <c>hwloc</c>
  475. topology (NUMA node, socket, cache, ...) a combined worker will be created. If
  476. some nodes of the hierarchy have a big arity (e.g. many cores in a socket
  477. without a hierarchy of shared caches), StarPU will create combined workers of
  478. intermediate sizes. The variable \ref STARPU_SYNTHESIZE_ARITY_COMBINED_WORKER
  479. permits to tune the maximum arity between levels of combined workers.
  480. The combined workers actually produced can be seen in the output of the
  481. tool <c>starpu_machine_display</c> (the environment variable
  482. \ref STARPU_SCHED has to be set to a combined worker-aware scheduler such
  483. as <c>pheft</c> or <c>peager</c>).
  484. \subsection ConcurrentParallelTasks Concurrent Parallel Tasks
  485. Unfortunately, many environments and librairies do not support concurrent
  486. calls.
  487. For instance, most OpenMP implementations (including the main ones) do not
  488. support concurrent <c>pragma omp parallel</c> statements without nesting them in
  489. another <c>pragma omp parallel</c> statement, but StarPU does not yet support
  490. creating its CPU workers by using such pragma.
  491. Other parallel libraries are also not safe when being invoked concurrently
  492. from different threads, due to the use of global variables in their sequential
  493. sections for instance.
  494. The solution is then to use only one combined worker at a time. This can be
  495. done by setting the field starpu_conf::single_combined_worker to <c>1</c>, or
  496. setting the environment variable \ref STARPU_SINGLE_COMBINED_WORKER
  497. to <c>1</c>. StarPU will then run only one parallel task at a time (but other
  498. CPU and GPU tasks are not affected and can be run concurrently). The parallel
  499. task scheduler will however still try varying combined worker
  500. sizes to look for the most efficient ones.
  501. \subsection SynchronizationTasks Synchronization Tasks
  502. For the application conveniency, it may be useful to define tasks which do not
  503. actually make any computation, but wear for instance dependencies between other
  504. tasks or tags, or to be submitted in callbacks, etc.
  505. The obvious way is of course to make kernel functions empty, but such task will
  506. thus have to wait for a worker to become ready, transfer data, etc.
  507. A much lighter way to define a synchronization task is to set its starpu_task::cl
  508. field to <c>NULL</c>. The task will thus be a mere synchronization point,
  509. without any data access or execution content: as soon as its dependencies become
  510. available, it will terminate, call the callbacks, and release dependencies.
  511. An intermediate solution is to define a codelet with its
  512. starpu_codelet::where field set to \ref STARPU_NOWHERE, for instance:
  513. \code{.c}
  514. struct starpu_codelet cl =
  515. {
  516. .where = STARPU_NOWHERE,
  517. .nbuffers = 1,
  518. .modes = { STARPU_R },
  519. }
  520. task = starpu_task_create();
  521. task->cl = &cl;
  522. task->handles[0] = handle;
  523. starpu_task_submit(task);
  524. \endcode
  525. will create a task which simply waits for the value of <c>handle</c> to be
  526. available for read. This task can then be depended on, etc.
  527. */