starpu_openmp.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __STARPU_OPENMP_H__
  17. #define __STARPU_OPENMP_H__
  18. #include <starpu_config.h>
  19. /**
  20. @defgroup API_OpenMP_Runtime_Support OpenMP Runtime Support
  21. @brief This section describes the interface provided for implementing OpenMP runtimes on top of StarPU.
  22. @{
  23. */
  24. #if defined STARPU_OPENMP
  25. /**
  26. Opaque Simple Lock object (\anchor SimpleLock) for inter-task
  27. synchronization operations.
  28. \sa starpu_omp_init_lock()
  29. \sa starpu_omp_destroy_lock()
  30. \sa starpu_omp_set_lock()
  31. \sa starpu_omp_unset_lock()
  32. \sa starpu_omp_test_lock()
  33. */
  34. typedef struct { void *internal; /**< opaque pointer for internal use */ } starpu_omp_lock_t;
  35. /**
  36. Opaque Nestable Lock object (\anchor NestableLock) for inter-task
  37. synchronization operations.
  38. \sa starpu_omp_init_nest_lock()
  39. \sa starpu_omp_destroy_nest_lock()
  40. \sa starpu_omp_set_nest_lock()
  41. \sa starpu_omp_unset_nest_lock()
  42. \sa starpu_omp_test_nest_lock()
  43. */
  44. typedef struct { void *internal; /**< opaque pointer for internal use */ } starpu_omp_nest_lock_t;
  45. /**
  46. Set of constants for selecting the for loop iteration scheduling
  47. algorithm (\anchor OMPFor) as defined by the OpenMP specification.
  48. \sa starpu_omp_for()
  49. \sa starpu_omp_for_inline_first()
  50. \sa starpu_omp_for_inline_next()
  51. \sa starpu_omp_for_alt()
  52. \sa starpu_omp_for_inline_first_alt()
  53. \sa starpu_omp_for_inline_next_alt()
  54. */
  55. enum starpu_omp_sched_value
  56. {
  57. starpu_omp_sched_undefined = 0, /**< Undefined iteration scheduling algorithm. */
  58. starpu_omp_sched_static = 1, /**< \b Static iteration scheduling algorithm.*/
  59. starpu_omp_sched_dynamic = 2, /**< \b Dynamic iteration scheduling algorithm.*/
  60. starpu_omp_sched_guided = 3, /**< \b Guided iteration scheduling algorithm.*/
  61. starpu_omp_sched_auto = 4, /**< \b Automatically choosen iteration scheduling algorithm.*/
  62. starpu_omp_sched_runtime = 5 /**< Choice of iteration scheduling algorithm deferred at \b runtime.*/
  63. };
  64. /**
  65. Set of constants for selecting the processor binding method, as
  66. defined in the OpenMP specification.
  67. \sa starpu_omp_get_proc_bind()
  68. */
  69. enum starpu_omp_proc_bind_value
  70. {
  71. starpu_omp_proc_bind_undefined = -1, /**< Undefined processor binding method.*/
  72. starpu_omp_proc_bind_false = 0, /**< Team threads may be moved between places at any time.*/
  73. starpu_omp_proc_bind_true = 1, /**< Team threads may not be moved between places.*/
  74. starpu_omp_proc_bind_master = 2, /**< Assign every thread in the team to the same place as the \b master thread.*/
  75. starpu_omp_proc_bind_close = 3, /**< Assign every thread in the team to a place \b close to the parent thread.*/
  76. starpu_omp_proc_bind_spread = 4 /**< Assign team threads as a sparse distribution over the selected places.*/
  77. };
  78. /**
  79. Set of attributes used for creating a new parallel region.
  80. \sa starpu_omp_parallel_region()
  81. */
  82. struct starpu_omp_parallel_region_attr
  83. {
  84. /**
  85. ::starpu_codelet (\ref API_Codelet_And_Tasks) to use for the
  86. parallel region implicit tasks. The codelet must provide a
  87. CPU implementation function.
  88. */
  89. struct starpu_codelet cl;
  90. /**
  91. Array of zero or more ::starpu_data_handle_t data handle to
  92. be passed to the parallel region implicit tasks.
  93. */
  94. starpu_data_handle_t *handles;
  95. /**
  96. Optional pointer to an inline argument to be passed to the
  97. region implicit tasks.
  98. */
  99. void *cl_arg;
  100. /**
  101. Size of the optional inline argument to be passed to the
  102. region implicit tasks, or 0 if unused.
  103. */
  104. size_t cl_arg_size;
  105. /**
  106. Boolean indicating whether the optional inline argument
  107. should be automatically freed (true), or not (false).
  108. */
  109. unsigned cl_arg_free;
  110. /**
  111. Boolean indicating whether the \b if clause of the
  112. corresponding <c>pragma omp parallel</c> is true or false.
  113. */
  114. int if_clause;
  115. /**
  116. Integer indicating the requested number of threads in the
  117. team of the newly created parallel region, or 0 to let the
  118. runtime choose the number of threads alone. This attribute
  119. may be ignored by the runtime system if the requested
  120. number of threads is higher than the number of threads that
  121. the runtime can create.
  122. */
  123. int num_threads;
  124. };
  125. /**
  126. Set of attributes used for creating a new task region.
  127. \sa starpu_omp_task_region()
  128. */
  129. struct starpu_omp_task_region_attr
  130. {
  131. /**
  132. ::starpu_codelet (\ref API_Codelet_And_Tasks) to use for
  133. the task region explicit task. The codelet must provide a
  134. CPU implementation function or an accelerator
  135. implementation for offloaded target regions.
  136. */
  137. struct starpu_codelet cl;
  138. /**
  139. Array of zero or more ::starpu_data_handle_t data handle to
  140. be passed to the task region explicit tasks.
  141. */
  142. starpu_data_handle_t *handles;
  143. /**
  144. Optional pointer to an inline argument to be passed to the
  145. region implicit tasks.
  146. */
  147. void *cl_arg;
  148. /**
  149. Size of the optional inline argument to be passed to the
  150. region implicit tasks, or 0 if unused.
  151. */
  152. size_t cl_arg_size;
  153. /**
  154. Boolean indicating whether the optional inline argument
  155. should be automatically freed (true), or not (false).
  156. */
  157. unsigned cl_arg_free;
  158. int priority;
  159. /**
  160. Boolean indicating whether the \b if clause of the
  161. corresponding <c>pragma omp task</c> is true or false.
  162. */
  163. int if_clause;
  164. /**
  165. Boolean indicating whether the \b final clause of the
  166. corresponding <c>pragma omp task</c> is true or false.
  167. */
  168. int final_clause;
  169. /**
  170. Boolean indicating whether the \b untied clause of the
  171. corresponding <c>pragma omp task</c> is true or false.
  172. */
  173. int untied_clause;
  174. /**
  175. Boolean indicating whether the \b mergeable clause of the
  176. corresponding <c>pragma omp task</c> is true or false.
  177. */
  178. int mergeable_clause;
  179. /**
  180. taskloop attribute
  181. */
  182. int is_loop;
  183. int nogroup_clause;
  184. int collapse;
  185. int num_tasks;
  186. unsigned long long nb_iterations;
  187. unsigned long long grainsize;
  188. unsigned long long begin_i;
  189. unsigned long long end_i;
  190. unsigned long long chunk;
  191. };
  192. #ifdef __cplusplus
  193. extern "C"
  194. {
  195. #define __STARPU_OMP_NOTHROW throw ()
  196. #else
  197. #define __STARPU_OMP_NOTHROW __attribute__((__nothrow__))
  198. #endif
  199. /**
  200. @name Initialisation
  201. @{
  202. */
  203. /**
  204. Initialize StarPU and its OpenMP Runtime support.
  205. */
  206. extern int starpu_omp_init(void) __STARPU_OMP_NOTHROW;
  207. /**
  208. Shutdown StarPU and its OpenMP Runtime support.
  209. */
  210. extern void starpu_omp_shutdown(void) __STARPU_OMP_NOTHROW;
  211. /** @} */
  212. /**
  213. @name Parallel
  214. \anchor ORS_Parallel
  215. @{
  216. */
  217. /**
  218. Generate and launch an OpenMP parallel region and return after its
  219. completion. \p attr specifies the attributes for the generated parallel region.
  220. If this function is called from inside another, generating, parallel region, the
  221. generated parallel region is nested within the generating parallel region.
  222. This function can be used to implement <c>\#pragma omp parallel</c>.
  223. */
  224. extern void starpu_omp_parallel_region(const struct starpu_omp_parallel_region_attr *attr) __STARPU_OMP_NOTHROW;
  225. /**
  226. Execute a function only on the master thread of the OpenMP
  227. parallel region it is called from. When called from a thread that is not the
  228. master of the parallel region it is called from, this function does nothing. \p
  229. f is the function to be called. \p arg is an argument passed to function \p f.
  230. This function can be used to implement <c>\#pragma omp master</c>.
  231. */
  232. extern void starpu_omp_master(void (*f)(void *arg), void *arg) __STARPU_OMP_NOTHROW;
  233. /**
  234. Determine whether the calling thread is the master of the OpenMP parallel region
  235. it is called from or not.
  236. This function can be used to implement <c>\#pragma omp master</c> without code
  237. outlining.
  238. \return <c>!0</c> if called by the region's master thread.
  239. \return <c>0</c> if not called by the region's master thread.
  240. */
  241. extern int starpu_omp_master_inline(void) __STARPU_OMP_NOTHROW;
  242. /** @} */
  243. /**
  244. @name Synchronization
  245. \anchor ORS_Synchronization
  246. @{
  247. */
  248. /**
  249. Wait until each participating thread of the innermost OpenMP parallel region
  250. has reached the barrier and each explicit OpenMP task bound to this region has
  251. completed its execution.
  252. This function can be used to implement <c>\#pragma omp barrier</c>.
  253. */
  254. extern void starpu_omp_barrier(void) __STARPU_OMP_NOTHROW;
  255. /**
  256. Wait until no other thread is executing within the context of the selected
  257. critical section, then proceeds to the exclusive execution of a function within
  258. the critical section. \p f is the function to be executed in the critical
  259. section. \p arg is an argument passed to function \p f. \p name is the name of
  260. the selected critical section. If <c>name == NULL</c>, the selected critical
  261. section is the unique anonymous critical section.
  262. This function can be used to implement <c>\#pragma omp
  263. critical</c>.
  264. */
  265. extern void starpu_omp_critical(void (*f)(void *arg), void *arg, const char *name) __STARPU_OMP_NOTHROW;
  266. /**
  267. Wait until execution can proceed exclusively within the context of the
  268. selected critical section. \p name is the name of the selected critical
  269. section. If <c>name == NULL</c>, the selected critical section is the unique
  270. anonymous critical section.
  271. This function together with #starpu_omp_critical_inline_end can be used to
  272. implement <c>\#pragma omp critical</c> without code outlining.
  273. */
  274. extern void starpu_omp_critical_inline_begin(const char *name) __STARPU_OMP_NOTHROW;
  275. /**
  276. End the exclusive execution within the context of the selected critical
  277. section. \p name is the name of the selected critical section. If
  278. <c>name==NULL</c>, the selected critical section is the unique anonymous
  279. critical section.
  280. This function together with #starpu_omp_critical_inline_begin can be used to
  281. implement <c>\#pragma omp critical</c> without code outlining.
  282. */
  283. extern void starpu_omp_critical_inline_end(const char *name) __STARPU_OMP_NOTHROW;
  284. /** @} */
  285. /**
  286. @name Worksharing
  287. \anchor ORS_Worksharing
  288. @{
  289. */
  290. /**
  291. Ensure that a single participating thread of the innermost OpenMP parallel
  292. region executes a function. \p f is the function to be executed by a single
  293. thread. \p arg is an argument passed to function \p f. \p nowait is a flag
  294. indicating whether an implicit barrier is requested after the single section
  295. (<c>nowait==0</c>) or not (<c>nowait==!0</c>).
  296. This function can be used to implement <c>\#pragma omp single</c>.
  297. */
  298. extern void starpu_omp_single(void (*f)(void *arg), void *arg, int nowait) __STARPU_OMP_NOTHROW;
  299. /**
  300. Decide whether the current thread is elected to run the following single
  301. section among the participating threads of the innermost OpenMP parallel
  302. region.
  303. This function can be used to implement <c>\#pragma omp single</c> without code
  304. outlining.
  305. \return <c>!0</c> if the calling thread has won the election.
  306. \return <c>0</c> if the calling thread has lost the election.
  307. */
  308. extern int starpu_omp_single_inline(void) __STARPU_OMP_NOTHROW;
  309. /**
  310. Execute \p f on a single task of the current parallel region
  311. task, and then broadcast the contents of the memory block pointed by the
  312. copyprivate pointer \p data and of size \p data_size to the corresponding \p
  313. data pointed memory blocks of all the other participating region tasks. This
  314. function can be used to implement <c>\#pragma omp single</c> with a copyprivate
  315. clause.
  316. \sa starpu_omp_single_copyprivate_inline
  317. \sa starpu_omp_single_copyprivate_inline_begin
  318. \sa starpu_omp_single_copyprivate_inline_end
  319. */
  320. extern void starpu_omp_single_copyprivate(void (*f)(void *arg, void *data, unsigned long long data_size), void *arg, void *data, unsigned long long data_size) __STARPU_OMP_NOTHROW;
  321. /**
  322. Elect one task among the tasks of the current parallel region
  323. task to execute the following single section, and then broadcast the
  324. copyprivate pointer \p data to all the other participating region tasks. This
  325. function can be used to implement <c>\#pragma omp single</c> with a copyprivate
  326. clause without code outlining.
  327. \sa starpu_omp_single_copyprivate_inline
  328. \sa starpu_omp_single_copyprivate_inline_end
  329. */
  330. extern void *starpu_omp_single_copyprivate_inline_begin(void *data) __STARPU_OMP_NOTHROW;
  331. /**
  332. Complete the execution of a single section and return the
  333. broadcasted copyprivate pointer for tasks that lost the election and <c>NULL</c> for
  334. the task that won the election. This function can be used to implement
  335. <c>\#pragma omp single</c> with a copyprivate clause without code outlining.
  336. \return the copyprivate pointer for tasks that lost the election and therefore did not execute the code of the single section.
  337. \return <c>NULL</c> for the task that won the election and executed the code of the single section.
  338. \sa starpu_omp_single_copyprivate_inline
  339. \sa starpu_omp_single_copyprivate_inline_begin
  340. */
  341. extern void starpu_omp_single_copyprivate_inline_end(void) __STARPU_OMP_NOTHROW;
  342. /**
  343. Execute a parallel loop together with the other threads participating to the
  344. innermost parallel region. \p f is the function to be executed iteratively. \p
  345. arg is an argument passed to function \p f. \p nb_iterations is the number of
  346. iterations to be performed by the parallel loop. \p chunk is the number of
  347. consecutive iterations that should be affected to the same thread when
  348. scheduling the loop workshares, it follows the semantics of the \c modifier
  349. argument in OpenMP <c>\#pragma omp for</c> specification. \p schedule is the
  350. scheduling mode according to the OpenMP specification. \p ordered is a flag
  351. indicating whether the loop region may contain an ordered section
  352. (<c>ordered==!0</c>) or not (<c>ordered==0</c>). \p nowait is a flag
  353. indicating whether an implicit barrier is requested after the for section
  354. (<c>nowait==0</c>) or not (<c>nowait==!0</c>).
  355. The function \p f will be called with arguments \p _first_i, the first iteration
  356. to perform, \p _nb_i, the number of consecutive iterations to perform before
  357. returning, \p arg, the free \p arg argument.
  358. This function can be used to implement <c>\#pragma omp for</c>.
  359. */
  360. extern void starpu_omp_for(void (*f)(unsigned long long _first_i, unsigned long long _nb_i, void *arg), void *arg, unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, int nowait) __STARPU_OMP_NOTHROW;
  361. /**
  362. Decide whether the current thread should start to execute a parallel loop
  363. section. See #starpu_omp_for for the argument description.
  364. This function together with #starpu_omp_for_inline_next can be used to
  365. implement <c>\#pragma omp for</c> without code outlining.
  366. \return <c>!0</c> if the calling thread participates to the loop region and
  367. should execute a first chunk of iterations. In that case, \p *_first_i will be
  368. set to the first iteration of the chunk to perform and \p *_nb_i will be set to
  369. the number of iterations of the chunk to perform.
  370. \return <c>0</c> if the calling thread does not participate to the loop region
  371. because all the available iterations have been affected to the other threads of
  372. the parallel region.
  373. \sa starpu_omp_for
  374. */
  375. extern int starpu_omp_for_inline_first(unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, unsigned long long *_first_i, unsigned long long *_nb_i) __STARPU_OMP_NOTHROW;
  376. /**
  377. Decide whether the current thread should continue to execute a parallel loop
  378. section. See #starpu_omp_for for the argument description.
  379. This function together with #starpu_omp_for_inline_first can be used to
  380. implement <c>\#pragma omp for</c> without code outlining.
  381. \return <c>!0</c> if the calling thread should execute a next chunk of
  382. iterations. In that case, \p *_first_i will be set to the first iteration of the
  383. chunk to perform and \p *_nb_i will be set to the number of iterations of the
  384. chunk to perform.
  385. \return <c>0</c> if the calling thread does not participate anymore to the loop
  386. region because all the available iterations have been affected to the other
  387. threads of the parallel region.
  388. \sa starpu_omp_for
  389. */
  390. extern int starpu_omp_for_inline_next(unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, unsigned long long *_first_i, unsigned long long *_nb_i) __STARPU_OMP_NOTHROW;
  391. /**
  392. Alternative implementation of a parallel loop. Differ from
  393. #starpu_omp_for in the expected arguments of the loop function \c f.
  394. The function \p f will be called with arguments \p _begin_i, the first iteration
  395. to perform, \p _end_i, the first iteration not to perform before
  396. returning, \p arg, the free \p arg argument.
  397. This function can be used to implement <c>\#pragma omp for</c>.
  398. \sa starpu_omp_for
  399. */
  400. extern void starpu_omp_for_alt(void (*f)(unsigned long long _begin_i, unsigned long long _end_i, void *arg), void *arg, unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, int nowait) __STARPU_OMP_NOTHROW;
  401. /**
  402. Inline version of the alternative implementation of a parallel loop.
  403. This function together with #starpu_omp_for_inline_next_alt can be used to
  404. implement <c>\#pragma omp for</c> without code outlining.
  405. \sa starpu_omp_for
  406. \sa starpu_omp_for_alt
  407. \sa starpu_omp_for_inline_first
  408. */
  409. extern int starpu_omp_for_inline_first_alt(unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, unsigned long long *_begin_i, unsigned long long *_end_i) __STARPU_OMP_NOTHROW;
  410. /**
  411. Inline version of the alternative implementation of a parallel loop.
  412. This function together with #starpu_omp_for_inline_first_alt can be used to
  413. implement <c>\#pragma omp for</c> without code outlining.
  414. \sa starpu_omp_for
  415. \sa starpu_omp_for_alt
  416. \sa starpu_omp_for_inline_next
  417. */
  418. extern int starpu_omp_for_inline_next_alt(unsigned long long nb_iterations, unsigned long long chunk, int schedule, int ordered, unsigned long long *_begin_i, unsigned long long *_end_i) __STARPU_OMP_NOTHROW;
  419. /**
  420. Ensure that a function is sequentially executed once for each iteration in
  421. order within a parallel loop, by the thread that own the iteration. \p f is the
  422. function to be executed by the thread that own the current iteration. \p arg is
  423. an argument passed to function \p f.
  424. This function can be used to implement <c>\#pragma omp ordered</c>.
  425. */
  426. extern void starpu_omp_ordered(void (*f)(void *arg), void *arg) __STARPU_OMP_NOTHROW;
  427. /**
  428. Wait until all the iterations of a parallel loop below the iteration owned by
  429. the current thread have been executed.
  430. This function together with #starpu_omp_ordered_inline_end can be used to
  431. implement <c>\#pragma omp ordered</c> without code code outlining.
  432. */
  433. extern void starpu_omp_ordered_inline_begin(void) __STARPU_OMP_NOTHROW;
  434. /**
  435. Notify that the ordered section for the current iteration has been completed.
  436. This function together with #starpu_omp_ordered_inline_begin can be used to
  437. implement <c>\#pragma omp ordered</c> without code code outlining.
  438. */
  439. extern void starpu_omp_ordered_inline_end(void) __STARPU_OMP_NOTHROW;
  440. /**
  441. Ensure that each function of a given array of functions is executed by one and
  442. only one thread. \p nb_sections is the number of functions in the array \p
  443. section_f. \p section_f is the array of functions to be executed as sections. \p
  444. section_arg is an array of arguments to be passed to the corresponding function.
  445. \p nowait is a flag indicating whether an implicit barrier is requested after
  446. the execution of all the sections (<c>nowait==0</c>) or not (<c>nowait==!0</c>).
  447. This function can be used to implement <c>\#pragma omp sections</c> and <c>\#pragma omp section</c>.
  448. */
  449. extern void starpu_omp_sections(unsigned long long nb_sections, void (**section_f)(void *arg), void **section_arg, int nowait) __STARPU_OMP_NOTHROW;
  450. /**
  451. Alternative implementation of sections. Differ from
  452. #starpu_omp_sections in that all the sections are combined within a single
  453. function in this version. \p section_f is the function implementing the combined
  454. sections.
  455. The function \p section_f will be called with arguments \p section_num, the
  456. section number to be executed, \p arg, the entry of \p section_arg corresponding
  457. to this section.
  458. This function can be used to implement <c>\#pragma omp sections</c> and <c>\#pragma omp section</c>.
  459. \sa starpu_omp_sections
  460. */
  461. extern void starpu_omp_sections_combined(unsigned long long nb_sections, void (*section_f)(unsigned long long section_num, void *arg), void *section_arg, int nowait) __STARPU_OMP_NOTHROW;
  462. /** @} */
  463. /**
  464. @name Task
  465. \anchor ORS_Task
  466. @{
  467. */
  468. /**
  469. Generate an explicit child task. The execution of the generated task is
  470. asynchronous with respect to the calling code unless specified otherwise.
  471. \p attr specifies the attributes for the generated task region.
  472. This function can be used to implement <c>\#pragma omp task</c>.
  473. */
  474. extern void starpu_omp_task_region(const struct starpu_omp_task_region_attr *attr) __STARPU_OMP_NOTHROW;
  475. /**
  476. Wait for the completion of the tasks generated by the current task. This
  477. function does not wait for the descendants of the tasks generated by the current
  478. task.
  479. This function can be used to implement <c>\#pragma omp taskwait</c>.
  480. */
  481. extern void starpu_omp_taskwait(void) __STARPU_OMP_NOTHROW;
  482. /**
  483. Launch a function and wait for the completion of every descendant task
  484. generated during the execution of the function.
  485. This function can be used to implement <c>\#pragma omp taskgroup</c>.
  486. \sa starpu_omp_taskgroup_inline_begin
  487. \sa starpu_omp_taskgroup_inline_end
  488. */
  489. extern void starpu_omp_taskgroup(void (*f)(void *arg), void *arg) __STARPU_OMP_NOTHROW;
  490. /**
  491. Launch a function and gets ready to wait for the completion of every descendant task
  492. generated during the dynamic scope of the taskgroup.
  493. This function can be used to implement <c>\#pragma omp taskgroup</c> without code outlining.
  494. \sa starpu_omp_taskgroup
  495. \sa starpu_omp_taskgroup_inline_end
  496. */
  497. extern void starpu_omp_taskgroup_inline_begin(void) __STARPU_OMP_NOTHROW;
  498. /**
  499. Wait for the completion of every descendant task
  500. generated during the dynamic scope of the taskgroup.
  501. This function can be used to implement <c>\#pragma omp taskgroup</c> without code outlining.
  502. \sa starpu_omp_taskgroup
  503. \sa starpu_omp_taskgroup_inline_begin
  504. */
  505. extern void starpu_omp_taskgroup_inline_end(void) __STARPU_OMP_NOTHROW;
  506. extern void starpu_omp_taskloop_inline_begin(struct starpu_omp_task_region_attr *attr) __STARPU_OMP_NOTHROW;
  507. extern void starpu_omp_taskloop_inline_end(const struct starpu_omp_task_region_attr *attr) __STARPU_OMP_NOTHROW;
  508. /** @} */
  509. /**
  510. @name API
  511. \anchor ORS_API
  512. @{
  513. */
  514. /**
  515. Set ICVS nthreads_var for the parallel regions to be created
  516. with the current region.
  517. Note: The StarPU OpenMP runtime support currently ignores
  518. this setting for nested parallel regions.
  519. \sa starpu_omp_get_num_threads
  520. \sa starpu_omp_get_thread_num
  521. \sa starpu_omp_get_max_threads
  522. \sa starpu_omp_get_num_procs
  523. */
  524. extern void starpu_omp_set_num_threads(int threads) __STARPU_OMP_NOTHROW;
  525. /**
  526. Return the number of threads of the current region.
  527. \return the number of threads of the current region.
  528. \sa starpu_omp_set_num_threads
  529. \sa starpu_omp_get_thread_num
  530. \sa starpu_omp_get_max_threads
  531. \sa starpu_omp_get_num_procs
  532. */
  533. extern int starpu_omp_get_num_threads(void) __STARPU_OMP_NOTHROW;
  534. /**
  535. Return the rank of the current thread among the threads
  536. of the current region.
  537. \return the rank of the current thread in the current region.
  538. \sa starpu_omp_set_num_threads
  539. \sa starpu_omp_get_num_threads
  540. \sa starpu_omp_get_max_threads
  541. \sa starpu_omp_get_num_procs
  542. */
  543. extern int starpu_omp_get_thread_num(void) __STARPU_OMP_NOTHROW;
  544. /**
  545. Return the maximum number of threads that can be used to
  546. create a region from the current region.
  547. \return the maximum number of threads that can be used to create a region from the current region.
  548. \sa starpu_omp_set_num_threads
  549. \sa starpu_omp_get_num_threads
  550. \sa starpu_omp_get_thread_num
  551. \sa starpu_omp_get_num_procs
  552. */
  553. extern int starpu_omp_get_max_threads(void) __STARPU_OMP_NOTHROW;
  554. /**
  555. Return the number of StarPU CPU workers.
  556. \return the number of StarPU CPU workers.
  557. \sa starpu_omp_set_num_threads
  558. \sa starpu_omp_get_num_threads
  559. \sa starpu_omp_get_thread_num
  560. \sa starpu_omp_get_max_threads
  561. */
  562. extern int starpu_omp_get_num_procs(void) __STARPU_OMP_NOTHROW;
  563. /**
  564. Return whether it is called from the scope of a parallel region or not.
  565. \return <c>!0</c> if called from a parallel region scope.
  566. \return <c>0</c> otherwise.
  567. */
  568. extern int starpu_omp_in_parallel(void) __STARPU_OMP_NOTHROW;
  569. /**
  570. Enable (1) or disable (0) dynamically adjusting the number of parallel threads.
  571. Note: The StarPU OpenMP runtime support currently ignores the argument of this function.
  572. \sa starpu_omp_get_dynamic
  573. */
  574. extern void starpu_omp_set_dynamic(int dynamic_threads) __STARPU_OMP_NOTHROW;
  575. /**
  576. Return the state of dynamic thread number adjustment.
  577. \return <c>!0</c> if dynamic thread number adjustment is enabled.
  578. \return <c>0</c> otherwise.
  579. \sa starpu_omp_set_dynamic
  580. */
  581. extern int starpu_omp_get_dynamic(void) __STARPU_OMP_NOTHROW;
  582. /**
  583. Enable (1) or disable (0) nested parallel regions.
  584. Note: The StarPU OpenMP runtime support currently ignores the argument of this function.
  585. \sa starpu_omp_get_nested
  586. \sa starpu_omp_get_max_active_levels
  587. \sa starpu_omp_set_max_active_levels
  588. \sa starpu_omp_get_level
  589. \sa starpu_omp_get_active_level
  590. */
  591. extern void starpu_omp_set_nested(int nested) __STARPU_OMP_NOTHROW;
  592. /**
  593. Return whether nested parallel sections are enabled or not.
  594. \return <c>!0</c> if nested parallel sections are enabled.
  595. \return <c>0</c> otherwise.
  596. \sa starpu_omp_set_nested
  597. \sa starpu_omp_get_max_active_levels
  598. \sa starpu_omp_set_max_active_levels
  599. \sa starpu_omp_get_level
  600. \sa starpu_omp_get_active_level
  601. */
  602. extern int starpu_omp_get_nested(void) __STARPU_OMP_NOTHROW;
  603. /**
  604. Return the state of the cancel ICVS var.
  605. */
  606. extern int starpu_omp_get_cancellation(void) __STARPU_OMP_NOTHROW;
  607. /**
  608. Set the default scheduling kind for upcoming loops within the
  609. current parallel section. \p kind is the scheduler kind, \p modifier
  610. complements the scheduler kind with informations such as the chunk size,
  611. in accordance with the OpenMP specification.
  612. \sa starpu_omp_get_schedule
  613. */
  614. extern void starpu_omp_set_schedule(enum starpu_omp_sched_value kind, int modifier) __STARPU_OMP_NOTHROW;
  615. /**
  616. Return the current selected default loop scheduler.
  617. \return the kind and the modifier of the current default loop scheduler.
  618. \sa starpu_omp_set_schedule
  619. */
  620. extern void starpu_omp_get_schedule(enum starpu_omp_sched_value *kind, int *modifier) __STARPU_OMP_NOTHROW;
  621. /**
  622. Return the number of StarPU CPU workers.
  623. \return the number of StarPU CPU workers.
  624. */
  625. extern int starpu_omp_get_thread_limit(void) __STARPU_OMP_NOTHROW;
  626. /**
  627. Set the maximum number of allowed active parallel section levels.
  628. Note: The StarPU OpenMP runtime support currently ignores the argument of this function and assume \p max_levels equals <c>1</c> instead.
  629. \sa starpu_omp_set_nested
  630. \sa starpu_omp_get_nested
  631. \sa starpu_omp_get_max_active_levels
  632. \sa starpu_omp_get_level
  633. \sa starpu_omp_get_active_level
  634. */
  635. extern void starpu_omp_set_max_active_levels(int max_levels) __STARPU_OMP_NOTHROW;
  636. /**
  637. Return the current maximum number of allowed active parallel section levels
  638. \return the current maximum number of allowed active parallel section levels.
  639. \sa starpu_omp_set_nested
  640. \sa starpu_omp_get_nested
  641. \sa starpu_omp_set_max_active_levels
  642. \sa starpu_omp_get_level
  643. \sa starpu_omp_get_active_level
  644. */
  645. extern int starpu_omp_get_max_active_levels(void) __STARPU_OMP_NOTHROW;
  646. /**
  647. Return the nesting level of the current parallel section.
  648. \return the nesting level of the current parallel section.
  649. \sa starpu_omp_set_nested
  650. \sa starpu_omp_get_nested
  651. \sa starpu_omp_get_max_active_levels
  652. \sa starpu_omp_set_max_active_levels
  653. \sa starpu_omp_get_active_level
  654. */
  655. extern int starpu_omp_get_level(void) __STARPU_OMP_NOTHROW;
  656. /**
  657. Return the number of the ancestor of the current parallel section.
  658. \return the number of the ancestor of the current parallel section.
  659. */
  660. extern int starpu_omp_get_ancestor_thread_num(int level) __STARPU_OMP_NOTHROW;
  661. /**
  662. Return the size of the team of the current parallel section.
  663. \return the size of the team of the current parallel section.
  664. */
  665. extern int starpu_omp_get_team_size(int level) __STARPU_OMP_NOTHROW;
  666. /**
  667. Return the nestinglevel of the current innermost active parallel section.
  668. \return the nestinglevel of the current innermost active parallel section.
  669. \sa starpu_omp_set_nested
  670. \sa starpu_omp_get_nested
  671. \sa starpu_omp_get_max_active_levels
  672. \sa starpu_omp_set_max_active_levels
  673. \sa starpu_omp_get_level
  674. */
  675. extern int starpu_omp_get_active_level(void) __STARPU_OMP_NOTHROW;
  676. /**
  677. Check whether the current task is final or not.
  678. \return <c>!0</c> if called from a final task.
  679. \return <c>0</c> otherwise.
  680. */
  681. extern int starpu_omp_in_final(void) __STARPU_OMP_NOTHROW;
  682. /**
  683. Return the proc_bind setting of the current parallel region.
  684. \return the proc_bind setting of the current parallel region.
  685. */
  686. extern enum starpu_omp_proc_bind_value starpu_omp_get_proc_bind(void) __STARPU_OMP_NOTHROW;
  687. extern int starpu_omp_get_num_places(void) __STARPU_OMP_NOTHROW;
  688. extern int starpu_omp_get_place_num_procs(int place_num) __STARPU_OMP_NOTHROW;
  689. extern void starpu_omp_get_place_proc_ids(int place_num, int *ids) __STARPU_OMP_NOTHROW;
  690. extern int starpu_omp_get_place_num(void) __STARPU_OMP_NOTHROW;
  691. extern int starpu_omp_get_partition_num_places(void) __STARPU_OMP_NOTHROW;
  692. extern void starpu_omp_get_partition_place_nums(int *place_nums) __STARPU_OMP_NOTHROW;
  693. /**
  694. Set the number of the device to use as default.
  695. Note: The StarPU OpenMP runtime support currently ignores the argument of this function.
  696. \sa starpu_omp_get_default_device
  697. \sa starpu_omp_is_initial_device
  698. */
  699. extern void starpu_omp_set_default_device(int device_num) __STARPU_OMP_NOTHROW;
  700. /**
  701. Return the number of the device used as default.
  702. \return the number of the device used as default.
  703. \sa starpu_omp_set_default_device
  704. \sa starpu_omp_is_initial_device
  705. */
  706. extern int starpu_omp_get_default_device(void) __STARPU_OMP_NOTHROW;
  707. /**
  708. Return the number of the devices.
  709. \return the number of the devices.
  710. */
  711. extern int starpu_omp_get_num_devices(void) __STARPU_OMP_NOTHROW;
  712. /**
  713. Return the number of teams in the current teams region.
  714. \return the number of teams in the current teams region.
  715. \sa starpu_omp_get_num_teams
  716. */
  717. extern int starpu_omp_get_num_teams(void) __STARPU_OMP_NOTHROW;
  718. /**
  719. Return the team number of the calling thread.
  720. \return the team number of the calling thread.
  721. \sa starpu_omp_get_num_teams
  722. */
  723. extern int starpu_omp_get_team_num(void) __STARPU_OMP_NOTHROW;
  724. /**
  725. Check whether the current device is the initial device or not.
  726. */
  727. extern int starpu_omp_is_initial_device(void) __STARPU_OMP_NOTHROW;
  728. /**
  729. */
  730. extern int starpu_omp_get_initial_device(void) __STARPU_OMP_NOTHROW;
  731. /**
  732. Return the maximum value that can be specified in the priority
  733. clause.
  734. \return <c>!0</c> if called from the host device.
  735. \return <c>0</c> otherwise.
  736. \sa starpu_omp_set_default_device
  737. \sa starpu_omp_get_default_device
  738. */
  739. extern int starpu_omp_get_max_task_priority(void) __STARPU_OMP_NOTHROW;
  740. /**
  741. Initialize an opaque lock object.
  742. \sa starpu_omp_destroy_lock
  743. \sa starpu_omp_set_lock
  744. \sa starpu_omp_unset_lock
  745. \sa starpu_omp_test_lock
  746. */
  747. extern void starpu_omp_init_lock(starpu_omp_lock_t *lock) __STARPU_OMP_NOTHROW;
  748. /**
  749. Destroy an opaque lock object.
  750. \sa starpu_omp_init_lock
  751. \sa starpu_omp_set_lock
  752. \sa starpu_omp_unset_lock
  753. \sa starpu_omp_test_lock
  754. */
  755. extern void starpu_omp_destroy_lock(starpu_omp_lock_t *lock) __STARPU_OMP_NOTHROW;
  756. /**
  757. Lock an opaque lock object. If the lock is already locked, the
  758. function will block until it succeeds in exclusively acquiring the lock.
  759. \sa starpu_omp_init_lock
  760. \sa starpu_omp_destroy_lock
  761. \sa starpu_omp_unset_lock
  762. \sa starpu_omp_test_lock
  763. */
  764. extern void starpu_omp_set_lock(starpu_omp_lock_t *lock) __STARPU_OMP_NOTHROW;
  765. /**
  766. Unlock a previously locked lock object. The behaviour of this
  767. function is unspecified if it is called on an unlocked lock object.
  768. \sa starpu_omp_init_lock
  769. \sa starpu_omp_destroy_lock
  770. \sa starpu_omp_set_lock
  771. \sa starpu_omp_test_lock
  772. */
  773. extern void starpu_omp_unset_lock(starpu_omp_lock_t *lock) __STARPU_OMP_NOTHROW;
  774. /**
  775. Unblockingly attempt to lock a lock object and return whether
  776. it succeeded or not.
  777. \return <c>!0</c> if the function succeeded in acquiring the lock.
  778. \return <c>0</c> if the lock was already locked.
  779. \sa starpu_omp_init_lock
  780. \sa starpu_omp_destroy_lock
  781. \sa starpu_omp_set_lock
  782. \sa starpu_omp_unset_lock
  783. */
  784. extern int starpu_omp_test_lock(starpu_omp_lock_t *lock) __STARPU_OMP_NOTHROW;
  785. /**
  786. Initialize an opaque lock object supporting nested locking operations.
  787. \sa starpu_omp_destroy_nest_lock
  788. \sa starpu_omp_set_nest_lock
  789. \sa starpu_omp_unset_nest_lock
  790. \sa starpu_omp_test_nest_lock
  791. */
  792. extern void starpu_omp_init_nest_lock(starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
  793. /**
  794. Destroy an opaque lock object supporting nested locking operations.
  795. \sa starpu_omp_init_nest_lock
  796. \sa starpu_omp_set_nest_lock
  797. \sa starpu_omp_unset_nest_lock
  798. \sa starpu_omp_test_nest_lock
  799. */
  800. extern void starpu_omp_destroy_nest_lock(starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
  801. /**
  802. Lock an opaque lock object supporting nested locking operations.
  803. If the lock is already locked by another task, the function will block until
  804. it succeeds in exclusively acquiring the lock. If the lock is already taken by
  805. the current task, the function will increase the nested locking level of the
  806. lock object.
  807. \sa starpu_omp_init_nest_lock
  808. \sa starpu_omp_destroy_nest_lock
  809. \sa starpu_omp_unset_nest_lock
  810. \sa starpu_omp_test_nest_lock
  811. */
  812. extern void starpu_omp_set_nest_lock(starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
  813. /**
  814. Unlock a previously locked lock object supporting nested locking
  815. operations. If the lock has been locked multiple times in nested fashion, the
  816. nested locking level is decreased and the lock remains locked. Otherwise, if
  817. the lock has only been locked once, it becomes unlocked. The behaviour of this
  818. function is unspecified if it is called on an unlocked lock object. The
  819. behaviour of this function is unspecified if it is called from a different task
  820. than the one that locked the lock object.
  821. \sa starpu_omp_init_nest_lock
  822. \sa starpu_omp_destroy_nest_lock
  823. \sa starpu_omp_set_nest_lock
  824. \sa starpu_omp_test_nest_lock
  825. */
  826. extern void starpu_omp_unset_nest_lock(starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
  827. /**
  828. Unblocking attempt to lock an opaque lock object supporting
  829. nested locking operations and returns whether it succeeded or not. If the lock
  830. is already locked by another task, the function will return without having
  831. acquired the lock. If the lock is already taken by the current task, the
  832. function will increase the nested locking level of the lock object.
  833. \return <c>!0</c> if the function succeeded in acquiring the lock.
  834. \return <c>0</c> if the lock was already locked.
  835. \sa starpu_omp_init_nest_lock
  836. \sa starpu_omp_destroy_nest_lock
  837. \sa starpu_omp_set_nest_lock
  838. \sa starpu_omp_unset_nest_lock
  839. */
  840. extern int starpu_omp_test_nest_lock(starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
  841. /**
  842. Implement the entry point of a fallback global atomic region.
  843. Block until it succeeds in acquiring exclusive access to the global atomic
  844. region.
  845. \sa starpu_omp_atomic_fallback_inline_end
  846. */
  847. extern void starpu_omp_atomic_fallback_inline_begin(void) __STARPU_OMP_NOTHROW;
  848. /**
  849. Implement the exit point of a fallback global atomic region.
  850. Release the exclusive access to the global atomic region.
  851. \sa starpu_omp_atomic_fallback_inline_begin
  852. */
  853. extern void starpu_omp_atomic_fallback_inline_end(void) __STARPU_OMP_NOTHROW;
  854. /**
  855. Return the elapsed wallclock time in seconds.
  856. \return the elapsed wallclock time in seconds.
  857. \sa starpu_omp_get_wtick
  858. */
  859. extern double starpu_omp_get_wtime(void) __STARPU_OMP_NOTHROW;
  860. /**
  861. Return the precision of the time used by \p starpu_omp_get_wtime().
  862. \return the precision of the time used by \p starpu_omp_get_wtime().
  863. \sa starpu_omp_get_wtime
  864. */
  865. extern double starpu_omp_get_wtick(void) __STARPU_OMP_NOTHROW;
  866. /**
  867. Enable setting additional vector metadata needed by the OpenMP Runtime Support.
  868. \p handle is vector data handle.
  869. \p slice_base is the base of an array slice, expressed in number of vector elements from the array base.
  870. \sa STARPU_VECTOR_GET_SLICE_BASE
  871. */
  872. extern void starpu_omp_vector_annotate(starpu_data_handle_t handle, uint32_t slice_base) __STARPU_OMP_NOTHROW;
  873. /**
  874. */
  875. extern struct starpu_arbiter *starpu_omp_get_default_arbiter(void) __STARPU_OMP_NOTHROW;
  876. /** @} */
  877. #ifdef __cplusplus
  878. }
  879. #endif
  880. #endif /* STARPU_USE_OPENMP && !STARPU_DONT_INCLUDE_OPENMP_HEADERS */
  881. /** @} */
  882. #endif /* __STARPU_OPENMP_H__ */