d: Merge upstream dmd, druntime f8bae04558, phobos ba2ade9dec
[official-gcc.git] / libgomp / libgomp.texi
blobbf5c7a76fc99238e7f6d178573d6bf408d865985
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 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{coexecute} directive for Fortran @tab N @tab
519 @item Fortran DO CONCURRENT as associated loop in a @code{loop} construct
520       @tab N @tab
521 @item @code{threadset} clause in task-generating constructs @tab N @tab
522 @item @code{nowait} clause with reverse-offload @code{target} directives
523       @tab N @tab
524 @item Boolean argument to @code{nowait} and @code{nogroup} may be non constant
525       @tab N @tab
526 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
527 @item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
528       @tab N @tab
529 @item @code{omp_target_memset} and @code{omp_target_memset_rect_async} routines
530       @tab N @tab
531 @item Routines for obtaining memory spaces/allocators for shared/device memory
532       @tab N @tab
533 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
534 @item @code{omp_get_submemspace} routine @tab N @tab
535 @item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
536       values in @code{ompt_target_data_op_t} enum @tab N @tab
537 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
538 @end multitable
540 @unnumberedsubsec Other new TR 12 features
541 @multitable @columnfractions .60 .10 .25
542 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
543 @item Mapping lambda captures @tab N @tab
544 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
545 @end multitable
549 @c ---------------------------------------------------------------------
550 @c OpenMP Runtime Library Routines
551 @c ---------------------------------------------------------------------
553 @node Runtime Library Routines
554 @chapter OpenMP Runtime Library Routines
556 The runtime routines described here are defined by Section 18 of the OpenMP
557 specification in version 5.2.
559 @menu
560 * Thread Team Routines::
561 * Thread Affinity Routines::
562 * Teams Region Routines::
563 * Tasking Routines::
564 * Resource Relinquishing Routines::
565 * Device Information Routines::
566 * Device Memory Routines::
567 * Lock Routines::
568 * Timing Routines::
569 * Event Routine::
570 @c * Interoperability Routines::
571 * Memory Management Routines::
572 @c * Tool Control Routine::
573 * Environment Display Routine::
574 @end menu
578 @node Thread Team Routines
579 @section Thread Team Routines
581 Routines controlling threads in the current contention group.
582 They have C linkage and do not throw exceptions.
584 @menu
585 * omp_set_num_threads::         Set upper team size limit
586 * omp_get_num_threads::         Size of the active team
587 * omp_get_max_threads::         Maximum number of threads of parallel region
588 * omp_get_thread_num::          Current thread ID
589 * omp_in_parallel::             Whether a parallel region is active
590 * omp_set_dynamic::             Enable/disable dynamic teams
591 * omp_get_dynamic::             Dynamic teams setting
592 * omp_get_cancellation::        Whether cancellation support is enabled
593 * omp_set_nested::              Enable/disable nested parallel regions
594 * omp_get_nested::              Nested parallel regions
595 * omp_set_schedule::            Set the runtime scheduling method
596 * omp_get_schedule::            Obtain the runtime scheduling method
597 * omp_get_teams_thread_limit::  Maximum number of threads imposed by teams
598 * omp_get_supported_active_levels:: Maximum number of active regions supported
599 * omp_set_max_active_levels::   Limits the number of active parallel regions
600 * omp_get_max_active_levels::   Current maximum number of active regions
601 * omp_get_level::               Number of parallel regions
602 * omp_get_ancestor_thread_num:: Ancestor thread ID
603 * omp_get_team_size::           Number of threads in a team
604 * omp_get_active_level::        Number of active parallel regions
605 @end menu
609 @node omp_set_num_threads
610 @subsection @code{omp_set_num_threads} -- Set upper team size limit
611 @table @asis
612 @item @emph{Description}:
613 Specifies the number of threads used by default in subsequent parallel
614 sections, if those do not specify a @code{num_threads} clause.  The
615 argument of @code{omp_set_num_threads} shall be a positive integer.
617 @item @emph{C/C++}:
618 @multitable @columnfractions .20 .80
619 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
620 @end multitable
622 @item @emph{Fortran}:
623 @multitable @columnfractions .20 .80
624 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
625 @item                   @tab @code{integer, intent(in) :: num_threads}
626 @end multitable
628 @item @emph{See also}:
629 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
631 @item @emph{Reference}:
632 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
633 @end table
637 @node omp_get_num_threads
638 @subsection @code{omp_get_num_threads} -- Size of the active team
639 @table @asis
640 @item @emph{Description}:
641 Returns the number of threads in the current team.  In a sequential section of
642 the program @code{omp_get_num_threads} returns 1.
644 The default team size may be initialized at startup by the
645 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
646 of the current team may be set either by the @code{NUM_THREADS}
647 clause or by @code{omp_set_num_threads}.  If none of the above were
648 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
649 one thread per CPU online is used.
651 @item @emph{C/C++}:
652 @multitable @columnfractions .20 .80
653 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
654 @end multitable
656 @item @emph{Fortran}:
657 @multitable @columnfractions .20 .80
658 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
659 @end multitable
661 @item @emph{See also}:
662 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
664 @item @emph{Reference}:
665 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
666 @end table
670 @node omp_get_max_threads
671 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
672 @table @asis
673 @item @emph{Description}:
674 Return the maximum number of threads used for the current parallel region
675 that does not use the clause @code{num_threads}.
677 @item @emph{C/C++}:
678 @multitable @columnfractions .20 .80
679 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
680 @end multitable
682 @item @emph{Fortran}:
683 @multitable @columnfractions .20 .80
684 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
685 @end multitable
687 @item @emph{See also}:
688 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
690 @item @emph{Reference}:
691 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
692 @end table
696 @node omp_get_thread_num
697 @subsection @code{omp_get_thread_num} -- Current thread ID
698 @table @asis
699 @item @emph{Description}:
700 Returns a unique thread identification number within the current team.
701 In a sequential parts of the program, @code{omp_get_thread_num}
702 always returns 0.  In parallel regions the return value varies
703 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
704 value of the primary thread of a team is always 0.
706 @item @emph{C/C++}:
707 @multitable @columnfractions .20 .80
708 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
709 @end multitable
711 @item @emph{Fortran}:
712 @multitable @columnfractions .20 .80
713 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
714 @end multitable
716 @item @emph{See also}:
717 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
719 @item @emph{Reference}:
720 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
721 @end table
725 @node omp_in_parallel
726 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
727 @table @asis
728 @item @emph{Description}:
729 This function returns @code{true} if currently running in parallel,
730 @code{false} otherwise.  Here, @code{true} and @code{false} represent
731 their language-specific counterparts.
733 @item @emph{C/C++}:
734 @multitable @columnfractions .20 .80
735 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
736 @end multitable
738 @item @emph{Fortran}:
739 @multitable @columnfractions .20 .80
740 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
741 @end multitable
743 @item @emph{Reference}:
744 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
745 @end table
748 @node omp_set_dynamic
749 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
750 @table @asis
751 @item @emph{Description}:
752 Enable or disable the dynamic adjustment of the number of threads 
753 within a team.  The function takes the language-specific equivalent
754 of @code{true} and @code{false}, where @code{true} enables dynamic 
755 adjustment of team sizes and @code{false} disables it.
757 @item @emph{C/C++}:
758 @multitable @columnfractions .20 .80
759 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
760 @end multitable
762 @item @emph{Fortran}:
763 @multitable @columnfractions .20 .80
764 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
765 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
766 @end multitable
768 @item @emph{See also}:
769 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
771 @item @emph{Reference}:
772 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
773 @end table
777 @node omp_get_dynamic
778 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
779 @table @asis
780 @item @emph{Description}:
781 This function returns @code{true} if enabled, @code{false} otherwise. 
782 Here, @code{true} and @code{false} represent their language-specific 
783 counterparts.
785 The dynamic team setting may be initialized at startup by the 
786 @env{OMP_DYNAMIC} environment variable or at runtime using
787 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
788 disabled by default.
790 @item @emph{C/C++}:
791 @multitable @columnfractions .20 .80
792 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
793 @end multitable
795 @item @emph{Fortran}:
796 @multitable @columnfractions .20 .80
797 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
798 @end multitable
800 @item @emph{See also}:
801 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
803 @item @emph{Reference}:
804 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
805 @end table
809 @node omp_get_cancellation
810 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
811 @table @asis
812 @item @emph{Description}:
813 This function returns @code{true} if cancellation is activated, @code{false}
814 otherwise.  Here, @code{true} and @code{false} represent their language-specific
815 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
816 deactivated.
818 @item @emph{C/C++}:
819 @multitable @columnfractions .20 .80
820 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
821 @end multitable
823 @item @emph{Fortran}:
824 @multitable @columnfractions .20 .80
825 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
826 @end multitable
828 @item @emph{See also}:
829 @ref{OMP_CANCELLATION}
831 @item @emph{Reference}:
832 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
833 @end table
837 @node omp_set_nested
838 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
839 @table @asis
840 @item @emph{Description}:
841 Enable or disable nested parallel regions, i.e., whether team members
842 are allowed to create new teams.  The function takes the language-specific
843 equivalent of @code{true} and @code{false}, where @code{true} enables 
844 dynamic adjustment of team sizes and @code{false} disables it.
846 Enabling nested parallel regions also sets the maximum number of
847 active nested regions to the maximum supported.  Disabling nested parallel
848 regions sets the maximum number of active nested regions to one.
850 Note that the @code{omp_set_nested} API routine was deprecated
851 in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
853 @item @emph{C/C++}:
854 @multitable @columnfractions .20 .80
855 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
856 @end multitable
858 @item @emph{Fortran}:
859 @multitable @columnfractions .20 .80
860 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
861 @item                   @tab @code{logical, intent(in) :: nested}
862 @end multitable
864 @item @emph{See also}:
865 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
866 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
868 @item @emph{Reference}:
869 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
870 @end table
874 @node omp_get_nested
875 @subsection @code{omp_get_nested} -- Nested parallel regions
876 @table @asis
877 @item @emph{Description}:
878 This function returns @code{true} if nested parallel regions are
879 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
880 represent their language-specific counterparts.
882 The state of nested parallel regions at startup depends on several
883 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
884 and is set to greater than one, then nested parallel regions will be
885 enabled.  If not defined, then the value of the @env{OMP_NESTED}
886 environment variable will be followed if defined.  If neither are
887 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
888 are defined with a list of more than one value, then nested parallel
889 regions are enabled.  If none of these are defined, then nested parallel
890 regions are disabled by default.
892 Nested parallel regions can be enabled or disabled at runtime using
893 @code{omp_set_nested}, or by setting the maximum number of nested
894 regions with @code{omp_set_max_active_levels} to one to disable, or
895 above one to enable.
897 Note that the @code{omp_get_nested} API routine was deprecated
898 in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
900 @item @emph{C/C++}:
901 @multitable @columnfractions .20 .80
902 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
903 @end multitable
905 @item @emph{Fortran}:
906 @multitable @columnfractions .20 .80
907 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
908 @end multitable
910 @item @emph{See also}:
911 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
912 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
914 @item @emph{Reference}:
915 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
916 @end table
920 @node omp_set_schedule
921 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
922 @table @asis
923 @item @emph{Description}:
924 Sets the runtime scheduling method.  The @var{kind} argument can have the
925 value @code{omp_sched_static}, @code{omp_sched_dynamic},
926 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
927 @code{omp_sched_auto}, the chunk size is set to the value of
928 @var{chunk_size} if positive, or to the default value if zero or negative.
929 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
931 @item @emph{C/C++}
932 @multitable @columnfractions .20 .80
933 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
934 @end multitable
936 @item @emph{Fortran}:
937 @multitable @columnfractions .20 .80
938 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
939 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
940 @item                   @tab @code{integer chunk_size}
941 @end multitable
943 @item @emph{See also}:
944 @ref{omp_get_schedule}
945 @ref{OMP_SCHEDULE}
947 @item @emph{Reference}:
948 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
949 @end table
953 @node omp_get_schedule
954 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
955 @table @asis
956 @item @emph{Description}:
957 Obtain the runtime scheduling method.  The @var{kind} argument is set to
958 @code{omp_sched_static}, @code{omp_sched_dynamic},
959 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
960 @var{chunk_size}, is set to the chunk size.
962 @item @emph{C/C++}
963 @multitable @columnfractions .20 .80
964 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
965 @end multitable
967 @item @emph{Fortran}:
968 @multitable @columnfractions .20 .80
969 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
970 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
971 @item                   @tab @code{integer chunk_size}
972 @end multitable
974 @item @emph{See also}:
975 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
977 @item @emph{Reference}:
978 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
979 @end table
982 @node omp_get_teams_thread_limit
983 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
984 @table @asis
985 @item @emph{Description}:
986 Return the maximum number of threads that are able to participate in
987 each team created by a teams construct.
989 @item @emph{C/C++}:
990 @multitable @columnfractions .20 .80
991 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
992 @end multitable
994 @item @emph{Fortran}:
995 @multitable @columnfractions .20 .80
996 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
997 @end multitable
999 @item @emph{See also}:
1000 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1002 @item @emph{Reference}:
1003 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1004 @end table
1008 @node omp_get_supported_active_levels
1009 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1010 @table @asis
1011 @item @emph{Description}:
1012 This function returns the maximum number of nested, active parallel regions
1013 supported by this implementation.
1015 @item @emph{C/C++}
1016 @multitable @columnfractions .20 .80
1017 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1018 @end multitable
1020 @item @emph{Fortran}:
1021 @multitable @columnfractions .20 .80
1022 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1023 @end multitable
1025 @item @emph{See also}:
1026 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1028 @item @emph{Reference}:
1029 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1030 @end table
1034 @node omp_set_max_active_levels
1035 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1036 @table @asis
1037 @item @emph{Description}:
1038 This function limits the maximum allowed number of nested, active
1039 parallel regions.  @var{max_levels} must be less or equal to
1040 the value returned by @code{omp_get_supported_active_levels}.
1042 @item @emph{C/C++}
1043 @multitable @columnfractions .20 .80
1044 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1045 @end multitable
1047 @item @emph{Fortran}:
1048 @multitable @columnfractions .20 .80
1049 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1050 @item                   @tab @code{integer max_levels}
1051 @end multitable
1053 @item @emph{See also}:
1054 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1055 @ref{omp_get_supported_active_levels}
1057 @item @emph{Reference}:
1058 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1059 @end table
1063 @node omp_get_max_active_levels
1064 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1065 @table @asis
1066 @item @emph{Description}:
1067 This function obtains the maximum allowed number of nested, active parallel regions.
1069 @item @emph{C/C++}
1070 @multitable @columnfractions .20 .80
1071 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1072 @end multitable
1074 @item @emph{Fortran}:
1075 @multitable @columnfractions .20 .80
1076 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1077 @end multitable
1079 @item @emph{See also}:
1080 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1082 @item @emph{Reference}:
1083 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1084 @end table
1087 @node omp_get_level
1088 @subsection @code{omp_get_level} -- Obtain the current nesting level
1089 @table @asis
1090 @item @emph{Description}:
1091 This function returns the nesting level for the parallel blocks,
1092 which enclose the calling call.
1094 @item @emph{C/C++}
1095 @multitable @columnfractions .20 .80
1096 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1097 @end multitable
1099 @item @emph{Fortran}:
1100 @multitable @columnfractions .20 .80
1101 @item @emph{Interface}: @tab @code{integer function omp_level()}
1102 @end multitable
1104 @item @emph{See also}:
1105 @ref{omp_get_active_level}
1107 @item @emph{Reference}:
1108 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1109 @end table
1113 @node omp_get_ancestor_thread_num
1114 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1115 @table @asis
1116 @item @emph{Description}:
1117 This function returns the thread identification number for the given
1118 nesting level of the current thread.  For values of @var{level} outside
1119 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1120 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1122 @item @emph{C/C++}
1123 @multitable @columnfractions .20 .80
1124 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1125 @end multitable
1127 @item @emph{Fortran}:
1128 @multitable @columnfractions .20 .80
1129 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1130 @item                   @tab @code{integer level}
1131 @end multitable
1133 @item @emph{See also}:
1134 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1136 @item @emph{Reference}:
1137 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1138 @end table
1142 @node omp_get_team_size
1143 @subsection @code{omp_get_team_size} -- Number of threads in a team
1144 @table @asis
1145 @item @emph{Description}:
1146 This function returns the number of threads in a thread team to which
1147 either the current thread or its ancestor belongs.  For values of @var{level}
1148 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1149 1 is returned, and for @code{omp_get_level}, the result is identical
1150 to @code{omp_get_num_threads}.
1152 @item @emph{C/C++}:
1153 @multitable @columnfractions .20 .80
1154 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1155 @end multitable
1157 @item @emph{Fortran}:
1158 @multitable @columnfractions .20 .80
1159 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1160 @item                   @tab @code{integer level}
1161 @end multitable
1163 @item @emph{See also}:
1164 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1166 @item @emph{Reference}:
1167 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1168 @end table
1172 @node omp_get_active_level
1173 @subsection @code{omp_get_active_level} -- Number of parallel regions
1174 @table @asis
1175 @item @emph{Description}:
1176 This function returns the nesting level for the active parallel blocks,
1177 which enclose the calling call.
1179 @item @emph{C/C++}
1180 @multitable @columnfractions .20 .80
1181 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1182 @end multitable
1184 @item @emph{Fortran}:
1185 @multitable @columnfractions .20 .80
1186 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1187 @end multitable
1189 @item @emph{See also}:
1190 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1192 @item @emph{Reference}:
1193 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1194 @end table
1198 @node Thread Affinity Routines
1199 @section Thread Affinity Routines
1201 Routines controlling and accessing thread-affinity policies.
1202 They have C linkage and do not throw exceptions.
1204 @menu
1205 * omp_get_proc_bind::           Whether threads may be moved between CPUs
1206 @c * omp_get_num_places:: <fixme>
1207 @c * omp_get_place_num_procs:: <fixme>
1208 @c * omp_get_place_proc_ids:: <fixme>
1209 @c * omp_get_place_num:: <fixme>
1210 @c * omp_get_partition_num_places:: <fixme>
1211 @c * omp_get_partition_place_nums:: <fixme>
1212 @c * omp_set_affinity_format:: <fixme>
1213 @c * omp_get_affinity_format:: <fixme>
1214 @c * omp_display_affinity:: <fixme>
1215 @c * omp_capture_affinity:: <fixme>
1216 @end menu
1220 @node omp_get_proc_bind
1221 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1222 @table @asis
1223 @item @emph{Description}:
1224 This functions returns the currently active thread affinity policy, which is
1225 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
1226 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1227 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1228 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1230 @item @emph{C/C++}:
1231 @multitable @columnfractions .20 .80
1232 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1233 @end multitable
1235 @item @emph{Fortran}:
1236 @multitable @columnfractions .20 .80
1237 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1238 @end multitable
1240 @item @emph{See also}:
1241 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1243 @item @emph{Reference}:
1244 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1245 @end table
1249 @node Teams Region Routines
1250 @section Teams Region Routines
1252 Routines controlling the league of teams that are executed in a @code{teams}
1253 region.  They have C linkage and do not throw exceptions.
1255 @menu
1256 * omp_get_num_teams::           Number of teams
1257 * omp_get_team_num::            Get team number
1258 * omp_set_num_teams::           Set upper teams limit for teams region
1259 * omp_get_max_teams::           Maximum number of teams for teams region
1260 * omp_set_teams_thread_limit::  Set upper thread limit for teams construct
1261 * omp_get_thread_limit::        Maximum number of threads
1262 @end menu
1266 @node omp_get_num_teams
1267 @subsection @code{omp_get_num_teams} -- Number of teams
1268 @table @asis
1269 @item @emph{Description}:
1270 Returns the number of teams in the current team region.
1272 @item @emph{C/C++}:
1273 @multitable @columnfractions .20 .80
1274 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1275 @end multitable
1277 @item @emph{Fortran}:
1278 @multitable @columnfractions .20 .80
1279 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1280 @end multitable
1282 @item @emph{Reference}:
1283 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1284 @end table
1288 @node omp_get_team_num
1289 @subsection @code{omp_get_team_num} -- Get team number
1290 @table @asis
1291 @item @emph{Description}:
1292 Returns the team number of the calling thread.
1294 @item @emph{C/C++}:
1295 @multitable @columnfractions .20 .80
1296 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1297 @end multitable
1299 @item @emph{Fortran}:
1300 @multitable @columnfractions .20 .80
1301 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1302 @end multitable
1304 @item @emph{Reference}:
1305 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1306 @end table
1310 @node omp_set_num_teams
1311 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1312 @table @asis
1313 @item @emph{Description}:
1314 Specifies the upper bound for number of teams created by the teams construct
1315 which does not specify a @code{num_teams} clause.  The
1316 argument of @code{omp_set_num_teams} shall be a positive integer.
1318 @item @emph{C/C++}:
1319 @multitable @columnfractions .20 .80
1320 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1321 @end multitable
1323 @item @emph{Fortran}:
1324 @multitable @columnfractions .20 .80
1325 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1326 @item                   @tab @code{integer, intent(in) :: num_teams}
1327 @end multitable
1329 @item @emph{See also}:
1330 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1332 @item @emph{Reference}:
1333 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1334 @end table
1338 @node omp_get_max_teams
1339 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1340 @table @asis
1341 @item @emph{Description}:
1342 Return the maximum number of teams used for the teams region
1343 that does not use the clause @code{num_teams}.
1345 @item @emph{C/C++}:
1346 @multitable @columnfractions .20 .80
1347 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1348 @end multitable
1350 @item @emph{Fortran}:
1351 @multitable @columnfractions .20 .80
1352 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1353 @end multitable
1355 @item @emph{See also}:
1356 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1358 @item @emph{Reference}:
1359 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1360 @end table
1364 @node omp_set_teams_thread_limit
1365 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1366 @table @asis
1367 @item @emph{Description}:
1368 Specifies the upper bound for number of threads that are available
1369 for each team created by the teams construct which does not specify a
1370 @code{thread_limit} clause.  The argument of
1371 @code{omp_set_teams_thread_limit} shall be a positive integer.
1373 @item @emph{C/C++}:
1374 @multitable @columnfractions .20 .80
1375 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1376 @end multitable
1378 @item @emph{Fortran}:
1379 @multitable @columnfractions .20 .80
1380 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1381 @item                   @tab @code{integer, intent(in) :: thread_limit}
1382 @end multitable
1384 @item @emph{See also}:
1385 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1387 @item @emph{Reference}:
1388 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1389 @end table
1393 @node omp_get_thread_limit
1394 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1395 @table @asis
1396 @item @emph{Description}:
1397 Return the maximum number of threads of the program.
1399 @item @emph{C/C++}:
1400 @multitable @columnfractions .20 .80
1401 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1402 @end multitable
1404 @item @emph{Fortran}:
1405 @multitable @columnfractions .20 .80
1406 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1407 @end multitable
1409 @item @emph{See also}:
1410 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1412 @item @emph{Reference}:
1413 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1414 @end table
1418 @node Tasking Routines
1419 @section Tasking Routines
1421 Routines relating to explicit tasks.
1422 They have C linkage and do not throw exceptions.
1424 @menu
1425 * omp_get_max_task_priority::   Maximum task priority value that can be set
1426 * omp_in_explicit_task::        Whether a given task is an explicit task
1427 * omp_in_final::                Whether in final or included task region
1428 @c * omp_is_free_agent:: <fixme>/TR12
1429 @c * omp_ancestor_is_free_agent:: <fixme>/TR12
1430 @end menu
1434 @node omp_get_max_task_priority
1435 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1436 that can be set for tasks.
1437 @table @asis
1438 @item @emph{Description}:
1439 This function obtains the maximum allowed priority number for tasks.
1441 @item @emph{C/C++}
1442 @multitable @columnfractions .20 .80
1443 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1444 @end multitable
1446 @item @emph{Fortran}:
1447 @multitable @columnfractions .20 .80
1448 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1449 @end multitable
1451 @item @emph{Reference}:
1452 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1453 @end table
1457 @node omp_in_explicit_task
1458 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1459 @table @asis
1460 @item @emph{Description}:
1461 The function returns the @var{explicit-task-var} ICV; it returns true when the
1462 encountering task was generated by a task-generating construct such as
1463 @code{target}, @code{task} or @code{taskloop}.  Otherwise, the encountering task
1464 is in an implicit task region such as generated by the implicit or explicit
1465 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1467 @item @emph{C/C++}
1468 @multitable @columnfractions .20 .80
1469 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1470 @end multitable
1472 @item @emph{Fortran}:
1473 @multitable @columnfractions .20 .80
1474 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1475 @end multitable
1477 @item @emph{Reference}:
1478 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1479 @end table
1483 @node omp_in_final
1484 @subsection @code{omp_in_final} -- Whether in final or included task region
1485 @table @asis
1486 @item @emph{Description}:
1487 This function returns @code{true} if currently running in a final
1488 or included task region, @code{false} otherwise.  Here, @code{true}
1489 and @code{false} represent their language-specific counterparts.
1491 @item @emph{C/C++}:
1492 @multitable @columnfractions .20 .80
1493 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1494 @end multitable
1496 @item @emph{Fortran}:
1497 @multitable @columnfractions .20 .80
1498 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1499 @end multitable
1501 @item @emph{Reference}:
1502 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1503 @end table
1507 @node Resource Relinquishing Routines
1508 @section Resource Relinquishing Routines
1510 Routines releasing resources used by the OpenMP runtime.
1511 They have C linkage and do not throw exceptions.
1513 @menu
1514 * omp_pause_resource:: Release OpenMP resources on a device
1515 * omp_pause_resource_all:: Release OpenMP resources on all devices
1516 @end menu
1520 @node omp_pause_resource
1521 @subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1522 @table @asis
1523 @item @emph{Description}:
1524 Free resources used by the OpenMP program and the runtime library on and for the
1525 device specified by @var{device_num}; on success, zero is returned and non-zero
1526 otherwise.
1528 The value of @var{device_num} must be a conforming device number.  The routine
1529 may not be called from within any explicit region and all explicit threads that
1530 do not bind to the implicit parallel region have finalized execution.
1532 @item @emph{C/C++}:
1533 @multitable @columnfractions .20 .80
1534 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1535 @end multitable
1537 @item @emph{Fortran}:
1538 @multitable @columnfractions .20 .80
1539 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1540 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1541 @item                   @tab @code{integer device_num}
1542 @end multitable
1544 @item @emph{Reference}:
1545 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1546 @end table
1550 @node omp_pause_resource_all
1551 @subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1552 @table @asis
1553 @item @emph{Description}:
1554 Free resources used by the OpenMP program and the runtime library on all devices,
1555 including the host. On success, zero is returned and non-zero otherwise.
1557 The routine may not be called from within any explicit region and all explicit
1558 threads that do not bind to the implicit parallel region have finalized execution.
1560 @item @emph{C/C++}:
1561 @multitable @columnfractions .20 .80
1562 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1563 @end multitable
1565 @item @emph{Fortran}:
1566 @multitable @columnfractions .20 .80
1567 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1568 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1569 @end multitable
1571 @item @emph{See also}:
1572 @ref{omp_pause_resource}
1574 @item @emph{Reference}:
1575 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1576 @end table
1580 @node Device Information Routines
1581 @section Device Information Routines
1583 Routines related to devices available to an OpenMP program.
1584 They have C linkage and do not throw exceptions.
1586 @menu
1587 * omp_get_num_procs::           Number of processors online
1588 @c * omp_get_max_progress_width:: <fixme>/TR11
1589 * omp_set_default_device::      Set the default device for target regions
1590 * omp_get_default_device::      Get the default device for target regions
1591 * omp_get_num_devices::         Number of target devices
1592 * omp_get_device_num::          Get device that current thread is running on
1593 * omp_is_initial_device::       Whether executing on the host device
1594 * omp_get_initial_device::      Device number of host device
1595 @end menu
1599 @node omp_get_num_procs
1600 @subsection @code{omp_get_num_procs} -- Number of processors online
1601 @table @asis
1602 @item @emph{Description}:
1603 Returns the number of processors online on that device.
1605 @item @emph{C/C++}:
1606 @multitable @columnfractions .20 .80
1607 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1608 @end multitable
1610 @item @emph{Fortran}:
1611 @multitable @columnfractions .20 .80
1612 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1613 @end multitable
1615 @item @emph{Reference}:
1616 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1617 @end table
1621 @node omp_set_default_device
1622 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1623 @table @asis
1624 @item @emph{Description}:
1625 Set the default device for target regions without device clause.  The argument
1626 shall be a nonnegative device number.
1628 @item @emph{C/C++}:
1629 @multitable @columnfractions .20 .80
1630 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1631 @end multitable
1633 @item @emph{Fortran}:
1634 @multitable @columnfractions .20 .80
1635 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1636 @item                   @tab @code{integer device_num}
1637 @end multitable
1639 @item @emph{See also}:
1640 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1642 @item @emph{Reference}:
1643 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1644 @end table
1648 @node omp_get_default_device
1649 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1650 @table @asis
1651 @item @emph{Description}:
1652 Get the default device for target regions without device clause.
1654 @item @emph{C/C++}:
1655 @multitable @columnfractions .20 .80
1656 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1657 @end multitable
1659 @item @emph{Fortran}:
1660 @multitable @columnfractions .20 .80
1661 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1662 @end multitable
1664 @item @emph{See also}:
1665 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
1667 @item @emph{Reference}:
1668 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1669 @end table
1673 @node omp_get_num_devices
1674 @subsection @code{omp_get_num_devices} -- Number of target devices
1675 @table @asis
1676 @item @emph{Description}:
1677 Returns the number of target devices.
1679 @item @emph{C/C++}:
1680 @multitable @columnfractions .20 .80
1681 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1682 @end multitable
1684 @item @emph{Fortran}:
1685 @multitable @columnfractions .20 .80
1686 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1687 @end multitable
1689 @item @emph{Reference}:
1690 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1691 @end table
1695 @node omp_get_device_num
1696 @subsection @code{omp_get_device_num} -- Return device number of current device
1697 @table @asis
1698 @item @emph{Description}:
1699 This function returns a device number that represents the device that the
1700 current thread is executing on. For OpenMP 5.0, this must be equal to the
1701 value returned by the @code{omp_get_initial_device} function when called
1702 from the host.
1704 @item @emph{C/C++}
1705 @multitable @columnfractions .20 .80
1706 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1707 @end multitable
1709 @item @emph{Fortran}:
1710 @multitable @columnfractions .20 .80
1711 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1712 @end multitable
1714 @item @emph{See also}:
1715 @ref{omp_get_initial_device}
1717 @item @emph{Reference}:
1718 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1719 @end table
1723 @node omp_is_initial_device
1724 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1725 @table @asis
1726 @item @emph{Description}:
1727 This function returns @code{true} if currently running on the host device,
1728 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1729 their language-specific counterparts.
1731 @item @emph{C/C++}:
1732 @multitable @columnfractions .20 .80
1733 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1734 @end multitable
1736 @item @emph{Fortran}:
1737 @multitable @columnfractions .20 .80
1738 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1739 @end multitable
1741 @item @emph{Reference}:
1742 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1743 @end table
1747 @node omp_get_initial_device
1748 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1749 @table @asis
1750 @item @emph{Description}:
1751 This function returns a device number that represents the host device.
1752 For OpenMP 5.1, this must be equal to the value returned by the
1753 @code{omp_get_num_devices} function.
1755 @item @emph{C/C++}
1756 @multitable @columnfractions .20 .80
1757 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1758 @end multitable
1760 @item @emph{Fortran}:
1761 @multitable @columnfractions .20 .80
1762 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1763 @end multitable
1765 @item @emph{See also}:
1766 @ref{omp_get_num_devices}
1768 @item @emph{Reference}:
1769 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1770 @end table
1774 @node Device Memory Routines
1775 @section Device Memory Routines
1777 Routines related to memory allocation and managing corresponding
1778 pointers on devices. They have C linkage and do not throw exceptions.
1780 @menu
1781 * omp_target_alloc:: Allocate device memory
1782 * omp_target_free:: Free device memory
1783 * omp_target_is_present:: Check whether storage is mapped
1784 * omp_target_is_accessible:: Check whether memory is device accessible
1785 * omp_target_memcpy:: Copy data between devices
1786 * omp_target_memcpy_rect:: Copy a subvolume of data between devices
1787 * omp_target_memcpy_async:: Copy data between devices asynchronously
1788 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
1789 @c * omp_target_memset:: <fixme>/TR12
1790 @c * omp_target_memset_async:: <fixme>/TR12
1791 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
1792 * omp_target_disassociate_ptr:: Remove device--host pointer association
1793 * omp_get_mapped_ptr:: Return device pointer to a host pointer
1794 @end menu
1798 @node omp_target_alloc
1799 @subsection @code{omp_target_alloc} -- Allocate device memory
1800 @table @asis
1801 @item @emph{Description}:
1802 This routine allocates @var{size} bytes of memory in the device environment
1803 associated with the device number @var{device_num}.  If successful, a device
1804 pointer is returned, otherwise a null pointer.
1806 In GCC, when the device is the host or the device shares memory with the host,
1807 the memory is allocated on the host; in that case, when @var{size} is zero,
1808 either NULL or a unique pointer value that can later be successfully passed to
1809 @code{omp_target_free} is returned.  When the allocation is not performed on
1810 the host, a null pointer is returned when @var{size} is zero; in that case,
1811 additionally a diagnostic might be printed to standard error (stderr).
1813 Running this routine in a @code{target} region except on the initial device
1814 is not supported.
1816 @item @emph{C/C++}
1817 @multitable @columnfractions .20 .80
1818 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
1819 @end multitable
1821 @item @emph{Fortran}:
1822 @multitable @columnfractions .20 .80
1823 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
1824 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
1825 @item                   @tab @code{integer(c_size_t), value :: size}
1826 @item                   @tab @code{integer(c_int), value :: device_num}
1827 @end multitable
1829 @item @emph{See also}:
1830 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
1832 @item @emph{Reference}:
1833 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
1834 @end table
1838 @node omp_target_free
1839 @subsection @code{omp_target_free} -- Free device memory
1840 @table @asis
1841 @item @emph{Description}:
1842 This routine frees memory allocated by the @code{omp_target_alloc} routine.
1843 The @var{device_ptr} argument must be either a null pointer or a device pointer
1844 returned by @code{omp_target_alloc} for the specified @code{device_num}.  The
1845 device number @var{device_num} must be a conforming device number.
1847 Running this routine in a @code{target} region except on the initial device
1848 is not supported.
1850 @item @emph{C/C++}
1851 @multitable @columnfractions .20 .80
1852 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
1853 @end multitable
1855 @item @emph{Fortran}:
1856 @multitable @columnfractions .20 .80
1857 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
1858 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1859 @item                   @tab @code{type(c_ptr), value :: device_ptr}
1860 @item                   @tab @code{integer(c_int), value :: device_num}
1861 @end multitable
1863 @item @emph{See also}:
1864 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
1866 @item @emph{Reference}:
1867 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
1868 @end table
1872 @node omp_target_is_present
1873 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
1874 @table @asis
1875 @item @emph{Description}:
1876 This routine tests whether storage, identified by the host pointer @var{ptr}
1877 is mapped to the device specified by @var{device_num}.  If so, it returns
1878 a nonzero value and otherwise zero.
1880 In GCC, this includes self mapping such that @code{omp_target_is_present}
1881 returns @emph{true} when @var{device_num} specifies the host or when the host
1882 and the device share memory.  If @var{ptr} is a null pointer, @var{true} is
1883 returned and if @var{device_num} is an invalid device number, @var{false} is
1884 returned.
1886 If those conditions do not apply, @emph{true} is returned if the association has
1887 been established by an explicit or implicit @code{map} clause, the
1888 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
1889 routine.
1891 Running this routine in a @code{target} region except on the initial device
1892 is not supported.
1894 @item @emph{C/C++}
1895 @multitable @columnfractions .20 .80
1896 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
1897 @item                   @tab @code{                          int device_num)}
1898 @end multitable
1900 @item @emph{Fortran}:
1901 @multitable @columnfractions .20 .80
1902 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
1903 @item                   @tab @code{    device_num) bind(C)}
1904 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1905 @item                   @tab @code{type(c_ptr), value :: ptr}
1906 @item                   @tab @code{integer(c_int), value :: device_num}
1907 @end multitable
1909 @item @emph{See also}:
1910 @ref{omp_target_associate_ptr}
1912 @item @emph{Reference}:
1913 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
1914 @end table
1918 @node omp_target_is_accessible
1919 @subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
1920 @table @asis
1921 @item @emph{Description}:
1922 This routine tests whether memory, starting at the address given by @var{ptr}
1923 and extending @var{size} bytes, is accessibly on the device specified by
1924 @var{device_num}.  If so, it returns a nonzero value and otherwise zero.
1926 The address given by @var{ptr} is interpreted to be in the address space of
1927 the device and @var{size} must be positive.
1929 Note that GCC's current implementation assumes that @var{ptr} is a valid host
1930 pointer. Therefore, all addresses given by @var{ptr} are assumed to be
1931 accessible on the initial device. And, to err on the safe side, this memory
1932 is only available on a non-host device that can access all host memory
1933 ([uniform] shared memory access).
1935 Running this routine in a @code{target} region except on the initial device
1936 is not supported.
1938 @item @emph{C/C++}
1939 @multitable @columnfractions .20 .80
1940 @item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
1941 @item                   @tab @code{                             size_t size,}
1942 @item                   @tab @code{                             int device_num)}
1943 @end multitable
1945 @item @emph{Fortran}:
1946 @multitable @columnfractions .20 .80
1947 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
1948 @item                   @tab @code{    size, device_num) bind(C)}
1949 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
1950 @item                   @tab @code{type(c_ptr), value :: ptr}
1951 @item                   @tab @code{integer(c_size_t), value :: size}
1952 @item                   @tab @code{integer(c_int), value :: device_num}
1953 @end multitable
1955 @item @emph{See also}:
1956 @ref{omp_target_associate_ptr}
1958 @item @emph{Reference}:
1959 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
1960 @end table
1964 @node omp_target_memcpy
1965 @subsection @code{omp_target_memcpy} -- Copy data between devices
1966 @table @asis
1967 @item @emph{Description}:
1968 This routine copies @var{length} of bytes of data from the device
1969 identified by device number @var{src_device_num} to device @var{dst_device_num}.
1970 The data is copied from the source device from the address provided by
1971 @var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
1972 device's @var{dst} address shifted by @var{dst_offset}.  The routine returns
1973 zero on success and non-zero otherwise.
1975 Running this routine in a @code{target} region except on the initial device
1976 is not supported.
1978 @item @emph{C/C++}
1979 @multitable @columnfractions .20 .80
1980 @item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
1981 @item                   @tab @code{                           const void *src,}
1982 @item                   @tab @code{                           size_t length,}
1983 @item                   @tab @code{                           size_t dst_offset,}
1984 @item                   @tab @code{                           size_t src_offset,}
1985 @item                   @tab @code{                           int dst_device_num,}
1986 @item                   @tab @code{                           int src_device_num)}
1987 @end multitable
1989 @item @emph{Fortran}:
1990 @multitable @columnfractions .20 .80
1991 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
1992 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
1993 @item                   @tab @code{    dst_device_num, src_device_num) bind(C)}
1994 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
1995 @item                   @tab @code{type(c_ptr), value :: dst, src}
1996 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
1997 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
1998 @end multitable
2000 @item @emph{See also}:
2001 @ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2003 @item @emph{Reference}:
2004 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2005 @end table
2009 @node omp_target_memcpy_async
2010 @subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2011 @table @asis
2012 @item @emph{Description}:
2013 This routine copies asynchronously @var{length} of bytes of data from the
2014 device identified by device number @var{src_device_num} to device
2015 @var{dst_device_num}.  The data is copied from the source device from the
2016 address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2017 to the destination device's @var{dst} address shifted by @var{dst_offset}.
2018 Task dependence is expressed by passing an array of depend objects to
2019 @var{depobj_list}, where the number of array elements is passed as
2020 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2021 ignored.  The routine returns zero if the copying process has successfully
2022 been started and non-zero otherwise.
2024 Running this routine in a @code{target} region except on the initial device
2025 is not supported.
2027 @item @emph{C/C++}
2028 @multitable @columnfractions .20 .80
2029 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2030 @item                   @tab @code{                           const void *src,}
2031 @item                   @tab @code{                           size_t length,}
2032 @item                   @tab @code{                           size_t dst_offset,}
2033 @item                   @tab @code{                           size_t src_offset,}
2034 @item                   @tab @code{                           int dst_device_num,}
2035 @item                   @tab @code{                           int src_device_num,}
2036 @item                   @tab @code{                           int depobj_count,}
2037 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2038 @end multitable
2040 @item @emph{Fortran}:
2041 @multitable @columnfractions .20 .80
2042 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2043 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
2044 @item                   @tab @code{    dst_device_num, src_device_num, &}
2045 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2046 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2047 @item                   @tab @code{type(c_ptr), value :: dst, src}
2048 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2049 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2050 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2051 @end multitable
2053 @item @emph{See also}:
2054 @ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2056 @item @emph{Reference}:
2057 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2058 @end table
2062 @node omp_target_memcpy_rect
2063 @subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2064 @table @asis
2065 @item @emph{Description}:
2066 This routine copies a subvolume of data from the device identified by
2067 device number @var{src_device_num} to device @var{dst_device_num}. 
2068 The array has @var{num_dims} dimensions and each array element has a size of
2069 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2070 per dimension are copied.  The full sizes of the destination and source arrays
2071 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2072 respectively.  The offset per dimension to the first element to be copied is
2073 given by the @var{dst_offset} and @var{src_offset} arguments.  The routine
2074 returns zero on success and non-zero otherwise.
2076 The OpenMP specification only requires that @var{num_dims} up to three is
2077 supported.  In order to find implementation-specific maximally supported number
2078 of dimensions, the routine returns this value when invoked with a null pointer
2079 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2080 dimensions, it returns @code{INT_MAX}.
2082 The device-number arguments must be conforming device numbers, the @var{src} and
2083 @var{dst} must be either both null pointers or all of the following must be
2084 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2085 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2086 dimensions.
2088 Running this routine in a @code{target} region is not supported except on
2089 the initial device.
2091 @item @emph{C/C++}
2092 @multitable @columnfractions .20 .80
2093 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2094 @item                   @tab @code{                           const void *src,}
2095 @item                   @tab @code{                           size_t element_size,}
2096 @item                   @tab @code{                           int num_dims,}
2097 @item                   @tab @code{                           const size_t *volume,}
2098 @item                   @tab @code{                           const size_t *dst_offset,}
2099 @item                   @tab @code{                           const size_t *src_offset,}
2100 @item                   @tab @code{                           const size_t *dst_dimensions,}
2101 @item                   @tab @code{                           const size_t *src_dimensions,}
2102 @item                   @tab @code{                           int dst_device_num,}
2103 @item                   @tab @code{                           int src_device_num)}
2104 @end multitable
2106 @item @emph{Fortran}:
2107 @multitable @columnfractions .20 .80
2108 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2109 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2110 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2111 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num) bind(C)}
2112 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2113 @item                   @tab @code{type(c_ptr), value :: dst, src}
2114 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2115 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2116 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2117 @end multitable
2119 @item @emph{See also}:
2120 @ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}
2122 @item @emph{Reference}:
2123 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2124 @end table
2128 @node omp_target_memcpy_rect_async
2129 @subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2130 @table @asis
2131 @item @emph{Description}:
2132 This routine copies asynchronously a subvolume of data from the device
2133 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2134 The array has @var{num_dims} dimensions and each array element has a size of
2135 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2136 per dimension are copied.  The full sizes of the destination and source arrays
2137 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2138 respectively.  The offset per dimension to the first element to be copied is
2139 given by the @var{dst_offset} and @var{src_offset} arguments.  Task dependence
2140 is expressed by passing an array of depend objects to @var{depobj_list}, where
2141 the number of array elements is passed as @var{depobj_count}; if the count is
2142 zero, the @var{depobj_list} argument is ignored.  The routine
2143 returns zero on success and non-zero otherwise.
2145 The OpenMP specification only requires that @var{num_dims} up to three is
2146 supported.  In order to find implementation-specific maximally supported number
2147 of dimensions, the routine returns this value when invoked with a null pointer
2148 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2149 dimensions, it returns @code{INT_MAX}.
2151 The device-number arguments must be conforming device numbers, the @var{src} and
2152 @var{dst} must be either both null pointers or all of the following must be
2153 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2154 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2155 dimensions.
2157 Running this routine in a @code{target} region is not supported except on
2158 the initial device.
2160 @item @emph{C/C++}
2161 @multitable @columnfractions .20 .80
2162 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2163 @item                   @tab @code{                           const void *src,}
2164 @item                   @tab @code{                           size_t element_size,}
2165 @item                   @tab @code{                           int num_dims,}
2166 @item                   @tab @code{                           const size_t *volume,}
2167 @item                   @tab @code{                           const size_t *dst_offset,}
2168 @item                   @tab @code{                           const size_t *src_offset,}
2169 @item                   @tab @code{                           const size_t *dst_dimensions,}
2170 @item                   @tab @code{                           const size_t *src_dimensions,}
2171 @item                   @tab @code{                           int dst_device_num,}
2172 @item                   @tab @code{                           int src_device_num,}
2173 @item                   @tab @code{                           int depobj_count,}
2174 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2175 @end multitable
2177 @item @emph{Fortran}:
2178 @multitable @columnfractions .20 .80
2179 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2180 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2181 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2182 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num, &}
2183 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2184 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2185 @item                   @tab @code{type(c_ptr), value :: dst, src}
2186 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2187 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2188 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2189 @item                   @tab @code{integer(c_int), value :: depobj_count}
2190 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2191 @end multitable
2193 @item @emph{See also}:
2194 @ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}
2196 @item @emph{Reference}:
2197 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2198 @end table
2202 @node omp_target_associate_ptr
2203 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2204 @table @asis
2205 @item @emph{Description}:
2206 This routine associates storage on the host with storage on a device identified
2207 by @var{device_num}.  The device pointer is usually obtained by calling
2208 @code{omp_target_alloc} or by other means (but not by using the @code{map}
2209 clauses or the @code{declare target} directive).  The host pointer should point
2210 to memory that has a storage size of at least @var{size}.
2212 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2213 that is used as the base address for the device side of the mapping; the
2214 storage size should be at least @var{device_offset} plus @var{size}.
2216 After the association, the host pointer can be used in a @code{map} clause and
2217 in the @code{to} and @code{from} clauses of the @code{target update} directive
2218 to transfer data between the associated pointers. The reference count of such
2219 associated storage is infinite.  The association can be removed by calling
2220 @code{omp_target_disassociate_ptr} which should be done before the lifetime
2221 of either either storage ends.
2223 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2224 for when the initial device or the associated device shares memory with the
2225 host.  @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2226 into already associated storage that is fully inside of a previously associated
2227 memory.  Otherwise, if the association was successful zero is returned; if none
2228 of the cases above apply, nonzero (@code{EINVAL}) is returned.
2230 The @code{omp_target_is_present} routine can be used to test whether
2231 associated storage for a device pointer exists.
2233 Running this routine in a @code{target} region except on the initial device
2234 is not supported.
2236 @item @emph{C/C++}
2237 @multitable @columnfractions .20 .80
2238 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2239 @item                   @tab @code{                             const void *device_ptr,}
2240 @item                   @tab @code{                             size_t size,}
2241 @item                   @tab @code{                             size_t device_offset,}
2242 @item                   @tab @code{                             int device_num)}
2243 @end multitable
2245 @item @emph{Fortran}:
2246 @multitable @columnfractions .20 .80
2247 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2248 @item                   @tab @code{    device_ptr, size, device_offset, device_num) bind(C)}
2249 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2250 @item                   @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2251 @item                   @tab @code{integer(c_size_t), value :: size, device_offset}
2252 @item                   @tab @code{integer(c_int), value :: device_num}
2253 @end multitable
2255 @item @emph{See also}:
2256 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2257 @ref{omp_target_alloc}
2259 @item @emph{Reference}:
2260 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2261 @end table
2265 @node omp_target_disassociate_ptr
2266 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2267 @table @asis
2268 @item @emph{Description}:
2269 This routine removes the storage association established by calling
2270 @code{omp_target_associate_ptr} and sets the reference count to zero,
2271 even if @code{omp_target_associate_ptr} was invoked multiple times for
2272 for host pointer @code{ptr}.  If applicable, the device memory needs
2273 to be freed by the user.
2275 If an associated device storage location for the @var{device_num} was
2276 found and has infinite reference count, the association is removed and
2277 zero is returned.  In all other cases, nonzero (@code{EINVAL}) is returned
2278 and no other action is taken.
2280 Note that passing a host pointer where the association to the device pointer
2281 was established with the @code{declare target} directive yields undefined
2282 behavior.
2284 Running this routine in a @code{target} region except on the initial device
2285 is not supported.
2287 @item @emph{C/C++}
2288 @multitable @columnfractions .20 .80
2289 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2290 @item                   @tab @code{                                int device_num)}
2291 @end multitable
2293 @item @emph{Fortran}:
2294 @multitable @columnfractions .20 .80
2295 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2296 @item                   @tab @code{    device_num) bind(C)}
2297 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2298 @item                   @tab @code{type(c_ptr), value :: ptr}
2299 @item                   @tab @code{integer(c_int), value :: device_num}
2300 @end multitable
2302 @item @emph{See also}:
2303 @ref{omp_target_associate_ptr}
2305 @item @emph{Reference}:
2306 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2307 @end table
2311 @node omp_get_mapped_ptr
2312 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2313 @table @asis
2314 @item @emph{Description}:
2315 If the device number is refers to the initial device or to a device with
2316 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2317 routines returns the value of the passed @var{ptr}.  Otherwise, if associated
2318 storage to the passed host pointer @var{ptr} exists on device associated with
2319 @var{device_num}, it returns that pointer. In all other cases and in cases of
2320 an error, a null pointer is returned.
2322 The association of storage location is established either via an explicit or
2323 implicit @code{map} clause, the @code{declare target} directive or the
2324 @code{omp_target_associate_ptr} routine.
2326 Running this routine in a @code{target} region except on the initial device
2327 is not supported.
2329 @item @emph{C/C++}
2330 @multitable @columnfractions .20 .80
2331 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2332 @end multitable
2334 @item @emph{Fortran}:
2335 @multitable @columnfractions .20 .80
2336 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2337 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2338 @item                   @tab @code{type(c_ptr), value :: ptr}
2339 @item                   @tab @code{integer(c_int), value :: device_num}
2340 @end multitable
2342 @item @emph{See also}:
2343 @ref{omp_target_associate_ptr}
2345 @item @emph{Reference}:
2346 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2347 @end table
2351 @node Lock Routines
2352 @section Lock Routines
2354 Initialize, set, test, unset and destroy simple and nested locks.
2355 The routines have C linkage and do not throw exceptions.
2357 @menu
2358 * omp_init_lock::            Initialize simple lock
2359 * omp_init_nest_lock::       Initialize nested lock
2360 @c * omp_init_lock_with_hint:: <fixme>
2361 @c * omp_init_nest_lock_with_hint:: <fixme>
2362 * omp_destroy_lock::         Destroy simple lock
2363 * omp_destroy_nest_lock::    Destroy nested lock
2364 * omp_set_lock::             Wait for and set simple lock
2365 * omp_set_nest_lock::        Wait for and set simple lock
2366 * omp_unset_lock::           Unset simple lock
2367 * omp_unset_nest_lock::      Unset nested lock
2368 * omp_test_lock::            Test and set simple lock if available
2369 * omp_test_nest_lock::       Test and set nested lock if available
2370 @end menu
2374 @node omp_init_lock
2375 @subsection @code{omp_init_lock} -- Initialize simple lock
2376 @table @asis
2377 @item @emph{Description}:
2378 Initialize a simple lock.  After initialization, the lock is in
2379 an unlocked state.
2381 @item @emph{C/C++}:
2382 @multitable @columnfractions .20 .80
2383 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2384 @end multitable
2386 @item @emph{Fortran}:
2387 @multitable @columnfractions .20 .80
2388 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2389 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2390 @end multitable
2392 @item @emph{See also}:
2393 @ref{omp_destroy_lock}
2395 @item @emph{Reference}: 
2396 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2397 @end table
2401 @node omp_init_nest_lock
2402 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2403 @table @asis
2404 @item @emph{Description}:
2405 Initialize a nested lock.  After initialization, the lock is in
2406 an unlocked state and the nesting count is set to zero.
2408 @item @emph{C/C++}:
2409 @multitable @columnfractions .20 .80
2410 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2411 @end multitable
2413 @item @emph{Fortran}:
2414 @multitable @columnfractions .20 .80
2415 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2416 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2417 @end multitable
2419 @item @emph{See also}:
2420 @ref{omp_destroy_nest_lock}
2422 @item @emph{Reference}:
2423 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2424 @end table
2428 @node omp_destroy_lock
2429 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2430 @table @asis
2431 @item @emph{Description}:
2432 Destroy a simple lock.  In order to be destroyed, a simple lock must be
2433 in the unlocked state. 
2435 @item @emph{C/C++}:
2436 @multitable @columnfractions .20 .80
2437 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2438 @end multitable
2440 @item @emph{Fortran}:
2441 @multitable @columnfractions .20 .80
2442 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2443 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2444 @end multitable
2446 @item @emph{See also}:
2447 @ref{omp_init_lock}
2449 @item @emph{Reference}: 
2450 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2451 @end table
2455 @node omp_destroy_nest_lock
2456 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2457 @table @asis
2458 @item @emph{Description}:
2459 Destroy a nested lock.  In order to be destroyed, a nested lock must be
2460 in the unlocked state and its nesting count must equal zero.
2462 @item @emph{C/C++}:
2463 @multitable @columnfractions .20 .80
2464 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2465 @end multitable
2467 @item @emph{Fortran}:
2468 @multitable @columnfractions .20 .80
2469 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2470 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2471 @end multitable
2473 @item @emph{See also}:
2474 @ref{omp_init_lock}
2476 @item @emph{Reference}: 
2477 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2478 @end table
2482 @node omp_set_lock
2483 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2484 @table @asis
2485 @item @emph{Description}:
2486 Before setting a simple lock, the lock variable must be initialized by 
2487 @code{omp_init_lock}.  The calling thread is blocked until the lock 
2488 is available.  If the lock is already held by the current thread, 
2489 a deadlock occurs.
2491 @item @emph{C/C++}:
2492 @multitable @columnfractions .20 .80
2493 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2494 @end multitable
2496 @item @emph{Fortran}:
2497 @multitable @columnfractions .20 .80
2498 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2499 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2500 @end multitable
2502 @item @emph{See also}:
2503 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2505 @item @emph{Reference}: 
2506 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2507 @end table
2511 @node omp_set_nest_lock
2512 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2513 @table @asis
2514 @item @emph{Description}:
2515 Before setting a nested lock, the lock variable must be initialized by 
2516 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
2517 is available.  If the lock is already held by the current thread, the
2518 nesting count for the lock is incremented.
2520 @item @emph{C/C++}:
2521 @multitable @columnfractions .20 .80
2522 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2523 @end multitable
2525 @item @emph{Fortran}:
2526 @multitable @columnfractions .20 .80
2527 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2528 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2529 @end multitable
2531 @item @emph{See also}:
2532 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2534 @item @emph{Reference}: 
2535 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2536 @end table
2540 @node omp_unset_lock
2541 @subsection @code{omp_unset_lock} -- Unset simple lock
2542 @table @asis
2543 @item @emph{Description}:
2544 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2545 or @code{omp_test_lock} before.  In addition, the lock must be held by the
2546 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
2547 or more threads attempted to set the lock before, one of them is chosen to,
2548 again, set the lock to itself.
2550 @item @emph{C/C++}:
2551 @multitable @columnfractions .20 .80
2552 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2553 @end multitable
2555 @item @emph{Fortran}:
2556 @multitable @columnfractions .20 .80
2557 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2558 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2559 @end multitable
2561 @item @emph{See also}:
2562 @ref{omp_set_lock}, @ref{omp_test_lock}
2564 @item @emph{Reference}: 
2565 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2566 @end table
2570 @node omp_unset_nest_lock
2571 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2572 @table @asis
2573 @item @emph{Description}:
2574 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2575 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
2576 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
2577 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
2578 one of them is chosen to, again, set the lock to itself.
2580 @item @emph{C/C++}:
2581 @multitable @columnfractions .20 .80
2582 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2583 @end multitable
2585 @item @emph{Fortran}:
2586 @multitable @columnfractions .20 .80
2587 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2588 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2589 @end multitable
2591 @item @emph{See also}:
2592 @ref{omp_set_nest_lock}
2594 @item @emph{Reference}: 
2595 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2596 @end table
2600 @node omp_test_lock
2601 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2602 @table @asis
2603 @item @emph{Description}:
2604 Before setting a simple lock, the lock variable must be initialized by 
2605 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
2606 does not block if the lock is not available.  This function returns
2607 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
2608 @code{false} represent their language-specific counterparts.
2610 @item @emph{C/C++}:
2611 @multitable @columnfractions .20 .80
2612 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2613 @end multitable
2615 @item @emph{Fortran}:
2616 @multitable @columnfractions .20 .80
2617 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2618 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2619 @end multitable
2621 @item @emph{See also}:
2622 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2624 @item @emph{Reference}: 
2625 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2626 @end table
2630 @node omp_test_nest_lock
2631 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2632 @table @asis
2633 @item @emph{Description}:
2634 Before setting a nested lock, the lock variable must be initialized by 
2635 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
2636 @code{omp_test_nest_lock} does not block if the lock is not available. 
2637 If the lock is already held by the current thread, the new nesting count 
2638 is returned.  Otherwise, the return value equals zero.
2640 @item @emph{C/C++}:
2641 @multitable @columnfractions .20 .80
2642 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2643 @end multitable
2645 @item @emph{Fortran}:
2646 @multitable @columnfractions .20 .80
2647 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2648 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2649 @end multitable
2652 @item @emph{See also}:
2653 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2655 @item @emph{Reference}: 
2656 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2657 @end table
2661 @node Timing Routines
2662 @section Timing Routines
2664 Portable, thread-based, wall clock timer.
2665 The routines have C linkage and do not throw exceptions.
2667 @menu
2668 * omp_get_wtick::            Get timer precision.
2669 * omp_get_wtime::            Elapsed wall clock time.
2670 @end menu
2674 @node omp_get_wtick
2675 @subsection @code{omp_get_wtick} -- Get timer precision
2676 @table @asis
2677 @item @emph{Description}:
2678 Gets the timer precision, i.e., the number of seconds between two 
2679 successive clock ticks.
2681 @item @emph{C/C++}:
2682 @multitable @columnfractions .20 .80
2683 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2684 @end multitable
2686 @item @emph{Fortran}:
2687 @multitable @columnfractions .20 .80
2688 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2689 @end multitable
2691 @item @emph{See also}:
2692 @ref{omp_get_wtime}
2694 @item @emph{Reference}: 
2695 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2696 @end table
2700 @node omp_get_wtime
2701 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2702 @table @asis
2703 @item @emph{Description}:
2704 Elapsed wall clock time in seconds.  The time is measured per thread, no
2705 guarantee can be made that two distinct threads measure the same time.
2706 Time is measured from some "time in the past", which is an arbitrary time
2707 guaranteed not to change during the execution of the program.
2709 @item @emph{C/C++}:
2710 @multitable @columnfractions .20 .80
2711 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2712 @end multitable
2714 @item @emph{Fortran}:
2715 @multitable @columnfractions .20 .80
2716 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2717 @end multitable
2719 @item @emph{See also}:
2720 @ref{omp_get_wtick}
2722 @item @emph{Reference}: 
2723 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2724 @end table
2728 @node Event Routine
2729 @section Event Routine
2731 Support for event objects.
2732 The routine has C linkage and do not throw exceptions.
2734 @menu
2735 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
2736 @end menu
2740 @node omp_fulfill_event
2741 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2742 @table @asis
2743 @item @emph{Description}:
2744 Fulfill the event associated with the event handle argument.  Currently, it
2745 is only used to fulfill events generated by detach clauses on task
2746 constructs - the effect of fulfilling the event is to allow the task to
2747 complete.
2749 The result of calling @code{omp_fulfill_event} with an event handle other
2750 than that generated by a detach clause is undefined.  Calling it with an
2751 event handle that has already been fulfilled is also undefined.
2753 @item @emph{C/C++}:
2754 @multitable @columnfractions .20 .80
2755 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2756 @end multitable
2758 @item @emph{Fortran}:
2759 @multitable @columnfractions .20 .80
2760 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2761 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
2762 @end multitable
2764 @item @emph{Reference}:
2765 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2766 @end table
2770 @c @node Interoperability Routines
2771 @c @section Interoperability Routines
2773 @c Routines to obtain properties from an @code{omp_interop_t} object.
2774 @c They have C linkage and do not throw exceptions.
2776 @c @menu
2777 @c * omp_get_num_interop_properties:: <fixme>
2778 @c * omp_get_interop_int:: <fixme>
2779 @c * omp_get_interop_ptr:: <fixme>
2780 @c * omp_get_interop_str:: <fixme>
2781 @c * omp_get_interop_name:: <fixme>
2782 @c * omp_get_interop_type_desc:: <fixme>
2783 @c * omp_get_interop_rc_desc:: <fixme>
2784 @c @end menu
2786 @node Memory Management Routines
2787 @section Memory Management Routines
2789 Routines to manage and allocate memory on the current device.
2790 They have C linkage and do not throw exceptions.
2792 @menu
2793 * omp_init_allocator:: Create an allocator
2794 * omp_destroy_allocator:: Destroy an allocator
2795 * omp_set_default_allocator:: Set the default allocator
2796 * omp_get_default_allocator:: Get the default allocator
2797 * omp_alloc:: Memory allocation with an allocator
2798 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
2799 * omp_free:: Freeing memory allocated with OpenMP routines
2800 * omp_calloc:: Allocate nullified memory with an allocator
2801 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
2802 * omp_realloc:: Reallocate memory allocated with OpenMP routines
2803 @c * omp_get_memspace_num_resources:: <fixme>/TR11
2804 @c * omp_get_submemspace:: <fixme>/TR11
2805 @end menu
2809 @node omp_init_allocator
2810 @subsection @code{omp_init_allocator} -- Create an allocator
2811 @table @asis
2812 @item @emph{Description}:
2813 Create an allocator that uses the specified memory space and has the specified
2814 traits; if an allocator that fulfills the requirements cannot be created,
2815 @code{omp_null_allocator} is returned.
2817 The predefined memory spaces and available traits can be found at
2818 @ref{OMP_ALLOCATOR}, where the trait names have to be be prefixed by
2819 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
2820 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
2821 may be used as trait value to specify that the default value should be used.
2823 @item @emph{C/C++}:
2824 @multitable @columnfractions .20 .80
2825 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
2826 @item                   @tab @code{  omp_memspace_handle_t memspace,}
2827 @item                   @tab @code{  int ntraits,}
2828 @item                   @tab @code{  const omp_alloctrait_t traits[]);}
2829 @end multitable
2831 @item @emph{Fortran}:
2832 @multitable @columnfractions .20 .80
2833 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
2834 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
2835 @item                   @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
2836 @item                   @tab @code{integer, intent(in) :: ntraits}
2837 @item                   @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
2838 @end multitable
2840 @item @emph{See also}:
2841 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
2843 @item @emph{Reference}:
2844 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
2845 @end table
2849 @node omp_destroy_allocator
2850 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
2851 @table @asis
2852 @item @emph{Description}:
2853 Releases all resources used by a memory allocator, which must not represent
2854 a predefined memory allocator.  Accessing memory after its allocator has been
2855 destroyed has unspecified behavior.  Passing @code{omp_null_allocator} to the
2856 routine is permitted but has no effect.
2859 @item @emph{C/C++}:
2860 @multitable @columnfractions .20 .80
2861 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
2862 @end multitable
2864 @item @emph{Fortran}:
2865 @multitable @columnfractions .20 .80
2866 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
2867 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2868 @end multitable
2870 @item @emph{See also}:
2871 @ref{omp_init_allocator}
2873 @item @emph{Reference}:
2874 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
2875 @end table
2879 @node omp_set_default_allocator
2880 @subsection @code{omp_set_default_allocator} -- Set the default allocator
2881 @table @asis
2882 @item @emph{Description}:
2883 Sets the default allocator that is used when no allocator has been specified
2884 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2885 routine is invoked with the @code{omp_null_allocator} allocator.
2887 @item @emph{C/C++}:
2888 @multitable @columnfractions .20 .80
2889 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
2890 @end multitable
2892 @item @emph{Fortran}:
2893 @multitable @columnfractions .20 .80
2894 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
2895 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2896 @end multitable
2898 @item @emph{See also}:
2899 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
2900 @ref{Memory allocation}
2902 @item @emph{Reference}:
2903 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
2904 @end table
2908 @node omp_get_default_allocator
2909 @subsection @code{omp_get_default_allocator} -- Get the default allocator
2910 @table @asis
2911 @item @emph{Description}:
2912 The routine returns the default allocator that is used when no allocator has
2913 been specified in the @code{allocate} or @code{allocator} clause or if an
2914 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
2916 @item @emph{C/C++}:
2917 @multitable @columnfractions .20 .80
2918 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
2919 @end multitable
2921 @item @emph{Fortran}:
2922 @multitable @columnfractions .20 .80
2923 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
2924 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
2925 @end multitable
2927 @item @emph{See also}:
2928 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
2930 @item @emph{Reference}:
2931 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
2932 @end table
2936 @node omp_alloc
2937 @subsection @code{omp_alloc} -- Memory allocation with an allocator
2938 @table @asis
2939 @item @emph{Description}:
2940 Allocate memory with the specified allocator, which can either be a predefined
2941 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2942 is @code{omp_null_allocator}, the allocator specified by the
2943 @var{def-allocator-var} ICV is used.  @var{size} must be a nonnegative number
2944 denoting the number of bytes to be allocated; if @var{size} is zero,
2945 @code{omp_alloc} will return a null pointer.  If successful, a pointer to the
2946 allocated memory is returned, otherwise the @code{fallback} trait of the
2947 allocator determines the behavior.  The content of the allocated memory is
2948 unspecified.
2950 In @code{target} regions, either the @code{dynamic_allocators} clause must
2951 appear on a @code{requires} directive in the same compilation unit -- or the
2952 @var{allocator} argument may only be a constant expression with the value of
2953 one of the predefined allocators and may not be @code{omp_null_allocator}.
2955 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
2957 @item @emph{C}:
2958 @multitable @columnfractions .20 .80
2959 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2960 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2961 @end multitable
2963 @item @emph{C++}:
2964 @multitable @columnfractions .20 .80
2965 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2966 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2967 @end multitable
2969 @item @emph{Fortran}:
2970 @multitable @columnfractions .20 .80
2971 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
2972 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2973 @item                   @tab @code{integer (c_size_t), value :: size}
2974 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2975 @end multitable
2977 @item @emph{See also}:
2978 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2979 @ref{omp_free}, @ref{omp_init_allocator}
2981 @item @emph{Reference}:
2982 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
2983 @end table
2987 @node omp_aligned_alloc
2988 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
2989 @table @asis
2990 @item @emph{Description}:
2991 Allocate memory with the specified allocator, which can either be a predefined
2992 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2993 is @code{omp_null_allocator}, the allocator specified by the
2994 @var{def-allocator-var} ICV is used.  @var{alignment} must be a positive power
2995 of two and @var{size} must be a nonnegative number that is a multiple of the
2996 alignment and denotes the number of bytes to be allocated; if @var{size} is
2997 zero, @code{omp_aligned_alloc} will return a null pointer.  The alignment will
2998 be at least the maximal value required by @code{alignment} trait of the
2999 allocator and the value of the  passed @var{alignment} argument.  If successful,
3000 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3001 trait of the allocator determines the behavior.  The content of the allocated
3002 memory is unspecified.
3004 In @code{target} regions, either the @code{dynamic_allocators} clause must
3005 appear on a @code{requires} directive in the same compilation unit -- or the
3006 @var{allocator} argument may only be a constant expression with the value of
3007 one of the predefined allocators and may not be @code{omp_null_allocator}.
3009 Memory allocated by @code{omp_aligned_alloc} must be freed using
3010 @code{omp_free}.
3012 @item @emph{C}:
3013 @multitable @columnfractions .20 .80
3014 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3015 @item                   @tab @code{  size_t size,}
3016 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3017 @end multitable
3019 @item @emph{C++}:
3020 @multitable @columnfractions .20 .80
3021 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3022 @item                   @tab @code{  size_t size,}
3023 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3024 @end multitable
3026 @item @emph{Fortran}:
3027 @multitable @columnfractions .20 .80
3028 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3029 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3030 @item                   @tab @code{integer (c_size_t), value :: alignment, size}
3031 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3032 @end multitable
3034 @item @emph{See also}:
3035 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3036 @ref{omp_free}, @ref{omp_init_allocator}
3038 @item @emph{Reference}:
3039 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3040 @end table
3044 @node omp_free
3045 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3046 @table @asis
3047 @item @emph{Description}:
3048 The @code{omp_free} routine deallocates memory previously allocated by an
3049 OpenMP memory-management routine. The @var{ptr} argument must point to such
3050 memory or be a null pointer; if it is a null pointer, no operation is
3051 performed.  If specified, the @var{allocator} argument must be either the
3052 memory allocator that was used for the allocation or @code{omp_null_allocator};
3053 if it is @code{omp_null_allocator}, the implementation will determine the value
3054 automatically.
3056 Calling @code{omp_free} invokes undefined behavior if the memory
3057 was already deallocated or when the used allocator has already been destroyed.
3059 @item @emph{C}:
3060 @multitable @columnfractions .20 .80
3061 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3062 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3063 @end multitable
3065 @item @emph{C++}:
3066 @multitable @columnfractions .20 .80
3067 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3068 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3069 @end multitable
3071 @item @emph{Fortran}:
3072 @multitable @columnfractions .20 .80
3073 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3074 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3075 @item                   @tab @code{type (c_ptr), value :: ptr}
3076 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3077 @end multitable
3079 @item @emph{See also}:
3080 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3081 @ref{omp_aligned_calloc}, @ref{omp_realloc}
3083 @item @emph{Reference}:
3084 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3085 @end table
3089 @node omp_calloc
3090 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3091 @table @asis
3092 @item @emph{Description}:
3093 Allocate zero-initialized memory with the specified allocator, which can either
3094 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3095 the allocators is @code{omp_null_allocator}, the allocator specified by the
3096 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3097 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3098 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3099 zero, @code{omp_calloc} will return a null pointer.  If successful, a pointer to
3100 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3101 trait of the allocator determines the behavior.
3103 In @code{target} regions, either the @code{dynamic_allocators} clause must
3104 appear on a @code{requires} directive in the same compilation unit -- or the
3105 @var{allocator} argument may only be a constant expression with the value of
3106 one of the predefined allocators and may not be @code{omp_null_allocator}.
3108 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3110 @item @emph{C}:
3111 @multitable @columnfractions .20 .80
3112 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3113 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3114 @end multitable
3116 @item @emph{C++}:
3117 @multitable @columnfractions .20 .80
3118 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3119 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3120 @end multitable
3122 @item @emph{Fortran}:
3123 @multitable @columnfractions .20 .80
3124 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3125 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3126 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3127 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3128 @end multitable
3130 @item @emph{See also}:
3131 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3132 @ref{omp_free}, @ref{omp_init_allocator}
3134 @item @emph{Reference}:
3135 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3136 @end table
3140 @node omp_aligned_calloc
3141 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3142 @table @asis
3143 @item @emph{Description}:
3144 Allocate zero-initialized memory with the specified allocator, which can either
3145 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3146 the allocators is @code{omp_null_allocator}, the allocator specified by the
3147 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3148 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3149 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3150 zero, @code{omp_aligned_calloc} will return a null pointer.  @var{alignment}
3151 must be a positive power of two and @var{size} must be a multiple of the
3152 alignment; the alignment will be at least the maximal value required by
3153 @code{alignment} trait of the allocator and the value of the  passed
3154 @var{alignment} argument.  If successful, a pointer to the zero-initialized
3155 allocated memory is returned, otherwise the @code{fallback} trait of the
3156 allocator determines the behavior.
3158 In @code{target} regions, either the @code{dynamic_allocators} clause must
3159 appear on a @code{requires} directive in the same compilation unit -- or the
3160 @var{allocator} argument may only be a constant expression with the value of
3161 one of the predefined allocators and may not be @code{omp_null_allocator}.
3163 Memory allocated by @code{omp_aligned_calloc} must be freed using
3164 @code{omp_free}.
3166 @item @emph{C}:
3167 @multitable @columnfractions .20 .80
3168 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3169 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3170 @end multitable
3172 @item @emph{C++}:
3173 @multitable @columnfractions .20 .80
3174 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3175 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3176 @end multitable
3178 @item @emph{Fortran}:
3179 @multitable @columnfractions .20 .80
3180 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3181 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3182 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3183 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3184 @end multitable
3186 @item @emph{See also}:
3187 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3188 @ref{omp_free}, @ref{omp_init_allocator}
3190 @item @emph{Reference}:
3191 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3192 @end table
3196 @node omp_realloc
3197 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3198 @table @asis
3199 @item @emph{Description}:
3200 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3201 and allocates new memory with the specified @var{allocator} argument; the
3202 new memory will have the content of the old memory up to the minimum of the
3203 old size and the new @var{size}, otherwise the content of the returned memory
3204 is unspecified.  If the new allocator is the same as the old one, the routine
3205 tries to resize the existing memory allocation, returning the same address as
3206 @var{ptr} if successful.  @var{ptr} must point to memory allocated by an OpenMP
3207 memory-management routine.
3209 The @var{allocator} and @var{free_allocator} arguments must be a predefined
3210 allocator, an allocator handle or @code{omp_null_allocator}.  If
3211 @var{free_allocator} is @code{omp_null_allocator}, the implementation
3212 automatically determines the allocator used for the allocation of @var{ptr}.
3213 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is is not a
3214 null pointer, the same allocator as @code{free_allocator} is used and
3215 when @var{ptr} is a null pointer the allocator specified by the
3216 @var{def-allocator-var} ICV is used.
3218 The @var{size} must be a nonnegative number denoting the number of bytes to be
3219 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3220 memory and return a null pointer.  When @var{size} is nonzero: if successful,
3221 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3222 trait of the allocator determines the behavior.
3224 In @code{target} regions, either the @code{dynamic_allocators} clause must
3225 appear on a @code{requires} directive in the same compilation unit -- or the
3226 @var{free_allocator} and @var{allocator} arguments may only be a constant
3227 expression with the value of one of the predefined allocators and may not be
3228 @code{omp_null_allocator}.
3230 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3231 Calling @code{omp_free} invokes undefined behavior if the memory
3232 was already deallocated or when the used allocator has already been destroyed.
3234 @item @emph{C}:
3235 @multitable @columnfractions .20 .80
3236 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3237 @item                   @tab @code{  omp_allocator_handle_t allocator,}
3238 @item                   @tab @code{  omp_allocator_handle_t free_allocator)}
3239 @end multitable
3241 @item @emph{C++}:
3242 @multitable @columnfractions .20 .80
3243 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3244 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator,}
3245 @item                   @tab @code{  omp_allocator_handle_t free_allocator=omp_null_allocator)}
3246 @end multitable
3248 @item @emph{Fortran}:
3249 @multitable @columnfractions .20 .80
3250 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3251 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3252 @item                   @tab @code{type(C_ptr), value :: ptr}
3253 @item                   @tab @code{integer (c_size_t), value :: size}
3254 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3255 @end multitable
3257 @item @emph{See also}:
3258 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3259 @ref{omp_free}, @ref{omp_init_allocator}
3261 @item @emph{Reference}:
3262 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3263 @end table
3267 @c @node Tool Control Routine
3268 @c @section Tool Control Routine
3270 @c FIXME
3272 @node Environment Display Routine
3273 @section Environment Display Routine
3275 Routine to display the OpenMP version number and the initial value of ICVs.
3276 It has C linkage and does not throw exceptions.
3278 @menu
3279 * omp_display_env:: print the initial ICV values
3280 @end menu
3282 @node omp_display_env
3283 @subsection @code{omp_display_env} -- print the initial ICV values
3284 @table @asis
3285 @item @emph{Description}:
3286 Each time this routine is invoked, the OpenMP version number and initial value
3287 of internal control variables (ICVs) is printed on @code{stderr}.  The displayed
3288 values are those at startup after evaluating the environment variables; later
3289 calls to API routines or clauses used in enclosing constructs do not affect
3290 the output.
3292 If the @var{verbose} argument is @code{false}, only the OpenMP version and
3293 standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3294 GCC-specific ICVs are shown.
3296 The output consists of multiple lines and starts with
3297 @samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3298 ends with @samp{OPENMP DISPLAY ENVIRONMENT END}.  The @var{name} is followed by
3299 an equal sign and the @var{value} is enclosed in single quotes.
3301 The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3302 and shows as value the supported OpenMP version number (4-digit year, 2-digit
3303 month) of the implementation, matching the value of the @code{_OPENMP} macro
3304 and, in Fortran, the named constant @code{openmp_version}.
3306 In each of the succeeding lines, the @var{name} matches the environment-variable
3307 name of an ICV and shows its value.  Those line are might be prefixed by pair of
3308 brackets and a space, where the brackets enclose a comma-separated list of
3309 devices to which the ICV-value combination applies to; the value can either be a
3310 numeric device number or an abstract name denoting all devices (@code{all}), the
3311 initial host device (@code{host}) or all devices but the host (@code{device}).
3312 Note that the same ICV might be printed multiple times for multiple devices,
3313 even if all have the same value.
3315 The effect when invoked from within a @code{target} region is unspecified.
3317 @item @emph{C/C++}:
3318 @multitable @columnfractions .20 .80
3319 @item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3320 @end multitable
3322 @item @emph{Fortran}:
3323 @multitable @columnfractions .20 .80
3324 @item @emph{Interface}: @tab @code{subroutine omp_display_env(vebose)}
3325 @item                   @tab @code{logical, intent(in) :: verbose}
3326 @end multitable
3328 @item @emph{Example}:
3329 Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3330 are only printed when @var{varbose} set to @code{true}.
3332 @smallexample
3333 OPENMP DISPLAY ENVIRONMENT BEGIN
3334   _OPENMP = '201511'
3335   [host] OMP_DYNAMIC = 'FALSE'
3336   [host] OMP_NESTED = 'FALSE'
3337   [all] OMP_CANCELLATION = 'FALSE'
3338   ...
3339   [host] GOMP_SPINCOUNT = '300000'
3340 OPENMP DISPLAY ENVIRONMENT END
3341 @end smallexample
3344 @item @emph{See also}:
3345 @ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3346 @ref{Implementation-defined ICV Initialization}
3348 @item @emph{Reference}:
3349 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3350 @end table
3353 @c ---------------------------------------------------------------------
3354 @c OpenMP Environment Variables
3355 @c ---------------------------------------------------------------------
3357 @node Environment Variables
3358 @chapter OpenMP Environment Variables
3360 The environment variables which beginning with @env{OMP_} are defined by
3361 section 4 of the OpenMP specification in version 4.5 or in a later version
3362 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
3363 Most @env{OMP_} environment variables have an associated internal control
3364 variable (ICV).
3366 For any OpenMP environment variable that sets an ICV and is neither
3367 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
3368 device-specific environment variables exist.  For them, the environment
3369 variable without suffix affects the host.  The suffix @code{_DEV_} followed
3370 by a non-negative device number less that the number of available devices sets
3371 the ICV for the corresponding device.  The suffix @code{_DEV} sets the ICV
3372 of all non-host devices for which a device-specific corresponding environment
3373 variable has not been set while the @code{_ALL} suffix sets the ICV of all
3374 host and non-host devices for which a more specific corresponding environment
3375 variable is not set.
3377 @menu
3378 * OMP_ALLOCATOR::           Set the default allocator
3379 * OMP_AFFINITY_FORMAT::     Set the format string used for affinity display
3380 * OMP_CANCELLATION::        Set whether cancellation is activated
3381 * OMP_DISPLAY_AFFINITY::    Display thread affinity information
3382 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
3383 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
3384 * OMP_DYNAMIC::             Dynamic adjustment of threads
3385 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
3386 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
3387 * OMP_NESTED::              Nested parallel regions
3388 * OMP_NUM_TEAMS::           Specifies the number of teams to use by teams region
3389 * OMP_NUM_THREADS::         Specifies the number of threads to use
3390 * OMP_PROC_BIND::           Whether threads may be moved between CPUs
3391 * OMP_PLACES::              Specifies on which CPUs the threads should be placed
3392 * OMP_STACKSIZE::           Set default thread stack size
3393 * OMP_SCHEDULE::            How threads are scheduled
3394 * OMP_TARGET_OFFLOAD::      Controls offloading behavior
3395 * OMP_TEAMS_THREAD_LIMIT::  Set the maximum number of threads imposed by teams
3396 * OMP_THREAD_LIMIT::        Set the maximum number of threads
3397 * OMP_WAIT_POLICY::         How waiting threads are handled
3398 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
3399 * GOMP_DEBUG::              Enable debugging output
3400 * GOMP_STACKSIZE::          Set default thread stack size
3401 * GOMP_SPINCOUNT::          Set the busy-wait spin count
3402 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
3403 @end menu
3406 @node OMP_ALLOCATOR
3407 @section @env{OMP_ALLOCATOR} -- Set the default allocator
3408 @cindex Environment Variable
3409 @table @asis
3410 @item @emph{ICV:} @var{def-allocator-var}
3411 @item @emph{Scope:} data environment
3412 @item @emph{Description}:
3413 Sets the default allocator that is used when no allocator has been specified
3414 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3415 routine is invoked with the @code{omp_null_allocator} allocator.
3416 If unset, @code{omp_default_mem_alloc} is used.
3418 The value can either be a predefined allocator or a predefined memory space
3419 or a predefined memory space followed by a colon and a comma-separated list
3420 of memory trait and value pairs, separated by @code{=}.
3422 Note: The corresponding device environment variables are currently not
3423 supported.  Therefore, the non-host @var{def-allocator-var} ICVs are always
3424 initialized to @code{omp_default_mem_alloc}.  However, on all devices,
3425 the @code{omp_set_default_allocator} API routine can be used to change
3426 value.
3428 @multitable @columnfractions .45 .45
3429 @headitem Predefined allocators @tab Associated predefined memory spaces
3430 @item omp_default_mem_alloc     @tab omp_default_mem_space
3431 @item omp_large_cap_mem_alloc   @tab omp_large_cap_mem_space
3432 @item omp_const_mem_alloc       @tab omp_const_mem_space
3433 @item omp_high_bw_mem_alloc     @tab omp_high_bw_mem_space
3434 @item omp_low_lat_mem_alloc     @tab omp_low_lat_mem_space
3435 @item omp_cgroup_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3436 @item omp_pteam_mem_alloc       @tab omp_low_lat_mem_space (implementation defined)
3437 @item omp_thread_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3438 @end multitable
3440 The predefined allocators use the default values for the traits,
3441 as listed below.  Except that the last three allocators have the
3442 @code{access} trait set to @code{cgroup}, @code{pteam}, and
3443 @code{thread}, respectively.
3445 @multitable @columnfractions .25 .40 .25
3446 @headitem Trait @tab Allowed values @tab Default value
3447 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
3448                             @code{serialized}, @code{private}
3449                        @tab @code{contended}
3450 @item @code{alignment} @tab Positive integer being a power of two
3451                        @tab 1 byte
3452 @item @code{access}    @tab @code{all}, @code{cgroup},
3453                             @code{pteam}, @code{thread}
3454                        @tab @code{all}
3455 @item @code{pool_size} @tab Positive integer
3456                        @tab See @ref{Memory allocation}
3457 @item @code{fallback}  @tab @code{default_mem_fb}, @code{null_fb},
3458                             @code{abort_fb}, @code{allocator_fb}
3459                        @tab See below
3460 @item @code{fb_data}   @tab @emph{unsupported as it needs an allocator handle}
3461                        @tab (none)
3462 @item @code{pinned}    @tab @code{true}, @code{false}
3463                        @tab @code{false}
3464 @item @code{partition} @tab @code{environment}, @code{nearest},
3465                             @code{blocked}, @code{interleaved}
3466                        @tab @code{environment}
3467 @end multitable
3469 For the @code{fallback} trait, the default value is @code{null_fb} for the
3470 @code{omp_default_mem_alloc} allocator and any allocator that is associated
3471 with device memory; for all other other allocators, it is @code{default_mem_fb}
3472 by default.
3474 Examples:
3475 @smallexample
3476 OMP_ALLOCATOR=omp_high_bw_mem_alloc
3477 OMP_ALLOCATOR=omp_large_cap_mem_space
3478 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
3479 @end smallexample
3481 @item @emph{See also}:
3482 @ref{Memory allocation}, @ref{omp_get_default_allocator},
3483 @ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
3485 @item @emph{Reference}:
3486 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
3487 @end table
3491 @node OMP_AFFINITY_FORMAT
3492 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
3493 @cindex Environment Variable
3494 @table @asis
3495 @item @emph{ICV:} @var{affinity-format-var}
3496 @item @emph{Scope:} device
3497 @item @emph{Description}:
3498 Sets the format string used when displaying OpenMP thread affinity information.
3499 Special values are output using @code{%} followed by an optional size
3500 specification and then either the single-character field type or its long
3501 name enclosed in curly braces; using @code{%%} displays a literal percent.
3502 The size specification consists of an optional @code{0.} or @code{.} followed
3503 by a positive integer, specifying the minimal width of the output.  With
3504 @code{0.} and numerical values, the output is padded with zeros on the left;
3505 with @code{.}, the output is padded by spaces on the left; otherwise, the
3506 output is padded by spaces on the right.  If unset, the value is
3507 ``@code{level %L thread %i affinity %A}''.
3509 Supported field types are:
3511 @multitable @columnfractions .10 .25 .60
3512 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
3513 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
3514 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
3515 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
3516 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
3517 @item a @tab ancestor_tnum
3518       @tab value returned by
3519            @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
3520 @item H @tab host @tab name of the host that executes the thread
3521 @item P @tab process_id @tab process identifier
3522 @item i @tab native_thread_id @tab native thread identifier
3523 @item A @tab thread_affinity
3524       @tab comma separated list of integer values or ranges, representing the
3525            processors on which a process might execute, subject to affinity
3526            mechanisms
3527 @end multitable
3529 For instance, after setting
3531 @smallexample
3532 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
3533 @end smallexample
3535 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
3536 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
3537 might display the following:
3539 @smallexample
3540 00!0!   1!4; 0;01;0;1;0-11
3541 00!3!   1!4; 0;01;0;1;0-11
3542 00!2!   1!4; 0;01;0;1;0-11
3543 00!1!   1!4; 0;01;0;1;0-11
3544 @end smallexample
3546 @item @emph{See also}:
3547 @ref{OMP_DISPLAY_AFFINITY}
3549 @item @emph{Reference}:
3550 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
3551 @end table
3555 @node OMP_CANCELLATION
3556 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
3557 @cindex Environment Variable
3558 @table @asis
3559 @item @emph{ICV:} @var{cancel-var}
3560 @item @emph{Scope:} global
3561 @item @emph{Description}:
3562 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
3563 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
3565 @item @emph{See also}:
3566 @ref{omp_get_cancellation}
3568 @item @emph{Reference}:
3569 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
3570 @end table
3574 @node OMP_DISPLAY_AFFINITY
3575 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
3576 @cindex Environment Variable
3577 @table @asis
3578 @item @emph{ICV:} @var{display-affinity-var}
3579 @item @emph{Scope:} global
3580 @item @emph{Description}:
3581 If set to @code{FALSE} or if unset, affinity displaying is disabled.
3582 If set to @code{TRUE}, the runtime displays affinity information about
3583 OpenMP threads in a parallel region upon entering the region and every time
3584 any change occurs.
3586 @item @emph{See also}:
3587 @ref{OMP_AFFINITY_FORMAT}
3589 @item @emph{Reference}:
3590 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
3591 @end table
3596 @node OMP_DISPLAY_ENV
3597 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
3598 @cindex Environment Variable
3599 @table @asis
3600 @item @emph{ICV:} none
3601 @item @emph{Scope:} not applicable
3602 @item @emph{Description}:
3603 If set to @code{TRUE}, the runtime displays the same information to
3604 @code{stderr} as shown by the @code{omp_display_env} routine invoked with
3605 @var{verbose} argument set to @code{false}.  If set to @code{VERBOSE}, the same
3606 information is shown as invoking the routine with @var{verbose} set to
3607 @code{true}. If unset or set to @code{FALSE}, this information is not shown.
3608 The result for any other value is unspecified.
3610 @item @emph{See also}:
3611 @ref{omp_display_env}
3613 @item @emph{Reference}:
3614 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
3615 @end table
3619 @node OMP_DEFAULT_DEVICE
3620 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
3621 @cindex Environment Variable
3622 @table @asis
3623 @item @emph{ICV:} @var{default-device-var}
3624 @item @emph{Scope:} data environment
3625 @item @emph{Description}:
3626 Set to choose the device which is used in a @code{target} region, unless the
3627 value is overridden by @code{omp_set_default_device} or by a @code{device}
3628 clause.  The value shall be the nonnegative device number. If no device with
3629 the given device number exists, the code is executed on the host.  If unset,
3630 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
3631 available, it is set to @code{omp_invalid_device}.  Otherwise, if unset,
3632 device number 0 is used.
3635 @item @emph{See also}:
3636 @ref{omp_get_default_device}, @ref{omp_set_default_device},
3637 @ref{OMP_TARGET_OFFLOAD}
3639 @item @emph{Reference}:
3640 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
3641 @end table
3645 @node OMP_DYNAMIC
3646 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
3647 @cindex Environment Variable
3648 @table @asis
3649 @item @emph{ICV:} @var{dyn-var}
3650 @item @emph{Scope:} global
3651 @item @emph{Description}:
3652 Enable or disable the dynamic adjustment of the number of threads 
3653 within a team.  The value of this environment variable shall be 
3654 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
3655 disabled by default.
3657 @item @emph{See also}:
3658 @ref{omp_set_dynamic}
3660 @item @emph{Reference}: 
3661 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
3662 @end table
3666 @node OMP_MAX_ACTIVE_LEVELS
3667 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
3668 @cindex Environment Variable
3669 @table @asis
3670 @item @emph{ICV:} @var{max-active-levels-var}
3671 @item @emph{Scope:} data environment
3672 @item @emph{Description}:
3673 Specifies the initial value for the maximum number of nested parallel
3674 regions.  The value of this variable shall be a positive integer.
3675 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
3676 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
3677 a list with more than one item, the maximum number of nested parallel
3678 regions is initialized to the largest number supported, otherwise
3679 it is set to one.
3681 @item @emph{See also}:
3682 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
3683 @ref{OMP_NUM_THREADS}
3686 @item @emph{Reference}: 
3687 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
3688 @end table
3692 @node OMP_MAX_TASK_PRIORITY
3693 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
3694 number that can be set for a task.
3695 @cindex Environment Variable
3696 @table @asis
3697 @item @emph{ICV:} @var{max-task-priority-var}
3698 @item @emph{Scope:} global
3699 @item @emph{Description}:
3700 Specifies the initial value for the maximum priority value that can be
3701 set for a task.  The value of this variable shall be a non-negative
3702 integer, and zero is allowed.  If undefined, the default priority is
3705 @item @emph{See also}:
3706 @ref{omp_get_max_task_priority}
3708 @item @emph{Reference}: 
3709 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
3710 @end table
3714 @node OMP_NESTED
3715 @section @env{OMP_NESTED} -- Nested parallel regions
3716 @cindex Environment Variable
3717 @cindex Implementation specific setting
3718 @table @asis
3719 @item @emph{ICV:} @var{max-active-levels-var}
3720 @item @emph{Scope:} data environment
3721 @item @emph{Description}:
3722 Enable or disable nested parallel regions, i.e., whether team members
3723 are allowed to create new teams.  The value of this environment variable 
3724 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
3725 of maximum active nested regions supported is by default set to the
3726 maximum supported, otherwise it is set to one.  If
3727 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
3728 setting.  If both are undefined, nested parallel regions are enabled if
3729 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
3730 more than one item, otherwise they are disabled by default.
3732 Note that the @code{OMP_NESTED} environment variable was deprecated in
3733 the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
3735 @item @emph{See also}:
3736 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
3737 @ref{OMP_MAX_ACTIVE_LEVELS}
3739 @item @emph{Reference}: 
3740 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
3741 @end table
3745 @node OMP_NUM_TEAMS
3746 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
3747 @cindex Environment Variable
3748 @table @asis
3749 @item @emph{ICV:} @var{nteams-var}
3750 @item @emph{Scope:} device
3751 @item @emph{Description}:
3752 Specifies the upper bound for number of teams to use in teams regions
3753 without explicit @code{num_teams} clause.  The value of this variable shall
3754 be a positive integer.  If undefined it defaults to 0 which means
3755 implementation defined upper bound.
3757 @item @emph{See also}:
3758 @ref{omp_set_num_teams}
3760 @item @emph{Reference}: 
3761 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
3762 @end table
3766 @node OMP_NUM_THREADS
3767 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
3768 @cindex Environment Variable
3769 @cindex Implementation specific setting
3770 @table @asis
3771 @item @emph{ICV:} @var{nthreads-var}
3772 @item @emph{Scope:} data environment
3773 @item @emph{Description}:
3774 Specifies the default number of threads to use in parallel regions.  The 
3775 value of this variable shall be a comma-separated list of positive integers;
3776 the value specifies the number of threads to use for the corresponding nested
3777 level.  Specifying more than one item in the list automatically enables
3778 nesting by default.  If undefined one thread per CPU is used.
3780 When a list with more than value is specified, it also affects the
3781 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3783 @item @emph{See also}:
3784 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
3786 @item @emph{Reference}: 
3787 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
3788 @end table
3792 @node OMP_PROC_BIND
3793 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
3794 @cindex Environment Variable
3795 @table @asis
3796 @item @emph{ICV:} @var{bind-var}
3797 @item @emph{Scope:} data environment
3798 @item @emph{Description}:
3799 Specifies whether threads may be moved between processors.  If set to
3800 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
3801 they may be moved.  Alternatively, a comma separated list with the
3802 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
3803 be used to specify the thread affinity policy for the corresponding nesting
3804 level.  With @code{PRIMARY} and @code{MASTER} the worker threads are in the
3805 same place partition as the primary thread.  With @code{CLOSE} those are
3806 kept close to the primary thread in contiguous place partitions.  And
3807 with @code{SPREAD} a sparse distribution
3808 across the place partitions is used.  Specifying more than one item in the
3809 list automatically enables nesting by default.
3811 When a list is specified, it also affects the @var{max-active-levels-var} ICV
3812 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3814 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
3815 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
3817 @item @emph{See also}:
3818 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
3819 @ref{OMP_MAX_ACTIVE_LEVELS}
3821 @item @emph{Reference}:
3822 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
3823 @end table
3827 @node OMP_PLACES
3828 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
3829 @cindex Environment Variable
3830 @table @asis
3831 @item @emph{ICV:} @var{place-partition-var}
3832 @item @emph{Scope:} implicit tasks
3833 @item @emph{Description}:
3834 The thread placement can be either specified using an abstract name or by an
3835 explicit list of the places.  The abstract names @code{threads}, @code{cores},
3836 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
3837 followed by a positive number in parentheses, which denotes the how many places
3838 shall be created.  With @code{threads} each place corresponds to a single
3839 hardware thread; @code{cores} to a single core with the corresponding number of
3840 hardware threads; with @code{sockets} the place corresponds to a single
3841 socket; with @code{ll_caches} to a set of cores that shares the last level
3842 cache on the device; and @code{numa_domains} to a set of cores for which their
3843 closest memory on the device is the same memory and at a similar distance from
3844 the cores.  The resulting placement can be shown by setting the
3845 @env{OMP_DISPLAY_ENV} environment variable.
3847 Alternatively, the placement can be specified explicitly as comma-separated
3848 list of places.  A place is specified by set of nonnegative numbers in curly
3849 braces, denoting the hardware threads.  The curly braces can be omitted
3850 when only a single number has been specified.  The hardware threads
3851 belonging to a place can either be specified as comma-separated list of
3852 nonnegative thread numbers or using an interval.  Multiple places can also be
3853 either specified by a comma-separated list of places or by an interval.  To
3854 specify an interval, a colon followed by the count is placed after
3855 the hardware thread number or the place.  Optionally, the length can be
3856 followed by a colon and the stride number -- otherwise a unit stride is
3857 assumed.  Placing an exclamation mark (@code{!}) directly before a curly
3858 brace or numbers inside the curly braces (excluding intervals)
3859 excludes those hardware threads.
3861 For instance, the following specifies the same places list:
3862 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
3863 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
3865 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
3866 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
3867 between CPUs following no placement policy.
3869 @item @emph{See also}:
3870 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
3871 @ref{OMP_DISPLAY_ENV}
3873 @item @emph{Reference}:
3874 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
3875 @end table
3879 @node OMP_STACKSIZE
3880 @section @env{OMP_STACKSIZE} -- Set default thread stack size
3881 @cindex Environment Variable
3882 @table @asis
3883 @item @emph{ICV:} @var{stacksize-var}
3884 @item @emph{Scope:} device
3885 @item @emph{Description}:
3886 Set the default thread stack size in kilobytes, unless the number
3887 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
3888 case the size is, respectively, in bytes, kilobytes, megabytes
3889 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
3890 which gets the number of bytes as an argument.  If the stack size cannot
3891 be set due to system constraints, an error is reported and the initial
3892 stack size is left unchanged.  If undefined, the stack size is system
3893 dependent.
3895 @item @emph{See also}:
3896 @ref{GOMP_STACKSIZE}
3898 @item @emph{Reference}: 
3899 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
3900 @end table
3904 @node OMP_SCHEDULE
3905 @section @env{OMP_SCHEDULE} -- How threads are scheduled
3906 @cindex Environment Variable
3907 @cindex Implementation specific setting
3908 @table @asis
3909 @item @emph{ICV:} @var{run-sched-var}
3910 @item @emph{Scope:} data environment
3911 @item @emph{Description}:
3912 Allows to specify @code{schedule type} and @code{chunk size}. 
3913 The value of the variable shall have the form: @code{type[,chunk]} where
3914 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
3915 The optional @code{chunk} size shall be a positive integer.  If undefined,
3916 dynamic scheduling and a chunk size of 1 is used.
3918 @item @emph{See also}:
3919 @ref{omp_set_schedule}
3921 @item @emph{Reference}: 
3922 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
3923 @end table
3927 @node OMP_TARGET_OFFLOAD
3928 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
3929 @cindex Environment Variable
3930 @cindex Implementation specific setting
3931 @table @asis
3932 @item @emph{ICV:} @var{target-offload-var}
3933 @item @emph{Scope:} global
3934 @item @emph{Description}:
3935 Specifies the behavior with regard to offloading code to a device.  This
3936 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
3937 or @code{DEFAULT}.
3939 If set to @code{MANDATORY}, the program terminates with an error if
3940 any device construct or device memory routine uses a device that is unavailable
3941 or not supported by the implementation, or uses a non-conforming device number.
3942 If set to @code{DISABLED}, then offloading is disabled and all code runs on
3943 the host. If set to @code{DEFAULT}, the program tries offloading to the
3944 device first, then falls back to running code on the host if it cannot.
3946 If undefined, then the program behaves as if @code{DEFAULT} was set.
3948 Note: Even with @code{MANDATORY}, no run-time termination is performed when
3949 the device number in a @code{device} clause or argument to a device memory
3950 routine is for host, which includes using the device number in the
3951 @var{default-device-var} ICV.  However, the initial value of
3952 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
3954 @item @emph{See also}:
3955 @ref{OMP_DEFAULT_DEVICE}
3957 @item @emph{Reference}:
3958 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
3959 @end table
3963 @node OMP_TEAMS_THREAD_LIMIT
3964 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
3965 @cindex Environment Variable
3966 @table @asis
3967 @item @emph{ICV:} @var{teams-thread-limit-var}
3968 @item @emph{Scope:} device
3969 @item @emph{Description}:
3970 Specifies an upper bound for the number of threads to use by each contention
3971 group created by a teams construct without explicit @code{thread_limit}
3972 clause.  The value of this variable shall be a positive integer.  If undefined,
3973 the value of 0 is used which stands for an implementation defined upper
3974 limit.
3976 @item @emph{See also}:
3977 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
3979 @item @emph{Reference}: 
3980 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
3981 @end table
3985 @node OMP_THREAD_LIMIT
3986 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
3987 @cindex Environment Variable
3988 @table @asis
3989 @item @emph{ICV:} @var{thread-limit-var}
3990 @item @emph{Scope:} data environment
3991 @item @emph{Description}:
3992 Specifies the number of threads to use for the whole program.  The
3993 value of this variable shall be a positive integer.  If undefined,
3994 the number of threads is not limited.
3996 @item @emph{See also}:
3997 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
3999 @item @emph{Reference}: 
4000 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4001 @end table
4005 @node OMP_WAIT_POLICY
4006 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4007 @cindex Environment Variable
4008 @table @asis
4009 @item @emph{Description}:
4010 Specifies whether waiting threads should be active or passive.  If
4011 the value is @code{PASSIVE}, waiting threads should not consume CPU
4012 power while waiting; while the value is @code{ACTIVE} specifies that
4013 they should.  If undefined, threads wait actively for a short time
4014 before waiting passively.
4016 @item @emph{See also}:
4017 @ref{GOMP_SPINCOUNT}
4019 @item @emph{Reference}: 
4020 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4021 @end table
4025 @node GOMP_CPU_AFFINITY
4026 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4027 @cindex Environment Variable
4028 @table @asis
4029 @item @emph{Description}:
4030 Binds threads to specific CPUs.  The variable should contain a space-separated
4031 or comma-separated list of CPUs.  This list may contain different kinds of 
4032 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
4033 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
4034 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4035 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
4036 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4037 and 14 respectively and then starts assigning back from the beginning of
4038 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4040 There is no libgomp library routine to determine whether a CPU affinity
4041 specification is in effect.  As a workaround, language-specific library 
4042 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
4043 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
4044 environment variable.  A defined CPU affinity on startup cannot be changed 
4045 or disabled during the runtime of the application.
4047 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4048 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
4049 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4050 @code{FALSE}, the host system handles the assignment of threads to CPUs.
4052 @item @emph{See also}:
4053 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4054 @end table
4058 @node GOMP_DEBUG
4059 @section @env{GOMP_DEBUG} -- Enable debugging output
4060 @cindex Environment Variable
4061 @table @asis
4062 @item @emph{Description}:
4063 Enable debugging output.  The variable should be set to @code{0}
4064 (disabled, also the default if not set), or @code{1} (enabled).
4066 If enabled, some debugging output is printed during execution.
4067 This is currently not specified in more detail, and subject to change.
4068 @end table
4072 @node GOMP_STACKSIZE
4073 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
4074 @cindex Environment Variable
4075 @cindex Implementation specific setting
4076 @table @asis
4077 @item @emph{Description}:
4078 Set the default thread stack size in kilobytes.  This is different from
4079 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
4080 argument.  If the stack size cannot be set due to system constraints, an 
4081 error is reported and the initial stack size is left unchanged.  If undefined,
4082 the stack size is system dependent.
4084 @item @emph{See also}:
4085 @ref{OMP_STACKSIZE}
4087 @item @emph{Reference}: 
4088 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4089 GCC Patches Mailinglist}, 
4090 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4091 GCC Patches Mailinglist}
4092 @end table
4096 @node GOMP_SPINCOUNT
4097 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4098 @cindex Environment Variable
4099 @cindex Implementation specific setting
4100 @table @asis
4101 @item @emph{Description}:
4102 Determines how long a threads waits actively with consuming CPU power
4103 before waiting passively without consuming CPU power.  The value may be
4104 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4105 integer which gives the number of spins of the busy-wait loop.  The
4106 integer may optionally be followed by the following suffixes acting
4107 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4108 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4109 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4110 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
4111 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4112 If there are more OpenMP threads than available CPUs, 1000 and 100
4113 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4114 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4115 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4117 @item @emph{See also}:
4118 @ref{OMP_WAIT_POLICY}
4119 @end table
4123 @node GOMP_RTEMS_THREAD_POOLS
4124 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4125 @cindex Environment Variable
4126 @cindex Implementation specific setting
4127 @table @asis
4128 @item @emph{Description}:
4129 This environment variable is only used on the RTEMS real-time operating system.
4130 It determines the scheduler instance specific thread pools.  The format for
4131 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4132 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4133 separated by @code{:} where:
4134 @itemize @bullet
4135 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
4136 instance.
4137 @item @code{$<priority>} is an optional priority for the worker threads of a
4138 thread pool according to @code{pthread_setschedparam}.  In case a priority
4139 value is omitted, then a worker thread inherits the priority of the OpenMP
4140 primary thread that created it.  The priority of the worker thread is not
4141 changed after creation, even if a new OpenMP primary thread using the worker has
4142 a different priority.
4143 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
4144 RTEMS application configuration.
4145 @end itemize
4146 In case no thread pool configuration is specified for a scheduler instance,
4147 then each OpenMP primary thread of this scheduler instance uses its own
4148 dynamically allocated thread pool.  To limit the worker thread count of the
4149 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4150 @item @emph{Example}:
4151 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4152 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4153 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
4154 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
4155 one thread pool available.  Since no priority is specified for this scheduler
4156 instance, the worker thread inherits the priority of the OpenMP primary thread
4157 that created it.  In the scheduler instance @code{WRK1} there are three thread
4158 pools available and their worker threads run at priority four.
4159 @end table
4163 @c ---------------------------------------------------------------------
4164 @c Enabling OpenACC
4165 @c ---------------------------------------------------------------------
4167 @node Enabling OpenACC
4168 @chapter Enabling OpenACC
4170 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
4171 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
4172 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4173 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4174 fixed source form.  The flag also arranges for automatic linking of the OpenACC
4175 runtime library (@ref{OpenACC Runtime Library Routines}).
4177 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4179 A complete description of all OpenACC directives accepted may be found in 
4180 the @uref{https://www.openacc.org, OpenACC} Application Programming
4181 Interface manual, version 2.6.
4185 @c ---------------------------------------------------------------------
4186 @c OpenACC Runtime Library Routines
4187 @c ---------------------------------------------------------------------
4189 @node OpenACC Runtime Library Routines
4190 @chapter OpenACC Runtime Library Routines
4192 The runtime routines described here are defined by section 3 of the OpenACC
4193 specifications in version 2.6.
4194 They have C linkage, and do not throw exceptions.
4195 Generally, they are available only for the host, with the exception of
4196 @code{acc_on_device}, which is available for both the host and the
4197 acceleration device.
4199 @menu
4200 * acc_get_num_devices::         Get number of devices for the given device
4201                                 type.
4202 * acc_set_device_type::         Set type of device accelerator to use.
4203 * acc_get_device_type::         Get type of device accelerator to be used.
4204 * acc_set_device_num::          Set device number to use.
4205 * acc_get_device_num::          Get device number to be used.
4206 * acc_get_property::            Get device property.
4207 * acc_async_test::              Tests for completion of a specific asynchronous
4208                                 operation.
4209 * acc_async_test_all::          Tests for completion of all asynchronous
4210                                 operations.
4211 * acc_wait::                    Wait for completion of a specific asynchronous
4212                                 operation.
4213 * acc_wait_all::                Waits for completion of all asynchronous
4214                                 operations.
4215 * acc_wait_all_async::          Wait for completion of all asynchronous
4216                                 operations.
4217 * acc_wait_async::              Wait for completion of asynchronous operations.
4218 * acc_init::                    Initialize runtime for a specific device type.
4219 * acc_shutdown::                Shuts down the runtime for a specific device
4220                                 type.
4221 * acc_on_device::               Whether executing on a particular device
4222 * acc_malloc::                  Allocate device memory.
4223 * acc_free::                    Free device memory.
4224 * acc_copyin::                  Allocate device memory and copy host memory to
4225                                 it.
4226 * acc_present_or_copyin::       If the data is not present on the device,
4227                                 allocate device memory and copy from host
4228                                 memory.
4229 * acc_create::                  Allocate device memory and map it to host
4230                                 memory.
4231 * acc_present_or_create::       If the data is not present on the device,
4232                                 allocate device memory and map it to host
4233                                 memory.
4234 * acc_copyout::                 Copy device memory to host memory.
4235 * acc_delete::                  Free device memory.
4236 * acc_update_device::           Update device memory from mapped host memory.
4237 * acc_update_self::             Update host memory from mapped device memory.
4238 * acc_map_data::                Map previously allocated device memory to host
4239                                 memory.
4240 * acc_unmap_data::              Unmap device memory from host memory.
4241 * acc_deviceptr::               Get device pointer associated with specific
4242                                 host address.
4243 * acc_hostptr::                 Get host pointer associated with specific
4244                                 device address.
4245 * acc_is_present::              Indicate whether host variable / array is
4246                                 present on device.
4247 * acc_memcpy_to_device::        Copy host memory to device memory.
4248 * acc_memcpy_from_device::      Copy device memory to host memory.
4249 * acc_attach::                  Let device pointer point to device-pointer target.
4250 * acc_detach::                  Let device pointer point to host-pointer target.
4252 API routines for target platforms.
4254 * acc_get_current_cuda_device:: Get CUDA device handle.
4255 * acc_get_current_cuda_context::Get CUDA context handle.
4256 * acc_get_cuda_stream::         Get CUDA stream handle.
4257 * acc_set_cuda_stream::         Set CUDA stream handle.
4259 API routines for the OpenACC Profiling Interface.
4261 * acc_prof_register::           Register callbacks.
4262 * acc_prof_unregister::         Unregister callbacks.
4263 * acc_prof_lookup::             Obtain inquiry functions.
4264 * acc_register_library::        Library registration.
4265 @end menu
4269 @node acc_get_num_devices
4270 @section @code{acc_get_num_devices} -- Get number of devices for given device type
4271 @table @asis
4272 @item @emph{Description}
4273 This function returns a value indicating the number of devices available
4274 for the device type specified in @var{devicetype}. 
4276 @item @emph{C/C++}:
4277 @multitable @columnfractions .20 .80
4278 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4279 @end multitable
4281 @item @emph{Fortran}:
4282 @multitable @columnfractions .20 .80
4283 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4284 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
4285 @end multitable
4287 @item @emph{Reference}:
4288 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4289 3.2.1.
4290 @end table
4294 @node acc_set_device_type
4295 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
4296 @table @asis
4297 @item @emph{Description}
4298 This function indicates to the runtime library which device type, specified
4299 in @var{devicetype}, to use when executing a parallel or kernels region. 
4301 @item @emph{C/C++}:
4302 @multitable @columnfractions .20 .80
4303 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4304 @end multitable
4306 @item @emph{Fortran}:
4307 @multitable @columnfractions .20 .80
4308 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4309 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4310 @end multitable
4312 @item @emph{Reference}:
4313 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4314 3.2.2.
4315 @end table
4319 @node acc_get_device_type
4320 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4321 @table @asis
4322 @item @emph{Description}
4323 This function returns what device type will be used when executing a
4324 parallel or kernels region.
4326 This function returns @code{acc_device_none} if
4327 @code{acc_get_device_type} is called from
4328 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4329 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4330 Interface}), that is, if the device is currently being initialized.
4332 @item @emph{C/C++}:
4333 @multitable @columnfractions .20 .80
4334 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4335 @end multitable
4337 @item @emph{Fortran}:
4338 @multitable @columnfractions .20 .80
4339 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4340 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4341 @end multitable
4343 @item @emph{Reference}:
4344 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4345 3.2.3.
4346 @end table
4350 @node acc_set_device_num
4351 @section @code{acc_set_device_num} -- Set device number to use.
4352 @table @asis
4353 @item @emph{Description}
4354 This function will indicate to the runtime which device number,
4355 specified by @var{devicenum}, associated with the specified device
4356 type @var{devicetype}.
4358 @item @emph{C/C++}:
4359 @multitable @columnfractions .20 .80
4360 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4361 @end multitable
4363 @item @emph{Fortran}:
4364 @multitable @columnfractions .20 .80
4365 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4366 @item                   @tab @code{integer devicenum}
4367 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4368 @end multitable
4370 @item @emph{Reference}:
4371 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4372 3.2.4.
4373 @end table
4377 @node acc_get_device_num
4378 @section @code{acc_get_device_num} -- Get device number to be used.
4379 @table @asis
4380 @item @emph{Description}
4381 This function returns which device number associated with the specified device
4382 type @var{devicetype}, will be used when executing a parallel or kernels
4383 region.
4385 @item @emph{C/C++}:
4386 @multitable @columnfractions .20 .80
4387 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4388 @end multitable
4390 @item @emph{Fortran}:
4391 @multitable @columnfractions .20 .80
4392 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4393 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4394 @item                   @tab @code{integer acc_get_device_num}
4395 @end multitable
4397 @item @emph{Reference}:
4398 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4399 3.2.5.
4400 @end table
4404 @node acc_get_property
4405 @section @code{acc_get_property} -- Get device property.
4406 @cindex acc_get_property
4407 @cindex acc_get_property_string
4408 @table @asis
4409 @item @emph{Description}
4410 These routines return the value of the specified @var{property} for the
4411 device being queried according to @var{devicenum} and @var{devicetype}.
4412 Integer-valued and string-valued properties are returned by
4413 @code{acc_get_property} and @code{acc_get_property_string} respectively.
4414 The Fortran @code{acc_get_property_string} subroutine returns the string
4415 retrieved in its fourth argument while the remaining entry points are
4416 functions, which pass the return value as their result.
4418 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
4419 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
4420 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
4421 for consistency and the return type of the @code{acc_get_property} function is
4422 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
4423 The parameter @code{acc_device_property} is still provided,
4424 but might be removed in a future version of GCC.
4426 @item @emph{C/C++}:
4427 @multitable @columnfractions .20 .80
4428 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4429 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4430 @end multitable
4432 @item @emph{Fortran}:
4433 @multitable @columnfractions .20 .80
4434 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
4435 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
4436 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
4437 @item                   @tab @code{integer devicenum}
4438 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4439 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
4440 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
4441 @item                   @tab @code{character(*) string}
4442 @end multitable
4444 @item @emph{Reference}:
4445 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4446 3.2.6.
4447 @end table
4451 @node acc_async_test
4452 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
4453 @table @asis
4454 @item @emph{Description}
4455 This function tests for completion of the asynchronous operation specified
4456 in @var{arg}. In C/C++, a non-zero value is returned to indicate
4457 the specified asynchronous operation has completed while Fortran returns
4458 @code{true}. If the asynchronous operation has not completed, C/C++ returns
4459 zero and Fortran returns @code{false}.
4461 @item @emph{C/C++}:
4462 @multitable @columnfractions .20 .80
4463 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
4464 @end multitable
4466 @item @emph{Fortran}:
4467 @multitable @columnfractions .20 .80
4468 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
4469 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
4470 @item                   @tab @code{logical acc_async_test}
4471 @end multitable
4473 @item @emph{Reference}:
4474 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4475 3.2.9.
4476 @end table
4480 @node acc_async_test_all
4481 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
4482 @table @asis
4483 @item @emph{Description}
4484 This function tests for completion of all asynchronous operations.
4485 In C/C++, a non-zero value is returned to indicate all asynchronous
4486 operations have completed while Fortran returns @code{true}. If
4487 any asynchronous operation has not completed, C/C++ returns zero and
4488 Fortran returns @code{false}.
4490 @item @emph{C/C++}:
4491 @multitable @columnfractions .20 .80
4492 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
4493 @end multitable
4495 @item @emph{Fortran}:
4496 @multitable @columnfractions .20 .80
4497 @item @emph{Interface}: @tab @code{function acc_async_test()}
4498 @item                   @tab @code{logical acc_get_device_num}
4499 @end multitable
4501 @item @emph{Reference}:
4502 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4503 3.2.10.
4504 @end table
4508 @node acc_wait
4509 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
4510 @table @asis
4511 @item @emph{Description}
4512 This function waits for completion of the asynchronous operation
4513 specified in @var{arg}.
4515 @item @emph{C/C++}:
4516 @multitable @columnfractions .20 .80
4517 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
4518 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
4519 @end multitable
4521 @item @emph{Fortran}:
4522 @multitable @columnfractions .20 .80
4523 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
4524 @item                   @tab @code{integer(acc_handle_kind) arg}
4525 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
4526 @item                                               @tab @code{integer(acc_handle_kind) arg}
4527 @end multitable
4529 @item @emph{Reference}:
4530 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4531 3.2.11.
4532 @end table
4536 @node acc_wait_all
4537 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
4538 @table @asis
4539 @item @emph{Description}
4540 This function waits for the completion of all asynchronous operations.
4542 @item @emph{C/C++}:
4543 @multitable @columnfractions .20 .80
4544 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
4545 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
4546 @end multitable
4548 @item @emph{Fortran}:
4549 @multitable @columnfractions .20 .80
4550 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
4551 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
4552 @end multitable
4554 @item @emph{Reference}:
4555 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4556 3.2.13.
4557 @end table
4561 @node acc_wait_all_async
4562 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
4563 @table @asis
4564 @item @emph{Description}
4565 This function enqueues a wait operation on the queue @var{async} for any
4566 and all asynchronous operations that have been previously enqueued on
4567 any queue.
4569 @item @emph{C/C++}:
4570 @multitable @columnfractions .20 .80
4571 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
4572 @end multitable
4574 @item @emph{Fortran}:
4575 @multitable @columnfractions .20 .80
4576 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
4577 @item                   @tab @code{integer(acc_handle_kind) async}
4578 @end multitable
4580 @item @emph{Reference}:
4581 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4582 3.2.14.
4583 @end table
4587 @node acc_wait_async
4588 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
4589 @table @asis
4590 @item @emph{Description}
4591 This function enqueues a wait operation on queue @var{async} for any and all
4592 asynchronous operations enqueued on queue @var{arg}.
4594 @item @emph{C/C++}:
4595 @multitable @columnfractions .20 .80
4596 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
4597 @end multitable
4599 @item @emph{Fortran}:
4600 @multitable @columnfractions .20 .80
4601 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
4602 @item                   @tab @code{integer(acc_handle_kind) arg, async}
4603 @end multitable
4605 @item @emph{Reference}:
4606 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4607 3.2.12.
4608 @end table
4612 @node acc_init
4613 @section @code{acc_init} -- Initialize runtime for a specific device type.
4614 @table @asis
4615 @item @emph{Description}
4616 This function initializes the runtime for the device type specified in
4617 @var{devicetype}.
4619 @item @emph{C/C++}:
4620 @multitable @columnfractions .20 .80
4621 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
4622 @end multitable
4624 @item @emph{Fortran}:
4625 @multitable @columnfractions .20 .80
4626 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
4627 @item                   @tab @code{integer(acc_device_kind) devicetype}
4628 @end multitable
4630 @item @emph{Reference}:
4631 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4632 3.2.7.
4633 @end table
4637 @node acc_shutdown
4638 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
4639 @table @asis
4640 @item @emph{Description}
4641 This function shuts down the runtime for the device type specified in
4642 @var{devicetype}.
4644 @item @emph{C/C++}:
4645 @multitable @columnfractions .20 .80
4646 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
4647 @end multitable
4649 @item @emph{Fortran}:
4650 @multitable @columnfractions .20 .80
4651 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
4652 @item                   @tab @code{integer(acc_device_kind) devicetype}
4653 @end multitable
4655 @item @emph{Reference}:
4656 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4657 3.2.8.
4658 @end table
4662 @node acc_on_device
4663 @section @code{acc_on_device} -- Whether executing on a particular device
4664 @table @asis
4665 @item @emph{Description}:
4666 This function returns whether the program is executing on a particular
4667 device specified in @var{devicetype}. In C/C++ a non-zero value is
4668 returned to indicate the device is executing on the specified device type.
4669 In Fortran, @code{true} is returned. If the program is not executing
4670 on the specified device type C/C++ returns zero, while Fortran
4671 returns @code{false}.
4673 @item @emph{C/C++}:
4674 @multitable @columnfractions .20 .80
4675 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
4676 @end multitable
4678 @item @emph{Fortran}:
4679 @multitable @columnfractions .20 .80
4680 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
4681 @item                   @tab @code{integer(acc_device_kind) devicetype}
4682 @item                   @tab @code{logical acc_on_device}
4683 @end multitable
4685 @item @emph{Reference}:
4686 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4687 3.2.17.
4688 @end table
4692 @node acc_malloc
4693 @section @code{acc_malloc} -- Allocate device memory.
4694 @table @asis
4695 @item @emph{Description}
4696 This function allocates @var{bytes} bytes of device memory. It returns
4697 the device address of the allocated memory.
4699 @item @emph{C/C++}:
4700 @multitable @columnfractions .20 .80
4701 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
4702 @end multitable
4704 @item @emph{Fortran}:
4705 @multitable @columnfractions .20 .80
4706 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
4707 @item                   @tab @code{integer(c_size_t), value :: bytes}
4708 @end multitable
4710 @item @emph{Reference}:
4711 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4712 3.2.18.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4713 3.2.16.
4714 @end table
4718 @node acc_free
4719 @section @code{acc_free} -- Free device memory.
4720 @table @asis
4721 @item @emph{Description}
4722 Free previously allocated device memory at the device address @code{data_dev}.
4724 @item @emph{C/C++}:
4725 @multitable @columnfractions .20 .80
4726 @item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
4727 @end multitable
4729 @item @emph{Fortran}:
4730 @multitable @columnfractions .20 .80
4731 @item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
4732 @item                   @tab @code{type(c_ptr), value :: data_dev}
4733 @end multitable
4735 @item @emph{Reference}:
4736 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4737 3.2.19.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4738 3.2.17.
4739 @end table
4743 @node acc_copyin
4744 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
4745 @table @asis
4746 @item @emph{Description}
4747 In C/C++, this function allocates @var{len} bytes of device memory
4748 and maps it to the specified host address in @var{a}. The device
4749 address of the newly allocated device memory is returned.
4751 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4752 a contiguous array section. The second form @var{a} specifies a
4753 variable or array element and @var{len} specifies the length in bytes.
4755 @item @emph{C/C++}:
4756 @multitable @columnfractions .20 .80
4757 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
4758 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
4759 @end multitable
4761 @item @emph{Fortran}:
4762 @multitable @columnfractions .20 .80
4763 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
4764 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4765 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
4766 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4767 @item                   @tab @code{integer len}
4768 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
4769 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4770 @item                   @tab @code{integer(acc_handle_kind) :: async}
4771 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
4772 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4773 @item                   @tab @code{integer len}
4774 @item                   @tab @code{integer(acc_handle_kind) :: async}
4775 @end multitable
4777 @item @emph{Reference}:
4778 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4779 3.2.20.
4780 @end table
4784 @node acc_present_or_copyin
4785 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
4786 @table @asis
4787 @item @emph{Description}
4788 This function tests if the host data specified by @var{a} and of length
4789 @var{len} is present or not. If it is not present, device memory
4790 is allocated and the host memory copied. The device address of
4791 the newly allocated device memory is returned.
4793 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4794 a contiguous array section. The second form @var{a} specifies a variable or
4795 array element and @var{len} specifies the length in bytes.
4797 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
4798 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
4800 @item @emph{C/C++}:
4801 @multitable @columnfractions .20 .80
4802 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
4803 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
4804 @end multitable
4806 @item @emph{Fortran}:
4807 @multitable @columnfractions .20 .80
4808 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
4809 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4810 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
4811 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4812 @item                   @tab @code{integer len}
4813 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
4814 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4815 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
4816 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4817 @item                   @tab @code{integer len}
4818 @end multitable
4820 @item @emph{Reference}:
4821 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4822 3.2.20.
4823 @end table
4827 @node acc_create
4828 @section @code{acc_create} -- Allocate device memory and map it to host memory.
4829 @table @asis
4830 @item @emph{Description}
4831 This function allocates device memory and maps it to host memory specified
4832 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
4833 the function returns the device address of the allocated device memory.
4835 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4836 a contiguous array section. The second form @var{a} specifies a variable or
4837 array element and @var{len} specifies the length in bytes.
4839 @item @emph{C/C++}:
4840 @multitable @columnfractions .20 .80
4841 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
4842 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
4843 @end multitable
4845 @item @emph{Fortran}:
4846 @multitable @columnfractions .20 .80
4847 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
4848 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4849 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
4850 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4851 @item                   @tab @code{integer len}
4852 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
4853 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4854 @item                   @tab @code{integer(acc_handle_kind) :: async}
4855 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
4856 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4857 @item                   @tab @code{integer len}
4858 @item                   @tab @code{integer(acc_handle_kind) :: async}
4859 @end multitable
4861 @item @emph{Reference}:
4862 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4863 3.2.21.
4864 @end table
4868 @node acc_present_or_create
4869 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
4870 @table @asis
4871 @item @emph{Description}
4872 This function tests if the host data specified by @var{a} and of length
4873 @var{len} is present or not. If it is not present, device memory
4874 is allocated and mapped to host memory. In C/C++, the device address
4875 of the newly allocated device memory is returned.
4877 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4878 a contiguous array section. The second form @var{a} specifies a variable or
4879 array element and @var{len} specifies the length in bytes.
4881 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
4882 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
4884 @item @emph{C/C++}:
4885 @multitable @columnfractions .20 .80
4886 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
4887 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
4888 @end multitable
4890 @item @emph{Fortran}:
4891 @multitable @columnfractions .20 .80
4892 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
4893 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4894 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
4895 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4896 @item                   @tab @code{integer len}
4897 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
4898 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4899 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
4900 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4901 @item                   @tab @code{integer len}
4902 @end multitable
4904 @item @emph{Reference}:
4905 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4906 3.2.21.
4907 @end table
4911 @node acc_copyout
4912 @section @code{acc_copyout} -- Copy device memory to host memory.
4913 @table @asis
4914 @item @emph{Description}
4915 This function copies mapped device memory to host memory which is specified
4916 by host address @var{a} for a length @var{len} bytes in C/C++.
4918 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4919 a contiguous array section. The second form @var{a} specifies a variable or
4920 array element and @var{len} specifies the length in bytes.
4922 @item @emph{C/C++}:
4923 @multitable @columnfractions .20 .80
4924 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
4925 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
4926 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
4927 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
4928 @end multitable
4930 @item @emph{Fortran}:
4931 @multitable @columnfractions .20 .80
4932 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
4933 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4934 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
4935 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4936 @item                   @tab @code{integer len}
4937 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
4938 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4939 @item                   @tab @code{integer(acc_handle_kind) :: async}
4940 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
4941 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4942 @item                   @tab @code{integer len}
4943 @item                   @tab @code{integer(acc_handle_kind) :: async}
4944 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
4945 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4946 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
4947 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4948 @item                   @tab @code{integer len}
4949 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
4950 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4951 @item                   @tab @code{integer(acc_handle_kind) :: async}
4952 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
4953 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4954 @item                   @tab @code{integer len}
4955 @item                   @tab @code{integer(acc_handle_kind) :: async}
4956 @end multitable
4958 @item @emph{Reference}:
4959 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4960 3.2.22.
4961 @end table
4965 @node acc_delete
4966 @section @code{acc_delete} -- Free device memory.
4967 @table @asis
4968 @item @emph{Description}
4969 This function frees previously allocated device memory specified by
4970 the device address @var{a} and the length of @var{len} bytes.
4972 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4973 a contiguous array section. The second form @var{a} specifies a variable or
4974 array element and @var{len} specifies the length in bytes.
4976 @item @emph{C/C++}:
4977 @multitable @columnfractions .20 .80
4978 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
4979 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
4980 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
4981 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
4982 @end multitable
4984 @item @emph{Fortran}:
4985 @multitable @columnfractions .20 .80
4986 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
4987 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4988 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
4989 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4990 @item                   @tab @code{integer len}
4991 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
4992 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4993 @item                   @tab @code{integer(acc_handle_kind) :: async}
4994 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
4995 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4996 @item                   @tab @code{integer len}
4997 @item                   @tab @code{integer(acc_handle_kind) :: async}
4998 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
4999 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5000 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5001 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5002 @item                   @tab @code{integer len}
5003 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5004 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5005 @item                   @tab @code{integer(acc_handle_kind) :: async}
5006 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5007 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5008 @item                   @tab @code{integer len}
5009 @item                   @tab @code{integer(acc_handle_kind) :: async}
5010 @end multitable
5012 @item @emph{Reference}:
5013 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5014 3.2.23.
5015 @end table
5019 @node acc_update_device
5020 @section @code{acc_update_device} -- Update device memory from mapped host memory.
5021 @table @asis
5022 @item @emph{Description}
5023 This function updates the device copy from the previously mapped host memory.
5024 The host memory is specified with the host address @var{a} and a length of
5025 @var{len} bytes.
5027 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5028 a contiguous array section. The second form @var{a} specifies a variable or
5029 array element and @var{len} specifies the length in bytes.
5031 @item @emph{C/C++}:
5032 @multitable @columnfractions .20 .80
5033 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5034 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5035 @end multitable
5037 @item @emph{Fortran}:
5038 @multitable @columnfractions .20 .80
5039 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5040 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5041 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5042 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5043 @item                   @tab @code{integer len}
5044 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5045 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5046 @item                   @tab @code{integer(acc_handle_kind) :: async}
5047 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5048 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5049 @item                   @tab @code{integer len}
5050 @item                   @tab @code{integer(acc_handle_kind) :: async}
5051 @end multitable
5053 @item @emph{Reference}:
5054 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5055 3.2.24.
5056 @end table
5060 @node acc_update_self
5061 @section @code{acc_update_self} -- Update host memory from mapped device memory.
5062 @table @asis
5063 @item @emph{Description}
5064 This function updates the host copy from the previously mapped device memory.
5065 The host memory is specified with the host address @var{a} and a length of
5066 @var{len} bytes.
5068 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5069 a contiguous array section. The second form @var{a} specifies a variable or
5070 array element and @var{len} specifies the length in bytes.
5072 @item @emph{C/C++}:
5073 @multitable @columnfractions .20 .80
5074 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5075 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5076 @end multitable
5078 @item @emph{Fortran}:
5079 @multitable @columnfractions .20 .80
5080 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5081 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5082 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5083 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5084 @item                   @tab @code{integer len}
5085 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5086 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5087 @item                   @tab @code{integer(acc_handle_kind) :: async}
5088 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5089 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5090 @item                   @tab @code{integer len}
5091 @item                   @tab @code{integer(acc_handle_kind) :: async}
5092 @end multitable
5094 @item @emph{Reference}:
5095 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5096 3.2.25.
5097 @end table
5101 @node acc_map_data
5102 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5103 @table @asis
5104 @item @emph{Description}
5105 This function maps previously allocated device and host memory. The device
5106 memory is specified with the device address @var{data_dev}. The host memory is
5107 specified with the host address @var{data_arg} and a length of @var{bytes}.
5109 @item @emph{C/C++}:
5110 @multitable @columnfractions .20 .80
5111 @item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5112 @end multitable
5114 @item @emph{Fortran}:
5115 @multitable @columnfractions .20 .80
5116 @item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5117 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5118 @item                   @tab @code{type(c_ptr), value :: data_dev}
5119 @item                   @tab @code{integer(c_size_t), value :: bytes}
5120 @end multitable
5122 @item @emph{Reference}:
5123 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5124 3.2.26.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5125 3.2.21.
5126 @end table
5130 @node acc_unmap_data
5131 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
5132 @table @asis
5133 @item @emph{Description}
5134 This function unmaps previously mapped device and host memory. The latter
5135 specified by @var{data_arg}.
5137 @item @emph{C/C++}:
5138 @multitable @columnfractions .20 .80
5139 @item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5140 @end multitable
5142 @item @emph{Fortran}:
5143 @multitable @columnfractions .20 .80
5144 @item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5145 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5146 @end multitable
5148 @item @emph{Reference}:
5149 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5150 3.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5151 3.2.22.
5152 @end table
5156 @node acc_deviceptr
5157 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5158 @table @asis
5159 @item @emph{Description}
5160 This function returns the device address that has been mapped to the
5161 host address specified by @var{data_arg}.
5163 @item @emph{C/C++}:
5164 @multitable @columnfractions .20 .80
5165 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5166 @end multitable
5168 @item @emph{Fortran}:
5169 @multitable @columnfractions .20 .80
5170 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5171 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5172 @end multitable
5174 @item @emph{Reference}:
5175 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5176 3.2.28.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5177 3.2.23.
5178 @end table
5182 @node acc_hostptr
5183 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5184 @table @asis
5185 @item @emph{Description}
5186 This function returns the host address that has been mapped to the
5187 device address specified by @var{data_dev}.
5189 @item @emph{C/C++}:
5190 @multitable @columnfractions .20 .80
5191 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5192 @end multitable
5194 @item @emph{Fortran}:
5195 @multitable @columnfractions .20 .80
5196 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5197 @item                   @tab @code{type(c_ptr), value :: data_dev}
5198 @end multitable
5200 @item @emph{Reference}:
5201 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5202 3.2.29.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5203 3.2.24.
5204 @end table
5208 @node acc_is_present
5209 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5210 @table @asis
5211 @item @emph{Description}
5212 This function indicates whether the specified host address in @var{a} and a
5213 length of @var{len} bytes is present on the device. In C/C++, a non-zero
5214 value is returned to indicate the presence of the mapped memory on the
5215 device. A zero is returned to indicate the memory is not mapped on the
5216 device.
5218 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5219 a contiguous array section. The second form @var{a} specifies a variable or
5220 array element and @var{len} specifies the length in bytes. If the host
5221 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5222 a @code{false} is return to indicate the mapped memory is not present.
5224 @item @emph{C/C++}:
5225 @multitable @columnfractions .20 .80
5226 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5227 @end multitable
5229 @item @emph{Fortran}:
5230 @multitable @columnfractions .20 .80
5231 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
5232 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5233 @item                   @tab @code{logical acc_is_present}
5234 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5235 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5236 @item                   @tab @code{integer len}
5237 @item                   @tab @code{logical acc_is_present}
5238 @end multitable
5240 @item @emph{Reference}:
5241 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5242 3.2.30.
5243 @end table
5247 @node acc_memcpy_to_device
5248 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5249 @table @asis
5250 @item @emph{Description}
5251 This function copies host memory specified by host address of
5252 @var{data_host_src} to device memory specified by the device address
5253 @var{data_dev_dest} for a length of @var{bytes} bytes.
5255 @item @emph{C/C++}:
5256 @multitable @columnfractions .20 .80
5257 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5258 @item                   @tab @code{h_void* data_host_src, size_t bytes);}
5259 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5260 @item                   @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5261 @end multitable
5263 @item @emph{Fortran}:
5264 @multitable @columnfractions .20 .80
5265 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5266 @item                   @tab @code{data_host_src, bytes)}
5267 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5268 @item                   @tab @code{data_host_src, bytes, async_arg)}
5269 @item                   @tab @code{type(c_ptr), value :: data_dev_dest}
5270 @item                   @tab @code{type(*), dimension(*) :: data_host_src}
5271 @item                   @tab @code{integer(c_size_t), value :: bytes}
5272 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5273 @end multitable
5275 @item @emph{Reference}:
5276 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5277 3.2.31  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5278 3.2.26.
5279 @end table
5283 @node acc_memcpy_from_device
5284 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5285 @table @asis
5286 @item @emph{Description}
5287 This function copies device memory specified by device address of
5288 @var{data_dev_src} to host memory specified by the host address
5289 @var{data_host_dest} for a length of @var{bytes} bytes.
5291 @item @emph{C/C++}:
5292 @multitable @columnfractions .20 .80
5293 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5294 @item                   @tab @code{d_void* data_dev_src, size_t bytes);}
5295 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5296 @item                   @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5297 @end multitable
5299 @item @emph{Fortran}:
5300 @multitable @columnfractions .20 .80
5301 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5302 @item                   @tab @code{data_dev_src, bytes)}
5303 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5304 @item                   @tab @code{data_dev_src, bytes, async_arg)}
5305 @item                   @tab @code{type(*), dimension(*) :: data_host_dest}
5306 @item                   @tab @code{type(c_ptr), value :: data_dev_src}
5307 @item                   @tab @code{integer(c_size_t), value :: bytes}
5308 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5309 @end multitable
5311 @item @emph{Reference}:
5312 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5313 3.2.32.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5314 3.2.27.
5315 @end table
5319 @node acc_attach
5320 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
5321 @table @asis
5322 @item @emph{Description}
5323 This function updates a pointer on the device from pointing to a host-pointer
5324 address to pointing to the corresponding device data.
5326 @item @emph{C/C++}:
5327 @multitable @columnfractions .20 .80
5328 @item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5329 @item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5330 @end multitable
5332 @c @item @emph{Fortran}:
5333 @c @multitable @columnfractions .20 .80
5334 @c @item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5335 @c @item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5336 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5337 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5338 @c @end multitable
5340 @item @emph{Reference}:
5341 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5342 3.2.34.
5343 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5344 @c 3.2.29.
5345 @end table
5349 @node acc_detach
5350 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
5351 @table @asis
5352 @item @emph{Description}
5353 This function updates a pointer on the device from pointing to a device-pointer
5354 address to pointing to the corresponding host data.
5356 @item @emph{C/C++}:
5357 @multitable @columnfractions .20 .80
5358 @item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5359 @item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5360 @item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5361 @item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
5362 @end multitable
5364 @c @item @emph{Fortran}:
5365 @c @multitable @columnfractions .20 .80
5366 @c @item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
5367 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
5368 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
5369 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
5370 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5371 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5372 @c @end multitable
5374 @item @emph{Reference}:
5375 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5376 3.2.35.
5377 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5378 @c 3.2.29.
5379 @end table
5383 @node acc_get_current_cuda_device
5384 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
5385 @table @asis
5386 @item @emph{Description}
5387 This function returns the CUDA device handle. This handle is the same
5388 as used by the CUDA Runtime or Driver API's.
5390 @item @emph{C/C++}:
5391 @multitable @columnfractions .20 .80
5392 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
5393 @end multitable
5395 @item @emph{Reference}:
5396 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5397 A.2.1.1.
5398 @end table
5402 @node acc_get_current_cuda_context
5403 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
5404 @table @asis
5405 @item @emph{Description}
5406 This function returns the CUDA context handle. This handle is the same
5407 as used by the CUDA Runtime or Driver API's.
5409 @item @emph{C/C++}:
5410 @multitable @columnfractions .20 .80
5411 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
5412 @end multitable
5414 @item @emph{Reference}:
5415 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5416 A.2.1.2.
5417 @end table
5421 @node acc_get_cuda_stream
5422 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
5423 @table @asis
5424 @item @emph{Description}
5425 This function returns the CUDA stream handle for the queue @var{async}.
5426 This handle is the same as used by the CUDA Runtime or Driver API's.
5428 @item @emph{C/C++}:
5429 @multitable @columnfractions .20 .80
5430 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
5431 @end multitable
5433 @item @emph{Reference}:
5434 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5435 A.2.1.3.
5436 @end table
5440 @node acc_set_cuda_stream
5441 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
5442 @table @asis
5443 @item @emph{Description}
5444 This function associates the stream handle specified by @var{stream} with
5445 the queue @var{async}.
5447 This cannot be used to change the stream handle associated with
5448 @code{acc_async_sync}.
5450 The return value is not specified.
5452 @item @emph{C/C++}:
5453 @multitable @columnfractions .20 .80
5454 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
5455 @end multitable
5457 @item @emph{Reference}:
5458 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5459 A.2.1.4.
5460 @end table
5464 @node acc_prof_register
5465 @section @code{acc_prof_register} -- Register callbacks.
5466 @table @asis
5467 @item @emph{Description}:
5468 This function registers callbacks.
5470 @item @emph{C/C++}:
5471 @multitable @columnfractions .20 .80
5472 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
5473 @end multitable
5475 @item @emph{See also}:
5476 @ref{OpenACC Profiling Interface}
5478 @item @emph{Reference}:
5479 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5480 5.3.
5481 @end table
5485 @node acc_prof_unregister
5486 @section @code{acc_prof_unregister} -- Unregister callbacks.
5487 @table @asis
5488 @item @emph{Description}:
5489 This function unregisters callbacks.
5491 @item @emph{C/C++}:
5492 @multitable @columnfractions .20 .80
5493 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
5494 @end multitable
5496 @item @emph{See also}:
5497 @ref{OpenACC Profiling Interface}
5499 @item @emph{Reference}:
5500 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5501 5.3.
5502 @end table
5506 @node acc_prof_lookup
5507 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
5508 @table @asis
5509 @item @emph{Description}:
5510 Function to obtain inquiry functions.
5512 @item @emph{C/C++}:
5513 @multitable @columnfractions .20 .80
5514 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
5515 @end multitable
5517 @item @emph{See also}:
5518 @ref{OpenACC Profiling Interface}
5520 @item @emph{Reference}:
5521 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5522 5.3.
5523 @end table
5527 @node acc_register_library
5528 @section @code{acc_register_library} -- Library registration.
5529 @table @asis
5530 @item @emph{Description}:
5531 Function for library registration.
5533 @item @emph{C/C++}:
5534 @multitable @columnfractions .20 .80
5535 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
5536 @end multitable
5538 @item @emph{See also}:
5539 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
5541 @item @emph{Reference}:
5542 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5543 5.3.
5544 @end table
5548 @c ---------------------------------------------------------------------
5549 @c OpenACC Environment Variables
5550 @c ---------------------------------------------------------------------
5552 @node OpenACC Environment Variables
5553 @chapter OpenACC Environment Variables
5555 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
5556 are defined by section 4 of the OpenACC specification in version 2.0.
5557 The variable @env{ACC_PROFLIB}
5558 is defined by section 4 of the OpenACC specification in version 2.6.
5560 @menu
5561 * ACC_DEVICE_TYPE::
5562 * ACC_DEVICE_NUM::
5563 * ACC_PROFLIB::
5564 @end menu
5568 @node ACC_DEVICE_TYPE
5569 @section @code{ACC_DEVICE_TYPE}
5570 @table @asis
5571 @item @emph{Description}:
5572 Control the default device type to use when executing compute regions.
5573 If unset, the code can be run on any device type, favoring a non-host
5574 device type.
5576 Supported values in GCC (if compiled in) are
5577 @itemize
5578 @item @code{host}
5579 @item @code{nvidia}
5580 @item @code{radeon}
5581 @end itemize
5582 @item @emph{Reference}:
5583 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5584 4.1.
5585 @end table
5589 @node ACC_DEVICE_NUM
5590 @section @code{ACC_DEVICE_NUM}
5591 @table @asis
5592 @item @emph{Description}:
5593 Control which device, identified by device number, is the default device.
5594 The value must be a nonnegative integer less than the number of devices.
5595 If unset, device number zero is used.
5596 @item @emph{Reference}:
5597 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5598 4.2.
5599 @end table
5603 @node ACC_PROFLIB
5604 @section @code{ACC_PROFLIB}
5605 @table @asis
5606 @item @emph{Description}:
5607 Semicolon-separated list of dynamic libraries that are loaded as profiling
5608 libraries.  Each library must provide at least the @code{acc_register_library}
5609 routine.  Each library file is found as described by the documentation of
5610 @code{dlopen} of your operating system.
5611 @item @emph{See also}:
5612 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
5614 @item @emph{Reference}:
5615 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5616 4.3.
5617 @end table
5621 @c ---------------------------------------------------------------------
5622 @c CUDA Streams Usage
5623 @c ---------------------------------------------------------------------
5625 @node CUDA Streams Usage
5626 @chapter CUDA Streams Usage
5628 This applies to the @code{nvptx} plugin only.
5630 The library provides elements that perform asynchronous movement of
5631 data and asynchronous operation of computing constructs.  This
5632 asynchronous functionality is implemented by making use of CUDA
5633 streams@footnote{See "Stream Management" in "CUDA Driver API",
5634 TRM-06703-001, Version 5.5, for additional information}.
5636 The primary means by that the asynchronous functionality is accessed
5637 is through the use of those OpenACC directives which make use of the
5638 @code{async} and @code{wait} clauses.  When the @code{async} clause is
5639 first used with a directive, it creates a CUDA stream.  If an
5640 @code{async-argument} is used with the @code{async} clause, then the
5641 stream is associated with the specified @code{async-argument}.
5643 Following the creation of an association between a CUDA stream and the
5644 @code{async-argument} of an @code{async} clause, both the @code{wait}
5645 clause and the @code{wait} directive can be used.  When either the
5646 clause or directive is used after stream creation, it creates a
5647 rendezvous point whereby execution waits until all operations
5648 associated with the @code{async-argument}, that is, stream, have
5649 completed.
5651 Normally, the management of the streams that are created as a result of
5652 using the @code{async} clause, is done without any intervention by the
5653 caller.  This implies the association between the @code{async-argument}
5654 and the CUDA stream is maintained for the lifetime of the program.
5655 However, this association can be changed through the use of the library
5656 function @code{acc_set_cuda_stream}.  When the function
5657 @code{acc_set_cuda_stream} is called, the CUDA stream that was
5658 originally associated with the @code{async} clause is destroyed.
5659 Caution should be taken when changing the association as subsequent
5660 references to the @code{async-argument} refer to a different
5661 CUDA stream.
5665 @c ---------------------------------------------------------------------
5666 @c OpenACC Library Interoperability
5667 @c ---------------------------------------------------------------------
5669 @node OpenACC Library Interoperability
5670 @chapter OpenACC Library Interoperability
5672 @section Introduction
5674 The OpenACC library uses the CUDA Driver API, and may interact with
5675 programs that use the Runtime library directly, or another library
5676 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
5677 "Interactions with the CUDA Driver API" in
5678 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
5679 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
5680 for additional information on library interoperability.}.
5681 This chapter describes the use cases and what changes are
5682 required in order to use both the OpenACC library and the CUBLAS and Runtime
5683 libraries within a program.
5685 @section First invocation: NVIDIA CUBLAS library API
5687 In this first use case (see below), a function in the CUBLAS library is called
5688 prior to any of the functions in the OpenACC library. More specifically, the
5689 function @code{cublasCreate()}.
5691 When invoked, the function initializes the library and allocates the
5692 hardware resources on the host and the device on behalf of the caller. Once
5693 the initialization and allocation has completed, a handle is returned to the
5694 caller. The OpenACC library also requires initialization and allocation of
5695 hardware resources. Since the CUBLAS library has already allocated the
5696 hardware resources for the device, all that is left to do is to initialize
5697 the OpenACC library and acquire the hardware resources on the host.
5699 Prior to calling the OpenACC function that initializes the library and
5700 allocate the host hardware resources, you need to acquire the device number
5701 that was allocated during the call to @code{cublasCreate()}. The invoking of the
5702 runtime library function @code{cudaGetDevice()} accomplishes this. Once
5703 acquired, the device number is passed along with the device type as
5704 parameters to the OpenACC library function @code{acc_set_device_num()}.
5706 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
5707 library uses the  context that was created during the call to
5708 @code{cublasCreate()}. In other words, both libraries share the
5709 same context.
5711 @smallexample
5712     /* Create the handle */
5713     s = cublasCreate(&h);
5714     if (s != CUBLAS_STATUS_SUCCESS)
5715     @{
5716         fprintf(stderr, "cublasCreate failed %d\n", s);
5717         exit(EXIT_FAILURE);
5718     @}
5720     /* Get the device number */
5721     e = cudaGetDevice(&dev);
5722     if (e != cudaSuccess)
5723     @{
5724         fprintf(stderr, "cudaGetDevice failed %d\n", e);
5725         exit(EXIT_FAILURE);
5726     @}
5728     /* Initialize OpenACC library and use device 'dev' */
5729     acc_set_device_num(dev, acc_device_nvidia);
5731 @end smallexample
5732 @center Use Case 1 
5734 @section First invocation: OpenACC library API
5736 In this second use case (see below), a function in the OpenACC library is
5737 called prior to any of the functions in the CUBLAS library. More specifically,
5738 the function @code{acc_set_device_num()}.
5740 In the use case presented here, the function @code{acc_set_device_num()}
5741 is used to both initialize the OpenACC library and allocate the hardware
5742 resources on the host and the device. In the call to the function, the
5743 call parameters specify which device to use and what device
5744 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
5745 is but one method to initialize the OpenACC library and allocate the
5746 appropriate hardware resources. Other methods are available through the
5747 use of environment variables and these is discussed in the next section.
5749 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
5750 functions can be called as seen with multiple calls being made to
5751 @code{acc_copyin()}. In addition, calls can be made to functions in the
5752 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
5753 subsequent to the calls to @code{acc_copyin()}.
5754 As seen in the previous use case, a call to @code{cublasCreate()}
5755 initializes the CUBLAS library and allocates the hardware resources on the
5756 host and the device.  However, since the device has already been allocated,
5757 @code{cublasCreate()} only initializes the CUBLAS library and allocates
5758 the appropriate hardware resources on the host. The context that was created
5759 as part of the OpenACC initialization is shared with the CUBLAS library,
5760 similarly to the first use case.
5762 @smallexample
5763     dev = 0;
5765     acc_set_device_num(dev, acc_device_nvidia);
5767     /* Copy the first set to the device */
5768     d_X = acc_copyin(&h_X[0], N * sizeof (float));
5769     if (d_X == NULL)
5770     @{ 
5771         fprintf(stderr, "copyin error h_X\n");
5772         exit(EXIT_FAILURE);
5773     @}
5775     /* Copy the second set to the device */
5776     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
5777     if (d_Y == NULL)
5778     @{ 
5779         fprintf(stderr, "copyin error h_Y1\n");
5780         exit(EXIT_FAILURE);
5781     @}
5783     /* Create the handle */
5784     s = cublasCreate(&h);
5785     if (s != CUBLAS_STATUS_SUCCESS)
5786     @{
5787         fprintf(stderr, "cublasCreate failed %d\n", s);
5788         exit(EXIT_FAILURE);
5789     @}
5791     /* Perform saxpy using CUBLAS library function */
5792     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
5793     if (s != CUBLAS_STATUS_SUCCESS)
5794     @{
5795         fprintf(stderr, "cublasSaxpy failed %d\n", s);
5796         exit(EXIT_FAILURE);
5797     @}
5799     /* Copy the results from the device */
5800     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
5802 @end smallexample
5803 @center Use Case 2
5805 @section OpenACC library and environment variables
5807 There are two environment variables associated with the OpenACC library
5808 that may be used to control the device type and device number:
5809 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
5810 environment variables can be used as an alternative to calling
5811 @code{acc_set_device_num()}. As seen in the second use case, the device
5812 type and device number were specified using @code{acc_set_device_num()}.
5813 If however, the aforementioned environment variables were set, then the
5814 call to @code{acc_set_device_num()} would not be required.
5817 The use of the environment variables is only relevant when an OpenACC function
5818 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
5819 is called prior to a call to an OpenACC function, then you must call
5820 @code{acc_set_device_num()}@footnote{More complete information
5821 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
5822 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
5823 Application Programming Interface”, Version 2.6.}
5827 @c ---------------------------------------------------------------------
5828 @c OpenACC Profiling Interface
5829 @c ---------------------------------------------------------------------
5831 @node OpenACC Profiling Interface
5832 @chapter OpenACC Profiling Interface
5834 @section Implementation Status and Implementation-Defined Behavior
5836 We're implementing the OpenACC Profiling Interface as defined by the
5837 OpenACC 2.6 specification.  We're clarifying some aspects here as
5838 @emph{implementation-defined behavior}, while they're still under
5839 discussion within the OpenACC Technical Committee.
5841 This implementation is tuned to keep the performance impact as low as
5842 possible for the (very common) case that the Profiling Interface is
5843 not enabled.  This is relevant, as the Profiling Interface affects all
5844 the @emph{hot} code paths (in the target code, not in the offloaded
5845 code).  Users of the OpenACC Profiling Interface can be expected to
5846 understand that performance is impacted to some degree once the
5847 Profiling Interface is enabled: for example, because of the
5848 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
5849 every event that has been registered.
5851 We're not yet accounting for the fact that @cite{OpenACC events may
5852 occur during event processing}.
5853 We just handle one case specially, as required by CUDA 9.0
5854 @command{nvprof}, that @code{acc_get_device_type}
5855 (@ref{acc_get_device_type})) may be called from
5856 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
5857 callbacks.
5859 We're not yet implementing initialization via a
5860 @code{acc_register_library} function that is either statically linked
5861 in, or dynamically via @env{LD_PRELOAD}.
5862 Initialization via @code{acc_register_library} functions dynamically
5863 loaded via the @env{ACC_PROFLIB} environment variable does work, as
5864 does directly calling @code{acc_prof_register},
5865 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
5867 As currently there are no inquiry functions defined, calls to
5868 @code{acc_prof_lookup} always returns @code{NULL}.
5870 There aren't separate @emph{start}, @emph{stop} events defined for the
5871 event types @code{acc_ev_create}, @code{acc_ev_delete},
5872 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
5873 should be triggered before or after the actual device-specific call is
5874 made.  We trigger them after.
5876 Remarks about data provided to callbacks:
5878 @table @asis
5880 @item @code{acc_prof_info.event_type}
5881 It's not clear if for @emph{nested} event callbacks (for example,
5882 @code{acc_ev_enqueue_launch_start} as part of a parent compute
5883 construct), this should be set for the nested event
5884 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
5885 construct should remain (@code{acc_ev_compute_construct_start}).  In
5886 this implementation, the value generally corresponds to the
5887 innermost nested event type.
5889 @item @code{acc_prof_info.device_type}
5890 @itemize
5892 @item
5893 For @code{acc_ev_compute_construct_start}, and in presence of an
5894 @code{if} clause with @emph{false} argument, this still refers to
5895 the offloading device type.
5896 It's not clear if that's the expected behavior.
5898 @item
5899 Complementary to the item before, for
5900 @code{acc_ev_compute_construct_end}, this is set to
5901 @code{acc_device_host} in presence of an @code{if} clause with
5902 @emph{false} argument.
5903 It's not clear if that's the expected behavior.
5905 @end itemize
5907 @item @code{acc_prof_info.thread_id}
5908 Always @code{-1}; not yet implemented.
5910 @item @code{acc_prof_info.async}
5911 @itemize
5913 @item
5914 Not yet implemented correctly for
5915 @code{acc_ev_compute_construct_start}.
5917 @item
5918 In a compute construct, for host-fallback
5919 execution/@code{acc_device_host} it always is
5920 @code{acc_async_sync}.
5921 It is unclear if that is the expected behavior.
5923 @item
5924 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
5925 it will always be @code{acc_async_sync}.
5926 It is unclear if that is the expected behavior.
5928 @end itemize
5930 @item @code{acc_prof_info.async_queue}
5931 There is no @cite{limited number of asynchronous queues} in libgomp.
5932 This always has the same value as @code{acc_prof_info.async}.
5934 @item @code{acc_prof_info.src_file}
5935 Always @code{NULL}; not yet implemented.
5937 @item @code{acc_prof_info.func_name}
5938 Always @code{NULL}; not yet implemented.
5940 @item @code{acc_prof_info.line_no}
5941 Always @code{-1}; not yet implemented.
5943 @item @code{acc_prof_info.end_line_no}
5944 Always @code{-1}; not yet implemented.
5946 @item @code{acc_prof_info.func_line_no}
5947 Always @code{-1}; not yet implemented.
5949 @item @code{acc_prof_info.func_end_line_no}
5950 Always @code{-1}; not yet implemented.
5952 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
5953 Relating to @code{acc_prof_info.event_type} discussed above, in this
5954 implementation, this will always be the same value as
5955 @code{acc_prof_info.event_type}.
5957 @item @code{acc_event_info.*.parent_construct}
5958 @itemize
5960 @item
5961 Will be @code{acc_construct_parallel} for all OpenACC compute
5962 constructs as well as many OpenACC Runtime API calls; should be the
5963 one matching the actual construct, or
5964 @code{acc_construct_runtime_api}, respectively.
5966 @item
5967 Will be @code{acc_construct_enter_data} or
5968 @code{acc_construct_exit_data} when processing variable mappings
5969 specified in OpenACC @emph{declare} directives; should be
5970 @code{acc_construct_declare}.
5972 @item
5973 For implicit @code{acc_ev_device_init_start},
5974 @code{acc_ev_device_init_end}, and explicit as well as implicit
5975 @code{acc_ev_alloc}, @code{acc_ev_free},
5976 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5977 @code{acc_ev_enqueue_download_start}, and
5978 @code{acc_ev_enqueue_download_end}, will be
5979 @code{acc_construct_parallel}; should reflect the real parent
5980 construct.
5982 @end itemize
5984 @item @code{acc_event_info.*.implicit}
5985 For @code{acc_ev_alloc}, @code{acc_ev_free},
5986 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5987 @code{acc_ev_enqueue_download_start}, and
5988 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
5989 also for explicit usage.
5991 @item @code{acc_event_info.data_event.var_name}
5992 Always @code{NULL}; not yet implemented.
5994 @item @code{acc_event_info.data_event.host_ptr}
5995 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
5996 @code{NULL}.
5998 @item @code{typedef union acc_api_info}
5999 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6000 Information}.  This should obviously be @code{typedef @emph{struct}
6001 acc_api_info}.
6003 @item @code{acc_api_info.device_api}
6004 Possibly not yet implemented correctly for
6005 @code{acc_ev_compute_construct_start},
6006 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6007 will always be @code{acc_device_api_none} for these event types.
6008 For @code{acc_ev_enter_data_start}, it will be
6009 @code{acc_device_api_none} in some cases.
6011 @item @code{acc_api_info.device_type}
6012 Always the same as @code{acc_prof_info.device_type}.
6014 @item @code{acc_api_info.vendor}
6015 Always @code{-1}; not yet implemented.
6017 @item @code{acc_api_info.device_handle}
6018 Always @code{NULL}; not yet implemented.
6020 @item @code{acc_api_info.context_handle}
6021 Always @code{NULL}; not yet implemented.
6023 @item @code{acc_api_info.async_handle}
6024 Always @code{NULL}; not yet implemented.
6026 @end table
6028 Remarks about certain event types:
6030 @table @asis
6032 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6033 @itemize
6035 @item
6036 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6037 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6038 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6039 When a compute construct triggers implicit
6040 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6041 events, they currently aren't @emph{nested within} the corresponding
6042 @code{acc_ev_compute_construct_start} and
6043 @code{acc_ev_compute_construct_end}, but they're currently observed
6044 @emph{before} @code{acc_ev_compute_construct_start}.
6045 It's not clear what to do: the standard asks us provide a lot of
6046 details to the @code{acc_ev_compute_construct_start} callback, without
6047 (implicitly) initializing a device before?
6049 @item
6050 Callbacks for these event types will not be invoked for calls to the
6051 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
6052 It's not clear if they should be.
6054 @end itemize
6056 @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}
6057 @itemize
6059 @item
6060 Callbacks for these event types will also be invoked for OpenACC
6061 @emph{host_data} constructs.
6062 It's not clear if they should be.
6064 @item
6065 Callbacks for these event types will also be invoked when processing
6066 variable mappings specified in OpenACC @emph{declare} directives.
6067 It's not clear if they should be.
6069 @end itemize
6071 @end table
6073 Callbacks for the following event types will be invoked, but dispatch
6074 and information provided therein has not yet been thoroughly reviewed:
6076 @itemize
6077 @item @code{acc_ev_alloc}
6078 @item @code{acc_ev_free}
6079 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6080 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6081 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6082 @end itemize
6084 During device initialization, and finalization, respectively,
6085 callbacks for the following event types will not yet be invoked:
6087 @itemize
6088 @item @code{acc_ev_alloc}
6089 @item @code{acc_ev_free}
6090 @end itemize
6092 Callbacks for the following event types have not yet been implemented,
6093 so currently won't be invoked:
6095 @itemize
6096 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6097 @item @code{acc_ev_runtime_shutdown}
6098 @item @code{acc_ev_create}, @code{acc_ev_delete}
6099 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6100 @end itemize
6102 For the following runtime library functions, not all expected
6103 callbacks will be invoked (mostly concerning implicit device
6104 initialization):
6106 @itemize
6107 @item @code{acc_get_num_devices}
6108 @item @code{acc_set_device_type}
6109 @item @code{acc_get_device_type}
6110 @item @code{acc_set_device_num}
6111 @item @code{acc_get_device_num}
6112 @item @code{acc_init}
6113 @item @code{acc_shutdown}
6114 @end itemize
6116 Aside from implicit device initialization, for the following runtime
6117 library functions, no callbacks will be invoked for shared-memory
6118 offloading devices (it's not clear if they should be):
6120 @itemize
6121 @item @code{acc_malloc}
6122 @item @code{acc_free}
6123 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6124 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6125 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6126 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6127 @item @code{acc_update_device}, @code{acc_update_device_async}
6128 @item @code{acc_update_self}, @code{acc_update_self_async}
6129 @item @code{acc_map_data}, @code{acc_unmap_data}
6130 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6131 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6132 @end itemize
6134 @c ---------------------------------------------------------------------
6135 @c OpenMP-Implementation Specifics
6136 @c ---------------------------------------------------------------------
6138 @node OpenMP-Implementation Specifics
6139 @chapter OpenMP-Implementation Specifics
6141 @menu
6142 * Implementation-defined ICV Initialization::
6143 * OpenMP Context Selectors::
6144 * Memory allocation::
6145 @end menu
6147 @node Implementation-defined ICV Initialization
6148 @section Implementation-defined ICV Initialization
6149 @cindex Implementation specific setting
6151 @multitable @columnfractions .30 .70
6152 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6153 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6154 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6155 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6156 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6157 @item @var{num-devices-var} @tab Number of non-host devices found
6158 by GCC's run-time library
6159 @item @var{num-procs-var} @tab The number of CPU cores on the
6160 initial device, except that affinity settings might lead to a
6161 smaller number.  On non-host devices, the value of the
6162 @var{nthreads-var} ICV.
6163 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6164 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6165 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6166 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6167 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6168 @ref{GOMP_SPINCOUNT}
6169 @end multitable
6171 @node OpenMP Context Selectors
6172 @section OpenMP Context Selectors
6174 @code{vendor} is always @code{gnu}. References are to the GCC manual.
6176 @c NOTE: Only the following selectors have been implemented. To add
6177 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6178 @c has to be implemented; cf. also PR target/105640.
6179 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6181 For the host compiler, @code{kind} always matches @code{host}; for the
6182 offloading architectures AMD GCN and Nvidia PTX, @code{kind} always matches
6183 @code{gpu}.  For the x86 family of computers, AMD GCN and Nvidia PTX
6184 the following traits are supported in addition; while OpenMP is supported
6185 on more architectures, GCC currently does not match any @code{arch} or
6186 @code{isa} traits for those.
6188 @multitable @columnfractions .65 .30
6189 @headitem @code{arch} @tab @code{isa}
6190 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6191       @code{i586}, @code{i686}, @code{ia32}
6192       @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6193 @item @code{amdgcn}, @code{gcn}
6194       @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
6195       @code{gfx803} is supported as an alias for @code{fiji}.}
6196 @item @code{nvptx}, @code{nvptx64}
6197       @tab See @code{-march=} in ``Nvidia PTX Options''
6198 @end multitable
6200 @node Memory allocation
6201 @section Memory allocation
6203 The description below applies to:
6205 @itemize
6206 @item Explicit use of the OpenMP API routines, see
6207       @ref{Memory Management Routines}.
6208 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
6209       constant expression with value @code{omp_default_mem_alloc} and no
6210       @code{align} modifier has been specified. (In that case, the normal
6211       @code{malloc} allocation is used.)
6212 @item Using the @code{allocate} directive for automatic/stack variables, except
6213       when the @code{allocator} clause is a constant expression with value
6214       @code{omp_default_mem_alloc} and no @code{align} clause has been
6215       specified. (In that case, the normal allocation is used: stack allocation
6216       and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6217       @option{-fstack-arrays}].)
6218 @item Using the @code{allocate} directive for variable in static memory is
6219       currently not supported (compile time error).
6220 @item In Fortran, the @code{allocators} directive and the executable
6221       @code{allocate} directive for Fortran pointers and allocatables is
6222       supported, but requires that files containing those directives has to be
6223       compiled with @option{-fopenmp-allocators}.  Additionally, all files that
6224       might explicitly or implicitly deallocate memory allocated that way must
6225       also be compiled with that option.
6226 @end itemize
6228 For the available predefined allocators and, as applicable, their associated
6229 predefined memory spaces and for the available traits and their default values,
6230 see @ref{OMP_ALLOCATOR}.  Predefined allocators without an associated memory
6231 space use the @code{omp_default_mem_space} memory space.
6233 For the memory spaces, the following applies:
6234 @itemize
6235 @item @code{omp_default_mem_space} is supported
6236 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6237 @item @code{omp_low_lat_mem_space} is only available on supported devices,
6238       and maps to @code{omp_default_mem_space} otherwise.
6239 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6240       unless the memkind library is available
6241 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6242       unless the memkind library is available
6243 @end itemize
6245 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6246 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
6247 creating memory allocators requesting
6249 @itemize
6250 @item the memory space @code{omp_high_bw_mem_space}
6251 @item the memory space @code{omp_large_cap_mem_space}
6252 @item the @code{partition} trait @code{interleaved}; note that for
6253       @code{omp_large_cap_mem_space} the allocation will not be interleaved
6254 @end itemize
6256 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6257 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6258 memory allocators requesting
6260 @itemize
6261 @item the @code{partition} trait @code{nearest}, except when both the
6262 libmemkind library is available and the memory space is either
6263 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6264 @end itemize
6266 Note that the numa library will round up the allocation size to a multiple of
6267 the system page size; therefore, consider using it only with large data or
6268 by sharing allocations via the @code{pool_size} trait.  Furthermore, the Linux
6269 kernel does not guarantee that an allocation will always be on the nearest NUMA
6270 node nor that after reallocation the same node will be used.  Note additionally
6271 that, on Linux, the default setting of the memory placement policy is to use the
6272 current node; therefore, unless the memory placement policy has been overridden,
6273 the @code{partition} trait @code{environment} (the default) will be effectively
6274 a @code{nearest} allocation.
6276 Additional notes regarding the traits:
6277 @itemize
6278 @item The @code{pinned} trait is supported on Linux hosts, but is subject to
6279       the OS @code{ulimit}/@code{rlimit} locked memory settings.
6280 @item The default for the @code{pool_size} trait is no pool and for every
6281       (re)allocation the associated library routine is called, which might
6282       internally use a memory pool.
6283 @item For the @code{partition} trait, the partition part size will be the same
6284       as the requested size (i.e. @code{interleaved} or @code{blocked} has no
6285       effect), except for @code{interleaved} when the memkind library is
6286       available.  Furthermore, for @code{nearest} and unless the numa library
6287       is available, the memory might not be on the same NUMA node as thread
6288       that allocated the memory; on Linux, this is in particular the case when
6289       the memory placement policy is set to preferred.
6290 @item The @code{access} trait has no effect such that memory is always
6291       accessible by all threads.
6292 @item The @code{sync_hint} trait has no effect.
6293 @end itemize
6295 See also:
6296 @ref{Offload-Target Specifics}
6298 @c ---------------------------------------------------------------------
6299 @c Offload-Target Specifics
6300 @c ---------------------------------------------------------------------
6302 @node Offload-Target Specifics
6303 @chapter Offload-Target Specifics
6305 The following sections present notes on the offload-target specifics
6307 @menu
6308 * AMD Radeon::
6309 * nvptx::
6310 @end menu
6312 @node AMD Radeon
6313 @section AMD Radeon (GCN)
6315 On the hardware side, there is the hierarchy (fine to coarse):
6316 @itemize
6317 @item work item (thread)
6318 @item wavefront
6319 @item work group
6320 @item compute unit (CU)
6321 @end itemize
6323 All OpenMP and OpenACC levels are used, i.e.
6324 @itemize
6325 @item OpenMP's simd and OpenACC's vector map to work items (thread)
6326 @item OpenMP's threads (``parallel'') and OpenACC's workers map
6327       to wavefronts
6328 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6329       size of the number of teams or gangs, respectively.
6330 @end itemize
6332 The used sizes are
6333 @itemize
6334 @item Number of teams is the specified @code{num_teams} (OpenMP) or
6335       @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
6336       by two times the number of CU.
6337 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
6338       @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
6339       overrides this if smaller.
6340 @item The wavefront has 102 scalars and 64 vectors
6341 @item Number of workitems is always 64
6342 @item The hardware permits maximally 40 workgroups/CU and
6343       16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
6344 @item 80 scalars registers and 24 vector registers in non-kernel functions
6345       (the chosen procedure-calling API).
6346 @item For the kernel itself: as many as register pressure demands (number of
6347       teams and number of threads, scaled down if registers are exhausted)
6348 @end itemize
6350 The implementation remark:
6351 @itemize
6352 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
6353       using the C library @code{printf} functions and the Fortran
6354       @code{print}/@code{write} statements.
6355 @item Reverse offload regions (i.e. @code{target} regions with
6356       @code{device(ancestor:1)}) are processed serially per @code{target} region
6357       such that the next reverse offload region is only executed after the previous
6358       one returned.
6359 @item OpenMP code that has a @code{requires} directive with
6360       @code{unified_shared_memory} will remove any GCN device from the list of
6361       available devices (``host fallback'').
6362 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
6363       environment variable; the default is 32 kiB per thread.
6364 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6365       the @code{access} trait is set to @code{cgroup}.  The default pool size
6366       is automatically scaled to share the 64 kiB LDS memory between the number
6367       of teams configured to run on each compute-unit, but may be adjusted at
6368       runtime by setting environment variable
6369       @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
6370 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6371       because the definition implies the @code{omp_atv_all} trait; main
6372       graphics memory is used instead.
6373 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6374       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6375       preference, and fall back to main graphics memory when the low-latency
6376       pool is exhausted.
6377 @end itemize
6381 @node nvptx
6382 @section nvptx
6384 On the hardware side, there is the hierarchy (fine to coarse):
6385 @itemize
6386 @item thread
6387 @item warp
6388 @item thread block
6389 @item streaming multiprocessor
6390 @end itemize
6392 All OpenMP and OpenACC levels are used, i.e.
6393 @itemize
6394 @item OpenMP's simd and OpenACC's vector map to threads
6395 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
6396 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6397       size of the number of teams or gangs, respectively.
6398 @end itemize
6400 The used sizes are
6401 @itemize
6402 @item The @code{warp_size} is always 32
6403 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
6404 @item The number of teams is limited by the number of blocks the device can
6405       host simultaneously.
6406 @end itemize
6408 Additional information can be obtained by setting the environment variable to
6409 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
6410 parameters).
6412 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
6413 which caches the JIT in the user's directory (see CUDA documentation; can be
6414 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
6416 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
6417 options still affect the used PTX ISA code and, thus, the requirements on
6418 CUDA version and hardware.
6420 The implementation remark:
6421 @itemize
6422 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
6423       using the C library @code{printf} functions. Note that the Fortran
6424       @code{print}/@code{write} statements are not supported, yet.
6425 @item Compilation OpenMP code that contains @code{requires reverse_offload}
6426       requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
6427       is not supported.
6428 @item For code containing reverse offload (i.e. @code{target} regions with
6429       @code{device(ancestor:1)}), there is a slight performance penalty
6430       for @emph{all} target regions, consisting mostly of shutdown delay
6431       Per device, reverse offload regions are processed serially such that
6432       the next reverse offload region is only executed after the previous
6433       one returned.
6434 @item OpenMP code that has a @code{requires} directive with
6435       @code{unified_shared_memory} will remove any nvptx device from the
6436       list of available devices (``host fallback'').
6437 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
6438       in the GCC manual.
6439 @item The OpenMP routines @code{omp_target_memcpy_rect} and
6440       @code{omp_target_memcpy_rect_async} and the @code{target update}
6441       directive for non-contiguous list items will use the 2D and 3D
6442       memory-copy functions of the CUDA library.  Higher dimensions will
6443       call those functions in a loop and are therefore supported.
6444 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6445       the @code{access} trait is set to @code{cgroup}, the ISA is at least
6446       @code{sm_53}, and the PTX version is at least 4.1.  The default pool size
6447       is 8 kiB per team, but may be adjusted at runtime by setting environment
6448       variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}.  The maximum value is
6449       limited by the available hardware, and care should be taken that the
6450       selected pool size does not unduly limit the number of teams that can
6451       run simultaneously.
6452 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6453       because the definition implies the @code{omp_atv_all} trait; main
6454       graphics memory is used instead.
6455 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6456       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6457       preference, and fall back to main graphics memory when the low-latency
6458       pool is exhausted.
6459 @end itemize
6462 @c ---------------------------------------------------------------------
6463 @c The libgomp ABI
6464 @c ---------------------------------------------------------------------
6466 @node The libgomp ABI
6467 @chapter The libgomp ABI
6469 The following sections present notes on the external ABI as 
6470 presented by libgomp.  Only maintainers should need them.
6472 @menu
6473 * Implementing MASTER construct::
6474 * Implementing CRITICAL construct::
6475 * Implementing ATOMIC construct::
6476 * Implementing FLUSH construct::
6477 * Implementing BARRIER construct::
6478 * Implementing THREADPRIVATE construct::
6479 * Implementing PRIVATE clause::
6480 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
6481 * Implementing REDUCTION clause::
6482 * Implementing PARALLEL construct::
6483 * Implementing FOR construct::
6484 * Implementing ORDERED construct::
6485 * Implementing SECTIONS construct::
6486 * Implementing SINGLE construct::
6487 * Implementing OpenACC's PARALLEL construct::
6488 @end menu
6491 @node Implementing MASTER construct
6492 @section Implementing MASTER construct
6494 @smallexample
6495 if (omp_get_thread_num () == 0)
6496   block
6497 @end smallexample
6499 Alternately, we generate two copies of the parallel subfunction
6500 and only include this in the version run by the primary thread.
6501 Surely this is not worthwhile though...
6505 @node Implementing CRITICAL construct
6506 @section Implementing CRITICAL construct
6508 Without a specified name,
6510 @smallexample
6511   void GOMP_critical_start (void);
6512   void GOMP_critical_end (void);
6513 @end smallexample
6515 so that we don't get COPY relocations from libgomp to the main
6516 application.
6518 With a specified name, use omp_set_lock and omp_unset_lock with
6519 name being transformed into a variable declared like
6521 @smallexample
6522   omp_lock_t gomp_critical_user_<name> __attribute__((common))
6523 @end smallexample
6525 Ideally the ABI would specify that all zero is a valid unlocked
6526 state, and so we wouldn't need to initialize this at
6527 startup.
6531 @node Implementing ATOMIC construct
6532 @section Implementing ATOMIC construct
6534 The target should implement the @code{__sync} builtins.
6536 Failing that we could add
6538 @smallexample
6539   void GOMP_atomic_enter (void)
6540   void GOMP_atomic_exit (void)
6541 @end smallexample
6543 which reuses the regular lock code, but with yet another lock
6544 object private to the library.
6548 @node Implementing FLUSH construct
6549 @section Implementing FLUSH construct
6551 Expands to the @code{__sync_synchronize} builtin.
6555 @node Implementing BARRIER construct
6556 @section Implementing BARRIER construct
6558 @smallexample
6559   void GOMP_barrier (void)
6560 @end smallexample
6563 @node Implementing THREADPRIVATE construct
6564 @section Implementing THREADPRIVATE construct
6566 In _most_ cases we can map this directly to @code{__thread}.  Except
6567 that OMP allows constructors for C++ objects.  We can either
6568 refuse to support this (how often is it used?) or we can 
6569 implement something akin to .ctors.
6571 Even more ideally, this ctor feature is handled by extensions
6572 to the main pthreads library.  Failing that, we can have a set
6573 of entry points to register ctor functions to be called.
6577 @node Implementing PRIVATE clause
6578 @section Implementing PRIVATE clause
6580 In association with a PARALLEL, or within the lexical extent
6581 of a PARALLEL block, the variable becomes a local variable in
6582 the parallel subfunction.
6584 In association with FOR or SECTIONS blocks, create a new
6585 automatic variable within the current function.  This preserves
6586 the semantic of new variable creation.
6590 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6591 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6593 This seems simple enough for PARALLEL blocks.  Create a private 
6594 struct for communicating between the parent and subfunction.
6595 In the parent, copy in values for scalar and "small" structs;
6596 copy in addresses for others TREE_ADDRESSABLE types.  In the 
6597 subfunction, copy the value into the local variable.
6599 It is not clear what to do with bare FOR or SECTION blocks.
6600 The only thing I can figure is that we do something like:
6602 @smallexample
6603 #pragma omp for firstprivate(x) lastprivate(y)
6604 for (int i = 0; i < n; ++i)
6605   body;
6606 @end smallexample
6608 which becomes
6610 @smallexample
6612   int x = x, y;
6614   // for stuff
6616   if (i == n)
6617     y = y;
6619 @end smallexample
6621 where the "x=x" and "y=y" assignments actually have different
6622 uids for the two variables, i.e. not something you could write
6623 directly in C.  Presumably this only makes sense if the "outer"
6624 x and y are global variables.
6626 COPYPRIVATE would work the same way, except the structure 
6627 broadcast would have to happen via SINGLE machinery instead.
6631 @node Implementing REDUCTION clause
6632 @section Implementing REDUCTION clause
6634 The private struct mentioned in the previous section should have 
6635 a pointer to an array of the type of the variable, indexed by the 
6636 thread's @var{team_id}.  The thread stores its final value into the 
6637 array, and after the barrier, the primary thread iterates over the
6638 array to collect the values.
6641 @node Implementing PARALLEL construct
6642 @section Implementing PARALLEL construct
6644 @smallexample
6645   #pragma omp parallel
6646   @{
6647     body;
6648   @}
6649 @end smallexample
6651 becomes
6653 @smallexample
6654   void subfunction (void *data)
6655   @{
6656     use data;
6657     body;
6658   @}
6660   setup data;
6661   GOMP_parallel_start (subfunction, &data, num_threads);
6662   subfunction (&data);
6663   GOMP_parallel_end ();
6664 @end smallexample
6666 @smallexample
6667   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
6668 @end smallexample
6670 The @var{FN} argument is the subfunction to be run in parallel.
6672 The @var{DATA} argument is a pointer to a structure used to 
6673 communicate data in and out of the subfunction, as discussed
6674 above with respect to FIRSTPRIVATE et al.
6676 The @var{NUM_THREADS} argument is 1 if an IF clause is present
6677 and false, or the value of the NUM_THREADS clause, if
6678 present, or 0.
6680 The function needs to create the appropriate number of
6681 threads and/or launch them from the dock.  It needs to
6682 create the team structure and assign team ids.
6684 @smallexample
6685   void GOMP_parallel_end (void)
6686 @end smallexample
6688 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
6692 @node Implementing FOR construct
6693 @section Implementing FOR construct
6695 @smallexample
6696   #pragma omp parallel for
6697   for (i = lb; i <= ub; i++)
6698     body;
6699 @end smallexample
6701 becomes
6703 @smallexample
6704   void subfunction (void *data)
6705   @{
6706     long _s0, _e0;
6707     while (GOMP_loop_static_next (&_s0, &_e0))
6708     @{
6709       long _e1 = _e0, i;
6710       for (i = _s0; i < _e1; i++)
6711         body;
6712     @}
6713     GOMP_loop_end_nowait ();
6714   @}
6716   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
6717   subfunction (NULL);
6718   GOMP_parallel_end ();
6719 @end smallexample
6721 @smallexample
6722   #pragma omp for schedule(runtime)
6723   for (i = 0; i < n; i++)
6724     body;
6725 @end smallexample
6727 becomes
6729 @smallexample
6730   @{
6731     long i, _s0, _e0;
6732     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
6733       do @{
6734         long _e1 = _e0;
6735         for (i = _s0, i < _e0; i++)
6736           body;
6737       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
6738     GOMP_loop_end ();
6739   @}
6740 @end smallexample
6742 Note that while it looks like there is trickiness to propagating
6743 a non-constant STEP, there isn't really.  We're explicitly allowed
6744 to evaluate it as many times as we want, and any variables involved
6745 should automatically be handled as PRIVATE or SHARED like any other
6746 variables.  So the expression should remain evaluable in the 
6747 subfunction.  We can also pull it into a local variable if we like,
6748 but since its supposed to remain unchanged, we can also not if we like.
6750 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
6751 able to get away with no work-sharing context at all, since we can
6752 simply perform the arithmetic directly in each thread to divide up
6753 the iterations.  Which would mean that we wouldn't need to call any
6754 of these routines.
6756 There are separate routines for handling loops with an ORDERED
6757 clause.  Bookkeeping for that is non-trivial...
6761 @node Implementing ORDERED construct
6762 @section Implementing ORDERED construct
6764 @smallexample
6765   void GOMP_ordered_start (void)
6766   void GOMP_ordered_end (void)
6767 @end smallexample
6771 @node Implementing SECTIONS construct
6772 @section Implementing SECTIONS construct
6774 A block as 
6776 @smallexample
6777   #pragma omp sections
6778   @{
6779     #pragma omp section
6780     stmt1;
6781     #pragma omp section
6782     stmt2;
6783     #pragma omp section
6784     stmt3;
6785   @}
6786 @end smallexample
6788 becomes
6790 @smallexample
6791   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
6792     switch (i)
6793       @{
6794       case 1:
6795         stmt1;
6796         break;
6797       case 2:
6798         stmt2;
6799         break;
6800       case 3:
6801         stmt3;
6802         break;
6803       @}
6804   GOMP_barrier ();
6805 @end smallexample
6808 @node Implementing SINGLE construct
6809 @section Implementing SINGLE construct
6811 A block like 
6813 @smallexample
6814   #pragma omp single
6815   @{
6816     body;
6817   @}
6818 @end smallexample
6820 becomes
6822 @smallexample
6823   if (GOMP_single_start ())
6824     body;
6825   GOMP_barrier ();
6826 @end smallexample
6828 while 
6830 @smallexample
6831   #pragma omp single copyprivate(x)
6832     body;
6833 @end smallexample
6835 becomes
6837 @smallexample
6838   datap = GOMP_single_copy_start ();
6839   if (datap == NULL)
6840     @{
6841       body;
6842       data.x = x;
6843       GOMP_single_copy_end (&data);
6844     @}
6845   else
6846     x = datap->x;
6847   GOMP_barrier ();
6848 @end smallexample
6852 @node Implementing OpenACC's PARALLEL construct
6853 @section Implementing OpenACC's PARALLEL construct
6855 @smallexample
6856   void GOACC_parallel ()
6857 @end smallexample
6861 @c ---------------------------------------------------------------------
6862 @c Reporting Bugs
6863 @c ---------------------------------------------------------------------
6865 @node Reporting Bugs
6866 @chapter Reporting Bugs
6868 Bugs in the GNU Offloading and Multi Processing Runtime Library should
6869 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
6870 "openacc", or "openmp", or both to the keywords field in the bug
6871 report, as appropriate.
6875 @c ---------------------------------------------------------------------
6876 @c GNU General Public License
6877 @c ---------------------------------------------------------------------
6879 @include gpl_v3.texi
6883 @c ---------------------------------------------------------------------
6884 @c GNU Free Documentation License
6885 @c ---------------------------------------------------------------------
6887 @include fdl.texi
6891 @c ---------------------------------------------------------------------
6892 @c Funding Free Software
6893 @c ---------------------------------------------------------------------
6895 @include funding.texi
6897 @c ---------------------------------------------------------------------
6898 @c Index
6899 @c ---------------------------------------------------------------------
6901 @node Library Index
6902 @unnumbered Library Index
6904 @printindex cp
6906 @bye