c++: only cache constexpr calls that are constant exprs
[official-gcc.git] / libgomp / libgomp.texi
blob639dd05eb7ba2cfe9929fc03264f70ff00c58ab9
1 \input texinfo @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
9 @copying
10 Copyright @copyright{} 2006-2023 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below).  A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
22      A GNU Manual
24 (b) The FSF's Back-Cover Text is:
26      You have freedom to copy and modify this GNU Manual, like GNU
27      software.  Copies published by the Free Software Foundation raise
28      funds for GNU development.
29 @end copying
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library.  This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
40 Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
46 @insertcopying
47 @end ifinfo
50 @setchapternewpage odd
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
66 @summarycontents
67 @contents
68 @page
71 @node Top, Enabling OpenMP
72 @top Introduction
73 @cindex Introduction
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library.  This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
82 and Fortran.
84 Originally, libgomp implemented the GNU OpenMP Runtime Library.  Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
91 @comment
92 @comment  When you add a new menu item, please keep the right hand
93 @comment  aligned to the same column.  Do not use tabs.  This provides
94 @comment  better formatting.
95 @comment
96 @menu
97 * Enabling OpenMP::            How to enable OpenMP for your applications.
98 * OpenMP Implementation Status:: List of implemented features by OpenMP version
99 * OpenMP Runtime Library Routines: Runtime Library Routines.
100                                The OpenMP runtime application programming
101                                interface.
102 * OpenMP Environment Variables: Environment Variables.
103                                Influencing OpenMP runtime behavior with
104                                environment variables.
105 * Enabling OpenACC::           How to enable OpenACC for your
106                                applications.
107 * OpenACC Runtime Library Routines:: The OpenACC runtime application
108                                programming interface.
109 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
110                                environment variables.
111 * CUDA Streams Usage::         Notes on the implementation of
112                                asynchronous operations.
113 * OpenACC Library Interoperability:: OpenACC library interoperability with the
114                                NVIDIA CUBLAS library.
115 * OpenACC Profiling Interface::
116 * OpenMP-Implementation Specifics:: Notes specifics of this OpenMP
117                                implementation
118 * Offload-Target Specifics::   Notes on offload-target specific internals
119 * The libgomp ABI::            Notes on the external ABI presented by libgomp.
120 * Reporting Bugs::             How to report bugs in the GNU Offloading and
121                                Multi Processing Runtime Library.
122 * Copying::                    GNU general public license says
123                                how you can copy and share libgomp.
124 * GNU Free Documentation License::
125                                How you can copy and share this manual.
126 * Funding::                    How to help assure continued work for free 
127                                software.
128 * Library Index::              Index of this documentation.
129 @end menu
132 @c ---------------------------------------------------------------------
133 @c Enabling OpenMP
134 @c ---------------------------------------------------------------------
136 @node Enabling OpenMP
137 @chapter Enabling OpenMP
139 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time 
140 flag @command{-fopenmp} must be specified.  This enables the OpenMP directive
141 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form, 
142 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form, 
143 @code{!$} conditional compilation sentinels in free form and @code{c$},
144 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
145 arranges for automatic linking of the OpenMP runtime library 
146 (@ref{Runtime Library Routines}).
148 A complete description of all OpenMP directives may be found in the
149 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
150 See also @ref{OpenMP Implementation Status}.
153 @c ---------------------------------------------------------------------
154 @c OpenMP Implementation Status
155 @c ---------------------------------------------------------------------
157 @node OpenMP Implementation Status
158 @chapter OpenMP Implementation Status
160 @menu
161 * OpenMP 4.5:: Feature completion status to 4.5 specification
162 * OpenMP 5.0:: Feature completion status to 5.0 specification
163 * OpenMP 5.1:: Feature completion status to 5.1 specification
164 * OpenMP 5.2:: Feature completion status to 5.2 specification
165 * OpenMP Technical Report 11:: Feature completion status to first 6.0 preview
166 @end menu
168 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
169 parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
170 the value @code{201511} (i.e. OpenMP 4.5).
172 @node OpenMP 4.5
173 @section OpenMP 4.5
175 The OpenMP 4.5 specification is fully supported.
177 @node OpenMP 5.0
178 @section OpenMP 5.0
180 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
181 @c This list is sorted as in OpenMP 5.1's B.3 not as in OpenMP 5.0's B.2
183 @multitable @columnfractions .60 .10 .25
184 @headitem Description @tab Status @tab Comments
185 @item Array shaping @tab N @tab
186 @item Array sections with non-unit strides in C and C++ @tab N @tab
187 @item Iterators @tab Y @tab
188 @item @code{metadirective} directive @tab N @tab
189 @item @code{declare variant} directive
190       @tab P @tab @emph{simd} traits not handled correctly
191 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
192       env variable @tab Y @tab
193 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
194 @item @code{requires} directive @tab P
195       @tab complete but no non-host device provides @code{unified_shared_memory}
196 @item @code{teams} construct outside an enclosing target region @tab Y @tab
197 @item Non-rectangular loop nests @tab P @tab Full support for C/C++, partial for Fortran
198 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
199 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
200       constructs @tab Y @tab
201 @item Collapse of associated loops that are imperfectly nested loops @tab N @tab
202 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
203       @code{simd} construct @tab Y @tab
204 @item @code{atomic} constructs in @code{simd} @tab Y @tab
205 @item @code{loop} construct @tab Y @tab
206 @item @code{order(concurrent)} clause @tab Y @tab
207 @item @code{scan} directive and @code{in_scan} modifier for the
208       @code{reduction} clause @tab Y @tab
209 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
210 @item @code{in_reduction} clause on @code{target} constructs @tab P
211       @tab @code{nowait} only stub
212 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
213 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
214 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
215 @item @code{detach} clause to @code{task} construct @tab Y @tab
216 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
217 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
218       and @code{taskloop simd} constructs @tab Y @tab
219 @item @code{taskloop} construct cancelable by @code{cancel} construct
220       @tab Y @tab
221 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
222       @tab Y @tab
223 @item Predefined memory spaces, memory allocators, allocator traits
224       @tab Y @tab See also @ref{Memory allocation}
225 @item Memory management routines @tab Y @tab
226 @item @code{allocate} directive @tab N @tab
227 @item @code{allocate} clause @tab P @tab Initial support
228 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
229 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
230 @item Implicit declare target directive @tab Y @tab
231 @item Discontiguous array section with @code{target update} construct
232       @tab N @tab
233 @item C/C++'s lvalue expressions in @code{to}, @code{from}
234       and @code{map} clauses @tab N @tab
235 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
236 @item Nested @code{declare target} directive @tab Y @tab
237 @item Combined @code{master} constructs @tab Y @tab
238 @item @code{depend} clause on @code{taskwait} @tab Y @tab
239 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
240       @tab Y @tab
241 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
242 @item @code{depobj} construct and depend objects  @tab Y @tab
243 @item Lock hints were renamed to synchronization hints @tab Y @tab
244 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
245 @item Map-order clarifications @tab P @tab
246 @item @code{close} @emph{map-type-modifier} @tab Y @tab
247 @item Mapping C/C++ pointer variables and to assign the address of
248       device memory mapped by an array section @tab P @tab
249 @item Mapping of Fortran pointer and allocatable variables, including pointer
250       and allocatable components of variables
251       @tab P @tab Mapping of vars with allocatable components unsupported
252 @item @code{defaultmap} extensions @tab Y @tab
253 @item @code{declare mapper} directive @tab N @tab
254 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
255 @item Runtime routines and environment variables to display runtime thread
256       affinity information @tab Y @tab
257 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
258       routines @tab Y @tab
259 @item @code{omp_get_device_num} runtime routine @tab Y @tab
260 @item OMPT interface @tab N @tab
261 @item OMPD interface @tab N @tab
262 @end multitable
264 @unnumberedsubsec Other new OpenMP 5.0 features
266 @multitable @columnfractions .60 .10 .25
267 @headitem Description @tab Status @tab Comments
268 @item Supporting C++'s range-based for loop @tab Y @tab
269 @end multitable
272 @node OpenMP 5.1
273 @section OpenMP 5.1
275 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
277 @multitable @columnfractions .60 .10 .25
278 @headitem Description @tab Status @tab Comments
279 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
280 @item @code{omp_all_memory} reserved locator @tab Y @tab
281 @item @emph{target_device trait} in OpenMP Context @tab N @tab
282 @item @code{target_device} selector set in context selectors @tab N @tab
283 @item C/C++'s @code{declare variant} directive: elision support of
284       preprocessed code @tab N @tab
285 @item @code{declare variant}: new clauses @code{adjust_args} and
286       @code{append_args} @tab N @tab
287 @item @code{dispatch} construct @tab N @tab
288 @item device-specific ICV settings with environment variables @tab Y @tab
289 @item @code{assume} and @code{assumes} directives @tab Y @tab
290 @item @code{nothing} directive @tab Y @tab
291 @item @code{error} directive @tab Y @tab
292 @item @code{masked} construct @tab Y @tab
293 @item @code{scope} directive @tab Y @tab
294 @item Loop transformation constructs @tab N @tab
295 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
296       clauses of the @code{taskloop} construct @tab Y @tab
297 @item @code{align} clause in @code{allocate} directive @tab N @tab
298 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
299 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
300 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
301 @item Iterators in @code{target update} motion clauses and @code{map}
302       clauses @tab N @tab
303 @item Indirect calls to the device version of a procedure or function in
304       @code{target} regions @tab N @tab
305 @item @code{interop} directive @tab N @tab
306 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
307 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
308 @item Extensions to the @code{atomic} directive @tab Y @tab
309 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
310 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
311 @item @code{private} and @code{firstprivate} argument to @code{default}
312       clause in C and C++ @tab Y @tab
313 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
314 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
315       @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
316       routines @tab Y @tab
317 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
318 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
319       runtime routines @tab Y @tab
320 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
321 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
322       @code{omp_aligned_calloc} runtime routines @tab Y @tab
323 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
324       @code{omp_atv_default} changed @tab Y @tab
325 @item @code{omp_display_env} runtime routine @tab Y @tab
326 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
327 @item @code{ompt_sync_region_t} enum additions @tab N @tab
328 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
329       and @code{ompt_state_wait_barrier_teams} @tab N @tab
330 @item @code{ompt_callback_target_data_op_emi_t},
331       @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
332       and @code{ompt_callback_target_submit_emi_t} @tab N @tab
333 @item @code{ompt_callback_error_t} type @tab N @tab
334 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
335 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
336       variables @tab Y @tab
337 @end multitable
339 @unnumberedsubsec Other new OpenMP 5.1 features
341 @multitable @columnfractions .60 .10 .25
342 @headitem Description @tab Status @tab Comments
343 @item Support of strictly structured blocks in Fortran @tab Y @tab
344 @item Support of structured block sequences in C/C++ @tab Y @tab
345 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
346       clause @tab Y @tab
347 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
348 @item Pointer predetermined firstprivate getting initialized
349 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
350 @item For Fortran, diagnose placing declarative before/between @code{USE},
351       @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
352 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
353 @item @code{indirect} clause in @code{declare target} @tab N @tab
354 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
355 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
356       clauses @tab Y @tab
357 @end multitable
360 @node OpenMP 5.2
361 @section OpenMP 5.2
363 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
365 @multitable @columnfractions .60 .10 .25
366 @headitem Description @tab Status @tab Comments
367 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
368       @tab Y @tab
369 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
370       namespaces @tab N/A
371       @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
372       sentinel as C/C++ pragma and C++ attributes are warned for with
373       @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
374       (enabled by default), respectively; for Fortran free-source code, there is
375       a warning enabled by default and, for fixed-source code, the @code{omx}
376       sentinel is warned for with with @code{-Wsurprising} (enabled by
377       @code{-Wall}).  Unknown clauses are always rejected with an error.}
378 @item Clauses on @code{end} directive can be on directive @tab Y @tab
379 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
380       @tab N @tab
381 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
382 @item Deprecation of minus operator for reductions @tab N @tab
383 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
384 @item @code{declare mapper} with iterator and @code{present} modifiers
385       @tab N @tab
386 @item If a matching mapped list item is not found in the data environment, the
387       pointer retains its original value @tab Y @tab
388 @item New @code{enter} clause as alias for @code{to} on declare target directive
389       @tab Y @tab
390 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
391 @item Extended list of directives permitted in Fortran pure procedures
392       @tab Y @tab
393 @item New @code{allocators} directive for Fortran @tab N @tab
394 @item Deprecation of @code{allocate} directive for Fortran
395       allocatables/pointers @tab N @tab
396 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
397 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
398       @tab N @tab
399 @item Deprecation of traits array following the allocator_handle expression in
400       @code{uses_allocators} @tab N @tab
401 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
402       @tab N @tab
403 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
404 @item Deprecation of delimited form of @code{declare target} @tab N @tab
405 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
406 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
407       @tab Y @tab
408 @item @code{ompt_callback_work} @tab N @tab
409 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
410       @tab Y @tab
411 @item New @code{doacross} clause as alias for @code{depend} with
412       @code{source}/@code{sink} modifier @tab Y @tab
413 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
414       @tab N @tab
415 @item @code{omp_cur_iteration} keyword @tab Y @tab
416 @end multitable
418 @unnumberedsubsec Other new OpenMP 5.2 features
420 @multitable @columnfractions .60 .10 .25
421 @headitem Description @tab Status @tab Comments
422 @item For Fortran, optional comma between directive and clause @tab N @tab
423 @item Conforming device numbers and @code{omp_initial_device} and
424       @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
425 @item Initial value of @var{default-device-var} ICV with
426       @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
427 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
428       of the @code{interop} construct @tab N @tab
429 @end multitable
432 @node OpenMP Technical Report 11
433 @section OpenMP Technical Report 11
435 Technical Report (TR) 11 is the first preview for OpenMP 6.0.
437 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
438 @multitable @columnfractions .60 .10 .25
439 @item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
440       @tab N/A @tab Backward compatibility
441 @item The @code{decl} attribute was added to the C++ attribute syntax
442       @tab N @tab
443 @item @code{_ALL} suffix to the device-scope environment variables
444       @tab P @tab Host device number wrongly accepted
445 @item For Fortran, @emph{locator list} can be also function reference with
446       data pointer result @tab N @tab
447 @item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
448       @tab N @tab
449 @item Implicit reduction identifiers of C++ classes
450       @tab N @tab
451 @item Change of the @emph{map-type} property from @emph{ultimate} to
452       @emph{default} @tab N @tab
453 @item Concept of @emph{assumed-size arrays} in C and C++
454       @tab N @tab
455 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
456       @tab N @tab
457 @item @code{groupprivate} directive @tab N @tab
458 @item @code{local} clause to declare target directive @tab N @tab
459 @item @code{part_size} allocator trait @tab N @tab
460 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
461       allocator traits
462       @tab N @tab
463 @item @code{access} allocator trait changes @tab N @tab
464 @item Extension of @code{interop} operation of @code{append_args}, allowing all
465       modifiers of the @code{init} clause
466       @tab N @tab
467 @item @code{interop} clause to @code{dispatch} @tab N @tab
468 @item @code{apply} code to loop-transforming constructs @tab N @tab
469 @item @code{omp_curr_progress_width} identifier @tab N @tab
470 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
471 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
472 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
473 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
474 @item Routines for obtaining memory spaces/allocators for shared/device memory
475       @tab N @tab
476 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
477 @item @code{omp_get_submemspace} routine @tab N @tab
478 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
479 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
480       @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
481 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
482 @end multitable
484 @unnumberedsubsec Other new TR 11 features
485 @multitable @columnfractions .60 .10 .25
486 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
487 @item Mapping lambda captures @tab N @tab
488 @item For Fortran, atomic compare with storing the comparison result
489       @tab N @tab
490 @end multitable
494 @c ---------------------------------------------------------------------
495 @c OpenMP Runtime Library Routines
496 @c ---------------------------------------------------------------------
498 @node Runtime Library Routines
499 @chapter OpenMP Runtime Library Routines
501 The runtime routines described here are defined by Section 3 of the OpenMP
502 specification in version 4.5.  The routines are structured in following
503 three parts:
505 @menu
506 Control threads, processors and the parallel environment.  They have C
507 linkage, and do not throw exceptions.
509 * omp_get_active_level::        Number of active parallel regions
510 * omp_get_ancestor_thread_num:: Ancestor thread ID
511 * omp_get_cancellation::        Whether cancellation support is enabled
512 * omp_get_default_device::      Get the default device for target regions
513 * omp_get_device_num::          Get device that current thread is running on
514 * omp_get_dynamic::             Dynamic teams setting
515 * omp_get_initial_device::      Device number of host device
516 * omp_get_level::               Number of parallel regions
517 * omp_get_max_active_levels::   Current maximum number of active regions
518 * omp_get_max_task_priority::   Maximum task priority value that can be set
519 * omp_get_max_teams::           Maximum number of teams for teams region
520 * omp_get_max_threads::         Maximum number of threads of parallel region
521 * omp_get_nested::              Nested parallel regions
522 * omp_get_num_devices::         Number of target devices
523 * omp_get_num_procs::           Number of processors online
524 * omp_get_num_teams::           Number of teams
525 * omp_get_num_threads::         Size of the active team
526 * omp_get_proc_bind::           Whether threads may be moved between CPUs
527 * omp_get_schedule::            Obtain the runtime scheduling method
528 * omp_get_supported_active_levels:: Maximum number of active regions supported
529 * omp_get_team_num::            Get team number
530 * omp_get_team_size::           Number of threads in a team
531 * omp_get_teams_thread_limit::  Maximum number of threads imposed by teams
532 * omp_get_thread_limit::        Maximum number of threads
533 * omp_get_thread_num::          Current thread ID
534 * omp_in_parallel::             Whether a parallel region is active
535 * omp_in_final::                Whether in final or included task region
536 * omp_is_initial_device::       Whether executing on the host device
537 * omp_set_default_device::      Set the default device for target regions
538 * omp_set_dynamic::             Enable/disable dynamic teams
539 * omp_set_max_active_levels::   Limits the number of active parallel regions
540 * omp_set_nested::              Enable/disable nested parallel regions
541 * omp_set_num_teams::           Set upper teams limit for teams region
542 * omp_set_num_threads::         Set upper team size limit
543 * omp_set_schedule::            Set the runtime scheduling method
544 * omp_set_teams_thread_limit::  Set upper thread limit for teams construct
546 Initialize, set, test, unset and destroy simple and nested locks.
548 * omp_init_lock::            Initialize simple lock
549 * omp_set_lock::             Wait for and set simple lock
550 * omp_test_lock::            Test and set simple lock if available
551 * omp_unset_lock::           Unset simple lock
552 * omp_destroy_lock::         Destroy simple lock
553 * omp_init_nest_lock::       Initialize nested lock
554 * omp_set_nest_lock::        Wait for and set simple lock
555 * omp_test_nest_lock::       Test and set nested lock if available
556 * omp_unset_nest_lock::      Unset nested lock
557 * omp_destroy_nest_lock::    Destroy nested lock
559 Portable, thread-based, wall clock timer.
561 * omp_get_wtick::            Get timer precision.
562 * omp_get_wtime::            Elapsed wall clock time.
564 Support for event objects.
566 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
567 @end menu
571 @node omp_get_active_level
572 @section @code{omp_get_active_level} -- Number of parallel regions
573 @table @asis
574 @item @emph{Description}:
575 This function returns the nesting level for the active parallel blocks,
576 which enclose the calling call.
578 @item @emph{C/C++}
579 @multitable @columnfractions .20 .80
580 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
581 @end multitable
583 @item @emph{Fortran}:
584 @multitable @columnfractions .20 .80
585 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
586 @end multitable
588 @item @emph{See also}:
589 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
591 @item @emph{Reference}:
592 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
593 @end table
597 @node omp_get_ancestor_thread_num
598 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
599 @table @asis
600 @item @emph{Description}:
601 This function returns the thread identification number for the given
602 nesting level of the current thread.  For values of @var{level} outside
603 zero to @code{omp_get_level} -1 is returned; if @var{level} is
604 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
606 @item @emph{C/C++}
607 @multitable @columnfractions .20 .80
608 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
609 @end multitable
611 @item @emph{Fortran}:
612 @multitable @columnfractions .20 .80
613 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
614 @item                   @tab @code{integer level}
615 @end multitable
617 @item @emph{See also}:
618 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
620 @item @emph{Reference}:
621 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
622 @end table
626 @node omp_get_cancellation
627 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
628 @table @asis
629 @item @emph{Description}:
630 This function returns @code{true} if cancellation is activated, @code{false}
631 otherwise.  Here, @code{true} and @code{false} represent their language-specific
632 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
633 deactivated.
635 @item @emph{C/C++}:
636 @multitable @columnfractions .20 .80
637 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
638 @end multitable
640 @item @emph{Fortran}:
641 @multitable @columnfractions .20 .80
642 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
643 @end multitable
645 @item @emph{See also}:
646 @ref{OMP_CANCELLATION}
648 @item @emph{Reference}:
649 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
650 @end table
654 @node omp_get_default_device
655 @section @code{omp_get_default_device} -- Get the default device for target regions
656 @table @asis
657 @item @emph{Description}:
658 Get the default device for target regions without device clause.
660 @item @emph{C/C++}:
661 @multitable @columnfractions .20 .80
662 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
663 @end multitable
665 @item @emph{Fortran}:
666 @multitable @columnfractions .20 .80
667 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
668 @end multitable
670 @item @emph{See also}:
671 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
673 @item @emph{Reference}:
674 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
675 @end table
679 @node omp_get_device_num
680 @section @code{omp_get_device_num} -- Return device number of current device
681 @table @asis
682 @item @emph{Description}:
683 This function returns a device number that represents the device that the
684 current thread is executing on. For OpenMP 5.0, this must be equal to the
685 value returned by the @code{omp_get_initial_device} function when called
686 from the host.
688 @item @emph{C/C++}
689 @multitable @columnfractions .20 .80
690 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
691 @end multitable
693 @item @emph{Fortran}:
694 @multitable @columnfractions .20 .80
695 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
696 @end multitable
698 @item @emph{See also}:
699 @ref{omp_get_initial_device}
701 @item @emph{Reference}:
702 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
703 @end table
707 @node omp_get_dynamic
708 @section @code{omp_get_dynamic} -- Dynamic teams setting
709 @table @asis
710 @item @emph{Description}:
711 This function returns @code{true} if enabled, @code{false} otherwise. 
712 Here, @code{true} and @code{false} represent their language-specific 
713 counterparts.
715 The dynamic team setting may be initialized at startup by the 
716 @env{OMP_DYNAMIC} environment variable or at runtime using
717 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
718 disabled by default.
720 @item @emph{C/C++}:
721 @multitable @columnfractions .20 .80
722 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
723 @end multitable
725 @item @emph{Fortran}:
726 @multitable @columnfractions .20 .80
727 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
728 @end multitable
730 @item @emph{See also}:
731 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
733 @item @emph{Reference}:
734 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
735 @end table
739 @node omp_get_initial_device
740 @section @code{omp_get_initial_device} -- Return device number of initial device
741 @table @asis
742 @item @emph{Description}:
743 This function returns a device number that represents the host device.
744 For OpenMP 5.1, this must be equal to the value returned by the
745 @code{omp_get_num_devices} function.
747 @item @emph{C/C++}
748 @multitable @columnfractions .20 .80
749 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
750 @end multitable
752 @item @emph{Fortran}:
753 @multitable @columnfractions .20 .80
754 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
755 @end multitable
757 @item @emph{See also}:
758 @ref{omp_get_num_devices}
760 @item @emph{Reference}:
761 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
762 @end table
766 @node omp_get_level
767 @section @code{omp_get_level} -- Obtain the current nesting level
768 @table @asis
769 @item @emph{Description}:
770 This function returns the nesting level for the parallel blocks,
771 which enclose the calling call.
773 @item @emph{C/C++}
774 @multitable @columnfractions .20 .80
775 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
776 @end multitable
778 @item @emph{Fortran}:
779 @multitable @columnfractions .20 .80
780 @item @emph{Interface}: @tab @code{integer function omp_level()}
781 @end multitable
783 @item @emph{See also}:
784 @ref{omp_get_active_level}
786 @item @emph{Reference}:
787 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
788 @end table
792 @node omp_get_max_active_levels
793 @section @code{omp_get_max_active_levels} -- Current maximum number of active regions
794 @table @asis
795 @item @emph{Description}:
796 This function obtains the maximum allowed number of nested, active parallel regions.
798 @item @emph{C/C++}
799 @multitable @columnfractions .20 .80
800 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
801 @end multitable
803 @item @emph{Fortran}:
804 @multitable @columnfractions .20 .80
805 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
806 @end multitable
808 @item @emph{See also}:
809 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
811 @item @emph{Reference}:
812 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
813 @end table
816 @node omp_get_max_task_priority
817 @section @code{omp_get_max_task_priority} -- Maximum priority value
818 that can be set for tasks.
819 @table @asis
820 @item @emph{Description}:
821 This function obtains the maximum allowed priority number for tasks.
823 @item @emph{C/C++}
824 @multitable @columnfractions .20 .80
825 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
826 @end multitable
828 @item @emph{Fortran}:
829 @multitable @columnfractions .20 .80
830 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
831 @end multitable
833 @item @emph{Reference}:
834 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
835 @end table
838 @node omp_get_max_teams
839 @section @code{omp_get_max_teams} -- Maximum number of teams of teams region
840 @table @asis
841 @item @emph{Description}:
842 Return the maximum number of teams used for the teams region
843 that does not use the clause @code{num_teams}.
845 @item @emph{C/C++}:
846 @multitable @columnfractions .20 .80
847 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
848 @end multitable
850 @item @emph{Fortran}:
851 @multitable @columnfractions .20 .80
852 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
853 @end multitable
855 @item @emph{See also}:
856 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
858 @item @emph{Reference}:
859 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
860 @end table
864 @node omp_get_max_threads
865 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
866 @table @asis
867 @item @emph{Description}:
868 Return the maximum number of threads used for the current parallel region
869 that does not use the clause @code{num_threads}.
871 @item @emph{C/C++}:
872 @multitable @columnfractions .20 .80
873 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
874 @end multitable
876 @item @emph{Fortran}:
877 @multitable @columnfractions .20 .80
878 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
879 @end multitable
881 @item @emph{See also}:
882 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
884 @item @emph{Reference}:
885 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
886 @end table
890 @node omp_get_nested
891 @section @code{omp_get_nested} -- Nested parallel regions
892 @table @asis
893 @item @emph{Description}:
894 This function returns @code{true} if nested parallel regions are
895 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
896 represent their language-specific counterparts.
898 The state of nested parallel regions at startup depends on several
899 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
900 and is set to greater than one, then nested parallel regions will be
901 enabled.  If not defined, then the value of the @env{OMP_NESTED}
902 environment variable will be followed if defined.  If neither are
903 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
904 are defined with a list of more than one value, then nested parallel
905 regions are enabled.  If none of these are defined, then nested parallel
906 regions are disabled by default.
908 Nested parallel regions can be enabled or disabled at runtime using
909 @code{omp_set_nested}, or by setting the maximum number of nested
910 regions with @code{omp_set_max_active_levels} to one to disable, or
911 above one to enable.
913 Note that the @code{omp_get_nested} API routine was deprecated
914 in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
916 @item @emph{C/C++}:
917 @multitable @columnfractions .20 .80
918 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
919 @end multitable
921 @item @emph{Fortran}:
922 @multitable @columnfractions .20 .80
923 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
924 @end multitable
926 @item @emph{See also}:
927 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
928 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
930 @item @emph{Reference}:
931 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
932 @end table
936 @node omp_get_num_devices
937 @section @code{omp_get_num_devices} -- Number of target devices
938 @table @asis
939 @item @emph{Description}:
940 Returns the number of target devices.
942 @item @emph{C/C++}:
943 @multitable @columnfractions .20 .80
944 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
945 @end multitable
947 @item @emph{Fortran}:
948 @multitable @columnfractions .20 .80
949 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
950 @end multitable
952 @item @emph{Reference}:
953 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
954 @end table
958 @node omp_get_num_procs
959 @section @code{omp_get_num_procs} -- Number of processors online
960 @table @asis
961 @item @emph{Description}:
962 Returns the number of processors online on that device.
964 @item @emph{C/C++}:
965 @multitable @columnfractions .20 .80
966 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
967 @end multitable
969 @item @emph{Fortran}:
970 @multitable @columnfractions .20 .80
971 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
972 @end multitable
974 @item @emph{Reference}:
975 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
976 @end table
980 @node omp_get_num_teams
981 @section @code{omp_get_num_teams} -- Number of teams
982 @table @asis
983 @item @emph{Description}:
984 Returns the number of teams in the current team region.
986 @item @emph{C/C++}:
987 @multitable @columnfractions .20 .80
988 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
989 @end multitable
991 @item @emph{Fortran}:
992 @multitable @columnfractions .20 .80
993 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
994 @end multitable
996 @item @emph{Reference}:
997 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
998 @end table
1002 @node omp_get_num_threads
1003 @section @code{omp_get_num_threads} -- Size of the active team
1004 @table @asis
1005 @item @emph{Description}:
1006 Returns the number of threads in the current team.  In a sequential section of
1007 the program @code{omp_get_num_threads} returns 1.
1009 The default team size may be initialized at startup by the 
1010 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
1011 of the current team may be set either by the @code{NUM_THREADS}
1012 clause or by @code{omp_set_num_threads}.  If none of the above were
1013 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
1014 one thread per CPU online is used.
1016 @item @emph{C/C++}:
1017 @multitable @columnfractions .20 .80
1018 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
1019 @end multitable
1021 @item @emph{Fortran}:
1022 @multitable @columnfractions .20 .80
1023 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
1024 @end multitable
1026 @item @emph{See also}:
1027 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
1029 @item @emph{Reference}:
1030 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
1031 @end table
1035 @node omp_get_proc_bind
1036 @section @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1037 @table @asis
1038 @item @emph{Description}:
1039 This functions returns the currently active thread affinity policy, which is
1040 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
1041 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1042 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1043 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1045 @item @emph{C/C++}:
1046 @multitable @columnfractions .20 .80
1047 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1048 @end multitable
1050 @item @emph{Fortran}:
1051 @multitable @columnfractions .20 .80
1052 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1053 @end multitable
1055 @item @emph{See also}:
1056 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1058 @item @emph{Reference}:
1059 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1060 @end table
1064 @node omp_get_schedule
1065 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
1066 @table @asis
1067 @item @emph{Description}:
1068 Obtain the runtime scheduling method.  The @var{kind} argument will be
1069 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
1070 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
1071 @var{chunk_size}, is set to the chunk size.
1073 @item @emph{C/C++}
1074 @multitable @columnfractions .20 .80
1075 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1076 @end multitable
1078 @item @emph{Fortran}:
1079 @multitable @columnfractions .20 .80
1080 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1081 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
1082 @item                   @tab @code{integer chunk_size}
1083 @end multitable
1085 @item @emph{See also}:
1086 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1088 @item @emph{Reference}:
1089 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1090 @end table
1093 @node omp_get_supported_active_levels
1094 @section @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1095 @table @asis
1096 @item @emph{Description}:
1097 This function returns the maximum number of nested, active parallel regions
1098 supported by this implementation.
1100 @item @emph{C/C++}
1101 @multitable @columnfractions .20 .80
1102 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1103 @end multitable
1105 @item @emph{Fortran}:
1106 @multitable @columnfractions .20 .80
1107 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1108 @end multitable
1110 @item @emph{See also}:
1111 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1113 @item @emph{Reference}:
1114 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1115 @end table
1119 @node omp_get_team_num
1120 @section @code{omp_get_team_num} -- Get team number
1121 @table @asis
1122 @item @emph{Description}:
1123 Returns the team number of the calling thread.
1125 @item @emph{C/C++}:
1126 @multitable @columnfractions .20 .80
1127 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1128 @end multitable
1130 @item @emph{Fortran}:
1131 @multitable @columnfractions .20 .80
1132 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1133 @end multitable
1135 @item @emph{Reference}:
1136 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1137 @end table
1141 @node omp_get_team_size
1142 @section @code{omp_get_team_size} -- Number of threads in a team
1143 @table @asis
1144 @item @emph{Description}:
1145 This function returns the number of threads in a thread team to which
1146 either the current thread or its ancestor belongs.  For values of @var{level}
1147 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1148 1 is returned, and for @code{omp_get_level}, the result is identical
1149 to @code{omp_get_num_threads}.
1151 @item @emph{C/C++}:
1152 @multitable @columnfractions .20 .80
1153 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1154 @end multitable
1156 @item @emph{Fortran}:
1157 @multitable @columnfractions .20 .80
1158 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1159 @item                   @tab @code{integer level}
1160 @end multitable
1162 @item @emph{See also}:
1163 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1165 @item @emph{Reference}:
1166 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1167 @end table
1171 @node omp_get_teams_thread_limit
1172 @section @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1173 @table @asis
1174 @item @emph{Description}:
1175 Return the maximum number of threads that will be able to participate in
1176 each team created by a teams construct.
1178 @item @emph{C/C++}:
1179 @multitable @columnfractions .20 .80
1180 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1181 @end multitable
1183 @item @emph{Fortran}:
1184 @multitable @columnfractions .20 .80
1185 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1186 @end multitable
1188 @item @emph{See also}:
1189 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1191 @item @emph{Reference}:
1192 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1193 @end table
1197 @node omp_get_thread_limit
1198 @section @code{omp_get_thread_limit} -- Maximum number of threads
1199 @table @asis
1200 @item @emph{Description}:
1201 Return the maximum number of threads of the program.
1203 @item @emph{C/C++}:
1204 @multitable @columnfractions .20 .80
1205 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1206 @end multitable
1208 @item @emph{Fortran}:
1209 @multitable @columnfractions .20 .80
1210 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1211 @end multitable
1213 @item @emph{See also}:
1214 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1216 @item @emph{Reference}:
1217 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1218 @end table
1222 @node omp_get_thread_num
1223 @section @code{omp_get_thread_num} -- Current thread ID
1224 @table @asis
1225 @item @emph{Description}:
1226 Returns a unique thread identification number within the current team.
1227 In a sequential parts of the program, @code{omp_get_thread_num}
1228 always returns 0.  In parallel regions the return value varies
1229 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
1230 value of the primary thread of a team is always 0.
1232 @item @emph{C/C++}:
1233 @multitable @columnfractions .20 .80
1234 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
1235 @end multitable
1237 @item @emph{Fortran}:
1238 @multitable @columnfractions .20 .80
1239 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
1240 @end multitable
1242 @item @emph{See also}:
1243 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
1245 @item @emph{Reference}:
1246 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
1247 @end table
1251 @node omp_in_parallel
1252 @section @code{omp_in_parallel} -- Whether a parallel region is active
1253 @table @asis
1254 @item @emph{Description}:
1255 This function returns @code{true} if currently running in parallel,
1256 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1257 their language-specific counterparts.
1259 @item @emph{C/C++}:
1260 @multitable @columnfractions .20 .80
1261 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
1262 @end multitable
1264 @item @emph{Fortran}:
1265 @multitable @columnfractions .20 .80
1266 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
1267 @end multitable
1269 @item @emph{Reference}:
1270 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
1271 @end table
1274 @node omp_in_final
1275 @section @code{omp_in_final} -- Whether in final or included task region
1276 @table @asis
1277 @item @emph{Description}:
1278 This function returns @code{true} if currently running in a final
1279 or included task region, @code{false} otherwise.  Here, @code{true}
1280 and @code{false} represent their language-specific counterparts.
1282 @item @emph{C/C++}:
1283 @multitable @columnfractions .20 .80
1284 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1285 @end multitable
1287 @item @emph{Fortran}:
1288 @multitable @columnfractions .20 .80
1289 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1290 @end multitable
1292 @item @emph{Reference}:
1293 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1294 @end table
1298 @node omp_is_initial_device
1299 @section @code{omp_is_initial_device} -- Whether executing on the host device
1300 @table @asis
1301 @item @emph{Description}:
1302 This function returns @code{true} if currently running on the host device,
1303 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1304 their language-specific counterparts.
1306 @item @emph{C/C++}:
1307 @multitable @columnfractions .20 .80
1308 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1309 @end multitable
1311 @item @emph{Fortran}:
1312 @multitable @columnfractions .20 .80
1313 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1314 @end multitable
1316 @item @emph{Reference}:
1317 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1318 @end table
1322 @node omp_set_default_device
1323 @section @code{omp_set_default_device} -- Set the default device for target regions
1324 @table @asis
1325 @item @emph{Description}:
1326 Set the default device for target regions without device clause.  The argument
1327 shall be a nonnegative device number.
1329 @item @emph{C/C++}:
1330 @multitable @columnfractions .20 .80
1331 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1332 @end multitable
1334 @item @emph{Fortran}:
1335 @multitable @columnfractions .20 .80
1336 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1337 @item                   @tab @code{integer device_num}
1338 @end multitable
1340 @item @emph{See also}:
1341 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1343 @item @emph{Reference}:
1344 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1345 @end table
1349 @node omp_set_dynamic
1350 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
1351 @table @asis
1352 @item @emph{Description}:
1353 Enable or disable the dynamic adjustment of the number of threads 
1354 within a team.  The function takes the language-specific equivalent
1355 of @code{true} and @code{false}, where @code{true} enables dynamic 
1356 adjustment of team sizes and @code{false} disables it.
1358 @item @emph{C/C++}:
1359 @multitable @columnfractions .20 .80
1360 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
1361 @end multitable
1363 @item @emph{Fortran}:
1364 @multitable @columnfractions .20 .80
1365 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
1366 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
1367 @end multitable
1369 @item @emph{See also}:
1370 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
1372 @item @emph{Reference}:
1373 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
1374 @end table
1378 @node omp_set_max_active_levels
1379 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1380 @table @asis
1381 @item @emph{Description}:
1382 This function limits the maximum allowed number of nested, active
1383 parallel regions.  @var{max_levels} must be less or equal to
1384 the value returned by @code{omp_get_supported_active_levels}.
1386 @item @emph{C/C++}
1387 @multitable @columnfractions .20 .80
1388 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1389 @end multitable
1391 @item @emph{Fortran}:
1392 @multitable @columnfractions .20 .80
1393 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1394 @item                   @tab @code{integer max_levels}
1395 @end multitable
1397 @item @emph{See also}:
1398 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1399 @ref{omp_get_supported_active_levels}
1401 @item @emph{Reference}:
1402 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1403 @end table
1407 @node omp_set_nested
1408 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
1409 @table @asis
1410 @item @emph{Description}:
1411 Enable or disable nested parallel regions, i.e., whether team members
1412 are allowed to create new teams.  The function takes the language-specific
1413 equivalent of @code{true} and @code{false}, where @code{true} enables 
1414 dynamic adjustment of team sizes and @code{false} disables it.
1416 Enabling nested parallel regions will also set the maximum number of
1417 active nested regions to the maximum supported.  Disabling nested parallel
1418 regions will set the maximum number of active nested regions to one.
1420 Note that the @code{omp_set_nested} API routine was deprecated
1421 in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
1423 @item @emph{C/C++}:
1424 @multitable @columnfractions .20 .80
1425 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
1426 @end multitable
1428 @item @emph{Fortran}:
1429 @multitable @columnfractions .20 .80
1430 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
1431 @item                   @tab @code{logical, intent(in) :: nested}
1432 @end multitable
1434 @item @emph{See also}:
1435 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
1436 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1438 @item @emph{Reference}:
1439 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
1440 @end table
1444 @node omp_set_num_teams
1445 @section @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1446 @table @asis
1447 @item @emph{Description}:
1448 Specifies the upper bound for number of teams created by the teams construct
1449 which does not specify a @code{num_teams} clause.  The
1450 argument of @code{omp_set_num_teams} shall be a positive integer.
1452 @item @emph{C/C++}:
1453 @multitable @columnfractions .20 .80
1454 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1455 @end multitable
1457 @item @emph{Fortran}:
1458 @multitable @columnfractions .20 .80
1459 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1460 @item                   @tab @code{integer, intent(in) :: num_teams}
1461 @end multitable
1463 @item @emph{See also}:
1464 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1466 @item @emph{Reference}:
1467 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1468 @end table
1472 @node omp_set_num_threads
1473 @section @code{omp_set_num_threads} -- Set upper team size limit
1474 @table @asis
1475 @item @emph{Description}:
1476 Specifies the number of threads used by default in subsequent parallel 
1477 sections, if those do not specify a @code{num_threads} clause.  The
1478 argument of @code{omp_set_num_threads} shall be a positive integer.
1480 @item @emph{C/C++}:
1481 @multitable @columnfractions .20 .80
1482 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
1483 @end multitable
1485 @item @emph{Fortran}:
1486 @multitable @columnfractions .20 .80
1487 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
1488 @item                   @tab @code{integer, intent(in) :: num_threads}
1489 @end multitable
1491 @item @emph{See also}:
1492 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
1494 @item @emph{Reference}:
1495 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
1496 @end table
1500 @node omp_set_schedule
1501 @section @code{omp_set_schedule} -- Set the runtime scheduling method
1502 @table @asis
1503 @item @emph{Description}:
1504 Sets the runtime scheduling method.  The @var{kind} argument can have the
1505 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1506 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
1507 @code{omp_sched_auto}, the chunk size is set to the value of
1508 @var{chunk_size} if positive, or to the default value if zero or negative.
1509 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1511 @item @emph{C/C++}
1512 @multitable @columnfractions .20 .80
1513 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1514 @end multitable
1516 @item @emph{Fortran}:
1517 @multitable @columnfractions .20 .80
1518 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1519 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
1520 @item                   @tab @code{integer chunk_size}
1521 @end multitable
1523 @item @emph{See also}:
1524 @ref{omp_get_schedule}
1525 @ref{OMP_SCHEDULE}
1527 @item @emph{Reference}:
1528 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1529 @end table
1533 @node omp_set_teams_thread_limit
1534 @section @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1535 @table @asis
1536 @item @emph{Description}:
1537 Specifies the upper bound for number of threads that will be available
1538 for each team created by the teams construct which does not specify a
1539 @code{thread_limit} clause.  The argument of
1540 @code{omp_set_teams_thread_limit} shall be a positive integer.
1542 @item @emph{C/C++}:
1543 @multitable @columnfractions .20 .80
1544 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1545 @end multitable
1547 @item @emph{Fortran}:
1548 @multitable @columnfractions .20 .80
1549 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1550 @item                   @tab @code{integer, intent(in) :: thread_limit}
1551 @end multitable
1553 @item @emph{See also}:
1554 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1556 @item @emph{Reference}:
1557 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1558 @end table
1562 @node omp_init_lock
1563 @section @code{omp_init_lock} -- Initialize simple lock
1564 @table @asis
1565 @item @emph{Description}:
1566 Initialize a simple lock.  After initialization, the lock is in
1567 an unlocked state.
1569 @item @emph{C/C++}:
1570 @multitable @columnfractions .20 .80
1571 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1572 @end multitable
1574 @item @emph{Fortran}:
1575 @multitable @columnfractions .20 .80
1576 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1577 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1578 @end multitable
1580 @item @emph{See also}:
1581 @ref{omp_destroy_lock}
1583 @item @emph{Reference}: 
1584 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1585 @end table
1589 @node omp_set_lock
1590 @section @code{omp_set_lock} -- Wait for and set simple lock
1591 @table @asis
1592 @item @emph{Description}:
1593 Before setting a simple lock, the lock variable must be initialized by 
1594 @code{omp_init_lock}.  The calling thread is blocked until the lock 
1595 is available.  If the lock is already held by the current thread, 
1596 a deadlock occurs.
1598 @item @emph{C/C++}:
1599 @multitable @columnfractions .20 .80
1600 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1601 @end multitable
1603 @item @emph{Fortran}:
1604 @multitable @columnfractions .20 .80
1605 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1606 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1607 @end multitable
1609 @item @emph{See also}:
1610 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1612 @item @emph{Reference}: 
1613 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1614 @end table
1618 @node omp_test_lock
1619 @section @code{omp_test_lock} -- Test and set simple lock if available
1620 @table @asis
1621 @item @emph{Description}:
1622 Before setting a simple lock, the lock variable must be initialized by 
1623 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
1624 does not block if the lock is not available.  This function returns
1625 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
1626 @code{false} represent their language-specific counterparts.
1628 @item @emph{C/C++}:
1629 @multitable @columnfractions .20 .80
1630 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1631 @end multitable
1633 @item @emph{Fortran}:
1634 @multitable @columnfractions .20 .80
1635 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1636 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1637 @end multitable
1639 @item @emph{See also}:
1640 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1642 @item @emph{Reference}: 
1643 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1644 @end table
1648 @node omp_unset_lock
1649 @section @code{omp_unset_lock} -- Unset simple lock
1650 @table @asis
1651 @item @emph{Description}:
1652 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1653 or @code{omp_test_lock} before.  In addition, the lock must be held by the
1654 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
1655 or more threads attempted to set the lock before, one of them is chosen to,
1656 again, set the lock to itself.
1658 @item @emph{C/C++}:
1659 @multitable @columnfractions .20 .80
1660 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1661 @end multitable
1663 @item @emph{Fortran}:
1664 @multitable @columnfractions .20 .80
1665 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1666 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1667 @end multitable
1669 @item @emph{See also}:
1670 @ref{omp_set_lock}, @ref{omp_test_lock}
1672 @item @emph{Reference}: 
1673 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1674 @end table
1678 @node omp_destroy_lock
1679 @section @code{omp_destroy_lock} -- Destroy simple lock
1680 @table @asis
1681 @item @emph{Description}:
1682 Destroy a simple lock.  In order to be destroyed, a simple lock must be
1683 in the unlocked state. 
1685 @item @emph{C/C++}:
1686 @multitable @columnfractions .20 .80
1687 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1688 @end multitable
1690 @item @emph{Fortran}:
1691 @multitable @columnfractions .20 .80
1692 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1693 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1694 @end multitable
1696 @item @emph{See also}:
1697 @ref{omp_init_lock}
1699 @item @emph{Reference}: 
1700 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1701 @end table
1705 @node omp_init_nest_lock
1706 @section @code{omp_init_nest_lock} -- Initialize nested lock
1707 @table @asis
1708 @item @emph{Description}:
1709 Initialize a nested lock.  After initialization, the lock is in
1710 an unlocked state and the nesting count is set to zero.
1712 @item @emph{C/C++}:
1713 @multitable @columnfractions .20 .80
1714 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1715 @end multitable
1717 @item @emph{Fortran}:
1718 @multitable @columnfractions .20 .80
1719 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1720 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1721 @end multitable
1723 @item @emph{See also}:
1724 @ref{omp_destroy_nest_lock}
1726 @item @emph{Reference}:
1727 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1728 @end table
1731 @node omp_set_nest_lock
1732 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1733 @table @asis
1734 @item @emph{Description}:
1735 Before setting a nested lock, the lock variable must be initialized by 
1736 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
1737 is available.  If the lock is already held by the current thread, the
1738 nesting count for the lock is incremented.
1740 @item @emph{C/C++}:
1741 @multitable @columnfractions .20 .80
1742 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1743 @end multitable
1745 @item @emph{Fortran}:
1746 @multitable @columnfractions .20 .80
1747 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1748 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1749 @end multitable
1751 @item @emph{See also}:
1752 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1754 @item @emph{Reference}: 
1755 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1756 @end table
1760 @node omp_test_nest_lock
1761 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1762 @table @asis
1763 @item @emph{Description}:
1764 Before setting a nested lock, the lock variable must be initialized by 
1765 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
1766 @code{omp_test_nest_lock} does not block if the lock is not available. 
1767 If the lock is already held by the current thread, the new nesting count 
1768 is returned.  Otherwise, the return value equals zero.
1770 @item @emph{C/C++}:
1771 @multitable @columnfractions .20 .80
1772 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1773 @end multitable
1775 @item @emph{Fortran}:
1776 @multitable @columnfractions .20 .80
1777 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1778 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1779 @end multitable
1782 @item @emph{See also}:
1783 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1785 @item @emph{Reference}: 
1786 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1787 @end table
1791 @node omp_unset_nest_lock
1792 @section @code{omp_unset_nest_lock} -- Unset nested lock
1793 @table @asis
1794 @item @emph{Description}:
1795 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1796 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
1797 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
1798 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
1799 one of them is chosen to, again, set the lock to itself.
1801 @item @emph{C/C++}:
1802 @multitable @columnfractions .20 .80
1803 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1804 @end multitable
1806 @item @emph{Fortran}:
1807 @multitable @columnfractions .20 .80
1808 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1809 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1810 @end multitable
1812 @item @emph{See also}:
1813 @ref{omp_set_nest_lock}
1815 @item @emph{Reference}: 
1816 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1817 @end table
1821 @node omp_destroy_nest_lock
1822 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1823 @table @asis
1824 @item @emph{Description}:
1825 Destroy a nested lock.  In order to be destroyed, a nested lock must be
1826 in the unlocked state and its nesting count must equal zero.
1828 @item @emph{C/C++}:
1829 @multitable @columnfractions .20 .80
1830 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1831 @end multitable
1833 @item @emph{Fortran}:
1834 @multitable @columnfractions .20 .80
1835 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1836 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1837 @end multitable
1839 @item @emph{See also}:
1840 @ref{omp_init_lock}
1842 @item @emph{Reference}: 
1843 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1844 @end table
1848 @node omp_get_wtick
1849 @section @code{omp_get_wtick} -- Get timer precision
1850 @table @asis
1851 @item @emph{Description}:
1852 Gets the timer precision, i.e., the number of seconds between two 
1853 successive clock ticks.
1855 @item @emph{C/C++}:
1856 @multitable @columnfractions .20 .80
1857 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1858 @end multitable
1860 @item @emph{Fortran}:
1861 @multitable @columnfractions .20 .80
1862 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1863 @end multitable
1865 @item @emph{See also}:
1866 @ref{omp_get_wtime}
1868 @item @emph{Reference}: 
1869 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
1870 @end table
1874 @node omp_get_wtime
1875 @section @code{omp_get_wtime} -- Elapsed wall clock time
1876 @table @asis
1877 @item @emph{Description}:
1878 Elapsed wall clock time in seconds.  The time is measured per thread, no
1879 guarantee can be made that two distinct threads measure the same time.
1880 Time is measured from some "time in the past", which is an arbitrary time
1881 guaranteed not to change during the execution of the program.
1883 @item @emph{C/C++}:
1884 @multitable @columnfractions .20 .80
1885 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1886 @end multitable
1888 @item @emph{Fortran}:
1889 @multitable @columnfractions .20 .80
1890 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1891 @end multitable
1893 @item @emph{See also}:
1894 @ref{omp_get_wtick}
1896 @item @emph{Reference}: 
1897 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
1898 @end table
1902 @node omp_fulfill_event
1903 @section @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
1904 @table @asis
1905 @item @emph{Description}:
1906 Fulfill the event associated with the event handle argument.  Currently, it
1907 is only used to fulfill events generated by detach clauses on task
1908 constructs - the effect of fulfilling the event is to allow the task to
1909 complete.
1911 The result of calling @code{omp_fulfill_event} with an event handle other
1912 than that generated by a detach clause is undefined.  Calling it with an
1913 event handle that has already been fulfilled is also undefined.
1915 @item @emph{C/C++}:
1916 @multitable @columnfractions .20 .80
1917 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
1918 @end multitable
1920 @item @emph{Fortran}:
1921 @multitable @columnfractions .20 .80
1922 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
1923 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
1924 @end multitable
1926 @item @emph{Reference}:
1927 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
1928 @end table
1932 @c ---------------------------------------------------------------------
1933 @c OpenMP Environment Variables
1934 @c ---------------------------------------------------------------------
1936 @node Environment Variables
1937 @chapter OpenMP Environment Variables
1939 The environment variables which beginning with @env{OMP_} are defined by
1940 section 4 of the OpenMP specification in version 4.5 or in a later version
1941 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
1942 Most @env{OMP_} environment variables have an associated internal control
1943 variable (ICV).
1945 For any OpenMP environment variable that sets an ICV and is neither
1946 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
1947 device-specific environment variables exist.  For them, the environment
1948 variable without suffix affects the host.  The suffix @code{_DEV_} followed
1949 by a non-negative device number less that the number of available devices sets
1950 the ICV for the corresponding device.  The suffix @code{_DEV} sets the ICV
1951 of all non-host devices for which a device-specific corresponding environment
1952 variable has not been set while the @code{_ALL} suffix sets the ICV of all
1953 host and non-host devices for which a more specific corresponding environment
1954 variable is not set.
1956 @menu
1957 * OMP_ALLOCATOR::           Set the default allocator
1958 * OMP_AFFINITY_FORMAT::     Set the format string used for affinity display
1959 * OMP_CANCELLATION::        Set whether cancellation is activated
1960 * OMP_DISPLAY_AFFINITY::    Display thread affinity information
1961 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
1962 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
1963 * OMP_DYNAMIC::             Dynamic adjustment of threads
1964 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
1965 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
1966 * OMP_NESTED::              Nested parallel regions
1967 * OMP_NUM_TEAMS::           Specifies the number of teams to use by teams region
1968 * OMP_NUM_THREADS::         Specifies the number of threads to use
1969 * OMP_PROC_BIND::           Whether threads may be moved between CPUs
1970 * OMP_PLACES::              Specifies on which CPUs the threads should be placed
1971 * OMP_STACKSIZE::           Set default thread stack size
1972 * OMP_SCHEDULE::            How threads are scheduled
1973 * OMP_TARGET_OFFLOAD::      Controls offloading behaviour
1974 * OMP_TEAMS_THREAD_LIMIT::  Set the maximum number of threads imposed by teams
1975 * OMP_THREAD_LIMIT::        Set the maximum number of threads
1976 * OMP_WAIT_POLICY::         How waiting threads are handled
1977 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
1978 * GOMP_DEBUG::              Enable debugging output
1979 * GOMP_STACKSIZE::          Set default thread stack size
1980 * GOMP_SPINCOUNT::          Set the busy-wait spin count
1981 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1982 @end menu
1985 @node OMP_ALLOCATOR
1986 @section @env{OMP_ALLOCATOR} -- Set the default allocator
1987 @cindex Environment Variable
1988 @table @asis
1989 @item @emph{ICV:} @var{available-devices-var}
1990 @item @emph{Scope:} data environment
1991 @item @emph{Description}:
1992 Sets the default allocator that is used when no allocator has been specified
1993 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
1994 routine is invoked with the @code{omp_null_allocator} allocator.
1995 If unset, @code{omp_default_mem_alloc} is used.
1997 The value can either be a predefined allocator or a predefined memory space
1998 or a predefined memory space followed by a colon and a comma-separated list
1999 of memory trait and value pairs, separated by @code{=}.
2001 Note: The corresponding device environment variables are currently not
2002 supported.  Therefore, the non-host @var{def-allocator-var} ICVs are always
2003 initialized to @code{omp_default_mem_alloc}.  However, on all devices,
2004 the @code{omp_set_default_allocator} API routine can be used to change
2005 value.
2007 @multitable @columnfractions .45 .45
2008 @headitem Predefined allocators @tab Associated predefined memory spaces
2009 @item omp_default_mem_alloc     @tab omp_default_mem_space
2010 @item omp_large_cap_mem_alloc   @tab omp_large_cap_mem_space
2011 @item omp_const_mem_alloc       @tab omp_const_mem_space
2012 @item omp_high_bw_mem_alloc     @tab omp_high_bw_mem_space
2013 @item omp_low_lat_mem_alloc     @tab omp_low_lat_mem_space
2014 @item omp_cgroup_mem_alloc      @tab --
2015 @item omp_pteam_mem_alloc       @tab --
2016 @item omp_thread_mem_alloc      @tab --
2017 @end multitable
2019 The predefined allocators use the default values for the traits,
2020 as listed below.  Except that the last three allocators have the
2021 @code{access} trait set to @code{cgroup}, @code{pteam}, and
2022 @code{thread}, respectively.
2024 @multitable @columnfractions .25 .40 .25
2025 @headitem Trait @tab Allowed values @tab Default value
2026 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
2027                             @code{serialized}, @code{private}
2028                        @tab @code{contended}
2029 @item @code{alignment} @tab Positive integer being a power of two
2030                        @tab 1 byte
2031 @item @code{access}    @tab @code{all}, @code{cgroup},
2032                             @code{pteam}, @code{thread}
2033                        @tab @code{all}
2034 @item @code{pool_size} @tab Positive integer
2035                        @tab See @ref{Memory allocation}
2036 @item @code{fallback}  @tab @code{default_mem_fb}, @code{null_fb},
2037                             @code{abort_fb}, @code{allocator_fb}
2038                        @tab See below
2039 @item @code{fb_data}   @tab @emph{unsupported as it needs an allocator handle}
2040                        @tab (none)
2041 @item @code{pinned}    @tab @code{true}, @code{false}
2042                        @tab @code{false}
2043 @item @code{partition} @tab @code{environment}, @code{nearest},
2044                             @code{blocked}, @code{interleaved}
2045                        @tab @code{environment}
2046 @end multitable
2048 For the @code{fallback} trait, the default value is @code{null_fb} for the
2049 @code{omp_default_mem_alloc} allocator and any allocator that is associated
2050 with device memory; for all other other allocators, it is @code{default_mem_fb}
2051 by default.
2053 Examples:
2054 @smallexample
2055 OMP_ALLOCATOR=omp_high_bw_mem_alloc
2056 OMP_ALLOCATOR=omp_large_cap_mem_space
2057 OMP_ALLOCATR=omp_low_lat_mem_space:pinned=true,partition=nearest
2058 @end smallexample
2060 @item @emph{See also}:
2061 @ref{Memory allocation}
2063 @item @emph{Reference}:
2064 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
2065 @end table
2069 @node OMP_AFFINITY_FORMAT
2070 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
2071 @cindex Environment Variable
2072 @table @asis
2073 @item @emph{ICV:} @var{affinity-format-var}
2074 @item @emph{Scope:} device
2075 @item @emph{Description}:
2076 Sets the format string used when displaying OpenMP thread affinity information.
2077 Special values are output using @code{%} followed by an optional size
2078 specification and then either the single-character field type or its long
2079 name enclosed in curly braces; using @code{%%} will display a literal percent.
2080 The size specification consists of an optional @code{0.} or @code{.} followed
2081 by a positive integer, specifying the minimal width of the output.  With
2082 @code{0.} and numerical values, the output is padded with zeros on the left;
2083 with @code{.}, the output is padded by spaces on the left; otherwise, the
2084 output is padded by spaces on the right.  If unset, the value is
2085 ``@code{level %L thread %i affinity %A}''.
2087 Supported field types are:
2089 @multitable @columnfractions .10 .25 .60
2090 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
2091 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
2092 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
2093 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
2094 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
2095 @item a @tab ancestor_tnum
2096       @tab value returned by
2097            @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
2098 @item H @tab host @tab name of the host that executes the thread
2099 @item P @tab process_id @tab process identifier
2100 @item i @tab native_thread_id @tab native thread identifier
2101 @item A @tab thread_affinity
2102       @tab comma separated list of integer values or ranges, representing the
2103            processors on which a process might execute, subject to affinity
2104            mechanisms
2105 @end multitable
2107 For instance, after setting
2109 @smallexample
2110 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
2111 @end smallexample
2113 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
2114 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
2115 might display the following:
2117 @smallexample
2118 00!0!   1!4; 0;01;0;1;0-11
2119 00!3!   1!4; 0;01;0;1;0-11
2120 00!2!   1!4; 0;01;0;1;0-11
2121 00!1!   1!4; 0;01;0;1;0-11
2122 @end smallexample
2124 @item @emph{See also}:
2125 @ref{OMP_DISPLAY_AFFINITY}
2127 @item @emph{Reference}:
2128 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
2129 @end table
2133 @node OMP_CANCELLATION
2134 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
2135 @cindex Environment Variable
2136 @table @asis
2137 @item @emph{ICV:} @var{cancel-var}
2138 @item @emph{Scope:} global
2139 @item @emph{Description}:
2140 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
2141 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
2143 @item @emph{See also}:
2144 @ref{omp_get_cancellation}
2146 @item @emph{Reference}:
2147 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
2148 @end table
2152 @node OMP_DISPLAY_AFFINITY
2153 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
2154 @cindex Environment Variable
2155 @table @asis
2156 @item @emph{ICV:} @var{display-affinity-var}
2157 @item @emph{Scope:} global
2158 @item @emph{Description}:
2159 If set to @code{FALSE} or if unset, affinity displaying is disabled.
2160 If set to @code{TRUE}, the runtime will display affinity information about
2161 OpenMP threads in a parallel region upon entering the region and every time
2162 any change occurs.
2164 @item @emph{See also}:
2165 @ref{OMP_AFFINITY_FORMAT}
2167 @item @emph{Reference}:
2168 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
2169 @end table
2174 @node OMP_DISPLAY_ENV
2175 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
2176 @cindex Environment Variable
2177 @table @asis
2178 @item @emph{ICV:} none
2179 @item @emph{Scope:} not applicable
2180 @item @emph{Description}:
2181 If set to @code{TRUE}, the OpenMP version number and the values
2182 associated with the OpenMP environment variables are printed to @code{stderr}.
2183 If set to @code{VERBOSE}, it additionally shows the value of the environment
2184 variables which are GNU extensions.  If undefined or set to @code{FALSE},
2185 this information will not be shown.
2188 @item @emph{Reference}:
2189 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
2190 @end table
2194 @node OMP_DEFAULT_DEVICE
2195 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
2196 @cindex Environment Variable
2197 @table @asis
2198 @item @emph{ICV:} @var{default-device-var}
2199 @item @emph{Scope:} data environment
2200 @item @emph{Description}:
2201 Set to choose the device which is used in a @code{target} region, unless the
2202 value is overridden by @code{omp_set_default_device} or by a @code{device}
2203 clause.  The value shall be the nonnegative device number. If no device with
2204 the given device number exists, the code is executed on the host.  If unset,
2205 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
2206 available, it is set to @code{omp_invalid_device}.  Otherwise, if unset,
2207 device number 0 will be used.
2210 @item @emph{See also}:
2211 @ref{omp_get_default_device}, @ref{omp_set_default_device},
2213 @item @emph{Reference}:
2214 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
2215 @end table
2219 @node OMP_DYNAMIC
2220 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
2221 @cindex Environment Variable
2222 @table @asis
2223 @item @emph{ICV:} @var{dyn-var}
2224 @item @emph{Scope:} global
2225 @item @emph{Description}:
2226 Enable or disable the dynamic adjustment of the number of threads 
2227 within a team.  The value of this environment variable shall be 
2228 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
2229 disabled by default.
2231 @item @emph{See also}:
2232 @ref{omp_set_dynamic}
2234 @item @emph{Reference}: 
2235 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
2236 @end table
2240 @node OMP_MAX_ACTIVE_LEVELS
2241 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
2242 @cindex Environment Variable
2243 @table @asis
2244 @item @emph{ICV:} @var{max-active-levels-var}
2245 @item @emph{Scope:} data environment
2246 @item @emph{Description}:
2247 Specifies the initial value for the maximum number of nested parallel
2248 regions.  The value of this variable shall be a positive integer.
2249 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
2250 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
2251 a list with more than one item, the maximum number of nested parallel
2252 regions will be initialized to the largest number supported, otherwise
2253 it will be set to one.
2255 @item @emph{See also}:
2256 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
2257 @ref{OMP_NUM_THREADS}
2260 @item @emph{Reference}: 
2261 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
2262 @end table
2266 @node OMP_MAX_TASK_PRIORITY
2267 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
2268 number that can be set for a task.
2269 @cindex Environment Variable
2270 @table @asis
2271 @item @emph{ICV:} @var{max-task-priority-var}
2272 @item @emph{Scope:} global
2273 @item @emph{Description}:
2274 Specifies the initial value for the maximum priority value that can be
2275 set for a task.  The value of this variable shall be a non-negative
2276 integer, and zero is allowed.  If undefined, the default priority is
2279 @item @emph{See also}:
2280 @ref{omp_get_max_task_priority}
2282 @item @emph{Reference}: 
2283 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
2284 @end table
2288 @node OMP_NESTED
2289 @section @env{OMP_NESTED} -- Nested parallel regions
2290 @cindex Environment Variable
2291 @cindex Implementation specific setting
2292 @table @asis
2293 @item @emph{ICV:} @var{max-active-levels-var}
2294 @item @emph{Scope:} data environment
2295 @item @emph{Description}:
2296 Enable or disable nested parallel regions, i.e., whether team members
2297 are allowed to create new teams.  The value of this environment variable 
2298 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
2299 of maximum active nested regions supported will by default be set to the
2300 maximum supported, otherwise it will be set to one.  If
2301 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting will override this
2302 setting.  If both are undefined, nested parallel regions are enabled if
2303 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
2304 more than one item, otherwise they are disabled by default.
2306 Note that the @code{OMP_NESTED} environment variable was deprecated in
2307 the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
2309 @item @emph{See also}:
2310 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
2311 @ref{OMP_MAX_ACTIVE_LEVELS}
2313 @item @emph{Reference}: 
2314 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
2315 @end table
2319 @node OMP_NUM_TEAMS
2320 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
2321 @cindex Environment Variable
2322 @table @asis
2323 @item @emph{ICV:} @var{nteams-var}
2324 @item @emph{Scope:} device
2325 @item @emph{Description}:
2326 Specifies the upper bound for number of teams to use in teams regions
2327 without explicit @code{num_teams} clause.  The value of this variable shall
2328 be a positive integer.  If undefined it defaults to 0 which means
2329 implementation defined upper bound.
2331 @item @emph{See also}:
2332 @ref{omp_set_num_teams}
2334 @item @emph{Reference}: 
2335 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
2336 @end table
2340 @node OMP_NUM_THREADS
2341 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
2342 @cindex Environment Variable
2343 @cindex Implementation specific setting
2344 @table @asis
2345 @item @emph{ICV:} @var{nthreads-var}
2346 @item @emph{Scope:} data environment
2347 @item @emph{Description}:
2348 Specifies the default number of threads to use in parallel regions.  The 
2349 value of this variable shall be a comma-separated list of positive integers;
2350 the value specifies the number of threads to use for the corresponding nested
2351 level.  Specifying more than one item in the list will automatically enable
2352 nesting by default.  If undefined one thread per CPU is used.
2354 When a list with more than value is specified, it also affects the
2355 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
2357 @item @emph{See also}:
2358 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
2360 @item @emph{Reference}: 
2361 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
2362 @end table
2366 @node OMP_PROC_BIND
2367 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
2368 @cindex Environment Variable
2369 @table @asis
2370 @item @emph{ICV:} @var{bind-var}
2371 @item @emph{Scope:} data environment
2372 @item @emph{Description}:
2373 Specifies whether threads may be moved between processors.  If set to
2374 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
2375 they may be moved.  Alternatively, a comma separated list with the
2376 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
2377 be used to specify the thread affinity policy for the corresponding nesting
2378 level.  With @code{PRIMARY} and @code{MASTER} the worker threads are in the
2379 same place partition as the primary thread.  With @code{CLOSE} those are
2380 kept close to the primary thread in contiguous place partitions.  And
2381 with @code{SPREAD} a sparse distribution
2382 across the place partitions is used.  Specifying more than one item in the
2383 list will automatically enable nesting by default.
2385 When a list is specified, it also affects the @var{max-active-levels-var} ICV
2386 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
2388 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
2389 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
2391 @item @emph{See also}:
2392 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
2393 @ref{OMP_MAX_ACTIVE_LEVELS}
2395 @item @emph{Reference}:
2396 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
2397 @end table
2401 @node OMP_PLACES
2402 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
2403 @cindex Environment Variable
2404 @table @asis
2405 @item @emph{ICV:} @var{place-partition-var}
2406 @item @emph{Scope:} implicit tasks
2407 @item @emph{Description}:
2408 The thread placement can be either specified using an abstract name or by an
2409 explicit list of the places.  The abstract names @code{threads}, @code{cores},
2410 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
2411 followed by a positive number in parentheses, which denotes the how many places
2412 shall be created.  With @code{threads} each place corresponds to a single
2413 hardware thread; @code{cores} to a single core with the corresponding number of
2414 hardware threads; with @code{sockets} the place corresponds to a single
2415 socket; with @code{ll_caches} to a set of cores that shares the last level
2416 cache on the device; and @code{numa_domains} to a set of cores for which their
2417 closest memory on the device is the same memory and at a similar distance from
2418 the cores.  The resulting placement can be shown by setting the
2419 @env{OMP_DISPLAY_ENV} environment variable.
2421 Alternatively, the placement can be specified explicitly as comma-separated
2422 list of places.  A place is specified by set of nonnegative numbers in curly
2423 braces, denoting the hardware threads.  The curly braces can be omitted
2424 when only a single number has been specified.  The hardware threads
2425 belonging to a place can either be specified as comma-separated list of
2426 nonnegative thread numbers or using an interval.  Multiple places can also be
2427 either specified by a comma-separated list of places or by an interval.  To
2428 specify an interval, a colon followed by the count is placed after
2429 the hardware thread number or the place.  Optionally, the length can be
2430 followed by a colon and the stride number -- otherwise a unit stride is
2431 assumed.  Placing an exclamation mark (@code{!}) directly before a curly
2432 brace or numbers inside the curly braces (excluding intervals) will
2433 exclude those hardware threads.
2435 For instance, the following specifies the same places list:
2436 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
2437 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
2439 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
2440 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
2441 between CPUs following no placement policy.
2443 @item @emph{See also}:
2444 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
2445 @ref{OMP_DISPLAY_ENV}
2447 @item @emph{Reference}:
2448 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
2449 @end table
2453 @node OMP_STACKSIZE
2454 @section @env{OMP_STACKSIZE} -- Set default thread stack size
2455 @cindex Environment Variable
2456 @table @asis
2457 @item @emph{ICV:} @var{stacksize-var}
2458 @item @emph{Scope:} device
2459 @item @emph{Description}:
2460 Set the default thread stack size in kilobytes, unless the number
2461 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
2462 case the size is, respectively, in bytes, kilobytes, megabytes
2463 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
2464 which gets the number of bytes as an argument.  If the stack size cannot
2465 be set due to system constraints, an error is reported and the initial
2466 stack size is left unchanged.  If undefined, the stack size is system
2467 dependent.
2469 @item @emph{See also}:
2470 @ref{GOMP_STACKSIZE}
2472 @item @emph{Reference}: 
2473 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
2474 @end table
2478 @node OMP_SCHEDULE
2479 @section @env{OMP_SCHEDULE} -- How threads are scheduled
2480 @cindex Environment Variable
2481 @cindex Implementation specific setting
2482 @table @asis
2483 @item @emph{ICV:} @var{run-sched-var}
2484 @item @emph{Scope:} data environment
2485 @item @emph{Description}:
2486 Allows to specify @code{schedule type} and @code{chunk size}. 
2487 The value of the variable shall have the form: @code{type[,chunk]} where
2488 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
2489 The optional @code{chunk} size shall be a positive integer.  If undefined,
2490 dynamic scheduling and a chunk size of 1 is used.
2492 @item @emph{See also}:
2493 @ref{omp_set_schedule}
2495 @item @emph{Reference}: 
2496 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
2497 @end table
2501 @node OMP_TARGET_OFFLOAD
2502 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behaviour
2503 @cindex Environment Variable
2504 @cindex Implementation specific setting
2505 @table @asis
2506 @item @emph{ICV:} @var{target-offload-var}
2507 @item @emph{Scope:} global
2508 @item @emph{Description}:
2509 Specifies the behaviour with regard to offloading code to a device.  This
2510 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
2511 or @code{DEFAULT}.
2513 If set to @code{MANDATORY}, the program will terminate with an error if
2514 the offload device is not present or is not supported.  If set to
2515 @code{DISABLED}, then offloading is disabled and all code will run on the
2516 host. If set to @code{DEFAULT}, the program will try offloading to the
2517 device first, then fall back to running code on the host if it cannot.
2519 If undefined, then the program will behave as if @code{DEFAULT} was set.
2521 @item @emph{Reference}:
2522 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.17
2523 @end table
2527 @node OMP_TEAMS_THREAD_LIMIT
2528 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
2529 @cindex Environment Variable
2530 @table @asis
2531 @item @emph{ICV:} @var{teams-thread-limit-var}
2532 @item @emph{Scope:} device
2533 @item @emph{Description}:
2534 Specifies an upper bound for the number of threads to use by each contention
2535 group created by a teams construct without explicit @code{thread_limit}
2536 clause.  The value of this variable shall be a positive integer.  If undefined,
2537 the value of 0 is used which stands for an implementation defined upper
2538 limit.
2540 @item @emph{See also}:
2541 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
2543 @item @emph{Reference}: 
2544 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
2545 @end table
2549 @node OMP_THREAD_LIMIT
2550 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
2551 @cindex Environment Variable
2552 @table @asis
2553 @item @emph{ICV:} @var{thread-limit-var}
2554 @item @emph{Scope:} data environment
2555 @item @emph{Description}:
2556 Specifies the number of threads to use for the whole program.  The
2557 value of this variable shall be a positive integer.  If undefined,
2558 the number of threads is not limited.
2560 @item @emph{See also}:
2561 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
2563 @item @emph{Reference}: 
2564 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
2565 @end table
2569 @node OMP_WAIT_POLICY
2570 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
2571 @cindex Environment Variable
2572 @table @asis
2573 @item @emph{Description}:
2574 Specifies whether waiting threads should be active or passive.  If
2575 the value is @code{PASSIVE}, waiting threads should not consume CPU
2576 power while waiting; while the value is @code{ACTIVE} specifies that
2577 they should.  If undefined, threads wait actively for a short time
2578 before waiting passively.
2580 @item @emph{See also}:
2581 @ref{GOMP_SPINCOUNT}
2583 @item @emph{Reference}: 
2584 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
2585 @end table
2589 @node GOMP_CPU_AFFINITY
2590 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
2591 @cindex Environment Variable
2592 @table @asis
2593 @item @emph{Description}:
2594 Binds threads to specific CPUs.  The variable should contain a space-separated
2595 or comma-separated list of CPUs.  This list may contain different kinds of 
2596 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
2597 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
2598 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
2599 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
2600 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
2601 and 14 respectively and then start assigning back from the beginning of
2602 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
2604 There is no libgomp library routine to determine whether a CPU affinity
2605 specification is in effect.  As a workaround, language-specific library 
2606 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
2607 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
2608 environment variable.  A defined CPU affinity on startup cannot be changed 
2609 or disabled during the runtime of the application.
2611 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
2612 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
2613 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
2614 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
2616 @item @emph{See also}:
2617 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
2618 @end table
2622 @node GOMP_DEBUG
2623 @section @env{GOMP_DEBUG} -- Enable debugging output
2624 @cindex Environment Variable
2625 @table @asis
2626 @item @emph{Description}:
2627 Enable debugging output.  The variable should be set to @code{0}
2628 (disabled, also the default if not set), or @code{1} (enabled).
2630 If enabled, some debugging output will be printed during execution.
2631 This is currently not specified in more detail, and subject to change.
2632 @end table
2636 @node GOMP_STACKSIZE
2637 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
2638 @cindex Environment Variable
2639 @cindex Implementation specific setting
2640 @table @asis
2641 @item @emph{Description}:
2642 Set the default thread stack size in kilobytes.  This is different from
2643 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
2644 argument.  If the stack size cannot be set due to system constraints, an 
2645 error is reported and the initial stack size is left unchanged.  If undefined,
2646 the stack size is system dependent.
2648 @item @emph{See also}:
2649 @ref{OMP_STACKSIZE}
2651 @item @emph{Reference}: 
2652 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
2653 GCC Patches Mailinglist}, 
2654 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
2655 GCC Patches Mailinglist}
2656 @end table
2660 @node GOMP_SPINCOUNT
2661 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
2662 @cindex Environment Variable
2663 @cindex Implementation specific setting
2664 @table @asis
2665 @item @emph{Description}:
2666 Determines how long a threads waits actively with consuming CPU power
2667 before waiting passively without consuming CPU power.  The value may be
2668 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
2669 integer which gives the number of spins of the busy-wait loop.  The
2670 integer may optionally be followed by the following suffixes acting
2671 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
2672 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
2673 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
2674 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
2675 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
2676 If there are more OpenMP threads than available CPUs, 1000 and 100
2677 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
2678 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
2679 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
2681 @item @emph{See also}:
2682 @ref{OMP_WAIT_POLICY}
2683 @end table
2687 @node GOMP_RTEMS_THREAD_POOLS
2688 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
2689 @cindex Environment Variable
2690 @cindex Implementation specific setting
2691 @table @asis
2692 @item @emph{Description}:
2693 This environment variable is only used on the RTEMS real-time operating system.
2694 It determines the scheduler instance specific thread pools.  The format for
2695 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
2696 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
2697 separated by @code{:} where:
2698 @itemize @bullet
2699 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
2700 instance.
2701 @item @code{$<priority>} is an optional priority for the worker threads of a
2702 thread pool according to @code{pthread_setschedparam}.  In case a priority
2703 value is omitted, then a worker thread will inherit the priority of the OpenMP
2704 primary thread that created it.  The priority of the worker thread is not
2705 changed after creation, even if a new OpenMP primary thread using the worker has
2706 a different priority.
2707 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
2708 RTEMS application configuration.
2709 @end itemize
2710 In case no thread pool configuration is specified for a scheduler instance,
2711 then each OpenMP primary thread of this scheduler instance will use its own
2712 dynamically allocated thread pool.  To limit the worker thread count of the
2713 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
2714 @item @emph{Example}:
2715 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
2716 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
2717 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
2718 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
2719 one thread pool available.  Since no priority is specified for this scheduler
2720 instance, the worker thread inherits the priority of the OpenMP primary thread
2721 that created it.  In the scheduler instance @code{WRK1} there are three thread
2722 pools available and their worker threads run at priority four.
2723 @end table
2727 @c ---------------------------------------------------------------------
2728 @c Enabling OpenACC
2729 @c ---------------------------------------------------------------------
2731 @node Enabling OpenACC
2732 @chapter Enabling OpenACC
2734 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
2735 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
2736 @code{#pragma acc} in C/C++ and @code{!$acc} directives in free form,
2737 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
2738 @code{!$} conditional compilation sentinels in free form and @code{c$},
2739 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
2740 arranges for automatic linking of the OpenACC runtime library 
2741 (@ref{OpenACC Runtime Library Routines}).
2743 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
2745 A complete description of all OpenACC directives accepted may be found in 
2746 the @uref{https://www.openacc.org, OpenACC} Application Programming
2747 Interface manual, version 2.6.
2751 @c ---------------------------------------------------------------------
2752 @c OpenACC Runtime Library Routines
2753 @c ---------------------------------------------------------------------
2755 @node OpenACC Runtime Library Routines
2756 @chapter OpenACC Runtime Library Routines
2758 The runtime routines described here are defined by section 3 of the OpenACC
2759 specifications in version 2.6.
2760 They have C linkage, and do not throw exceptions.
2761 Generally, they are available only for the host, with the exception of
2762 @code{acc_on_device}, which is available for both the host and the
2763 acceleration device.
2765 @menu
2766 * acc_get_num_devices::         Get number of devices for the given device
2767                                 type.
2768 * acc_set_device_type::         Set type of device accelerator to use.
2769 * acc_get_device_type::         Get type of device accelerator to be used.
2770 * acc_set_device_num::          Set device number to use.
2771 * acc_get_device_num::          Get device number to be used.
2772 * acc_get_property::            Get device property.
2773 * acc_async_test::              Tests for completion of a specific asynchronous
2774                                 operation.
2775 * acc_async_test_all::          Tests for completion of all asynchronous
2776                                 operations.
2777 * acc_wait::                    Wait for completion of a specific asynchronous
2778                                 operation.
2779 * acc_wait_all::                Waits for completion of all asynchronous
2780                                 operations.
2781 * acc_wait_all_async::          Wait for completion of all asynchronous
2782                                 operations.
2783 * acc_wait_async::              Wait for completion of asynchronous operations.
2784 * acc_init::                    Initialize runtime for a specific device type.
2785 * acc_shutdown::                Shuts down the runtime for a specific device
2786                                 type.
2787 * acc_on_device::               Whether executing on a particular device
2788 * acc_malloc::                  Allocate device memory.
2789 * acc_free::                    Free device memory.
2790 * acc_copyin::                  Allocate device memory and copy host memory to
2791                                 it.
2792 * acc_present_or_copyin::       If the data is not present on the device,
2793                                 allocate device memory and copy from host
2794                                 memory.
2795 * acc_create::                  Allocate device memory and map it to host
2796                                 memory.
2797 * acc_present_or_create::       If the data is not present on the device,
2798                                 allocate device memory and map it to host
2799                                 memory.
2800 * acc_copyout::                 Copy device memory to host memory.
2801 * acc_delete::                  Free device memory.
2802 * acc_update_device::           Update device memory from mapped host memory.
2803 * acc_update_self::             Update host memory from mapped device memory.
2804 * acc_map_data::                Map previously allocated device memory to host
2805                                 memory.
2806 * acc_unmap_data::              Unmap device memory from host memory.
2807 * acc_deviceptr::               Get device pointer associated with specific
2808                                 host address.
2809 * acc_hostptr::                 Get host pointer associated with specific
2810                                 device address.
2811 * acc_is_present::              Indicate whether host variable / array is
2812                                 present on device.
2813 * acc_memcpy_to_device::        Copy host memory to device memory.
2814 * acc_memcpy_from_device::      Copy device memory to host memory.
2815 * acc_attach::                  Let device pointer point to device-pointer target.
2816 * acc_detach::                  Let device pointer point to host-pointer target.
2818 API routines for target platforms.
2820 * acc_get_current_cuda_device:: Get CUDA device handle.
2821 * acc_get_current_cuda_context::Get CUDA context handle.
2822 * acc_get_cuda_stream::         Get CUDA stream handle.
2823 * acc_set_cuda_stream::         Set CUDA stream handle.
2825 API routines for the OpenACC Profiling Interface.
2827 * acc_prof_register::           Register callbacks.
2828 * acc_prof_unregister::         Unregister callbacks.
2829 * acc_prof_lookup::             Obtain inquiry functions.
2830 * acc_register_library::        Library registration.
2831 @end menu
2835 @node acc_get_num_devices
2836 @section @code{acc_get_num_devices} -- Get number of devices for given device type
2837 @table @asis
2838 @item @emph{Description}
2839 This function returns a value indicating the number of devices available
2840 for the device type specified in @var{devicetype}. 
2842 @item @emph{C/C++}:
2843 @multitable @columnfractions .20 .80
2844 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
2845 @end multitable
2847 @item @emph{Fortran}:
2848 @multitable @columnfractions .20 .80
2849 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
2850 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
2851 @end multitable
2853 @item @emph{Reference}:
2854 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2855 3.2.1.
2856 @end table
2860 @node acc_set_device_type
2861 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
2862 @table @asis
2863 @item @emph{Description}
2864 This function indicates to the runtime library which device type, specified
2865 in @var{devicetype}, to use when executing a parallel or kernels region. 
2867 @item @emph{C/C++}:
2868 @multitable @columnfractions .20 .80
2869 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
2870 @end multitable
2872 @item @emph{Fortran}:
2873 @multitable @columnfractions .20 .80
2874 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
2875 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2876 @end multitable
2878 @item @emph{Reference}:
2879 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2880 3.2.2.
2881 @end table
2885 @node acc_get_device_type
2886 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
2887 @table @asis
2888 @item @emph{Description}
2889 This function returns what device type will be used when executing a
2890 parallel or kernels region.
2892 This function returns @code{acc_device_none} if
2893 @code{acc_get_device_type} is called from
2894 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
2895 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
2896 Interface}), that is, if the device is currently being initialized.
2898 @item @emph{C/C++}:
2899 @multitable @columnfractions .20 .80
2900 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
2901 @end multitable
2903 @item @emph{Fortran}:
2904 @multitable @columnfractions .20 .80
2905 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
2906 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
2907 @end multitable
2909 @item @emph{Reference}:
2910 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2911 3.2.3.
2912 @end table
2916 @node acc_set_device_num
2917 @section @code{acc_set_device_num} -- Set device number to use.
2918 @table @asis
2919 @item @emph{Description}
2920 This function will indicate to the runtime which device number,
2921 specified by @var{devicenum}, associated with the specified device
2922 type @var{devicetype}.
2924 @item @emph{C/C++}:
2925 @multitable @columnfractions .20 .80
2926 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
2927 @end multitable
2929 @item @emph{Fortran}:
2930 @multitable @columnfractions .20 .80
2931 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
2932 @item                   @tab @code{integer devicenum}
2933 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2934 @end multitable
2936 @item @emph{Reference}:
2937 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2938 3.2.4.
2939 @end table
2943 @node acc_get_device_num
2944 @section @code{acc_get_device_num} -- Get device number to be used.
2945 @table @asis
2946 @item @emph{Description}
2947 This function returns which device number associated with the specified device
2948 type @var{devicetype}, will be used when executing a parallel or kernels
2949 region.
2951 @item @emph{C/C++}:
2952 @multitable @columnfractions .20 .80
2953 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2954 @end multitable
2956 @item @emph{Fortran}:
2957 @multitable @columnfractions .20 .80
2958 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2959 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2960 @item                   @tab @code{integer acc_get_device_num}
2961 @end multitable
2963 @item @emph{Reference}:
2964 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2965 3.2.5.
2966 @end table
2970 @node acc_get_property
2971 @section @code{acc_get_property} -- Get device property.
2972 @cindex acc_get_property
2973 @cindex acc_get_property_string
2974 @table @asis
2975 @item @emph{Description}
2976 These routines return the value of the specified @var{property} for the
2977 device being queried according to @var{devicenum} and @var{devicetype}.
2978 Integer-valued and string-valued properties are returned by
2979 @code{acc_get_property} and @code{acc_get_property_string} respectively.
2980 The Fortran @code{acc_get_property_string} subroutine returns the string
2981 retrieved in its fourth argument while the remaining entry points are
2982 functions, which pass the return value as their result.
2984 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
2985 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
2986 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
2987 for consistency and the return type of the @code{acc_get_property} function is
2988 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
2989 The parameter @code{acc_device_property} will continue to be provided,
2990 but might be removed in a future version of GCC.
2992 @item @emph{C/C++}:
2993 @multitable @columnfractions .20 .80
2994 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2995 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2996 @end multitable
2998 @item @emph{Fortran}:
2999 @multitable @columnfractions .20 .80
3000 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
3001 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
3002 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
3003 @item                   @tab @code{integer devicenum}
3004 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
3005 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
3006 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
3007 @item                   @tab @code{character(*) string}
3008 @end multitable
3010 @item @emph{Reference}:
3011 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3012 3.2.6.
3013 @end table
3017 @node acc_async_test
3018 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
3019 @table @asis
3020 @item @emph{Description}
3021 This function tests for completion of the asynchronous operation specified
3022 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
3023 the specified asynchronous operation has completed. While Fortran will return
3024 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
3025 a zero and Fortran returns a @code{false}.
3027 @item @emph{C/C++}:
3028 @multitable @columnfractions .20 .80
3029 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
3030 @end multitable
3032 @item @emph{Fortran}:
3033 @multitable @columnfractions .20 .80
3034 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
3035 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
3036 @item                   @tab @code{logical acc_async_test}
3037 @end multitable
3039 @item @emph{Reference}:
3040 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3041 3.2.9.
3042 @end table
3046 @node acc_async_test_all
3047 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
3048 @table @asis
3049 @item @emph{Description}
3050 This function tests for completion of all asynchronous operations.
3051 In C/C++, a non-zero value will be returned to indicate all asynchronous
3052 operations have completed. While Fortran will return a @code{true}. If
3053 any asynchronous operation has not completed, C/C++ returns a zero and
3054 Fortran returns a @code{false}.
3056 @item @emph{C/C++}:
3057 @multitable @columnfractions .20 .80
3058 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
3059 @end multitable
3061 @item @emph{Fortran}:
3062 @multitable @columnfractions .20 .80
3063 @item @emph{Interface}: @tab @code{function acc_async_test()}
3064 @item                   @tab @code{logical acc_get_device_num}
3065 @end multitable
3067 @item @emph{Reference}:
3068 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3069 3.2.10.
3070 @end table
3074 @node acc_wait
3075 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
3076 @table @asis
3077 @item @emph{Description}
3078 This function waits for completion of the asynchronous operation
3079 specified in @var{arg}.
3081 @item @emph{C/C++}:
3082 @multitable @columnfractions .20 .80
3083 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
3084 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
3085 @end multitable
3087 @item @emph{Fortran}:
3088 @multitable @columnfractions .20 .80
3089 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
3090 @item                   @tab @code{integer(acc_handle_kind) arg}
3091 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
3092 @item                                               @tab @code{integer(acc_handle_kind) arg}
3093 @end multitable
3095 @item @emph{Reference}:
3096 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3097 3.2.11.
3098 @end table
3102 @node acc_wait_all
3103 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
3104 @table @asis
3105 @item @emph{Description}
3106 This function waits for the completion of all asynchronous operations.
3108 @item @emph{C/C++}:
3109 @multitable @columnfractions .20 .80
3110 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
3111 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
3112 @end multitable
3114 @item @emph{Fortran}:
3115 @multitable @columnfractions .20 .80
3116 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
3117 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
3118 @end multitable
3120 @item @emph{Reference}:
3121 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3122 3.2.13.
3123 @end table
3127 @node acc_wait_all_async
3128 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
3129 @table @asis
3130 @item @emph{Description}
3131 This function enqueues a wait operation on the queue @var{async} for any
3132 and all asynchronous operations that have been previously enqueued on
3133 any queue.
3135 @item @emph{C/C++}:
3136 @multitable @columnfractions .20 .80
3137 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
3138 @end multitable
3140 @item @emph{Fortran}:
3141 @multitable @columnfractions .20 .80
3142 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
3143 @item                   @tab @code{integer(acc_handle_kind) async}
3144 @end multitable
3146 @item @emph{Reference}:
3147 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3148 3.2.14.
3149 @end table
3153 @node acc_wait_async
3154 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
3155 @table @asis
3156 @item @emph{Description}
3157 This function enqueues a wait operation on queue @var{async} for any and all
3158 asynchronous operations enqueued on queue @var{arg}.
3160 @item @emph{C/C++}:
3161 @multitable @columnfractions .20 .80
3162 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
3163 @end multitable
3165 @item @emph{Fortran}:
3166 @multitable @columnfractions .20 .80
3167 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
3168 @item                   @tab @code{integer(acc_handle_kind) arg, async}
3169 @end multitable
3171 @item @emph{Reference}:
3172 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3173 3.2.12.
3174 @end table
3178 @node acc_init
3179 @section @code{acc_init} -- Initialize runtime for a specific device type.
3180 @table @asis
3181 @item @emph{Description}
3182 This function initializes the runtime for the device type specified in
3183 @var{devicetype}.
3185 @item @emph{C/C++}:
3186 @multitable @columnfractions .20 .80
3187 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
3188 @end multitable
3190 @item @emph{Fortran}:
3191 @multitable @columnfractions .20 .80
3192 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
3193 @item                   @tab @code{integer(acc_device_kind) devicetype}
3194 @end multitable
3196 @item @emph{Reference}:
3197 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3198 3.2.7.
3199 @end table
3203 @node acc_shutdown
3204 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
3205 @table @asis
3206 @item @emph{Description}
3207 This function shuts down the runtime for the device type specified in
3208 @var{devicetype}.
3210 @item @emph{C/C++}:
3211 @multitable @columnfractions .20 .80
3212 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
3213 @end multitable
3215 @item @emph{Fortran}:
3216 @multitable @columnfractions .20 .80
3217 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
3218 @item                   @tab @code{integer(acc_device_kind) devicetype}
3219 @end multitable
3221 @item @emph{Reference}:
3222 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3223 3.2.8.
3224 @end table
3228 @node acc_on_device
3229 @section @code{acc_on_device} -- Whether executing on a particular device
3230 @table @asis
3231 @item @emph{Description}:
3232 This function returns whether the program is executing on a particular
3233 device specified in @var{devicetype}. In C/C++ a non-zero value is
3234 returned to indicate the device is executing on the specified device type.
3235 In Fortran, @code{true} will be returned. If the program is not executing
3236 on the specified device type C/C++ will return a zero, while Fortran will
3237 return @code{false}.
3239 @item @emph{C/C++}:
3240 @multitable @columnfractions .20 .80
3241 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
3242 @end multitable
3244 @item @emph{Fortran}:
3245 @multitable @columnfractions .20 .80
3246 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
3247 @item                   @tab @code{integer(acc_device_kind) devicetype}
3248 @item                   @tab @code{logical acc_on_device}
3249 @end multitable
3252 @item @emph{Reference}:
3253 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3254 3.2.17.
3255 @end table
3259 @node acc_malloc
3260 @section @code{acc_malloc} -- Allocate device memory.
3261 @table @asis
3262 @item @emph{Description}
3263 This function allocates @var{len} bytes of device memory. It returns
3264 the device address of the allocated memory.
3266 @item @emph{C/C++}:
3267 @multitable @columnfractions .20 .80
3268 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
3269 @end multitable
3271 @item @emph{Reference}:
3272 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3273 3.2.18.
3274 @end table
3278 @node acc_free
3279 @section @code{acc_free} -- Free device memory.
3280 @table @asis
3281 @item @emph{Description}
3282 Free previously allocated device memory at the device address @code{a}.
3284 @item @emph{C/C++}:
3285 @multitable @columnfractions .20 .80
3286 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
3287 @end multitable
3289 @item @emph{Reference}:
3290 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3291 3.2.19.
3292 @end table
3296 @node acc_copyin
3297 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
3298 @table @asis
3299 @item @emph{Description}
3300 In C/C++, this function allocates @var{len} bytes of device memory
3301 and maps it to the specified host address in @var{a}. The device
3302 address of the newly allocated device memory is returned.
3304 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3305 a contiguous array section. The second form @var{a} specifies a
3306 variable or array element and @var{len} specifies the length in bytes.
3308 @item @emph{C/C++}:
3309 @multitable @columnfractions .20 .80
3310 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
3311 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
3312 @end multitable
3314 @item @emph{Fortran}:
3315 @multitable @columnfractions .20 .80
3316 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
3317 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3318 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
3319 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3320 @item                   @tab @code{integer len}
3321 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
3322 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3323 @item                   @tab @code{integer(acc_handle_kind) :: async}
3324 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
3325 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3326 @item                   @tab @code{integer len}
3327 @item                   @tab @code{integer(acc_handle_kind) :: async}
3328 @end multitable
3330 @item @emph{Reference}:
3331 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3332 3.2.20.
3333 @end table
3337 @node acc_present_or_copyin
3338 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
3339 @table @asis
3340 @item @emph{Description}
3341 This function tests if the host data specified by @var{a} and of length
3342 @var{len} is present or not. If it is not present, then device memory
3343 will be allocated and the host memory copied. The device address of
3344 the newly allocated device memory is returned.
3346 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3347 a contiguous array section. The second form @var{a} specifies a variable or
3348 array element and @var{len} specifies the length in bytes.
3350 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
3351 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
3353 @item @emph{C/C++}:
3354 @multitable @columnfractions .20 .80
3355 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
3356 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
3357 @end multitable
3359 @item @emph{Fortran}:
3360 @multitable @columnfractions .20 .80
3361 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
3362 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3363 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
3364 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3365 @item                   @tab @code{integer len}
3366 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
3367 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3368 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
3369 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3370 @item                   @tab @code{integer len}
3371 @end multitable
3373 @item @emph{Reference}:
3374 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3375 3.2.20.
3376 @end table
3380 @node acc_create
3381 @section @code{acc_create} -- Allocate device memory and map it to host memory.
3382 @table @asis
3383 @item @emph{Description}
3384 This function allocates device memory and maps it to host memory specified
3385 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
3386 the function returns the device address of the allocated device memory.
3388 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3389 a contiguous array section. The second form @var{a} specifies a variable or
3390 array element and @var{len} specifies the length in bytes.
3392 @item @emph{C/C++}:
3393 @multitable @columnfractions .20 .80
3394 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
3395 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
3396 @end multitable
3398 @item @emph{Fortran}:
3399 @multitable @columnfractions .20 .80
3400 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
3401 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3402 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
3403 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3404 @item                   @tab @code{integer len}
3405 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
3406 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3407 @item                   @tab @code{integer(acc_handle_kind) :: async}
3408 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
3409 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3410 @item                   @tab @code{integer len}
3411 @item                   @tab @code{integer(acc_handle_kind) :: async}
3412 @end multitable
3414 @item @emph{Reference}:
3415 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3416 3.2.21.
3417 @end table
3421 @node acc_present_or_create
3422 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
3423 @table @asis
3424 @item @emph{Description}
3425 This function tests if the host data specified by @var{a} and of length
3426 @var{len} is present or not. If it is not present, then device memory
3427 will be allocated and mapped to host memory. In C/C++, the device address
3428 of the newly allocated device memory is returned.
3430 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3431 a contiguous array section. The second form @var{a} specifies a variable or
3432 array element and @var{len} specifies the length in bytes.
3434 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
3435 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
3437 @item @emph{C/C++}:
3438 @multitable @columnfractions .20 .80
3439 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
3440 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
3441 @end multitable
3443 @item @emph{Fortran}:
3444 @multitable @columnfractions .20 .80
3445 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
3446 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3447 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
3448 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3449 @item                   @tab @code{integer len}
3450 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
3451 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3452 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
3453 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3454 @item                   @tab @code{integer len}
3455 @end multitable
3457 @item @emph{Reference}:
3458 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3459 3.2.21.
3460 @end table
3464 @node acc_copyout
3465 @section @code{acc_copyout} -- Copy device memory to host memory.
3466 @table @asis
3467 @item @emph{Description}
3468 This function copies mapped device memory to host memory which is specified
3469 by host address @var{a} for a length @var{len} bytes in C/C++.
3471 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3472 a contiguous array section. The second form @var{a} specifies a variable or
3473 array element and @var{len} specifies the length in bytes.
3475 @item @emph{C/C++}:
3476 @multitable @columnfractions .20 .80
3477 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
3478 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
3479 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
3480 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
3481 @end multitable
3483 @item @emph{Fortran}:
3484 @multitable @columnfractions .20 .80
3485 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
3486 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3487 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
3488 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3489 @item                   @tab @code{integer len}
3490 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
3491 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3492 @item                   @tab @code{integer(acc_handle_kind) :: async}
3493 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
3494 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3495 @item                   @tab @code{integer len}
3496 @item                   @tab @code{integer(acc_handle_kind) :: async}
3497 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
3498 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3499 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
3500 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3501 @item                   @tab @code{integer len}
3502 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
3503 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3504 @item                   @tab @code{integer(acc_handle_kind) :: async}
3505 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
3506 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3507 @item                   @tab @code{integer len}
3508 @item                   @tab @code{integer(acc_handle_kind) :: async}
3509 @end multitable
3511 @item @emph{Reference}:
3512 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3513 3.2.22.
3514 @end table
3518 @node acc_delete
3519 @section @code{acc_delete} -- Free device memory.
3520 @table @asis
3521 @item @emph{Description}
3522 This function frees previously allocated device memory specified by
3523 the device address @var{a} and the length of @var{len} bytes.
3525 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3526 a contiguous array section. The second form @var{a} specifies a variable or
3527 array element and @var{len} specifies the length in bytes.
3529 @item @emph{C/C++}:
3530 @multitable @columnfractions .20 .80
3531 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
3532 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
3533 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
3534 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
3535 @end multitable
3537 @item @emph{Fortran}:
3538 @multitable @columnfractions .20 .80
3539 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
3540 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3541 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
3542 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3543 @item                   @tab @code{integer len}
3544 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
3545 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3546 @item                   @tab @code{integer(acc_handle_kind) :: async}
3547 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
3548 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3549 @item                   @tab @code{integer len}
3550 @item                   @tab @code{integer(acc_handle_kind) :: async}
3551 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
3552 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3553 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
3554 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3555 @item                   @tab @code{integer len}
3556 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
3557 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3558 @item                   @tab @code{integer(acc_handle_kind) :: async}
3559 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
3560 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3561 @item                   @tab @code{integer len}
3562 @item                   @tab @code{integer(acc_handle_kind) :: async}
3563 @end multitable
3565 @item @emph{Reference}:
3566 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3567 3.2.23.
3568 @end table
3572 @node acc_update_device
3573 @section @code{acc_update_device} -- Update device memory from mapped host memory.
3574 @table @asis
3575 @item @emph{Description}
3576 This function updates the device copy from the previously mapped host memory.
3577 The host memory is specified with the host address @var{a} and a length of
3578 @var{len} bytes.
3580 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3581 a contiguous array section. The second form @var{a} specifies a variable or
3582 array element and @var{len} specifies the length in bytes.
3584 @item @emph{C/C++}:
3585 @multitable @columnfractions .20 .80
3586 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
3587 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
3588 @end multitable
3590 @item @emph{Fortran}:
3591 @multitable @columnfractions .20 .80
3592 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
3593 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3594 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
3595 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3596 @item                   @tab @code{integer len}
3597 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
3598 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3599 @item                   @tab @code{integer(acc_handle_kind) :: async}
3600 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
3601 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3602 @item                   @tab @code{integer len}
3603 @item                   @tab @code{integer(acc_handle_kind) :: async}
3604 @end multitable
3606 @item @emph{Reference}:
3607 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3608 3.2.24.
3609 @end table
3613 @node acc_update_self
3614 @section @code{acc_update_self} -- Update host memory from mapped device memory.
3615 @table @asis
3616 @item @emph{Description}
3617 This function updates the host copy from the previously mapped device memory.
3618 The host memory is specified with the host address @var{a} and a length of
3619 @var{len} bytes.
3621 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3622 a contiguous array section. The second form @var{a} specifies a variable or
3623 array element and @var{len} specifies the length in bytes.
3625 @item @emph{C/C++}:
3626 @multitable @columnfractions .20 .80
3627 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
3628 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
3629 @end multitable
3631 @item @emph{Fortran}:
3632 @multitable @columnfractions .20 .80
3633 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
3634 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3635 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
3636 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3637 @item                   @tab @code{integer len}
3638 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
3639 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3640 @item                   @tab @code{integer(acc_handle_kind) :: async}
3641 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
3642 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3643 @item                   @tab @code{integer len}
3644 @item                   @tab @code{integer(acc_handle_kind) :: async}
3645 @end multitable
3647 @item @emph{Reference}:
3648 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3649 3.2.25.
3650 @end table
3654 @node acc_map_data
3655 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
3656 @table @asis
3657 @item @emph{Description}
3658 This function maps previously allocated device and host memory. The device
3659 memory is specified with the device address @var{d}. The host memory is
3660 specified with the host address @var{h} and a length of @var{len}.
3662 @item @emph{C/C++}:
3663 @multitable @columnfractions .20 .80
3664 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
3665 @end multitable
3667 @item @emph{Reference}:
3668 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3669 3.2.26.
3670 @end table
3674 @node acc_unmap_data
3675 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
3676 @table @asis
3677 @item @emph{Description}
3678 This function unmaps previously mapped device and host memory. The latter
3679 specified by @var{h}.
3681 @item @emph{C/C++}:
3682 @multitable @columnfractions .20 .80
3683 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
3684 @end multitable
3686 @item @emph{Reference}:
3687 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3688 3.2.27.
3689 @end table
3693 @node acc_deviceptr
3694 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
3695 @table @asis
3696 @item @emph{Description}
3697 This function returns the device address that has been mapped to the
3698 host address specified by @var{h}.
3700 @item @emph{C/C++}:
3701 @multitable @columnfractions .20 .80
3702 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
3703 @end multitable
3705 @item @emph{Reference}:
3706 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3707 3.2.28.
3708 @end table
3712 @node acc_hostptr
3713 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
3714 @table @asis
3715 @item @emph{Description}
3716 This function returns the host address that has been mapped to the
3717 device address specified by @var{d}.
3719 @item @emph{C/C++}:
3720 @multitable @columnfractions .20 .80
3721 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
3722 @end multitable
3724 @item @emph{Reference}:
3725 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3726 3.2.29.
3727 @end table
3731 @node acc_is_present
3732 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
3733 @table @asis
3734 @item @emph{Description}
3735 This function indicates whether the specified host address in @var{a} and a
3736 length of @var{len} bytes is present on the device. In C/C++, a non-zero
3737 value is returned to indicate the presence of the mapped memory on the
3738 device. A zero is returned to indicate the memory is not mapped on the
3739 device.
3741 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3742 a contiguous array section. The second form @var{a} specifies a variable or
3743 array element and @var{len} specifies the length in bytes. If the host
3744 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
3745 a @code{false} is return to indicate the mapped memory is not present.
3747 @item @emph{C/C++}:
3748 @multitable @columnfractions .20 .80
3749 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
3750 @end multitable
3752 @item @emph{Fortran}:
3753 @multitable @columnfractions .20 .80
3754 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
3755 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3756 @item                   @tab @code{logical acc_is_present}
3757 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
3758 @item                   @tab @code{type, dimension(:[,:]...) :: a}
3759 @item                   @tab @code{integer len}
3760 @item                   @tab @code{logical acc_is_present}
3761 @end multitable
3763 @item @emph{Reference}:
3764 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3765 3.2.30.
3766 @end table
3770 @node acc_memcpy_to_device
3771 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
3772 @table @asis
3773 @item @emph{Description}
3774 This function copies host memory specified by host address of @var{src} to
3775 device memory specified by the device address @var{dest} for a length of
3776 @var{bytes} bytes.
3778 @item @emph{C/C++}:
3779 @multitable @columnfractions .20 .80
3780 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
3781 @end multitable
3783 @item @emph{Reference}:
3784 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3785 3.2.31.
3786 @end table
3790 @node acc_memcpy_from_device
3791 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
3792 @table @asis
3793 @item @emph{Description}
3794 This function copies host memory specified by host address of @var{src} from
3795 device memory specified by the device address @var{dest} for a length of
3796 @var{bytes} bytes.
3798 @item @emph{C/C++}:
3799 @multitable @columnfractions .20 .80
3800 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
3801 @end multitable
3803 @item @emph{Reference}:
3804 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3805 3.2.32.
3806 @end table
3810 @node acc_attach
3811 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
3812 @table @asis
3813 @item @emph{Description}
3814 This function updates a pointer on the device from pointing to a host-pointer
3815 address to pointing to the corresponding device data.
3817 @item @emph{C/C++}:
3818 @multitable @columnfractions .20 .80
3819 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
3820 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
3821 @end multitable
3823 @item @emph{Reference}:
3824 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3825 3.2.34.
3826 @end table
3830 @node acc_detach
3831 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
3832 @table @asis
3833 @item @emph{Description}
3834 This function updates a pointer on the device from pointing to a device-pointer
3835 address to pointing to the corresponding host data.
3837 @item @emph{C/C++}:
3838 @multitable @columnfractions .20 .80
3839 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
3840 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
3841 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
3842 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
3843 @end multitable
3845 @item @emph{Reference}:
3846 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3847 3.2.35.
3848 @end table
3852 @node acc_get_current_cuda_device
3853 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
3854 @table @asis
3855 @item @emph{Description}
3856 This function returns the CUDA device handle. This handle is the same
3857 as used by the CUDA Runtime or Driver API's.
3859 @item @emph{C/C++}:
3860 @multitable @columnfractions .20 .80
3861 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
3862 @end multitable
3864 @item @emph{Reference}:
3865 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3866 A.2.1.1.
3867 @end table
3871 @node acc_get_current_cuda_context
3872 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
3873 @table @asis
3874 @item @emph{Description}
3875 This function returns the CUDA context handle. This handle is the same
3876 as used by the CUDA Runtime or Driver API's.
3878 @item @emph{C/C++}:
3879 @multitable @columnfractions .20 .80
3880 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
3881 @end multitable
3883 @item @emph{Reference}:
3884 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3885 A.2.1.2.
3886 @end table
3890 @node acc_get_cuda_stream
3891 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
3892 @table @asis
3893 @item @emph{Description}
3894 This function returns the CUDA stream handle for the queue @var{async}.
3895 This handle is the same as used by the CUDA Runtime or Driver API's.
3897 @item @emph{C/C++}:
3898 @multitable @columnfractions .20 .80
3899 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
3900 @end multitable
3902 @item @emph{Reference}:
3903 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3904 A.2.1.3.
3905 @end table
3909 @node acc_set_cuda_stream
3910 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
3911 @table @asis
3912 @item @emph{Description}
3913 This function associates the stream handle specified by @var{stream} with
3914 the queue @var{async}.
3916 This cannot be used to change the stream handle associated with
3917 @code{acc_async_sync}.
3919 The return value is not specified.
3921 @item @emph{C/C++}:
3922 @multitable @columnfractions .20 .80
3923 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
3924 @end multitable
3926 @item @emph{Reference}:
3927 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3928 A.2.1.4.
3929 @end table
3933 @node acc_prof_register
3934 @section @code{acc_prof_register} -- Register callbacks.
3935 @table @asis
3936 @item @emph{Description}:
3937 This function registers callbacks.
3939 @item @emph{C/C++}:
3940 @multitable @columnfractions .20 .80
3941 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
3942 @end multitable
3944 @item @emph{See also}:
3945 @ref{OpenACC Profiling Interface}
3947 @item @emph{Reference}:
3948 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3949 5.3.
3950 @end table
3954 @node acc_prof_unregister
3955 @section @code{acc_prof_unregister} -- Unregister callbacks.
3956 @table @asis
3957 @item @emph{Description}:
3958 This function unregisters callbacks.
3960 @item @emph{C/C++}:
3961 @multitable @columnfractions .20 .80
3962 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
3963 @end multitable
3965 @item @emph{See also}:
3966 @ref{OpenACC Profiling Interface}
3968 @item @emph{Reference}:
3969 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3970 5.3.
3971 @end table
3975 @node acc_prof_lookup
3976 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
3977 @table @asis
3978 @item @emph{Description}:
3979 Function to obtain inquiry functions.
3981 @item @emph{C/C++}:
3982 @multitable @columnfractions .20 .80
3983 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
3984 @end multitable
3986 @item @emph{See also}:
3987 @ref{OpenACC Profiling Interface}
3989 @item @emph{Reference}:
3990 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3991 5.3.
3992 @end table
3996 @node acc_register_library
3997 @section @code{acc_register_library} -- Library registration.
3998 @table @asis
3999 @item @emph{Description}:
4000 Function for library registration.
4002 @item @emph{C/C++}:
4003 @multitable @columnfractions .20 .80
4004 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
4005 @end multitable
4007 @item @emph{See also}:
4008 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
4010 @item @emph{Reference}:
4011 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4012 5.3.
4013 @end table
4017 @c ---------------------------------------------------------------------
4018 @c OpenACC Environment Variables
4019 @c ---------------------------------------------------------------------
4021 @node OpenACC Environment Variables
4022 @chapter OpenACC Environment Variables
4024 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
4025 are defined by section 4 of the OpenACC specification in version 2.0.
4026 The variable @env{ACC_PROFLIB}
4027 is defined by section 4 of the OpenACC specification in version 2.6.
4028 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
4030 @menu
4031 * ACC_DEVICE_TYPE::
4032 * ACC_DEVICE_NUM::
4033 * ACC_PROFLIB::
4034 * GCC_ACC_NOTIFY::
4035 @end menu
4039 @node ACC_DEVICE_TYPE
4040 @section @code{ACC_DEVICE_TYPE}
4041 @table @asis
4042 @item @emph{Reference}:
4043 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4044 4.1.
4045 @end table
4049 @node ACC_DEVICE_NUM
4050 @section @code{ACC_DEVICE_NUM}
4051 @table @asis
4052 @item @emph{Reference}:
4053 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4054 4.2.
4055 @end table
4059 @node ACC_PROFLIB
4060 @section @code{ACC_PROFLIB}
4061 @table @asis
4062 @item @emph{See also}:
4063 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
4065 @item @emph{Reference}:
4066 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4067 4.3.
4068 @end table
4072 @node GCC_ACC_NOTIFY
4073 @section @code{GCC_ACC_NOTIFY}
4074 @table @asis
4075 @item @emph{Description}:
4076 Print debug information pertaining to the accelerator.
4077 @end table
4081 @c ---------------------------------------------------------------------
4082 @c CUDA Streams Usage
4083 @c ---------------------------------------------------------------------
4085 @node CUDA Streams Usage
4086 @chapter CUDA Streams Usage
4088 This applies to the @code{nvptx} plugin only.
4090 The library provides elements that perform asynchronous movement of
4091 data and asynchronous operation of computing constructs.  This
4092 asynchronous functionality is implemented by making use of CUDA
4093 streams@footnote{See "Stream Management" in "CUDA Driver API",
4094 TRM-06703-001, Version 5.5, for additional information}.
4096 The primary means by that the asynchronous functionality is accessed
4097 is through the use of those OpenACC directives which make use of the
4098 @code{async} and @code{wait} clauses.  When the @code{async} clause is
4099 first used with a directive, it creates a CUDA stream.  If an
4100 @code{async-argument} is used with the @code{async} clause, then the
4101 stream is associated with the specified @code{async-argument}.
4103 Following the creation of an association between a CUDA stream and the
4104 @code{async-argument} of an @code{async} clause, both the @code{wait}
4105 clause and the @code{wait} directive can be used.  When either the
4106 clause or directive is used after stream creation, it creates a
4107 rendezvous point whereby execution waits until all operations
4108 associated with the @code{async-argument}, that is, stream, have
4109 completed.
4111 Normally, the management of the streams that are created as a result of
4112 using the @code{async} clause, is done without any intervention by the
4113 caller.  This implies the association between the @code{async-argument}
4114 and the CUDA stream will be maintained for the lifetime of the program.
4115 However, this association can be changed through the use of the library
4116 function @code{acc_set_cuda_stream}.  When the function
4117 @code{acc_set_cuda_stream} is called, the CUDA stream that was
4118 originally associated with the @code{async} clause will be destroyed.
4119 Caution should be taken when changing the association as subsequent
4120 references to the @code{async-argument} refer to a different
4121 CUDA stream.
4125 @c ---------------------------------------------------------------------
4126 @c OpenACC Library Interoperability
4127 @c ---------------------------------------------------------------------
4129 @node OpenACC Library Interoperability
4130 @chapter OpenACC Library Interoperability
4132 @section Introduction
4134 The OpenACC library uses the CUDA Driver API, and may interact with
4135 programs that use the Runtime library directly, or another library
4136 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
4137 "Interactions with the CUDA Driver API" in
4138 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
4139 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
4140 for additional information on library interoperability.}.
4141 This chapter describes the use cases and what changes are
4142 required in order to use both the OpenACC library and the CUBLAS and Runtime
4143 libraries within a program.
4145 @section First invocation: NVIDIA CUBLAS library API
4147 In this first use case (see below), a function in the CUBLAS library is called
4148 prior to any of the functions in the OpenACC library. More specifically, the
4149 function @code{cublasCreate()}.
4151 When invoked, the function initializes the library and allocates the
4152 hardware resources on the host and the device on behalf of the caller. Once
4153 the initialization and allocation has completed, a handle is returned to the
4154 caller. The OpenACC library also requires initialization and allocation of
4155 hardware resources. Since the CUBLAS library has already allocated the
4156 hardware resources for the device, all that is left to do is to initialize
4157 the OpenACC library and acquire the hardware resources on the host.
4159 Prior to calling the OpenACC function that initializes the library and
4160 allocate the host hardware resources, you need to acquire the device number
4161 that was allocated during the call to @code{cublasCreate()}. The invoking of the
4162 runtime library function @code{cudaGetDevice()} accomplishes this. Once
4163 acquired, the device number is passed along with the device type as
4164 parameters to the OpenACC library function @code{acc_set_device_num()}.
4166 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
4167 library uses the  context that was created during the call to
4168 @code{cublasCreate()}. In other words, both libraries will be sharing the
4169 same context.
4171 @smallexample
4172     /* Create the handle */
4173     s = cublasCreate(&h);
4174     if (s != CUBLAS_STATUS_SUCCESS)
4175     @{
4176         fprintf(stderr, "cublasCreate failed %d\n", s);
4177         exit(EXIT_FAILURE);
4178     @}
4180     /* Get the device number */
4181     e = cudaGetDevice(&dev);
4182     if (e != cudaSuccess)
4183     @{
4184         fprintf(stderr, "cudaGetDevice failed %d\n", e);
4185         exit(EXIT_FAILURE);
4186     @}
4188     /* Initialize OpenACC library and use device 'dev' */
4189     acc_set_device_num(dev, acc_device_nvidia);
4191 @end smallexample
4192 @center Use Case 1 
4194 @section First invocation: OpenACC library API
4196 In this second use case (see below), a function in the OpenACC library is
4197 called prior to any of the functions in the CUBLAS library. More specifically,
4198 the function @code{acc_set_device_num()}.
4200 In the use case presented here, the function @code{acc_set_device_num()}
4201 is used to both initialize the OpenACC library and allocate the hardware
4202 resources on the host and the device. In the call to the function, the
4203 call parameters specify which device to use and what device
4204 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
4205 is but one method to initialize the OpenACC library and allocate the
4206 appropriate hardware resources. Other methods are available through the
4207 use of environment variables and these will be discussed in the next section.
4209 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
4210 functions can be called as seen with multiple calls being made to
4211 @code{acc_copyin()}. In addition, calls can be made to functions in the
4212 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
4213 subsequent to the calls to @code{acc_copyin()}.
4214 As seen in the previous use case, a call to @code{cublasCreate()}
4215 initializes the CUBLAS library and allocates the hardware resources on the
4216 host and the device.  However, since the device has already been allocated,
4217 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
4218 the appropriate hardware resources on the host. The context that was created
4219 as part of the OpenACC initialization is shared with the CUBLAS library,
4220 similarly to the first use case.
4222 @smallexample
4223     dev = 0;
4225     acc_set_device_num(dev, acc_device_nvidia);
4227     /* Copy the first set to the device */
4228     d_X = acc_copyin(&h_X[0], N * sizeof (float));
4229     if (d_X == NULL)
4230     @{ 
4231         fprintf(stderr, "copyin error h_X\n");
4232         exit(EXIT_FAILURE);
4233     @}
4235     /* Copy the second set to the device */
4236     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
4237     if (d_Y == NULL)
4238     @{ 
4239         fprintf(stderr, "copyin error h_Y1\n");
4240         exit(EXIT_FAILURE);
4241     @}
4243     /* Create the handle */
4244     s = cublasCreate(&h);
4245     if (s != CUBLAS_STATUS_SUCCESS)
4246     @{
4247         fprintf(stderr, "cublasCreate failed %d\n", s);
4248         exit(EXIT_FAILURE);
4249     @}
4251     /* Perform saxpy using CUBLAS library function */
4252     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
4253     if (s != CUBLAS_STATUS_SUCCESS)
4254     @{
4255         fprintf(stderr, "cublasSaxpy failed %d\n", s);
4256         exit(EXIT_FAILURE);
4257     @}
4259     /* Copy the results from the device */
4260     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
4262 @end smallexample
4263 @center Use Case 2
4265 @section OpenACC library and environment variables
4267 There are two environment variables associated with the OpenACC library
4268 that may be used to control the device type and device number:
4269 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
4270 environment variables can be used as an alternative to calling
4271 @code{acc_set_device_num()}. As seen in the second use case, the device
4272 type and device number were specified using @code{acc_set_device_num()}.
4273 If however, the aforementioned environment variables were set, then the
4274 call to @code{acc_set_device_num()} would not be required.
4277 The use of the environment variables is only relevant when an OpenACC function
4278 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
4279 is called prior to a call to an OpenACC function, then you must call
4280 @code{acc_set_device_num()}@footnote{More complete information
4281 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
4282 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
4283 Application Programming Interface”, Version 2.6.}
4287 @c ---------------------------------------------------------------------
4288 @c OpenACC Profiling Interface
4289 @c ---------------------------------------------------------------------
4291 @node OpenACC Profiling Interface
4292 @chapter OpenACC Profiling Interface
4294 @section Implementation Status and Implementation-Defined Behavior
4296 We're implementing the OpenACC Profiling Interface as defined by the
4297 OpenACC 2.6 specification.  We're clarifying some aspects here as
4298 @emph{implementation-defined behavior}, while they're still under
4299 discussion within the OpenACC Technical Committee.
4301 This implementation is tuned to keep the performance impact as low as
4302 possible for the (very common) case that the Profiling Interface is
4303 not enabled.  This is relevant, as the Profiling Interface affects all
4304 the @emph{hot} code paths (in the target code, not in the offloaded
4305 code).  Users of the OpenACC Profiling Interface can be expected to
4306 understand that performance will be impacted to some degree once the
4307 Profiling Interface has gotten enabled: for example, because of the
4308 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
4309 every event that has been registered.
4311 We're not yet accounting for the fact that @cite{OpenACC events may
4312 occur during event processing}.
4313 We just handle one case specially, as required by CUDA 9.0
4314 @command{nvprof}, that @code{acc_get_device_type}
4315 (@ref{acc_get_device_type})) may be called from
4316 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4317 callbacks.
4319 We're not yet implementing initialization via a
4320 @code{acc_register_library} function that is either statically linked
4321 in, or dynamically via @env{LD_PRELOAD}.
4322 Initialization via @code{acc_register_library} functions dynamically
4323 loaded via the @env{ACC_PROFLIB} environment variable does work, as
4324 does directly calling @code{acc_prof_register},
4325 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
4327 As currently there are no inquiry functions defined, calls to
4328 @code{acc_prof_lookup} will always return @code{NULL}.
4330 There aren't separate @emph{start}, @emph{stop} events defined for the
4331 event types @code{acc_ev_create}, @code{acc_ev_delete},
4332 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
4333 should be triggered before or after the actual device-specific call is
4334 made.  We trigger them after.
4336 Remarks about data provided to callbacks:
4338 @table @asis
4340 @item @code{acc_prof_info.event_type}
4341 It's not clear if for @emph{nested} event callbacks (for example,
4342 @code{acc_ev_enqueue_launch_start} as part of a parent compute
4343 construct), this should be set for the nested event
4344 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
4345 construct should remain (@code{acc_ev_compute_construct_start}).  In
4346 this implementation, the value will generally correspond to the
4347 innermost nested event type.
4349 @item @code{acc_prof_info.device_type}
4350 @itemize
4352 @item
4353 For @code{acc_ev_compute_construct_start}, and in presence of an
4354 @code{if} clause with @emph{false} argument, this will still refer to
4355 the offloading device type.
4356 It's not clear if that's the expected behavior.
4358 @item
4359 Complementary to the item before, for
4360 @code{acc_ev_compute_construct_end}, this is set to
4361 @code{acc_device_host} in presence of an @code{if} clause with
4362 @emph{false} argument.
4363 It's not clear if that's the expected behavior.
4365 @end itemize
4367 @item @code{acc_prof_info.thread_id}
4368 Always @code{-1}; not yet implemented.
4370 @item @code{acc_prof_info.async}
4371 @itemize
4373 @item
4374 Not yet implemented correctly for
4375 @code{acc_ev_compute_construct_start}.
4377 @item
4378 In a compute construct, for host-fallback
4379 execution/@code{acc_device_host} it will always be
4380 @code{acc_async_sync}.
4381 It's not clear if that's the expected behavior.
4383 @item
4384 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
4385 it will always be @code{acc_async_sync}.
4386 It's not clear if that's the expected behavior.
4388 @end itemize
4390 @item @code{acc_prof_info.async_queue}
4391 There is no @cite{limited number of asynchronous queues} in libgomp.
4392 This will always have the same value as @code{acc_prof_info.async}.
4394 @item @code{acc_prof_info.src_file}
4395 Always @code{NULL}; not yet implemented.
4397 @item @code{acc_prof_info.func_name}
4398 Always @code{NULL}; not yet implemented.
4400 @item @code{acc_prof_info.line_no}
4401 Always @code{-1}; not yet implemented.
4403 @item @code{acc_prof_info.end_line_no}
4404 Always @code{-1}; not yet implemented.
4406 @item @code{acc_prof_info.func_line_no}
4407 Always @code{-1}; not yet implemented.
4409 @item @code{acc_prof_info.func_end_line_no}
4410 Always @code{-1}; not yet implemented.
4412 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
4413 Relating to @code{acc_prof_info.event_type} discussed above, in this
4414 implementation, this will always be the same value as
4415 @code{acc_prof_info.event_type}.
4417 @item @code{acc_event_info.*.parent_construct}
4418 @itemize
4420 @item
4421 Will be @code{acc_construct_parallel} for all OpenACC compute
4422 constructs as well as many OpenACC Runtime API calls; should be the
4423 one matching the actual construct, or
4424 @code{acc_construct_runtime_api}, respectively.
4426 @item
4427 Will be @code{acc_construct_enter_data} or
4428 @code{acc_construct_exit_data} when processing variable mappings
4429 specified in OpenACC @emph{declare} directives; should be
4430 @code{acc_construct_declare}.
4432 @item
4433 For implicit @code{acc_ev_device_init_start},
4434 @code{acc_ev_device_init_end}, and explicit as well as implicit
4435 @code{acc_ev_alloc}, @code{acc_ev_free},
4436 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4437 @code{acc_ev_enqueue_download_start}, and
4438 @code{acc_ev_enqueue_download_end}, will be
4439 @code{acc_construct_parallel}; should reflect the real parent
4440 construct.
4442 @end itemize
4444 @item @code{acc_event_info.*.implicit}
4445 For @code{acc_ev_alloc}, @code{acc_ev_free},
4446 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4447 @code{acc_ev_enqueue_download_start}, and
4448 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
4449 also for explicit usage.
4451 @item @code{acc_event_info.data_event.var_name}
4452 Always @code{NULL}; not yet implemented.
4454 @item @code{acc_event_info.data_event.host_ptr}
4455 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
4456 @code{NULL}.
4458 @item @code{typedef union acc_api_info}
4459 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
4460 Information}.  This should obviously be @code{typedef @emph{struct}
4461 acc_api_info}.
4463 @item @code{acc_api_info.device_api}
4464 Possibly not yet implemented correctly for
4465 @code{acc_ev_compute_construct_start},
4466 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
4467 will always be @code{acc_device_api_none} for these event types.
4468 For @code{acc_ev_enter_data_start}, it will be
4469 @code{acc_device_api_none} in some cases.
4471 @item @code{acc_api_info.device_type}
4472 Always the same as @code{acc_prof_info.device_type}.
4474 @item @code{acc_api_info.vendor}
4475 Always @code{-1}; not yet implemented.
4477 @item @code{acc_api_info.device_handle}
4478 Always @code{NULL}; not yet implemented.
4480 @item @code{acc_api_info.context_handle}
4481 Always @code{NULL}; not yet implemented.
4483 @item @code{acc_api_info.async_handle}
4484 Always @code{NULL}; not yet implemented.
4486 @end table
4488 Remarks about certain event types:
4490 @table @asis
4492 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4493 @itemize
4495 @item
4496 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
4497 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
4498 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
4499 When a compute construct triggers implicit
4500 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
4501 events, they currently aren't @emph{nested within} the corresponding
4502 @code{acc_ev_compute_construct_start} and
4503 @code{acc_ev_compute_construct_end}, but they're currently observed
4504 @emph{before} @code{acc_ev_compute_construct_start}.
4505 It's not clear what to do: the standard asks us provide a lot of
4506 details to the @code{acc_ev_compute_construct_start} callback, without
4507 (implicitly) initializing a device before?
4509 @item
4510 Callbacks for these event types will not be invoked for calls to the
4511 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
4512 It's not clear if they should be.
4514 @end itemize
4516 @item @code{acc_ev_enter_data_start}, @code{acc_ev_enter_data_end}, @code{acc_ev_exit_data_start}, @code{acc_ev_exit_data_end}
4517 @itemize
4519 @item
4520 Callbacks for these event types will also be invoked for OpenACC
4521 @emph{host_data} constructs.
4522 It's not clear if they should be.
4524 @item
4525 Callbacks for these event types will also be invoked when processing
4526 variable mappings specified in OpenACC @emph{declare} directives.
4527 It's not clear if they should be.
4529 @end itemize
4531 @end table
4533 Callbacks for the following event types will be invoked, but dispatch
4534 and information provided therein has not yet been thoroughly reviewed:
4536 @itemize
4537 @item @code{acc_ev_alloc}
4538 @item @code{acc_ev_free}
4539 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
4540 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
4541 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
4542 @end itemize
4544 During device initialization, and finalization, respectively,
4545 callbacks for the following event types will not yet be invoked:
4547 @itemize
4548 @item @code{acc_ev_alloc}
4549 @item @code{acc_ev_free}
4550 @end itemize
4552 Callbacks for the following event types have not yet been implemented,
4553 so currently won't be invoked:
4555 @itemize
4556 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
4557 @item @code{acc_ev_runtime_shutdown}
4558 @item @code{acc_ev_create}, @code{acc_ev_delete}
4559 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
4560 @end itemize
4562 For the following runtime library functions, not all expected
4563 callbacks will be invoked (mostly concerning implicit device
4564 initialization):
4566 @itemize
4567 @item @code{acc_get_num_devices}
4568 @item @code{acc_set_device_type}
4569 @item @code{acc_get_device_type}
4570 @item @code{acc_set_device_num}
4571 @item @code{acc_get_device_num}
4572 @item @code{acc_init}
4573 @item @code{acc_shutdown}
4574 @end itemize
4576 Aside from implicit device initialization, for the following runtime
4577 library functions, no callbacks will be invoked for shared-memory
4578 offloading devices (it's not clear if they should be):
4580 @itemize
4581 @item @code{acc_malloc}
4582 @item @code{acc_free}
4583 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
4584 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
4585 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
4586 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
4587 @item @code{acc_update_device}, @code{acc_update_device_async}
4588 @item @code{acc_update_self}, @code{acc_update_self_async}
4589 @item @code{acc_map_data}, @code{acc_unmap_data}
4590 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
4591 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
4592 @end itemize
4594 @c ---------------------------------------------------------------------
4595 @c OpenMP-Implementation Specifics
4596 @c ---------------------------------------------------------------------
4598 @node OpenMP-Implementation Specifics
4599 @chapter OpenMP-Implementation Specifics
4601 @menu
4602 * Implementation-defined ICV Initialization::
4603 * OpenMP Context Selectors::
4604 * Memory allocation::
4605 @end menu
4607 @node Implementation-defined ICV Initialization
4608 @section Implementation-defined ICV Initialization
4609 @cindex Implementation specific setting
4611 @multitable @columnfractions .30 .70
4612 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
4613 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
4614 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
4615 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
4616 @item @var{nthreads-var} @tab See @code{OMP_NUM_THREADS}.
4617 @item @var{num-devices-var} @tab Number of non-host devices found
4618 by GCC's run-time library
4619 @item @var{num-procs-var} @tab The number of CPU cores on the
4620 initial device, except that affinity settings might lead to a
4621 smaller number.  On non-host devices, the value of the
4622 @var{nthreads-var} ICV.
4623 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
4624 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
4625 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
4626 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
4627 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
4628 @ref{GOMP_SPINCOUNT}
4629 @end multitable
4631 @node OpenMP Context Selectors
4632 @section OpenMP Context Selectors
4634 @code{vendor} is always @code{gnu}. References are to the GCC manual.
4636 @multitable @columnfractions .60 .10 .25
4637 @headitem @code{arch} @tab @code{kind} @tab @code{isa}
4638 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
4639       @code{i586}, @code{i686}, @code{ia32}
4640       @tab @code{host}
4641       @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
4642 @item @code{amdgcn}, @code{gcn}
4643       @tab @code{gpu}
4644       @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
4645       @code{gfx803} is supported as an alias for @code{fiji}.}
4646 @item @code{nvptx}
4647       @tab @code{gpu}
4648       @tab See @code{-march=} in ``Nvidia PTX Options''
4649 @end multitable
4651 @node Memory allocation
4652 @section Memory allocation
4654 For the available predefined allocators and, as applicable, their associated
4655 predefined memory spaces and for the available traits and their default values,
4656 see @ref{OMP_ALLOCATOR}.  Predefined allocators without an associated memory
4657 space use the @code{omp_default_mem_space} memory space.
4659 For the memory spaces, the following applies:
4660 @itemize
4661 @item @code{omp_default_mem_space} is supported
4662 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
4663 @item @code{omp_low_lat_mem_space} maps to @code{omp_default_mem_space}
4664 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
4665       unless the memkind library is available
4666 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
4667       unless the memkind library is available
4668 @end itemize
4670 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
4671 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
4672 creating memory allocators requesting
4674 @itemize
4675 @item the memory space @code{omp_high_bw_mem_space}
4676 @item the memory space @code{omp_large_cap_mem_space}
4677 @item the @code{partition} trait @code{interleaved}; note that for
4678       @code{omp_large_cap_mem_space} the allocation will not be interleaved
4679 @end itemize
4681 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
4682 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
4683 memory allocators requesting
4685 @itemize
4686 @item the @code{partition} trait @code{nearest}, except when both the
4687 libmemkind library is available and the memory space is either
4688 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
4689 @end itemize
4691 Note that the numa library will round up the allocation size to a multiple of
4692 the system page size; therefore, consider using it only with large data or
4693 by sharing allocations via the @code{pool_size} trait.  Furthermore, the Linux
4694 kernel does not guarantee that an allocation will always be on the nearest NUMA
4695 node nor that after reallocation the same node will be used.  Note additionally
4696 that, on Linux, the default setting of the memory placement policy is to use the
4697 current node; therefore, unless the memory placement policy has been overridden,
4698 the @code{partition} trait @code{environment} (the default) will be effectively
4699 a @code{nearest} allocation.
4701 Additional notes regarding the traits:
4702 @itemize
4703 @item The @code{pinned} trait is unsupported.
4704 @item The default for the @code{pool_size} trait is no pool and for every
4705       (re)allocation the associated library routine is called, which might
4706       internally use a memory pool.
4707 @item For the @code{partition} trait, the partition part size will be the same
4708       as the requested size (i.e. @code{interleaved} or @code{blocked} has no
4709       effect), except for @code{interleaved} when the memkind library is
4710       available.  Furthermore, for @code{nearest} and unless the numa library
4711       is available, the memory might not be on the same NUMA node as thread
4712       that allocated the memory; on Linux, this is in particular the case when
4713       the memory placement policy is set to preferred.
4714 @item The @code{access} trait has no effect such that memory is always
4715       accessible by all threads.
4716 @item The @code{sync_hint} trait has no effect.
4717 @end itemize
4719 @c ---------------------------------------------------------------------
4720 @c Offload-Target Specifics
4721 @c ---------------------------------------------------------------------
4723 @node Offload-Target Specifics
4724 @chapter Offload-Target Specifics
4726 The following sections present notes on the offload-target specifics
4728 @menu
4729 * AMD Radeon::
4730 * nvptx::
4731 @end menu
4733 @node AMD Radeon
4734 @section AMD Radeon (GCN)
4736 On the hardware side, there is the hierarchy (fine to coarse):
4737 @itemize
4738 @item work item (thread)
4739 @item wavefront
4740 @item work group
4741 @item compute unit (CU)
4742 @end itemize
4744 All OpenMP and OpenACC levels are used, i.e.
4745 @itemize
4746 @item OpenMP's simd and OpenACC's vector map to work items (thread)
4747 @item OpenMP's threads (``parallel'') and OpenACC's workers map
4748       to wavefronts
4749 @item OpenMP's teams and OpenACC's gang use a threadpool with the
4750       size of the number of teams or gangs, respectively.
4751 @end itemize
4753 The used sizes are
4754 @itemize
4755 @item Number of teams is the specified @code{num_teams} (OpenMP) or
4756       @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
4757       by two times the number of CU.
4758 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
4759       @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
4760       overrides this if smaller.
4761 @item The wavefront has 102 scalars and 64 vectors
4762 @item Number of workitems is always 64
4763 @item The hardware permits maximally 40 workgroups/CU and
4764       16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
4765 @item 80 scalars registers and 24 vector registers in non-kernel functions
4766       (the chosen procedure-calling API).
4767 @item For the kernel itself: as many as register pressure demands (number of
4768       teams and number of threads, scaled down if registers are exhausted)
4769 @end itemize
4771 The implementation remark:
4772 @itemize
4773 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
4774       using the C library @code{printf} functions and the Fortran
4775       @code{print}/@code{write} statements.
4776 @item Reverse offload regions (i.e. @code{target} regions with
4777       @code{device(ancestor:1)}) are processed serially per @code{target} region
4778       such that the next reverse offload region is only executed after the previous
4779       one returned.
4780 @item OpenMP code that has a @code{requires} directive with
4781       @code{unified_shared_memory} will remove any GCN device from the list of
4782       available devices (``host fallback'').
4783 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
4784       environment variable; the default is 32 kiB per thread.
4785 @end itemize
4789 @node nvptx
4790 @section nvptx
4792 On the hardware side, there is the hierarchy (fine to coarse):
4793 @itemize
4794 @item thread
4795 @item warp
4796 @item thread block
4797 @item streaming multiprocessor
4798 @end itemize
4800 All OpenMP and OpenACC levels are used, i.e.
4801 @itemize
4802 @item OpenMP's simd and OpenACC's vector map to threads
4803 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
4804 @item OpenMP's teams and OpenACC's gang use a threadpool with the
4805       size of the number of teams or gangs, respectively.
4806 @end itemize
4808 The used sizes are
4809 @itemize
4810 @item The @code{warp_size} is always 32
4811 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
4812 @item The number of teams is limited by the number of blocks the device can
4813       host simultaneously.
4814 @end itemize
4816 Additional information can be obtained by setting the environment variable to
4817 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
4818 parameters).
4820 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
4821 which caches the JIT in the user's directory (see CUDA documentation; can be
4822 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
4824 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
4825 options still affect the used PTX ISA code and, thus, the requirements on
4826 CUDA version and hardware.
4828 The implementation remark:
4829 @itemize
4830 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
4831       using the C library @code{printf} functions. Note that the Fortran
4832       @code{print}/@code{write} statements are not supported, yet.
4833 @item Compilation OpenMP code that contains @code{requires reverse_offload}
4834       requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
4835       is not supported.
4836 @item For code containing reverse offload (i.e. @code{target} regions with
4837       @code{device(ancestor:1)}), there is a slight performance penalty
4838       for @emph{all} target regions, consisting mostly of shutdown delay
4839       Per device, reverse offload regions are processed serially such that
4840       the next reverse offload region is only executed after the previous
4841       one returned.
4842 @item OpenMP code that has a @code{requires} directive with
4843       @code{unified_shared_memory} will remove any nvptx device from the
4844       list of available devices (``host fallback'').
4845 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
4846       in the GCC manual.
4847 @end itemize
4850 @c ---------------------------------------------------------------------
4851 @c The libgomp ABI
4852 @c ---------------------------------------------------------------------
4854 @node The libgomp ABI
4855 @chapter The libgomp ABI
4857 The following sections present notes on the external ABI as 
4858 presented by libgomp.  Only maintainers should need them.
4860 @menu
4861 * Implementing MASTER construct::
4862 * Implementing CRITICAL construct::
4863 * Implementing ATOMIC construct::
4864 * Implementing FLUSH construct::
4865 * Implementing BARRIER construct::
4866 * Implementing THREADPRIVATE construct::
4867 * Implementing PRIVATE clause::
4868 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
4869 * Implementing REDUCTION clause::
4870 * Implementing PARALLEL construct::
4871 * Implementing FOR construct::
4872 * Implementing ORDERED construct::
4873 * Implementing SECTIONS construct::
4874 * Implementing SINGLE construct::
4875 * Implementing OpenACC's PARALLEL construct::
4876 @end menu
4879 @node Implementing MASTER construct
4880 @section Implementing MASTER construct
4882 @smallexample
4883 if (omp_get_thread_num () == 0)
4884   block
4885 @end smallexample
4887 Alternately, we generate two copies of the parallel subfunction
4888 and only include this in the version run by the primary thread.
4889 Surely this is not worthwhile though...
4893 @node Implementing CRITICAL construct
4894 @section Implementing CRITICAL construct
4896 Without a specified name,
4898 @smallexample
4899   void GOMP_critical_start (void);
4900   void GOMP_critical_end (void);
4901 @end smallexample
4903 so that we don't get COPY relocations from libgomp to the main
4904 application.
4906 With a specified name, use omp_set_lock and omp_unset_lock with
4907 name being transformed into a variable declared like
4909 @smallexample
4910   omp_lock_t gomp_critical_user_<name> __attribute__((common))
4911 @end smallexample
4913 Ideally the ABI would specify that all zero is a valid unlocked
4914 state, and so we wouldn't need to initialize this at
4915 startup.
4919 @node Implementing ATOMIC construct
4920 @section Implementing ATOMIC construct
4922 The target should implement the @code{__sync} builtins.
4924 Failing that we could add
4926 @smallexample
4927   void GOMP_atomic_enter (void)
4928   void GOMP_atomic_exit (void)
4929 @end smallexample
4931 which reuses the regular lock code, but with yet another lock
4932 object private to the library.
4936 @node Implementing FLUSH construct
4937 @section Implementing FLUSH construct
4939 Expands to the @code{__sync_synchronize} builtin.
4943 @node Implementing BARRIER construct
4944 @section Implementing BARRIER construct
4946 @smallexample
4947   void GOMP_barrier (void)
4948 @end smallexample
4951 @node Implementing THREADPRIVATE construct
4952 @section Implementing THREADPRIVATE construct
4954 In _most_ cases we can map this directly to @code{__thread}.  Except
4955 that OMP allows constructors for C++ objects.  We can either
4956 refuse to support this (how often is it used?) or we can 
4957 implement something akin to .ctors.
4959 Even more ideally, this ctor feature is handled by extensions
4960 to the main pthreads library.  Failing that, we can have a set
4961 of entry points to register ctor functions to be called.
4965 @node Implementing PRIVATE clause
4966 @section Implementing PRIVATE clause
4968 In association with a PARALLEL, or within the lexical extent
4969 of a PARALLEL block, the variable becomes a local variable in
4970 the parallel subfunction.
4972 In association with FOR or SECTIONS blocks, create a new
4973 automatic variable within the current function.  This preserves
4974 the semantic of new variable creation.
4978 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4979 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4981 This seems simple enough for PARALLEL blocks.  Create a private 
4982 struct for communicating between the parent and subfunction.
4983 In the parent, copy in values for scalar and "small" structs;
4984 copy in addresses for others TREE_ADDRESSABLE types.  In the 
4985 subfunction, copy the value into the local variable.
4987 It is not clear what to do with bare FOR or SECTION blocks.
4988 The only thing I can figure is that we do something like:
4990 @smallexample
4991 #pragma omp for firstprivate(x) lastprivate(y)
4992 for (int i = 0; i < n; ++i)
4993   body;
4994 @end smallexample
4996 which becomes
4998 @smallexample
5000   int x = x, y;
5002   // for stuff
5004   if (i == n)
5005     y = y;
5007 @end smallexample
5009 where the "x=x" and "y=y" assignments actually have different
5010 uids for the two variables, i.e. not something you could write
5011 directly in C.  Presumably this only makes sense if the "outer"
5012 x and y are global variables.
5014 COPYPRIVATE would work the same way, except the structure 
5015 broadcast would have to happen via SINGLE machinery instead.
5019 @node Implementing REDUCTION clause
5020 @section Implementing REDUCTION clause
5022 The private struct mentioned in the previous section should have 
5023 a pointer to an array of the type of the variable, indexed by the 
5024 thread's @var{team_id}.  The thread stores its final value into the 
5025 array, and after the barrier, the primary thread iterates over the
5026 array to collect the values.
5029 @node Implementing PARALLEL construct
5030 @section Implementing PARALLEL construct
5032 @smallexample
5033   #pragma omp parallel
5034   @{
5035     body;
5036   @}
5037 @end smallexample
5039 becomes
5041 @smallexample
5042   void subfunction (void *data)
5043   @{
5044     use data;
5045     body;
5046   @}
5048   setup data;
5049   GOMP_parallel_start (subfunction, &data, num_threads);
5050   subfunction (&data);
5051   GOMP_parallel_end ();
5052 @end smallexample
5054 @smallexample
5055   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
5056 @end smallexample
5058 The @var{FN} argument is the subfunction to be run in parallel.
5060 The @var{DATA} argument is a pointer to a structure used to 
5061 communicate data in and out of the subfunction, as discussed
5062 above with respect to FIRSTPRIVATE et al.
5064 The @var{NUM_THREADS} argument is 1 if an IF clause is present
5065 and false, or the value of the NUM_THREADS clause, if
5066 present, or 0.
5068 The function needs to create the appropriate number of
5069 threads and/or launch them from the dock.  It needs to
5070 create the team structure and assign team ids.
5072 @smallexample
5073   void GOMP_parallel_end (void)
5074 @end smallexample
5076 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
5080 @node Implementing FOR construct
5081 @section Implementing FOR construct
5083 @smallexample
5084   #pragma omp parallel for
5085   for (i = lb; i <= ub; i++)
5086     body;
5087 @end smallexample
5089 becomes
5091 @smallexample
5092   void subfunction (void *data)
5093   @{
5094     long _s0, _e0;
5095     while (GOMP_loop_static_next (&_s0, &_e0))
5096     @{
5097       long _e1 = _e0, i;
5098       for (i = _s0; i < _e1; i++)
5099         body;
5100     @}
5101     GOMP_loop_end_nowait ();
5102   @}
5104   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
5105   subfunction (NULL);
5106   GOMP_parallel_end ();
5107 @end smallexample
5109 @smallexample
5110   #pragma omp for schedule(runtime)
5111   for (i = 0; i < n; i++)
5112     body;
5113 @end smallexample
5115 becomes
5117 @smallexample
5118   @{
5119     long i, _s0, _e0;
5120     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
5121       do @{
5122         long _e1 = _e0;
5123         for (i = _s0, i < _e0; i++)
5124           body;
5125       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
5126     GOMP_loop_end ();
5127   @}
5128 @end smallexample
5130 Note that while it looks like there is trickiness to propagating
5131 a non-constant STEP, there isn't really.  We're explicitly allowed
5132 to evaluate it as many times as we want, and any variables involved
5133 should automatically be handled as PRIVATE or SHARED like any other
5134 variables.  So the expression should remain evaluable in the 
5135 subfunction.  We can also pull it into a local variable if we like,
5136 but since its supposed to remain unchanged, we can also not if we like.
5138 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
5139 able to get away with no work-sharing context at all, since we can
5140 simply perform the arithmetic directly in each thread to divide up
5141 the iterations.  Which would mean that we wouldn't need to call any
5142 of these routines.
5144 There are separate routines for handling loops with an ORDERED
5145 clause.  Bookkeeping for that is non-trivial...
5149 @node Implementing ORDERED construct
5150 @section Implementing ORDERED construct
5152 @smallexample
5153   void GOMP_ordered_start (void)
5154   void GOMP_ordered_end (void)
5155 @end smallexample
5159 @node Implementing SECTIONS construct
5160 @section Implementing SECTIONS construct
5162 A block as 
5164 @smallexample
5165   #pragma omp sections
5166   @{
5167     #pragma omp section
5168     stmt1;
5169     #pragma omp section
5170     stmt2;
5171     #pragma omp section
5172     stmt3;
5173   @}
5174 @end smallexample
5176 becomes
5178 @smallexample
5179   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
5180     switch (i)
5181       @{
5182       case 1:
5183         stmt1;
5184         break;
5185       case 2:
5186         stmt2;
5187         break;
5188       case 3:
5189         stmt3;
5190         break;
5191       @}
5192   GOMP_barrier ();
5193 @end smallexample
5196 @node Implementing SINGLE construct
5197 @section Implementing SINGLE construct
5199 A block like 
5201 @smallexample
5202   #pragma omp single
5203   @{
5204     body;
5205   @}
5206 @end smallexample
5208 becomes
5210 @smallexample
5211   if (GOMP_single_start ())
5212     body;
5213   GOMP_barrier ();
5214 @end smallexample
5216 while 
5218 @smallexample
5219   #pragma omp single copyprivate(x)
5220     body;
5221 @end smallexample
5223 becomes
5225 @smallexample
5226   datap = GOMP_single_copy_start ();
5227   if (datap == NULL)
5228     @{
5229       body;
5230       data.x = x;
5231       GOMP_single_copy_end (&data);
5232     @}
5233   else
5234     x = datap->x;
5235   GOMP_barrier ();
5236 @end smallexample
5240 @node Implementing OpenACC's PARALLEL construct
5241 @section Implementing OpenACC's PARALLEL construct
5243 @smallexample
5244   void GOACC_parallel ()
5245 @end smallexample
5249 @c ---------------------------------------------------------------------
5250 @c Reporting Bugs
5251 @c ---------------------------------------------------------------------
5253 @node Reporting Bugs
5254 @chapter Reporting Bugs
5256 Bugs in the GNU Offloading and Multi Processing Runtime Library should
5257 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
5258 "openacc", or "openmp", or both to the keywords field in the bug
5259 report, as appropriate.
5263 @c ---------------------------------------------------------------------
5264 @c GNU General Public License
5265 @c ---------------------------------------------------------------------
5267 @include gpl_v3.texi
5271 @c ---------------------------------------------------------------------
5272 @c GNU Free Documentation License
5273 @c ---------------------------------------------------------------------
5275 @include fdl.texi
5279 @c ---------------------------------------------------------------------
5280 @c Funding Free Software
5281 @c ---------------------------------------------------------------------
5283 @include funding.texi
5285 @c ---------------------------------------------------------------------
5286 @c Index
5287 @c ---------------------------------------------------------------------
5289 @node Library Index
5290 @unnumbered Library Index
5292 @printindex cp
5294 @bye