i386: Rename sat_plusminus expanders to standard names [PR112600]
[official-gcc.git] / libgomp / libgomp.texi
blob71d62105a20e6fb89b1808dcc953c20d58e0aa84
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-2024 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 @option{-fopenmp} must be specified.  For C and C++, this enables
141 the handling of the OpenMP directives using @code{#pragma omp} and the
142 @code{[[omp::directive(...)]]}, @code{[[omp::sequence(...)]]} and
143 @code{[[omp::decl(...)]]} attributes.  For Fortran, it enables for
144 free source form the @code{!$omp} sentinel for directives and the
145 @code{!$} conditional compilation sentinel and for fixed source form the
146 @code{c$omp}, @code{*$omp} and @code{!$omp} sentinels for directives and
147 the @code{c$}, @code{*$} and @code{!$} conditional compilation sentinels.
148 The flag also arranges for automatic linking of the OpenMP runtime library
149 (@ref{Runtime Library Routines}).
151 The @option{-fopenmp-simd} flag can be used to enable a subset of
152 OpenMP directives that do not require the linking of either the
153 OpenMP runtime library or the POSIX threads library.
155 A complete description of all OpenMP directives may be found in the
156 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
157 See also @ref{OpenMP Implementation Status}.
160 @c ---------------------------------------------------------------------
161 @c OpenMP Implementation Status
162 @c ---------------------------------------------------------------------
164 @node OpenMP Implementation Status
165 @chapter OpenMP Implementation Status
167 @menu
168 * OpenMP 4.5:: Feature completion status to 4.5 specification
169 * OpenMP 5.0:: Feature completion status to 5.0 specification
170 * OpenMP 5.1:: Feature completion status to 5.1 specification
171 * OpenMP 5.2:: Feature completion status to 5.2 specification
172 * OpenMP Technical Report 12:: Feature completion status to second 6.0 preview
173 @end menu
175 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
176 parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
177 the value @code{201511} (i.e. OpenMP 4.5).
179 @node OpenMP 4.5
180 @section OpenMP 4.5
182 The OpenMP 4.5 specification is fully supported.
184 @node OpenMP 5.0
185 @section OpenMP 5.0
187 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
188 @c This list is sorted as in OpenMP 5.1's B.3 not as in OpenMP 5.0's B.2
190 @multitable @columnfractions .60 .10 .25
191 @headitem Description @tab Status @tab Comments
192 @item Array shaping @tab N @tab
193 @item Array sections with non-unit strides in C and C++ @tab N @tab
194 @item Iterators @tab Y @tab
195 @item @code{metadirective} directive @tab N @tab
196 @item @code{declare variant} directive
197       @tab P @tab @emph{simd} traits not handled correctly
198 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
199       env variable @tab Y @tab
200 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
201 @item @code{requires} directive @tab P
202       @tab complete but no non-host device provides @code{unified_shared_memory}
203 @item @code{teams} construct outside an enclosing target region @tab Y @tab
204 @item Non-rectangular loop nests @tab P
205       @tab Full support for C/C++, partial for Fortran
206            (@uref{https://gcc.gnu.org/PR110735,PR110735})
207 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
208 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
209       constructs @tab Y @tab
210 @item Collapse of associated loops that are imperfectly nested loops @tab Y @tab
211 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
212       @code{simd} construct @tab Y @tab
213 @item @code{atomic} constructs in @code{simd} @tab Y @tab
214 @item @code{loop} construct @tab Y @tab
215 @item @code{order(concurrent)} clause @tab Y @tab
216 @item @code{scan} directive and @code{in_scan} modifier for the
217       @code{reduction} clause @tab Y @tab
218 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
219 @item @code{in_reduction} clause on @code{target} constructs @tab P
220       @tab @code{nowait} only stub
221 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
222 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
223 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
224 @item @code{detach} clause to @code{task} construct @tab Y @tab
225 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
226 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
227       and @code{taskloop simd} constructs @tab Y @tab
228 @item @code{taskloop} construct cancelable by @code{cancel} construct
229       @tab Y @tab
230 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
231       @tab Y @tab
232 @item Predefined memory spaces, memory allocators, allocator traits
233       @tab Y @tab See also @ref{Memory allocation}
234 @item Memory management routines @tab Y @tab
235 @item @code{allocate} directive @tab P
236       @tab Only C for stack/automatic and Fortran for stack/automatic
237       and allocatable/pointer variables
238 @item @code{allocate} clause @tab P @tab Initial support
239 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
240 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
241 @item Implicit declare target directive @tab Y @tab
242 @item Discontiguous array section with @code{target update} construct
243       @tab N @tab
244 @item C/C++'s lvalue expressions in @code{to}, @code{from}
245       and @code{map} clauses @tab Y @tab
246 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
247 @item Nested @code{declare target} directive @tab Y @tab
248 @item Combined @code{master} constructs @tab Y @tab
249 @item @code{depend} clause on @code{taskwait} @tab Y @tab
250 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
251       @tab Y @tab
252 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
253 @item @code{depobj} construct and depend objects  @tab Y @tab
254 @item Lock hints were renamed to synchronization hints @tab Y @tab
255 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
256 @item Map-order clarifications @tab P @tab
257 @item @code{close} @emph{map-type-modifier} @tab Y @tab
258 @item Mapping C/C++ pointer variables and to assign the address of
259       device memory mapped by an array section @tab P @tab
260 @item Mapping of Fortran pointer and allocatable variables, including pointer
261       and allocatable components of variables
262       @tab P @tab Mapping of vars with allocatable components unsupported
263 @item @code{defaultmap} extensions @tab Y @tab
264 @item @code{declare mapper} directive @tab N @tab
265 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
266 @item Runtime routines and environment variables to display runtime thread
267       affinity information @tab Y @tab
268 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
269       routines @tab Y @tab
270 @item @code{omp_get_device_num} runtime routine @tab Y @tab
271 @item OMPT interface @tab N @tab
272 @item OMPD interface @tab N @tab
273 @end multitable
275 @unnumberedsubsec Other new OpenMP 5.0 features
277 @multitable @columnfractions .60 .10 .25
278 @headitem Description @tab Status @tab Comments
279 @item Supporting C++'s range-based for loop @tab Y @tab
280 @end multitable
283 @node OpenMP 5.1
284 @section OpenMP 5.1
286 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
288 @multitable @columnfractions .60 .10 .25
289 @headitem Description @tab Status @tab Comments
290 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
291 @item @code{omp_all_memory} reserved locator @tab Y @tab
292 @item @emph{target_device trait} in OpenMP Context @tab N @tab
293 @item @code{target_device} selector set in context selectors @tab N @tab
294 @item C/C++'s @code{declare variant} directive: elision support of
295       preprocessed code @tab N @tab
296 @item @code{declare variant}: new clauses @code{adjust_args} and
297       @code{append_args} @tab N @tab
298 @item @code{dispatch} construct @tab N @tab
299 @item device-specific ICV settings with environment variables @tab Y @tab
300 @item @code{assume} and @code{assumes} directives @tab Y @tab
301 @item @code{nothing} directive @tab Y @tab
302 @item @code{error} directive @tab Y @tab
303 @item @code{masked} construct @tab Y @tab
304 @item @code{scope} directive @tab Y @tab
305 @item Loop transformation constructs @tab N @tab
306 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
307       clauses of the @code{taskloop} construct @tab Y @tab
308 @item @code{align} clause in @code{allocate} directive @tab P
309       @tab Only C and Fortran (and not for static variables)
310 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
311 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
312 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
313 @item Iterators in @code{target update} motion clauses and @code{map}
314       clauses @tab N @tab
315 @item Indirect calls to the device version of a procedure or function in
316       @code{target} regions @tab Y @tab
317 @item @code{interop} directive @tab N @tab
318 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
319 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
320 @item Extensions to the @code{atomic} directive @tab Y @tab
321 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
322 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
323 @item @code{private} and @code{firstprivate} argument to @code{default}
324       clause in C and C++ @tab Y @tab
325 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
326 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
327       @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
328       routines @tab Y @tab
329 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
330 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
331       runtime routines @tab Y @tab
332 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
333 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
334       @code{omp_aligned_calloc} runtime routines @tab Y @tab
335 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
336       @code{omp_atv_default} changed @tab Y @tab
337 @item @code{omp_display_env} runtime routine @tab Y @tab
338 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
339 @item @code{ompt_sync_region_t} enum additions @tab N @tab
340 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
341       and @code{ompt_state_wait_barrier_teams} @tab N @tab
342 @item @code{ompt_callback_target_data_op_emi_t},
343       @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
344       and @code{ompt_callback_target_submit_emi_t} @tab N @tab
345 @item @code{ompt_callback_error_t} type @tab N @tab
346 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
347 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
348       variables @tab Y @tab
349 @end multitable
351 @unnumberedsubsec Other new OpenMP 5.1 features
353 @multitable @columnfractions .60 .10 .25
354 @headitem Description @tab Status @tab Comments
355 @item Support of strictly structured blocks in Fortran @tab Y @tab
356 @item Support of structured block sequences in C/C++ @tab Y @tab
357 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
358       clause @tab Y @tab
359 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
360 @item Pointer predetermined firstprivate getting initialized
361 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
362 @item For Fortran, diagnose placing declarative before/between @code{USE},
363       @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
364 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
365 @item @code{indirect} clause in @code{declare target} @tab Y @tab
366 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
367 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
368       clauses @tab Y @tab
369 @end multitable
372 @node OpenMP 5.2
373 @section OpenMP 5.2
375 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
377 @multitable @columnfractions .60 .10 .25
378 @headitem Description @tab Status @tab Comments
379 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
380       @tab Y @tab
381 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
382       namespaces @tab N/A
383       @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
384       sentinel as C/C++ pragma and C++ attributes are warned for with
385       @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
386       (enabled by default), respectively; for Fortran free-source code, there is
387       a warning enabled by default and, for fixed-source code, the @code{omx}
388       sentinel is warned for with @code{-Wsurprising} (enabled by
389       @code{-Wall}).  Unknown clauses are always rejected with an error.}
390 @item Clauses on @code{end} directive can be on directive @tab Y @tab
391 @item @code{destroy} clause with destroy-var argument on @code{depobj}
392       @tab Y @tab
393 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
394       @tab N @tab
395 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
396 @item Deprecation of minus operator for reductions @tab N @tab
397 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
398 @item @code{declare mapper} with iterator and @code{present} modifiers
399       @tab N @tab
400 @item If a matching mapped list item is not found in the data environment, the
401       pointer retains its original value @tab Y @tab
402 @item New @code{enter} clause as alias for @code{to} on declare target directive
403       @tab Y @tab
404 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
405 @item Extended list of directives permitted in Fortran pure procedures
406       @tab Y @tab
407 @item New @code{allocators} directive for Fortran @tab Y @tab
408 @item Deprecation of @code{allocate} directive for Fortran
409       allocatables/pointers @tab N @tab
410 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
411 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
412       @tab N @tab
413 @item Deprecation of traits array following the allocator_handle expression in
414       @code{uses_allocators} @tab N @tab
415 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
416       @tab N @tab
417 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
418 @item Deprecation of delimited form of @code{declare target} @tab N @tab
419 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
420 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
421       @tab Y @tab
422 @item @code{ompt_callback_work} @tab N @tab
423 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
424       @tab Y @tab
425 @item New @code{doacross} clause as alias for @code{depend} with
426       @code{source}/@code{sink} modifier @tab Y @tab
427 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
428       @tab N @tab
429 @item @code{omp_cur_iteration} keyword @tab Y @tab
430 @end multitable
432 @unnumberedsubsec Other new OpenMP 5.2 features
434 @multitable @columnfractions .60 .10 .25
435 @headitem Description @tab Status @tab Comments
436 @item For Fortran, optional comma between directive and clause @tab N @tab
437 @item Conforming device numbers and @code{omp_initial_device} and
438       @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
439 @item Initial value of @var{default-device-var} ICV with
440       @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
441 @item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
442 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
443       of the @code{interop} construct @tab N @tab
444 @item Invoke virtual member functions of C++ objects created on the host device
445       on other devices @tab N @tab
446 @end multitable
449 @node OpenMP Technical Report 12
450 @section OpenMP Technical Report 12
452 Technical Report (TR) 12 is the second preview for OpenMP 6.0.
454 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
455 @multitable @columnfractions .60 .10 .25
456 @item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
457       @tab N/A @tab Backward compatibility
458 @item Full support for C23 was added @tab P @tab
459 @item Full support for C++23 was added @tab P @tab
460 @item @code{_ALL} suffix to the device-scope environment variables
461       @tab P @tab Host device number wrongly accepted
462 @item @code{num_threads} now accepts a list @tab N @tab
463 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
464 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
465       @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
466 @item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
467 @item The @code{decl} attribute was added to the C++ attribute syntax
468       @tab Y @tab
469 @item The OpenMP directive syntax was extended to include C 23 attribute
470       specifiers @tab Y @tab
471 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
472 @item For Fortran, @emph{locator list} can be also function reference with
473       data pointer result @tab N @tab
474 @item Concept of @emph{assumed-size arrays} in C and C++
475       @tab N @tab
476 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
477 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
478       unlimited curly braces supported @tab N @tab
479 @item For Fortran, atomic compare with storing the comparison result
480       @tab N @tab
481 @item New @code{looprange} clause @tab N @tab
482 @item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
483       @tab N @tab
484 @item Support for inductions @tab N @tab
485 @item Implicit reduction identifiers of C++ classes
486       @tab N @tab
487 @item Change of the @emph{map-type} property from @emph{ultimate} to
488       @emph{default} @tab N @tab
489 @item @code{self} modifier to @code{map} and @code{self} as
490       @code{defaultmap} argument @tab N @tab
491 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
492       @tab N @tab
493 @item @code{groupprivate} directive @tab N @tab
494 @item @code{local} clause to @code{declare target} directive @tab N @tab
495 @item @code{part_size} allocator trait @tab N @tab
496 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
497       allocator traits
498       @tab N @tab
499 @item @code{access} allocator trait changes @tab N @tab
500 @item Extension of @code{interop} operation of @code{append_args}, allowing all
501       modifiers of the @code{init} clause
502       @tab N @tab
503 @item @code{interop} clause to @code{dispatch} @tab N @tab
504 @item @code{message} and @code{severity} clauses to @code{parallel} directive
505       @tab N @tab
506 @item @code{self} clause to @code{requires} directive @tab N @tab
507 @item @code{no_openmp_constructs} assumptions clause @tab N @tab
508 @item @code{reverse} loop-transformation construct @tab N @tab
509 @item @code{interchange} loop-transformation construct @tab N @tab
510 @item @code{fuse} loop-transformation construct @tab N @tab
511 @item @code{apply} code to loop-transforming constructs @tab N @tab
512 @item @code{omp_curr_progress_width} identifier @tab N @tab
513 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
514 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
515 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
516 @item @code{atomic} permitted in a construct with @code{order(concurrent)}
517       @tab N @tab
518 @item @code{workdistribute} directive for Fortran @tab N
519       @tab Renamed just after TR12; added in TR12 as @code{coexecute}
520 @item Fortran DO CONCURRENT as associated loop in a @code{loop} construct
521       @tab N @tab
522 @item @code{threadset} clause in task-generating constructs @tab N @tab
523 @item @code{nowait} clause with reverse-offload @code{target} directives
524       @tab N @tab
525 @item Boolean argument to @code{nowait} and @code{nogroup} may be non constant
526       @tab N @tab
527 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
528 @item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
529       @tab N @tab
530 @item @code{omp_target_memset} and @code{omp_target_memset_rect_async} routines
531       @tab N @tab
532 @item Routines for obtaining memory spaces/allocators for shared/device memory
533       @tab N @tab
534 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
535 @item @code{omp_get_submemspace} routine @tab N @tab
536 @item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
537       values in @code{ompt_target_data_op_t} enum @tab N @tab
538 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
539 @end multitable
541 @unnumberedsubsec Other new TR 12 features
542 @multitable @columnfractions .60 .10 .25
543 @item Canonical loop nest enclosed in (multiple) curly braces (C/C++) or BLOCK constructs (Fortran)
544       @tab N @tab
545 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
546 @item Mapping lambda captures @tab N @tab
547 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
548 @end multitable
552 @c ---------------------------------------------------------------------
553 @c OpenMP Runtime Library Routines
554 @c ---------------------------------------------------------------------
556 @node Runtime Library Routines
557 @chapter OpenMP Runtime Library Routines
559 The runtime routines described here are defined by Section 18 of the OpenMP
560 specification in version 5.2.
562 @menu
563 * Thread Team Routines::
564 * Thread Affinity Routines::
565 * Teams Region Routines::
566 * Tasking Routines::
567 * Resource Relinquishing Routines::
568 * Device Information Routines::
569 * Device Memory Routines::
570 * Lock Routines::
571 * Timing Routines::
572 * Event Routine::
573 @c * Interoperability Routines::
574 * Memory Management Routines::
575 @c * Tool Control Routine::
576 * Environment Display Routine::
577 @end menu
581 @node Thread Team Routines
582 @section Thread Team Routines
584 Routines controlling threads in the current contention group.
585 They have C linkage and do not throw exceptions.
587 @menu
588 * omp_set_num_threads::         Set upper team size limit
589 * omp_get_num_threads::         Size of the active team
590 * omp_get_max_threads::         Maximum number of threads of parallel region
591 * omp_get_thread_num::          Current thread ID
592 * omp_in_parallel::             Whether a parallel region is active
593 * omp_set_dynamic::             Enable/disable dynamic teams
594 * omp_get_dynamic::             Dynamic teams setting
595 * omp_get_cancellation::        Whether cancellation support is enabled
596 * omp_set_nested::              Enable/disable nested parallel regions
597 * omp_get_nested::              Nested parallel regions
598 * omp_set_schedule::            Set the runtime scheduling method
599 * omp_get_schedule::            Obtain the runtime scheduling method
600 * omp_get_teams_thread_limit::  Maximum number of threads imposed by teams
601 * omp_get_supported_active_levels:: Maximum number of active regions supported
602 * omp_set_max_active_levels::   Limits the number of active parallel regions
603 * omp_get_max_active_levels::   Current maximum number of active regions
604 * omp_get_level::               Number of parallel regions
605 * omp_get_ancestor_thread_num:: Ancestor thread ID
606 * omp_get_team_size::           Number of threads in a team
607 * omp_get_active_level::        Number of active parallel regions
608 @end menu
612 @node omp_set_num_threads
613 @subsection @code{omp_set_num_threads} -- Set upper team size limit
614 @table @asis
615 @item @emph{Description}:
616 Specifies the number of threads used by default in subsequent parallel
617 sections, if those do not specify a @code{num_threads} clause.  The
618 argument of @code{omp_set_num_threads} shall be a positive integer.
620 @item @emph{C/C++}:
621 @multitable @columnfractions .20 .80
622 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
623 @end multitable
625 @item @emph{Fortran}:
626 @multitable @columnfractions .20 .80
627 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
628 @item                   @tab @code{integer, intent(in) :: num_threads}
629 @end multitable
631 @item @emph{See also}:
632 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
634 @item @emph{Reference}:
635 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
636 @end table
640 @node omp_get_num_threads
641 @subsection @code{omp_get_num_threads} -- Size of the active team
642 @table @asis
643 @item @emph{Description}:
644 Returns the number of threads in the current team.  In a sequential section of
645 the program @code{omp_get_num_threads} returns 1.
647 The default team size may be initialized at startup by the
648 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
649 of the current team may be set either by the @code{NUM_THREADS}
650 clause or by @code{omp_set_num_threads}.  If none of the above were
651 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
652 one thread per CPU online is used.
654 @item @emph{C/C++}:
655 @multitable @columnfractions .20 .80
656 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
657 @end multitable
659 @item @emph{Fortran}:
660 @multitable @columnfractions .20 .80
661 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
662 @end multitable
664 @item @emph{See also}:
665 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
667 @item @emph{Reference}:
668 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
669 @end table
673 @node omp_get_max_threads
674 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
675 @table @asis
676 @item @emph{Description}:
677 Return the maximum number of threads used for the current parallel region
678 that does not use the clause @code{num_threads}.
680 @item @emph{C/C++}:
681 @multitable @columnfractions .20 .80
682 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
683 @end multitable
685 @item @emph{Fortran}:
686 @multitable @columnfractions .20 .80
687 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
688 @end multitable
690 @item @emph{See also}:
691 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
693 @item @emph{Reference}:
694 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
695 @end table
699 @node omp_get_thread_num
700 @subsection @code{omp_get_thread_num} -- Current thread ID
701 @table @asis
702 @item @emph{Description}:
703 Returns a unique thread identification number within the current team.
704 In a sequential parts of the program, @code{omp_get_thread_num}
705 always returns 0.  In parallel regions the return value varies
706 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
707 value of the primary thread of a team is always 0.
709 @item @emph{C/C++}:
710 @multitable @columnfractions .20 .80
711 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
712 @end multitable
714 @item @emph{Fortran}:
715 @multitable @columnfractions .20 .80
716 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
717 @end multitable
719 @item @emph{See also}:
720 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
722 @item @emph{Reference}:
723 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
724 @end table
728 @node omp_in_parallel
729 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
730 @table @asis
731 @item @emph{Description}:
732 This function returns @code{true} if currently running in parallel,
733 @code{false} otherwise.  Here, @code{true} and @code{false} represent
734 their language-specific counterparts.
736 @item @emph{C/C++}:
737 @multitable @columnfractions .20 .80
738 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
739 @end multitable
741 @item @emph{Fortran}:
742 @multitable @columnfractions .20 .80
743 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
744 @end multitable
746 @item @emph{Reference}:
747 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
748 @end table
751 @node omp_set_dynamic
752 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
753 @table @asis
754 @item @emph{Description}:
755 Enable or disable the dynamic adjustment of the number of threads 
756 within a team.  The function takes the language-specific equivalent
757 of @code{true} and @code{false}, where @code{true} enables dynamic 
758 adjustment of team sizes and @code{false} disables it.
760 @item @emph{C/C++}:
761 @multitable @columnfractions .20 .80
762 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
763 @end multitable
765 @item @emph{Fortran}:
766 @multitable @columnfractions .20 .80
767 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
768 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
769 @end multitable
771 @item @emph{See also}:
772 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
774 @item @emph{Reference}:
775 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
776 @end table
780 @node omp_get_dynamic
781 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
782 @table @asis
783 @item @emph{Description}:
784 This function returns @code{true} if enabled, @code{false} otherwise. 
785 Here, @code{true} and @code{false} represent their language-specific 
786 counterparts.
788 The dynamic team setting may be initialized at startup by the 
789 @env{OMP_DYNAMIC} environment variable or at runtime using
790 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
791 disabled by default.
793 @item @emph{C/C++}:
794 @multitable @columnfractions .20 .80
795 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
796 @end multitable
798 @item @emph{Fortran}:
799 @multitable @columnfractions .20 .80
800 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
801 @end multitable
803 @item @emph{See also}:
804 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
806 @item @emph{Reference}:
807 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
808 @end table
812 @node omp_get_cancellation
813 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
814 @table @asis
815 @item @emph{Description}:
816 This function returns @code{true} if cancellation is activated, @code{false}
817 otherwise.  Here, @code{true} and @code{false} represent their language-specific
818 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
819 deactivated.
821 @item @emph{C/C++}:
822 @multitable @columnfractions .20 .80
823 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
824 @end multitable
826 @item @emph{Fortran}:
827 @multitable @columnfractions .20 .80
828 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
829 @end multitable
831 @item @emph{See also}:
832 @ref{OMP_CANCELLATION}
834 @item @emph{Reference}:
835 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
836 @end table
840 @node omp_set_nested
841 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
842 @table @asis
843 @item @emph{Description}:
844 Enable or disable nested parallel regions, i.e., whether team members
845 are allowed to create new teams.  The function takes the language-specific
846 equivalent of @code{true} and @code{false}, where @code{true} enables 
847 dynamic adjustment of team sizes and @code{false} disables it.
849 Enabling nested parallel regions also sets the maximum number of
850 active nested regions to the maximum supported.  Disabling nested parallel
851 regions sets the maximum number of active nested regions to one.
853 Note that the @code{omp_set_nested} API routine was deprecated
854 in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
856 @item @emph{C/C++}:
857 @multitable @columnfractions .20 .80
858 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
859 @end multitable
861 @item @emph{Fortran}:
862 @multitable @columnfractions .20 .80
863 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
864 @item                   @tab @code{logical, intent(in) :: nested}
865 @end multitable
867 @item @emph{See also}:
868 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
869 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
871 @item @emph{Reference}:
872 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
873 @end table
877 @node omp_get_nested
878 @subsection @code{omp_get_nested} -- Nested parallel regions
879 @table @asis
880 @item @emph{Description}:
881 This function returns @code{true} if nested parallel regions are
882 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
883 represent their language-specific counterparts.
885 The state of nested parallel regions at startup depends on several
886 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
887 and is set to greater than one, then nested parallel regions will be
888 enabled.  If not defined, then the value of the @env{OMP_NESTED}
889 environment variable will be followed if defined.  If neither are
890 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
891 are defined with a list of more than one value, then nested parallel
892 regions are enabled.  If none of these are defined, then nested parallel
893 regions are disabled by default.
895 Nested parallel regions can be enabled or disabled at runtime using
896 @code{omp_set_nested}, or by setting the maximum number of nested
897 regions with @code{omp_set_max_active_levels} to one to disable, or
898 above one to enable.
900 Note that the @code{omp_get_nested} API routine was deprecated
901 in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
903 @item @emph{C/C++}:
904 @multitable @columnfractions .20 .80
905 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
906 @end multitable
908 @item @emph{Fortran}:
909 @multitable @columnfractions .20 .80
910 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
911 @end multitable
913 @item @emph{See also}:
914 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
915 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
917 @item @emph{Reference}:
918 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
919 @end table
923 @node omp_set_schedule
924 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
925 @table @asis
926 @item @emph{Description}:
927 Sets the runtime scheduling method.  The @var{kind} argument can have the
928 value @code{omp_sched_static}, @code{omp_sched_dynamic},
929 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
930 @code{omp_sched_auto}, the chunk size is set to the value of
931 @var{chunk_size} if positive, or to the default value if zero or negative.
932 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
934 @item @emph{C/C++}
935 @multitable @columnfractions .20 .80
936 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
937 @end multitable
939 @item @emph{Fortran}:
940 @multitable @columnfractions .20 .80
941 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
942 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
943 @item                   @tab @code{integer chunk_size}
944 @end multitable
946 @item @emph{See also}:
947 @ref{omp_get_schedule}
948 @ref{OMP_SCHEDULE}
950 @item @emph{Reference}:
951 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
952 @end table
956 @node omp_get_schedule
957 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
958 @table @asis
959 @item @emph{Description}:
960 Obtain the runtime scheduling method.  The @var{kind} argument is set to
961 @code{omp_sched_static}, @code{omp_sched_dynamic},
962 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
963 @var{chunk_size}, is set to the chunk size.
965 @item @emph{C/C++}
966 @multitable @columnfractions .20 .80
967 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
968 @end multitable
970 @item @emph{Fortran}:
971 @multitable @columnfractions .20 .80
972 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
973 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
974 @item                   @tab @code{integer chunk_size}
975 @end multitable
977 @item @emph{See also}:
978 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
980 @item @emph{Reference}:
981 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
982 @end table
985 @node omp_get_teams_thread_limit
986 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
987 @table @asis
988 @item @emph{Description}:
989 Return the maximum number of threads that are able to participate in
990 each team created by a teams construct.
992 @item @emph{C/C++}:
993 @multitable @columnfractions .20 .80
994 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
995 @end multitable
997 @item @emph{Fortran}:
998 @multitable @columnfractions .20 .80
999 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1000 @end multitable
1002 @item @emph{See also}:
1003 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1005 @item @emph{Reference}:
1006 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1007 @end table
1011 @node omp_get_supported_active_levels
1012 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1013 @table @asis
1014 @item @emph{Description}:
1015 This function returns the maximum number of nested, active parallel regions
1016 supported by this implementation.
1018 @item @emph{C/C++}
1019 @multitable @columnfractions .20 .80
1020 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1021 @end multitable
1023 @item @emph{Fortran}:
1024 @multitable @columnfractions .20 .80
1025 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1026 @end multitable
1028 @item @emph{See also}:
1029 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1031 @item @emph{Reference}:
1032 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1033 @end table
1037 @node omp_set_max_active_levels
1038 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1039 @table @asis
1040 @item @emph{Description}:
1041 This function limits the maximum allowed number of nested, active
1042 parallel regions.  @var{max_levels} must be less or equal to
1043 the value returned by @code{omp_get_supported_active_levels}.
1045 @item @emph{C/C++}
1046 @multitable @columnfractions .20 .80
1047 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1048 @end multitable
1050 @item @emph{Fortran}:
1051 @multitable @columnfractions .20 .80
1052 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1053 @item                   @tab @code{integer max_levels}
1054 @end multitable
1056 @item @emph{See also}:
1057 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1058 @ref{omp_get_supported_active_levels}
1060 @item @emph{Reference}:
1061 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1062 @end table
1066 @node omp_get_max_active_levels
1067 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1068 @table @asis
1069 @item @emph{Description}:
1070 This function obtains the maximum allowed number of nested, active parallel regions.
1072 @item @emph{C/C++}
1073 @multitable @columnfractions .20 .80
1074 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1075 @end multitable
1077 @item @emph{Fortran}:
1078 @multitable @columnfractions .20 .80
1079 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1080 @end multitable
1082 @item @emph{See also}:
1083 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1085 @item @emph{Reference}:
1086 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1087 @end table
1090 @node omp_get_level
1091 @subsection @code{omp_get_level} -- Obtain the current nesting level
1092 @table @asis
1093 @item @emph{Description}:
1094 This function returns the nesting level for the parallel blocks,
1095 which enclose the calling call.
1097 @item @emph{C/C++}
1098 @multitable @columnfractions .20 .80
1099 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1100 @end multitable
1102 @item @emph{Fortran}:
1103 @multitable @columnfractions .20 .80
1104 @item @emph{Interface}: @tab @code{integer function omp_level()}
1105 @end multitable
1107 @item @emph{See also}:
1108 @ref{omp_get_active_level}
1110 @item @emph{Reference}:
1111 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1112 @end table
1116 @node omp_get_ancestor_thread_num
1117 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1118 @table @asis
1119 @item @emph{Description}:
1120 This function returns the thread identification number for the given
1121 nesting level of the current thread.  For values of @var{level} outside
1122 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1123 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1125 @item @emph{C/C++}
1126 @multitable @columnfractions .20 .80
1127 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1128 @end multitable
1130 @item @emph{Fortran}:
1131 @multitable @columnfractions .20 .80
1132 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1133 @item                   @tab @code{integer level}
1134 @end multitable
1136 @item @emph{See also}:
1137 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1139 @item @emph{Reference}:
1140 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1141 @end table
1145 @node omp_get_team_size
1146 @subsection @code{omp_get_team_size} -- Number of threads in a team
1147 @table @asis
1148 @item @emph{Description}:
1149 This function returns the number of threads in a thread team to which
1150 either the current thread or its ancestor belongs.  For values of @var{level}
1151 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1152 1 is returned, and for @code{omp_get_level}, the result is identical
1153 to @code{omp_get_num_threads}.
1155 @item @emph{C/C++}:
1156 @multitable @columnfractions .20 .80
1157 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1158 @end multitable
1160 @item @emph{Fortran}:
1161 @multitable @columnfractions .20 .80
1162 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1163 @item                   @tab @code{integer level}
1164 @end multitable
1166 @item @emph{See also}:
1167 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1169 @item @emph{Reference}:
1170 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1171 @end table
1175 @node omp_get_active_level
1176 @subsection @code{omp_get_active_level} -- Number of parallel regions
1177 @table @asis
1178 @item @emph{Description}:
1179 This function returns the nesting level for the active parallel blocks,
1180 which enclose the calling call.
1182 @item @emph{C/C++}
1183 @multitable @columnfractions .20 .80
1184 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1185 @end multitable
1187 @item @emph{Fortran}:
1188 @multitable @columnfractions .20 .80
1189 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1190 @end multitable
1192 @item @emph{See also}:
1193 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1195 @item @emph{Reference}:
1196 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1197 @end table
1201 @node Thread Affinity Routines
1202 @section Thread Affinity Routines
1204 Routines controlling and accessing thread-affinity policies.
1205 They have C linkage and do not throw exceptions.
1207 @menu
1208 * omp_get_proc_bind::           Whether threads may be moved between CPUs
1209 @c * omp_get_num_places:: <fixme>
1210 @c * omp_get_place_num_procs:: <fixme>
1211 @c * omp_get_place_proc_ids:: <fixme>
1212 @c * omp_get_place_num:: <fixme>
1213 @c * omp_get_partition_num_places:: <fixme>
1214 @c * omp_get_partition_place_nums:: <fixme>
1215 @c * omp_set_affinity_format:: <fixme>
1216 @c * omp_get_affinity_format:: <fixme>
1217 @c * omp_display_affinity:: <fixme>
1218 @c * omp_capture_affinity:: <fixme>
1219 @end menu
1223 @node omp_get_proc_bind
1224 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1225 @table @asis
1226 @item @emph{Description}:
1227 This functions returns the currently active thread affinity policy, which is
1228 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
1229 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1230 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1231 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1233 @item @emph{C/C++}:
1234 @multitable @columnfractions .20 .80
1235 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1236 @end multitable
1238 @item @emph{Fortran}:
1239 @multitable @columnfractions .20 .80
1240 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1241 @end multitable
1243 @item @emph{See also}:
1244 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1246 @item @emph{Reference}:
1247 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1248 @end table
1252 @node Teams Region Routines
1253 @section Teams Region Routines
1255 Routines controlling the league of teams that are executed in a @code{teams}
1256 region.  They have C linkage and do not throw exceptions.
1258 @menu
1259 * omp_get_num_teams::           Number of teams
1260 * omp_get_team_num::            Get team number
1261 * omp_set_num_teams::           Set upper teams limit for teams region
1262 * omp_get_max_teams::           Maximum number of teams for teams region
1263 * omp_set_teams_thread_limit::  Set upper thread limit for teams construct
1264 * omp_get_thread_limit::        Maximum number of threads
1265 @end menu
1269 @node omp_get_num_teams
1270 @subsection @code{omp_get_num_teams} -- Number of teams
1271 @table @asis
1272 @item @emph{Description}:
1273 Returns the number of teams in the current team region.
1275 @item @emph{C/C++}:
1276 @multitable @columnfractions .20 .80
1277 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1278 @end multitable
1280 @item @emph{Fortran}:
1281 @multitable @columnfractions .20 .80
1282 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1283 @end multitable
1285 @item @emph{Reference}:
1286 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1287 @end table
1291 @node omp_get_team_num
1292 @subsection @code{omp_get_team_num} -- Get team number
1293 @table @asis
1294 @item @emph{Description}:
1295 Returns the team number of the calling thread.
1297 @item @emph{C/C++}:
1298 @multitable @columnfractions .20 .80
1299 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1300 @end multitable
1302 @item @emph{Fortran}:
1303 @multitable @columnfractions .20 .80
1304 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1305 @end multitable
1307 @item @emph{Reference}:
1308 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1309 @end table
1313 @node omp_set_num_teams
1314 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1315 @table @asis
1316 @item @emph{Description}:
1317 Specifies the upper bound for number of teams created by the teams construct
1318 which does not specify a @code{num_teams} clause.  The
1319 argument of @code{omp_set_num_teams} shall be a positive integer.
1321 @item @emph{C/C++}:
1322 @multitable @columnfractions .20 .80
1323 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1324 @end multitable
1326 @item @emph{Fortran}:
1327 @multitable @columnfractions .20 .80
1328 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1329 @item                   @tab @code{integer, intent(in) :: num_teams}
1330 @end multitable
1332 @item @emph{See also}:
1333 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1335 @item @emph{Reference}:
1336 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1337 @end table
1341 @node omp_get_max_teams
1342 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1343 @table @asis
1344 @item @emph{Description}:
1345 Return the maximum number of teams used for the teams region
1346 that does not use the clause @code{num_teams}.
1348 @item @emph{C/C++}:
1349 @multitable @columnfractions .20 .80
1350 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1351 @end multitable
1353 @item @emph{Fortran}:
1354 @multitable @columnfractions .20 .80
1355 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1356 @end multitable
1358 @item @emph{See also}:
1359 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1361 @item @emph{Reference}:
1362 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1363 @end table
1367 @node omp_set_teams_thread_limit
1368 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1369 @table @asis
1370 @item @emph{Description}:
1371 Specifies the upper bound for number of threads that are available
1372 for each team created by the teams construct which does not specify a
1373 @code{thread_limit} clause.  The argument of
1374 @code{omp_set_teams_thread_limit} shall be a positive integer.
1376 @item @emph{C/C++}:
1377 @multitable @columnfractions .20 .80
1378 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1379 @end multitable
1381 @item @emph{Fortran}:
1382 @multitable @columnfractions .20 .80
1383 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1384 @item                   @tab @code{integer, intent(in) :: thread_limit}
1385 @end multitable
1387 @item @emph{See also}:
1388 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1390 @item @emph{Reference}:
1391 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1392 @end table
1396 @node omp_get_thread_limit
1397 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1398 @table @asis
1399 @item @emph{Description}:
1400 Return the maximum number of threads of the program.
1402 @item @emph{C/C++}:
1403 @multitable @columnfractions .20 .80
1404 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1405 @end multitable
1407 @item @emph{Fortran}:
1408 @multitable @columnfractions .20 .80
1409 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1410 @end multitable
1412 @item @emph{See also}:
1413 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1415 @item @emph{Reference}:
1416 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1417 @end table
1421 @node Tasking Routines
1422 @section Tasking Routines
1424 Routines relating to explicit tasks.
1425 They have C linkage and do not throw exceptions.
1427 @menu
1428 * omp_get_max_task_priority::   Maximum task priority value that can be set
1429 * omp_in_explicit_task::        Whether a given task is an explicit task
1430 * omp_in_final::                Whether in final or included task region
1431 @c * omp_is_free_agent:: <fixme>/TR12
1432 @c * omp_ancestor_is_free_agent:: <fixme>/TR12
1433 @end menu
1437 @node omp_get_max_task_priority
1438 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1439 that can be set for tasks.
1440 @table @asis
1441 @item @emph{Description}:
1442 This function obtains the maximum allowed priority number for tasks.
1444 @item @emph{C/C++}
1445 @multitable @columnfractions .20 .80
1446 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1447 @end multitable
1449 @item @emph{Fortran}:
1450 @multitable @columnfractions .20 .80
1451 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1452 @end multitable
1454 @item @emph{Reference}:
1455 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1456 @end table
1460 @node omp_in_explicit_task
1461 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1462 @table @asis
1463 @item @emph{Description}:
1464 The function returns the @var{explicit-task-var} ICV; it returns true when the
1465 encountering task was generated by a task-generating construct such as
1466 @code{target}, @code{task} or @code{taskloop}.  Otherwise, the encountering task
1467 is in an implicit task region such as generated by the implicit or explicit
1468 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1470 @item @emph{C/C++}
1471 @multitable @columnfractions .20 .80
1472 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1473 @end multitable
1475 @item @emph{Fortran}:
1476 @multitable @columnfractions .20 .80
1477 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1478 @end multitable
1480 @item @emph{Reference}:
1481 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1482 @end table
1486 @node omp_in_final
1487 @subsection @code{omp_in_final} -- Whether in final or included task region
1488 @table @asis
1489 @item @emph{Description}:
1490 This function returns @code{true} if currently running in a final
1491 or included task region, @code{false} otherwise.  Here, @code{true}
1492 and @code{false} represent their language-specific counterparts.
1494 @item @emph{C/C++}:
1495 @multitable @columnfractions .20 .80
1496 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1497 @end multitable
1499 @item @emph{Fortran}:
1500 @multitable @columnfractions .20 .80
1501 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1502 @end multitable
1504 @item @emph{Reference}:
1505 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1506 @end table
1510 @node Resource Relinquishing Routines
1511 @section Resource Relinquishing Routines
1513 Routines releasing resources used by the OpenMP runtime.
1514 They have C linkage and do not throw exceptions.
1516 @menu
1517 * omp_pause_resource:: Release OpenMP resources on a device
1518 * omp_pause_resource_all:: Release OpenMP resources on all devices
1519 @end menu
1523 @node omp_pause_resource
1524 @subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1525 @table @asis
1526 @item @emph{Description}:
1527 Free resources used by the OpenMP program and the runtime library on and for the
1528 device specified by @var{device_num}; on success, zero is returned and non-zero
1529 otherwise.
1531 The value of @var{device_num} must be a conforming device number.  The routine
1532 may not be called from within any explicit region and all explicit threads that
1533 do not bind to the implicit parallel region have finalized execution.
1535 @item @emph{C/C++}:
1536 @multitable @columnfractions .20 .80
1537 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1538 @end multitable
1540 @item @emph{Fortran}:
1541 @multitable @columnfractions .20 .80
1542 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1543 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1544 @item                   @tab @code{integer device_num}
1545 @end multitable
1547 @item @emph{Reference}:
1548 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1549 @end table
1553 @node omp_pause_resource_all
1554 @subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1555 @table @asis
1556 @item @emph{Description}:
1557 Free resources used by the OpenMP program and the runtime library on all devices,
1558 including the host. On success, zero is returned and non-zero otherwise.
1560 The routine may not be called from within any explicit region and all explicit
1561 threads that do not bind to the implicit parallel region have finalized execution.
1563 @item @emph{C/C++}:
1564 @multitable @columnfractions .20 .80
1565 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1566 @end multitable
1568 @item @emph{Fortran}:
1569 @multitable @columnfractions .20 .80
1570 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1571 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1572 @end multitable
1574 @item @emph{See also}:
1575 @ref{omp_pause_resource}
1577 @item @emph{Reference}:
1578 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1579 @end table
1583 @node Device Information Routines
1584 @section Device Information Routines
1586 Routines related to devices available to an OpenMP program.
1587 They have C linkage and do not throw exceptions.
1589 @menu
1590 * omp_get_num_procs::           Number of processors online
1591 @c * omp_get_max_progress_width:: <fixme>/TR11
1592 * omp_set_default_device::      Set the default device for target regions
1593 * omp_get_default_device::      Get the default device for target regions
1594 * omp_get_num_devices::         Number of target devices
1595 * omp_get_device_num::          Get device that current thread is running on
1596 * omp_is_initial_device::       Whether executing on the host device
1597 * omp_get_initial_device::      Device number of host device
1598 @end menu
1602 @node omp_get_num_procs
1603 @subsection @code{omp_get_num_procs} -- Number of processors online
1604 @table @asis
1605 @item @emph{Description}:
1606 Returns the number of processors online on that device.
1608 @item @emph{C/C++}:
1609 @multitable @columnfractions .20 .80
1610 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1611 @end multitable
1613 @item @emph{Fortran}:
1614 @multitable @columnfractions .20 .80
1615 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1616 @end multitable
1618 @item @emph{Reference}:
1619 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1620 @end table
1624 @node omp_set_default_device
1625 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1626 @table @asis
1627 @item @emph{Description}:
1628 Set the default device for target regions without device clause.  The argument
1629 shall be a nonnegative device number.
1631 @item @emph{C/C++}:
1632 @multitable @columnfractions .20 .80
1633 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1634 @end multitable
1636 @item @emph{Fortran}:
1637 @multitable @columnfractions .20 .80
1638 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1639 @item                   @tab @code{integer device_num}
1640 @end multitable
1642 @item @emph{See also}:
1643 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1645 @item @emph{Reference}:
1646 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1647 @end table
1651 @node omp_get_default_device
1652 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1653 @table @asis
1654 @item @emph{Description}:
1655 Get the default device for target regions without device clause.
1657 @item @emph{C/C++}:
1658 @multitable @columnfractions .20 .80
1659 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1660 @end multitable
1662 @item @emph{Fortran}:
1663 @multitable @columnfractions .20 .80
1664 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1665 @end multitable
1667 @item @emph{See also}:
1668 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
1670 @item @emph{Reference}:
1671 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1672 @end table
1676 @node omp_get_num_devices
1677 @subsection @code{omp_get_num_devices} -- Number of target devices
1678 @table @asis
1679 @item @emph{Description}:
1680 Returns the number of target devices.
1682 @item @emph{C/C++}:
1683 @multitable @columnfractions .20 .80
1684 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1685 @end multitable
1687 @item @emph{Fortran}:
1688 @multitable @columnfractions .20 .80
1689 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1690 @end multitable
1692 @item @emph{Reference}:
1693 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1694 @end table
1698 @node omp_get_device_num
1699 @subsection @code{omp_get_device_num} -- Return device number of current device
1700 @table @asis
1701 @item @emph{Description}:
1702 This function returns a device number that represents the device that the
1703 current thread is executing on. For OpenMP 5.0, this must be equal to the
1704 value returned by the @code{omp_get_initial_device} function when called
1705 from the host.
1707 @item @emph{C/C++}
1708 @multitable @columnfractions .20 .80
1709 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1710 @end multitable
1712 @item @emph{Fortran}:
1713 @multitable @columnfractions .20 .80
1714 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1715 @end multitable
1717 @item @emph{See also}:
1718 @ref{omp_get_initial_device}
1720 @item @emph{Reference}:
1721 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1722 @end table
1726 @node omp_is_initial_device
1727 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1728 @table @asis
1729 @item @emph{Description}:
1730 This function returns @code{true} if currently running on the host device,
1731 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1732 their language-specific counterparts.
1734 @item @emph{C/C++}:
1735 @multitable @columnfractions .20 .80
1736 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1737 @end multitable
1739 @item @emph{Fortran}:
1740 @multitable @columnfractions .20 .80
1741 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1742 @end multitable
1744 @item @emph{Reference}:
1745 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1746 @end table
1750 @node omp_get_initial_device
1751 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1752 @table @asis
1753 @item @emph{Description}:
1754 This function returns a device number that represents the host device.
1755 For OpenMP 5.1, this must be equal to the value returned by the
1756 @code{omp_get_num_devices} function.
1758 @item @emph{C/C++}
1759 @multitable @columnfractions .20 .80
1760 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1761 @end multitable
1763 @item @emph{Fortran}:
1764 @multitable @columnfractions .20 .80
1765 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1766 @end multitable
1768 @item @emph{See also}:
1769 @ref{omp_get_num_devices}
1771 @item @emph{Reference}:
1772 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1773 @end table
1777 @node Device Memory Routines
1778 @section Device Memory Routines
1780 Routines related to memory allocation and managing corresponding
1781 pointers on devices. They have C linkage and do not throw exceptions.
1783 @menu
1784 * omp_target_alloc:: Allocate device memory
1785 * omp_target_free:: Free device memory
1786 * omp_target_is_present:: Check whether storage is mapped
1787 * omp_target_is_accessible:: Check whether memory is device accessible
1788 * omp_target_memcpy:: Copy data between devices
1789 * omp_target_memcpy_async:: Copy data between devices asynchronously
1790 * omp_target_memcpy_rect:: Copy a subvolume of data between devices
1791 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
1792 @c * omp_target_memset:: <fixme>/TR12
1793 @c * omp_target_memset_async:: <fixme>/TR12
1794 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
1795 * omp_target_disassociate_ptr:: Remove device--host pointer association
1796 * omp_get_mapped_ptr:: Return device pointer to a host pointer
1797 @end menu
1801 @node omp_target_alloc
1802 @subsection @code{omp_target_alloc} -- Allocate device memory
1803 @table @asis
1804 @item @emph{Description}:
1805 This routine allocates @var{size} bytes of memory in the device environment
1806 associated with the device number @var{device_num}.  If successful, a device
1807 pointer is returned, otherwise a null pointer.
1809 In GCC, when the device is the host or the device shares memory with the host,
1810 the memory is allocated on the host; in that case, when @var{size} is zero,
1811 either NULL or a unique pointer value that can later be successfully passed to
1812 @code{omp_target_free} is returned.  When the allocation is not performed on
1813 the host, a null pointer is returned when @var{size} is zero; in that case,
1814 additionally a diagnostic might be printed to standard error (stderr).
1816 Running this routine in a @code{target} region except on the initial device
1817 is not supported.
1819 @item @emph{C/C++}
1820 @multitable @columnfractions .20 .80
1821 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
1822 @end multitable
1824 @item @emph{Fortran}:
1825 @multitable @columnfractions .20 .80
1826 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
1827 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
1828 @item                   @tab @code{integer(c_size_t), value :: size}
1829 @item                   @tab @code{integer(c_int), value :: device_num}
1830 @end multitable
1832 @item @emph{See also}:
1833 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
1835 @item @emph{Reference}:
1836 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
1837 @end table
1841 @node omp_target_free
1842 @subsection @code{omp_target_free} -- Free device memory
1843 @table @asis
1844 @item @emph{Description}:
1845 This routine frees memory allocated by the @code{omp_target_alloc} routine.
1846 The @var{device_ptr} argument must be either a null pointer or a device pointer
1847 returned by @code{omp_target_alloc} for the specified @code{device_num}.  The
1848 device number @var{device_num} must be a conforming device number.
1850 Running this routine in a @code{target} region except on the initial device
1851 is not supported.
1853 @item @emph{C/C++}
1854 @multitable @columnfractions .20 .80
1855 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
1856 @end multitable
1858 @item @emph{Fortran}:
1859 @multitable @columnfractions .20 .80
1860 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
1861 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1862 @item                   @tab @code{type(c_ptr), value :: device_ptr}
1863 @item                   @tab @code{integer(c_int), value :: device_num}
1864 @end multitable
1866 @item @emph{See also}:
1867 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
1869 @item @emph{Reference}:
1870 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
1871 @end table
1875 @node omp_target_is_present
1876 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
1877 @table @asis
1878 @item @emph{Description}:
1879 This routine tests whether storage, identified by the host pointer @var{ptr}
1880 is mapped to the device specified by @var{device_num}.  If so, it returns
1881 a nonzero value and otherwise zero.
1883 In GCC, this includes self mapping such that @code{omp_target_is_present}
1884 returns @emph{true} when @var{device_num} specifies the host or when the host
1885 and the device share memory.  If @var{ptr} is a null pointer, @var{true} is
1886 returned and if @var{device_num} is an invalid device number, @var{false} is
1887 returned.
1889 If those conditions do not apply, @emph{true} is returned if the association has
1890 been established by an explicit or implicit @code{map} clause, the
1891 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
1892 routine.
1894 Running this routine in a @code{target} region except on the initial device
1895 is not supported.
1897 @item @emph{C/C++}
1898 @multitable @columnfractions .20 .80
1899 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
1900 @item                   @tab @code{                          int device_num)}
1901 @end multitable
1903 @item @emph{Fortran}:
1904 @multitable @columnfractions .20 .80
1905 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
1906 @item                   @tab @code{    device_num) bind(C)}
1907 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1908 @item                   @tab @code{type(c_ptr), value :: ptr}
1909 @item                   @tab @code{integer(c_int), value :: device_num}
1910 @end multitable
1912 @item @emph{See also}:
1913 @ref{omp_target_associate_ptr}
1915 @item @emph{Reference}:
1916 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
1917 @end table
1921 @node omp_target_is_accessible
1922 @subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
1923 @table @asis
1924 @item @emph{Description}:
1925 This routine tests whether memory, starting at the address given by @var{ptr}
1926 and extending @var{size} bytes, is accessibly on the device specified by
1927 @var{device_num}.  If so, it returns a nonzero value and otherwise zero.
1929 The address given by @var{ptr} is interpreted to be in the address space of
1930 the device and @var{size} must be positive.
1932 Note that GCC's current implementation assumes that @var{ptr} is a valid host
1933 pointer. Therefore, all addresses given by @var{ptr} are assumed to be
1934 accessible on the initial device. And, to err on the safe side, this memory
1935 is only available on a non-host device that can access all host memory
1936 ([uniform] shared memory access).
1938 Running this routine in a @code{target} region except on the initial device
1939 is not supported.
1941 @item @emph{C/C++}
1942 @multitable @columnfractions .20 .80
1943 @item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
1944 @item                   @tab @code{                             size_t size,}
1945 @item                   @tab @code{                             int device_num)}
1946 @end multitable
1948 @item @emph{Fortran}:
1949 @multitable @columnfractions .20 .80
1950 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
1951 @item                   @tab @code{    size, device_num) bind(C)}
1952 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
1953 @item                   @tab @code{type(c_ptr), value :: ptr}
1954 @item                   @tab @code{integer(c_size_t), value :: size}
1955 @item                   @tab @code{integer(c_int), value :: device_num}
1956 @end multitable
1958 @item @emph{See also}:
1959 @ref{omp_target_associate_ptr}
1961 @item @emph{Reference}:
1962 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
1963 @end table
1967 @node omp_target_memcpy
1968 @subsection @code{omp_target_memcpy} -- Copy data between devices
1969 @table @asis
1970 @item @emph{Description}:
1971 This routine copies @var{length} of bytes of data from the device
1972 identified by device number @var{src_device_num} to device @var{dst_device_num}.
1973 The data is copied from the source device from the address provided by
1974 @var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
1975 device's @var{dst} address shifted by @var{dst_offset}.  The routine returns
1976 zero on success and non-zero otherwise.
1978 Running this routine in a @code{target} region except on the initial device
1979 is not supported.
1981 @item @emph{C/C++}
1982 @multitable @columnfractions .20 .80
1983 @item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
1984 @item                   @tab @code{                           const void *src,}
1985 @item                   @tab @code{                           size_t length,}
1986 @item                   @tab @code{                           size_t dst_offset,}
1987 @item                   @tab @code{                           size_t src_offset,}
1988 @item                   @tab @code{                           int dst_device_num,}
1989 @item                   @tab @code{                           int src_device_num)}
1990 @end multitable
1992 @item @emph{Fortran}:
1993 @multitable @columnfractions .20 .80
1994 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
1995 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
1996 @item                   @tab @code{    dst_device_num, src_device_num) bind(C)}
1997 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
1998 @item                   @tab @code{type(c_ptr), value :: dst, src}
1999 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2000 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
2001 @end multitable
2003 @item @emph{See also}:
2004 @ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2006 @item @emph{Reference}:
2007 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2008 @end table
2012 @node omp_target_memcpy_async
2013 @subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2014 @table @asis
2015 @item @emph{Description}:
2016 This routine copies asynchronously @var{length} of bytes of data from the
2017 device identified by device number @var{src_device_num} to device
2018 @var{dst_device_num}.  The data is copied from the source device from the
2019 address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2020 to the destination device's @var{dst} address shifted by @var{dst_offset}.
2021 Task dependence is expressed by passing an array of depend objects to
2022 @var{depobj_list}, where the number of array elements is passed as
2023 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2024 ignored.  The routine returns zero if the copying process has successfully
2025 been started and non-zero otherwise.
2027 Running this routine in a @code{target} region except on the initial device
2028 is not supported.
2030 @item @emph{C/C++}
2031 @multitable @columnfractions .20 .80
2032 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2033 @item                   @tab @code{                           const void *src,}
2034 @item                   @tab @code{                           size_t length,}
2035 @item                   @tab @code{                           size_t dst_offset,}
2036 @item                   @tab @code{                           size_t src_offset,}
2037 @item                   @tab @code{                           int dst_device_num,}
2038 @item                   @tab @code{                           int src_device_num,}
2039 @item                   @tab @code{                           int depobj_count,}
2040 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2041 @end multitable
2043 @item @emph{Fortran}:
2044 @multitable @columnfractions .20 .80
2045 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2046 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
2047 @item                   @tab @code{    dst_device_num, src_device_num, &}
2048 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2049 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2050 @item                   @tab @code{type(c_ptr), value :: dst, src}
2051 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2052 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2053 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2054 @end multitable
2056 @item @emph{See also}:
2057 @ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2059 @item @emph{Reference}:
2060 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2061 @end table
2065 @node omp_target_memcpy_rect
2066 @subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2067 @table @asis
2068 @item @emph{Description}:
2069 This routine copies a subvolume of data from the device identified by
2070 device number @var{src_device_num} to device @var{dst_device_num}. 
2071 The array has @var{num_dims} dimensions and each array element has a size of
2072 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2073 per dimension are copied.  The full sizes of the destination and source arrays
2074 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2075 respectively.  The offset per dimension to the first element to be copied is
2076 given by the @var{dst_offset} and @var{src_offset} arguments.  The routine
2077 returns zero on success and non-zero otherwise.
2079 The OpenMP specification only requires that @var{num_dims} up to three is
2080 supported.  In order to find implementation-specific maximally supported number
2081 of dimensions, the routine returns this value when invoked with a null pointer
2082 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2083 dimensions, it returns @code{INT_MAX}.
2085 The device-number arguments must be conforming device numbers, the @var{src} and
2086 @var{dst} must be either both null pointers or all of the following must be
2087 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2088 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2089 dimensions.
2091 Running this routine in a @code{target} region is not supported except on
2092 the initial device.
2094 @item @emph{C/C++}
2095 @multitable @columnfractions .20 .80
2096 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2097 @item                   @tab @code{                           const void *src,}
2098 @item                   @tab @code{                           size_t element_size,}
2099 @item                   @tab @code{                           int num_dims,}
2100 @item                   @tab @code{                           const size_t *volume,}
2101 @item                   @tab @code{                           const size_t *dst_offset,}
2102 @item                   @tab @code{                           const size_t *src_offset,}
2103 @item                   @tab @code{                           const size_t *dst_dimensions,}
2104 @item                   @tab @code{                           const size_t *src_dimensions,}
2105 @item                   @tab @code{                           int dst_device_num,}
2106 @item                   @tab @code{                           int src_device_num)}
2107 @end multitable
2109 @item @emph{Fortran}:
2110 @multitable @columnfractions .20 .80
2111 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2112 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2113 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2114 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num) bind(C)}
2115 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2116 @item                   @tab @code{type(c_ptr), value :: dst, src}
2117 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2118 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2119 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2120 @end multitable
2122 @item @emph{See also}:
2123 @ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}
2125 @item @emph{Reference}:
2126 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2127 @end table
2131 @node omp_target_memcpy_rect_async
2132 @subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2133 @table @asis
2134 @item @emph{Description}:
2135 This routine copies asynchronously a subvolume of data from the device
2136 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2137 The array has @var{num_dims} dimensions and each array element has a size of
2138 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2139 per dimension are copied.  The full sizes of the destination and source arrays
2140 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2141 respectively.  The offset per dimension to the first element to be copied is
2142 given by the @var{dst_offset} and @var{src_offset} arguments.  Task dependence
2143 is expressed by passing an array of depend objects to @var{depobj_list}, where
2144 the number of array elements is passed as @var{depobj_count}; if the count is
2145 zero, the @var{depobj_list} argument is ignored.  The routine
2146 returns zero on success and non-zero otherwise.
2148 The OpenMP specification only requires that @var{num_dims} up to three is
2149 supported.  In order to find implementation-specific maximally supported number
2150 of dimensions, the routine returns this value when invoked with a null pointer
2151 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2152 dimensions, it returns @code{INT_MAX}.
2154 The device-number arguments must be conforming device numbers, the @var{src} and
2155 @var{dst} must be either both null pointers or all of the following must be
2156 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2157 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2158 dimensions.
2160 Running this routine in a @code{target} region is not supported except on
2161 the initial device.
2163 @item @emph{C/C++}
2164 @multitable @columnfractions .20 .80
2165 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2166 @item                   @tab @code{                           const void *src,}
2167 @item                   @tab @code{                           size_t element_size,}
2168 @item                   @tab @code{                           int num_dims,}
2169 @item                   @tab @code{                           const size_t *volume,}
2170 @item                   @tab @code{                           const size_t *dst_offset,}
2171 @item                   @tab @code{                           const size_t *src_offset,}
2172 @item                   @tab @code{                           const size_t *dst_dimensions,}
2173 @item                   @tab @code{                           const size_t *src_dimensions,}
2174 @item                   @tab @code{                           int dst_device_num,}
2175 @item                   @tab @code{                           int src_device_num,}
2176 @item                   @tab @code{                           int depobj_count,}
2177 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2178 @end multitable
2180 @item @emph{Fortran}:
2181 @multitable @columnfractions .20 .80
2182 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2183 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2184 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2185 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num, &}
2186 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2187 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2188 @item                   @tab @code{type(c_ptr), value :: dst, src}
2189 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2190 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2191 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2192 @item                   @tab @code{integer(c_int), value :: depobj_count}
2193 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2194 @end multitable
2196 @item @emph{See also}:
2197 @ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}
2199 @item @emph{Reference}:
2200 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2201 @end table
2205 @node omp_target_associate_ptr
2206 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2207 @table @asis
2208 @item @emph{Description}:
2209 This routine associates storage on the host with storage on a device identified
2210 by @var{device_num}.  The device pointer is usually obtained by calling
2211 @code{omp_target_alloc} or by other means (but not by using the @code{map}
2212 clauses or the @code{declare target} directive).  The host pointer should point
2213 to memory that has a storage size of at least @var{size}.
2215 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2216 that is used as the base address for the device side of the mapping; the
2217 storage size should be at least @var{device_offset} plus @var{size}.
2219 After the association, the host pointer can be used in a @code{map} clause and
2220 in the @code{to} and @code{from} clauses of the @code{target update} directive
2221 to transfer data between the associated pointers. The reference count of such
2222 associated storage is infinite.  The association can be removed by calling
2223 @code{omp_target_disassociate_ptr} which should be done before the lifetime
2224 of either storage ends.
2226 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2227 for when the initial device or the associated device shares memory with the
2228 host.  @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2229 into already associated storage that is fully inside of a previously associated
2230 memory.  Otherwise, if the association was successful zero is returned; if none
2231 of the cases above apply, nonzero (@code{EINVAL}) is returned.
2233 The @code{omp_target_is_present} routine can be used to test whether
2234 associated storage for a device pointer exists.
2236 Running this routine in a @code{target} region except on the initial device
2237 is not supported.
2239 @item @emph{C/C++}
2240 @multitable @columnfractions .20 .80
2241 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2242 @item                   @tab @code{                             const void *device_ptr,}
2243 @item                   @tab @code{                             size_t size,}
2244 @item                   @tab @code{                             size_t device_offset,}
2245 @item                   @tab @code{                             int device_num)}
2246 @end multitable
2248 @item @emph{Fortran}:
2249 @multitable @columnfractions .20 .80
2250 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2251 @item                   @tab @code{    device_ptr, size, device_offset, device_num) bind(C)}
2252 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2253 @item                   @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2254 @item                   @tab @code{integer(c_size_t), value :: size, device_offset}
2255 @item                   @tab @code{integer(c_int), value :: device_num}
2256 @end multitable
2258 @item @emph{See also}:
2259 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2260 @ref{omp_target_alloc}
2262 @item @emph{Reference}:
2263 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2264 @end table
2268 @node omp_target_disassociate_ptr
2269 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2270 @table @asis
2271 @item @emph{Description}:
2272 This routine removes the storage association established by calling
2273 @code{omp_target_associate_ptr} and sets the reference count to zero,
2274 even if @code{omp_target_associate_ptr} was invoked multiple times for
2275 for host pointer @code{ptr}.  If applicable, the device memory needs
2276 to be freed by the user.
2278 If an associated device storage location for the @var{device_num} was
2279 found and has infinite reference count, the association is removed and
2280 zero is returned.  In all other cases, nonzero (@code{EINVAL}) is returned
2281 and no other action is taken.
2283 Note that passing a host pointer where the association to the device pointer
2284 was established with the @code{declare target} directive yields undefined
2285 behavior.
2287 Running this routine in a @code{target} region except on the initial device
2288 is not supported.
2290 @item @emph{C/C++}
2291 @multitable @columnfractions .20 .80
2292 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2293 @item                   @tab @code{                                int device_num)}
2294 @end multitable
2296 @item @emph{Fortran}:
2297 @multitable @columnfractions .20 .80
2298 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2299 @item                   @tab @code{    device_num) bind(C)}
2300 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2301 @item                   @tab @code{type(c_ptr), value :: ptr}
2302 @item                   @tab @code{integer(c_int), value :: device_num}
2303 @end multitable
2305 @item @emph{See also}:
2306 @ref{omp_target_associate_ptr}
2308 @item @emph{Reference}:
2309 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2310 @end table
2314 @node omp_get_mapped_ptr
2315 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2316 @table @asis
2317 @item @emph{Description}:
2318 If the device number is refers to the initial device or to a device with
2319 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2320 routines returns the value of the passed @var{ptr}.  Otherwise, if associated
2321 storage to the passed host pointer @var{ptr} exists on device associated with
2322 @var{device_num}, it returns that pointer. In all other cases and in cases of
2323 an error, a null pointer is returned.
2325 The association of storage location is established either via an explicit or
2326 implicit @code{map} clause, the @code{declare target} directive or the
2327 @code{omp_target_associate_ptr} routine.
2329 Running this routine in a @code{target} region except on the initial device
2330 is not supported.
2332 @item @emph{C/C++}
2333 @multitable @columnfractions .20 .80
2334 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2335 @end multitable
2337 @item @emph{Fortran}:
2338 @multitable @columnfractions .20 .80
2339 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2340 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2341 @item                   @tab @code{type(c_ptr), value :: ptr}
2342 @item                   @tab @code{integer(c_int), value :: device_num}
2343 @end multitable
2345 @item @emph{See also}:
2346 @ref{omp_target_associate_ptr}
2348 @item @emph{Reference}:
2349 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2350 @end table
2354 @node Lock Routines
2355 @section Lock Routines
2357 Initialize, set, test, unset and destroy simple and nested locks.
2358 The routines have C linkage and do not throw exceptions.
2360 @menu
2361 * omp_init_lock::            Initialize simple lock
2362 * omp_init_nest_lock::       Initialize nested lock
2363 @c * omp_init_lock_with_hint:: <fixme>
2364 @c * omp_init_nest_lock_with_hint:: <fixme>
2365 * omp_destroy_lock::         Destroy simple lock
2366 * omp_destroy_nest_lock::    Destroy nested lock
2367 * omp_set_lock::             Wait for and set simple lock
2368 * omp_set_nest_lock::        Wait for and set simple lock
2369 * omp_unset_lock::           Unset simple lock
2370 * omp_unset_nest_lock::      Unset nested lock
2371 * omp_test_lock::            Test and set simple lock if available
2372 * omp_test_nest_lock::       Test and set nested lock if available
2373 @end menu
2377 @node omp_init_lock
2378 @subsection @code{omp_init_lock} -- Initialize simple lock
2379 @table @asis
2380 @item @emph{Description}:
2381 Initialize a simple lock.  After initialization, the lock is in
2382 an unlocked state.
2384 @item @emph{C/C++}:
2385 @multitable @columnfractions .20 .80
2386 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2387 @end multitable
2389 @item @emph{Fortran}:
2390 @multitable @columnfractions .20 .80
2391 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2392 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2393 @end multitable
2395 @item @emph{See also}:
2396 @ref{omp_destroy_lock}
2398 @item @emph{Reference}: 
2399 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2400 @end table
2404 @node omp_init_nest_lock
2405 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2406 @table @asis
2407 @item @emph{Description}:
2408 Initialize a nested lock.  After initialization, the lock is in
2409 an unlocked state and the nesting count is set to zero.
2411 @item @emph{C/C++}:
2412 @multitable @columnfractions .20 .80
2413 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2414 @end multitable
2416 @item @emph{Fortran}:
2417 @multitable @columnfractions .20 .80
2418 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2419 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2420 @end multitable
2422 @item @emph{See also}:
2423 @ref{omp_destroy_nest_lock}
2425 @item @emph{Reference}:
2426 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2427 @end table
2431 @node omp_destroy_lock
2432 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2433 @table @asis
2434 @item @emph{Description}:
2435 Destroy a simple lock.  In order to be destroyed, a simple lock must be
2436 in the unlocked state. 
2438 @item @emph{C/C++}:
2439 @multitable @columnfractions .20 .80
2440 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2441 @end multitable
2443 @item @emph{Fortran}:
2444 @multitable @columnfractions .20 .80
2445 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2446 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2447 @end multitable
2449 @item @emph{See also}:
2450 @ref{omp_init_lock}
2452 @item @emph{Reference}: 
2453 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2454 @end table
2458 @node omp_destroy_nest_lock
2459 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2460 @table @asis
2461 @item @emph{Description}:
2462 Destroy a nested lock.  In order to be destroyed, a nested lock must be
2463 in the unlocked state and its nesting count must equal zero.
2465 @item @emph{C/C++}:
2466 @multitable @columnfractions .20 .80
2467 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2468 @end multitable
2470 @item @emph{Fortran}:
2471 @multitable @columnfractions .20 .80
2472 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2473 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2474 @end multitable
2476 @item @emph{See also}:
2477 @ref{omp_init_lock}
2479 @item @emph{Reference}: 
2480 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2481 @end table
2485 @node omp_set_lock
2486 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2487 @table @asis
2488 @item @emph{Description}:
2489 Before setting a simple lock, the lock variable must be initialized by 
2490 @code{omp_init_lock}.  The calling thread is blocked until the lock 
2491 is available.  If the lock is already held by the current thread, 
2492 a deadlock occurs.
2494 @item @emph{C/C++}:
2495 @multitable @columnfractions .20 .80
2496 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2497 @end multitable
2499 @item @emph{Fortran}:
2500 @multitable @columnfractions .20 .80
2501 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2502 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2503 @end multitable
2505 @item @emph{See also}:
2506 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2508 @item @emph{Reference}: 
2509 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2510 @end table
2514 @node omp_set_nest_lock
2515 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2516 @table @asis
2517 @item @emph{Description}:
2518 Before setting a nested lock, the lock variable must be initialized by 
2519 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
2520 is available.  If the lock is already held by the current thread, the
2521 nesting count for the lock is incremented.
2523 @item @emph{C/C++}:
2524 @multitable @columnfractions .20 .80
2525 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2526 @end multitable
2528 @item @emph{Fortran}:
2529 @multitable @columnfractions .20 .80
2530 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2531 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2532 @end multitable
2534 @item @emph{See also}:
2535 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2537 @item @emph{Reference}: 
2538 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2539 @end table
2543 @node omp_unset_lock
2544 @subsection @code{omp_unset_lock} -- Unset simple lock
2545 @table @asis
2546 @item @emph{Description}:
2547 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2548 or @code{omp_test_lock} before.  In addition, the lock must be held by the
2549 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
2550 or more threads attempted to set the lock before, one of them is chosen to,
2551 again, set the lock to itself.
2553 @item @emph{C/C++}:
2554 @multitable @columnfractions .20 .80
2555 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2556 @end multitable
2558 @item @emph{Fortran}:
2559 @multitable @columnfractions .20 .80
2560 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2561 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2562 @end multitable
2564 @item @emph{See also}:
2565 @ref{omp_set_lock}, @ref{omp_test_lock}
2567 @item @emph{Reference}: 
2568 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2569 @end table
2573 @node omp_unset_nest_lock
2574 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2575 @table @asis
2576 @item @emph{Description}:
2577 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2578 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
2579 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
2580 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
2581 one of them is chosen to, again, set the lock to itself.
2583 @item @emph{C/C++}:
2584 @multitable @columnfractions .20 .80
2585 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2586 @end multitable
2588 @item @emph{Fortran}:
2589 @multitable @columnfractions .20 .80
2590 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2591 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2592 @end multitable
2594 @item @emph{See also}:
2595 @ref{omp_set_nest_lock}
2597 @item @emph{Reference}: 
2598 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2599 @end table
2603 @node omp_test_lock
2604 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2605 @table @asis
2606 @item @emph{Description}:
2607 Before setting a simple lock, the lock variable must be initialized by 
2608 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
2609 does not block if the lock is not available.  This function returns
2610 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
2611 @code{false} represent their language-specific counterparts.
2613 @item @emph{C/C++}:
2614 @multitable @columnfractions .20 .80
2615 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2616 @end multitable
2618 @item @emph{Fortran}:
2619 @multitable @columnfractions .20 .80
2620 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2621 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2622 @end multitable
2624 @item @emph{See also}:
2625 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2627 @item @emph{Reference}: 
2628 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2629 @end table
2633 @node omp_test_nest_lock
2634 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2635 @table @asis
2636 @item @emph{Description}:
2637 Before setting a nested lock, the lock variable must be initialized by 
2638 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
2639 @code{omp_test_nest_lock} does not block if the lock is not available. 
2640 If the lock is already held by the current thread, the new nesting count 
2641 is returned.  Otherwise, the return value equals zero.
2643 @item @emph{C/C++}:
2644 @multitable @columnfractions .20 .80
2645 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2646 @end multitable
2648 @item @emph{Fortran}:
2649 @multitable @columnfractions .20 .80
2650 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2651 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2652 @end multitable
2655 @item @emph{See also}:
2656 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2658 @item @emph{Reference}: 
2659 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2660 @end table
2664 @node Timing Routines
2665 @section Timing Routines
2667 Portable, thread-based, wall clock timer.
2668 The routines have C linkage and do not throw exceptions.
2670 @menu
2671 * omp_get_wtick::            Get timer precision.
2672 * omp_get_wtime::            Elapsed wall clock time.
2673 @end menu
2677 @node omp_get_wtick
2678 @subsection @code{omp_get_wtick} -- Get timer precision
2679 @table @asis
2680 @item @emph{Description}:
2681 Gets the timer precision, i.e., the number of seconds between two 
2682 successive clock ticks.
2684 @item @emph{C/C++}:
2685 @multitable @columnfractions .20 .80
2686 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2687 @end multitable
2689 @item @emph{Fortran}:
2690 @multitable @columnfractions .20 .80
2691 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2692 @end multitable
2694 @item @emph{See also}:
2695 @ref{omp_get_wtime}
2697 @item @emph{Reference}: 
2698 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2699 @end table
2703 @node omp_get_wtime
2704 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2705 @table @asis
2706 @item @emph{Description}:
2707 Elapsed wall clock time in seconds.  The time is measured per thread, no
2708 guarantee can be made that two distinct threads measure the same time.
2709 Time is measured from some "time in the past", which is an arbitrary time
2710 guaranteed not to change during the execution of the program.
2712 @item @emph{C/C++}:
2713 @multitable @columnfractions .20 .80
2714 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2715 @end multitable
2717 @item @emph{Fortran}:
2718 @multitable @columnfractions .20 .80
2719 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2720 @end multitable
2722 @item @emph{See also}:
2723 @ref{omp_get_wtick}
2725 @item @emph{Reference}: 
2726 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2727 @end table
2731 @node Event Routine
2732 @section Event Routine
2734 Support for event objects.
2735 The routine has C linkage and do not throw exceptions.
2737 @menu
2738 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
2739 @end menu
2743 @node omp_fulfill_event
2744 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2745 @table @asis
2746 @item @emph{Description}:
2747 Fulfill the event associated with the event handle argument.  Currently, it
2748 is only used to fulfill events generated by detach clauses on task
2749 constructs - the effect of fulfilling the event is to allow the task to
2750 complete.
2752 The result of calling @code{omp_fulfill_event} with an event handle other
2753 than that generated by a detach clause is undefined.  Calling it with an
2754 event handle that has already been fulfilled is also undefined.
2756 @item @emph{C/C++}:
2757 @multitable @columnfractions .20 .80
2758 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2759 @end multitable
2761 @item @emph{Fortran}:
2762 @multitable @columnfractions .20 .80
2763 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2764 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
2765 @end multitable
2767 @item @emph{Reference}:
2768 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2769 @end table
2773 @c @node Interoperability Routines
2774 @c @section Interoperability Routines
2776 @c Routines to obtain properties from an @code{omp_interop_t} object.
2777 @c They have C linkage and do not throw exceptions.
2779 @c @menu
2780 @c * omp_get_num_interop_properties:: <fixme>
2781 @c * omp_get_interop_int:: <fixme>
2782 @c * omp_get_interop_ptr:: <fixme>
2783 @c * omp_get_interop_str:: <fixme>
2784 @c * omp_get_interop_name:: <fixme>
2785 @c * omp_get_interop_type_desc:: <fixme>
2786 @c * omp_get_interop_rc_desc:: <fixme>
2787 @c @end menu
2789 @node Memory Management Routines
2790 @section Memory Management Routines
2792 Routines to manage and allocate memory on the current device.
2793 They have C linkage and do not throw exceptions.
2795 @menu
2796 * omp_init_allocator:: Create an allocator
2797 * omp_destroy_allocator:: Destroy an allocator
2798 * omp_set_default_allocator:: Set the default allocator
2799 * omp_get_default_allocator:: Get the default allocator
2800 * omp_alloc:: Memory allocation with an allocator
2801 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
2802 * omp_free:: Freeing memory allocated with OpenMP routines
2803 * omp_calloc:: Allocate nullified memory with an allocator
2804 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
2805 * omp_realloc:: Reallocate memory allocated with OpenMP routines
2806 @c * omp_get_memspace_num_resources:: <fixme>/TR11
2807 @c * omp_get_submemspace:: <fixme>/TR11
2808 @end menu
2812 @node omp_init_allocator
2813 @subsection @code{omp_init_allocator} -- Create an allocator
2814 @table @asis
2815 @item @emph{Description}:
2816 Create an allocator that uses the specified memory space and has the specified
2817 traits; if an allocator that fulfills the requirements cannot be created,
2818 @code{omp_null_allocator} is returned.
2820 The predefined memory spaces and available traits can be found at
2821 @ref{OMP_ALLOCATOR}, where the trait names have to be prefixed by
2822 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
2823 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
2824 may be used as trait value to specify that the default value should be used.
2826 @item @emph{C/C++}:
2827 @multitable @columnfractions .20 .80
2828 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
2829 @item                   @tab @code{  omp_memspace_handle_t memspace,}
2830 @item                   @tab @code{  int ntraits,}
2831 @item                   @tab @code{  const omp_alloctrait_t traits[]);}
2832 @end multitable
2834 @item @emph{Fortran}:
2835 @multitable @columnfractions .20 .80
2836 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
2837 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
2838 @item                   @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
2839 @item                   @tab @code{integer, intent(in) :: ntraits}
2840 @item                   @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
2841 @end multitable
2843 @item @emph{See also}:
2844 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
2846 @item @emph{Reference}:
2847 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
2848 @end table
2852 @node omp_destroy_allocator
2853 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
2854 @table @asis
2855 @item @emph{Description}:
2856 Releases all resources used by a memory allocator, which must not represent
2857 a predefined memory allocator.  Accessing memory after its allocator has been
2858 destroyed has unspecified behavior.  Passing @code{omp_null_allocator} to the
2859 routine is permitted but has no effect.
2862 @item @emph{C/C++}:
2863 @multitable @columnfractions .20 .80
2864 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
2865 @end multitable
2867 @item @emph{Fortran}:
2868 @multitable @columnfractions .20 .80
2869 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
2870 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2871 @end multitable
2873 @item @emph{See also}:
2874 @ref{omp_init_allocator}
2876 @item @emph{Reference}:
2877 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
2878 @end table
2882 @node omp_set_default_allocator
2883 @subsection @code{omp_set_default_allocator} -- Set the default allocator
2884 @table @asis
2885 @item @emph{Description}:
2886 Sets the default allocator that is used when no allocator has been specified
2887 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2888 routine is invoked with the @code{omp_null_allocator} allocator.
2890 @item @emph{C/C++}:
2891 @multitable @columnfractions .20 .80
2892 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
2893 @end multitable
2895 @item @emph{Fortran}:
2896 @multitable @columnfractions .20 .80
2897 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
2898 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2899 @end multitable
2901 @item @emph{See also}:
2902 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
2903 @ref{Memory allocation}
2905 @item @emph{Reference}:
2906 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
2907 @end table
2911 @node omp_get_default_allocator
2912 @subsection @code{omp_get_default_allocator} -- Get the default allocator
2913 @table @asis
2914 @item @emph{Description}:
2915 The routine returns the default allocator that is used when no allocator has
2916 been specified in the @code{allocate} or @code{allocator} clause or if an
2917 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
2919 @item @emph{C/C++}:
2920 @multitable @columnfractions .20 .80
2921 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
2922 @end multitable
2924 @item @emph{Fortran}:
2925 @multitable @columnfractions .20 .80
2926 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
2927 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
2928 @end multitable
2930 @item @emph{See also}:
2931 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
2933 @item @emph{Reference}:
2934 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
2935 @end table
2939 @node omp_alloc
2940 @subsection @code{omp_alloc} -- Memory allocation with an allocator
2941 @table @asis
2942 @item @emph{Description}:
2943 Allocate memory with the specified allocator, which can either be a predefined
2944 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2945 is @code{omp_null_allocator}, the allocator specified by the
2946 @var{def-allocator-var} ICV is used.  @var{size} must be a nonnegative number
2947 denoting the number of bytes to be allocated; if @var{size} is zero,
2948 @code{omp_alloc} will return a null pointer.  If successful, a pointer to the
2949 allocated memory is returned, otherwise the @code{fallback} trait of the
2950 allocator determines the behavior.  The content of the allocated memory is
2951 unspecified.
2953 In @code{target} regions, either the @code{dynamic_allocators} clause must
2954 appear on a @code{requires} directive in the same compilation unit -- or the
2955 @var{allocator} argument may only be a constant expression with the value of
2956 one of the predefined allocators and may not be @code{omp_null_allocator}.
2958 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
2960 @item @emph{C}:
2961 @multitable @columnfractions .20 .80
2962 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2963 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2964 @end multitable
2966 @item @emph{C++}:
2967 @multitable @columnfractions .20 .80
2968 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2969 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2970 @end multitable
2972 @item @emph{Fortran}:
2973 @multitable @columnfractions .20 .80
2974 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
2975 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2976 @item                   @tab @code{integer (c_size_t), value :: size}
2977 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2978 @end multitable
2980 @item @emph{See also}:
2981 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2982 @ref{omp_free}, @ref{omp_init_allocator}
2984 @item @emph{Reference}:
2985 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
2986 @end table
2990 @node omp_aligned_alloc
2991 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
2992 @table @asis
2993 @item @emph{Description}:
2994 Allocate memory with the specified allocator, which can either be a predefined
2995 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2996 is @code{omp_null_allocator}, the allocator specified by the
2997 @var{def-allocator-var} ICV is used.  @var{alignment} must be a positive power
2998 of two and @var{size} must be a nonnegative number that is a multiple of the
2999 alignment and denotes the number of bytes to be allocated; if @var{size} is
3000 zero, @code{omp_aligned_alloc} will return a null pointer.  The alignment will
3001 be at least the maximal value required by @code{alignment} trait of the
3002 allocator and the value of the  passed @var{alignment} argument.  If successful,
3003 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3004 trait of the allocator determines the behavior.  The content of the allocated
3005 memory is unspecified.
3007 In @code{target} regions, either the @code{dynamic_allocators} clause must
3008 appear on a @code{requires} directive in the same compilation unit -- or the
3009 @var{allocator} argument may only be a constant expression with the value of
3010 one of the predefined allocators and may not be @code{omp_null_allocator}.
3012 Memory allocated by @code{omp_aligned_alloc} must be freed using
3013 @code{omp_free}.
3015 @item @emph{C}:
3016 @multitable @columnfractions .20 .80
3017 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3018 @item                   @tab @code{  size_t size,}
3019 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3020 @end multitable
3022 @item @emph{C++}:
3023 @multitable @columnfractions .20 .80
3024 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3025 @item                   @tab @code{  size_t size,}
3026 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3027 @end multitable
3029 @item @emph{Fortran}:
3030 @multitable @columnfractions .20 .80
3031 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3032 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3033 @item                   @tab @code{integer (c_size_t), value :: alignment, size}
3034 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3035 @end multitable
3037 @item @emph{See also}:
3038 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3039 @ref{omp_free}, @ref{omp_init_allocator}
3041 @item @emph{Reference}:
3042 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3043 @end table
3047 @node omp_free
3048 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3049 @table @asis
3050 @item @emph{Description}:
3051 The @code{omp_free} routine deallocates memory previously allocated by an
3052 OpenMP memory-management routine. The @var{ptr} argument must point to such
3053 memory or be a null pointer; if it is a null pointer, no operation is
3054 performed.  If specified, the @var{allocator} argument must be either the
3055 memory allocator that was used for the allocation or @code{omp_null_allocator};
3056 if it is @code{omp_null_allocator}, the implementation will determine the value
3057 automatically.
3059 Calling @code{omp_free} invokes undefined behavior if the memory
3060 was already deallocated or when the used allocator has already been destroyed.
3062 @item @emph{C}:
3063 @multitable @columnfractions .20 .80
3064 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3065 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3066 @end multitable
3068 @item @emph{C++}:
3069 @multitable @columnfractions .20 .80
3070 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3071 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3072 @end multitable
3074 @item @emph{Fortran}:
3075 @multitable @columnfractions .20 .80
3076 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3077 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3078 @item                   @tab @code{type (c_ptr), value :: ptr}
3079 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3080 @end multitable
3082 @item @emph{See also}:
3083 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3084 @ref{omp_aligned_calloc}, @ref{omp_realloc}
3086 @item @emph{Reference}:
3087 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3088 @end table
3092 @node omp_calloc
3093 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3094 @table @asis
3095 @item @emph{Description}:
3096 Allocate zero-initialized memory with the specified allocator, which can either
3097 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3098 the allocators is @code{omp_null_allocator}, the allocator specified by the
3099 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3100 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3101 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3102 zero, @code{omp_calloc} will return a null pointer.  If successful, a pointer to
3103 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3104 trait of the allocator determines the behavior.
3106 In @code{target} regions, either the @code{dynamic_allocators} clause must
3107 appear on a @code{requires} directive in the same compilation unit -- or the
3108 @var{allocator} argument may only be a constant expression with the value of
3109 one of the predefined allocators and may not be @code{omp_null_allocator}.
3111 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3113 @item @emph{C}:
3114 @multitable @columnfractions .20 .80
3115 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3116 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3117 @end multitable
3119 @item @emph{C++}:
3120 @multitable @columnfractions .20 .80
3121 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3122 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3123 @end multitable
3125 @item @emph{Fortran}:
3126 @multitable @columnfractions .20 .80
3127 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3128 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3129 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3130 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3131 @end multitable
3133 @item @emph{See also}:
3134 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3135 @ref{omp_free}, @ref{omp_init_allocator}
3137 @item @emph{Reference}:
3138 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3139 @end table
3143 @node omp_aligned_calloc
3144 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3145 @table @asis
3146 @item @emph{Description}:
3147 Allocate zero-initialized memory with the specified allocator, which can either
3148 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3149 the allocators is @code{omp_null_allocator}, the allocator specified by the
3150 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3151 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3152 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3153 zero, @code{omp_aligned_calloc} will return a null pointer.  @var{alignment}
3154 must be a positive power of two and @var{size} must be a multiple of the
3155 alignment; the alignment will be at least the maximal value required by
3156 @code{alignment} trait of the allocator and the value of the  passed
3157 @var{alignment} argument.  If successful, a pointer to the zero-initialized
3158 allocated memory is returned, otherwise the @code{fallback} trait of the
3159 allocator determines the behavior.
3161 In @code{target} regions, either the @code{dynamic_allocators} clause must
3162 appear on a @code{requires} directive in the same compilation unit -- or the
3163 @var{allocator} argument may only be a constant expression with the value of
3164 one of the predefined allocators and may not be @code{omp_null_allocator}.
3166 Memory allocated by @code{omp_aligned_calloc} must be freed using
3167 @code{omp_free}.
3169 @item @emph{C}:
3170 @multitable @columnfractions .20 .80
3171 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3172 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3173 @end multitable
3175 @item @emph{C++}:
3176 @multitable @columnfractions .20 .80
3177 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3178 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3179 @end multitable
3181 @item @emph{Fortran}:
3182 @multitable @columnfractions .20 .80
3183 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3184 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3185 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3186 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3187 @end multitable
3189 @item @emph{See also}:
3190 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3191 @ref{omp_free}, @ref{omp_init_allocator}
3193 @item @emph{Reference}:
3194 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3195 @end table
3199 @node omp_realloc
3200 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3201 @table @asis
3202 @item @emph{Description}:
3203 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3204 and allocates new memory with the specified @var{allocator} argument; the
3205 new memory will have the content of the old memory up to the minimum of the
3206 old size and the new @var{size}, otherwise the content of the returned memory
3207 is unspecified.  If the new allocator is the same as the old one, the routine
3208 tries to resize the existing memory allocation, returning the same address as
3209 @var{ptr} if successful.  @var{ptr} must point to memory allocated by an OpenMP
3210 memory-management routine.
3212 The @var{allocator} and @var{free_allocator} arguments must be a predefined
3213 allocator, an allocator handle or @code{omp_null_allocator}.  If
3214 @var{free_allocator} is @code{omp_null_allocator}, the implementation
3215 automatically determines the allocator used for the allocation of @var{ptr}.
3216 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is not a
3217 null pointer, the same allocator as @code{free_allocator} is used and
3218 when @var{ptr} is a null pointer the allocator specified by the
3219 @var{def-allocator-var} ICV is used.
3221 The @var{size} must be a nonnegative number denoting the number of bytes to be
3222 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3223 memory and return a null pointer.  When @var{size} is nonzero: if successful,
3224 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3225 trait of the allocator determines the behavior.
3227 In @code{target} regions, either the @code{dynamic_allocators} clause must
3228 appear on a @code{requires} directive in the same compilation unit -- or the
3229 @var{free_allocator} and @var{allocator} arguments may only be a constant
3230 expression with the value of one of the predefined allocators and may not be
3231 @code{omp_null_allocator}.
3233 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3234 Calling @code{omp_free} invokes undefined behavior if the memory
3235 was already deallocated or when the used allocator has already been destroyed.
3237 @item @emph{C}:
3238 @multitable @columnfractions .20 .80
3239 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3240 @item                   @tab @code{  omp_allocator_handle_t allocator,}
3241 @item                   @tab @code{  omp_allocator_handle_t free_allocator)}
3242 @end multitable
3244 @item @emph{C++}:
3245 @multitable @columnfractions .20 .80
3246 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3247 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator,}
3248 @item                   @tab @code{  omp_allocator_handle_t free_allocator=omp_null_allocator)}
3249 @end multitable
3251 @item @emph{Fortran}:
3252 @multitable @columnfractions .20 .80
3253 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3254 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3255 @item                   @tab @code{type(C_ptr), value :: ptr}
3256 @item                   @tab @code{integer (c_size_t), value :: size}
3257 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3258 @end multitable
3260 @item @emph{See also}:
3261 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3262 @ref{omp_free}, @ref{omp_init_allocator}
3264 @item @emph{Reference}:
3265 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3266 @end table
3270 @c @node Tool Control Routine
3271 @c @section Tool Control Routine
3273 @c FIXME
3275 @node Environment Display Routine
3276 @section Environment Display Routine
3278 Routine to display the OpenMP version number and the initial value of ICVs.
3279 It has C linkage and does not throw exceptions.
3281 @menu
3282 * omp_display_env:: print the initial ICV values
3283 @end menu
3285 @node omp_display_env
3286 @subsection @code{omp_display_env} -- print the initial ICV values
3287 @table @asis
3288 @item @emph{Description}:
3289 Each time this routine is invoked, the OpenMP version number and initial value
3290 of internal control variables (ICVs) is printed on @code{stderr}.  The displayed
3291 values are those at startup after evaluating the environment variables; later
3292 calls to API routines or clauses used in enclosing constructs do not affect
3293 the output.
3295 If the @var{verbose} argument is @code{false}, only the OpenMP version and
3296 standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3297 GCC-specific ICVs are shown.
3299 The output consists of multiple lines and starts with
3300 @samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3301 ends with @samp{OPENMP DISPLAY ENVIRONMENT END}.  The @var{name} is followed by
3302 an equal sign and the @var{value} is enclosed in single quotes.
3304 The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3305 and shows as value the supported OpenMP version number (4-digit year, 2-digit
3306 month) of the implementation, matching the value of the @code{_OPENMP} macro
3307 and, in Fortran, the named constant @code{openmp_version}.
3309 In each of the succeeding lines, the @var{name} matches the environment-variable
3310 name of an ICV and shows its value.  Those line are might be prefixed by pair of
3311 brackets and a space, where the brackets enclose a comma-separated list of
3312 devices to which the ICV-value combination applies to; the value can either be a
3313 numeric device number or an abstract name denoting all devices (@code{all}), the
3314 initial host device (@code{host}) or all devices but the host (@code{device}).
3315 Note that the same ICV might be printed multiple times for multiple devices,
3316 even if all have the same value.
3318 The effect when invoked from within a @code{target} region is unspecified.
3320 @item @emph{C/C++}:
3321 @multitable @columnfractions .20 .80
3322 @item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3323 @end multitable
3325 @item @emph{Fortran}:
3326 @multitable @columnfractions .20 .80
3327 @item @emph{Interface}: @tab @code{subroutine omp_display_env(vebose)}
3328 @item                   @tab @code{logical, intent(in) :: verbose}
3329 @end multitable
3331 @item @emph{Example}:
3332 Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3333 are only printed when @var{varbose} set to @code{true}.
3335 @smallexample
3336 OPENMP DISPLAY ENVIRONMENT BEGIN
3337   _OPENMP = '201511'
3338   [host] OMP_DYNAMIC = 'FALSE'
3339   [host] OMP_NESTED = 'FALSE'
3340   [all] OMP_CANCELLATION = 'FALSE'
3341   ...
3342   [host] GOMP_SPINCOUNT = '300000'
3343 OPENMP DISPLAY ENVIRONMENT END
3344 @end smallexample
3347 @item @emph{See also}:
3348 @ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3349 @ref{Implementation-defined ICV Initialization}
3351 @item @emph{Reference}:
3352 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3353 @end table
3356 @c ---------------------------------------------------------------------
3357 @c OpenMP Environment Variables
3358 @c ---------------------------------------------------------------------
3360 @node Environment Variables
3361 @chapter OpenMP Environment Variables
3363 The environment variables which beginning with @env{OMP_} are defined by
3364 section 4 of the OpenMP specification in version 4.5 or in a later version
3365 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
3366 Most @env{OMP_} environment variables have an associated internal control
3367 variable (ICV).
3369 For any OpenMP environment variable that sets an ICV and is neither
3370 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
3371 device-specific environment variables exist.  For them, the environment
3372 variable without suffix affects the host.  The suffix @code{_DEV_} followed
3373 by a non-negative device number less that the number of available devices sets
3374 the ICV for the corresponding device.  The suffix @code{_DEV} sets the ICV
3375 of all non-host devices for which a device-specific corresponding environment
3376 variable has not been set while the @code{_ALL} suffix sets the ICV of all
3377 host and non-host devices for which a more specific corresponding environment
3378 variable is not set.
3380 @menu
3381 * OMP_ALLOCATOR::           Set the default allocator
3382 * OMP_AFFINITY_FORMAT::     Set the format string used for affinity display
3383 * OMP_CANCELLATION::        Set whether cancellation is activated
3384 * OMP_DISPLAY_AFFINITY::    Display thread affinity information
3385 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
3386 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
3387 * OMP_DYNAMIC::             Dynamic adjustment of threads
3388 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
3389 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
3390 * OMP_NESTED::              Nested parallel regions
3391 * OMP_NUM_TEAMS::           Specifies the number of teams to use by teams region
3392 * OMP_NUM_THREADS::         Specifies the number of threads to use
3393 * OMP_PROC_BIND::           Whether threads may be moved between CPUs
3394 * OMP_PLACES::              Specifies on which CPUs the threads should be placed
3395 * OMP_STACKSIZE::           Set default thread stack size
3396 * OMP_SCHEDULE::            How threads are scheduled
3397 * OMP_TARGET_OFFLOAD::      Controls offloading behavior
3398 * OMP_TEAMS_THREAD_LIMIT::  Set the maximum number of threads imposed by teams
3399 * OMP_THREAD_LIMIT::        Set the maximum number of threads
3400 * OMP_WAIT_POLICY::         How waiting threads are handled
3401 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
3402 * GOMP_DEBUG::              Enable debugging output
3403 * GOMP_STACKSIZE::          Set default thread stack size
3404 * GOMP_SPINCOUNT::          Set the busy-wait spin count
3405 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
3406 @end menu
3409 @node OMP_ALLOCATOR
3410 @section @env{OMP_ALLOCATOR} -- Set the default allocator
3411 @cindex Environment Variable
3412 @table @asis
3413 @item @emph{ICV:} @var{def-allocator-var}
3414 @item @emph{Scope:} data environment
3415 @item @emph{Description}:
3416 Sets the default allocator that is used when no allocator has been specified
3417 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3418 routine is invoked with the @code{omp_null_allocator} allocator.
3419 If unset, @code{omp_default_mem_alloc} is used.
3421 The value can either be a predefined allocator or a predefined memory space
3422 or a predefined memory space followed by a colon and a comma-separated list
3423 of memory trait and value pairs, separated by @code{=}.
3425 Note: The corresponding device environment variables are currently not
3426 supported.  Therefore, the non-host @var{def-allocator-var} ICVs are always
3427 initialized to @code{omp_default_mem_alloc}.  However, on all devices,
3428 the @code{omp_set_default_allocator} API routine can be used to change
3429 value.
3431 @multitable @columnfractions .45 .45
3432 @headitem Predefined allocators @tab Associated predefined memory spaces
3433 @item omp_default_mem_alloc     @tab omp_default_mem_space
3434 @item omp_large_cap_mem_alloc   @tab omp_large_cap_mem_space
3435 @item omp_const_mem_alloc       @tab omp_const_mem_space
3436 @item omp_high_bw_mem_alloc     @tab omp_high_bw_mem_space
3437 @item omp_low_lat_mem_alloc     @tab omp_low_lat_mem_space
3438 @item omp_cgroup_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3439 @item omp_pteam_mem_alloc       @tab omp_low_lat_mem_space (implementation defined)
3440 @item omp_thread_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3441 @end multitable
3443 The predefined allocators use the default values for the traits,
3444 as listed below.  Except that the last three allocators have the
3445 @code{access} trait set to @code{cgroup}, @code{pteam}, and
3446 @code{thread}, respectively.
3448 @multitable @columnfractions .25 .40 .25
3449 @headitem Trait @tab Allowed values @tab Default value
3450 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
3451                             @code{serialized}, @code{private}
3452                        @tab @code{contended}
3453 @item @code{alignment} @tab Positive integer being a power of two
3454                        @tab 1 byte
3455 @item @code{access}    @tab @code{all}, @code{cgroup},
3456                             @code{pteam}, @code{thread}
3457                        @tab @code{all}
3458 @item @code{pool_size} @tab Positive integer
3459                        @tab See @ref{Memory allocation}
3460 @item @code{fallback}  @tab @code{default_mem_fb}, @code{null_fb},
3461                             @code{abort_fb}, @code{allocator_fb}
3462                        @tab See below
3463 @item @code{fb_data}   @tab @emph{unsupported as it needs an allocator handle}
3464                        @tab (none)
3465 @item @code{pinned}    @tab @code{true}, @code{false}
3466                        @tab @code{false}
3467 @item @code{partition} @tab @code{environment}, @code{nearest},
3468                             @code{blocked}, @code{interleaved}
3469                        @tab @code{environment}
3470 @end multitable
3472 For the @code{fallback} trait, the default value is @code{null_fb} for the
3473 @code{omp_default_mem_alloc} allocator and any allocator that is associated
3474 with device memory; for all other allocators, it is @code{default_mem_fb}
3475 by default.
3477 Examples:
3478 @smallexample
3479 OMP_ALLOCATOR=omp_high_bw_mem_alloc
3480 OMP_ALLOCATOR=omp_large_cap_mem_space
3481 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
3482 @end smallexample
3484 @item @emph{See also}:
3485 @ref{Memory allocation}, @ref{omp_get_default_allocator},
3486 @ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
3488 @item @emph{Reference}:
3489 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
3490 @end table
3494 @node OMP_AFFINITY_FORMAT
3495 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
3496 @cindex Environment Variable
3497 @table @asis
3498 @item @emph{ICV:} @var{affinity-format-var}
3499 @item @emph{Scope:} device
3500 @item @emph{Description}:
3501 Sets the format string used when displaying OpenMP thread affinity information.
3502 Special values are output using @code{%} followed by an optional size
3503 specification and then either the single-character field type or its long
3504 name enclosed in curly braces; using @code{%%} displays a literal percent.
3505 The size specification consists of an optional @code{0.} or @code{.} followed
3506 by a positive integer, specifying the minimal width of the output.  With
3507 @code{0.} and numerical values, the output is padded with zeros on the left;
3508 with @code{.}, the output is padded by spaces on the left; otherwise, the
3509 output is padded by spaces on the right.  If unset, the value is
3510 ``@code{level %L thread %i affinity %A}''.
3512 Supported field types are:
3514 @multitable @columnfractions .10 .25 .60
3515 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
3516 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
3517 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
3518 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
3519 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
3520 @item a @tab ancestor_tnum
3521       @tab value returned by
3522            @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
3523 @item H @tab host @tab name of the host that executes the thread
3524 @item P @tab process_id @tab process identifier
3525 @item i @tab native_thread_id @tab native thread identifier
3526 @item A @tab thread_affinity
3527       @tab comma separated list of integer values or ranges, representing the
3528            processors on which a process might execute, subject to affinity
3529            mechanisms
3530 @end multitable
3532 For instance, after setting
3534 @smallexample
3535 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
3536 @end smallexample
3538 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
3539 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
3540 might display the following:
3542 @smallexample
3543 00!0!   1!4; 0;01;0;1;0-11
3544 00!3!   1!4; 0;01;0;1;0-11
3545 00!2!   1!4; 0;01;0;1;0-11
3546 00!1!   1!4; 0;01;0;1;0-11
3547 @end smallexample
3549 @item @emph{See also}:
3550 @ref{OMP_DISPLAY_AFFINITY}
3552 @item @emph{Reference}:
3553 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
3554 @end table
3558 @node OMP_CANCELLATION
3559 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
3560 @cindex Environment Variable
3561 @table @asis
3562 @item @emph{ICV:} @var{cancel-var}
3563 @item @emph{Scope:} global
3564 @item @emph{Description}:
3565 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
3566 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
3568 @item @emph{See also}:
3569 @ref{omp_get_cancellation}
3571 @item @emph{Reference}:
3572 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
3573 @end table
3577 @node OMP_DISPLAY_AFFINITY
3578 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
3579 @cindex Environment Variable
3580 @table @asis
3581 @item @emph{ICV:} @var{display-affinity-var}
3582 @item @emph{Scope:} global
3583 @item @emph{Description}:
3584 If set to @code{FALSE} or if unset, affinity displaying is disabled.
3585 If set to @code{TRUE}, the runtime displays affinity information about
3586 OpenMP threads in a parallel region upon entering the region and every time
3587 any change occurs.
3589 @item @emph{See also}:
3590 @ref{OMP_AFFINITY_FORMAT}
3592 @item @emph{Reference}:
3593 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
3594 @end table
3599 @node OMP_DISPLAY_ENV
3600 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
3601 @cindex Environment Variable
3602 @table @asis
3603 @item @emph{ICV:} none
3604 @item @emph{Scope:} not applicable
3605 @item @emph{Description}:
3606 If set to @code{TRUE}, the runtime displays the same information to
3607 @code{stderr} as shown by the @code{omp_display_env} routine invoked with
3608 @var{verbose} argument set to @code{false}.  If set to @code{VERBOSE}, the same
3609 information is shown as invoking the routine with @var{verbose} set to
3610 @code{true}. If unset or set to @code{FALSE}, this information is not shown.
3611 The result for any other value is unspecified.
3613 @item @emph{See also}:
3614 @ref{omp_display_env}
3616 @item @emph{Reference}:
3617 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
3618 @end table
3622 @node OMP_DEFAULT_DEVICE
3623 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
3624 @cindex Environment Variable
3625 @table @asis
3626 @item @emph{ICV:} @var{default-device-var}
3627 @item @emph{Scope:} data environment
3628 @item @emph{Description}:
3629 Set to choose the device which is used in a @code{target} region, unless the
3630 value is overridden by @code{omp_set_default_device} or by a @code{device}
3631 clause.  The value shall be the nonnegative device number. If no device with
3632 the given device number exists, the code is executed on the host.  If unset,
3633 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
3634 available, it is set to @code{omp_invalid_device}.  Otherwise, if unset,
3635 device number 0 is used.
3638 @item @emph{See also}:
3639 @ref{omp_get_default_device}, @ref{omp_set_default_device},
3640 @ref{OMP_TARGET_OFFLOAD}
3642 @item @emph{Reference}:
3643 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
3644 @end table
3648 @node OMP_DYNAMIC
3649 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
3650 @cindex Environment Variable
3651 @table @asis
3652 @item @emph{ICV:} @var{dyn-var}
3653 @item @emph{Scope:} global
3654 @item @emph{Description}:
3655 Enable or disable the dynamic adjustment of the number of threads 
3656 within a team.  The value of this environment variable shall be 
3657 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
3658 disabled by default.
3660 @item @emph{See also}:
3661 @ref{omp_set_dynamic}
3663 @item @emph{Reference}: 
3664 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
3665 @end table
3669 @node OMP_MAX_ACTIVE_LEVELS
3670 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
3671 @cindex Environment Variable
3672 @table @asis
3673 @item @emph{ICV:} @var{max-active-levels-var}
3674 @item @emph{Scope:} data environment
3675 @item @emph{Description}:
3676 Specifies the initial value for the maximum number of nested parallel
3677 regions.  The value of this variable shall be a positive integer.
3678 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
3679 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
3680 a list with more than one item, the maximum number of nested parallel
3681 regions is initialized to the largest number supported, otherwise
3682 it is set to one.
3684 @item @emph{See also}:
3685 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
3686 @ref{OMP_NUM_THREADS}
3689 @item @emph{Reference}: 
3690 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
3691 @end table
3695 @node OMP_MAX_TASK_PRIORITY
3696 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
3697 number that can be set for a task.
3698 @cindex Environment Variable
3699 @table @asis
3700 @item @emph{ICV:} @var{max-task-priority-var}
3701 @item @emph{Scope:} global
3702 @item @emph{Description}:
3703 Specifies the initial value for the maximum priority value that can be
3704 set for a task.  The value of this variable shall be a non-negative
3705 integer, and zero is allowed.  If undefined, the default priority is
3708 @item @emph{See also}:
3709 @ref{omp_get_max_task_priority}
3711 @item @emph{Reference}: 
3712 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
3713 @end table
3717 @node OMP_NESTED
3718 @section @env{OMP_NESTED} -- Nested parallel regions
3719 @cindex Environment Variable
3720 @cindex Implementation specific setting
3721 @table @asis
3722 @item @emph{ICV:} @var{max-active-levels-var}
3723 @item @emph{Scope:} data environment
3724 @item @emph{Description}:
3725 Enable or disable nested parallel regions, i.e., whether team members
3726 are allowed to create new teams.  The value of this environment variable 
3727 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
3728 of maximum active nested regions supported is by default set to the
3729 maximum supported, otherwise it is set to one.  If
3730 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
3731 setting.  If both are undefined, nested parallel regions are enabled if
3732 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
3733 more than one item, otherwise they are disabled by default.
3735 Note that the @code{OMP_NESTED} environment variable was deprecated in
3736 the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
3738 @item @emph{See also}:
3739 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
3740 @ref{OMP_MAX_ACTIVE_LEVELS}
3742 @item @emph{Reference}: 
3743 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
3744 @end table
3748 @node OMP_NUM_TEAMS
3749 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
3750 @cindex Environment Variable
3751 @table @asis
3752 @item @emph{ICV:} @var{nteams-var}
3753 @item @emph{Scope:} device
3754 @item @emph{Description}:
3755 Specifies the upper bound for number of teams to use in teams regions
3756 without explicit @code{num_teams} clause.  The value of this variable shall
3757 be a positive integer.  If undefined it defaults to 0 which means
3758 implementation defined upper bound.
3760 @item @emph{See also}:
3761 @ref{omp_set_num_teams}
3763 @item @emph{Reference}: 
3764 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
3765 @end table
3769 @node OMP_NUM_THREADS
3770 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
3771 @cindex Environment Variable
3772 @cindex Implementation specific setting
3773 @table @asis
3774 @item @emph{ICV:} @var{nthreads-var}
3775 @item @emph{Scope:} data environment
3776 @item @emph{Description}:
3777 Specifies the default number of threads to use in parallel regions.  The 
3778 value of this variable shall be a comma-separated list of positive integers;
3779 the value specifies the number of threads to use for the corresponding nested
3780 level.  Specifying more than one item in the list automatically enables
3781 nesting by default.  If undefined one thread per CPU is used.
3783 When a list with more than value is specified, it also affects the
3784 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3786 @item @emph{See also}:
3787 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
3789 @item @emph{Reference}: 
3790 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
3791 @end table
3795 @node OMP_PROC_BIND
3796 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
3797 @cindex Environment Variable
3798 @table @asis
3799 @item @emph{ICV:} @var{bind-var}
3800 @item @emph{Scope:} data environment
3801 @item @emph{Description}:
3802 Specifies whether threads may be moved between processors.  If set to
3803 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
3804 they may be moved.  Alternatively, a comma separated list with the
3805 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
3806 be used to specify the thread affinity policy for the corresponding nesting
3807 level.  With @code{PRIMARY} and @code{MASTER} the worker threads are in the
3808 same place partition as the primary thread.  With @code{CLOSE} those are
3809 kept close to the primary thread in contiguous place partitions.  And
3810 with @code{SPREAD} a sparse distribution
3811 across the place partitions is used.  Specifying more than one item in the
3812 list automatically enables nesting by default.
3814 When a list is specified, it also affects the @var{max-active-levels-var} ICV
3815 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3817 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
3818 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
3820 @item @emph{See also}:
3821 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
3822 @ref{OMP_MAX_ACTIVE_LEVELS}
3824 @item @emph{Reference}:
3825 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
3826 @end table
3830 @node OMP_PLACES
3831 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
3832 @cindex Environment Variable
3833 @table @asis
3834 @item @emph{ICV:} @var{place-partition-var}
3835 @item @emph{Scope:} implicit tasks
3836 @item @emph{Description}:
3837 The thread placement can be either specified using an abstract name or by an
3838 explicit list of the places.  The abstract names @code{threads}, @code{cores},
3839 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
3840 followed by a positive number in parentheses, which denotes the how many places
3841 shall be created.  With @code{threads} each place corresponds to a single
3842 hardware thread; @code{cores} to a single core with the corresponding number of
3843 hardware threads; with @code{sockets} the place corresponds to a single
3844 socket; with @code{ll_caches} to a set of cores that shares the last level
3845 cache on the device; and @code{numa_domains} to a set of cores for which their
3846 closest memory on the device is the same memory and at a similar distance from
3847 the cores.  The resulting placement can be shown by setting the
3848 @env{OMP_DISPLAY_ENV} environment variable.
3850 Alternatively, the placement can be specified explicitly as comma-separated
3851 list of places.  A place is specified by set of nonnegative numbers in curly
3852 braces, denoting the hardware threads.  The curly braces can be omitted
3853 when only a single number has been specified.  The hardware threads
3854 belonging to a place can either be specified as comma-separated list of
3855 nonnegative thread numbers or using an interval.  Multiple places can also be
3856 either specified by a comma-separated list of places or by an interval.  To
3857 specify an interval, a colon followed by the count is placed after
3858 the hardware thread number or the place.  Optionally, the length can be
3859 followed by a colon and the stride number -- otherwise a unit stride is
3860 assumed.  Placing an exclamation mark (@code{!}) directly before a curly
3861 brace or numbers inside the curly braces (excluding intervals)
3862 excludes those hardware threads.
3864 For instance, the following specifies the same places list:
3865 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
3866 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
3868 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
3869 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
3870 between CPUs following no placement policy.
3872 @item @emph{See also}:
3873 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
3874 @ref{OMP_DISPLAY_ENV}
3876 @item @emph{Reference}:
3877 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
3878 @end table
3882 @node OMP_STACKSIZE
3883 @section @env{OMP_STACKSIZE} -- Set default thread stack size
3884 @cindex Environment Variable
3885 @table @asis
3886 @item @emph{ICV:} @var{stacksize-var}
3887 @item @emph{Scope:} device
3888 @item @emph{Description}:
3889 Set the default thread stack size in kilobytes, unless the number
3890 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
3891 case the size is, respectively, in bytes, kilobytes, megabytes
3892 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
3893 which gets the number of bytes as an argument.  If the stack size cannot
3894 be set due to system constraints, an error is reported and the initial
3895 stack size is left unchanged.  If undefined, the stack size is system
3896 dependent.
3898 @item @emph{See also}:
3899 @ref{GOMP_STACKSIZE}
3901 @item @emph{Reference}: 
3902 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
3903 @end table
3907 @node OMP_SCHEDULE
3908 @section @env{OMP_SCHEDULE} -- How threads are scheduled
3909 @cindex Environment Variable
3910 @cindex Implementation specific setting
3911 @table @asis
3912 @item @emph{ICV:} @var{run-sched-var}
3913 @item @emph{Scope:} data environment
3914 @item @emph{Description}:
3915 Allows to specify @code{schedule type} and @code{chunk size}. 
3916 The value of the variable shall have the form: @code{type[,chunk]} where
3917 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
3918 The optional @code{chunk} size shall be a positive integer.  If undefined,
3919 dynamic scheduling and a chunk size of 1 is used.
3921 @item @emph{See also}:
3922 @ref{omp_set_schedule}
3924 @item @emph{Reference}: 
3925 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
3926 @end table
3930 @node OMP_TARGET_OFFLOAD
3931 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
3932 @cindex Environment Variable
3933 @cindex Implementation specific setting
3934 @table @asis
3935 @item @emph{ICV:} @var{target-offload-var}
3936 @item @emph{Scope:} global
3937 @item @emph{Description}:
3938 Specifies the behavior with regard to offloading code to a device.  This
3939 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
3940 or @code{DEFAULT}.
3942 If set to @code{MANDATORY}, the program terminates with an error if
3943 any device construct or device memory routine uses a device that is unavailable
3944 or not supported by the implementation, or uses a non-conforming device number.
3945 If set to @code{DISABLED}, then offloading is disabled and all code runs on
3946 the host. If set to @code{DEFAULT}, the program tries offloading to the
3947 device first, then falls back to running code on the host if it cannot.
3949 If undefined, then the program behaves as if @code{DEFAULT} was set.
3951 Note: Even with @code{MANDATORY}, no run-time termination is performed when
3952 the device number in a @code{device} clause or argument to a device memory
3953 routine is for host, which includes using the device number in the
3954 @var{default-device-var} ICV.  However, the initial value of
3955 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
3957 @item @emph{See also}:
3958 @ref{OMP_DEFAULT_DEVICE}
3960 @item @emph{Reference}:
3961 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
3962 @end table
3966 @node OMP_TEAMS_THREAD_LIMIT
3967 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
3968 @cindex Environment Variable
3969 @table @asis
3970 @item @emph{ICV:} @var{teams-thread-limit-var}
3971 @item @emph{Scope:} device
3972 @item @emph{Description}:
3973 Specifies an upper bound for the number of threads to use by each contention
3974 group created by a teams construct without explicit @code{thread_limit}
3975 clause.  The value of this variable shall be a positive integer.  If undefined,
3976 the value of 0 is used which stands for an implementation defined upper
3977 limit.
3979 @item @emph{See also}:
3980 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
3982 @item @emph{Reference}: 
3983 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
3984 @end table
3988 @node OMP_THREAD_LIMIT
3989 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
3990 @cindex Environment Variable
3991 @table @asis
3992 @item @emph{ICV:} @var{thread-limit-var}
3993 @item @emph{Scope:} data environment
3994 @item @emph{Description}:
3995 Specifies the number of threads to use for the whole program.  The
3996 value of this variable shall be a positive integer.  If undefined,
3997 the number of threads is not limited.
3999 @item @emph{See also}:
4000 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
4002 @item @emph{Reference}: 
4003 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4004 @end table
4008 @node OMP_WAIT_POLICY
4009 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4010 @cindex Environment Variable
4011 @table @asis
4012 @item @emph{Description}:
4013 Specifies whether waiting threads should be active or passive.  If
4014 the value is @code{PASSIVE}, waiting threads should not consume CPU
4015 power while waiting; while the value is @code{ACTIVE} specifies that
4016 they should.  If undefined, threads wait actively for a short time
4017 before waiting passively.
4019 @item @emph{See also}:
4020 @ref{GOMP_SPINCOUNT}
4022 @item @emph{Reference}: 
4023 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4024 @end table
4028 @node GOMP_CPU_AFFINITY
4029 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4030 @cindex Environment Variable
4031 @table @asis
4032 @item @emph{Description}:
4033 Binds threads to specific CPUs.  The variable should contain a space-separated
4034 or comma-separated list of CPUs.  This list may contain different kinds of 
4035 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
4036 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
4037 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4038 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
4039 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4040 and 14 respectively and then starts assigning back from the beginning of
4041 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4043 There is no libgomp library routine to determine whether a CPU affinity
4044 specification is in effect.  As a workaround, language-specific library 
4045 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
4046 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
4047 environment variable.  A defined CPU affinity on startup cannot be changed 
4048 or disabled during the runtime of the application.
4050 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4051 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
4052 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4053 @code{FALSE}, the host system handles the assignment of threads to CPUs.
4055 @item @emph{See also}:
4056 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4057 @end table
4061 @node GOMP_DEBUG
4062 @section @env{GOMP_DEBUG} -- Enable debugging output
4063 @cindex Environment Variable
4064 @table @asis
4065 @item @emph{Description}:
4066 Enable debugging output.  The variable should be set to @code{0}
4067 (disabled, also the default if not set), or @code{1} (enabled).
4069 If enabled, some debugging output is printed during execution.
4070 This is currently not specified in more detail, and subject to change.
4071 @end table
4075 @node GOMP_STACKSIZE
4076 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
4077 @cindex Environment Variable
4078 @cindex Implementation specific setting
4079 @table @asis
4080 @item @emph{Description}:
4081 Set the default thread stack size in kilobytes.  This is different from
4082 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
4083 argument.  If the stack size cannot be set due to system constraints, an 
4084 error is reported and the initial stack size is left unchanged.  If undefined,
4085 the stack size is system dependent.
4087 @item @emph{See also}:
4088 @ref{OMP_STACKSIZE}
4090 @item @emph{Reference}: 
4091 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4092 GCC Patches Mailinglist}, 
4093 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4094 GCC Patches Mailinglist}
4095 @end table
4099 @node GOMP_SPINCOUNT
4100 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4101 @cindex Environment Variable
4102 @cindex Implementation specific setting
4103 @table @asis
4104 @item @emph{Description}:
4105 Determines how long a threads waits actively with consuming CPU power
4106 before waiting passively without consuming CPU power.  The value may be
4107 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4108 integer which gives the number of spins of the busy-wait loop.  The
4109 integer may optionally be followed by the following suffixes acting
4110 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4111 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4112 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4113 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
4114 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4115 If there are more OpenMP threads than available CPUs, 1000 and 100
4116 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4117 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4118 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4120 @item @emph{See also}:
4121 @ref{OMP_WAIT_POLICY}
4122 @end table
4126 @node GOMP_RTEMS_THREAD_POOLS
4127 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4128 @cindex Environment Variable
4129 @cindex Implementation specific setting
4130 @table @asis
4131 @item @emph{Description}:
4132 This environment variable is only used on the RTEMS real-time operating system.
4133 It determines the scheduler instance specific thread pools.  The format for
4134 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4135 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4136 separated by @code{:} where:
4137 @itemize @bullet
4138 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
4139 instance.
4140 @item @code{$<priority>} is an optional priority for the worker threads of a
4141 thread pool according to @code{pthread_setschedparam}.  In case a priority
4142 value is omitted, then a worker thread inherits the priority of the OpenMP
4143 primary thread that created it.  The priority of the worker thread is not
4144 changed after creation, even if a new OpenMP primary thread using the worker has
4145 a different priority.
4146 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
4147 RTEMS application configuration.
4148 @end itemize
4149 In case no thread pool configuration is specified for a scheduler instance,
4150 then each OpenMP primary thread of this scheduler instance uses its own
4151 dynamically allocated thread pool.  To limit the worker thread count of the
4152 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4153 @item @emph{Example}:
4154 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4155 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4156 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
4157 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
4158 one thread pool available.  Since no priority is specified for this scheduler
4159 instance, the worker thread inherits the priority of the OpenMP primary thread
4160 that created it.  In the scheduler instance @code{WRK1} there are three thread
4161 pools available and their worker threads run at priority four.
4162 @end table
4166 @c ---------------------------------------------------------------------
4167 @c Enabling OpenACC
4168 @c ---------------------------------------------------------------------
4170 @node Enabling OpenACC
4171 @chapter Enabling OpenACC
4173 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
4174 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
4175 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4176 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4177 fixed source form.  The flag also arranges for automatic linking of the OpenACC
4178 runtime library (@ref{OpenACC Runtime Library Routines}).
4180 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4182 A complete description of all OpenACC directives accepted may be found in 
4183 the @uref{https://www.openacc.org, OpenACC} Application Programming
4184 Interface manual, version 2.6.
4188 @c ---------------------------------------------------------------------
4189 @c OpenACC Runtime Library Routines
4190 @c ---------------------------------------------------------------------
4192 @node OpenACC Runtime Library Routines
4193 @chapter OpenACC Runtime Library Routines
4195 The runtime routines described here are defined by section 3 of the OpenACC
4196 specifications in version 2.6.
4197 They have C linkage, and do not throw exceptions.
4198 Generally, they are available only for the host, with the exception of
4199 @code{acc_on_device}, which is available for both the host and the
4200 acceleration device.
4202 @menu
4203 * acc_get_num_devices::         Get number of devices for the given device
4204                                 type.
4205 * acc_set_device_type::         Set type of device accelerator to use.
4206 * acc_get_device_type::         Get type of device accelerator to be used.
4207 * acc_set_device_num::          Set device number to use.
4208 * acc_get_device_num::          Get device number to be used.
4209 * acc_get_property::            Get device property.
4210 * acc_async_test::              Tests for completion of a specific asynchronous
4211                                 operation.
4212 * acc_async_test_all::          Tests for completion of all asynchronous
4213                                 operations.
4214 * acc_wait::                    Wait for completion of a specific asynchronous
4215                                 operation.
4216 * acc_wait_all::                Waits for completion of all asynchronous
4217                                 operations.
4218 * acc_wait_all_async::          Wait for completion of all asynchronous
4219                                 operations.
4220 * acc_wait_async::              Wait for completion of asynchronous operations.
4221 * acc_init::                    Initialize runtime for a specific device type.
4222 * acc_shutdown::                Shuts down the runtime for a specific device
4223                                 type.
4224 * acc_on_device::               Whether executing on a particular device
4225 * acc_malloc::                  Allocate device memory.
4226 * acc_free::                    Free device memory.
4227 * acc_copyin::                  Allocate device memory and copy host memory to
4228                                 it.
4229 * acc_present_or_copyin::       If the data is not present on the device,
4230                                 allocate device memory and copy from host
4231                                 memory.
4232 * acc_create::                  Allocate device memory and map it to host
4233                                 memory.
4234 * acc_present_or_create::       If the data is not present on the device,
4235                                 allocate device memory and map it to host
4236                                 memory.
4237 * acc_copyout::                 Copy device memory to host memory.
4238 * acc_delete::                  Free device memory.
4239 * acc_update_device::           Update device memory from mapped host memory.
4240 * acc_update_self::             Update host memory from mapped device memory.
4241 * acc_map_data::                Map previously allocated device memory to host
4242                                 memory.
4243 * acc_unmap_data::              Unmap device memory from host memory.
4244 * acc_deviceptr::               Get device pointer associated with specific
4245                                 host address.
4246 * acc_hostptr::                 Get host pointer associated with specific
4247                                 device address.
4248 * acc_is_present::              Indicate whether host variable / array is
4249                                 present on device.
4250 * acc_memcpy_to_device::        Copy host memory to device memory.
4251 * acc_memcpy_from_device::      Copy device memory to host memory.
4252 * acc_attach::                  Let device pointer point to device-pointer target.
4253 * acc_detach::                  Let device pointer point to host-pointer target.
4255 API routines for target platforms.
4257 * acc_get_current_cuda_device:: Get CUDA device handle.
4258 * acc_get_current_cuda_context::Get CUDA context handle.
4259 * acc_get_cuda_stream::         Get CUDA stream handle.
4260 * acc_set_cuda_stream::         Set CUDA stream handle.
4262 API routines for the OpenACC Profiling Interface.
4264 * acc_prof_register::           Register callbacks.
4265 * acc_prof_unregister::         Unregister callbacks.
4266 * acc_prof_lookup::             Obtain inquiry functions.
4267 * acc_register_library::        Library registration.
4268 @end menu
4272 @node acc_get_num_devices
4273 @section @code{acc_get_num_devices} -- Get number of devices for given device type
4274 @table @asis
4275 @item @emph{Description}
4276 This function returns a value indicating the number of devices available
4277 for the device type specified in @var{devicetype}. 
4279 @item @emph{C/C++}:
4280 @multitable @columnfractions .20 .80
4281 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4282 @end multitable
4284 @item @emph{Fortran}:
4285 @multitable @columnfractions .20 .80
4286 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4287 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
4288 @end multitable
4290 @item @emph{Reference}:
4291 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4292 3.2.1.
4293 @end table
4297 @node acc_set_device_type
4298 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
4299 @table @asis
4300 @item @emph{Description}
4301 This function indicates to the runtime library which device type, specified
4302 in @var{devicetype}, to use when executing a parallel or kernels region. 
4304 @item @emph{C/C++}:
4305 @multitable @columnfractions .20 .80
4306 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4307 @end multitable
4309 @item @emph{Fortran}:
4310 @multitable @columnfractions .20 .80
4311 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4312 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4313 @end multitable
4315 @item @emph{Reference}:
4316 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4317 3.2.2.
4318 @end table
4322 @node acc_get_device_type
4323 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4324 @table @asis
4325 @item @emph{Description}
4326 This function returns what device type will be used when executing a
4327 parallel or kernels region.
4329 This function returns @code{acc_device_none} if
4330 @code{acc_get_device_type} is called from
4331 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4332 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4333 Interface}), that is, if the device is currently being initialized.
4335 @item @emph{C/C++}:
4336 @multitable @columnfractions .20 .80
4337 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4338 @end multitable
4340 @item @emph{Fortran}:
4341 @multitable @columnfractions .20 .80
4342 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4343 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4344 @end multitable
4346 @item @emph{Reference}:
4347 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4348 3.2.3.
4349 @end table
4353 @node acc_set_device_num
4354 @section @code{acc_set_device_num} -- Set device number to use.
4355 @table @asis
4356 @item @emph{Description}
4357 This function will indicate to the runtime which device number,
4358 specified by @var{devicenum}, associated with the specified device
4359 type @var{devicetype}.
4361 @item @emph{C/C++}:
4362 @multitable @columnfractions .20 .80
4363 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4364 @end multitable
4366 @item @emph{Fortran}:
4367 @multitable @columnfractions .20 .80
4368 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4369 @item                   @tab @code{integer devicenum}
4370 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4371 @end multitable
4373 @item @emph{Reference}:
4374 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4375 3.2.4.
4376 @end table
4380 @node acc_get_device_num
4381 @section @code{acc_get_device_num} -- Get device number to be used.
4382 @table @asis
4383 @item @emph{Description}
4384 This function returns which device number associated with the specified device
4385 type @var{devicetype}, will be used when executing a parallel or kernels
4386 region.
4388 @item @emph{C/C++}:
4389 @multitable @columnfractions .20 .80
4390 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4391 @end multitable
4393 @item @emph{Fortran}:
4394 @multitable @columnfractions .20 .80
4395 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4396 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4397 @item                   @tab @code{integer acc_get_device_num}
4398 @end multitable
4400 @item @emph{Reference}:
4401 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4402 3.2.5.
4403 @end table
4407 @node acc_get_property
4408 @section @code{acc_get_property} -- Get device property.
4409 @cindex acc_get_property
4410 @cindex acc_get_property_string
4411 @table @asis
4412 @item @emph{Description}
4413 These routines return the value of the specified @var{property} for the
4414 device being queried according to @var{devicenum} and @var{devicetype}.
4415 Integer-valued and string-valued properties are returned by
4416 @code{acc_get_property} and @code{acc_get_property_string} respectively.
4417 The Fortran @code{acc_get_property_string} subroutine returns the string
4418 retrieved in its fourth argument while the remaining entry points are
4419 functions, which pass the return value as their result.
4421 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
4422 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
4423 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
4424 for consistency and the return type of the @code{acc_get_property} function is
4425 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
4426 The parameter @code{acc_device_property} is still provided,
4427 but might be removed in a future version of GCC.
4429 @item @emph{C/C++}:
4430 @multitable @columnfractions .20 .80
4431 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4432 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4433 @end multitable
4435 @item @emph{Fortran}:
4436 @multitable @columnfractions .20 .80
4437 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
4438 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
4439 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
4440 @item                   @tab @code{integer devicenum}
4441 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4442 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
4443 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
4444 @item                   @tab @code{character(*) string}
4445 @end multitable
4447 @item @emph{Reference}:
4448 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4449 3.2.6.
4450 @end table
4454 @node acc_async_test
4455 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
4456 @table @asis
4457 @item @emph{Description}
4458 This function tests for completion of the asynchronous operation specified
4459 in @var{arg}. In C/C++, a non-zero value is returned to indicate
4460 the specified asynchronous operation has completed while Fortran returns
4461 @code{true}. If the asynchronous operation has not completed, C/C++ returns
4462 zero and Fortran returns @code{false}.
4464 @item @emph{C/C++}:
4465 @multitable @columnfractions .20 .80
4466 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
4467 @end multitable
4469 @item @emph{Fortran}:
4470 @multitable @columnfractions .20 .80
4471 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
4472 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
4473 @item                   @tab @code{logical acc_async_test}
4474 @end multitable
4476 @item @emph{Reference}:
4477 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4478 3.2.9.
4479 @end table
4483 @node acc_async_test_all
4484 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
4485 @table @asis
4486 @item @emph{Description}
4487 This function tests for completion of all asynchronous operations.
4488 In C/C++, a non-zero value is returned to indicate all asynchronous
4489 operations have completed while Fortran returns @code{true}. If
4490 any asynchronous operation has not completed, C/C++ returns zero and
4491 Fortran returns @code{false}.
4493 @item @emph{C/C++}:
4494 @multitable @columnfractions .20 .80
4495 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
4496 @end multitable
4498 @item @emph{Fortran}:
4499 @multitable @columnfractions .20 .80
4500 @item @emph{Interface}: @tab @code{function acc_async_test()}
4501 @item                   @tab @code{logical acc_get_device_num}
4502 @end multitable
4504 @item @emph{Reference}:
4505 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4506 3.2.10.
4507 @end table
4511 @node acc_wait
4512 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
4513 @table @asis
4514 @item @emph{Description}
4515 This function waits for completion of the asynchronous operation
4516 specified in @var{arg}.
4518 @item @emph{C/C++}:
4519 @multitable @columnfractions .20 .80
4520 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
4521 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
4522 @end multitable
4524 @item @emph{Fortran}:
4525 @multitable @columnfractions .20 .80
4526 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
4527 @item                   @tab @code{integer(acc_handle_kind) arg}
4528 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
4529 @item                                               @tab @code{integer(acc_handle_kind) arg}
4530 @end multitable
4532 @item @emph{Reference}:
4533 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4534 3.2.11.
4535 @end table
4539 @node acc_wait_all
4540 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
4541 @table @asis
4542 @item @emph{Description}
4543 This function waits for the completion of all asynchronous operations.
4545 @item @emph{C/C++}:
4546 @multitable @columnfractions .20 .80
4547 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
4548 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
4549 @end multitable
4551 @item @emph{Fortran}:
4552 @multitable @columnfractions .20 .80
4553 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
4554 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
4555 @end multitable
4557 @item @emph{Reference}:
4558 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4559 3.2.13.
4560 @end table
4564 @node acc_wait_all_async
4565 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
4566 @table @asis
4567 @item @emph{Description}
4568 This function enqueues a wait operation on the queue @var{async} for any
4569 and all asynchronous operations that have been previously enqueued on
4570 any queue.
4572 @item @emph{C/C++}:
4573 @multitable @columnfractions .20 .80
4574 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
4575 @end multitable
4577 @item @emph{Fortran}:
4578 @multitable @columnfractions .20 .80
4579 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
4580 @item                   @tab @code{integer(acc_handle_kind) async}
4581 @end multitable
4583 @item @emph{Reference}:
4584 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4585 3.2.14.
4586 @end table
4590 @node acc_wait_async
4591 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
4592 @table @asis
4593 @item @emph{Description}
4594 This function enqueues a wait operation on queue @var{async} for any and all
4595 asynchronous operations enqueued on queue @var{arg}.
4597 @item @emph{C/C++}:
4598 @multitable @columnfractions .20 .80
4599 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
4600 @end multitable
4602 @item @emph{Fortran}:
4603 @multitable @columnfractions .20 .80
4604 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
4605 @item                   @tab @code{integer(acc_handle_kind) arg, async}
4606 @end multitable
4608 @item @emph{Reference}:
4609 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4610 3.2.12.
4611 @end table
4615 @node acc_init
4616 @section @code{acc_init} -- Initialize runtime for a specific device type.
4617 @table @asis
4618 @item @emph{Description}
4619 This function initializes the runtime for the device type specified in
4620 @var{devicetype}.
4622 @item @emph{C/C++}:
4623 @multitable @columnfractions .20 .80
4624 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
4625 @end multitable
4627 @item @emph{Fortran}:
4628 @multitable @columnfractions .20 .80
4629 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
4630 @item                   @tab @code{integer(acc_device_kind) devicetype}
4631 @end multitable
4633 @item @emph{Reference}:
4634 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4635 3.2.7.
4636 @end table
4640 @node acc_shutdown
4641 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
4642 @table @asis
4643 @item @emph{Description}
4644 This function shuts down the runtime for the device type specified in
4645 @var{devicetype}.
4647 @item @emph{C/C++}:
4648 @multitable @columnfractions .20 .80
4649 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
4650 @end multitable
4652 @item @emph{Fortran}:
4653 @multitable @columnfractions .20 .80
4654 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
4655 @item                   @tab @code{integer(acc_device_kind) devicetype}
4656 @end multitable
4658 @item @emph{Reference}:
4659 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4660 3.2.8.
4661 @end table
4665 @node acc_on_device
4666 @section @code{acc_on_device} -- Whether executing on a particular device
4667 @table @asis
4668 @item @emph{Description}:
4669 This function returns whether the program is executing on a particular
4670 device specified in @var{devicetype}. In C/C++ a non-zero value is
4671 returned to indicate the device is executing on the specified device type.
4672 In Fortran, @code{true} is returned. If the program is not executing
4673 on the specified device type C/C++ returns zero, while Fortran
4674 returns @code{false}.
4676 @item @emph{C/C++}:
4677 @multitable @columnfractions .20 .80
4678 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
4679 @end multitable
4681 @item @emph{Fortran}:
4682 @multitable @columnfractions .20 .80
4683 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
4684 @item                   @tab @code{integer(acc_device_kind) devicetype}
4685 @item                   @tab @code{logical acc_on_device}
4686 @end multitable
4688 @item @emph{Reference}:
4689 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4690 3.2.17.
4691 @end table
4695 @node acc_malloc
4696 @section @code{acc_malloc} -- Allocate device memory.
4697 @table @asis
4698 @item @emph{Description}
4699 This function allocates @var{bytes} bytes of device memory. It returns
4700 the device address of the allocated memory.
4702 @item @emph{C/C++}:
4703 @multitable @columnfractions .20 .80
4704 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
4705 @end multitable
4707 @item @emph{Fortran}:
4708 @multitable @columnfractions .20 .80
4709 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
4710 @item                   @tab @code{integer(c_size_t), value :: bytes}
4711 @end multitable
4713 @item @emph{Reference}:
4714 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4715 3.2.18.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4716 3.2.16.
4717 @end table
4721 @node acc_free
4722 @section @code{acc_free} -- Free device memory.
4723 @table @asis
4724 @item @emph{Description}
4725 Free previously allocated device memory at the device address @code{data_dev}.
4727 @item @emph{C/C++}:
4728 @multitable @columnfractions .20 .80
4729 @item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
4730 @end multitable
4732 @item @emph{Fortran}:
4733 @multitable @columnfractions .20 .80
4734 @item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
4735 @item                   @tab @code{type(c_ptr), value :: data_dev}
4736 @end multitable
4738 @item @emph{Reference}:
4739 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4740 3.2.19.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4741 3.2.17.
4742 @end table
4746 @node acc_copyin
4747 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
4748 @table @asis
4749 @item @emph{Description}
4750 In C/C++, this function allocates @var{len} bytes of device memory
4751 and maps it to the specified host address in @var{a}. The device
4752 address of the newly allocated device memory is returned.
4754 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4755 a contiguous array section. The second form @var{a} specifies a
4756 variable or array element and @var{len} specifies the length in bytes.
4758 @item @emph{C/C++}:
4759 @multitable @columnfractions .20 .80
4760 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
4761 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
4762 @end multitable
4764 @item @emph{Fortran}:
4765 @multitable @columnfractions .20 .80
4766 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
4767 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4768 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
4769 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4770 @item                   @tab @code{integer len}
4771 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
4772 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4773 @item                   @tab @code{integer(acc_handle_kind) :: async}
4774 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
4775 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4776 @item                   @tab @code{integer len}
4777 @item                   @tab @code{integer(acc_handle_kind) :: async}
4778 @end multitable
4780 @item @emph{Reference}:
4781 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4782 3.2.20.
4783 @end table
4787 @node acc_present_or_copyin
4788 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
4789 @table @asis
4790 @item @emph{Description}
4791 This function tests if the host data specified by @var{a} and of length
4792 @var{len} is present or not. If it is not present, device memory
4793 is allocated and the host memory copied. The device address of
4794 the newly allocated device memory is returned.
4796 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4797 a contiguous array section. The second form @var{a} specifies a variable or
4798 array element and @var{len} specifies the length in bytes.
4800 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
4801 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
4803 @item @emph{C/C++}:
4804 @multitable @columnfractions .20 .80
4805 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
4806 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
4807 @end multitable
4809 @item @emph{Fortran}:
4810 @multitable @columnfractions .20 .80
4811 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
4812 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4813 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
4814 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4815 @item                   @tab @code{integer len}
4816 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
4817 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4818 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
4819 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4820 @item                   @tab @code{integer len}
4821 @end multitable
4823 @item @emph{Reference}:
4824 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4825 3.2.20.
4826 @end table
4830 @node acc_create
4831 @section @code{acc_create} -- Allocate device memory and map it to host memory.
4832 @table @asis
4833 @item @emph{Description}
4834 This function allocates device memory and maps it to host memory specified
4835 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
4836 the function returns the device address of the allocated device memory.
4838 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4839 a contiguous array section. The second form @var{a} specifies a variable or
4840 array element and @var{len} specifies the length in bytes.
4842 @item @emph{C/C++}:
4843 @multitable @columnfractions .20 .80
4844 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
4845 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
4846 @end multitable
4848 @item @emph{Fortran}:
4849 @multitable @columnfractions .20 .80
4850 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
4851 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4852 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
4853 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4854 @item                   @tab @code{integer len}
4855 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
4856 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4857 @item                   @tab @code{integer(acc_handle_kind) :: async}
4858 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
4859 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4860 @item                   @tab @code{integer len}
4861 @item                   @tab @code{integer(acc_handle_kind) :: async}
4862 @end multitable
4864 @item @emph{Reference}:
4865 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4866 3.2.21.
4867 @end table
4871 @node acc_present_or_create
4872 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
4873 @table @asis
4874 @item @emph{Description}
4875 This function tests if the host data specified by @var{a} and of length
4876 @var{len} is present or not. If it is not present, device memory
4877 is allocated and mapped to host memory. In C/C++, the device address
4878 of the newly allocated device memory is returned.
4880 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4881 a contiguous array section. The second form @var{a} specifies a variable or
4882 array element and @var{len} specifies the length in bytes.
4884 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
4885 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
4887 @item @emph{C/C++}:
4888 @multitable @columnfractions .20 .80
4889 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
4890 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
4891 @end multitable
4893 @item @emph{Fortran}:
4894 @multitable @columnfractions .20 .80
4895 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
4896 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4897 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
4898 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4899 @item                   @tab @code{integer len}
4900 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
4901 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4902 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
4903 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4904 @item                   @tab @code{integer len}
4905 @end multitable
4907 @item @emph{Reference}:
4908 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4909 3.2.21.
4910 @end table
4914 @node acc_copyout
4915 @section @code{acc_copyout} -- Copy device memory to host memory.
4916 @table @asis
4917 @item @emph{Description}
4918 This function copies mapped device memory to host memory which is specified
4919 by host address @var{a} for a length @var{len} bytes in C/C++.
4921 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4922 a contiguous array section. The second form @var{a} specifies a variable or
4923 array element and @var{len} specifies the length in bytes.
4925 @item @emph{C/C++}:
4926 @multitable @columnfractions .20 .80
4927 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
4928 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
4929 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
4930 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
4931 @end multitable
4933 @item @emph{Fortran}:
4934 @multitable @columnfractions .20 .80
4935 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
4936 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4937 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
4938 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4939 @item                   @tab @code{integer len}
4940 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
4941 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4942 @item                   @tab @code{integer(acc_handle_kind) :: async}
4943 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
4944 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4945 @item                   @tab @code{integer len}
4946 @item                   @tab @code{integer(acc_handle_kind) :: async}
4947 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
4948 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4949 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
4950 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4951 @item                   @tab @code{integer len}
4952 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
4953 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4954 @item                   @tab @code{integer(acc_handle_kind) :: async}
4955 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
4956 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4957 @item                   @tab @code{integer len}
4958 @item                   @tab @code{integer(acc_handle_kind) :: async}
4959 @end multitable
4961 @item @emph{Reference}:
4962 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4963 3.2.22.
4964 @end table
4968 @node acc_delete
4969 @section @code{acc_delete} -- Free device memory.
4970 @table @asis
4971 @item @emph{Description}
4972 This function frees previously allocated device memory specified by
4973 the device address @var{a} and the length of @var{len} bytes.
4975 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4976 a contiguous array section. The second form @var{a} specifies a variable or
4977 array element and @var{len} specifies the length in bytes.
4979 @item @emph{C/C++}:
4980 @multitable @columnfractions .20 .80
4981 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
4982 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
4983 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
4984 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
4985 @end multitable
4987 @item @emph{Fortran}:
4988 @multitable @columnfractions .20 .80
4989 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
4990 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4991 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
4992 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4993 @item                   @tab @code{integer len}
4994 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
4995 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4996 @item                   @tab @code{integer(acc_handle_kind) :: async}
4997 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
4998 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4999 @item                   @tab @code{integer len}
5000 @item                   @tab @code{integer(acc_handle_kind) :: async}
5001 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
5002 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5003 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5004 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5005 @item                   @tab @code{integer len}
5006 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5007 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5008 @item                   @tab @code{integer(acc_handle_kind) :: async}
5009 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5010 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5011 @item                   @tab @code{integer len}
5012 @item                   @tab @code{integer(acc_handle_kind) :: async}
5013 @end multitable
5015 @item @emph{Reference}:
5016 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5017 3.2.23.
5018 @end table
5022 @node acc_update_device
5023 @section @code{acc_update_device} -- Update device memory from mapped host memory.
5024 @table @asis
5025 @item @emph{Description}
5026 This function updates the device copy from the previously mapped host memory.
5027 The host memory is specified with the host address @var{a} and a length of
5028 @var{len} bytes.
5030 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5031 a contiguous array section. The second form @var{a} specifies a variable or
5032 array element and @var{len} specifies the length in bytes.
5034 @item @emph{C/C++}:
5035 @multitable @columnfractions .20 .80
5036 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5037 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5038 @end multitable
5040 @item @emph{Fortran}:
5041 @multitable @columnfractions .20 .80
5042 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5043 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5044 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5045 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5046 @item                   @tab @code{integer len}
5047 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5048 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5049 @item                   @tab @code{integer(acc_handle_kind) :: async}
5050 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5051 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5052 @item                   @tab @code{integer len}
5053 @item                   @tab @code{integer(acc_handle_kind) :: async}
5054 @end multitable
5056 @item @emph{Reference}:
5057 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5058 3.2.24.
5059 @end table
5063 @node acc_update_self
5064 @section @code{acc_update_self} -- Update host memory from mapped device memory.
5065 @table @asis
5066 @item @emph{Description}
5067 This function updates the host copy from the previously mapped device memory.
5068 The host memory is specified with the host address @var{a} and a length of
5069 @var{len} bytes.
5071 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5072 a contiguous array section. The second form @var{a} specifies a variable or
5073 array element and @var{len} specifies the length in bytes.
5075 @item @emph{C/C++}:
5076 @multitable @columnfractions .20 .80
5077 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5078 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5079 @end multitable
5081 @item @emph{Fortran}:
5082 @multitable @columnfractions .20 .80
5083 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5084 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5085 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5086 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5087 @item                   @tab @code{integer len}
5088 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5089 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5090 @item                   @tab @code{integer(acc_handle_kind) :: async}
5091 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5092 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5093 @item                   @tab @code{integer len}
5094 @item                   @tab @code{integer(acc_handle_kind) :: async}
5095 @end multitable
5097 @item @emph{Reference}:
5098 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5099 3.2.25.
5100 @end table
5104 @node acc_map_data
5105 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5106 @table @asis
5107 @item @emph{Description}
5108 This function maps previously allocated device and host memory. The device
5109 memory is specified with the device address @var{data_dev}. The host memory is
5110 specified with the host address @var{data_arg} and a length of @var{bytes}.
5112 @item @emph{C/C++}:
5113 @multitable @columnfractions .20 .80
5114 @item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5115 @end multitable
5117 @item @emph{Fortran}:
5118 @multitable @columnfractions .20 .80
5119 @item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5120 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5121 @item                   @tab @code{type(c_ptr), value :: data_dev}
5122 @item                   @tab @code{integer(c_size_t), value :: bytes}
5123 @end multitable
5125 @item @emph{Reference}:
5126 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5127 3.2.26.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5128 3.2.21.
5129 @end table
5133 @node acc_unmap_data
5134 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
5135 @table @asis
5136 @item @emph{Description}
5137 This function unmaps previously mapped device and host memory. The latter
5138 specified by @var{data_arg}.
5140 @item @emph{C/C++}:
5141 @multitable @columnfractions .20 .80
5142 @item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5143 @end multitable
5145 @item @emph{Fortran}:
5146 @multitable @columnfractions .20 .80
5147 @item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5148 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5149 @end multitable
5151 @item @emph{Reference}:
5152 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5153 3.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5154 3.2.22.
5155 @end table
5159 @node acc_deviceptr
5160 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5161 @table @asis
5162 @item @emph{Description}
5163 This function returns the device address that has been mapped to the
5164 host address specified by @var{data_arg}.
5166 @item @emph{C/C++}:
5167 @multitable @columnfractions .20 .80
5168 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5169 @end multitable
5171 @item @emph{Fortran}:
5172 @multitable @columnfractions .20 .80
5173 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5174 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5175 @end multitable
5177 @item @emph{Reference}:
5178 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5179 3.2.28.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5180 3.2.23.
5181 @end table
5185 @node acc_hostptr
5186 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5187 @table @asis
5188 @item @emph{Description}
5189 This function returns the host address that has been mapped to the
5190 device address specified by @var{data_dev}.
5192 @item @emph{C/C++}:
5193 @multitable @columnfractions .20 .80
5194 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5195 @end multitable
5197 @item @emph{Fortran}:
5198 @multitable @columnfractions .20 .80
5199 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5200 @item                   @tab @code{type(c_ptr), value :: data_dev}
5201 @end multitable
5203 @item @emph{Reference}:
5204 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5205 3.2.29.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5206 3.2.24.
5207 @end table
5211 @node acc_is_present
5212 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5213 @table @asis
5214 @item @emph{Description}
5215 This function indicates whether the specified host address in @var{a} and a
5216 length of @var{len} bytes is present on the device. In C/C++, a non-zero
5217 value is returned to indicate the presence of the mapped memory on the
5218 device. A zero is returned to indicate the memory is not mapped on the
5219 device.
5221 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5222 a contiguous array section. The second form @var{a} specifies a variable or
5223 array element and @var{len} specifies the length in bytes. If the host
5224 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5225 a @code{false} is return to indicate the mapped memory is not present.
5227 @item @emph{C/C++}:
5228 @multitable @columnfractions .20 .80
5229 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5230 @end multitable
5232 @item @emph{Fortran}:
5233 @multitable @columnfractions .20 .80
5234 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
5235 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5236 @item                   @tab @code{logical acc_is_present}
5237 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5238 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5239 @item                   @tab @code{integer len}
5240 @item                   @tab @code{logical acc_is_present}
5241 @end multitable
5243 @item @emph{Reference}:
5244 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5245 3.2.30.
5246 @end table
5250 @node acc_memcpy_to_device
5251 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5252 @table @asis
5253 @item @emph{Description}
5254 This function copies host memory specified by host address of
5255 @var{data_host_src} to device memory specified by the device address
5256 @var{data_dev_dest} for a length of @var{bytes} bytes.
5258 @item @emph{C/C++}:
5259 @multitable @columnfractions .20 .80
5260 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5261 @item                   @tab @code{h_void* data_host_src, size_t bytes);}
5262 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5263 @item                   @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5264 @end multitable
5266 @item @emph{Fortran}:
5267 @multitable @columnfractions .20 .80
5268 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5269 @item                   @tab @code{data_host_src, bytes)}
5270 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5271 @item                   @tab @code{data_host_src, bytes, async_arg)}
5272 @item                   @tab @code{type(c_ptr), value :: data_dev_dest}
5273 @item                   @tab @code{type(*), dimension(*) :: data_host_src}
5274 @item                   @tab @code{integer(c_size_t), value :: bytes}
5275 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5276 @end multitable
5278 @item @emph{Reference}:
5279 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5280 3.2.31  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5281 3.2.26.
5282 @end table
5286 @node acc_memcpy_from_device
5287 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5288 @table @asis
5289 @item @emph{Description}
5290 This function copies device memory specified by device address of
5291 @var{data_dev_src} to host memory specified by the host address
5292 @var{data_host_dest} for a length of @var{bytes} bytes.
5294 @item @emph{C/C++}:
5295 @multitable @columnfractions .20 .80
5296 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5297 @item                   @tab @code{d_void* data_dev_src, size_t bytes);}
5298 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5299 @item                   @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5300 @end multitable
5302 @item @emph{Fortran}:
5303 @multitable @columnfractions .20 .80
5304 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5305 @item                   @tab @code{data_dev_src, bytes)}
5306 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5307 @item                   @tab @code{data_dev_src, bytes, async_arg)}
5308 @item                   @tab @code{type(*), dimension(*) :: data_host_dest}
5309 @item                   @tab @code{type(c_ptr), value :: data_dev_src}
5310 @item                   @tab @code{integer(c_size_t), value :: bytes}
5311 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5312 @end multitable
5314 @item @emph{Reference}:
5315 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5316 3.2.32.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5317 3.2.27.
5318 @end table
5322 @node acc_attach
5323 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
5324 @table @asis
5325 @item @emph{Description}
5326 This function updates a pointer on the device from pointing to a host-pointer
5327 address to pointing to the corresponding device data.
5329 @item @emph{C/C++}:
5330 @multitable @columnfractions .20 .80
5331 @item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5332 @item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5333 @end multitable
5335 @c @item @emph{Fortran}:
5336 @c @multitable @columnfractions .20 .80
5337 @c @item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5338 @c @item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5339 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5340 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5341 @c @end multitable
5343 @item @emph{Reference}:
5344 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5345 3.2.34.
5346 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5347 @c 3.2.29.
5348 @end table
5352 @node acc_detach
5353 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
5354 @table @asis
5355 @item @emph{Description}
5356 This function updates a pointer on the device from pointing to a device-pointer
5357 address to pointing to the corresponding host data.
5359 @item @emph{C/C++}:
5360 @multitable @columnfractions .20 .80
5361 @item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5362 @item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5363 @item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5364 @item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
5365 @end multitable
5367 @c @item @emph{Fortran}:
5368 @c @multitable @columnfractions .20 .80
5369 @c @item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
5370 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
5371 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
5372 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
5373 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5374 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5375 @c @end multitable
5377 @item @emph{Reference}:
5378 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5379 3.2.35.
5380 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5381 @c 3.2.29.
5382 @end table
5386 @node acc_get_current_cuda_device
5387 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
5388 @table @asis
5389 @item @emph{Description}
5390 This function returns the CUDA device handle. This handle is the same
5391 as used by the CUDA Runtime or Driver API's.
5393 @item @emph{C/C++}:
5394 @multitable @columnfractions .20 .80
5395 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
5396 @end multitable
5398 @item @emph{Reference}:
5399 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5400 A.2.1.1.
5401 @end table
5405 @node acc_get_current_cuda_context
5406 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
5407 @table @asis
5408 @item @emph{Description}
5409 This function returns the CUDA context handle. This handle is the same
5410 as used by the CUDA Runtime or Driver API's.
5412 @item @emph{C/C++}:
5413 @multitable @columnfractions .20 .80
5414 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
5415 @end multitable
5417 @item @emph{Reference}:
5418 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5419 A.2.1.2.
5420 @end table
5424 @node acc_get_cuda_stream
5425 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
5426 @table @asis
5427 @item @emph{Description}
5428 This function returns the CUDA stream handle for the queue @var{async}.
5429 This handle is the same as used by the CUDA Runtime or Driver API's.
5431 @item @emph{C/C++}:
5432 @multitable @columnfractions .20 .80
5433 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
5434 @end multitable
5436 @item @emph{Reference}:
5437 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5438 A.2.1.3.
5439 @end table
5443 @node acc_set_cuda_stream
5444 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
5445 @table @asis
5446 @item @emph{Description}
5447 This function associates the stream handle specified by @var{stream} with
5448 the queue @var{async}.
5450 This cannot be used to change the stream handle associated with
5451 @code{acc_async_sync}.
5453 The return value is not specified.
5455 @item @emph{C/C++}:
5456 @multitable @columnfractions .20 .80
5457 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
5458 @end multitable
5460 @item @emph{Reference}:
5461 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5462 A.2.1.4.
5463 @end table
5467 @node acc_prof_register
5468 @section @code{acc_prof_register} -- Register callbacks.
5469 @table @asis
5470 @item @emph{Description}:
5471 This function registers callbacks.
5473 @item @emph{C/C++}:
5474 @multitable @columnfractions .20 .80
5475 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
5476 @end multitable
5478 @item @emph{See also}:
5479 @ref{OpenACC Profiling Interface}
5481 @item @emph{Reference}:
5482 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5483 5.3.
5484 @end table
5488 @node acc_prof_unregister
5489 @section @code{acc_prof_unregister} -- Unregister callbacks.
5490 @table @asis
5491 @item @emph{Description}:
5492 This function unregisters callbacks.
5494 @item @emph{C/C++}:
5495 @multitable @columnfractions .20 .80
5496 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
5497 @end multitable
5499 @item @emph{See also}:
5500 @ref{OpenACC Profiling Interface}
5502 @item @emph{Reference}:
5503 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5504 5.3.
5505 @end table
5509 @node acc_prof_lookup
5510 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
5511 @table @asis
5512 @item @emph{Description}:
5513 Function to obtain inquiry functions.
5515 @item @emph{C/C++}:
5516 @multitable @columnfractions .20 .80
5517 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
5518 @end multitable
5520 @item @emph{See also}:
5521 @ref{OpenACC Profiling Interface}
5523 @item @emph{Reference}:
5524 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5525 5.3.
5526 @end table
5530 @node acc_register_library
5531 @section @code{acc_register_library} -- Library registration.
5532 @table @asis
5533 @item @emph{Description}:
5534 Function for library registration.
5536 @item @emph{C/C++}:
5537 @multitable @columnfractions .20 .80
5538 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
5539 @end multitable
5541 @item @emph{See also}:
5542 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
5544 @item @emph{Reference}:
5545 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5546 5.3.
5547 @end table
5551 @c ---------------------------------------------------------------------
5552 @c OpenACC Environment Variables
5553 @c ---------------------------------------------------------------------
5555 @node OpenACC Environment Variables
5556 @chapter OpenACC Environment Variables
5558 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
5559 are defined by section 4 of the OpenACC specification in version 2.0.
5560 The variable @env{ACC_PROFLIB}
5561 is defined by section 4 of the OpenACC specification in version 2.6.
5563 @menu
5564 * ACC_DEVICE_TYPE::
5565 * ACC_DEVICE_NUM::
5566 * ACC_PROFLIB::
5567 @end menu
5571 @node ACC_DEVICE_TYPE
5572 @section @code{ACC_DEVICE_TYPE}
5573 @table @asis
5574 @item @emph{Description}:
5575 Control the default device type to use when executing compute regions.
5576 If unset, the code can be run on any device type, favoring a non-host
5577 device type.
5579 Supported values in GCC (if compiled in) are
5580 @itemize
5581 @item @code{host}
5582 @item @code{nvidia}
5583 @item @code{radeon}
5584 @end itemize
5585 @item @emph{Reference}:
5586 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5587 4.1.
5588 @end table
5592 @node ACC_DEVICE_NUM
5593 @section @code{ACC_DEVICE_NUM}
5594 @table @asis
5595 @item @emph{Description}:
5596 Control which device, identified by device number, is the default device.
5597 The value must be a nonnegative integer less than the number of devices.
5598 If unset, device number zero is used.
5599 @item @emph{Reference}:
5600 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5601 4.2.
5602 @end table
5606 @node ACC_PROFLIB
5607 @section @code{ACC_PROFLIB}
5608 @table @asis
5609 @item @emph{Description}:
5610 Semicolon-separated list of dynamic libraries that are loaded as profiling
5611 libraries.  Each library must provide at least the @code{acc_register_library}
5612 routine.  Each library file is found as described by the documentation of
5613 @code{dlopen} of your operating system.
5614 @item @emph{See also}:
5615 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
5617 @item @emph{Reference}:
5618 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5619 4.3.
5620 @end table
5624 @c ---------------------------------------------------------------------
5625 @c CUDA Streams Usage
5626 @c ---------------------------------------------------------------------
5628 @node CUDA Streams Usage
5629 @chapter CUDA Streams Usage
5631 This applies to the @code{nvptx} plugin only.
5633 The library provides elements that perform asynchronous movement of
5634 data and asynchronous operation of computing constructs.  This
5635 asynchronous functionality is implemented by making use of CUDA
5636 streams@footnote{See "Stream Management" in "CUDA Driver API",
5637 TRM-06703-001, Version 5.5, for additional information}.
5639 The primary means by that the asynchronous functionality is accessed
5640 is through the use of those OpenACC directives which make use of the
5641 @code{async} and @code{wait} clauses.  When the @code{async} clause is
5642 first used with a directive, it creates a CUDA stream.  If an
5643 @code{async-argument} is used with the @code{async} clause, then the
5644 stream is associated with the specified @code{async-argument}.
5646 Following the creation of an association between a CUDA stream and the
5647 @code{async-argument} of an @code{async} clause, both the @code{wait}
5648 clause and the @code{wait} directive can be used.  When either the
5649 clause or directive is used after stream creation, it creates a
5650 rendezvous point whereby execution waits until all operations
5651 associated with the @code{async-argument}, that is, stream, have
5652 completed.
5654 Normally, the management of the streams that are created as a result of
5655 using the @code{async} clause, is done without any intervention by the
5656 caller.  This implies the association between the @code{async-argument}
5657 and the CUDA stream is maintained for the lifetime of the program.
5658 However, this association can be changed through the use of the library
5659 function @code{acc_set_cuda_stream}.  When the function
5660 @code{acc_set_cuda_stream} is called, the CUDA stream that was
5661 originally associated with the @code{async} clause is destroyed.
5662 Caution should be taken when changing the association as subsequent
5663 references to the @code{async-argument} refer to a different
5664 CUDA stream.
5668 @c ---------------------------------------------------------------------
5669 @c OpenACC Library Interoperability
5670 @c ---------------------------------------------------------------------
5672 @node OpenACC Library Interoperability
5673 @chapter OpenACC Library Interoperability
5675 @section Introduction
5677 The OpenACC library uses the CUDA Driver API, and may interact with
5678 programs that use the Runtime library directly, or another library
5679 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
5680 "Interactions with the CUDA Driver API" in
5681 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
5682 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
5683 for additional information on library interoperability.}.
5684 This chapter describes the use cases and what changes are
5685 required in order to use both the OpenACC library and the CUBLAS and Runtime
5686 libraries within a program.
5688 @section First invocation: NVIDIA CUBLAS library API
5690 In this first use case (see below), a function in the CUBLAS library is called
5691 prior to any of the functions in the OpenACC library. More specifically, the
5692 function @code{cublasCreate()}.
5694 When invoked, the function initializes the library and allocates the
5695 hardware resources on the host and the device on behalf of the caller. Once
5696 the initialization and allocation has completed, a handle is returned to the
5697 caller. The OpenACC library also requires initialization and allocation of
5698 hardware resources. Since the CUBLAS library has already allocated the
5699 hardware resources for the device, all that is left to do is to initialize
5700 the OpenACC library and acquire the hardware resources on the host.
5702 Prior to calling the OpenACC function that initializes the library and
5703 allocate the host hardware resources, you need to acquire the device number
5704 that was allocated during the call to @code{cublasCreate()}. The invoking of the
5705 runtime library function @code{cudaGetDevice()} accomplishes this. Once
5706 acquired, the device number is passed along with the device type as
5707 parameters to the OpenACC library function @code{acc_set_device_num()}.
5709 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
5710 library uses the  context that was created during the call to
5711 @code{cublasCreate()}. In other words, both libraries share the
5712 same context.
5714 @smallexample
5715     /* Create the handle */
5716     s = cublasCreate(&h);
5717     if (s != CUBLAS_STATUS_SUCCESS)
5718     @{
5719         fprintf(stderr, "cublasCreate failed %d\n", s);
5720         exit(EXIT_FAILURE);
5721     @}
5723     /* Get the device number */
5724     e = cudaGetDevice(&dev);
5725     if (e != cudaSuccess)
5726     @{
5727         fprintf(stderr, "cudaGetDevice failed %d\n", e);
5728         exit(EXIT_FAILURE);
5729     @}
5731     /* Initialize OpenACC library and use device 'dev' */
5732     acc_set_device_num(dev, acc_device_nvidia);
5734 @end smallexample
5735 @center Use Case 1 
5737 @section First invocation: OpenACC library API
5739 In this second use case (see below), a function in the OpenACC library is
5740 called prior to any of the functions in the CUBLAS library. More specifically,
5741 the function @code{acc_set_device_num()}.
5743 In the use case presented here, the function @code{acc_set_device_num()}
5744 is used to both initialize the OpenACC library and allocate the hardware
5745 resources on the host and the device. In the call to the function, the
5746 call parameters specify which device to use and what device
5747 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
5748 is but one method to initialize the OpenACC library and allocate the
5749 appropriate hardware resources. Other methods are available through the
5750 use of environment variables and these is discussed in the next section.
5752 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
5753 functions can be called as seen with multiple calls being made to
5754 @code{acc_copyin()}. In addition, calls can be made to functions in the
5755 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
5756 subsequent to the calls to @code{acc_copyin()}.
5757 As seen in the previous use case, a call to @code{cublasCreate()}
5758 initializes the CUBLAS library and allocates the hardware resources on the
5759 host and the device.  However, since the device has already been allocated,
5760 @code{cublasCreate()} only initializes the CUBLAS library and allocates
5761 the appropriate hardware resources on the host. The context that was created
5762 as part of the OpenACC initialization is shared with the CUBLAS library,
5763 similarly to the first use case.
5765 @smallexample
5766     dev = 0;
5768     acc_set_device_num(dev, acc_device_nvidia);
5770     /* Copy the first set to the device */
5771     d_X = acc_copyin(&h_X[0], N * sizeof (float));
5772     if (d_X == NULL)
5773     @{ 
5774         fprintf(stderr, "copyin error h_X\n");
5775         exit(EXIT_FAILURE);
5776     @}
5778     /* Copy the second set to the device */
5779     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
5780     if (d_Y == NULL)
5781     @{ 
5782         fprintf(stderr, "copyin error h_Y1\n");
5783         exit(EXIT_FAILURE);
5784     @}
5786     /* Create the handle */
5787     s = cublasCreate(&h);
5788     if (s != CUBLAS_STATUS_SUCCESS)
5789     @{
5790         fprintf(stderr, "cublasCreate failed %d\n", s);
5791         exit(EXIT_FAILURE);
5792     @}
5794     /* Perform saxpy using CUBLAS library function */
5795     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
5796     if (s != CUBLAS_STATUS_SUCCESS)
5797     @{
5798         fprintf(stderr, "cublasSaxpy failed %d\n", s);
5799         exit(EXIT_FAILURE);
5800     @}
5802     /* Copy the results from the device */
5803     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
5805 @end smallexample
5806 @center Use Case 2
5808 @section OpenACC library and environment variables
5810 There are two environment variables associated with the OpenACC library
5811 that may be used to control the device type and device number:
5812 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
5813 environment variables can be used as an alternative to calling
5814 @code{acc_set_device_num()}. As seen in the second use case, the device
5815 type and device number were specified using @code{acc_set_device_num()}.
5816 If however, the aforementioned environment variables were set, then the
5817 call to @code{acc_set_device_num()} would not be required.
5820 The use of the environment variables is only relevant when an OpenACC function
5821 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
5822 is called prior to a call to an OpenACC function, then you must call
5823 @code{acc_set_device_num()}@footnote{More complete information
5824 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
5825 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
5826 Application Programming Interface”, Version 2.6.}
5830 @c ---------------------------------------------------------------------
5831 @c OpenACC Profiling Interface
5832 @c ---------------------------------------------------------------------
5834 @node OpenACC Profiling Interface
5835 @chapter OpenACC Profiling Interface
5837 @section Implementation Status and Implementation-Defined Behavior
5839 We're implementing the OpenACC Profiling Interface as defined by the
5840 OpenACC 2.6 specification.  We're clarifying some aspects here as
5841 @emph{implementation-defined behavior}, while they're still under
5842 discussion within the OpenACC Technical Committee.
5844 This implementation is tuned to keep the performance impact as low as
5845 possible for the (very common) case that the Profiling Interface is
5846 not enabled.  This is relevant, as the Profiling Interface affects all
5847 the @emph{hot} code paths (in the target code, not in the offloaded
5848 code).  Users of the OpenACC Profiling Interface can be expected to
5849 understand that performance is impacted to some degree once the
5850 Profiling Interface is enabled: for example, because of the
5851 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
5852 every event that has been registered.
5854 We're not yet accounting for the fact that @cite{OpenACC events may
5855 occur during event processing}.
5856 We just handle one case specially, as required by CUDA 9.0
5857 @command{nvprof}, that @code{acc_get_device_type}
5858 (@ref{acc_get_device_type})) may be called from
5859 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
5860 callbacks.
5862 We're not yet implementing initialization via a
5863 @code{acc_register_library} function that is either statically linked
5864 in, or dynamically via @env{LD_PRELOAD}.
5865 Initialization via @code{acc_register_library} functions dynamically
5866 loaded via the @env{ACC_PROFLIB} environment variable does work, as
5867 does directly calling @code{acc_prof_register},
5868 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
5870 As currently there are no inquiry functions defined, calls to
5871 @code{acc_prof_lookup} always returns @code{NULL}.
5873 There aren't separate @emph{start}, @emph{stop} events defined for the
5874 event types @code{acc_ev_create}, @code{acc_ev_delete},
5875 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
5876 should be triggered before or after the actual device-specific call is
5877 made.  We trigger them after.
5879 Remarks about data provided to callbacks:
5881 @table @asis
5883 @item @code{acc_prof_info.event_type}
5884 It's not clear if for @emph{nested} event callbacks (for example,
5885 @code{acc_ev_enqueue_launch_start} as part of a parent compute
5886 construct), this should be set for the nested event
5887 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
5888 construct should remain (@code{acc_ev_compute_construct_start}).  In
5889 this implementation, the value generally corresponds to the
5890 innermost nested event type.
5892 @item @code{acc_prof_info.device_type}
5893 @itemize
5895 @item
5896 For @code{acc_ev_compute_construct_start}, and in presence of an
5897 @code{if} clause with @emph{false} argument, this still refers to
5898 the offloading device type.
5899 It's not clear if that's the expected behavior.
5901 @item
5902 Complementary to the item before, for
5903 @code{acc_ev_compute_construct_end}, this is set to
5904 @code{acc_device_host} in presence of an @code{if} clause with
5905 @emph{false} argument.
5906 It's not clear if that's the expected behavior.
5908 @end itemize
5910 @item @code{acc_prof_info.thread_id}
5911 Always @code{-1}; not yet implemented.
5913 @item @code{acc_prof_info.async}
5914 @itemize
5916 @item
5917 Not yet implemented correctly for
5918 @code{acc_ev_compute_construct_start}.
5920 @item
5921 In a compute construct, for host-fallback
5922 execution/@code{acc_device_host} it always is
5923 @code{acc_async_sync}.
5924 It is unclear if that is the expected behavior.
5926 @item
5927 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
5928 it will always be @code{acc_async_sync}.
5929 It is unclear if that is the expected behavior.
5931 @end itemize
5933 @item @code{acc_prof_info.async_queue}
5934 There is no @cite{limited number of asynchronous queues} in libgomp.
5935 This always has the same value as @code{acc_prof_info.async}.
5937 @item @code{acc_prof_info.src_file}
5938 Always @code{NULL}; not yet implemented.
5940 @item @code{acc_prof_info.func_name}
5941 Always @code{NULL}; not yet implemented.
5943 @item @code{acc_prof_info.line_no}
5944 Always @code{-1}; not yet implemented.
5946 @item @code{acc_prof_info.end_line_no}
5947 Always @code{-1}; not yet implemented.
5949 @item @code{acc_prof_info.func_line_no}
5950 Always @code{-1}; not yet implemented.
5952 @item @code{acc_prof_info.func_end_line_no}
5953 Always @code{-1}; not yet implemented.
5955 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
5956 Relating to @code{acc_prof_info.event_type} discussed above, in this
5957 implementation, this will always be the same value as
5958 @code{acc_prof_info.event_type}.
5960 @item @code{acc_event_info.*.parent_construct}
5961 @itemize
5963 @item
5964 Will be @code{acc_construct_parallel} for all OpenACC compute
5965 constructs as well as many OpenACC Runtime API calls; should be the
5966 one matching the actual construct, or
5967 @code{acc_construct_runtime_api}, respectively.
5969 @item
5970 Will be @code{acc_construct_enter_data} or
5971 @code{acc_construct_exit_data} when processing variable mappings
5972 specified in OpenACC @emph{declare} directives; should be
5973 @code{acc_construct_declare}.
5975 @item
5976 For implicit @code{acc_ev_device_init_start},
5977 @code{acc_ev_device_init_end}, and explicit as well as implicit
5978 @code{acc_ev_alloc}, @code{acc_ev_free},
5979 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5980 @code{acc_ev_enqueue_download_start}, and
5981 @code{acc_ev_enqueue_download_end}, will be
5982 @code{acc_construct_parallel}; should reflect the real parent
5983 construct.
5985 @end itemize
5987 @item @code{acc_event_info.*.implicit}
5988 For @code{acc_ev_alloc}, @code{acc_ev_free},
5989 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5990 @code{acc_ev_enqueue_download_start}, and
5991 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
5992 also for explicit usage.
5994 @item @code{acc_event_info.data_event.var_name}
5995 Always @code{NULL}; not yet implemented.
5997 @item @code{acc_event_info.data_event.host_ptr}
5998 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
5999 @code{NULL}.
6001 @item @code{typedef union acc_api_info}
6002 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6003 Information}.  This should obviously be @code{typedef @emph{struct}
6004 acc_api_info}.
6006 @item @code{acc_api_info.device_api}
6007 Possibly not yet implemented correctly for
6008 @code{acc_ev_compute_construct_start},
6009 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6010 will always be @code{acc_device_api_none} for these event types.
6011 For @code{acc_ev_enter_data_start}, it will be
6012 @code{acc_device_api_none} in some cases.
6014 @item @code{acc_api_info.device_type}
6015 Always the same as @code{acc_prof_info.device_type}.
6017 @item @code{acc_api_info.vendor}
6018 Always @code{-1}; not yet implemented.
6020 @item @code{acc_api_info.device_handle}
6021 Always @code{NULL}; not yet implemented.
6023 @item @code{acc_api_info.context_handle}
6024 Always @code{NULL}; not yet implemented.
6026 @item @code{acc_api_info.async_handle}
6027 Always @code{NULL}; not yet implemented.
6029 @end table
6031 Remarks about certain event types:
6033 @table @asis
6035 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6036 @itemize
6038 @item
6039 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6040 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6041 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6042 When a compute construct triggers implicit
6043 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6044 events, they currently aren't @emph{nested within} the corresponding
6045 @code{acc_ev_compute_construct_start} and
6046 @code{acc_ev_compute_construct_end}, but they're currently observed
6047 @emph{before} @code{acc_ev_compute_construct_start}.
6048 It's not clear what to do: the standard asks us provide a lot of
6049 details to the @code{acc_ev_compute_construct_start} callback, without
6050 (implicitly) initializing a device before?
6052 @item
6053 Callbacks for these event types will not be invoked for calls to the
6054 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
6055 It's not clear if they should be.
6057 @end itemize
6059 @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}
6060 @itemize
6062 @item
6063 Callbacks for these event types will also be invoked for OpenACC
6064 @emph{host_data} constructs.
6065 It's not clear if they should be.
6067 @item
6068 Callbacks for these event types will also be invoked when processing
6069 variable mappings specified in OpenACC @emph{declare} directives.
6070 It's not clear if they should be.
6072 @end itemize
6074 @end table
6076 Callbacks for the following event types will be invoked, but dispatch
6077 and information provided therein has not yet been thoroughly reviewed:
6079 @itemize
6080 @item @code{acc_ev_alloc}
6081 @item @code{acc_ev_free}
6082 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6083 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6084 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6085 @end itemize
6087 During device initialization, and finalization, respectively,
6088 callbacks for the following event types will not yet be invoked:
6090 @itemize
6091 @item @code{acc_ev_alloc}
6092 @item @code{acc_ev_free}
6093 @end itemize
6095 Callbacks for the following event types have not yet been implemented,
6096 so currently won't be invoked:
6098 @itemize
6099 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6100 @item @code{acc_ev_runtime_shutdown}
6101 @item @code{acc_ev_create}, @code{acc_ev_delete}
6102 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6103 @end itemize
6105 For the following runtime library functions, not all expected
6106 callbacks will be invoked (mostly concerning implicit device
6107 initialization):
6109 @itemize
6110 @item @code{acc_get_num_devices}
6111 @item @code{acc_set_device_type}
6112 @item @code{acc_get_device_type}
6113 @item @code{acc_set_device_num}
6114 @item @code{acc_get_device_num}
6115 @item @code{acc_init}
6116 @item @code{acc_shutdown}
6117 @end itemize
6119 Aside from implicit device initialization, for the following runtime
6120 library functions, no callbacks will be invoked for shared-memory
6121 offloading devices (it's not clear if they should be):
6123 @itemize
6124 @item @code{acc_malloc}
6125 @item @code{acc_free}
6126 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6127 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6128 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6129 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6130 @item @code{acc_update_device}, @code{acc_update_device_async}
6131 @item @code{acc_update_self}, @code{acc_update_self_async}
6132 @item @code{acc_map_data}, @code{acc_unmap_data}
6133 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6134 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6135 @end itemize
6137 @c ---------------------------------------------------------------------
6138 @c OpenMP-Implementation Specifics
6139 @c ---------------------------------------------------------------------
6141 @node OpenMP-Implementation Specifics
6142 @chapter OpenMP-Implementation Specifics
6144 @menu
6145 * Implementation-defined ICV Initialization::
6146 * OpenMP Context Selectors::
6147 * Memory allocation::
6148 @end menu
6150 @node Implementation-defined ICV Initialization
6151 @section Implementation-defined ICV Initialization
6152 @cindex Implementation specific setting
6154 @multitable @columnfractions .30 .70
6155 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6156 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6157 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6158 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6159 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6160 @item @var{num-devices-var} @tab Number of non-host devices found
6161 by GCC's run-time library
6162 @item @var{num-procs-var} @tab The number of CPU cores on the
6163 initial device, except that affinity settings might lead to a
6164 smaller number.  On non-host devices, the value of the
6165 @var{nthreads-var} ICV.
6166 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6167 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6168 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6169 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6170 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6171 @ref{GOMP_SPINCOUNT}
6172 @end multitable
6174 @node OpenMP Context Selectors
6175 @section OpenMP Context Selectors
6177 @code{vendor} is always @code{gnu}. References are to the GCC manual.
6179 @c NOTE: Only the following selectors have been implemented. To add
6180 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6181 @c has to be implemented; cf. also PR target/105640.
6182 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6184 For the host compiler, @code{kind} always matches @code{host}; for the
6185 offloading architectures AMD GCN and Nvidia PTX, @code{kind} always matches
6186 @code{gpu}.  For the x86 family of computers, AMD GCN and Nvidia PTX
6187 the following traits are supported in addition; while OpenMP is supported
6188 on more architectures, GCC currently does not match any @code{arch} or
6189 @code{isa} traits for those.
6191 @multitable @columnfractions .65 .30
6192 @headitem @code{arch} @tab @code{isa}
6193 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6194       @code{i586}, @code{i686}, @code{ia32}
6195       @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6196 @item @code{amdgcn}, @code{gcn}
6197       @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
6198       @code{gfx803} is supported as an alias for @code{fiji}.}
6199 @item @code{nvptx}, @code{nvptx64}
6200       @tab See @code{-march=} in ``Nvidia PTX Options''
6201 @end multitable
6203 @node Memory allocation
6204 @section Memory allocation
6206 The description below applies to:
6208 @itemize
6209 @item Explicit use of the OpenMP API routines, see
6210       @ref{Memory Management Routines}.
6211 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
6212       constant expression with value @code{omp_default_mem_alloc} and no
6213       @code{align} modifier has been specified. (In that case, the normal
6214       @code{malloc} allocation is used.)
6215 @item Using the @code{allocate} directive for automatic/stack variables, except
6216       when the @code{allocator} clause is a constant expression with value
6217       @code{omp_default_mem_alloc} and no @code{align} clause has been
6218       specified. (In that case, the normal allocation is used: stack allocation
6219       and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6220       @option{-fstack-arrays}].)
6221 @item Using the @code{allocate} directive for variable in static memory is
6222       currently not supported (compile time error).
6223 @item In Fortran, the @code{allocators} directive and the executable
6224       @code{allocate} directive for Fortran pointers and allocatables is
6225       supported, but requires that files containing those directives has to be
6226       compiled with @option{-fopenmp-allocators}.  Additionally, all files that
6227       might explicitly or implicitly deallocate memory allocated that way must
6228       also be compiled with that option.
6229 @end itemize
6231 For the available predefined allocators and, as applicable, their associated
6232 predefined memory spaces and for the available traits and their default values,
6233 see @ref{OMP_ALLOCATOR}.  Predefined allocators without an associated memory
6234 space use the @code{omp_default_mem_space} memory space.
6236 For the memory spaces, the following applies:
6237 @itemize
6238 @item @code{omp_default_mem_space} is supported
6239 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6240 @item @code{omp_low_lat_mem_space} is only available on supported devices,
6241       and maps to @code{omp_default_mem_space} otherwise.
6242 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6243       unless the memkind library is available
6244 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6245       unless the memkind library is available
6246 @end itemize
6248 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6249 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
6250 creating memory allocators requesting
6252 @itemize
6253 @item the memory space @code{omp_high_bw_mem_space}
6254 @item the memory space @code{omp_large_cap_mem_space}
6255 @item the @code{partition} trait @code{interleaved}; note that for
6256       @code{omp_large_cap_mem_space} the allocation will not be interleaved
6257 @end itemize
6259 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6260 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6261 memory allocators requesting
6263 @itemize
6264 @item the @code{partition} trait @code{nearest}, except when both the
6265 libmemkind library is available and the memory space is either
6266 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6267 @end itemize
6269 Note that the numa library will round up the allocation size to a multiple of
6270 the system page size; therefore, consider using it only with large data or
6271 by sharing allocations via the @code{pool_size} trait.  Furthermore, the Linux
6272 kernel does not guarantee that an allocation will always be on the nearest NUMA
6273 node nor that after reallocation the same node will be used.  Note additionally
6274 that, on Linux, the default setting of the memory placement policy is to use the
6275 current node; therefore, unless the memory placement policy has been overridden,
6276 the @code{partition} trait @code{environment} (the default) will be effectively
6277 a @code{nearest} allocation.
6279 Additional notes regarding the traits:
6280 @itemize
6281 @item The @code{pinned} trait is supported on Linux hosts, but is subject to
6282       the OS @code{ulimit}/@code{rlimit} locked memory settings.
6283 @item The default for the @code{pool_size} trait is no pool and for every
6284       (re)allocation the associated library routine is called, which might
6285       internally use a memory pool.
6286 @item For the @code{partition} trait, the partition part size will be the same
6287       as the requested size (i.e. @code{interleaved} or @code{blocked} has no
6288       effect), except for @code{interleaved} when the memkind library is
6289       available.  Furthermore, for @code{nearest} and unless the numa library
6290       is available, the memory might not be on the same NUMA node as thread
6291       that allocated the memory; on Linux, this is in particular the case when
6292       the memory placement policy is set to preferred.
6293 @item The @code{access} trait has no effect such that memory is always
6294       accessible by all threads.
6295 @item The @code{sync_hint} trait has no effect.
6296 @end itemize
6298 See also:
6299 @ref{Offload-Target Specifics}
6301 @c ---------------------------------------------------------------------
6302 @c Offload-Target Specifics
6303 @c ---------------------------------------------------------------------
6305 @node Offload-Target Specifics
6306 @chapter Offload-Target Specifics
6308 The following sections present notes on the offload-target specifics
6310 @menu
6311 * AMD Radeon::
6312 * nvptx::
6313 @end menu
6315 @node AMD Radeon
6316 @section AMD Radeon (GCN)
6318 On the hardware side, there is the hierarchy (fine to coarse):
6319 @itemize
6320 @item work item (thread)
6321 @item wavefront
6322 @item work group
6323 @item compute unit (CU)
6324 @end itemize
6326 All OpenMP and OpenACC levels are used, i.e.
6327 @itemize
6328 @item OpenMP's simd and OpenACC's vector map to work items (thread)
6329 @item OpenMP's threads (``parallel'') and OpenACC's workers map
6330       to wavefronts
6331 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6332       size of the number of teams or gangs, respectively.
6333 @end itemize
6335 The used sizes are
6336 @itemize
6337 @item Number of teams is the specified @code{num_teams} (OpenMP) or
6338       @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
6339       by two times the number of CU.
6340 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
6341       @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
6342       overrides this if smaller.
6343 @item The wavefront has 102 scalars and 64 vectors
6344 @item Number of workitems is always 64
6345 @item The hardware permits maximally 40 workgroups/CU and
6346       16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
6347 @item 80 scalars registers and 24 vector registers in non-kernel functions
6348       (the chosen procedure-calling API).
6349 @item For the kernel itself: as many as register pressure demands (number of
6350       teams and number of threads, scaled down if registers are exhausted)
6351 @end itemize
6353 The implementation remark:
6354 @itemize
6355 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
6356       using the C library @code{printf} functions and the Fortran
6357       @code{print}/@code{write} statements.
6358 @item Reverse offload regions (i.e. @code{target} regions with
6359       @code{device(ancestor:1)}) are processed serially per @code{target} region
6360       such that the next reverse offload region is only executed after the previous
6361       one returned.
6362 @item OpenMP code that has a @code{requires} directive with
6363       @code{unified_shared_memory} will remove any GCN device from the list of
6364       available devices (``host fallback'').
6365 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
6366       environment variable; the default is 32 kiB per thread.
6367 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6368       the @code{access} trait is set to @code{cgroup}.  The default pool size
6369       is automatically scaled to share the 64 kiB LDS memory between the number
6370       of teams configured to run on each compute-unit, but may be adjusted at
6371       runtime by setting environment variable
6372       @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
6373 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6374       because the definition implies the @code{omp_atv_all} trait; main
6375       graphics memory is used instead.
6376 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6377       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6378       preference, and fall back to main graphics memory when the low-latency
6379       pool is exhausted.
6380 @end itemize
6384 @node nvptx
6385 @section nvptx
6387 On the hardware side, there is the hierarchy (fine to coarse):
6388 @itemize
6389 @item thread
6390 @item warp
6391 @item thread block
6392 @item streaming multiprocessor
6393 @end itemize
6395 All OpenMP and OpenACC levels are used, i.e.
6396 @itemize
6397 @item OpenMP's simd and OpenACC's vector map to threads
6398 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
6399 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6400       size of the number of teams or gangs, respectively.
6401 @end itemize
6403 The used sizes are
6404 @itemize
6405 @item The @code{warp_size} is always 32
6406 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
6407 @item The number of teams is limited by the number of blocks the device can
6408       host simultaneously.
6409 @end itemize
6411 Additional information can be obtained by setting the environment variable to
6412 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
6413 parameters).
6415 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
6416 which caches the JIT in the user's directory (see CUDA documentation; can be
6417 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
6419 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
6420 options still affect the used PTX ISA code and, thus, the requirements on
6421 CUDA version and hardware.
6423 The implementation remark:
6424 @itemize
6425 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
6426       using the C library @code{printf} functions. Note that the Fortran
6427       @code{print}/@code{write} statements are not supported, yet.
6428 @item Compilation OpenMP code that contains @code{requires reverse_offload}
6429       requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
6430       is not supported.
6431 @item For code containing reverse offload (i.e. @code{target} regions with
6432       @code{device(ancestor:1)}), there is a slight performance penalty
6433       for @emph{all} target regions, consisting mostly of shutdown delay
6434       Per device, reverse offload regions are processed serially such that
6435       the next reverse offload region is only executed after the previous
6436       one returned.
6437 @item OpenMP code that has a @code{requires} directive with
6438       @code{unified_shared_memory} will remove any nvptx device from the
6439       list of available devices (``host fallback'').
6440 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
6441       in the GCC manual.
6442 @item The OpenMP routines @code{omp_target_memcpy_rect} and
6443       @code{omp_target_memcpy_rect_async} and the @code{target update}
6444       directive for non-contiguous list items will use the 2D and 3D
6445       memory-copy functions of the CUDA library.  Higher dimensions will
6446       call those functions in a loop and are therefore supported.
6447 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6448       the @code{access} trait is set to @code{cgroup}, the ISA is at least
6449       @code{sm_53}, and the PTX version is at least 4.1.  The default pool size
6450       is 8 kiB per team, but may be adjusted at runtime by setting environment
6451       variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}.  The maximum value is
6452       limited by the available hardware, and care should be taken that the
6453       selected pool size does not unduly limit the number of teams that can
6454       run simultaneously.
6455 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6456       because the definition implies the @code{omp_atv_all} trait; main
6457       graphics memory is used instead.
6458 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6459       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6460       preference, and fall back to main graphics memory when the low-latency
6461       pool is exhausted.
6462 @end itemize
6465 @c ---------------------------------------------------------------------
6466 @c The libgomp ABI
6467 @c ---------------------------------------------------------------------
6469 @node The libgomp ABI
6470 @chapter The libgomp ABI
6472 The following sections present notes on the external ABI as 
6473 presented by libgomp.  Only maintainers should need them.
6475 @menu
6476 * Implementing MASTER construct::
6477 * Implementing CRITICAL construct::
6478 * Implementing ATOMIC construct::
6479 * Implementing FLUSH construct::
6480 * Implementing BARRIER construct::
6481 * Implementing THREADPRIVATE construct::
6482 * Implementing PRIVATE clause::
6483 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
6484 * Implementing REDUCTION clause::
6485 * Implementing PARALLEL construct::
6486 * Implementing FOR construct::
6487 * Implementing ORDERED construct::
6488 * Implementing SECTIONS construct::
6489 * Implementing SINGLE construct::
6490 * Implementing OpenACC's PARALLEL construct::
6491 @end menu
6494 @node Implementing MASTER construct
6495 @section Implementing MASTER construct
6497 @smallexample
6498 if (omp_get_thread_num () == 0)
6499   block
6500 @end smallexample
6502 Alternately, we generate two copies of the parallel subfunction
6503 and only include this in the version run by the primary thread.
6504 Surely this is not worthwhile though...
6508 @node Implementing CRITICAL construct
6509 @section Implementing CRITICAL construct
6511 Without a specified name,
6513 @smallexample
6514   void GOMP_critical_start (void);
6515   void GOMP_critical_end (void);
6516 @end smallexample
6518 so that we don't get COPY relocations from libgomp to the main
6519 application.
6521 With a specified name, use omp_set_lock and omp_unset_lock with
6522 name being transformed into a variable declared like
6524 @smallexample
6525   omp_lock_t gomp_critical_user_<name> __attribute__((common))
6526 @end smallexample
6528 Ideally the ABI would specify that all zero is a valid unlocked
6529 state, and so we wouldn't need to initialize this at
6530 startup.
6534 @node Implementing ATOMIC construct
6535 @section Implementing ATOMIC construct
6537 The target should implement the @code{__sync} builtins.
6539 Failing that we could add
6541 @smallexample
6542   void GOMP_atomic_enter (void)
6543   void GOMP_atomic_exit (void)
6544 @end smallexample
6546 which reuses the regular lock code, but with yet another lock
6547 object private to the library.
6551 @node Implementing FLUSH construct
6552 @section Implementing FLUSH construct
6554 Expands to the @code{__sync_synchronize} builtin.
6558 @node Implementing BARRIER construct
6559 @section Implementing BARRIER construct
6561 @smallexample
6562   void GOMP_barrier (void)
6563 @end smallexample
6566 @node Implementing THREADPRIVATE construct
6567 @section Implementing THREADPRIVATE construct
6569 In _most_ cases we can map this directly to @code{__thread}.  Except
6570 that OMP allows constructors for C++ objects.  We can either
6571 refuse to support this (how often is it used?) or we can 
6572 implement something akin to .ctors.
6574 Even more ideally, this ctor feature is handled by extensions
6575 to the main pthreads library.  Failing that, we can have a set
6576 of entry points to register ctor functions to be called.
6580 @node Implementing PRIVATE clause
6581 @section Implementing PRIVATE clause
6583 In association with a PARALLEL, or within the lexical extent
6584 of a PARALLEL block, the variable becomes a local variable in
6585 the parallel subfunction.
6587 In association with FOR or SECTIONS blocks, create a new
6588 automatic variable within the current function.  This preserves
6589 the semantic of new variable creation.
6593 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6594 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6596 This seems simple enough for PARALLEL blocks.  Create a private 
6597 struct for communicating between the parent and subfunction.
6598 In the parent, copy in values for scalar and "small" structs;
6599 copy in addresses for others TREE_ADDRESSABLE types.  In the 
6600 subfunction, copy the value into the local variable.
6602 It is not clear what to do with bare FOR or SECTION blocks.
6603 The only thing I can figure is that we do something like:
6605 @smallexample
6606 #pragma omp for firstprivate(x) lastprivate(y)
6607 for (int i = 0; i < n; ++i)
6608   body;
6609 @end smallexample
6611 which becomes
6613 @smallexample
6615   int x = x, y;
6617   // for stuff
6619   if (i == n)
6620     y = y;
6622 @end smallexample
6624 where the "x=x" and "y=y" assignments actually have different
6625 uids for the two variables, i.e. not something you could write
6626 directly in C.  Presumably this only makes sense if the "outer"
6627 x and y are global variables.
6629 COPYPRIVATE would work the same way, except the structure 
6630 broadcast would have to happen via SINGLE machinery instead.
6634 @node Implementing REDUCTION clause
6635 @section Implementing REDUCTION clause
6637 The private struct mentioned in the previous section should have 
6638 a pointer to an array of the type of the variable, indexed by the 
6639 thread's @var{team_id}.  The thread stores its final value into the 
6640 array, and after the barrier, the primary thread iterates over the
6641 array to collect the values.
6644 @node Implementing PARALLEL construct
6645 @section Implementing PARALLEL construct
6647 @smallexample
6648   #pragma omp parallel
6649   @{
6650     body;
6651   @}
6652 @end smallexample
6654 becomes
6656 @smallexample
6657   void subfunction (void *data)
6658   @{
6659     use data;
6660     body;
6661   @}
6663   setup data;
6664   GOMP_parallel_start (subfunction, &data, num_threads);
6665   subfunction (&data);
6666   GOMP_parallel_end ();
6667 @end smallexample
6669 @smallexample
6670   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
6671 @end smallexample
6673 The @var{FN} argument is the subfunction to be run in parallel.
6675 The @var{DATA} argument is a pointer to a structure used to 
6676 communicate data in and out of the subfunction, as discussed
6677 above with respect to FIRSTPRIVATE et al.
6679 The @var{NUM_THREADS} argument is 1 if an IF clause is present
6680 and false, or the value of the NUM_THREADS clause, if
6681 present, or 0.
6683 The function needs to create the appropriate number of
6684 threads and/or launch them from the dock.  It needs to
6685 create the team structure and assign team ids.
6687 @smallexample
6688   void GOMP_parallel_end (void)
6689 @end smallexample
6691 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
6695 @node Implementing FOR construct
6696 @section Implementing FOR construct
6698 @smallexample
6699   #pragma omp parallel for
6700   for (i = lb; i <= ub; i++)
6701     body;
6702 @end smallexample
6704 becomes
6706 @smallexample
6707   void subfunction (void *data)
6708   @{
6709     long _s0, _e0;
6710     while (GOMP_loop_static_next (&_s0, &_e0))
6711     @{
6712       long _e1 = _e0, i;
6713       for (i = _s0; i < _e1; i++)
6714         body;
6715     @}
6716     GOMP_loop_end_nowait ();
6717   @}
6719   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
6720   subfunction (NULL);
6721   GOMP_parallel_end ();
6722 @end smallexample
6724 @smallexample
6725   #pragma omp for schedule(runtime)
6726   for (i = 0; i < n; i++)
6727     body;
6728 @end smallexample
6730 becomes
6732 @smallexample
6733   @{
6734     long i, _s0, _e0;
6735     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
6736       do @{
6737         long _e1 = _e0;
6738         for (i = _s0, i < _e0; i++)
6739           body;
6740       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
6741     GOMP_loop_end ();
6742   @}
6743 @end smallexample
6745 Note that while it looks like there is trickiness to propagating
6746 a non-constant STEP, there isn't really.  We're explicitly allowed
6747 to evaluate it as many times as we want, and any variables involved
6748 should automatically be handled as PRIVATE or SHARED like any other
6749 variables.  So the expression should remain evaluable in the 
6750 subfunction.  We can also pull it into a local variable if we like,
6751 but since its supposed to remain unchanged, we can also not if we like.
6753 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
6754 able to get away with no work-sharing context at all, since we can
6755 simply perform the arithmetic directly in each thread to divide up
6756 the iterations.  Which would mean that we wouldn't need to call any
6757 of these routines.
6759 There are separate routines for handling loops with an ORDERED
6760 clause.  Bookkeeping for that is non-trivial...
6764 @node Implementing ORDERED construct
6765 @section Implementing ORDERED construct
6767 @smallexample
6768   void GOMP_ordered_start (void)
6769   void GOMP_ordered_end (void)
6770 @end smallexample
6774 @node Implementing SECTIONS construct
6775 @section Implementing SECTIONS construct
6777 A block as 
6779 @smallexample
6780   #pragma omp sections
6781   @{
6782     #pragma omp section
6783     stmt1;
6784     #pragma omp section
6785     stmt2;
6786     #pragma omp section
6787     stmt3;
6788   @}
6789 @end smallexample
6791 becomes
6793 @smallexample
6794   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
6795     switch (i)
6796       @{
6797       case 1:
6798         stmt1;
6799         break;
6800       case 2:
6801         stmt2;
6802         break;
6803       case 3:
6804         stmt3;
6805         break;
6806       @}
6807   GOMP_barrier ();
6808 @end smallexample
6811 @node Implementing SINGLE construct
6812 @section Implementing SINGLE construct
6814 A block like 
6816 @smallexample
6817   #pragma omp single
6818   @{
6819     body;
6820   @}
6821 @end smallexample
6823 becomes
6825 @smallexample
6826   if (GOMP_single_start ())
6827     body;
6828   GOMP_barrier ();
6829 @end smallexample
6831 while 
6833 @smallexample
6834   #pragma omp single copyprivate(x)
6835     body;
6836 @end smallexample
6838 becomes
6840 @smallexample
6841   datap = GOMP_single_copy_start ();
6842   if (datap == NULL)
6843     @{
6844       body;
6845       data.x = x;
6846       GOMP_single_copy_end (&data);
6847     @}
6848   else
6849     x = datap->x;
6850   GOMP_barrier ();
6851 @end smallexample
6855 @node Implementing OpenACC's PARALLEL construct
6856 @section Implementing OpenACC's PARALLEL construct
6858 @smallexample
6859   void GOACC_parallel ()
6860 @end smallexample
6864 @c ---------------------------------------------------------------------
6865 @c Reporting Bugs
6866 @c ---------------------------------------------------------------------
6868 @node Reporting Bugs
6869 @chapter Reporting Bugs
6871 Bugs in the GNU Offloading and Multi Processing Runtime Library should
6872 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
6873 "openacc", or "openmp", or both to the keywords field in the bug
6874 report, as appropriate.
6878 @c ---------------------------------------------------------------------
6879 @c GNU General Public License
6880 @c ---------------------------------------------------------------------
6882 @include gpl_v3.texi
6886 @c ---------------------------------------------------------------------
6887 @c GNU Free Documentation License
6888 @c ---------------------------------------------------------------------
6890 @include fdl.texi
6894 @c ---------------------------------------------------------------------
6895 @c Funding Free Software
6896 @c ---------------------------------------------------------------------
6898 @include funding.texi
6900 @c ---------------------------------------------------------------------
6901 @c Index
6902 @c ---------------------------------------------------------------------
6904 @node Library Index
6905 @unnumbered Library Index
6907 @printindex cp
6909 @bye