libgomp.texi 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename libgomp.info
  4. @settitle GNU libgomp
  5. @c %**end of header
  6. @copying
  7. Copyright @copyright{} 2006-2015 Free Software Foundation, Inc.
  8. Permission is granted to copy, distribute and/or modify this document
  9. under the terms of the GNU Free Documentation License, Version 1.3 or
  10. any later version published by the Free Software Foundation; with the
  11. Invariant Sections being ``Funding Free Software'', the Front-Cover
  12. texts being (a) (see below), and with the Back-Cover Texts being (b)
  13. (see below). A copy of the license is included in the section entitled
  14. ``GNU Free Documentation License''.
  15. (a) The FSF's Front-Cover Text is:
  16. A GNU Manual
  17. (b) The FSF's Back-Cover Text is:
  18. You have freedom to copy and modify this GNU Manual, like GNU
  19. software. Copies published by the Free Software Foundation raise
  20. funds for GNU development.
  21. @end copying
  22. @ifinfo
  23. @dircategory GNU Libraries
  24. @direntry
  25. * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
  26. @end direntry
  27. This manual documents libgomp, the GNU Offloading and Multi Processing
  28. Runtime library. This is the GNU implementation of the OpenMP and
  29. OpenACC APIs for parallel and accelerator programming in C/C++ and
  30. Fortran.
  31. Published by the Free Software Foundation
  32. 51 Franklin Street, Fifth Floor
  33. Boston, MA 02110-1301 USA
  34. @insertcopying
  35. @end ifinfo
  36. @setchapternewpage odd
  37. @titlepage
  38. @title GNU Offloading and Multi Processing Runtime Library
  39. @subtitle The GNU OpenMP and OpenACC Implementation
  40. @page
  41. @vskip 0pt plus 1filll
  42. @comment For the @value{version-GCC} Version*
  43. @sp 1
  44. Published by the Free Software Foundation @*
  45. 51 Franklin Street, Fifth Floor@*
  46. Boston, MA 02110-1301, USA@*
  47. @sp 1
  48. @insertcopying
  49. @end titlepage
  50. @summarycontents
  51. @contents
  52. @page
  53. @node Top
  54. @top Introduction
  55. @cindex Introduction
  56. This manual documents the usage of libgomp, the GNU Offloading and
  57. Multi Processing Runtime Library. This includes the GNU
  58. implementation of the @uref{http://www.openmp.org, OpenMP} Application
  59. Programming Interface (API) for multi-platform shared-memory parallel
  60. programming in C/C++ and Fortran, and the GNU implementation of the
  61. @uref{http://www.openacc.org/, OpenACC} Application Programming
  62. Interface (API) for offloading of code to accelerator devices in C/C++
  63. and Fortran.
  64. Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
  65. on this, support for OpenACC and offloading (both OpenACC and OpenMP
  66. 4's target construct) has been added later on, and the library's name
  67. changed to GNU Offloading and Multi Processing Runtime Library.
  68. @comment
  69. @comment When you add a new menu item, please keep the right hand
  70. @comment aligned to the same column. Do not use tabs. This provides
  71. @comment better formatting.
  72. @comment
  73. @menu
  74. * Enabling OpenMP:: How to enable OpenMP for your applications.
  75. * Runtime Library Routines:: The OpenMP runtime application programming
  76. interface.
  77. * Environment Variables:: Influencing runtime behavior with environment
  78. variables.
  79. * The libgomp ABI:: Notes on the external ABI presented by libgomp.
  80. * Reporting Bugs:: How to report bugs in the GNU Offloading and
  81. Multi Processing Runtime Library.
  82. * Copying:: GNU general public license says
  83. how you can copy and share libgomp.
  84. * GNU Free Documentation License::
  85. How you can copy and share this manual.
  86. * Funding:: How to help assure continued work for free
  87. software.
  88. * Library Index:: Index of this documentation.
  89. @end menu
  90. @c ---------------------------------------------------------------------
  91. @c Enabling OpenMP
  92. @c ---------------------------------------------------------------------
  93. @node Enabling OpenMP
  94. @chapter Enabling OpenMP
  95. To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
  96. flag @command{-fopenmp} must be specified. This enables the OpenMP directive
  97. @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
  98. @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
  99. @code{!$} conditional compilation sentinels in free form and @code{c$},
  100. @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
  101. arranges for automatic linking of the OpenMP runtime library
  102. (@ref{Runtime Library Routines}).
  103. A complete description of all OpenMP directives accepted may be found in
  104. the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
  105. version 4.0.
  106. @c ---------------------------------------------------------------------
  107. @c Runtime Library Routines
  108. @c ---------------------------------------------------------------------
  109. @node Runtime Library Routines
  110. @chapter Runtime Library Routines
  111. The runtime routines described here are defined by Section 3 of the OpenMP
  112. specification in version 4.0. The routines are structured in following
  113. three parts:
  114. @menu
  115. Control threads, processors and the parallel environment. They have C
  116. linkage, and do not throw exceptions.
  117. * omp_get_active_level:: Number of active parallel regions
  118. * omp_get_ancestor_thread_num:: Ancestor thread ID
  119. * omp_get_cancellation:: Whether cancellation support is enabled
  120. * omp_get_default_device:: Get the default device for target regions
  121. * omp_get_dynamic:: Dynamic teams setting
  122. * omp_get_level:: Number of parallel regions
  123. * omp_get_max_active_levels:: Maximum number of active regions
  124. * omp_get_max_threads:: Maximum number of threads of parallel region
  125. * omp_get_nested:: Nested parallel regions
  126. * omp_get_num_devices:: Number of target devices
  127. * omp_get_num_procs:: Number of processors online
  128. * omp_get_num_teams:: Number of teams
  129. * omp_get_num_threads:: Size of the active team
  130. * omp_get_proc_bind:: Whether theads may be moved between CPUs
  131. * omp_get_schedule:: Obtain the runtime scheduling method
  132. * omp_get_team_num:: Get team number
  133. * omp_get_team_size:: Number of threads in a team
  134. * omp_get_thread_limit:: Maximum number of threads
  135. * omp_get_thread_num:: Current thread ID
  136. * omp_in_parallel:: Whether a parallel region is active
  137. * omp_in_final:: Whether in final or included task region
  138. * omp_is_initial_device:: Whether executing on the host device
  139. * omp_set_default_device:: Set the default device for target regions
  140. * omp_set_dynamic:: Enable/disable dynamic teams
  141. * omp_set_max_active_levels:: Limits the number of active parallel regions
  142. * omp_set_nested:: Enable/disable nested parallel regions
  143. * omp_set_num_threads:: Set upper team size limit
  144. * omp_set_schedule:: Set the runtime scheduling method
  145. Initialize, set, test, unset and destroy simple and nested locks.
  146. * omp_init_lock:: Initialize simple lock
  147. * omp_set_lock:: Wait for and set simple lock
  148. * omp_test_lock:: Test and set simple lock if available
  149. * omp_unset_lock:: Unset simple lock
  150. * omp_destroy_lock:: Destroy simple lock
  151. * omp_init_nest_lock:: Initialize nested lock
  152. * omp_set_nest_lock:: Wait for and set simple lock
  153. * omp_test_nest_lock:: Test and set nested lock if available
  154. * omp_unset_nest_lock:: Unset nested lock
  155. * omp_destroy_nest_lock:: Destroy nested lock
  156. Portable, thread-based, wall clock timer.
  157. * omp_get_wtick:: Get timer precision.
  158. * omp_get_wtime:: Elapsed wall clock time.
  159. @end menu
  160. @node omp_get_active_level
  161. @section @code{omp_get_active_level} -- Number of parallel regions
  162. @table @asis
  163. @item @emph{Description}:
  164. This function returns the nesting level for the active parallel blocks,
  165. which enclose the calling call.
  166. @item @emph{C/C++}
  167. @multitable @columnfractions .20 .80
  168. @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
  169. @end multitable
  170. @item @emph{Fortran}:
  171. @multitable @columnfractions .20 .80
  172. @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
  173. @end multitable
  174. @item @emph{See also}:
  175. @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
  176. @item @emph{Reference}:
  177. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
  178. @end table
  179. @node omp_get_ancestor_thread_num
  180. @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
  181. @table @asis
  182. @item @emph{Description}:
  183. This function returns the thread identification number for the given
  184. nesting level of the current thread. For values of @var{level} outside
  185. zero to @code{omp_get_level} -1 is returned; if @var{level} is
  186. @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
  187. @item @emph{C/C++}
  188. @multitable @columnfractions .20 .80
  189. @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
  190. @end multitable
  191. @item @emph{Fortran}:
  192. @multitable @columnfractions .20 .80
  193. @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
  194. @item @tab @code{integer level}
  195. @end multitable
  196. @item @emph{See also}:
  197. @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
  198. @item @emph{Reference}:
  199. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
  200. @end table
  201. @node omp_get_cancellation
  202. @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
  203. @table @asis
  204. @item @emph{Description}:
  205. This function returns @code{true} if cancellation is activated, @code{false}
  206. otherwise. Here, @code{true} and @code{false} represent their language-specific
  207. counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
  208. deactivated.
  209. @item @emph{C/C++}:
  210. @multitable @columnfractions .20 .80
  211. @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
  212. @end multitable
  213. @item @emph{Fortran}:
  214. @multitable @columnfractions .20 .80
  215. @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
  216. @end multitable
  217. @item @emph{See also}:
  218. @ref{OMP_CANCELLATION}
  219. @item @emph{Reference}:
  220. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
  221. @end table
  222. @node omp_get_default_device
  223. @section @code{omp_get_default_device} -- Get the default device for target regions
  224. @table @asis
  225. @item @emph{Description}:
  226. Get the default device for target regions without device clause.
  227. @item @emph{C/C++}:
  228. @multitable @columnfractions .20 .80
  229. @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
  230. @end multitable
  231. @item @emph{Fortran}:
  232. @multitable @columnfractions .20 .80
  233. @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
  234. @end multitable
  235. @item @emph{See also}:
  236. @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
  237. @item @emph{Reference}:
  238. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
  239. @end table
  240. @node omp_get_dynamic
  241. @section @code{omp_get_dynamic} -- Dynamic teams setting
  242. @table @asis
  243. @item @emph{Description}:
  244. This function returns @code{true} if enabled, @code{false} otherwise.
  245. Here, @code{true} and @code{false} represent their language-specific
  246. counterparts.
  247. The dynamic team setting may be initialized at startup by the
  248. @env{OMP_DYNAMIC} environment variable or at runtime using
  249. @code{omp_set_dynamic}. If undefined, dynamic adjustment is
  250. disabled by default.
  251. @item @emph{C/C++}:
  252. @multitable @columnfractions .20 .80
  253. @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
  254. @end multitable
  255. @item @emph{Fortran}:
  256. @multitable @columnfractions .20 .80
  257. @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
  258. @end multitable
  259. @item @emph{See also}:
  260. @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
  261. @item @emph{Reference}:
  262. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
  263. @end table
  264. @node omp_get_level
  265. @section @code{omp_get_level} -- Obtain the current nesting level
  266. @table @asis
  267. @item @emph{Description}:
  268. This function returns the nesting level for the parallel blocks,
  269. which enclose the calling call.
  270. @item @emph{C/C++}
  271. @multitable @columnfractions .20 .80
  272. @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
  273. @end multitable
  274. @item @emph{Fortran}:
  275. @multitable @columnfractions .20 .80
  276. @item @emph{Interface}: @tab @code{integer function omp_level()}
  277. @end multitable
  278. @item @emph{See also}:
  279. @ref{omp_get_active_level}
  280. @item @emph{Reference}:
  281. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
  282. @end table
  283. @node omp_get_max_active_levels
  284. @section @code{omp_get_max_active_levels} -- Maximum number of active regions
  285. @table @asis
  286. @item @emph{Description}:
  287. This function obtains the maximum allowed number of nested, active parallel regions.
  288. @item @emph{C/C++}
  289. @multitable @columnfractions .20 .80
  290. @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
  291. @end multitable
  292. @item @emph{Fortran}:
  293. @multitable @columnfractions .20 .80
  294. @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
  295. @end multitable
  296. @item @emph{See also}:
  297. @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
  298. @item @emph{Reference}:
  299. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
  300. @end table
  301. @node omp_get_max_threads
  302. @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
  303. @table @asis
  304. @item @emph{Description}:
  305. Return the maximum number of threads used for the current parallel region
  306. that does not use the clause @code{num_threads}.
  307. @item @emph{C/C++}:
  308. @multitable @columnfractions .20 .80
  309. @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
  310. @end multitable
  311. @item @emph{Fortran}:
  312. @multitable @columnfractions .20 .80
  313. @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
  314. @end multitable
  315. @item @emph{See also}:
  316. @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
  317. @item @emph{Reference}:
  318. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
  319. @end table
  320. @node omp_get_nested
  321. @section @code{omp_get_nested} -- Nested parallel regions
  322. @table @asis
  323. @item @emph{Description}:
  324. This function returns @code{true} if nested parallel regions are
  325. enabled, @code{false} otherwise. Here, @code{true} and @code{false}
  326. represent their language-specific counterparts.
  327. Nested parallel regions may be initialized at startup by the
  328. @env{OMP_NESTED} environment variable or at runtime using
  329. @code{omp_set_nested}. If undefined, nested parallel regions are
  330. disabled by default.
  331. @item @emph{C/C++}:
  332. @multitable @columnfractions .20 .80
  333. @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
  334. @end multitable
  335. @item @emph{Fortran}:
  336. @multitable @columnfractions .20 .80
  337. @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
  338. @end multitable
  339. @item @emph{See also}:
  340. @ref{omp_set_nested}, @ref{OMP_NESTED}
  341. @item @emph{Reference}:
  342. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
  343. @end table
  344. @node omp_get_num_devices
  345. @section @code{omp_get_num_devices} -- Number of target devices
  346. @table @asis
  347. @item @emph{Description}:
  348. Returns the number of target devices.
  349. @item @emph{C/C++}:
  350. @multitable @columnfractions .20 .80
  351. @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
  352. @end multitable
  353. @item @emph{Fortran}:
  354. @multitable @columnfractions .20 .80
  355. @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
  356. @end multitable
  357. @item @emph{Reference}:
  358. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
  359. @end table
  360. @node omp_get_num_procs
  361. @section @code{omp_get_num_procs} -- Number of processors online
  362. @table @asis
  363. @item @emph{Description}:
  364. Returns the number of processors online on that device.
  365. @item @emph{C/C++}:
  366. @multitable @columnfractions .20 .80
  367. @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
  368. @end multitable
  369. @item @emph{Fortran}:
  370. @multitable @columnfractions .20 .80
  371. @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
  372. @end multitable
  373. @item @emph{Reference}:
  374. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
  375. @end table
  376. @node omp_get_num_teams
  377. @section @code{omp_get_num_teams} -- Number of teams
  378. @table @asis
  379. @item @emph{Description}:
  380. Returns the number of teams in the current team region.
  381. @item @emph{C/C++}:
  382. @multitable @columnfractions .20 .80
  383. @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
  384. @end multitable
  385. @item @emph{Fortran}:
  386. @multitable @columnfractions .20 .80
  387. @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
  388. @end multitable
  389. @item @emph{Reference}:
  390. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
  391. @end table
  392. @node omp_get_num_threads
  393. @section @code{omp_get_num_threads} -- Size of the active team
  394. @table @asis
  395. @item @emph{Description}:
  396. Returns the number of threads in the current team. In a sequential section of
  397. the program @code{omp_get_num_threads} returns 1.
  398. The default team size may be initialized at startup by the
  399. @env{OMP_NUM_THREADS} environment variable. At runtime, the size
  400. of the current team may be set either by the @code{NUM_THREADS}
  401. clause or by @code{omp_set_num_threads}. If none of the above were
  402. used to define a specific value and @env{OMP_DYNAMIC} is disabled,
  403. one thread per CPU online is used.
  404. @item @emph{C/C++}:
  405. @multitable @columnfractions .20 .80
  406. @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
  407. @end multitable
  408. @item @emph{Fortran}:
  409. @multitable @columnfractions .20 .80
  410. @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
  411. @end multitable
  412. @item @emph{See also}:
  413. @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
  414. @item @emph{Reference}:
  415. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
  416. @end table
  417. @node omp_get_proc_bind
  418. @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
  419. @table @asis
  420. @item @emph{Description}:
  421. This functions returns the currently active thread affinity policy, which is
  422. set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
  423. @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
  424. @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
  425. @item @emph{C/C++}:
  426. @multitable @columnfractions .20 .80
  427. @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
  428. @end multitable
  429. @item @emph{Fortran}:
  430. @multitable @columnfractions .20 .80
  431. @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
  432. @end multitable
  433. @item @emph{See also}:
  434. @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
  435. @item @emph{Reference}:
  436. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
  437. @end table
  438. @node omp_get_schedule
  439. @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
  440. @table @asis
  441. @item @emph{Description}:
  442. Obtain the runtime scheduling method. The @var{kind} argument will be
  443. set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
  444. @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
  445. @var{modifier}, is set to the chunk size.
  446. @item @emph{C/C++}
  447. @multitable @columnfractions .20 .80
  448. @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
  449. @end multitable
  450. @item @emph{Fortran}:
  451. @multitable @columnfractions .20 .80
  452. @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
  453. @item @tab @code{integer(kind=omp_sched_kind) kind}
  454. @item @tab @code{integer modifier}
  455. @end multitable
  456. @item @emph{See also}:
  457. @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
  458. @item @emph{Reference}:
  459. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
  460. @end table
  461. @node omp_get_team_num
  462. @section @code{omp_get_team_num} -- Get team number
  463. @table @asis
  464. @item @emph{Description}:
  465. Returns the team number of the calling thread.
  466. @item @emph{C/C++}:
  467. @multitable @columnfractions .20 .80
  468. @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
  469. @end multitable
  470. @item @emph{Fortran}:
  471. @multitable @columnfractions .20 .80
  472. @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
  473. @end multitable
  474. @item @emph{Reference}:
  475. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
  476. @end table
  477. @node omp_get_team_size
  478. @section @code{omp_get_team_size} -- Number of threads in a team
  479. @table @asis
  480. @item @emph{Description}:
  481. This function returns the number of threads in a thread team to which
  482. either the current thread or its ancestor belongs. For values of @var{level}
  483. outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
  484. 1 is returned, and for @code{omp_get_level}, the result is identical
  485. to @code{omp_get_num_threads}.
  486. @item @emph{C/C++}:
  487. @multitable @columnfractions .20 .80
  488. @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
  489. @end multitable
  490. @item @emph{Fortran}:
  491. @multitable @columnfractions .20 .80
  492. @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
  493. @item @tab @code{integer level}
  494. @end multitable
  495. @item @emph{See also}:
  496. @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
  497. @item @emph{Reference}:
  498. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
  499. @end table
  500. @node omp_get_thread_limit
  501. @section @code{omp_get_thread_limit} -- Maximum number of threads
  502. @table @asis
  503. @item @emph{Description}:
  504. Return the maximum number of threads of the program.
  505. @item @emph{C/C++}:
  506. @multitable @columnfractions .20 .80
  507. @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
  508. @end multitable
  509. @item @emph{Fortran}:
  510. @multitable @columnfractions .20 .80
  511. @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
  512. @end multitable
  513. @item @emph{See also}:
  514. @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
  515. @item @emph{Reference}:
  516. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
  517. @end table
  518. @node omp_get_thread_num
  519. @section @code{omp_get_thread_num} -- Current thread ID
  520. @table @asis
  521. @item @emph{Description}:
  522. Returns a unique thread identification number within the current team.
  523. In a sequential parts of the program, @code{omp_get_thread_num}
  524. always returns 0. In parallel regions the return value varies
  525. from 0 to @code{omp_get_num_threads}-1 inclusive. The return
  526. value of the master thread of a team is always 0.
  527. @item @emph{C/C++}:
  528. @multitable @columnfractions .20 .80
  529. @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
  530. @end multitable
  531. @item @emph{Fortran}:
  532. @multitable @columnfractions .20 .80
  533. @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
  534. @end multitable
  535. @item @emph{See also}:
  536. @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
  537. @item @emph{Reference}:
  538. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
  539. @end table
  540. @node omp_in_parallel
  541. @section @code{omp_in_parallel} -- Whether a parallel region is active
  542. @table @asis
  543. @item @emph{Description}:
  544. This function returns @code{true} if currently running in parallel,
  545. @code{false} otherwise. Here, @code{true} and @code{false} represent
  546. their language-specific counterparts.
  547. @item @emph{C/C++}:
  548. @multitable @columnfractions .20 .80
  549. @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
  550. @end multitable
  551. @item @emph{Fortran}:
  552. @multitable @columnfractions .20 .80
  553. @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
  554. @end multitable
  555. @item @emph{Reference}:
  556. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
  557. @end table
  558. @node omp_in_final
  559. @section @code{omp_in_final} -- Whether in final or included task region
  560. @table @asis
  561. @item @emph{Description}:
  562. This function returns @code{true} if currently running in a final
  563. or included task region, @code{false} otherwise. Here, @code{true}
  564. and @code{false} represent their language-specific counterparts.
  565. @item @emph{C/C++}:
  566. @multitable @columnfractions .20 .80
  567. @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
  568. @end multitable
  569. @item @emph{Fortran}:
  570. @multitable @columnfractions .20 .80
  571. @item @emph{Interface}: @tab @code{logical function omp_in_final()}
  572. @end multitable
  573. @item @emph{Reference}:
  574. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
  575. @end table
  576. @node omp_is_initial_device
  577. @section @code{omp_is_initial_device} -- Whether executing on the host device
  578. @table @asis
  579. @item @emph{Description}:
  580. This function returns @code{true} if currently running on the host device,
  581. @code{false} otherwise. Here, @code{true} and @code{false} represent
  582. their language-specific counterparts.
  583. @item @emph{C/C++}:
  584. @multitable @columnfractions .20 .80
  585. @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
  586. @end multitable
  587. @item @emph{Fortran}:
  588. @multitable @columnfractions .20 .80
  589. @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
  590. @end multitable
  591. @item @emph{Reference}:
  592. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
  593. @end table
  594. @node omp_set_default_device
  595. @section @code{omp_set_default_device} -- Set the default device for target regions
  596. @table @asis
  597. @item @emph{Description}:
  598. Set the default device for target regions without device clause. The argument
  599. shall be a nonnegative device number.
  600. @item @emph{C/C++}:
  601. @multitable @columnfractions .20 .80
  602. @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
  603. @end multitable
  604. @item @emph{Fortran}:
  605. @multitable @columnfractions .20 .80
  606. @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
  607. @item @tab @code{integer device_num}
  608. @end multitable
  609. @item @emph{See also}:
  610. @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
  611. @item @emph{Reference}:
  612. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
  613. @end table
  614. @node omp_set_dynamic
  615. @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
  616. @table @asis
  617. @item @emph{Description}:
  618. Enable or disable the dynamic adjustment of the number of threads
  619. within a team. The function takes the language-specific equivalent
  620. of @code{true} and @code{false}, where @code{true} enables dynamic
  621. adjustment of team sizes and @code{false} disables it.
  622. @item @emph{C/C++}:
  623. @multitable @columnfractions .20 .80
  624. @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
  625. @end multitable
  626. @item @emph{Fortran}:
  627. @multitable @columnfractions .20 .80
  628. @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
  629. @item @tab @code{logical, intent(in) :: dynamic_threads}
  630. @end multitable
  631. @item @emph{See also}:
  632. @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
  633. @item @emph{Reference}:
  634. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
  635. @end table
  636. @node omp_set_max_active_levels
  637. @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
  638. @table @asis
  639. @item @emph{Description}:
  640. This function limits the maximum allowed number of nested, active
  641. parallel regions.
  642. @item @emph{C/C++}
  643. @multitable @columnfractions .20 .80
  644. @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
  645. @end multitable
  646. @item @emph{Fortran}:
  647. @multitable @columnfractions .20 .80
  648. @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
  649. @item @tab @code{integer max_levels}
  650. @end multitable
  651. @item @emph{See also}:
  652. @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
  653. @item @emph{Reference}:
  654. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
  655. @end table
  656. @node omp_set_nested
  657. @section @code{omp_set_nested} -- Enable/disable nested parallel regions
  658. @table @asis
  659. @item @emph{Description}:
  660. Enable or disable nested parallel regions, i.e., whether team members
  661. are allowed to create new teams. The function takes the language-specific
  662. equivalent of @code{true} and @code{false}, where @code{true} enables
  663. dynamic adjustment of team sizes and @code{false} disables it.
  664. @item @emph{C/C++}:
  665. @multitable @columnfractions .20 .80
  666. @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
  667. @end multitable
  668. @item @emph{Fortran}:
  669. @multitable @columnfractions .20 .80
  670. @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
  671. @item @tab @code{logical, intent(in) :: nested}
  672. @end multitable
  673. @item @emph{See also}:
  674. @ref{OMP_NESTED}, @ref{omp_get_nested}
  675. @item @emph{Reference}:
  676. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
  677. @end table
  678. @node omp_set_num_threads
  679. @section @code{omp_set_num_threads} -- Set upper team size limit
  680. @table @asis
  681. @item @emph{Description}:
  682. Specifies the number of threads used by default in subsequent parallel
  683. sections, if those do not specify a @code{num_threads} clause. The
  684. argument of @code{omp_set_num_threads} shall be a positive integer.
  685. @item @emph{C/C++}:
  686. @multitable @columnfractions .20 .80
  687. @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
  688. @end multitable
  689. @item @emph{Fortran}:
  690. @multitable @columnfractions .20 .80
  691. @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
  692. @item @tab @code{integer, intent(in) :: num_threads}
  693. @end multitable
  694. @item @emph{See also}:
  695. @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
  696. @item @emph{Reference}:
  697. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
  698. @end table
  699. @node omp_set_schedule
  700. @section @code{omp_set_schedule} -- Set the runtime scheduling method
  701. @table @asis
  702. @item @emph{Description}:
  703. Sets the runtime scheduling method. The @var{kind} argument can have the
  704. value @code{omp_sched_static}, @code{omp_sched_dynamic},
  705. @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
  706. @code{omp_sched_auto}, the chunk size is set to the value of
  707. @var{modifier} if positive, or to the default value if zero or negative.
  708. For @code{omp_sched_auto} the @var{modifier} argument is ignored.
  709. @item @emph{C/C++}
  710. @multitable @columnfractions .20 .80
  711. @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
  712. @end multitable
  713. @item @emph{Fortran}:
  714. @multitable @columnfractions .20 .80
  715. @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
  716. @item @tab @code{integer(kind=omp_sched_kind) kind}
  717. @item @tab @code{integer modifier}
  718. @end multitable
  719. @item @emph{See also}:
  720. @ref{omp_get_schedule}
  721. @ref{OMP_SCHEDULE}
  722. @item @emph{Reference}:
  723. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
  724. @end table
  725. @node omp_init_lock
  726. @section @code{omp_init_lock} -- Initialize simple lock
  727. @table @asis
  728. @item @emph{Description}:
  729. Initialize a simple lock. After initialization, the lock is in
  730. an unlocked state.
  731. @item @emph{C/C++}:
  732. @multitable @columnfractions .20 .80
  733. @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
  734. @end multitable
  735. @item @emph{Fortran}:
  736. @multitable @columnfractions .20 .80
  737. @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
  738. @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
  739. @end multitable
  740. @item @emph{See also}:
  741. @ref{omp_destroy_lock}
  742. @item @emph{Reference}:
  743. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
  744. @end table
  745. @node omp_set_lock
  746. @section @code{omp_set_lock} -- Wait for and set simple lock
  747. @table @asis
  748. @item @emph{Description}:
  749. Before setting a simple lock, the lock variable must be initialized by
  750. @code{omp_init_lock}. The calling thread is blocked until the lock
  751. is available. If the lock is already held by the current thread,
  752. a deadlock occurs.
  753. @item @emph{C/C++}:
  754. @multitable @columnfractions .20 .80
  755. @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
  756. @end multitable
  757. @item @emph{Fortran}:
  758. @multitable @columnfractions .20 .80
  759. @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
  760. @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
  761. @end multitable
  762. @item @emph{See also}:
  763. @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
  764. @item @emph{Reference}:
  765. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
  766. @end table
  767. @node omp_test_lock
  768. @section @code{omp_test_lock} -- Test and set simple lock if available
  769. @table @asis
  770. @item @emph{Description}:
  771. Before setting a simple lock, the lock variable must be initialized by
  772. @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
  773. does not block if the lock is not available. This function returns
  774. @code{true} upon success, @code{false} otherwise. Here, @code{true} and
  775. @code{false} represent their language-specific counterparts.
  776. @item @emph{C/C++}:
  777. @multitable @columnfractions .20 .80
  778. @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
  779. @end multitable
  780. @item @emph{Fortran}:
  781. @multitable @columnfractions .20 .80
  782. @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
  783. @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
  784. @end multitable
  785. @item @emph{See also}:
  786. @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
  787. @item @emph{Reference}:
  788. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
  789. @end table
  790. @node omp_unset_lock
  791. @section @code{omp_unset_lock} -- Unset simple lock
  792. @table @asis
  793. @item @emph{Description}:
  794. A simple lock about to be unset must have been locked by @code{omp_set_lock}
  795. or @code{omp_test_lock} before. In addition, the lock must be held by the
  796. thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
  797. or more threads attempted to set the lock before, one of them is chosen to,
  798. again, set the lock to itself.
  799. @item @emph{C/C++}:
  800. @multitable @columnfractions .20 .80
  801. @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
  802. @end multitable
  803. @item @emph{Fortran}:
  804. @multitable @columnfractions .20 .80
  805. @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
  806. @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
  807. @end multitable
  808. @item @emph{See also}:
  809. @ref{omp_set_lock}, @ref{omp_test_lock}
  810. @item @emph{Reference}:
  811. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
  812. @end table
  813. @node omp_destroy_lock
  814. @section @code{omp_destroy_lock} -- Destroy simple lock
  815. @table @asis
  816. @item @emph{Description}:
  817. Destroy a simple lock. In order to be destroyed, a simple lock must be
  818. in the unlocked state.
  819. @item @emph{C/C++}:
  820. @multitable @columnfractions .20 .80
  821. @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
  822. @end multitable
  823. @item @emph{Fortran}:
  824. @multitable @columnfractions .20 .80
  825. @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
  826. @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
  827. @end multitable
  828. @item @emph{See also}:
  829. @ref{omp_init_lock}
  830. @item @emph{Reference}:
  831. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
  832. @end table
  833. @node omp_init_nest_lock
  834. @section @code{omp_init_nest_lock} -- Initialize nested lock
  835. @table @asis
  836. @item @emph{Description}:
  837. Initialize a nested lock. After initialization, the lock is in
  838. an unlocked state and the nesting count is set to zero.
  839. @item @emph{C/C++}:
  840. @multitable @columnfractions .20 .80
  841. @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
  842. @end multitable
  843. @item @emph{Fortran}:
  844. @multitable @columnfractions .20 .80
  845. @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
  846. @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
  847. @end multitable
  848. @item @emph{See also}:
  849. @ref{omp_destroy_nest_lock}
  850. @item @emph{Reference}:
  851. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
  852. @end table
  853. @node omp_set_nest_lock
  854. @section @code{omp_set_nest_lock} -- Wait for and set nested lock
  855. @table @asis
  856. @item @emph{Description}:
  857. Before setting a nested lock, the lock variable must be initialized by
  858. @code{omp_init_nest_lock}. The calling thread is blocked until the lock
  859. is available. If the lock is already held by the current thread, the
  860. nesting count for the lock is incremented.
  861. @item @emph{C/C++}:
  862. @multitable @columnfractions .20 .80
  863. @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
  864. @end multitable
  865. @item @emph{Fortran}:
  866. @multitable @columnfractions .20 .80
  867. @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
  868. @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
  869. @end multitable
  870. @item @emph{See also}:
  871. @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
  872. @item @emph{Reference}:
  873. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
  874. @end table
  875. @node omp_test_nest_lock
  876. @section @code{omp_test_nest_lock} -- Test and set nested lock if available
  877. @table @asis
  878. @item @emph{Description}:
  879. Before setting a nested lock, the lock variable must be initialized by
  880. @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
  881. @code{omp_test_nest_lock} does not block if the lock is not available.
  882. If the lock is already held by the current thread, the new nesting count
  883. is returned. Otherwise, the return value equals zero.
  884. @item @emph{C/C++}:
  885. @multitable @columnfractions .20 .80
  886. @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
  887. @end multitable
  888. @item @emph{Fortran}:
  889. @multitable @columnfractions .20 .80
  890. @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
  891. @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
  892. @end multitable
  893. @item @emph{See also}:
  894. @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
  895. @item @emph{Reference}:
  896. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
  897. @end table
  898. @node omp_unset_nest_lock
  899. @section @code{omp_unset_nest_lock} -- Unset nested lock
  900. @table @asis
  901. @item @emph{Description}:
  902. A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
  903. or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
  904. thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
  905. lock becomes unlocked. If one ore more threads attempted to set the lock before,
  906. one of them is chosen to, again, set the lock to itself.
  907. @item @emph{C/C++}:
  908. @multitable @columnfractions .20 .80
  909. @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
  910. @end multitable
  911. @item @emph{Fortran}:
  912. @multitable @columnfractions .20 .80
  913. @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
  914. @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
  915. @end multitable
  916. @item @emph{See also}:
  917. @ref{omp_set_nest_lock}
  918. @item @emph{Reference}:
  919. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
  920. @end table
  921. @node omp_destroy_nest_lock
  922. @section @code{omp_destroy_nest_lock} -- Destroy nested lock
  923. @table @asis
  924. @item @emph{Description}:
  925. Destroy a nested lock. In order to be destroyed, a nested lock must be
  926. in the unlocked state and its nesting count must equal zero.
  927. @item @emph{C/C++}:
  928. @multitable @columnfractions .20 .80
  929. @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
  930. @end multitable
  931. @item @emph{Fortran}:
  932. @multitable @columnfractions .20 .80
  933. @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
  934. @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
  935. @end multitable
  936. @item @emph{See also}:
  937. @ref{omp_init_lock}
  938. @item @emph{Reference}:
  939. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
  940. @end table
  941. @node omp_get_wtick
  942. @section @code{omp_get_wtick} -- Get timer precision
  943. @table @asis
  944. @item @emph{Description}:
  945. Gets the timer precision, i.e., the number of seconds between two
  946. successive clock ticks.
  947. @item @emph{C/C++}:
  948. @multitable @columnfractions .20 .80
  949. @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
  950. @end multitable
  951. @item @emph{Fortran}:
  952. @multitable @columnfractions .20 .80
  953. @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
  954. @end multitable
  955. @item @emph{See also}:
  956. @ref{omp_get_wtime}
  957. @item @emph{Reference}:
  958. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
  959. @end table
  960. @node omp_get_wtime
  961. @section @code{omp_get_wtime} -- Elapsed wall clock time
  962. @table @asis
  963. @item @emph{Description}:
  964. Elapsed wall clock time in seconds. The time is measured per thread, no
  965. guarantee can be made that two distinct threads measure the same time.
  966. Time is measured from some "time in the past", which is an arbitrary time
  967. guaranteed not to change during the execution of the program.
  968. @item @emph{C/C++}:
  969. @multitable @columnfractions .20 .80
  970. @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
  971. @end multitable
  972. @item @emph{Fortran}:
  973. @multitable @columnfractions .20 .80
  974. @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
  975. @end multitable
  976. @item @emph{See also}:
  977. @ref{omp_get_wtick}
  978. @item @emph{Reference}:
  979. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
  980. @end table
  981. @c ---------------------------------------------------------------------
  982. @c Environment Variables
  983. @c ---------------------------------------------------------------------
  984. @node Environment Variables
  985. @chapter Environment Variables
  986. The environment variables which beginning with @env{OMP_} are defined by
  987. section 4 of the OpenMP specification in version 4.0, while those
  988. beginning with @env{GOMP_} are GNU extensions.
  989. @menu
  990. * OMP_CANCELLATION:: Set whether cancellation is activated
  991. * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
  992. * OMP_DEFAULT_DEVICE:: Set the device used in target regions
  993. * OMP_DYNAMIC:: Dynamic adjustment of threads
  994. * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
  995. * OMP_NESTED:: Nested parallel regions
  996. * OMP_NUM_THREADS:: Specifies the number of threads to use
  997. * OMP_PROC_BIND:: Whether theads may be moved between CPUs
  998. * OMP_PLACES:: Specifies on which CPUs the theads should be placed
  999. * OMP_STACKSIZE:: Set default thread stack size
  1000. * OMP_SCHEDULE:: How threads are scheduled
  1001. * OMP_THREAD_LIMIT:: Set the maximum number of threads
  1002. * OMP_WAIT_POLICY:: How waiting threads are handled
  1003. * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
  1004. * GOMP_DEBUG:: Enable debugging output
  1005. * GOMP_STACKSIZE:: Set default thread stack size
  1006. * GOMP_SPINCOUNT:: Set the busy-wait spin count
  1007. @end menu
  1008. @node OMP_CANCELLATION
  1009. @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
  1010. @cindex Environment Variable
  1011. @table @asis
  1012. @item @emph{Description}:
  1013. If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
  1014. if unset, cancellation is disabled and the @code{cancel} construct is ignored.
  1015. @item @emph{See also}:
  1016. @ref{omp_get_cancellation}
  1017. @item @emph{Reference}:
  1018. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
  1019. @end table
  1020. @node OMP_DISPLAY_ENV
  1021. @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
  1022. @cindex Environment Variable
  1023. @table @asis
  1024. @item @emph{Description}:
  1025. If set to @code{TRUE}, the OpenMP version number and the values
  1026. associated with the OpenMP environment variables are printed to @code{stderr}.
  1027. If set to @code{VERBOSE}, it additionally shows the value of the environment
  1028. variables which are GNU extensions. If undefined or set to @code{FALSE},
  1029. this information will not be shown.
  1030. @item @emph{Reference}:
  1031. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
  1032. @end table
  1033. @node OMP_DEFAULT_DEVICE
  1034. @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
  1035. @cindex Environment Variable
  1036. @table @asis
  1037. @item @emph{Description}:
  1038. Set to choose the device which is used in a @code{target} region, unless the
  1039. value is overridden by @code{omp_set_default_device} or by a @code{device}
  1040. clause. The value shall be the nonnegative device number. If no device with
  1041. the given device number exists, the code is executed on the host. If unset,
  1042. device number 0 will be used.
  1043. @item @emph{See also}:
  1044. @ref{omp_get_default_device}, @ref{omp_set_default_device},
  1045. @item @emph{Reference}:
  1046. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
  1047. @end table
  1048. @node OMP_DYNAMIC
  1049. @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
  1050. @cindex Environment Variable
  1051. @table @asis
  1052. @item @emph{Description}:
  1053. Enable or disable the dynamic adjustment of the number of threads
  1054. within a team. The value of this environment variable shall be
  1055. @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
  1056. disabled by default.
  1057. @item @emph{See also}:
  1058. @ref{omp_set_dynamic}
  1059. @item @emph{Reference}:
  1060. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
  1061. @end table
  1062. @node OMP_MAX_ACTIVE_LEVELS
  1063. @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
  1064. @cindex Environment Variable
  1065. @table @asis
  1066. @item @emph{Description}:
  1067. Specifies the initial value for the maximum number of nested parallel
  1068. regions. The value of this variable shall be a positive integer.
  1069. If undefined, the number of active levels is unlimited.
  1070. @item @emph{See also}:
  1071. @ref{omp_set_max_active_levels}
  1072. @item @emph{Reference}:
  1073. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
  1074. @end table
  1075. @node OMP_NESTED
  1076. @section @env{OMP_NESTED} -- Nested parallel regions
  1077. @cindex Environment Variable
  1078. @cindex Implementation specific setting
  1079. @table @asis
  1080. @item @emph{Description}:
  1081. Enable or disable nested parallel regions, i.e., whether team members
  1082. are allowed to create new teams. The value of this environment variable
  1083. shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
  1084. regions are disabled by default.
  1085. @item @emph{See also}:
  1086. @ref{omp_set_nested}
  1087. @item @emph{Reference}:
  1088. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
  1089. @end table
  1090. @node OMP_NUM_THREADS
  1091. @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
  1092. @cindex Environment Variable
  1093. @cindex Implementation specific setting
  1094. @table @asis
  1095. @item @emph{Description}:
  1096. Specifies the default number of threads to use in parallel regions. The
  1097. value of this variable shall be a comma-separated list of positive integers;
  1098. the value specified the number of threads to use for the corresponding nested
  1099. level. If undefined one thread per CPU is used.
  1100. @item @emph{See also}:
  1101. @ref{omp_set_num_threads}
  1102. @item @emph{Reference}:
  1103. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
  1104. @end table
  1105. @node OMP_PROC_BIND
  1106. @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
  1107. @cindex Environment Variable
  1108. @table @asis
  1109. @item @emph{Description}:
  1110. Specifies whether threads may be moved between processors. If set to
  1111. @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
  1112. they may be moved. Alternatively, a comma separated list with the
  1113. values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
  1114. the thread affinity policy for the corresponding nesting level. With
  1115. @code{MASTER} the worker threads are in the same place partition as the
  1116. master thread. With @code{CLOSE} those are kept close to the master thread
  1117. in contiguous place partitions. And with @code{SPREAD} a sparse distribution
  1118. across the place partitions is used.
  1119. When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
  1120. @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
  1121. @item @emph{See also}:
  1122. @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
  1123. @item @emph{Reference}:
  1124. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
  1125. @end table
  1126. @node OMP_PLACES
  1127. @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
  1128. @cindex Environment Variable
  1129. @table @asis
  1130. @item @emph{Description}:
  1131. The thread placement can be either specified using an abstract name or by an
  1132. explicit list of the places. The abstract names @code{threads}, @code{cores}
  1133. and @code{sockets} can be optionally followed by a positive number in
  1134. parentheses, which denotes the how many places shall be created. With
  1135. @code{threads} each place corresponds to a single hardware thread; @code{cores}
  1136. to a single core with the corresponding number of hardware threads; and with
  1137. @code{sockets} the place corresponds to a single socket. The resulting
  1138. placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
  1139. variable.
  1140. Alternatively, the placement can be specified explicitly as comma-separated
  1141. list of places. A place is specified by set of nonnegative numbers in curly
  1142. braces, denoting the denoting the hardware threads. The hardware threads
  1143. belonging to a place can either be specified as comma-separated list of
  1144. nonnegative thread numbers or using an interval. Multiple places can also be
  1145. either specified by a comma-separated list of places or by an interval. To
  1146. specify an interval, a colon followed by the count is placed after after
  1147. the hardware thread number or the place. Optionally, the length can be
  1148. followed by a colon and the stride number -- otherwise a unit stride is
  1149. assumed. For instance, the following specifies the same places list:
  1150. @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
  1151. @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
  1152. If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
  1153. @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
  1154. between CPUs following no placement policy.
  1155. @item @emph{See also}:
  1156. @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
  1157. @ref{OMP_DISPLAY_ENV}
  1158. @item @emph{Reference}:
  1159. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
  1160. @end table
  1161. @node OMP_STACKSIZE
  1162. @section @env{OMP_STACKSIZE} -- Set default thread stack size
  1163. @cindex Environment Variable
  1164. @table @asis
  1165. @item @emph{Description}:
  1166. Set the default thread stack size in kilobytes, unless the number
  1167. is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
  1168. case the size is, respectively, in bytes, kilobytes, megabytes
  1169. or gigabytes. This is different from @code{pthread_attr_setstacksize}
  1170. which gets the number of bytes as an argument. If the stack size cannot
  1171. be set due to system constraints, an error is reported and the initial
  1172. stack size is left unchanged. If undefined, the stack size is system
  1173. dependent.
  1174. @item @emph{Reference}:
  1175. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
  1176. @end table
  1177. @node OMP_SCHEDULE
  1178. @section @env{OMP_SCHEDULE} -- How threads are scheduled
  1179. @cindex Environment Variable
  1180. @cindex Implementation specific setting
  1181. @table @asis
  1182. @item @emph{Description}:
  1183. Allows to specify @code{schedule type} and @code{chunk size}.
  1184. The value of the variable shall have the form: @code{type[,chunk]} where
  1185. @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
  1186. The optional @code{chunk} size shall be a positive integer. If undefined,
  1187. dynamic scheduling and a chunk size of 1 is used.
  1188. @item @emph{See also}:
  1189. @ref{omp_set_schedule}
  1190. @item @emph{Reference}:
  1191. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
  1192. @end table
  1193. @node OMP_THREAD_LIMIT
  1194. @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
  1195. @cindex Environment Variable
  1196. @table @asis
  1197. @item @emph{Description}:
  1198. Specifies the number of threads to use for the whole program. The
  1199. value of this variable shall be a positive integer. If undefined,
  1200. the number of threads is not limited.
  1201. @item @emph{See also}:
  1202. @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
  1203. @item @emph{Reference}:
  1204. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
  1205. @end table
  1206. @node OMP_WAIT_POLICY
  1207. @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
  1208. @cindex Environment Variable
  1209. @table @asis
  1210. @item @emph{Description}:
  1211. Specifies whether waiting threads should be active or passive. If
  1212. the value is @code{PASSIVE}, waiting threads should not consume CPU
  1213. power while waiting; while the value is @code{ACTIVE} specifies that
  1214. they should. If undefined, threads wait actively for a short time
  1215. before waiting passively.
  1216. @item @emph{See also}:
  1217. @ref{GOMP_SPINCOUNT}
  1218. @item @emph{Reference}:
  1219. @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
  1220. @end table
  1221. @node GOMP_CPU_AFFINITY
  1222. @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
  1223. @cindex Environment Variable
  1224. @table @asis
  1225. @item @emph{Description}:
  1226. Binds threads to specific CPUs. The variable should contain a space-separated
  1227. or comma-separated list of CPUs. This list may contain different kinds of
  1228. entries: either single CPU numbers in any order, a range of CPUs (M-N)
  1229. or a range with some stride (M-N:S). CPU numbers are zero based. For example,
  1230. @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
  1231. to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
  1232. CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
  1233. and 14 respectively and then start assigning back from the beginning of
  1234. the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
  1235. There is no libgomp library routine to determine whether a CPU affinity
  1236. specification is in effect. As a workaround, language-specific library
  1237. functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
  1238. Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
  1239. environment variable. A defined CPU affinity on startup cannot be changed
  1240. or disabled during the runtime of the application.
  1241. If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
  1242. @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
  1243. @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
  1244. @code{FALSE}, the host system will handle the assignment of threads to CPUs.
  1245. @item @emph{See also}:
  1246. @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
  1247. @end table
  1248. @node GOMP_DEBUG
  1249. @section @env{GOMP_DEBUG} -- Enable debugging output
  1250. @cindex Environment Variable
  1251. @table @asis
  1252. @item @emph{Description}:
  1253. Enable debugging output. The variable should be set to @code{0}
  1254. (disabled, also the default if not set), or @code{1} (enabled).
  1255. If enabled, some debugging output will be printed during execution.
  1256. This is currently not specified in more detail, and subject to change.
  1257. @end table
  1258. @node GOMP_STACKSIZE
  1259. @section @env{GOMP_STACKSIZE} -- Set default thread stack size
  1260. @cindex Environment Variable
  1261. @cindex Implementation specific setting
  1262. @table @asis
  1263. @item @emph{Description}:
  1264. Set the default thread stack size in kilobytes. This is different from
  1265. @code{pthread_attr_setstacksize} which gets the number of bytes as an
  1266. argument. If the stack size cannot be set due to system constraints, an
  1267. error is reported and the initial stack size is left unchanged. If undefined,
  1268. the stack size is system dependent.
  1269. @item @emph{See also}:
  1270. @ref{OMP_STACKSIZE}
  1271. @item @emph{Reference}:
  1272. @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
  1273. GCC Patches Mailinglist},
  1274. @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
  1275. GCC Patches Mailinglist}
  1276. @end table
  1277. @node GOMP_SPINCOUNT
  1278. @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
  1279. @cindex Environment Variable
  1280. @cindex Implementation specific setting
  1281. @table @asis
  1282. @item @emph{Description}:
  1283. Determines how long a threads waits actively with consuming CPU power
  1284. before waiting passively without consuming CPU power. The value may be
  1285. either @code{INFINITE}, @code{INFINITY} to always wait actively or an
  1286. integer which gives the number of spins of the busy-wait loop. The
  1287. integer may optionally be followed by the following suffixes acting
  1288. as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
  1289. million), @code{G} (giga, billion), or @code{T} (tera, trillion).
  1290. If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
  1291. 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
  1292. 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
  1293. If there are more OpenMP threads than available CPUs, 1000 and 100
  1294. spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
  1295. undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
  1296. or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
  1297. @item @emph{See also}:
  1298. @ref{OMP_WAIT_POLICY}
  1299. @end table
  1300. @c ---------------------------------------------------------------------
  1301. @c The libgomp ABI
  1302. @c ---------------------------------------------------------------------
  1303. @node The libgomp ABI
  1304. @chapter The libgomp ABI
  1305. The following sections present notes on the external ABI as
  1306. presented by libgomp. Only maintainers should need them.
  1307. @menu
  1308. * Implementing MASTER construct::
  1309. * Implementing CRITICAL construct::
  1310. * Implementing ATOMIC construct::
  1311. * Implementing FLUSH construct::
  1312. * Implementing BARRIER construct::
  1313. * Implementing THREADPRIVATE construct::
  1314. * Implementing PRIVATE clause::
  1315. * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
  1316. * Implementing REDUCTION clause::
  1317. * Implementing PARALLEL construct::
  1318. * Implementing FOR construct::
  1319. * Implementing ORDERED construct::
  1320. * Implementing SECTIONS construct::
  1321. * Implementing SINGLE construct::
  1322. @end menu
  1323. @node Implementing MASTER construct
  1324. @section Implementing MASTER construct
  1325. @smallexample
  1326. if (omp_get_thread_num () == 0)
  1327. block
  1328. @end smallexample
  1329. Alternately, we generate two copies of the parallel subfunction
  1330. and only include this in the version run by the master thread.
  1331. Surely this is not worthwhile though...
  1332. @node Implementing CRITICAL construct
  1333. @section Implementing CRITICAL construct
  1334. Without a specified name,
  1335. @smallexample
  1336. void GOMP_critical_start (void);
  1337. void GOMP_critical_end (void);
  1338. @end smallexample
  1339. so that we don't get COPY relocations from libgomp to the main
  1340. application.
  1341. With a specified name, use omp_set_lock and omp_unset_lock with
  1342. name being transformed into a variable declared like
  1343. @smallexample
  1344. omp_lock_t gomp_critical_user_<name> __attribute__((common))
  1345. @end smallexample
  1346. Ideally the ABI would specify that all zero is a valid unlocked
  1347. state, and so we wouldn't need to initialize this at
  1348. startup.
  1349. @node Implementing ATOMIC construct
  1350. @section Implementing ATOMIC construct
  1351. The target should implement the @code{__sync} builtins.
  1352. Failing that we could add
  1353. @smallexample
  1354. void GOMP_atomic_enter (void)
  1355. void GOMP_atomic_exit (void)
  1356. @end smallexample
  1357. which reuses the regular lock code, but with yet another lock
  1358. object private to the library.
  1359. @node Implementing FLUSH construct
  1360. @section Implementing FLUSH construct
  1361. Expands to the @code{__sync_synchronize} builtin.
  1362. @node Implementing BARRIER construct
  1363. @section Implementing BARRIER construct
  1364. @smallexample
  1365. void GOMP_barrier (void)
  1366. @end smallexample
  1367. @node Implementing THREADPRIVATE construct
  1368. @section Implementing THREADPRIVATE construct
  1369. In _most_ cases we can map this directly to @code{__thread}. Except
  1370. that OMP allows constructors for C++ objects. We can either
  1371. refuse to support this (how often is it used?) or we can
  1372. implement something akin to .ctors.
  1373. Even more ideally, this ctor feature is handled by extensions
  1374. to the main pthreads library. Failing that, we can have a set
  1375. of entry points to register ctor functions to be called.
  1376. @node Implementing PRIVATE clause
  1377. @section Implementing PRIVATE clause
  1378. In association with a PARALLEL, or within the lexical extent
  1379. of a PARALLEL block, the variable becomes a local variable in
  1380. the parallel subfunction.
  1381. In association with FOR or SECTIONS blocks, create a new
  1382. automatic variable within the current function. This preserves
  1383. the semantic of new variable creation.
  1384. @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
  1385. @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
  1386. This seems simple enough for PARALLEL blocks. Create a private
  1387. struct for communicating between the parent and subfunction.
  1388. In the parent, copy in values for scalar and "small" structs;
  1389. copy in addresses for others TREE_ADDRESSABLE types. In the
  1390. subfunction, copy the value into the local variable.
  1391. It is not clear what to do with bare FOR or SECTION blocks.
  1392. The only thing I can figure is that we do something like:
  1393. @smallexample
  1394. #pragma omp for firstprivate(x) lastprivate(y)
  1395. for (int i = 0; i < n; ++i)
  1396. body;
  1397. @end smallexample
  1398. which becomes
  1399. @smallexample
  1400. @{
  1401. int x = x, y;
  1402. // for stuff
  1403. if (i == n)
  1404. y = y;
  1405. @}
  1406. @end smallexample
  1407. where the "x=x" and "y=y" assignments actually have different
  1408. uids for the two variables, i.e. not something you could write
  1409. directly in C. Presumably this only makes sense if the "outer"
  1410. x and y are global variables.
  1411. COPYPRIVATE would work the same way, except the structure
  1412. broadcast would have to happen via SINGLE machinery instead.
  1413. @node Implementing REDUCTION clause
  1414. @section Implementing REDUCTION clause
  1415. The private struct mentioned in the previous section should have
  1416. a pointer to an array of the type of the variable, indexed by the
  1417. thread's @var{team_id}. The thread stores its final value into the
  1418. array, and after the barrier, the master thread iterates over the
  1419. array to collect the values.
  1420. @node Implementing PARALLEL construct
  1421. @section Implementing PARALLEL construct
  1422. @smallexample
  1423. #pragma omp parallel
  1424. @{
  1425. body;
  1426. @}
  1427. @end smallexample
  1428. becomes
  1429. @smallexample
  1430. void subfunction (void *data)
  1431. @{
  1432. use data;
  1433. body;
  1434. @}
  1435. setup data;
  1436. GOMP_parallel_start (subfunction, &data, num_threads);
  1437. subfunction (&data);
  1438. GOMP_parallel_end ();
  1439. @end smallexample
  1440. @smallexample
  1441. void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
  1442. @end smallexample
  1443. The @var{FN} argument is the subfunction to be run in parallel.
  1444. The @var{DATA} argument is a pointer to a structure used to
  1445. communicate data in and out of the subfunction, as discussed
  1446. above with respect to FIRSTPRIVATE et al.
  1447. The @var{NUM_THREADS} argument is 1 if an IF clause is present
  1448. and false, or the value of the NUM_THREADS clause, if
  1449. present, or 0.
  1450. The function needs to create the appropriate number of
  1451. threads and/or launch them from the dock. It needs to
  1452. create the team structure and assign team ids.
  1453. @smallexample
  1454. void GOMP_parallel_end (void)
  1455. @end smallexample
  1456. Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
  1457. @node Implementing FOR construct
  1458. @section Implementing FOR construct
  1459. @smallexample
  1460. #pragma omp parallel for
  1461. for (i = lb; i <= ub; i++)
  1462. body;
  1463. @end smallexample
  1464. becomes
  1465. @smallexample
  1466. void subfunction (void *data)
  1467. @{
  1468. long _s0, _e0;
  1469. while (GOMP_loop_static_next (&_s0, &_e0))
  1470. @{
  1471. long _e1 = _e0, i;
  1472. for (i = _s0; i < _e1; i++)
  1473. body;
  1474. @}
  1475. GOMP_loop_end_nowait ();
  1476. @}
  1477. GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
  1478. subfunction (NULL);
  1479. GOMP_parallel_end ();
  1480. @end smallexample
  1481. @smallexample
  1482. #pragma omp for schedule(runtime)
  1483. for (i = 0; i < n; i++)
  1484. body;
  1485. @end smallexample
  1486. becomes
  1487. @smallexample
  1488. @{
  1489. long i, _s0, _e0;
  1490. if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
  1491. do @{
  1492. long _e1 = _e0;
  1493. for (i = _s0, i < _e0; i++)
  1494. body;
  1495. @} while (GOMP_loop_runtime_next (&_s0, _&e0));
  1496. GOMP_loop_end ();
  1497. @}
  1498. @end smallexample
  1499. Note that while it looks like there is trickiness to propagating
  1500. a non-constant STEP, there isn't really. We're explicitly allowed
  1501. to evaluate it as many times as we want, and any variables involved
  1502. should automatically be handled as PRIVATE or SHARED like any other
  1503. variables. So the expression should remain evaluable in the
  1504. subfunction. We can also pull it into a local variable if we like,
  1505. but since its supposed to remain unchanged, we can also not if we like.
  1506. If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
  1507. able to get away with no work-sharing context at all, since we can
  1508. simply perform the arithmetic directly in each thread to divide up
  1509. the iterations. Which would mean that we wouldn't need to call any
  1510. of these routines.
  1511. There are separate routines for handling loops with an ORDERED
  1512. clause. Bookkeeping for that is non-trivial...
  1513. @node Implementing ORDERED construct
  1514. @section Implementing ORDERED construct
  1515. @smallexample
  1516. void GOMP_ordered_start (void)
  1517. void GOMP_ordered_end (void)
  1518. @end smallexample
  1519. @node Implementing SECTIONS construct
  1520. @section Implementing SECTIONS construct
  1521. A block as
  1522. @smallexample
  1523. #pragma omp sections
  1524. @{
  1525. #pragma omp section
  1526. stmt1;
  1527. #pragma omp section
  1528. stmt2;
  1529. #pragma omp section
  1530. stmt3;
  1531. @}
  1532. @end smallexample
  1533. becomes
  1534. @smallexample
  1535. for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
  1536. switch (i)
  1537. @{
  1538. case 1:
  1539. stmt1;
  1540. break;
  1541. case 2:
  1542. stmt2;
  1543. break;
  1544. case 3:
  1545. stmt3;
  1546. break;
  1547. @}
  1548. GOMP_barrier ();
  1549. @end smallexample
  1550. @node Implementing SINGLE construct
  1551. @section Implementing SINGLE construct
  1552. A block like
  1553. @smallexample
  1554. #pragma omp single
  1555. @{
  1556. body;
  1557. @}
  1558. @end smallexample
  1559. becomes
  1560. @smallexample
  1561. if (GOMP_single_start ())
  1562. body;
  1563. GOMP_barrier ();
  1564. @end smallexample
  1565. while
  1566. @smallexample
  1567. #pragma omp single copyprivate(x)
  1568. body;
  1569. @end smallexample
  1570. becomes
  1571. @smallexample
  1572. datap = GOMP_single_copy_start ();
  1573. if (datap == NULL)
  1574. @{
  1575. body;
  1576. data.x = x;
  1577. GOMP_single_copy_end (&data);
  1578. @}
  1579. else
  1580. x = datap->x;
  1581. GOMP_barrier ();
  1582. @end smallexample
  1583. @c ---------------------------------------------------------------------
  1584. @c Reporting Bugs
  1585. @c ---------------------------------------------------------------------
  1586. @node Reporting Bugs
  1587. @chapter Reporting Bugs
  1588. Bugs in the GNU Offloading and Multi Processing Runtime Library should
  1589. be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
  1590. "openacc", or "openmp", or both to the keywords field in the bug
  1591. report, as appropriate.
  1592. @c ---------------------------------------------------------------------
  1593. @c GNU General Public License
  1594. @c ---------------------------------------------------------------------
  1595. @include gpl_v3.texi
  1596. @c ---------------------------------------------------------------------
  1597. @c GNU Free Documentation License
  1598. @c ---------------------------------------------------------------------
  1599. @include fdl.texi
  1600. @c ---------------------------------------------------------------------
  1601. @c Funding Free Software
  1602. @c ---------------------------------------------------------------------
  1603. @include funding.texi
  1604. @c ---------------------------------------------------------------------
  1605. @c Index
  1606. @c ---------------------------------------------------------------------
  1607. @node Library Index
  1608. @unnumbered Library Index
  1609. @printindex cp
  1610. @bye