starpu_openmp.h 38 KB

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