Enable generation of GNU stack notes on Linux
[official-gcc.git] / libgomp / libgomp.texi
blobb635f81750b9bed0376d2970be5a3c8aa333657f
1 \input texinfo @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
9 @copying
10 Copyright @copyright{} 2006-2023 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below).  A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
22      A GNU Manual
24 (b) The FSF's Back-Cover Text is:
26      You have freedom to copy and modify this GNU Manual, like GNU
27      software.  Copies published by the Free Software Foundation raise
28      funds for GNU development.
29 @end copying
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library.  This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
40 Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
46 @insertcopying
47 @end ifinfo
50 @setchapternewpage odd
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
66 @summarycontents
67 @contents
68 @page
71 @node Top, Enabling OpenMP
72 @top Introduction
73 @cindex Introduction
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library.  This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
82 and Fortran.
84 Originally, libgomp implemented the GNU OpenMP Runtime Library.  Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
91 @comment
92 @comment  When you add a new menu item, please keep the right hand
93 @comment  aligned to the same column.  Do not use tabs.  This provides
94 @comment  better formatting.
95 @comment
96 @menu
97 * Enabling OpenMP::            How to enable OpenMP for your applications.
98 * OpenMP Implementation Status:: List of implemented features by OpenMP version
99 * OpenMP Runtime Library Routines: Runtime Library Routines.
100                                The OpenMP runtime application programming
101                                interface.
102 * OpenMP Environment Variables: Environment Variables.
103                                Influencing OpenMP runtime behavior with
104                                environment variables.
105 * Enabling OpenACC::           How to enable OpenACC for your
106                                applications.
107 * OpenACC Runtime Library Routines:: The OpenACC runtime application
108                                programming interface.
109 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
110                                environment variables.
111 * CUDA Streams Usage::         Notes on the implementation of
112                                asynchronous operations.
113 * OpenACC Library Interoperability:: OpenACC library interoperability with the
114                                NVIDIA CUBLAS library.
115 * OpenACC Profiling Interface::
116 * OpenMP-Implementation Specifics:: Notes specifics of this OpenMP
117                                implementation
118 * Offload-Target Specifics::   Notes on offload-target specific internals
119 * The libgomp ABI::            Notes on the external ABI presented by libgomp.
120 * Reporting Bugs::             How to report bugs in the GNU Offloading and
121                                Multi Processing Runtime Library.
122 * Copying::                    GNU general public license says
123                                how you can copy and share libgomp.
124 * GNU Free Documentation License::
125                                How you can copy and share this manual.
126 * Funding::                    How to help assure continued work for free 
127                                software.
128 * Library Index::              Index of this documentation.
129 @end menu
132 @c ---------------------------------------------------------------------
133 @c Enabling OpenMP
134 @c ---------------------------------------------------------------------
136 @node Enabling OpenMP
137 @chapter Enabling OpenMP
139 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
140 flag @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 11:: Feature completion status to first 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 @tab Only C and Fortran, only stack variables
236 @item @code{allocate} clause @tab P @tab Initial support
237 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
238 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
239 @item Implicit declare target directive @tab Y @tab
240 @item Discontiguous array section with @code{target update} construct
241       @tab N @tab
242 @item C/C++'s lvalue expressions in @code{to}, @code{from}
243       and @code{map} clauses @tab N @tab
244 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
245 @item Nested @code{declare target} directive @tab Y @tab
246 @item Combined @code{master} constructs @tab Y @tab
247 @item @code{depend} clause on @code{taskwait} @tab Y @tab
248 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
249       @tab Y @tab
250 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
251 @item @code{depobj} construct and depend objects  @tab Y @tab
252 @item Lock hints were renamed to synchronization hints @tab Y @tab
253 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
254 @item Map-order clarifications @tab P @tab
255 @item @code{close} @emph{map-type-modifier} @tab Y @tab
256 @item Mapping C/C++ pointer variables and to assign the address of
257       device memory mapped by an array section @tab P @tab
258 @item Mapping of Fortran pointer and allocatable variables, including pointer
259       and allocatable components of variables
260       @tab P @tab Mapping of vars with allocatable components unsupported
261 @item @code{defaultmap} extensions @tab Y @tab
262 @item @code{declare mapper} directive @tab N @tab
263 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
264 @item Runtime routines and environment variables to display runtime thread
265       affinity information @tab Y @tab
266 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
267       routines @tab Y @tab
268 @item @code{omp_get_device_num} runtime routine @tab Y @tab
269 @item OMPT interface @tab N @tab
270 @item OMPD interface @tab N @tab
271 @end multitable
273 @unnumberedsubsec Other new OpenMP 5.0 features
275 @multitable @columnfractions .60 .10 .25
276 @headitem Description @tab Status @tab Comments
277 @item Supporting C++'s range-based for loop @tab Y @tab
278 @end multitable
281 @node OpenMP 5.1
282 @section OpenMP 5.1
284 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
286 @multitable @columnfractions .60 .10 .25
287 @headitem Description @tab Status @tab Comments
288 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
289 @item @code{omp_all_memory} reserved locator @tab Y @tab
290 @item @emph{target_device trait} in OpenMP Context @tab N @tab
291 @item @code{target_device} selector set in context selectors @tab N @tab
292 @item C/C++'s @code{declare variant} directive: elision support of
293       preprocessed code @tab N @tab
294 @item @code{declare variant}: new clauses @code{adjust_args} and
295       @code{append_args} @tab N @tab
296 @item @code{dispatch} construct @tab N @tab
297 @item device-specific ICV settings with environment variables @tab Y @tab
298 @item @code{assume} and @code{assumes} directives @tab Y @tab
299 @item @code{nothing} directive @tab Y @tab
300 @item @code{error} directive @tab Y @tab
301 @item @code{masked} construct @tab Y @tab
302 @item @code{scope} directive @tab Y @tab
303 @item Loop transformation constructs @tab N @tab
304 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
305       clauses of the @code{taskloop} construct @tab Y @tab
306 @item @code{align} clause in @code{allocate} directive @tab P
307       @tab Only C and Fortran (and only stack variables)
308 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
309 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
310 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
311 @item Iterators in @code{target update} motion clauses and @code{map}
312       clauses @tab N @tab
313 @item Indirect calls to the device version of a procedure or function in
314       @code{target} regions @tab N @tab
315 @item @code{interop} directive @tab N @tab
316 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
317 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
318 @item Extensions to the @code{atomic} directive @tab Y @tab
319 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
320 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
321 @item @code{private} and @code{firstprivate} argument to @code{default}
322       clause in C and C++ @tab Y @tab
323 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
324 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
325       @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
326       routines @tab Y @tab
327 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
328 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
329       runtime routines @tab Y @tab
330 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
331 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
332       @code{omp_aligned_calloc} runtime routines @tab Y @tab
333 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
334       @code{omp_atv_default} changed @tab Y @tab
335 @item @code{omp_display_env} runtime routine @tab Y @tab
336 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
337 @item @code{ompt_sync_region_t} enum additions @tab N @tab
338 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
339       and @code{ompt_state_wait_barrier_teams} @tab N @tab
340 @item @code{ompt_callback_target_data_op_emi_t},
341       @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
342       and @code{ompt_callback_target_submit_emi_t} @tab N @tab
343 @item @code{ompt_callback_error_t} type @tab N @tab
344 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
345 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
346       variables @tab Y @tab
347 @end multitable
349 @unnumberedsubsec Other new OpenMP 5.1 features
351 @multitable @columnfractions .60 .10 .25
352 @headitem Description @tab Status @tab Comments
353 @item Support of strictly structured blocks in Fortran @tab Y @tab
354 @item Support of structured block sequences in C/C++ @tab Y @tab
355 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
356       clause @tab Y @tab
357 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
358 @item Pointer predetermined firstprivate getting initialized
359 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
360 @item For Fortran, diagnose placing declarative before/between @code{USE},
361       @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
362 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
363 @item @code{indirect} clause in @code{declare target} @tab N @tab
364 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
365 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
366       clauses @tab Y @tab
367 @end multitable
370 @node OpenMP 5.2
371 @section OpenMP 5.2
373 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
375 @multitable @columnfractions .60 .10 .25
376 @headitem Description @tab Status @tab Comments
377 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
378       @tab Y @tab
379 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
380       namespaces @tab N/A
381       @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
382       sentinel as C/C++ pragma and C++ attributes are warned for with
383       @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
384       (enabled by default), respectively; for Fortran free-source code, there is
385       a warning enabled by default and, for fixed-source code, the @code{omx}
386       sentinel is warned for with with @code{-Wsurprising} (enabled by
387       @code{-Wall}).  Unknown clauses are always rejected with an error.}
388 @item Clauses on @code{end} directive can be on directive @tab Y @tab
389 @item @code{destroy} clause with destroy-var argument on @code{depobj}
390       @tab N @tab
391 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
392       @tab N @tab
393 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
394 @item Deprecation of minus operator for reductions @tab N @tab
395 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
396 @item @code{declare mapper} with iterator and @code{present} modifiers
397       @tab N @tab
398 @item If a matching mapped list item is not found in the data environment, the
399       pointer retains its original value @tab Y @tab
400 @item New @code{enter} clause as alias for @code{to} on declare target directive
401       @tab Y @tab
402 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
403 @item Extended list of directives permitted in Fortran pure procedures
404       @tab Y @tab
405 @item New @code{allocators} directive for Fortran @tab N @tab
406 @item Deprecation of @code{allocate} directive for Fortran
407       allocatables/pointers @tab N @tab
408 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
409 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
410       @tab N @tab
411 @item Deprecation of traits array following the allocator_handle expression in
412       @code{uses_allocators} @tab N @tab
413 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
414       @tab N @tab
415 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
416 @item Deprecation of delimited form of @code{declare target} @tab N @tab
417 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
418 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
419       @tab Y @tab
420 @item @code{ompt_callback_work} @tab N @tab
421 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
422       @tab Y @tab
423 @item New @code{doacross} clause as alias for @code{depend} with
424       @code{source}/@code{sink} modifier @tab Y @tab
425 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
426       @tab N @tab
427 @item @code{omp_cur_iteration} keyword @tab Y @tab
428 @end multitable
430 @unnumberedsubsec Other new OpenMP 5.2 features
432 @multitable @columnfractions .60 .10 .25
433 @headitem Description @tab Status @tab Comments
434 @item For Fortran, optional comma between directive and clause @tab N @tab
435 @item Conforming device numbers and @code{omp_initial_device} and
436       @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
437 @item Initial value of @var{default-device-var} ICV with
438       @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
439 @item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
440 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
441       of the @code{interop} construct @tab N @tab
442 @end multitable
445 @node OpenMP Technical Report 11
446 @section OpenMP Technical Report 11
448 Technical Report (TR) 11 is the first preview for OpenMP 6.0.
450 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
451 @multitable @columnfractions .60 .10 .25
452 @item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
453       @tab N/A @tab Backward compatibility
454 @item The @code{decl} attribute was added to the C++ attribute syntax
455       @tab Y @tab
456 @item @code{_ALL} suffix to the device-scope environment variables
457       @tab P @tab Host device number wrongly accepted
458 @item For Fortran, @emph{locator list} can be also function reference with
459       data pointer result @tab N @tab
460 @item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
461       @tab N @tab
462 @item Implicit reduction identifiers of C++ classes
463       @tab N @tab
464 @item Change of the @emph{map-type} property from @emph{ultimate} to
465       @emph{default} @tab N @tab
466 @item Concept of @emph{assumed-size arrays} in C and C++
467       @tab N @tab
468 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
469       @tab N @tab
470 @item @code{groupprivate} directive @tab N @tab
471 @item @code{local} clause to declare target directive @tab N @tab
472 @item @code{part_size} allocator trait @tab N @tab
473 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
474       allocator traits
475       @tab N @tab
476 @item @code{access} allocator trait changes @tab N @tab
477 @item Extension of @code{interop} operation of @code{append_args}, allowing all
478       modifiers of the @code{init} clause
479       @tab N @tab
480 @item @code{interop} clause to @code{dispatch} @tab N @tab
481 @item @code{apply} code to loop-transforming constructs @tab N @tab
482 @item @code{omp_curr_progress_width} identifier @tab N @tab
483 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
484 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
485 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
486 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
487 @item Routines for obtaining memory spaces/allocators for shared/device memory
488       @tab N @tab
489 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
490 @item @code{omp_get_submemspace} routine @tab N @tab
491 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
492 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
493       @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
494 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
495 @end multitable
497 @unnumberedsubsec Other new TR 11 features
498 @multitable @columnfractions .60 .10 .25
499 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
500 @item Mapping lambda captures @tab N @tab
501 @item For Fortran, atomic compare with storing the comparison result
502       @tab N @tab
503 @end multitable
507 @c ---------------------------------------------------------------------
508 @c OpenMP Runtime Library Routines
509 @c ---------------------------------------------------------------------
511 @node Runtime Library Routines
512 @chapter OpenMP Runtime Library Routines
514 The runtime routines described here are defined by Section 18 of the OpenMP
515 specification in version 5.2.
517 @menu
518 * Thread Team Routines::
519 * Thread Affinity Routines::
520 * Teams Region Routines::
521 * Tasking Routines::
522 @c * Resource Relinquishing Routines::
523 * Device Information Routines::
524 * Device Memory Routines::
525 * Lock Routines::
526 * Timing Routines::
527 * Event Routine::
528 @c * Interoperability Routines::
529 * Memory Management Routines::
530 @c * Tool Control Routine::
531 @c * Environment Display Routine::
532 @end menu
536 @node Thread Team Routines
537 @section Thread Team Routines
539 Routines controlling threads in the current contention group.
540 They have C linkage and do not throw exceptions.
542 @menu
543 * omp_set_num_threads::         Set upper team size limit
544 * omp_get_num_threads::         Size of the active team
545 * omp_get_max_threads::         Maximum number of threads of parallel region
546 * omp_get_thread_num::          Current thread ID
547 * omp_in_parallel::             Whether a parallel region is active
548 * omp_set_dynamic::             Enable/disable dynamic teams
549 * omp_get_dynamic::             Dynamic teams setting
550 * omp_get_cancellation::        Whether cancellation support is enabled
551 * omp_set_nested::              Enable/disable nested parallel regions
552 * omp_get_nested::              Nested parallel regions
553 * omp_set_schedule::            Set the runtime scheduling method
554 * omp_get_schedule::            Obtain the runtime scheduling method
555 * omp_get_teams_thread_limit::  Maximum number of threads imposed by teams
556 * omp_get_supported_active_levels:: Maximum number of active regions supported
557 * omp_set_max_active_levels::   Limits the number of active parallel regions
558 * omp_get_max_active_levels::   Current maximum number of active regions
559 * omp_get_level::               Number of parallel regions
560 * omp_get_ancestor_thread_num:: Ancestor thread ID
561 * omp_get_team_size::           Number of threads in a team
562 * omp_get_active_level::        Number of active parallel regions
563 @end menu
567 @node omp_set_num_threads
568 @subsection @code{omp_set_num_threads} -- Set upper team size limit
569 @table @asis
570 @item @emph{Description}:
571 Specifies the number of threads used by default in subsequent parallel
572 sections, if those do not specify a @code{num_threads} clause.  The
573 argument of @code{omp_set_num_threads} shall be a positive integer.
575 @item @emph{C/C++}:
576 @multitable @columnfractions .20 .80
577 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
578 @end multitable
580 @item @emph{Fortran}:
581 @multitable @columnfractions .20 .80
582 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
583 @item                   @tab @code{integer, intent(in) :: num_threads}
584 @end multitable
586 @item @emph{See also}:
587 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
589 @item @emph{Reference}:
590 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
591 @end table
595 @node omp_get_num_threads
596 @subsection @code{omp_get_num_threads} -- Size of the active team
597 @table @asis
598 @item @emph{Description}:
599 Returns the number of threads in the current team.  In a sequential section of
600 the program @code{omp_get_num_threads} returns 1.
602 The default team size may be initialized at startup by the
603 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
604 of the current team may be set either by the @code{NUM_THREADS}
605 clause or by @code{omp_set_num_threads}.  If none of the above were
606 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
607 one thread per CPU online is used.
609 @item @emph{C/C++}:
610 @multitable @columnfractions .20 .80
611 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
612 @end multitable
614 @item @emph{Fortran}:
615 @multitable @columnfractions .20 .80
616 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
617 @end multitable
619 @item @emph{See also}:
620 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
622 @item @emph{Reference}:
623 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
624 @end table
628 @node omp_get_max_threads
629 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
630 @table @asis
631 @item @emph{Description}:
632 Return the maximum number of threads used for the current parallel region
633 that does not use the clause @code{num_threads}.
635 @item @emph{C/C++}:
636 @multitable @columnfractions .20 .80
637 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
638 @end multitable
640 @item @emph{Fortran}:
641 @multitable @columnfractions .20 .80
642 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
643 @end multitable
645 @item @emph{See also}:
646 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
648 @item @emph{Reference}:
649 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
650 @end table
654 @node omp_get_thread_num
655 @subsection @code{omp_get_thread_num} -- Current thread ID
656 @table @asis
657 @item @emph{Description}:
658 Returns a unique thread identification number within the current team.
659 In a sequential parts of the program, @code{omp_get_thread_num}
660 always returns 0.  In parallel regions the return value varies
661 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
662 value of the primary thread of a team is always 0.
664 @item @emph{C/C++}:
665 @multitable @columnfractions .20 .80
666 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
667 @end multitable
669 @item @emph{Fortran}:
670 @multitable @columnfractions .20 .80
671 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
672 @end multitable
674 @item @emph{See also}:
675 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
677 @item @emph{Reference}:
678 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
679 @end table
683 @node omp_in_parallel
684 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
685 @table @asis
686 @item @emph{Description}:
687 This function returns @code{true} if currently running in parallel,
688 @code{false} otherwise.  Here, @code{true} and @code{false} represent
689 their language-specific counterparts.
691 @item @emph{C/C++}:
692 @multitable @columnfractions .20 .80
693 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
694 @end multitable
696 @item @emph{Fortran}:
697 @multitable @columnfractions .20 .80
698 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
699 @end multitable
701 @item @emph{Reference}:
702 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
703 @end table
706 @node omp_set_dynamic
707 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
708 @table @asis
709 @item @emph{Description}:
710 Enable or disable the dynamic adjustment of the number of threads 
711 within a team.  The function takes the language-specific equivalent
712 of @code{true} and @code{false}, where @code{true} enables dynamic 
713 adjustment of team sizes and @code{false} disables it.
715 @item @emph{C/C++}:
716 @multitable @columnfractions .20 .80
717 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
718 @end multitable
720 @item @emph{Fortran}:
721 @multitable @columnfractions .20 .80
722 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
723 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
724 @end multitable
726 @item @emph{See also}:
727 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
729 @item @emph{Reference}:
730 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
731 @end table
735 @node omp_get_dynamic
736 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
737 @table @asis
738 @item @emph{Description}:
739 This function returns @code{true} if enabled, @code{false} otherwise. 
740 Here, @code{true} and @code{false} represent their language-specific 
741 counterparts.
743 The dynamic team setting may be initialized at startup by the 
744 @env{OMP_DYNAMIC} environment variable or at runtime using
745 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
746 disabled by default.
748 @item @emph{C/C++}:
749 @multitable @columnfractions .20 .80
750 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
751 @end multitable
753 @item @emph{Fortran}:
754 @multitable @columnfractions .20 .80
755 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
756 @end multitable
758 @item @emph{See also}:
759 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
761 @item @emph{Reference}:
762 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
763 @end table
767 @node omp_get_cancellation
768 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
769 @table @asis
770 @item @emph{Description}:
771 This function returns @code{true} if cancellation is activated, @code{false}
772 otherwise.  Here, @code{true} and @code{false} represent their language-specific
773 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
774 deactivated.
776 @item @emph{C/C++}:
777 @multitable @columnfractions .20 .80
778 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
779 @end multitable
781 @item @emph{Fortran}:
782 @multitable @columnfractions .20 .80
783 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
784 @end multitable
786 @item @emph{See also}:
787 @ref{OMP_CANCELLATION}
789 @item @emph{Reference}:
790 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
791 @end table
795 @node omp_set_nested
796 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
797 @table @asis
798 @item @emph{Description}:
799 Enable or disable nested parallel regions, i.e., whether team members
800 are allowed to create new teams.  The function takes the language-specific
801 equivalent of @code{true} and @code{false}, where @code{true} enables 
802 dynamic adjustment of team sizes and @code{false} disables it.
804 Enabling nested parallel regions also sets the maximum number of
805 active nested regions to the maximum supported.  Disabling nested parallel
806 regions sets the maximum number of active nested regions to one.
808 Note that the @code{omp_set_nested} API routine was deprecated
809 in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
811 @item @emph{C/C++}:
812 @multitable @columnfractions .20 .80
813 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
814 @end multitable
816 @item @emph{Fortran}:
817 @multitable @columnfractions .20 .80
818 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
819 @item                   @tab @code{logical, intent(in) :: nested}
820 @end multitable
822 @item @emph{See also}:
823 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
824 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
826 @item @emph{Reference}:
827 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
828 @end table
832 @node omp_get_nested
833 @subsection @code{omp_get_nested} -- Nested parallel regions
834 @table @asis
835 @item @emph{Description}:
836 This function returns @code{true} if nested parallel regions are
837 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
838 represent their language-specific counterparts.
840 The state of nested parallel regions at startup depends on several
841 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
842 and is set to greater than one, then nested parallel regions will be
843 enabled.  If not defined, then the value of the @env{OMP_NESTED}
844 environment variable will be followed if defined.  If neither are
845 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
846 are defined with a list of more than one value, then nested parallel
847 regions are enabled.  If none of these are defined, then nested parallel
848 regions are disabled by default.
850 Nested parallel regions can be enabled or disabled at runtime using
851 @code{omp_set_nested}, or by setting the maximum number of nested
852 regions with @code{omp_set_max_active_levels} to one to disable, or
853 above one to enable.
855 Note that the @code{omp_get_nested} API routine was deprecated
856 in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
858 @item @emph{C/C++}:
859 @multitable @columnfractions .20 .80
860 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
861 @end multitable
863 @item @emph{Fortran}:
864 @multitable @columnfractions .20 .80
865 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
866 @end multitable
868 @item @emph{See also}:
869 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
870 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
872 @item @emph{Reference}:
873 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
874 @end table
878 @node omp_set_schedule
879 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
880 @table @asis
881 @item @emph{Description}:
882 Sets the runtime scheduling method.  The @var{kind} argument can have the
883 value @code{omp_sched_static}, @code{omp_sched_dynamic},
884 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
885 @code{omp_sched_auto}, the chunk size is set to the value of
886 @var{chunk_size} if positive, or to the default value if zero or negative.
887 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
889 @item @emph{C/C++}
890 @multitable @columnfractions .20 .80
891 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
892 @end multitable
894 @item @emph{Fortran}:
895 @multitable @columnfractions .20 .80
896 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
897 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
898 @item                   @tab @code{integer chunk_size}
899 @end multitable
901 @item @emph{See also}:
902 @ref{omp_get_schedule}
903 @ref{OMP_SCHEDULE}
905 @item @emph{Reference}:
906 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
907 @end table
911 @node omp_get_schedule
912 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
913 @table @asis
914 @item @emph{Description}:
915 Obtain the runtime scheduling method.  The @var{kind} argument is set to
916 @code{omp_sched_static}, @code{omp_sched_dynamic},
917 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
918 @var{chunk_size}, is set to the chunk size.
920 @item @emph{C/C++}
921 @multitable @columnfractions .20 .80
922 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
923 @end multitable
925 @item @emph{Fortran}:
926 @multitable @columnfractions .20 .80
927 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
928 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
929 @item                   @tab @code{integer chunk_size}
930 @end multitable
932 @item @emph{See also}:
933 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
935 @item @emph{Reference}:
936 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
937 @end table
940 @node omp_get_teams_thread_limit
941 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
942 @table @asis
943 @item @emph{Description}:
944 Return the maximum number of threads that are able to participate in
945 each team created by a teams construct.
947 @item @emph{C/C++}:
948 @multitable @columnfractions .20 .80
949 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
950 @end multitable
952 @item @emph{Fortran}:
953 @multitable @columnfractions .20 .80
954 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
955 @end multitable
957 @item @emph{See also}:
958 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
960 @item @emph{Reference}:
961 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
962 @end table
966 @node omp_get_supported_active_levels
967 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
968 @table @asis
969 @item @emph{Description}:
970 This function returns the maximum number of nested, active parallel regions
971 supported by this implementation.
973 @item @emph{C/C++}
974 @multitable @columnfractions .20 .80
975 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
976 @end multitable
978 @item @emph{Fortran}:
979 @multitable @columnfractions .20 .80
980 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
981 @end multitable
983 @item @emph{See also}:
984 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
986 @item @emph{Reference}:
987 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
988 @end table
992 @node omp_set_max_active_levels
993 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
994 @table @asis
995 @item @emph{Description}:
996 This function limits the maximum allowed number of nested, active
997 parallel regions.  @var{max_levels} must be less or equal to
998 the value returned by @code{omp_get_supported_active_levels}.
1000 @item @emph{C/C++}
1001 @multitable @columnfractions .20 .80
1002 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1003 @end multitable
1005 @item @emph{Fortran}:
1006 @multitable @columnfractions .20 .80
1007 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1008 @item                   @tab @code{integer max_levels}
1009 @end multitable
1011 @item @emph{See also}:
1012 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1013 @ref{omp_get_supported_active_levels}
1015 @item @emph{Reference}:
1016 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1017 @end table
1021 @node omp_get_max_active_levels
1022 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1023 @table @asis
1024 @item @emph{Description}:
1025 This function obtains the maximum allowed number of nested, active parallel regions.
1027 @item @emph{C/C++}
1028 @multitable @columnfractions .20 .80
1029 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1030 @end multitable
1032 @item @emph{Fortran}:
1033 @multitable @columnfractions .20 .80
1034 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1035 @end multitable
1037 @item @emph{See also}:
1038 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1040 @item @emph{Reference}:
1041 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1042 @end table
1045 @node omp_get_level
1046 @subsection @code{omp_get_level} -- Obtain the current nesting level
1047 @table @asis
1048 @item @emph{Description}:
1049 This function returns the nesting level for the parallel blocks,
1050 which enclose the calling call.
1052 @item @emph{C/C++}
1053 @multitable @columnfractions .20 .80
1054 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1055 @end multitable
1057 @item @emph{Fortran}:
1058 @multitable @columnfractions .20 .80
1059 @item @emph{Interface}: @tab @code{integer function omp_level()}
1060 @end multitable
1062 @item @emph{See also}:
1063 @ref{omp_get_active_level}
1065 @item @emph{Reference}:
1066 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1067 @end table
1071 @node omp_get_ancestor_thread_num
1072 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1073 @table @asis
1074 @item @emph{Description}:
1075 This function returns the thread identification number for the given
1076 nesting level of the current thread.  For values of @var{level} outside
1077 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1078 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1080 @item @emph{C/C++}
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1083 @end multitable
1085 @item @emph{Fortran}:
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1088 @item                   @tab @code{integer level}
1089 @end multitable
1091 @item @emph{See also}:
1092 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1094 @item @emph{Reference}:
1095 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1096 @end table
1100 @node omp_get_team_size
1101 @subsection @code{omp_get_team_size} -- Number of threads in a team
1102 @table @asis
1103 @item @emph{Description}:
1104 This function returns the number of threads in a thread team to which
1105 either the current thread or its ancestor belongs.  For values of @var{level}
1106 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1107 1 is returned, and for @code{omp_get_level}, the result is identical
1108 to @code{omp_get_num_threads}.
1110 @item @emph{C/C++}:
1111 @multitable @columnfractions .20 .80
1112 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1113 @end multitable
1115 @item @emph{Fortran}:
1116 @multitable @columnfractions .20 .80
1117 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1118 @item                   @tab @code{integer level}
1119 @end multitable
1121 @item @emph{See also}:
1122 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1124 @item @emph{Reference}:
1125 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1126 @end table
1130 @node omp_get_active_level
1131 @subsection @code{omp_get_active_level} -- Number of parallel regions
1132 @table @asis
1133 @item @emph{Description}:
1134 This function returns the nesting level for the active parallel blocks,
1135 which enclose the calling call.
1137 @item @emph{C/C++}
1138 @multitable @columnfractions .20 .80
1139 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1140 @end multitable
1142 @item @emph{Fortran}:
1143 @multitable @columnfractions .20 .80
1144 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1145 @end multitable
1147 @item @emph{See also}:
1148 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1150 @item @emph{Reference}:
1151 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1152 @end table
1156 @node Thread Affinity Routines
1157 @section Thread Affinity Routines
1159 Routines controlling and accessing thread-affinity policies.
1160 They have C linkage and do not throw exceptions.
1162 @menu
1163 * omp_get_proc_bind::           Whether threads may be moved between CPUs
1164 @c * omp_get_num_places:: <fixme>
1165 @c * omp_get_place_num_procs:: <fixme>
1166 @c * omp_get_place_proc_ids:: <fixme>
1167 @c * omp_get_place_num:: <fixme>
1168 @c * omp_get_partition_num_places:: <fixme>
1169 @c * omp_get_partition_place_nums:: <fixme>
1170 @c * omp_set_affinity_format:: <fixme>
1171 @c * omp_get_affinity_format:: <fixme>
1172 @c * omp_display_affinity:: <fixme>
1173 @c * omp_capture_affinity:: <fixme>
1174 @end menu
1178 @node omp_get_proc_bind
1179 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1180 @table @asis
1181 @item @emph{Description}:
1182 This functions returns the currently active thread affinity policy, which is
1183 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
1184 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1185 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1186 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1188 @item @emph{C/C++}:
1189 @multitable @columnfractions .20 .80
1190 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1191 @end multitable
1193 @item @emph{Fortran}:
1194 @multitable @columnfractions .20 .80
1195 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1196 @end multitable
1198 @item @emph{See also}:
1199 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1201 @item @emph{Reference}:
1202 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1203 @end table
1207 @node Teams Region Routines
1208 @section Teams Region Routines
1210 Routines controlling the league of teams that are executed in a @code{teams}
1211 region.  They have C linkage and do not throw exceptions.
1213 @menu
1214 * omp_get_num_teams::           Number of teams
1215 * omp_get_team_num::            Get team number
1216 * omp_set_num_teams::           Set upper teams limit for teams region
1217 * omp_get_max_teams::           Maximum number of teams for teams region
1218 * omp_set_teams_thread_limit::  Set upper thread limit for teams construct
1219 * omp_get_thread_limit::        Maximum number of threads
1220 @end menu
1224 @node omp_get_num_teams
1225 @subsection @code{omp_get_num_teams} -- Number of teams
1226 @table @asis
1227 @item @emph{Description}:
1228 Returns the number of teams in the current team region.
1230 @item @emph{C/C++}:
1231 @multitable @columnfractions .20 .80
1232 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1233 @end multitable
1235 @item @emph{Fortran}:
1236 @multitable @columnfractions .20 .80
1237 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1238 @end multitable
1240 @item @emph{Reference}:
1241 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1242 @end table
1246 @node omp_get_team_num
1247 @subsection @code{omp_get_team_num} -- Get team number
1248 @table @asis
1249 @item @emph{Description}:
1250 Returns the team number of the calling thread.
1252 @item @emph{C/C++}:
1253 @multitable @columnfractions .20 .80
1254 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1255 @end multitable
1257 @item @emph{Fortran}:
1258 @multitable @columnfractions .20 .80
1259 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1260 @end multitable
1262 @item @emph{Reference}:
1263 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1264 @end table
1268 @node omp_set_num_teams
1269 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1270 @table @asis
1271 @item @emph{Description}:
1272 Specifies the upper bound for number of teams created by the teams construct
1273 which does not specify a @code{num_teams} clause.  The
1274 argument of @code{omp_set_num_teams} shall be a positive integer.
1276 @item @emph{C/C++}:
1277 @multitable @columnfractions .20 .80
1278 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1279 @end multitable
1281 @item @emph{Fortran}:
1282 @multitable @columnfractions .20 .80
1283 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1284 @item                   @tab @code{integer, intent(in) :: num_teams}
1285 @end multitable
1287 @item @emph{See also}:
1288 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1290 @item @emph{Reference}:
1291 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1292 @end table
1296 @node omp_get_max_teams
1297 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1298 @table @asis
1299 @item @emph{Description}:
1300 Return the maximum number of teams used for the teams region
1301 that does not use the clause @code{num_teams}.
1303 @item @emph{C/C++}:
1304 @multitable @columnfractions .20 .80
1305 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1306 @end multitable
1308 @item @emph{Fortran}:
1309 @multitable @columnfractions .20 .80
1310 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1311 @end multitable
1313 @item @emph{See also}:
1314 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1316 @item @emph{Reference}:
1317 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1318 @end table
1322 @node omp_set_teams_thread_limit
1323 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1324 @table @asis
1325 @item @emph{Description}:
1326 Specifies the upper bound for number of threads that are available
1327 for each team created by the teams construct which does not specify a
1328 @code{thread_limit} clause.  The argument of
1329 @code{omp_set_teams_thread_limit} shall be a positive integer.
1331 @item @emph{C/C++}:
1332 @multitable @columnfractions .20 .80
1333 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1334 @end multitable
1336 @item @emph{Fortran}:
1337 @multitable @columnfractions .20 .80
1338 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1339 @item                   @tab @code{integer, intent(in) :: thread_limit}
1340 @end multitable
1342 @item @emph{See also}:
1343 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1345 @item @emph{Reference}:
1346 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1347 @end table
1351 @node omp_get_thread_limit
1352 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1353 @table @asis
1354 @item @emph{Description}:
1355 Return the maximum number of threads of the program.
1357 @item @emph{C/C++}:
1358 @multitable @columnfractions .20 .80
1359 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1360 @end multitable
1362 @item @emph{Fortran}:
1363 @multitable @columnfractions .20 .80
1364 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1365 @end multitable
1367 @item @emph{See also}:
1368 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1370 @item @emph{Reference}:
1371 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1372 @end table
1376 @node Tasking Routines
1377 @section Tasking Routines
1379 Routines relating to explicit tasks.
1380 They have C linkage and do not throw exceptions.
1382 @menu
1383 * omp_get_max_task_priority::   Maximum task priority value that can be set
1384 * omp_in_explicit_task::        Whether a given task is an explicit task
1385 * omp_in_final::                Whether in final or included task region
1386 @end menu
1390 @node omp_get_max_task_priority
1391 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1392 that can be set for tasks.
1393 @table @asis
1394 @item @emph{Description}:
1395 This function obtains the maximum allowed priority number for tasks.
1397 @item @emph{C/C++}
1398 @multitable @columnfractions .20 .80
1399 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1400 @end multitable
1402 @item @emph{Fortran}:
1403 @multitable @columnfractions .20 .80
1404 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1405 @end multitable
1407 @item @emph{Reference}:
1408 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1409 @end table
1413 @node omp_in_explicit_task
1414 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1415 @table @asis
1416 @item @emph{Description}:
1417 The function returns the @var{explicit-task-var} ICV; it returns true when the
1418 encountering task was generated by a task-generating construct such as
1419 @code{target}, @code{task} or @code{taskloop}.  Otherwise, the encountering task
1420 is in an implicit task region such as generated by the implicit or explicit
1421 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1423 @item @emph{C/C++}
1424 @multitable @columnfractions .20 .80
1425 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1426 @end multitable
1428 @item @emph{Fortran}:
1429 @multitable @columnfractions .20 .80
1430 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1431 @end multitable
1433 @item @emph{Reference}:
1434 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1435 @end table
1439 @node omp_in_final
1440 @subsection @code{omp_in_final} -- Whether in final or included task region
1441 @table @asis
1442 @item @emph{Description}:
1443 This function returns @code{true} if currently running in a final
1444 or included task region, @code{false} otherwise.  Here, @code{true}
1445 and @code{false} represent their language-specific counterparts.
1447 @item @emph{C/C++}:
1448 @multitable @columnfractions .20 .80
1449 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1450 @end multitable
1452 @item @emph{Fortran}:
1453 @multitable @columnfractions .20 .80
1454 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1455 @end multitable
1457 @item @emph{Reference}:
1458 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1459 @end table
1463 @c @node Resource Relinquishing Routines
1464 @c @section Resource Relinquishing Routines
1466 @c Routines releasing resources used by the OpenMP runtime.
1467 @c They have C linkage and do not throw exceptions.
1469 @c @menu
1470 @c * omp_pause_resource:: <fixme>
1471 @c * omp_pause_resource_all:: <fixme>
1472 @c @end menu
1474 @node Device Information Routines
1475 @section Device Information Routines
1477 Routines related to devices available to an OpenMP program.
1478 They have C linkage and do not throw exceptions.
1480 @menu
1481 * omp_get_num_procs::           Number of processors online
1482 @c * omp_get_max_progress_width:: <fixme>/TR11
1483 * omp_set_default_device::      Set the default device for target regions
1484 * omp_get_default_device::      Get the default device for target regions
1485 * omp_get_num_devices::         Number of target devices
1486 * omp_get_device_num::          Get device that current thread is running on
1487 * omp_is_initial_device::       Whether executing on the host device
1488 * omp_get_initial_device::      Device number of host device
1489 @end menu
1493 @node omp_get_num_procs
1494 @subsection @code{omp_get_num_procs} -- Number of processors online
1495 @table @asis
1496 @item @emph{Description}:
1497 Returns the number of processors online on that device.
1499 @item @emph{C/C++}:
1500 @multitable @columnfractions .20 .80
1501 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1502 @end multitable
1504 @item @emph{Fortran}:
1505 @multitable @columnfractions .20 .80
1506 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1507 @end multitable
1509 @item @emph{Reference}:
1510 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1511 @end table
1515 @node omp_set_default_device
1516 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1517 @table @asis
1518 @item @emph{Description}:
1519 Set the default device for target regions without device clause.  The argument
1520 shall be a nonnegative device number.
1522 @item @emph{C/C++}:
1523 @multitable @columnfractions .20 .80
1524 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1525 @end multitable
1527 @item @emph{Fortran}:
1528 @multitable @columnfractions .20 .80
1529 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1530 @item                   @tab @code{integer device_num}
1531 @end multitable
1533 @item @emph{See also}:
1534 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1536 @item @emph{Reference}:
1537 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1538 @end table
1542 @node omp_get_default_device
1543 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1544 @table @asis
1545 @item @emph{Description}:
1546 Get the default device for target regions without device clause.
1548 @item @emph{C/C++}:
1549 @multitable @columnfractions .20 .80
1550 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1551 @end multitable
1553 @item @emph{Fortran}:
1554 @multitable @columnfractions .20 .80
1555 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1556 @end multitable
1558 @item @emph{See also}:
1559 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
1561 @item @emph{Reference}:
1562 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1563 @end table
1567 @node omp_get_num_devices
1568 @subsection @code{omp_get_num_devices} -- Number of target devices
1569 @table @asis
1570 @item @emph{Description}:
1571 Returns the number of target devices.
1573 @item @emph{C/C++}:
1574 @multitable @columnfractions .20 .80
1575 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1576 @end multitable
1578 @item @emph{Fortran}:
1579 @multitable @columnfractions .20 .80
1580 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1581 @end multitable
1583 @item @emph{Reference}:
1584 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1585 @end table
1589 @node omp_get_device_num
1590 @subsection @code{omp_get_device_num} -- Return device number of current device
1591 @table @asis
1592 @item @emph{Description}:
1593 This function returns a device number that represents the device that the
1594 current thread is executing on. For OpenMP 5.0, this must be equal to the
1595 value returned by the @code{omp_get_initial_device} function when called
1596 from the host.
1598 @item @emph{C/C++}
1599 @multitable @columnfractions .20 .80
1600 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1601 @end multitable
1603 @item @emph{Fortran}:
1604 @multitable @columnfractions .20 .80
1605 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1606 @end multitable
1608 @item @emph{See also}:
1609 @ref{omp_get_initial_device}
1611 @item @emph{Reference}:
1612 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1613 @end table
1617 @node omp_is_initial_device
1618 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1619 @table @asis
1620 @item @emph{Description}:
1621 This function returns @code{true} if currently running on the host device,
1622 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1623 their language-specific counterparts.
1625 @item @emph{C/C++}:
1626 @multitable @columnfractions .20 .80
1627 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1628 @end multitable
1630 @item @emph{Fortran}:
1631 @multitable @columnfractions .20 .80
1632 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1633 @end multitable
1635 @item @emph{Reference}:
1636 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1637 @end table
1641 @node omp_get_initial_device
1642 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1643 @table @asis
1644 @item @emph{Description}:
1645 This function returns a device number that represents the host device.
1646 For OpenMP 5.1, this must be equal to the value returned by the
1647 @code{omp_get_num_devices} function.
1649 @item @emph{C/C++}
1650 @multitable @columnfractions .20 .80
1651 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1652 @end multitable
1654 @item @emph{Fortran}:
1655 @multitable @columnfractions .20 .80
1656 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1657 @end multitable
1659 @item @emph{See also}:
1660 @ref{omp_get_num_devices}
1662 @item @emph{Reference}:
1663 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1664 @end table
1668 @node Device Memory Routines
1669 @section Device Memory Routines
1671 Routines related to memory allocation and managing corresponding
1672 pointers on devices. They have C linkage and do not throw exceptions.
1674 @menu
1675 * omp_target_alloc:: Allocate device memory
1676 * omp_target_free:: Free device memory
1677 * omp_target_is_present:: Check whether storage is mapped
1678 @c * omp_target_is_accessible:: <fixme>
1679 @c * omp_target_memcpy:: <fixme>
1680 @c * omp_target_memcpy_rect:: <fixme>
1681 @c * omp_target_memcpy_async:: <fixme>
1682 @c * omp_target_memcpy_rect_async:: <fixme>
1683 @c * omp_target_memset:: <fixme>/TR12
1684 @c * omp_target_memset_async:: <fixme>/TR12
1685 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
1686 * omp_target_disassociate_ptr:: Remove device--host pointer association
1687 * omp_get_mapped_ptr:: Return device pointer to a host pointer
1688 @end menu
1692 @node omp_target_alloc
1693 @subsection @code{omp_target_alloc} -- Allocate device memory
1694 @table @asis
1695 @item @emph{Description}:
1696 This routine allocates @var{size} bytes of memory in the device environment
1697 associated with the device number @var{device_num}.  If successful, a device
1698 pointer is returned, otherwise a null pointer.
1700 In GCC, when the device is the host or the device shares memory with the host,
1701 the memory is allocated on the host; in that case, when @var{size} is zero,
1702 either NULL or a unique pointer value that can later be successfully passed to
1703 @code{omp_target_free} is returned.  When the allocation is not performed on
1704 the host, a null pointer is returned when @var{size} is zero; in that case,
1705 additionally a diagnostic might be printed to standard error (stderr).
1707 Running this routine in a @code{target} region except on the initial device
1708 is not supported.
1710 @item @emph{C/C++}
1711 @multitable @columnfractions .20 .80
1712 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
1713 @end multitable
1715 @item @emph{Fortran}:
1716 @multitable @columnfractions .20 .80
1717 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
1718 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
1719 @item                   @tab @code{integer(c_size_t), value :: size}
1720 @item                   @tab @code{integer(c_int), value :: device_num}
1721 @end multitable
1723 @item @emph{See also}:
1724 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
1726 @item @emph{Reference}:
1727 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.1
1728 @end table
1732 @node omp_target_free
1733 @subsection @code{omp_target_free} -- Free device memory
1734 @table @asis
1735 @item @emph{Description}:
1736 This routine frees memory allocated by the @code{omp_target_alloc} routine.
1737 The @var{device_ptr} argument must be either a null pointer or a device pointer
1738 returned by @code{omp_target_alloc} for the specified @code{device_num}.  The
1739 device number @var{device_num} must be a conforming device number.
1741 Running this routine in a @code{target} region except on the initial device
1742 is not supported.
1744 @item @emph{C/C++}
1745 @multitable @columnfractions .20 .80
1746 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
1747 @end multitable
1749 @item @emph{Fortran}:
1750 @multitable @columnfractions .20 .80
1751 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
1752 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1753 @item                   @tab @code{type(c_ptr), value :: device_ptr}
1754 @item                   @tab @code{integer(c_int), value :: device_num}
1755 @end multitable
1757 @item @emph{See also}:
1758 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
1760 @item @emph{Reference}:
1761 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.2
1762 @end table
1766 @node omp_target_is_present
1767 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
1768 @table @asis
1769 @item @emph{Description}:
1770 This routine tests whether storage, identified by the host pointer @var{ptr}
1771 is mapped to the device specified by @var{device_num}.  If so, it returns
1772 @emph{true} and otherwise @emph{false}.
1774 In GCC, this includes self mapping such that @code{omp_target_is_present}
1775 returns @emph{true} when @var{device_num} specifies the host or when the host
1776 and the device share memory.  If @var{ptr} is a null pointer, @var{true} is
1777 returned and if @var{device_num} is an invalid device number, @var{false} is
1778 returned.
1780 If those conditions do not apply, @emph{true} is returned if the association has
1781 been established by an explicit or implicit @code{map} clause, the
1782 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
1783 routine.
1785 Running this routine in a @code{target} region except on the initial device
1786 is not supported.
1788 @item @emph{C/C++}
1789 @multitable @columnfractions .20 .80
1790 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
1791 @item                   @tab @code{                          int device_num)}
1792 @end multitable
1794 @item @emph{Fortran}:
1795 @multitable @columnfractions .20 .80
1796 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
1797 @item                   @tab @code{    device_num) bind(C)}
1798 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1799 @item                   @tab @code{type(c_ptr), value :: ptr}
1800 @item                   @tab @code{integer(c_int), value :: device_num}
1801 @end multitable
1803 @item @emph{See also}:
1804 @ref{omp_target_associate_ptr}
1806 @item @emph{Reference}:
1807 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.3
1808 @end table
1812 @node omp_target_associate_ptr
1813 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
1814 @table @asis
1815 @item @emph{Description}:
1816 This routine associates storage on the host with storage on a device identified
1817 by @var{device_num}.  The device pointer is usually obtained by calling
1818 @code{omp_target_alloc} or by other means (but not by using the @code{map}
1819 clauses or the @code{declare target} directive).  The host pointer should point
1820 to memory that has a storage size of at least @var{size}.
1822 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
1823 that is used as the base address for the device side of the mapping; the
1824 storage size should be at least @var{device_offset} plus @var{size}.
1826 After the association, the host pointer can be used in a @code{map} clause and
1827 in the @code{to} and @code{from} clauses of the @code{target update} directive
1828 to transfer data between the associated pointers. The reference count of such
1829 associated storage is infinite.  The association can be removed by calling
1830 @code{omp_target_disassociate_ptr} which should be done before the lifetime
1831 of either either storage ends.
1833 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
1834 for when the initial device or the associated device shares memory with the
1835 host.  @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
1836 into already associated storage that is fully inside of a previously associated
1837 memory.  Otherwise, if the association was successful zero is returned; if none
1838 of the cases above apply, nonzero (@code{EINVAL}) is returned.
1840 The @code{omp_target_is_present} routine can be used to test whether
1841 associated storage for a device pointer exists.
1843 Running this routine in a @code{target} region except on the initial device
1844 is not supported.
1846 @item @emph{C/C++}
1847 @multitable @columnfractions .20 .80
1848 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
1849 @item                   @tab @code{                             const void *device_ptr,}
1850 @item                   @tab @code{                             size_t size,}
1851 @item                   @tab @code{                             size_t device_offset,}
1852 @item                   @tab @code{                             int device_num)}
1853 @end multitable
1855 @item @emph{Fortran}:
1856 @multitable @columnfractions .20 .80
1857 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
1858 @item                   @tab @code{    device_ptr, size, device_offset, device_num) bind(C)}
1859 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
1860 @item                   @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
1861 @item                   @tab @code{integer(c_size_t), value :: size, device_offset}
1862 @item                   @tab @code{integer(c_int), value :: device_num}
1863 @end multitable
1865 @item @emph{See also}:
1866 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
1867 @ref{omp_target_alloc}
1869 @item @emph{Reference}:
1870 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.9
1871 @end table
1875 @node omp_target_disassociate_ptr
1876 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
1877 @table @asis
1878 @item @emph{Description}:
1879 This routine removes the storage association established by calling
1880 @code{omp_target_associate_ptr} and sets the reference count to zero,
1881 even if @code{omp_target_associate_ptr} was invoked multiple times for
1882 for host pointer @code{ptr}.  If applicable, the device memory needs
1883 to be freed by the user.
1885 If an associated device storage location for the @var{device_num} was
1886 found and has infinite reference count, the association is removed and
1887 zero is returned.  In all other cases, nonzero (@code{EINVAL}) is returned
1888 and no other action is taken.
1890 Note that passing a host pointer where the association to the device pointer
1891 was established with the @code{declare target} directive yields undefined
1892 behavior.
1894 Running this routine in a @code{target} region except on the initial device
1895 is not supported.
1897 @item @emph{C/C++}
1898 @multitable @columnfractions .20 .80
1899 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
1900 @item                   @tab @code{                                int device_num)}
1901 @end multitable
1903 @item @emph{Fortran}:
1904 @multitable @columnfractions .20 .80
1905 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
1906 @item                   @tab @code{    device_num) bind(C)}
1907 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1908 @item                   @tab @code{type(c_ptr), value :: ptr}
1909 @item                   @tab @code{integer(c_int), value :: device_num}
1910 @end multitable
1912 @item @emph{See also}:
1913 @ref{omp_target_associate_ptr}
1915 @item @emph{Reference}:
1916 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.10
1917 @end table
1921 @node omp_get_mapped_ptr
1922 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
1923 @table @asis
1924 @item @emph{Description}:
1925 If the device number is refers to the initial device or to a device with
1926 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
1927 routines returns the value of the passed @var{ptr}.  Otherwise, if associated
1928 storage to the passed host pointer @var{ptr} exists on device associated with
1929 @var{device_num}, it returns that pointer. In all other cases and in cases of
1930 an error, a null pointer is returned.
1932 The association of storage location is established either via an explicit or
1933 implicit @code{map} clause, the @code{declare target} directive or the
1934 @code{omp_target_associate_ptr} routine.
1936 Running this routine in a @code{target} region except on the initial device
1937 is not supported.
1939 @item @emph{C/C++}
1940 @multitable @columnfractions .20 .80
1941 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
1942 @end multitable
1944 @item @emph{Fortran}:
1945 @multitable @columnfractions .20 .80
1946 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
1947 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
1948 @item                   @tab @code{type(c_ptr), value :: ptr}
1949 @item                   @tab @code{integer(c_int), value :: device_num}
1950 @end multitable
1952 @item @emph{See also}:
1953 @ref{omp_target_associate_ptr}
1955 @item @emph{Reference}:
1956 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 18.8.11
1957 @end table
1961 @node Lock Routines
1962 @section Lock Routines
1964 Initialize, set, test, unset and destroy simple and nested locks.
1965 The routines have C linkage and do not throw exceptions.
1967 @menu
1968 * omp_init_lock::            Initialize simple lock
1969 * omp_init_nest_lock::       Initialize nested lock
1970 @c * omp_init_lock_with_hint:: <fixme>
1971 @c * omp_init_nest_lock_with_hint:: <fixme>
1972 * omp_destroy_lock::         Destroy simple lock
1973 * omp_destroy_nest_lock::    Destroy nested lock
1974 * omp_set_lock::             Wait for and set simple lock
1975 * omp_set_nest_lock::        Wait for and set simple lock
1976 * omp_unset_lock::           Unset simple lock
1977 * omp_unset_nest_lock::      Unset nested lock
1978 * omp_test_lock::            Test and set simple lock if available
1979 * omp_test_nest_lock::       Test and set nested lock if available
1980 @end menu
1984 @node omp_init_lock
1985 @subsection @code{omp_init_lock} -- Initialize simple lock
1986 @table @asis
1987 @item @emph{Description}:
1988 Initialize a simple lock.  After initialization, the lock is in
1989 an unlocked state.
1991 @item @emph{C/C++}:
1992 @multitable @columnfractions .20 .80
1993 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1994 @end multitable
1996 @item @emph{Fortran}:
1997 @multitable @columnfractions .20 .80
1998 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1999 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2000 @end multitable
2002 @item @emph{See also}:
2003 @ref{omp_destroy_lock}
2005 @item @emph{Reference}: 
2006 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2007 @end table
2011 @node omp_init_nest_lock
2012 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2013 @table @asis
2014 @item @emph{Description}:
2015 Initialize a nested lock.  After initialization, the lock is in
2016 an unlocked state and the nesting count is set to zero.
2018 @item @emph{C/C++}:
2019 @multitable @columnfractions .20 .80
2020 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2021 @end multitable
2023 @item @emph{Fortran}:
2024 @multitable @columnfractions .20 .80
2025 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2026 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2027 @end multitable
2029 @item @emph{See also}:
2030 @ref{omp_destroy_nest_lock}
2032 @item @emph{Reference}:
2033 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2034 @end table
2038 @node omp_destroy_lock
2039 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2040 @table @asis
2041 @item @emph{Description}:
2042 Destroy a simple lock.  In order to be destroyed, a simple lock must be
2043 in the unlocked state. 
2045 @item @emph{C/C++}:
2046 @multitable @columnfractions .20 .80
2047 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2048 @end multitable
2050 @item @emph{Fortran}:
2051 @multitable @columnfractions .20 .80
2052 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2053 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2054 @end multitable
2056 @item @emph{See also}:
2057 @ref{omp_init_lock}
2059 @item @emph{Reference}: 
2060 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2061 @end table
2065 @node omp_destroy_nest_lock
2066 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2067 @table @asis
2068 @item @emph{Description}:
2069 Destroy a nested lock.  In order to be destroyed, a nested lock must be
2070 in the unlocked state and its nesting count must equal zero.
2072 @item @emph{C/C++}:
2073 @multitable @columnfractions .20 .80
2074 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2075 @end multitable
2077 @item @emph{Fortran}:
2078 @multitable @columnfractions .20 .80
2079 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2080 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2081 @end multitable
2083 @item @emph{See also}:
2084 @ref{omp_init_lock}
2086 @item @emph{Reference}: 
2087 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2088 @end table
2092 @node omp_set_lock
2093 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2094 @table @asis
2095 @item @emph{Description}:
2096 Before setting a simple lock, the lock variable must be initialized by 
2097 @code{omp_init_lock}.  The calling thread is blocked until the lock 
2098 is available.  If the lock is already held by the current thread, 
2099 a deadlock occurs.
2101 @item @emph{C/C++}:
2102 @multitable @columnfractions .20 .80
2103 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2104 @end multitable
2106 @item @emph{Fortran}:
2107 @multitable @columnfractions .20 .80
2108 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2109 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2110 @end multitable
2112 @item @emph{See also}:
2113 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2115 @item @emph{Reference}: 
2116 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2117 @end table
2121 @node omp_set_nest_lock
2122 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2123 @table @asis
2124 @item @emph{Description}:
2125 Before setting a nested lock, the lock variable must be initialized by 
2126 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
2127 is available.  If the lock is already held by the current thread, the
2128 nesting count for the lock is incremented.
2130 @item @emph{C/C++}:
2131 @multitable @columnfractions .20 .80
2132 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2133 @end multitable
2135 @item @emph{Fortran}:
2136 @multitable @columnfractions .20 .80
2137 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2138 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2139 @end multitable
2141 @item @emph{See also}:
2142 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2144 @item @emph{Reference}: 
2145 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2146 @end table
2150 @node omp_unset_lock
2151 @subsection @code{omp_unset_lock} -- Unset simple lock
2152 @table @asis
2153 @item @emph{Description}:
2154 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2155 or @code{omp_test_lock} before.  In addition, the lock must be held by the
2156 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
2157 or more threads attempted to set the lock before, one of them is chosen to,
2158 again, set the lock to itself.
2160 @item @emph{C/C++}:
2161 @multitable @columnfractions .20 .80
2162 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2163 @end multitable
2165 @item @emph{Fortran}:
2166 @multitable @columnfractions .20 .80
2167 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2168 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2169 @end multitable
2171 @item @emph{See also}:
2172 @ref{omp_set_lock}, @ref{omp_test_lock}
2174 @item @emph{Reference}: 
2175 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2176 @end table
2180 @node omp_unset_nest_lock
2181 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2182 @table @asis
2183 @item @emph{Description}:
2184 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2185 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
2186 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
2187 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
2188 one of them is chosen to, again, set the lock to itself.
2190 @item @emph{C/C++}:
2191 @multitable @columnfractions .20 .80
2192 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2193 @end multitable
2195 @item @emph{Fortran}:
2196 @multitable @columnfractions .20 .80
2197 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2198 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2199 @end multitable
2201 @item @emph{See also}:
2202 @ref{omp_set_nest_lock}
2204 @item @emph{Reference}: 
2205 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2206 @end table
2210 @node omp_test_lock
2211 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2212 @table @asis
2213 @item @emph{Description}:
2214 Before setting a simple lock, the lock variable must be initialized by 
2215 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
2216 does not block if the lock is not available.  This function returns
2217 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
2218 @code{false} represent their language-specific counterparts.
2220 @item @emph{C/C++}:
2221 @multitable @columnfractions .20 .80
2222 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2223 @end multitable
2225 @item @emph{Fortran}:
2226 @multitable @columnfractions .20 .80
2227 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2228 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2229 @end multitable
2231 @item @emph{See also}:
2232 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2234 @item @emph{Reference}: 
2235 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2236 @end table
2240 @node omp_test_nest_lock
2241 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2242 @table @asis
2243 @item @emph{Description}:
2244 Before setting a nested lock, the lock variable must be initialized by 
2245 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
2246 @code{omp_test_nest_lock} does not block if the lock is not available. 
2247 If the lock is already held by the current thread, the new nesting count 
2248 is returned.  Otherwise, the return value equals zero.
2250 @item @emph{C/C++}:
2251 @multitable @columnfractions .20 .80
2252 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2253 @end multitable
2255 @item @emph{Fortran}:
2256 @multitable @columnfractions .20 .80
2257 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2258 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2259 @end multitable
2262 @item @emph{See also}:
2263 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2265 @item @emph{Reference}: 
2266 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2267 @end table
2271 @node Timing Routines
2272 @section Timing Routines
2274 Portable, thread-based, wall clock timer.
2275 The routines have C linkage and do not throw exceptions.
2277 @menu
2278 * omp_get_wtick::            Get timer precision.
2279 * omp_get_wtime::            Elapsed wall clock time.
2280 @end menu
2284 @node omp_get_wtick
2285 @subsection @code{omp_get_wtick} -- Get timer precision
2286 @table @asis
2287 @item @emph{Description}:
2288 Gets the timer precision, i.e., the number of seconds between two 
2289 successive clock ticks.
2291 @item @emph{C/C++}:
2292 @multitable @columnfractions .20 .80
2293 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2294 @end multitable
2296 @item @emph{Fortran}:
2297 @multitable @columnfractions .20 .80
2298 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2299 @end multitable
2301 @item @emph{See also}:
2302 @ref{omp_get_wtime}
2304 @item @emph{Reference}: 
2305 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2306 @end table
2310 @node omp_get_wtime
2311 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2312 @table @asis
2313 @item @emph{Description}:
2314 Elapsed wall clock time in seconds.  The time is measured per thread, no
2315 guarantee can be made that two distinct threads measure the same time.
2316 Time is measured from some "time in the past", which is an arbitrary time
2317 guaranteed not to change during the execution of the program.
2319 @item @emph{C/C++}:
2320 @multitable @columnfractions .20 .80
2321 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2322 @end multitable
2324 @item @emph{Fortran}:
2325 @multitable @columnfractions .20 .80
2326 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2327 @end multitable
2329 @item @emph{See also}:
2330 @ref{omp_get_wtick}
2332 @item @emph{Reference}: 
2333 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2334 @end table
2338 @node Event Routine
2339 @section Event Routine
2341 Support for event objects.
2342 The routine has C linkage and do not throw exceptions.
2344 @menu
2345 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
2346 @end menu
2350 @node omp_fulfill_event
2351 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2352 @table @asis
2353 @item @emph{Description}:
2354 Fulfill the event associated with the event handle argument.  Currently, it
2355 is only used to fulfill events generated by detach clauses on task
2356 constructs - the effect of fulfilling the event is to allow the task to
2357 complete.
2359 The result of calling @code{omp_fulfill_event} with an event handle other
2360 than that generated by a detach clause is undefined.  Calling it with an
2361 event handle that has already been fulfilled is also undefined.
2363 @item @emph{C/C++}:
2364 @multitable @columnfractions .20 .80
2365 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2366 @end multitable
2368 @item @emph{Fortran}:
2369 @multitable @columnfractions .20 .80
2370 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2371 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
2372 @end multitable
2374 @item @emph{Reference}:
2375 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2376 @end table
2380 @c @node Interoperability Routines
2381 @c @section Interoperability Routines
2383 @c Routines to obtain properties from an @code{omp_interop_t} object.
2384 @c They have C linkage and do not throw exceptions.
2386 @c @menu
2387 @c * omp_get_num_interop_properties:: <fixme>
2388 @c * omp_get_interop_int:: <fixme>
2389 @c * omp_get_interop_ptr:: <fixme>
2390 @c * omp_get_interop_str:: <fixme>
2391 @c * omp_get_interop_name:: <fixme>
2392 @c * omp_get_interop_type_desc:: <fixme>
2393 @c * omp_get_interop_rc_desc:: <fixme>
2394 @c @end menu
2396 @node Memory Management Routines
2397 @section Memory Management Routines
2399 Routines to manage and allocate memory on the current device.
2400 They have C linkage and do not throw exceptions.
2402 @menu
2403 * omp_init_allocator:: Create an allocator
2404 * omp_destroy_allocator:: Destroy an allocator
2405 * omp_set_default_allocator:: Set the default allocator
2406 * omp_get_default_allocator:: Get the default allocator
2407 * omp_alloc:: Memory allocation with an allocator
2408 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
2409 * omp_free:: Freeing memory allocated with OpenMP routines
2410 * omp_calloc:: Allocate nullified memory with an allocator
2411 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
2412 * omp_realloc:: Reallocate memory allocated with OpenMP routines
2413 @c * omp_get_memspace_num_resources:: <fixme>/TR11
2414 @c * omp_get_submemspace:: <fixme>/TR11
2415 @end menu
2419 @node omp_init_allocator
2420 @subsection @code{omp_init_allocator} -- Create an allocator
2421 @table @asis
2422 @item @emph{Description}:
2423 Create an allocator that uses the specified memory space and has the specified
2424 traits; if an allocator that fulfills the requirements cannot be created,
2425 @code{omp_null_allocator} is returned.
2427 The predefined memory spaces and available traits can be found at
2428 @ref{OMP_ALLOCATOR}, where the trait names have to be be prefixed by
2429 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
2430 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
2431 may be used as trait value to specify that the default value should be used.
2433 @item @emph{C/C++}:
2434 @multitable @columnfractions .20 .80
2435 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
2436 @item                   @tab @code{  omp_memspace_handle_t memspace,}
2437 @item                   @tab @code{  int ntraits,}
2438 @item                   @tab @code{  const omp_alloctrait_t traits[]);}
2439 @end multitable
2441 @item @emph{Fortran}:
2442 @multitable @columnfractions .20 .80
2443 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
2444 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
2445 @item                   @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
2446 @item                   @tab @code{integer, intent(in) :: ntraits}
2447 @item                   @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
2448 @end multitable
2450 @item @emph{See also}:
2451 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
2453 @item @emph{Reference}:
2454 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
2455 @end table
2459 @node omp_destroy_allocator
2460 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
2461 @table @asis
2462 @item @emph{Description}:
2463 Releases all resources used by a memory allocator, which must not represent
2464 a predefined memory allocator.  Accessing memory after its allocator has been
2465 destroyed has unspecified behavior.  Passing @code{omp_null_allocator} to the
2466 routine is permitted but has no effect.
2469 @item @emph{C/C++}:
2470 @multitable @columnfractions .20 .80
2471 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
2472 @end multitable
2474 @item @emph{Fortran}:
2475 @multitable @columnfractions .20 .80
2476 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
2477 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2478 @end multitable
2480 @item @emph{See also}:
2481 @ref{omp_init_allocator}
2483 @item @emph{Reference}:
2484 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
2485 @end table
2489 @node omp_set_default_allocator
2490 @subsection @code{omp_set_default_allocator} -- Set the default allocator
2491 @table @asis
2492 @item @emph{Description}:
2493 Sets the default allocator that is used when no allocator has been specified
2494 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2495 routine is invoked with the @code{omp_null_allocator} allocator.
2497 @item @emph{C/C++}:
2498 @multitable @columnfractions .20 .80
2499 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
2500 @end multitable
2502 @item @emph{Fortran}:
2503 @multitable @columnfractions .20 .80
2504 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
2505 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
2506 @end multitable
2508 @item @emph{See also}:
2509 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
2510 @ref{Memory allocation}
2512 @item @emph{Reference}:
2513 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
2514 @end table
2518 @node omp_get_default_allocator
2519 @subsection @code{omp_get_default_allocator} -- Get the default allocator
2520 @table @asis
2521 @item @emph{Description}:
2522 The routine returns the default allocator that is used when no allocator has
2523 been specified in the @code{allocate} or @code{allocator} clause or if an
2524 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
2526 @item @emph{C/C++}:
2527 @multitable @columnfractions .20 .80
2528 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
2529 @end multitable
2531 @item @emph{Fortran}:
2532 @multitable @columnfractions .20 .80
2533 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
2534 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
2535 @end multitable
2537 @item @emph{See also}:
2538 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
2540 @item @emph{Reference}:
2541 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
2542 @end table
2546 @node omp_alloc
2547 @subsection @code{omp_alloc} -- Memory allocation with an allocator
2548 @table @asis
2549 @item @emph{Description}:
2550 Allocate memory with the specified allocator, which can either be a predefined
2551 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2552 is @code{omp_null_allocator}, the allocator specified by the
2553 @var{def-allocator-var} ICV is used.  @var{size} must be a nonnegative number
2554 denoting the number of bytes to be allocated; if @var{size} is zero,
2555 @code{omp_alloc} will return a null pointer.  If successful, a pointer to the
2556 allocated memory is returned, otherwise the @code{fallback} trait of the
2557 allocator determines the behavior.  The content of the allocated memory is
2558 unspecified.
2560 In @code{target} regions, either the @code{dynamic_allocators} clause must
2561 appear on a @code{requires} directive in the same compilation unit -- or the
2562 @var{allocator} argument may only be a constant expression with the value of
2563 one of the predefined allocators and may not be @code{omp_null_allocator}.
2565 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
2567 @item @emph{C}:
2568 @multitable @columnfractions .20 .80
2569 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2570 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2571 @end multitable
2573 @item @emph{C++}:
2574 @multitable @columnfractions .20 .80
2575 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
2576 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2577 @end multitable
2579 @item @emph{Fortran}:
2580 @multitable @columnfractions .20 .80
2581 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
2582 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2583 @item                   @tab @code{integer (c_size_t), value :: size}
2584 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2585 @end multitable
2587 @item @emph{See also}:
2588 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2589 @ref{omp_free}, @ref{omp_init_allocator}
2591 @item @emph{Reference}:
2592 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
2593 @end table
2597 @node omp_aligned_alloc
2598 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
2599 @table @asis
2600 @item @emph{Description}:
2601 Allocate memory with the specified allocator, which can either be a predefined
2602 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
2603 is @code{omp_null_allocator}, the allocator specified by the
2604 @var{def-allocator-var} ICV is used.  @var{alignment} must be a positive power
2605 of two and @var{size} must be a nonnegative number that is a multiple of the
2606 alignment and denotes the number of bytes to be allocated; if @var{size} is
2607 zero, @code{omp_aligned_alloc} will return a null pointer.  The alignment will
2608 be at least the maximal value required by @code{alignment} trait of the
2609 allocator and the value of the  passed @var{alignment} argument.  If successful,
2610 a pointer to the allocated memory is returned, otherwise the @code{fallback}
2611 trait of the allocator determines the behavior.  The content of the allocated
2612 memory is unspecified.
2614 In @code{target} regions, either the @code{dynamic_allocators} clause must
2615 appear on a @code{requires} directive in the same compilation unit -- or the
2616 @var{allocator} argument may only be a constant expression with the value of
2617 one of the predefined allocators and may not be @code{omp_null_allocator}.
2619 Memory allocated by @code{omp_aligned_alloc} must be freed using
2620 @code{omp_free}.
2622 @item @emph{C}:
2623 @multitable @columnfractions .20 .80
2624 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
2625 @item                   @tab @code{  size_t size,}
2626 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2627 @end multitable
2629 @item @emph{C++}:
2630 @multitable @columnfractions .20 .80
2631 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
2632 @item                   @tab @code{  size_t size,}
2633 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2634 @end multitable
2636 @item @emph{Fortran}:
2637 @multitable @columnfractions .20 .80
2638 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
2639 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2640 @item                   @tab @code{integer (c_size_t), value :: alignment, size}
2641 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2642 @end multitable
2644 @item @emph{See also}:
2645 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2646 @ref{omp_free}, @ref{omp_init_allocator}
2648 @item @emph{Reference}:
2649 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
2650 @end table
2654 @node omp_free
2655 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
2656 @table @asis
2657 @item @emph{Description}:
2658 The @code{omp_free} routine deallocates memory previously allocated by an
2659 OpenMP memory-management routine. The @var{ptr} argument must point to such
2660 memory or be a null pointer; if it is a null pointer, no operation is
2661 performed.  If specified, the @var{allocator} argument must be either the
2662 memory allocator that was used for the allocation or @code{omp_null_allocator};
2663 if it is @code{omp_null_allocator}, the implementation will determine the value
2664 automatically.
2666 Calling @code{omp_free} invokes undefined behavior if the memory
2667 was already deallocated or when the used allocator has already been destroyed.
2669 @item @emph{C}:
2670 @multitable @columnfractions .20 .80
2671 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
2672 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2673 @end multitable
2675 @item @emph{C++}:
2676 @multitable @columnfractions .20 .80
2677 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
2678 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2679 @end multitable
2681 @item @emph{Fortran}:
2682 @multitable @columnfractions .20 .80
2683 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
2684 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
2685 @item                   @tab @code{type (c_ptr), value :: ptr}
2686 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2687 @end multitable
2689 @item @emph{See also}:
2690 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
2691 @ref{omp_aligned_calloc}, @ref{omp_realloc}
2693 @item @emph{Reference}:
2694 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
2695 @end table
2699 @node omp_calloc
2700 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
2701 @table @asis
2702 @item @emph{Description}:
2703 Allocate zero-initialized memory with the specified allocator, which can either
2704 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
2705 the allocators is @code{omp_null_allocator}, the allocator specified by the
2706 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
2707 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
2708 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
2709 zero, @code{omp_calloc} will return a null pointer.  If successful, a pointer to
2710 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
2711 trait of the allocator determines the behavior.
2713 In @code{target} regions, either the @code{dynamic_allocators} clause must
2714 appear on a @code{requires} directive in the same compilation unit -- or the
2715 @var{allocator} argument may only be a constant expression with the value of
2716 one of the predefined allocators and may not be @code{omp_null_allocator}.
2718 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
2720 @item @emph{C}:
2721 @multitable @columnfractions .20 .80
2722 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
2723 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2724 @end multitable
2726 @item @emph{C++}:
2727 @multitable @columnfractions .20 .80
2728 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
2729 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2730 @end multitable
2732 @item @emph{Fortran}:
2733 @multitable @columnfractions .20 .80
2734 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
2735 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2736 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
2737 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2738 @end multitable
2740 @item @emph{See also}:
2741 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2742 @ref{omp_free}, @ref{omp_init_allocator}
2744 @item @emph{Reference}:
2745 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
2746 @end table
2750 @node omp_aligned_calloc
2751 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
2752 @table @asis
2753 @item @emph{Description}:
2754 Allocate zero-initialized memory with the specified allocator, which can either
2755 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
2756 the allocators is @code{omp_null_allocator}, the allocator specified by the
2757 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
2758 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
2759 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
2760 zero, @code{omp_aligned_calloc} will return a null pointer.  @var{alignment}
2761 must be a positive power of two and @var{size} must be a multiple of the
2762 alignment; the alignment will be at least the maximal value required by
2763 @code{alignment} trait of the allocator and the value of the  passed
2764 @var{alignment} argument.  If successful, a pointer to the zero-initialized
2765 allocated memory is returned, otherwise the @code{fallback} trait of the
2766 allocator determines the behavior.
2768 In @code{target} regions, either the @code{dynamic_allocators} clause must
2769 appear on a @code{requires} directive in the same compilation unit -- or the
2770 @var{allocator} argument may only be a constant expression with the value of
2771 one of the predefined allocators and may not be @code{omp_null_allocator}.
2773 Memory allocated by @code{omp_aligned_calloc} must be freed using
2774 @code{omp_free}.
2776 @item @emph{C}:
2777 @multitable @columnfractions .20 .80
2778 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
2779 @item                   @tab @code{  omp_allocator_handle_t allocator)}
2780 @end multitable
2782 @item @emph{C++}:
2783 @multitable @columnfractions .20 .80
2784 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
2785 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
2786 @end multitable
2788 @item @emph{Fortran}:
2789 @multitable @columnfractions .20 .80
2790 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
2791 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2792 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
2793 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
2794 @end multitable
2796 @item @emph{See also}:
2797 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2798 @ref{omp_free}, @ref{omp_init_allocator}
2800 @item @emph{Reference}:
2801 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
2802 @end table
2806 @node omp_realloc
2807 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
2808 @table @asis
2809 @item @emph{Description}:
2810 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
2811 and allocates new memory with the specified @var{allocator} argument; the
2812 new memory will have the content of the old memory up to the minimum of the
2813 old size and the new @var{size}, otherwise the content of the returned memory
2814 is unspecified.  If the new allocator is the same as the old one, the routine
2815 tries to resize the existing memory allocation, returning the same address as
2816 @var{ptr} if successful.  @var{ptr} must point to memory allocated by an OpenMP
2817 memory-management routine.
2819 The @var{allocator} and @var{free_allocator} arguments must be a predefined
2820 allocator, an allocator handle or @code{omp_null_allocator}.  If
2821 @var{free_allocator} is @code{omp_null_allocator}, the implementation
2822 automatically determines the allocator used for the allocation of @var{ptr}.
2823 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is is not a
2824 null pointer, the same allocator as @code{free_allocator} is used and
2825 when @var{ptr} is a null pointer the allocator specified by the
2826 @var{def-allocator-var} ICV is used.
2828 The @var{size} must be a nonnegative number denoting the number of bytes to be
2829 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
2830 memory and return a null pointer.  When @var{size} is nonzero: if successful,
2831 a pointer to the allocated memory is returned, otherwise the @code{fallback}
2832 trait of the allocator determines the behavior.
2834 In @code{target} regions, either the @code{dynamic_allocators} clause must
2835 appear on a @code{requires} directive in the same compilation unit -- or the
2836 @var{free_allocator} and @var{allocator} arguments may only be a constant
2837 expression with the value of one of the predefined allocators and may not be
2838 @code{omp_null_allocator}.
2840 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
2841 Calling @code{omp_free} invokes undefined behavior if the memory
2842 was already deallocated or when the used allocator has already been destroyed.
2844 @item @emph{C}:
2845 @multitable @columnfractions .20 .80
2846 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
2847 @item                   @tab @code{  omp_allocator_handle_t allocator,}
2848 @item                   @tab @code{  omp_allocator_handle_t free_allocator)}
2849 @end multitable
2851 @item @emph{C++}:
2852 @multitable @columnfractions .20 .80
2853 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
2854 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator,}
2855 @item                   @tab @code{  omp_allocator_handle_t free_allocator=omp_null_allocator)}
2856 @end multitable
2858 @item @emph{Fortran}:
2859 @multitable @columnfractions .20 .80
2860 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
2861 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
2862 @item                   @tab @code{type(C_ptr), value :: ptr}
2863 @item                   @tab @code{integer (c_size_t), value :: size}
2864 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
2865 @end multitable
2867 @item @emph{See also}:
2868 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
2869 @ref{omp_free}, @ref{omp_init_allocator}
2871 @item @emph{Reference}:
2872 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
2873 @end table
2877 @c @node Tool Control Routine
2879 @c FIXME
2881 @c @node Environment Display Routine
2882 @c @section Environment Display Routine
2884 @c Routine to display the OpenMP number and the initial value of ICVs.
2885 @c It has C linkage and do not throw exceptions.
2887 @c menu
2888 @c * omp_display_env:: <fixme>
2889 @c end menu
2891 @c ---------------------------------------------------------------------
2892 @c OpenMP Environment Variables
2893 @c ---------------------------------------------------------------------
2895 @node Environment Variables
2896 @chapter OpenMP Environment Variables
2898 The environment variables which beginning with @env{OMP_} are defined by
2899 section 4 of the OpenMP specification in version 4.5 or in a later version
2900 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
2901 Most @env{OMP_} environment variables have an associated internal control
2902 variable (ICV).
2904 For any OpenMP environment variable that sets an ICV and is neither
2905 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
2906 device-specific environment variables exist.  For them, the environment
2907 variable without suffix affects the host.  The suffix @code{_DEV_} followed
2908 by a non-negative device number less that the number of available devices sets
2909 the ICV for the corresponding device.  The suffix @code{_DEV} sets the ICV
2910 of all non-host devices for which a device-specific corresponding environment
2911 variable has not been set while the @code{_ALL} suffix sets the ICV of all
2912 host and non-host devices for which a more specific corresponding environment
2913 variable is not set.
2915 @menu
2916 * OMP_ALLOCATOR::           Set the default allocator
2917 * OMP_AFFINITY_FORMAT::     Set the format string used for affinity display
2918 * OMP_CANCELLATION::        Set whether cancellation is activated
2919 * OMP_DISPLAY_AFFINITY::    Display thread affinity information
2920 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
2921 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
2922 * OMP_DYNAMIC::             Dynamic adjustment of threads
2923 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
2924 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
2925 * OMP_NESTED::              Nested parallel regions
2926 * OMP_NUM_TEAMS::           Specifies the number of teams to use by teams region
2927 * OMP_NUM_THREADS::         Specifies the number of threads to use
2928 * OMP_PROC_BIND::           Whether threads may be moved between CPUs
2929 * OMP_PLACES::              Specifies on which CPUs the threads should be placed
2930 * OMP_STACKSIZE::           Set default thread stack size
2931 * OMP_SCHEDULE::            How threads are scheduled
2932 * OMP_TARGET_OFFLOAD::      Controls offloading behavior
2933 * OMP_TEAMS_THREAD_LIMIT::  Set the maximum number of threads imposed by teams
2934 * OMP_THREAD_LIMIT::        Set the maximum number of threads
2935 * OMP_WAIT_POLICY::         How waiting threads are handled
2936 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
2937 * GOMP_DEBUG::              Enable debugging output
2938 * GOMP_STACKSIZE::          Set default thread stack size
2939 * GOMP_SPINCOUNT::          Set the busy-wait spin count
2940 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
2941 @end menu
2944 @node OMP_ALLOCATOR
2945 @section @env{OMP_ALLOCATOR} -- Set the default allocator
2946 @cindex Environment Variable
2947 @table @asis
2948 @item @emph{ICV:} @var{def-allocator-var}
2949 @item @emph{Scope:} data environment
2950 @item @emph{Description}:
2951 Sets the default allocator that is used when no allocator has been specified
2952 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2953 routine is invoked with the @code{omp_null_allocator} allocator.
2954 If unset, @code{omp_default_mem_alloc} is used.
2956 The value can either be a predefined allocator or a predefined memory space
2957 or a predefined memory space followed by a colon and a comma-separated list
2958 of memory trait and value pairs, separated by @code{=}.
2960 Note: The corresponding device environment variables are currently not
2961 supported.  Therefore, the non-host @var{def-allocator-var} ICVs are always
2962 initialized to @code{omp_default_mem_alloc}.  However, on all devices,
2963 the @code{omp_set_default_allocator} API routine can be used to change
2964 value.
2966 @multitable @columnfractions .45 .45
2967 @headitem Predefined allocators @tab Associated predefined memory spaces
2968 @item omp_default_mem_alloc     @tab omp_default_mem_space
2969 @item omp_large_cap_mem_alloc   @tab omp_large_cap_mem_space
2970 @item omp_const_mem_alloc       @tab omp_const_mem_space
2971 @item omp_high_bw_mem_alloc     @tab omp_high_bw_mem_space
2972 @item omp_low_lat_mem_alloc     @tab omp_low_lat_mem_space
2973 @item omp_cgroup_mem_alloc      @tab --
2974 @item omp_pteam_mem_alloc       @tab --
2975 @item omp_thread_mem_alloc      @tab --
2976 @end multitable
2978 The predefined allocators use the default values for the traits,
2979 as listed below.  Except that the last three allocators have the
2980 @code{access} trait set to @code{cgroup}, @code{pteam}, and
2981 @code{thread}, respectively.
2983 @multitable @columnfractions .25 .40 .25
2984 @headitem Trait @tab Allowed values @tab Default value
2985 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
2986                             @code{serialized}, @code{private}
2987                        @tab @code{contended}
2988 @item @code{alignment} @tab Positive integer being a power of two
2989                        @tab 1 byte
2990 @item @code{access}    @tab @code{all}, @code{cgroup},
2991                             @code{pteam}, @code{thread}
2992                        @tab @code{all}
2993 @item @code{pool_size} @tab Positive integer
2994                        @tab See @ref{Memory allocation}
2995 @item @code{fallback}  @tab @code{default_mem_fb}, @code{null_fb},
2996                             @code{abort_fb}, @code{allocator_fb}
2997                        @tab See below
2998 @item @code{fb_data}   @tab @emph{unsupported as it needs an allocator handle}
2999                        @tab (none)
3000 @item @code{pinned}    @tab @code{true}, @code{false}
3001                        @tab @code{false}
3002 @item @code{partition} @tab @code{environment}, @code{nearest},
3003                             @code{blocked}, @code{interleaved}
3004                        @tab @code{environment}
3005 @end multitable
3007 For the @code{fallback} trait, the default value is @code{null_fb} for the
3008 @code{omp_default_mem_alloc} allocator and any allocator that is associated
3009 with device memory; for all other other allocators, it is @code{default_mem_fb}
3010 by default.
3012 Examples:
3013 @smallexample
3014 OMP_ALLOCATOR=omp_high_bw_mem_alloc
3015 OMP_ALLOCATOR=omp_large_cap_mem_space
3016 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
3017 @end smallexample
3019 @item @emph{See also}:
3020 @ref{Memory allocation}, @ref{omp_get_default_allocator},
3021 @ref{omp_set_default_allocator}
3023 @item @emph{Reference}:
3024 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
3025 @end table
3029 @node OMP_AFFINITY_FORMAT
3030 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
3031 @cindex Environment Variable
3032 @table @asis
3033 @item @emph{ICV:} @var{affinity-format-var}
3034 @item @emph{Scope:} device
3035 @item @emph{Description}:
3036 Sets the format string used when displaying OpenMP thread affinity information.
3037 Special values are output using @code{%} followed by an optional size
3038 specification and then either the single-character field type or its long
3039 name enclosed in curly braces; using @code{%%} displays a literal percent.
3040 The size specification consists of an optional @code{0.} or @code{.} followed
3041 by a positive integer, specifying the minimal width of the output.  With
3042 @code{0.} and numerical values, the output is padded with zeros on the left;
3043 with @code{.}, the output is padded by spaces on the left; otherwise, the
3044 output is padded by spaces on the right.  If unset, the value is
3045 ``@code{level %L thread %i affinity %A}''.
3047 Supported field types are:
3049 @multitable @columnfractions .10 .25 .60
3050 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
3051 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
3052 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
3053 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
3054 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
3055 @item a @tab ancestor_tnum
3056       @tab value returned by
3057            @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
3058 @item H @tab host @tab name of the host that executes the thread
3059 @item P @tab process_id @tab process identifier
3060 @item i @tab native_thread_id @tab native thread identifier
3061 @item A @tab thread_affinity
3062       @tab comma separated list of integer values or ranges, representing the
3063            processors on which a process might execute, subject to affinity
3064            mechanisms
3065 @end multitable
3067 For instance, after setting
3069 @smallexample
3070 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
3071 @end smallexample
3073 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
3074 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
3075 might display the following:
3077 @smallexample
3078 00!0!   1!4; 0;01;0;1;0-11
3079 00!3!   1!4; 0;01;0;1;0-11
3080 00!2!   1!4; 0;01;0;1;0-11
3081 00!1!   1!4; 0;01;0;1;0-11
3082 @end smallexample
3084 @item @emph{See also}:
3085 @ref{OMP_DISPLAY_AFFINITY}
3087 @item @emph{Reference}:
3088 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
3089 @end table
3093 @node OMP_CANCELLATION
3094 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
3095 @cindex Environment Variable
3096 @table @asis
3097 @item @emph{ICV:} @var{cancel-var}
3098 @item @emph{Scope:} global
3099 @item @emph{Description}:
3100 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
3101 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
3103 @item @emph{See also}:
3104 @ref{omp_get_cancellation}
3106 @item @emph{Reference}:
3107 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
3108 @end table
3112 @node OMP_DISPLAY_AFFINITY
3113 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
3114 @cindex Environment Variable
3115 @table @asis
3116 @item @emph{ICV:} @var{display-affinity-var}
3117 @item @emph{Scope:} global
3118 @item @emph{Description}:
3119 If set to @code{FALSE} or if unset, affinity displaying is disabled.
3120 If set to @code{TRUE}, the runtime displays affinity information about
3121 OpenMP threads in a parallel region upon entering the region and every time
3122 any change occurs.
3124 @item @emph{See also}:
3125 @ref{OMP_AFFINITY_FORMAT}
3127 @item @emph{Reference}:
3128 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
3129 @end table
3134 @node OMP_DISPLAY_ENV
3135 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
3136 @cindex Environment Variable
3137 @table @asis
3138 @item @emph{ICV:} none
3139 @item @emph{Scope:} not applicable
3140 @item @emph{Description}:
3141 If set to @code{TRUE}, the OpenMP version number and the values
3142 associated with the OpenMP environment variables are printed to @code{stderr}.
3143 If set to @code{VERBOSE}, it additionally shows the value of the environment
3144 variables which are GNU extensions.  If undefined or set to @code{FALSE},
3145 this information is not shown.
3148 @item @emph{Reference}:
3149 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
3150 @end table
3154 @node OMP_DEFAULT_DEVICE
3155 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
3156 @cindex Environment Variable
3157 @table @asis
3158 @item @emph{ICV:} @var{default-device-var}
3159 @item @emph{Scope:} data environment
3160 @item @emph{Description}:
3161 Set to choose the device which is used in a @code{target} region, unless the
3162 value is overridden by @code{omp_set_default_device} or by a @code{device}
3163 clause.  The value shall be the nonnegative device number. If no device with
3164 the given device number exists, the code is executed on the host.  If unset,
3165 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
3166 available, it is set to @code{omp_invalid_device}.  Otherwise, if unset,
3167 device number 0 is used.
3170 @item @emph{See also}:
3171 @ref{omp_get_default_device}, @ref{omp_set_default_device},
3172 @ref{OMP_TARGET_OFFLOAD}
3174 @item @emph{Reference}:
3175 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
3176 @end table
3180 @node OMP_DYNAMIC
3181 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
3182 @cindex Environment Variable
3183 @table @asis
3184 @item @emph{ICV:} @var{dyn-var}
3185 @item @emph{Scope:} global
3186 @item @emph{Description}:
3187 Enable or disable the dynamic adjustment of the number of threads 
3188 within a team.  The value of this environment variable shall be 
3189 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
3190 disabled by default.
3192 @item @emph{See also}:
3193 @ref{omp_set_dynamic}
3195 @item @emph{Reference}: 
3196 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
3197 @end table
3201 @node OMP_MAX_ACTIVE_LEVELS
3202 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
3203 @cindex Environment Variable
3204 @table @asis
3205 @item @emph{ICV:} @var{max-active-levels-var}
3206 @item @emph{Scope:} data environment
3207 @item @emph{Description}:
3208 Specifies the initial value for the maximum number of nested parallel
3209 regions.  The value of this variable shall be a positive integer.
3210 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
3211 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
3212 a list with more than one item, the maximum number of nested parallel
3213 regions is initialized to the largest number supported, otherwise
3214 it is set to one.
3216 @item @emph{See also}:
3217 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
3218 @ref{OMP_NUM_THREADS}
3221 @item @emph{Reference}: 
3222 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
3223 @end table
3227 @node OMP_MAX_TASK_PRIORITY
3228 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
3229 number that can be set for a task.
3230 @cindex Environment Variable
3231 @table @asis
3232 @item @emph{ICV:} @var{max-task-priority-var}
3233 @item @emph{Scope:} global
3234 @item @emph{Description}:
3235 Specifies the initial value for the maximum priority value that can be
3236 set for a task.  The value of this variable shall be a non-negative
3237 integer, and zero is allowed.  If undefined, the default priority is
3240 @item @emph{See also}:
3241 @ref{omp_get_max_task_priority}
3243 @item @emph{Reference}: 
3244 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
3245 @end table
3249 @node OMP_NESTED
3250 @section @env{OMP_NESTED} -- Nested parallel regions
3251 @cindex Environment Variable
3252 @cindex Implementation specific setting
3253 @table @asis
3254 @item @emph{ICV:} @var{max-active-levels-var}
3255 @item @emph{Scope:} data environment
3256 @item @emph{Description}:
3257 Enable or disable nested parallel regions, i.e., whether team members
3258 are allowed to create new teams.  The value of this environment variable 
3259 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
3260 of maximum active nested regions supported is by default set to the
3261 maximum supported, otherwise it is set to one.  If
3262 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
3263 setting.  If both are undefined, nested parallel regions are enabled if
3264 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
3265 more than one item, otherwise they are disabled by default.
3267 Note that the @code{OMP_NESTED} environment variable was deprecated in
3268 the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
3270 @item @emph{See also}:
3271 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
3272 @ref{OMP_MAX_ACTIVE_LEVELS}
3274 @item @emph{Reference}: 
3275 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
3276 @end table
3280 @node OMP_NUM_TEAMS
3281 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
3282 @cindex Environment Variable
3283 @table @asis
3284 @item @emph{ICV:} @var{nteams-var}
3285 @item @emph{Scope:} device
3286 @item @emph{Description}:
3287 Specifies the upper bound for number of teams to use in teams regions
3288 without explicit @code{num_teams} clause.  The value of this variable shall
3289 be a positive integer.  If undefined it defaults to 0 which means
3290 implementation defined upper bound.
3292 @item @emph{See also}:
3293 @ref{omp_set_num_teams}
3295 @item @emph{Reference}: 
3296 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
3297 @end table
3301 @node OMP_NUM_THREADS
3302 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
3303 @cindex Environment Variable
3304 @cindex Implementation specific setting
3305 @table @asis
3306 @item @emph{ICV:} @var{nthreads-var}
3307 @item @emph{Scope:} data environment
3308 @item @emph{Description}:
3309 Specifies the default number of threads to use in parallel regions.  The 
3310 value of this variable shall be a comma-separated list of positive integers;
3311 the value specifies the number of threads to use for the corresponding nested
3312 level.  Specifying more than one item in the list automatically enables
3313 nesting by default.  If undefined one thread per CPU is used.
3315 When a list with more than value is specified, it also affects the
3316 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3318 @item @emph{See also}:
3319 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
3321 @item @emph{Reference}: 
3322 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
3323 @end table
3327 @node OMP_PROC_BIND
3328 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
3329 @cindex Environment Variable
3330 @table @asis
3331 @item @emph{ICV:} @var{bind-var}
3332 @item @emph{Scope:} data environment
3333 @item @emph{Description}:
3334 Specifies whether threads may be moved between processors.  If set to
3335 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
3336 they may be moved.  Alternatively, a comma separated list with the
3337 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
3338 be used to specify the thread affinity policy for the corresponding nesting
3339 level.  With @code{PRIMARY} and @code{MASTER} the worker threads are in the
3340 same place partition as the primary thread.  With @code{CLOSE} those are
3341 kept close to the primary thread in contiguous place partitions.  And
3342 with @code{SPREAD} a sparse distribution
3343 across the place partitions is used.  Specifying more than one item in the
3344 list automatically enables nesting by default.
3346 When a list is specified, it also affects the @var{max-active-levels-var} ICV
3347 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3349 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
3350 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
3352 @item @emph{See also}:
3353 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
3354 @ref{OMP_MAX_ACTIVE_LEVELS}
3356 @item @emph{Reference}:
3357 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
3358 @end table
3362 @node OMP_PLACES
3363 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
3364 @cindex Environment Variable
3365 @table @asis
3366 @item @emph{ICV:} @var{place-partition-var}
3367 @item @emph{Scope:} implicit tasks
3368 @item @emph{Description}:
3369 The thread placement can be either specified using an abstract name or by an
3370 explicit list of the places.  The abstract names @code{threads}, @code{cores},
3371 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
3372 followed by a positive number in parentheses, which denotes the how many places
3373 shall be created.  With @code{threads} each place corresponds to a single
3374 hardware thread; @code{cores} to a single core with the corresponding number of
3375 hardware threads; with @code{sockets} the place corresponds to a single
3376 socket; with @code{ll_caches} to a set of cores that shares the last level
3377 cache on the device; and @code{numa_domains} to a set of cores for which their
3378 closest memory on the device is the same memory and at a similar distance from
3379 the cores.  The resulting placement can be shown by setting the
3380 @env{OMP_DISPLAY_ENV} environment variable.
3382 Alternatively, the placement can be specified explicitly as comma-separated
3383 list of places.  A place is specified by set of nonnegative numbers in curly
3384 braces, denoting the hardware threads.  The curly braces can be omitted
3385 when only a single number has been specified.  The hardware threads
3386 belonging to a place can either be specified as comma-separated list of
3387 nonnegative thread numbers or using an interval.  Multiple places can also be
3388 either specified by a comma-separated list of places or by an interval.  To
3389 specify an interval, a colon followed by the count is placed after
3390 the hardware thread number or the place.  Optionally, the length can be
3391 followed by a colon and the stride number -- otherwise a unit stride is
3392 assumed.  Placing an exclamation mark (@code{!}) directly before a curly
3393 brace or numbers inside the curly braces (excluding intervals)
3394 excludes those hardware threads.
3396 For instance, the following specifies the same places list:
3397 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
3398 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
3400 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
3401 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
3402 between CPUs following no placement policy.
3404 @item @emph{See also}:
3405 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
3406 @ref{OMP_DISPLAY_ENV}
3408 @item @emph{Reference}:
3409 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
3410 @end table
3414 @node OMP_STACKSIZE
3415 @section @env{OMP_STACKSIZE} -- Set default thread stack size
3416 @cindex Environment Variable
3417 @table @asis
3418 @item @emph{ICV:} @var{stacksize-var}
3419 @item @emph{Scope:} device
3420 @item @emph{Description}:
3421 Set the default thread stack size in kilobytes, unless the number
3422 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
3423 case the size is, respectively, in bytes, kilobytes, megabytes
3424 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
3425 which gets the number of bytes as an argument.  If the stack size cannot
3426 be set due to system constraints, an error is reported and the initial
3427 stack size is left unchanged.  If undefined, the stack size is system
3428 dependent.
3430 @item @emph{See also}:
3431 @ref{GOMP_STACKSIZE}
3433 @item @emph{Reference}: 
3434 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
3435 @end table
3439 @node OMP_SCHEDULE
3440 @section @env{OMP_SCHEDULE} -- How threads are scheduled
3441 @cindex Environment Variable
3442 @cindex Implementation specific setting
3443 @table @asis
3444 @item @emph{ICV:} @var{run-sched-var}
3445 @item @emph{Scope:} data environment
3446 @item @emph{Description}:
3447 Allows to specify @code{schedule type} and @code{chunk size}. 
3448 The value of the variable shall have the form: @code{type[,chunk]} where
3449 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
3450 The optional @code{chunk} size shall be a positive integer.  If undefined,
3451 dynamic scheduling and a chunk size of 1 is used.
3453 @item @emph{See also}:
3454 @ref{omp_set_schedule}
3456 @item @emph{Reference}: 
3457 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
3458 @end table
3462 @node OMP_TARGET_OFFLOAD
3463 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
3464 @cindex Environment Variable
3465 @cindex Implementation specific setting
3466 @table @asis
3467 @item @emph{ICV:} @var{target-offload-var}
3468 @item @emph{Scope:} global
3469 @item @emph{Description}:
3470 Specifies the behavior with regard to offloading code to a device.  This
3471 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
3472 or @code{DEFAULT}.
3474 If set to @code{MANDATORY}, the program terminates with an error if
3475 any device construct or device memory routine uses a device that is unavailable
3476 or not supported by the implementation, or uses a non-conforming device number.
3477 If set to @code{DISABLED}, then offloading is disabled and all code runs on
3478 the host. If set to @code{DEFAULT}, the program tries offloading to the
3479 device first, then falls back to running code on the host if it cannot.
3481 If undefined, then the program behaves as if @code{DEFAULT} was set.
3483 Note: Even with @code{MANDATORY}, no run-time termination is performed when
3484 the device number in a @code{device} clause or argument to a device memory
3485 routine is for host, which includes using the device number in the
3486 @var{default-device-var} ICV.  However, the initial value of
3487 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
3489 @item @emph{See also}:
3490 @ref{OMP_DEFAULT_DEVICE}
3492 @item @emph{Reference}:
3493 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
3494 @end table
3498 @node OMP_TEAMS_THREAD_LIMIT
3499 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
3500 @cindex Environment Variable
3501 @table @asis
3502 @item @emph{ICV:} @var{teams-thread-limit-var}
3503 @item @emph{Scope:} device
3504 @item @emph{Description}:
3505 Specifies an upper bound for the number of threads to use by each contention
3506 group created by a teams construct without explicit @code{thread_limit}
3507 clause.  The value of this variable shall be a positive integer.  If undefined,
3508 the value of 0 is used which stands for an implementation defined upper
3509 limit.
3511 @item @emph{See also}:
3512 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
3514 @item @emph{Reference}: 
3515 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
3516 @end table
3520 @node OMP_THREAD_LIMIT
3521 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
3522 @cindex Environment Variable
3523 @table @asis
3524 @item @emph{ICV:} @var{thread-limit-var}
3525 @item @emph{Scope:} data environment
3526 @item @emph{Description}:
3527 Specifies the number of threads to use for the whole program.  The
3528 value of this variable shall be a positive integer.  If undefined,
3529 the number of threads is not limited.
3531 @item @emph{See also}:
3532 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
3534 @item @emph{Reference}: 
3535 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
3536 @end table
3540 @node OMP_WAIT_POLICY
3541 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
3542 @cindex Environment Variable
3543 @table @asis
3544 @item @emph{Description}:
3545 Specifies whether waiting threads should be active or passive.  If
3546 the value is @code{PASSIVE}, waiting threads should not consume CPU
3547 power while waiting; while the value is @code{ACTIVE} specifies that
3548 they should.  If undefined, threads wait actively for a short time
3549 before waiting passively.
3551 @item @emph{See also}:
3552 @ref{GOMP_SPINCOUNT}
3554 @item @emph{Reference}: 
3555 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
3556 @end table
3560 @node GOMP_CPU_AFFINITY
3561 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
3562 @cindex Environment Variable
3563 @table @asis
3564 @item @emph{Description}:
3565 Binds threads to specific CPUs.  The variable should contain a space-separated
3566 or comma-separated list of CPUs.  This list may contain different kinds of 
3567 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
3568 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
3569 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
3570 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
3571 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
3572 and 14 respectively and then starts assigning back from the beginning of
3573 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
3575 There is no libgomp library routine to determine whether a CPU affinity
3576 specification is in effect.  As a workaround, language-specific library 
3577 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
3578 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
3579 environment variable.  A defined CPU affinity on startup cannot be changed 
3580 or disabled during the runtime of the application.
3582 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
3583 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
3584 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
3585 @code{FALSE}, the host system handles the assignment of threads to CPUs.
3587 @item @emph{See also}:
3588 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
3589 @end table
3593 @node GOMP_DEBUG
3594 @section @env{GOMP_DEBUG} -- Enable debugging output
3595 @cindex Environment Variable
3596 @table @asis
3597 @item @emph{Description}:
3598 Enable debugging output.  The variable should be set to @code{0}
3599 (disabled, also the default if not set), or @code{1} (enabled).
3601 If enabled, some debugging output is printed during execution.
3602 This is currently not specified in more detail, and subject to change.
3603 @end table
3607 @node GOMP_STACKSIZE
3608 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
3609 @cindex Environment Variable
3610 @cindex Implementation specific setting
3611 @table @asis
3612 @item @emph{Description}:
3613 Set the default thread stack size in kilobytes.  This is different from
3614 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
3615 argument.  If the stack size cannot be set due to system constraints, an 
3616 error is reported and the initial stack size is left unchanged.  If undefined,
3617 the stack size is system dependent.
3619 @item @emph{See also}:
3620 @ref{OMP_STACKSIZE}
3622 @item @emph{Reference}: 
3623 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
3624 GCC Patches Mailinglist}, 
3625 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
3626 GCC Patches Mailinglist}
3627 @end table
3631 @node GOMP_SPINCOUNT
3632 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
3633 @cindex Environment Variable
3634 @cindex Implementation specific setting
3635 @table @asis
3636 @item @emph{Description}:
3637 Determines how long a threads waits actively with consuming CPU power
3638 before waiting passively without consuming CPU power.  The value may be
3639 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
3640 integer which gives the number of spins of the busy-wait loop.  The
3641 integer may optionally be followed by the following suffixes acting
3642 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
3643 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
3644 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
3645 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
3646 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
3647 If there are more OpenMP threads than available CPUs, 1000 and 100
3648 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
3649 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
3650 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
3652 @item @emph{See also}:
3653 @ref{OMP_WAIT_POLICY}
3654 @end table
3658 @node GOMP_RTEMS_THREAD_POOLS
3659 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
3660 @cindex Environment Variable
3661 @cindex Implementation specific setting
3662 @table @asis
3663 @item @emph{Description}:
3664 This environment variable is only used on the RTEMS real-time operating system.
3665 It determines the scheduler instance specific thread pools.  The format for
3666 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
3667 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
3668 separated by @code{:} where:
3669 @itemize @bullet
3670 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
3671 instance.
3672 @item @code{$<priority>} is an optional priority for the worker threads of a
3673 thread pool according to @code{pthread_setschedparam}.  In case a priority
3674 value is omitted, then a worker thread inherits the priority of the OpenMP
3675 primary thread that created it.  The priority of the worker thread is not
3676 changed after creation, even if a new OpenMP primary thread using the worker has
3677 a different priority.
3678 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
3679 RTEMS application configuration.
3680 @end itemize
3681 In case no thread pool configuration is specified for a scheduler instance,
3682 then each OpenMP primary thread of this scheduler instance uses its own
3683 dynamically allocated thread pool.  To limit the worker thread count of the
3684 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
3685 @item @emph{Example}:
3686 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
3687 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
3688 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
3689 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
3690 one thread pool available.  Since no priority is specified for this scheduler
3691 instance, the worker thread inherits the priority of the OpenMP primary thread
3692 that created it.  In the scheduler instance @code{WRK1} there are three thread
3693 pools available and their worker threads run at priority four.
3694 @end table
3698 @c ---------------------------------------------------------------------
3699 @c Enabling OpenACC
3700 @c ---------------------------------------------------------------------
3702 @node Enabling OpenACC
3703 @chapter Enabling OpenACC
3705 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
3706 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
3707 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
3708 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
3709 fixed source form.  The flag also arranges for automatic linking of the OpenACC
3710 runtime library (@ref{OpenACC Runtime Library Routines}).
3712 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
3714 A complete description of all OpenACC directives accepted may be found in 
3715 the @uref{https://www.openacc.org, OpenACC} Application Programming
3716 Interface manual, version 2.6.
3720 @c ---------------------------------------------------------------------
3721 @c OpenACC Runtime Library Routines
3722 @c ---------------------------------------------------------------------
3724 @node OpenACC Runtime Library Routines
3725 @chapter OpenACC Runtime Library Routines
3727 The runtime routines described here are defined by section 3 of the OpenACC
3728 specifications in version 2.6.
3729 They have C linkage, and do not throw exceptions.
3730 Generally, they are available only for the host, with the exception of
3731 @code{acc_on_device}, which is available for both the host and the
3732 acceleration device.
3734 @menu
3735 * acc_get_num_devices::         Get number of devices for the given device
3736                                 type.
3737 * acc_set_device_type::         Set type of device accelerator to use.
3738 * acc_get_device_type::         Get type of device accelerator to be used.
3739 * acc_set_device_num::          Set device number to use.
3740 * acc_get_device_num::          Get device number to be used.
3741 * acc_get_property::            Get device property.
3742 * acc_async_test::              Tests for completion of a specific asynchronous
3743                                 operation.
3744 * acc_async_test_all::          Tests for completion of all asynchronous
3745                                 operations.
3746 * acc_wait::                    Wait for completion of a specific asynchronous
3747                                 operation.
3748 * acc_wait_all::                Waits for completion of all asynchronous
3749                                 operations.
3750 * acc_wait_all_async::          Wait for completion of all asynchronous
3751                                 operations.
3752 * acc_wait_async::              Wait for completion of asynchronous operations.
3753 * acc_init::                    Initialize runtime for a specific device type.
3754 * acc_shutdown::                Shuts down the runtime for a specific device
3755                                 type.
3756 * acc_on_device::               Whether executing on a particular device
3757 * acc_malloc::                  Allocate device memory.
3758 * acc_free::                    Free device memory.
3759 * acc_copyin::                  Allocate device memory and copy host memory to
3760                                 it.
3761 * acc_present_or_copyin::       If the data is not present on the device,
3762                                 allocate device memory and copy from host
3763                                 memory.
3764 * acc_create::                  Allocate device memory and map it to host
3765                                 memory.
3766 * acc_present_or_create::       If the data is not present on the device,
3767                                 allocate device memory and map it to host
3768                                 memory.
3769 * acc_copyout::                 Copy device memory to host memory.
3770 * acc_delete::                  Free device memory.
3771 * acc_update_device::           Update device memory from mapped host memory.
3772 * acc_update_self::             Update host memory from mapped device memory.
3773 * acc_map_data::                Map previously allocated device memory to host
3774                                 memory.
3775 * acc_unmap_data::              Unmap device memory from host memory.
3776 * acc_deviceptr::               Get device pointer associated with specific
3777                                 host address.
3778 * acc_hostptr::                 Get host pointer associated with specific
3779                                 device address.
3780 * acc_is_present::              Indicate whether host variable / array is
3781                                 present on device.
3782 * acc_memcpy_to_device::        Copy host memory to device memory.
3783 * acc_memcpy_from_device::      Copy device memory to host memory.
3784 * acc_attach::                  Let device pointer point to device-pointer target.
3785 * acc_detach::                  Let device pointer point to host-pointer target.
3787 API routines for target platforms.
3789 * acc_get_current_cuda_device:: Get CUDA device handle.
3790 * acc_get_current_cuda_context::Get CUDA context handle.
3791 * acc_get_cuda_stream::         Get CUDA stream handle.
3792 * acc_set_cuda_stream::         Set CUDA stream handle.
3794 API routines for the OpenACC Profiling Interface.
3796 * acc_prof_register::           Register callbacks.
3797 * acc_prof_unregister::         Unregister callbacks.
3798 * acc_prof_lookup::             Obtain inquiry functions.
3799 * acc_register_library::        Library registration.
3800 @end menu
3804 @node acc_get_num_devices
3805 @section @code{acc_get_num_devices} -- Get number of devices for given device type
3806 @table @asis
3807 @item @emph{Description}
3808 This function returns a value indicating the number of devices available
3809 for the device type specified in @var{devicetype}. 
3811 @item @emph{C/C++}:
3812 @multitable @columnfractions .20 .80
3813 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
3814 @end multitable
3816 @item @emph{Fortran}:
3817 @multitable @columnfractions .20 .80
3818 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
3819 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
3820 @end multitable
3822 @item @emph{Reference}:
3823 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3824 3.2.1.
3825 @end table
3829 @node acc_set_device_type
3830 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
3831 @table @asis
3832 @item @emph{Description}
3833 This function indicates to the runtime library which device type, specified
3834 in @var{devicetype}, to use when executing a parallel or kernels region. 
3836 @item @emph{C/C++}:
3837 @multitable @columnfractions .20 .80
3838 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
3839 @end multitable
3841 @item @emph{Fortran}:
3842 @multitable @columnfractions .20 .80
3843 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
3844 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
3845 @end multitable
3847 @item @emph{Reference}:
3848 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3849 3.2.2.
3850 @end table
3854 @node acc_get_device_type
3855 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
3856 @table @asis
3857 @item @emph{Description}
3858 This function returns what device type will be used when executing a
3859 parallel or kernels region.
3861 This function returns @code{acc_device_none} if
3862 @code{acc_get_device_type} is called from
3863 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
3864 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
3865 Interface}), that is, if the device is currently being initialized.
3867 @item @emph{C/C++}:
3868 @multitable @columnfractions .20 .80
3869 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
3870 @end multitable
3872 @item @emph{Fortran}:
3873 @multitable @columnfractions .20 .80
3874 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
3875 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
3876 @end multitable
3878 @item @emph{Reference}:
3879 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3880 3.2.3.
3881 @end table
3885 @node acc_set_device_num
3886 @section @code{acc_set_device_num} -- Set device number to use.
3887 @table @asis
3888 @item @emph{Description}
3889 This function will indicate to the runtime which device number,
3890 specified by @var{devicenum}, associated with the specified device
3891 type @var{devicetype}.
3893 @item @emph{C/C++}:
3894 @multitable @columnfractions .20 .80
3895 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
3896 @end multitable
3898 @item @emph{Fortran}:
3899 @multitable @columnfractions .20 .80
3900 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
3901 @item                   @tab @code{integer devicenum}
3902 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
3903 @end multitable
3905 @item @emph{Reference}:
3906 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3907 3.2.4.
3908 @end table
3912 @node acc_get_device_num
3913 @section @code{acc_get_device_num} -- Get device number to be used.
3914 @table @asis
3915 @item @emph{Description}
3916 This function returns which device number associated with the specified device
3917 type @var{devicetype}, will be used when executing a parallel or kernels
3918 region.
3920 @item @emph{C/C++}:
3921 @multitable @columnfractions .20 .80
3922 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
3923 @end multitable
3925 @item @emph{Fortran}:
3926 @multitable @columnfractions .20 .80
3927 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
3928 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
3929 @item                   @tab @code{integer acc_get_device_num}
3930 @end multitable
3932 @item @emph{Reference}:
3933 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3934 3.2.5.
3935 @end table
3939 @node acc_get_property
3940 @section @code{acc_get_property} -- Get device property.
3941 @cindex acc_get_property
3942 @cindex acc_get_property_string
3943 @table @asis
3944 @item @emph{Description}
3945 These routines return the value of the specified @var{property} for the
3946 device being queried according to @var{devicenum} and @var{devicetype}.
3947 Integer-valued and string-valued properties are returned by
3948 @code{acc_get_property} and @code{acc_get_property_string} respectively.
3949 The Fortran @code{acc_get_property_string} subroutine returns the string
3950 retrieved in its fourth argument while the remaining entry points are
3951 functions, which pass the return value as their result.
3953 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
3954 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
3955 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
3956 for consistency and the return type of the @code{acc_get_property} function is
3957 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
3958 The parameter @code{acc_device_property} is still provided,
3959 but might be removed in a future version of GCC.
3961 @item @emph{C/C++}:
3962 @multitable @columnfractions .20 .80
3963 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
3964 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
3965 @end multitable
3967 @item @emph{Fortran}:
3968 @multitable @columnfractions .20 .80
3969 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
3970 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
3971 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
3972 @item                   @tab @code{integer devicenum}
3973 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
3974 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
3975 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
3976 @item                   @tab @code{character(*) string}
3977 @end multitable
3979 @item @emph{Reference}:
3980 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3981 3.2.6.
3982 @end table
3986 @node acc_async_test
3987 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
3988 @table @asis
3989 @item @emph{Description}
3990 This function tests for completion of the asynchronous operation specified
3991 in @var{arg}. In C/C++, a non-zero value is returned to indicate
3992 the specified asynchronous operation has completed while Fortran returns
3993 @code{true}. If the asynchronous operation has not completed, C/C++ returns
3994 zero and Fortran returns @code{false}.
3996 @item @emph{C/C++}:
3997 @multitable @columnfractions .20 .80
3998 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
3999 @end multitable
4001 @item @emph{Fortran}:
4002 @multitable @columnfractions .20 .80
4003 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
4004 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
4005 @item                   @tab @code{logical acc_async_test}
4006 @end multitable
4008 @item @emph{Reference}:
4009 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4010 3.2.9.
4011 @end table
4015 @node acc_async_test_all
4016 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
4017 @table @asis
4018 @item @emph{Description}
4019 This function tests for completion of all asynchronous operations.
4020 In C/C++, a non-zero value is returned to indicate all asynchronous
4021 operations have completed while Fortran returns @code{true}. If
4022 any asynchronous operation has not completed, C/C++ returns zero and
4023 Fortran returns @code{false}.
4025 @item @emph{C/C++}:
4026 @multitable @columnfractions .20 .80
4027 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
4028 @end multitable
4030 @item @emph{Fortran}:
4031 @multitable @columnfractions .20 .80
4032 @item @emph{Interface}: @tab @code{function acc_async_test()}
4033 @item                   @tab @code{logical acc_get_device_num}
4034 @end multitable
4036 @item @emph{Reference}:
4037 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4038 3.2.10.
4039 @end table
4043 @node acc_wait
4044 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
4045 @table @asis
4046 @item @emph{Description}
4047 This function waits for completion of the asynchronous operation
4048 specified in @var{arg}.
4050 @item @emph{C/C++}:
4051 @multitable @columnfractions .20 .80
4052 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
4053 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
4054 @end multitable
4056 @item @emph{Fortran}:
4057 @multitable @columnfractions .20 .80
4058 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
4059 @item                   @tab @code{integer(acc_handle_kind) arg}
4060 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
4061 @item                                               @tab @code{integer(acc_handle_kind) arg}
4062 @end multitable
4064 @item @emph{Reference}:
4065 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4066 3.2.11.
4067 @end table
4071 @node acc_wait_all
4072 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
4073 @table @asis
4074 @item @emph{Description}
4075 This function waits for the completion of all asynchronous operations.
4077 @item @emph{C/C++}:
4078 @multitable @columnfractions .20 .80
4079 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
4080 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
4081 @end multitable
4083 @item @emph{Fortran}:
4084 @multitable @columnfractions .20 .80
4085 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
4086 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
4087 @end multitable
4089 @item @emph{Reference}:
4090 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4091 3.2.13.
4092 @end table
4096 @node acc_wait_all_async
4097 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
4098 @table @asis
4099 @item @emph{Description}
4100 This function enqueues a wait operation on the queue @var{async} for any
4101 and all asynchronous operations that have been previously enqueued on
4102 any queue.
4104 @item @emph{C/C++}:
4105 @multitable @columnfractions .20 .80
4106 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
4107 @end multitable
4109 @item @emph{Fortran}:
4110 @multitable @columnfractions .20 .80
4111 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
4112 @item                   @tab @code{integer(acc_handle_kind) async}
4113 @end multitable
4115 @item @emph{Reference}:
4116 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4117 3.2.14.
4118 @end table
4122 @node acc_wait_async
4123 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
4124 @table @asis
4125 @item @emph{Description}
4126 This function enqueues a wait operation on queue @var{async} for any and all
4127 asynchronous operations enqueued on queue @var{arg}.
4129 @item @emph{C/C++}:
4130 @multitable @columnfractions .20 .80
4131 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
4132 @end multitable
4134 @item @emph{Fortran}:
4135 @multitable @columnfractions .20 .80
4136 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
4137 @item                   @tab @code{integer(acc_handle_kind) arg, async}
4138 @end multitable
4140 @item @emph{Reference}:
4141 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4142 3.2.12.
4143 @end table
4147 @node acc_init
4148 @section @code{acc_init} -- Initialize runtime for a specific device type.
4149 @table @asis
4150 @item @emph{Description}
4151 This function initializes the runtime for the device type specified in
4152 @var{devicetype}.
4154 @item @emph{C/C++}:
4155 @multitable @columnfractions .20 .80
4156 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
4157 @end multitable
4159 @item @emph{Fortran}:
4160 @multitable @columnfractions .20 .80
4161 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
4162 @item                   @tab @code{integer(acc_device_kind) devicetype}
4163 @end multitable
4165 @item @emph{Reference}:
4166 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4167 3.2.7.
4168 @end table
4172 @node acc_shutdown
4173 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
4174 @table @asis
4175 @item @emph{Description}
4176 This function shuts down the runtime for the device type specified in
4177 @var{devicetype}.
4179 @item @emph{C/C++}:
4180 @multitable @columnfractions .20 .80
4181 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
4182 @end multitable
4184 @item @emph{Fortran}:
4185 @multitable @columnfractions .20 .80
4186 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
4187 @item                   @tab @code{integer(acc_device_kind) devicetype}
4188 @end multitable
4190 @item @emph{Reference}:
4191 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4192 3.2.8.
4193 @end table
4197 @node acc_on_device
4198 @section @code{acc_on_device} -- Whether executing on a particular device
4199 @table @asis
4200 @item @emph{Description}:
4201 This function returns whether the program is executing on a particular
4202 device specified in @var{devicetype}. In C/C++ a non-zero value is
4203 returned to indicate the device is executing on the specified device type.
4204 In Fortran, @code{true} is returned. If the program is not executing
4205 on the specified device type C/C++ returns zero, while Fortran
4206 returns @code{false}.
4208 @item @emph{C/C++}:
4209 @multitable @columnfractions .20 .80
4210 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
4211 @end multitable
4213 @item @emph{Fortran}:
4214 @multitable @columnfractions .20 .80
4215 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
4216 @item                   @tab @code{integer(acc_device_kind) devicetype}
4217 @item                   @tab @code{logical acc_on_device}
4218 @end multitable
4221 @item @emph{Reference}:
4222 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4223 3.2.17.
4224 @end table
4228 @node acc_malloc
4229 @section @code{acc_malloc} -- Allocate device memory.
4230 @table @asis
4231 @item @emph{Description}
4232 This function allocates @var{len} bytes of device memory. It returns
4233 the device address of the allocated memory.
4235 @item @emph{C/C++}:
4236 @multitable @columnfractions .20 .80
4237 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
4238 @end multitable
4240 @item @emph{Reference}:
4241 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4242 3.2.18.
4243 @end table
4247 @node acc_free
4248 @section @code{acc_free} -- Free device memory.
4249 @table @asis
4250 @item @emph{Description}
4251 Free previously allocated device memory at the device address @code{a}.
4253 @item @emph{C/C++}:
4254 @multitable @columnfractions .20 .80
4255 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
4256 @end multitable
4258 @item @emph{Reference}:
4259 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4260 3.2.19.
4261 @end table
4265 @node acc_copyin
4266 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
4267 @table @asis
4268 @item @emph{Description}
4269 In C/C++, this function allocates @var{len} bytes of device memory
4270 and maps it to the specified host address in @var{a}. The device
4271 address of the newly allocated device memory is returned.
4273 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4274 a contiguous array section. The second form @var{a} specifies a
4275 variable or array element and @var{len} specifies the length in bytes.
4277 @item @emph{C/C++}:
4278 @multitable @columnfractions .20 .80
4279 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
4280 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
4281 @end multitable
4283 @item @emph{Fortran}:
4284 @multitable @columnfractions .20 .80
4285 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
4286 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4287 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
4288 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4289 @item                   @tab @code{integer len}
4290 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
4291 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4292 @item                   @tab @code{integer(acc_handle_kind) :: async}
4293 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
4294 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4295 @item                   @tab @code{integer len}
4296 @item                   @tab @code{integer(acc_handle_kind) :: async}
4297 @end multitable
4299 @item @emph{Reference}:
4300 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4301 3.2.20.
4302 @end table
4306 @node acc_present_or_copyin
4307 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
4308 @table @asis
4309 @item @emph{Description}
4310 This function tests if the host data specified by @var{a} and of length
4311 @var{len} is present or not. If it is not present, device memory
4312 is allocated and the host memory copied. The device address of
4313 the newly allocated device memory is returned.
4315 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4316 a contiguous array section. The second form @var{a} specifies a variable or
4317 array element and @var{len} specifies the length in bytes.
4319 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
4320 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
4322 @item @emph{C/C++}:
4323 @multitable @columnfractions .20 .80
4324 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
4325 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
4326 @end multitable
4328 @item @emph{Fortran}:
4329 @multitable @columnfractions .20 .80
4330 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
4331 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4332 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
4333 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4334 @item                   @tab @code{integer len}
4335 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
4336 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4337 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
4338 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4339 @item                   @tab @code{integer len}
4340 @end multitable
4342 @item @emph{Reference}:
4343 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4344 3.2.20.
4345 @end table
4349 @node acc_create
4350 @section @code{acc_create} -- Allocate device memory and map it to host memory.
4351 @table @asis
4352 @item @emph{Description}
4353 This function allocates device memory and maps it to host memory specified
4354 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
4355 the function returns the device address of the allocated device memory.
4357 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4358 a contiguous array section. The second form @var{a} specifies a variable or
4359 array element and @var{len} specifies the length in bytes.
4361 @item @emph{C/C++}:
4362 @multitable @columnfractions .20 .80
4363 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
4364 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
4365 @end multitable
4367 @item @emph{Fortran}:
4368 @multitable @columnfractions .20 .80
4369 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
4370 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4371 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
4372 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4373 @item                   @tab @code{integer len}
4374 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
4375 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4376 @item                   @tab @code{integer(acc_handle_kind) :: async}
4377 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
4378 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4379 @item                   @tab @code{integer len}
4380 @item                   @tab @code{integer(acc_handle_kind) :: async}
4381 @end multitable
4383 @item @emph{Reference}:
4384 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4385 3.2.21.
4386 @end table
4390 @node acc_present_or_create
4391 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
4392 @table @asis
4393 @item @emph{Description}
4394 This function tests if the host data specified by @var{a} and of length
4395 @var{len} is present or not. If it is not present, device memory
4396 is allocated and mapped to host memory. In C/C++, the device address
4397 of the newly allocated device memory is returned.
4399 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4400 a contiguous array section. The second form @var{a} specifies a variable or
4401 array element and @var{len} specifies the length in bytes.
4403 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
4404 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
4406 @item @emph{C/C++}:
4407 @multitable @columnfractions .20 .80
4408 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
4409 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
4410 @end multitable
4412 @item @emph{Fortran}:
4413 @multitable @columnfractions .20 .80
4414 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
4415 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4416 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
4417 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4418 @item                   @tab @code{integer len}
4419 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
4420 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4421 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
4422 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4423 @item                   @tab @code{integer len}
4424 @end multitable
4426 @item @emph{Reference}:
4427 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4428 3.2.21.
4429 @end table
4433 @node acc_copyout
4434 @section @code{acc_copyout} -- Copy device memory to host memory.
4435 @table @asis
4436 @item @emph{Description}
4437 This function copies mapped device memory to host memory which is specified
4438 by host address @var{a} for a length @var{len} bytes in C/C++.
4440 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4441 a contiguous array section. The second form @var{a} specifies a variable or
4442 array element and @var{len} specifies the length in bytes.
4444 @item @emph{C/C++}:
4445 @multitable @columnfractions .20 .80
4446 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
4447 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
4448 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
4449 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
4450 @end multitable
4452 @item @emph{Fortran}:
4453 @multitable @columnfractions .20 .80
4454 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
4455 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4456 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
4457 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4458 @item                   @tab @code{integer len}
4459 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
4460 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4461 @item                   @tab @code{integer(acc_handle_kind) :: async}
4462 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
4463 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4464 @item                   @tab @code{integer len}
4465 @item                   @tab @code{integer(acc_handle_kind) :: async}
4466 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
4467 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4468 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
4469 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4470 @item                   @tab @code{integer len}
4471 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
4472 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4473 @item                   @tab @code{integer(acc_handle_kind) :: async}
4474 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
4475 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4476 @item                   @tab @code{integer len}
4477 @item                   @tab @code{integer(acc_handle_kind) :: async}
4478 @end multitable
4480 @item @emph{Reference}:
4481 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4482 3.2.22.
4483 @end table
4487 @node acc_delete
4488 @section @code{acc_delete} -- Free device memory.
4489 @table @asis
4490 @item @emph{Description}
4491 This function frees previously allocated device memory specified by
4492 the device address @var{a} and the length of @var{len} bytes.
4494 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4495 a contiguous array section. The second form @var{a} specifies a variable or
4496 array element and @var{len} specifies the length in bytes.
4498 @item @emph{C/C++}:
4499 @multitable @columnfractions .20 .80
4500 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
4501 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
4502 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
4503 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
4504 @end multitable
4506 @item @emph{Fortran}:
4507 @multitable @columnfractions .20 .80
4508 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
4509 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4510 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
4511 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4512 @item                   @tab @code{integer len}
4513 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
4514 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4515 @item                   @tab @code{integer(acc_handle_kind) :: async}
4516 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
4517 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4518 @item                   @tab @code{integer len}
4519 @item                   @tab @code{integer(acc_handle_kind) :: async}
4520 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
4521 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4522 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
4523 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4524 @item                   @tab @code{integer len}
4525 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
4526 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4527 @item                   @tab @code{integer(acc_handle_kind) :: async}
4528 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
4529 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4530 @item                   @tab @code{integer len}
4531 @item                   @tab @code{integer(acc_handle_kind) :: async}
4532 @end multitable
4534 @item @emph{Reference}:
4535 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4536 3.2.23.
4537 @end table
4541 @node acc_update_device
4542 @section @code{acc_update_device} -- Update device memory from mapped host memory.
4543 @table @asis
4544 @item @emph{Description}
4545 This function updates the device copy from the previously mapped host memory.
4546 The host memory is specified with the host address @var{a} and a length of
4547 @var{len} bytes.
4549 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4550 a contiguous array section. The second form @var{a} specifies a variable or
4551 array element and @var{len} specifies the length in bytes.
4553 @item @emph{C/C++}:
4554 @multitable @columnfractions .20 .80
4555 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
4556 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
4557 @end multitable
4559 @item @emph{Fortran}:
4560 @multitable @columnfractions .20 .80
4561 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
4562 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4563 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
4564 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4565 @item                   @tab @code{integer len}
4566 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
4567 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4568 @item                   @tab @code{integer(acc_handle_kind) :: async}
4569 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
4570 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4571 @item                   @tab @code{integer len}
4572 @item                   @tab @code{integer(acc_handle_kind) :: async}
4573 @end multitable
4575 @item @emph{Reference}:
4576 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4577 3.2.24.
4578 @end table
4582 @node acc_update_self
4583 @section @code{acc_update_self} -- Update host memory from mapped device memory.
4584 @table @asis
4585 @item @emph{Description}
4586 This function updates the host copy from the previously mapped device memory.
4587 The host memory is specified with the host address @var{a} and a length of
4588 @var{len} bytes.
4590 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4591 a contiguous array section. The second form @var{a} specifies a variable or
4592 array element and @var{len} specifies the length in bytes.
4594 @item @emph{C/C++}:
4595 @multitable @columnfractions .20 .80
4596 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
4597 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
4598 @end multitable
4600 @item @emph{Fortran}:
4601 @multitable @columnfractions .20 .80
4602 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
4603 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4604 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
4605 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4606 @item                   @tab @code{integer len}
4607 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
4608 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4609 @item                   @tab @code{integer(acc_handle_kind) :: async}
4610 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
4611 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4612 @item                   @tab @code{integer len}
4613 @item                   @tab @code{integer(acc_handle_kind) :: async}
4614 @end multitable
4616 @item @emph{Reference}:
4617 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4618 3.2.25.
4619 @end table
4623 @node acc_map_data
4624 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
4625 @table @asis
4626 @item @emph{Description}
4627 This function maps previously allocated device and host memory. The device
4628 memory is specified with the device address @var{d}. The host memory is
4629 specified with the host address @var{h} and a length of @var{len}.
4631 @item @emph{C/C++}:
4632 @multitable @columnfractions .20 .80
4633 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
4634 @end multitable
4636 @item @emph{Reference}:
4637 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4638 3.2.26.
4639 @end table
4643 @node acc_unmap_data
4644 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
4645 @table @asis
4646 @item @emph{Description}
4647 This function unmaps previously mapped device and host memory. The latter
4648 specified by @var{h}.
4650 @item @emph{C/C++}:
4651 @multitable @columnfractions .20 .80
4652 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
4653 @end multitable
4655 @item @emph{Reference}:
4656 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4657 3.2.27.
4658 @end table
4662 @node acc_deviceptr
4663 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
4664 @table @asis
4665 @item @emph{Description}
4666 This function returns the device address that has been mapped to the
4667 host address specified by @var{h}.
4669 @item @emph{C/C++}:
4670 @multitable @columnfractions .20 .80
4671 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
4672 @end multitable
4674 @item @emph{Reference}:
4675 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4676 3.2.28.
4677 @end table
4681 @node acc_hostptr
4682 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
4683 @table @asis
4684 @item @emph{Description}
4685 This function returns the host address that has been mapped to the
4686 device address specified by @var{d}.
4688 @item @emph{C/C++}:
4689 @multitable @columnfractions .20 .80
4690 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
4691 @end multitable
4693 @item @emph{Reference}:
4694 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4695 3.2.29.
4696 @end table
4700 @node acc_is_present
4701 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
4702 @table @asis
4703 @item @emph{Description}
4704 This function indicates whether the specified host address in @var{a} and a
4705 length of @var{len} bytes is present on the device. In C/C++, a non-zero
4706 value is returned to indicate the presence of the mapped memory on the
4707 device. A zero is returned to indicate the memory is not mapped on the
4708 device.
4710 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4711 a contiguous array section. The second form @var{a} specifies a variable or
4712 array element and @var{len} specifies the length in bytes. If the host
4713 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
4714 a @code{false} is return to indicate the mapped memory is not present.
4716 @item @emph{C/C++}:
4717 @multitable @columnfractions .20 .80
4718 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
4719 @end multitable
4721 @item @emph{Fortran}:
4722 @multitable @columnfractions .20 .80
4723 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
4724 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4725 @item                   @tab @code{logical acc_is_present}
4726 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
4727 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4728 @item                   @tab @code{integer len}
4729 @item                   @tab @code{logical acc_is_present}
4730 @end multitable
4732 @item @emph{Reference}:
4733 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4734 3.2.30.
4735 @end table
4739 @node acc_memcpy_to_device
4740 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
4741 @table @asis
4742 @item @emph{Description}
4743 This function copies host memory specified by host address of @var{src} to
4744 device memory specified by the device address @var{dest} for a length of
4745 @var{bytes} bytes.
4747 @item @emph{C/C++}:
4748 @multitable @columnfractions .20 .80
4749 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
4750 @end multitable
4752 @item @emph{Reference}:
4753 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4754 3.2.31.
4755 @end table
4759 @node acc_memcpy_from_device
4760 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
4761 @table @asis
4762 @item @emph{Description}
4763 This function copies host memory specified by host address of @var{src} from
4764 device memory specified by the device address @var{dest} for a length of
4765 @var{bytes} bytes.
4767 @item @emph{C/C++}:
4768 @multitable @columnfractions .20 .80
4769 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
4770 @end multitable
4772 @item @emph{Reference}:
4773 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4774 3.2.32.
4775 @end table
4779 @node acc_attach
4780 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
4781 @table @asis
4782 @item @emph{Description}
4783 This function updates a pointer on the device from pointing to a host-pointer
4784 address to pointing to the corresponding device data.
4786 @item @emph{C/C++}:
4787 @multitable @columnfractions .20 .80
4788 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
4789 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
4790 @end multitable
4792 @item @emph{Reference}:
4793 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4794 3.2.34.
4795 @end table
4799 @node acc_detach
4800 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
4801 @table @asis
4802 @item @emph{Description}
4803 This function updates a pointer on the device from pointing to a device-pointer
4804 address to pointing to the corresponding host data.
4806 @item @emph{C/C++}:
4807 @multitable @columnfractions .20 .80
4808 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
4809 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
4810 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
4811 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
4812 @end multitable
4814 @item @emph{Reference}:
4815 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4816 3.2.35.
4817 @end table
4821 @node acc_get_current_cuda_device
4822 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
4823 @table @asis
4824 @item @emph{Description}
4825 This function returns the CUDA device handle. This handle is the same
4826 as used by the CUDA Runtime or Driver API's.
4828 @item @emph{C/C++}:
4829 @multitable @columnfractions .20 .80
4830 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
4831 @end multitable
4833 @item @emph{Reference}:
4834 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4835 A.2.1.1.
4836 @end table
4840 @node acc_get_current_cuda_context
4841 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
4842 @table @asis
4843 @item @emph{Description}
4844 This function returns the CUDA context handle. This handle is the same
4845 as used by the CUDA Runtime or Driver API's.
4847 @item @emph{C/C++}:
4848 @multitable @columnfractions .20 .80
4849 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
4850 @end multitable
4852 @item @emph{Reference}:
4853 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4854 A.2.1.2.
4855 @end table
4859 @node acc_get_cuda_stream
4860 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
4861 @table @asis
4862 @item @emph{Description}
4863 This function returns the CUDA stream handle for the queue @var{async}.
4864 This handle is the same as used by the CUDA Runtime or Driver API's.
4866 @item @emph{C/C++}:
4867 @multitable @columnfractions .20 .80
4868 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
4869 @end multitable
4871 @item @emph{Reference}:
4872 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4873 A.2.1.3.
4874 @end table
4878 @node acc_set_cuda_stream
4879 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
4880 @table @asis
4881 @item @emph{Description}
4882 This function associates the stream handle specified by @var{stream} with
4883 the queue @var{async}.
4885 This cannot be used to change the stream handle associated with
4886 @code{acc_async_sync}.
4888 The return value is not specified.
4890 @item @emph{C/C++}:
4891 @multitable @columnfractions .20 .80
4892 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
4893 @end multitable
4895 @item @emph{Reference}:
4896 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4897 A.2.1.4.
4898 @end table
4902 @node acc_prof_register
4903 @section @code{acc_prof_register} -- Register callbacks.
4904 @table @asis
4905 @item @emph{Description}:
4906 This function registers callbacks.
4908 @item @emph{C/C++}:
4909 @multitable @columnfractions .20 .80
4910 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
4911 @end multitable
4913 @item @emph{See also}:
4914 @ref{OpenACC Profiling Interface}
4916 @item @emph{Reference}:
4917 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4918 5.3.
4919 @end table
4923 @node acc_prof_unregister
4924 @section @code{acc_prof_unregister} -- Unregister callbacks.
4925 @table @asis
4926 @item @emph{Description}:
4927 This function unregisters callbacks.
4929 @item @emph{C/C++}:
4930 @multitable @columnfractions .20 .80
4931 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
4932 @end multitable
4934 @item @emph{See also}:
4935 @ref{OpenACC Profiling Interface}
4937 @item @emph{Reference}:
4938 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4939 5.3.
4940 @end table
4944 @node acc_prof_lookup
4945 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
4946 @table @asis
4947 @item @emph{Description}:
4948 Function to obtain inquiry functions.
4950 @item @emph{C/C++}:
4951 @multitable @columnfractions .20 .80
4952 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
4953 @end multitable
4955 @item @emph{See also}:
4956 @ref{OpenACC Profiling Interface}
4958 @item @emph{Reference}:
4959 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4960 5.3.
4961 @end table
4965 @node acc_register_library
4966 @section @code{acc_register_library} -- Library registration.
4967 @table @asis
4968 @item @emph{Description}:
4969 Function for library registration.
4971 @item @emph{C/C++}:
4972 @multitable @columnfractions .20 .80
4973 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
4974 @end multitable
4976 @item @emph{See also}:
4977 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
4979 @item @emph{Reference}:
4980 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4981 5.3.
4982 @end table
4986 @c ---------------------------------------------------------------------
4987 @c OpenACC Environment Variables
4988 @c ---------------------------------------------------------------------
4990 @node OpenACC Environment Variables
4991 @chapter OpenACC Environment Variables
4993 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
4994 are defined by section 4 of the OpenACC specification in version 2.0.
4995 The variable @env{ACC_PROFLIB}
4996 is defined by section 4 of the OpenACC specification in version 2.6.
4998 @menu
4999 * ACC_DEVICE_TYPE::
5000 * ACC_DEVICE_NUM::
5001 * ACC_PROFLIB::
5002 @end menu
5006 @node ACC_DEVICE_TYPE
5007 @section @code{ACC_DEVICE_TYPE}
5008 @table @asis
5009 @item @emph{Description}:
5010 Control the default device type to use when executing compute regions.
5011 If unset, the code can be run on any device type, favoring a non-host
5012 device type.
5014 Supported values in GCC (if compiled in) are
5015 @itemize
5016 @item @code{host}
5017 @item @code{nvidia}
5018 @item @code{radeon}
5019 @end itemize
5020 @item @emph{Reference}:
5021 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5022 4.1.
5023 @end table
5027 @node ACC_DEVICE_NUM
5028 @section @code{ACC_DEVICE_NUM}
5029 @table @asis
5030 @item @emph{Description}:
5031 Control which device, identified by device number, is the default device.
5032 The value must be a nonnegative integer less than the number of devices.
5033 If unset, device number zero is used.
5034 @item @emph{Reference}:
5035 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5036 4.2.
5037 @end table
5041 @node ACC_PROFLIB
5042 @section @code{ACC_PROFLIB}
5043 @table @asis
5044 @item @emph{Description}:
5045 Semicolon-separated list of dynamic libraries that are loaded as profiling
5046 libraries.  Each library must provide at least the @code{acc_register_library}
5047 routine.  Each library file is found as described by the documentation of
5048 @code{dlopen} of your operating system.
5049 @item @emph{See also}:
5050 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
5052 @item @emph{Reference}:
5053 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5054 4.3.
5055 @end table
5059 @c ---------------------------------------------------------------------
5060 @c CUDA Streams Usage
5061 @c ---------------------------------------------------------------------
5063 @node CUDA Streams Usage
5064 @chapter CUDA Streams Usage
5066 This applies to the @code{nvptx} plugin only.
5068 The library provides elements that perform asynchronous movement of
5069 data and asynchronous operation of computing constructs.  This
5070 asynchronous functionality is implemented by making use of CUDA
5071 streams@footnote{See "Stream Management" in "CUDA Driver API",
5072 TRM-06703-001, Version 5.5, for additional information}.
5074 The primary means by that the asynchronous functionality is accessed
5075 is through the use of those OpenACC directives which make use of the
5076 @code{async} and @code{wait} clauses.  When the @code{async} clause is
5077 first used with a directive, it creates a CUDA stream.  If an
5078 @code{async-argument} is used with the @code{async} clause, then the
5079 stream is associated with the specified @code{async-argument}.
5081 Following the creation of an association between a CUDA stream and the
5082 @code{async-argument} of an @code{async} clause, both the @code{wait}
5083 clause and the @code{wait} directive can be used.  When either the
5084 clause or directive is used after stream creation, it creates a
5085 rendezvous point whereby execution waits until all operations
5086 associated with the @code{async-argument}, that is, stream, have
5087 completed.
5089 Normally, the management of the streams that are created as a result of
5090 using the @code{async} clause, is done without any intervention by the
5091 caller.  This implies the association between the @code{async-argument}
5092 and the CUDA stream is maintained for the lifetime of the program.
5093 However, this association can be changed through the use of the library
5094 function @code{acc_set_cuda_stream}.  When the function
5095 @code{acc_set_cuda_stream} is called, the CUDA stream that was
5096 originally associated with the @code{async} clause is destroyed.
5097 Caution should be taken when changing the association as subsequent
5098 references to the @code{async-argument} refer to a different
5099 CUDA stream.
5103 @c ---------------------------------------------------------------------
5104 @c OpenACC Library Interoperability
5105 @c ---------------------------------------------------------------------
5107 @node OpenACC Library Interoperability
5108 @chapter OpenACC Library Interoperability
5110 @section Introduction
5112 The OpenACC library uses the CUDA Driver API, and may interact with
5113 programs that use the Runtime library directly, or another library
5114 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
5115 "Interactions with the CUDA Driver API" in
5116 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
5117 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
5118 for additional information on library interoperability.}.
5119 This chapter describes the use cases and what changes are
5120 required in order to use both the OpenACC library and the CUBLAS and Runtime
5121 libraries within a program.
5123 @section First invocation: NVIDIA CUBLAS library API
5125 In this first use case (see below), a function in the CUBLAS library is called
5126 prior to any of the functions in the OpenACC library. More specifically, the
5127 function @code{cublasCreate()}.
5129 When invoked, the function initializes the library and allocates the
5130 hardware resources on the host and the device on behalf of the caller. Once
5131 the initialization and allocation has completed, a handle is returned to the
5132 caller. The OpenACC library also requires initialization and allocation of
5133 hardware resources. Since the CUBLAS library has already allocated the
5134 hardware resources for the device, all that is left to do is to initialize
5135 the OpenACC library and acquire the hardware resources on the host.
5137 Prior to calling the OpenACC function that initializes the library and
5138 allocate the host hardware resources, you need to acquire the device number
5139 that was allocated during the call to @code{cublasCreate()}. The invoking of the
5140 runtime library function @code{cudaGetDevice()} accomplishes this. Once
5141 acquired, the device number is passed along with the device type as
5142 parameters to the OpenACC library function @code{acc_set_device_num()}.
5144 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
5145 library uses the  context that was created during the call to
5146 @code{cublasCreate()}. In other words, both libraries share the
5147 same context.
5149 @smallexample
5150     /* Create the handle */
5151     s = cublasCreate(&h);
5152     if (s != CUBLAS_STATUS_SUCCESS)
5153     @{
5154         fprintf(stderr, "cublasCreate failed %d\n", s);
5155         exit(EXIT_FAILURE);
5156     @}
5158     /* Get the device number */
5159     e = cudaGetDevice(&dev);
5160     if (e != cudaSuccess)
5161     @{
5162         fprintf(stderr, "cudaGetDevice failed %d\n", e);
5163         exit(EXIT_FAILURE);
5164     @}
5166     /* Initialize OpenACC library and use device 'dev' */
5167     acc_set_device_num(dev, acc_device_nvidia);
5169 @end smallexample
5170 @center Use Case 1 
5172 @section First invocation: OpenACC library API
5174 In this second use case (see below), a function in the OpenACC library is
5175 called prior to any of the functions in the CUBLAS library. More specifically,
5176 the function @code{acc_set_device_num()}.
5178 In the use case presented here, the function @code{acc_set_device_num()}
5179 is used to both initialize the OpenACC library and allocate the hardware
5180 resources on the host and the device. In the call to the function, the
5181 call parameters specify which device to use and what device
5182 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
5183 is but one method to initialize the OpenACC library and allocate the
5184 appropriate hardware resources. Other methods are available through the
5185 use of environment variables and these is discussed in the next section.
5187 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
5188 functions can be called as seen with multiple calls being made to
5189 @code{acc_copyin()}. In addition, calls can be made to functions in the
5190 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
5191 subsequent to the calls to @code{acc_copyin()}.
5192 As seen in the previous use case, a call to @code{cublasCreate()}
5193 initializes the CUBLAS library and allocates the hardware resources on the
5194 host and the device.  However, since the device has already been allocated,
5195 @code{cublasCreate()} only initializes the CUBLAS library and allocates
5196 the appropriate hardware resources on the host. The context that was created
5197 as part of the OpenACC initialization is shared with the CUBLAS library,
5198 similarly to the first use case.
5200 @smallexample
5201     dev = 0;
5203     acc_set_device_num(dev, acc_device_nvidia);
5205     /* Copy the first set to the device */
5206     d_X = acc_copyin(&h_X[0], N * sizeof (float));
5207     if (d_X == NULL)
5208     @{ 
5209         fprintf(stderr, "copyin error h_X\n");
5210         exit(EXIT_FAILURE);
5211     @}
5213     /* Copy the second set to the device */
5214     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
5215     if (d_Y == NULL)
5216     @{ 
5217         fprintf(stderr, "copyin error h_Y1\n");
5218         exit(EXIT_FAILURE);
5219     @}
5221     /* Create the handle */
5222     s = cublasCreate(&h);
5223     if (s != CUBLAS_STATUS_SUCCESS)
5224     @{
5225         fprintf(stderr, "cublasCreate failed %d\n", s);
5226         exit(EXIT_FAILURE);
5227     @}
5229     /* Perform saxpy using CUBLAS library function */
5230     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
5231     if (s != CUBLAS_STATUS_SUCCESS)
5232     @{
5233         fprintf(stderr, "cublasSaxpy failed %d\n", s);
5234         exit(EXIT_FAILURE);
5235     @}
5237     /* Copy the results from the device */
5238     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
5240 @end smallexample
5241 @center Use Case 2
5243 @section OpenACC library and environment variables
5245 There are two environment variables associated with the OpenACC library
5246 that may be used to control the device type and device number:
5247 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
5248 environment variables can be used as an alternative to calling
5249 @code{acc_set_device_num()}. As seen in the second use case, the device
5250 type and device number were specified using @code{acc_set_device_num()}.
5251 If however, the aforementioned environment variables were set, then the
5252 call to @code{acc_set_device_num()} would not be required.
5255 The use of the environment variables is only relevant when an OpenACC function
5256 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
5257 is called prior to a call to an OpenACC function, then you must call
5258 @code{acc_set_device_num()}@footnote{More complete information
5259 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
5260 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
5261 Application Programming Interface”, Version 2.6.}
5265 @c ---------------------------------------------------------------------
5266 @c OpenACC Profiling Interface
5267 @c ---------------------------------------------------------------------
5269 @node OpenACC Profiling Interface
5270 @chapter OpenACC Profiling Interface
5272 @section Implementation Status and Implementation-Defined Behavior
5274 We're implementing the OpenACC Profiling Interface as defined by the
5275 OpenACC 2.6 specification.  We're clarifying some aspects here as
5276 @emph{implementation-defined behavior}, while they're still under
5277 discussion within the OpenACC Technical Committee.
5279 This implementation is tuned to keep the performance impact as low as
5280 possible for the (very common) case that the Profiling Interface is
5281 not enabled.  This is relevant, as the Profiling Interface affects all
5282 the @emph{hot} code paths (in the target code, not in the offloaded
5283 code).  Users of the OpenACC Profiling Interface can be expected to
5284 understand that performance is impacted to some degree once the
5285 Profiling Interface is enabled: for example, because of the
5286 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
5287 every event that has been registered.
5289 We're not yet accounting for the fact that @cite{OpenACC events may
5290 occur during event processing}.
5291 We just handle one case specially, as required by CUDA 9.0
5292 @command{nvprof}, that @code{acc_get_device_type}
5293 (@ref{acc_get_device_type})) may be called from
5294 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
5295 callbacks.
5297 We're not yet implementing initialization via a
5298 @code{acc_register_library} function that is either statically linked
5299 in, or dynamically via @env{LD_PRELOAD}.
5300 Initialization via @code{acc_register_library} functions dynamically
5301 loaded via the @env{ACC_PROFLIB} environment variable does work, as
5302 does directly calling @code{acc_prof_register},
5303 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
5305 As currently there are no inquiry functions defined, calls to
5306 @code{acc_prof_lookup} always returns @code{NULL}.
5308 There aren't separate @emph{start}, @emph{stop} events defined for the
5309 event types @code{acc_ev_create}, @code{acc_ev_delete},
5310 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
5311 should be triggered before or after the actual device-specific call is
5312 made.  We trigger them after.
5314 Remarks about data provided to callbacks:
5316 @table @asis
5318 @item @code{acc_prof_info.event_type}
5319 It's not clear if for @emph{nested} event callbacks (for example,
5320 @code{acc_ev_enqueue_launch_start} as part of a parent compute
5321 construct), this should be set for the nested event
5322 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
5323 construct should remain (@code{acc_ev_compute_construct_start}).  In
5324 this implementation, the value generally corresponds to the
5325 innermost nested event type.
5327 @item @code{acc_prof_info.device_type}
5328 @itemize
5330 @item
5331 For @code{acc_ev_compute_construct_start}, and in presence of an
5332 @code{if} clause with @emph{false} argument, this still refers to
5333 the offloading device type.
5334 It's not clear if that's the expected behavior.
5336 @item
5337 Complementary to the item before, for
5338 @code{acc_ev_compute_construct_end}, this is set to
5339 @code{acc_device_host} in presence of an @code{if} clause with
5340 @emph{false} argument.
5341 It's not clear if that's the expected behavior.
5343 @end itemize
5345 @item @code{acc_prof_info.thread_id}
5346 Always @code{-1}; not yet implemented.
5348 @item @code{acc_prof_info.async}
5349 @itemize
5351 @item
5352 Not yet implemented correctly for
5353 @code{acc_ev_compute_construct_start}.
5355 @item
5356 In a compute construct, for host-fallback
5357 execution/@code{acc_device_host} it always is
5358 @code{acc_async_sync}.
5359 It is unclear if that is the expected behavior.
5361 @item
5362 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
5363 it will always be @code{acc_async_sync}.
5364 It is unclear if that is the expected behavior.
5366 @end itemize
5368 @item @code{acc_prof_info.async_queue}
5369 There is no @cite{limited number of asynchronous queues} in libgomp.
5370 This always has the same value as @code{acc_prof_info.async}.
5372 @item @code{acc_prof_info.src_file}
5373 Always @code{NULL}; not yet implemented.
5375 @item @code{acc_prof_info.func_name}
5376 Always @code{NULL}; not yet implemented.
5378 @item @code{acc_prof_info.line_no}
5379 Always @code{-1}; not yet implemented.
5381 @item @code{acc_prof_info.end_line_no}
5382 Always @code{-1}; not yet implemented.
5384 @item @code{acc_prof_info.func_line_no}
5385 Always @code{-1}; not yet implemented.
5387 @item @code{acc_prof_info.func_end_line_no}
5388 Always @code{-1}; not yet implemented.
5390 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
5391 Relating to @code{acc_prof_info.event_type} discussed above, in this
5392 implementation, this will always be the same value as
5393 @code{acc_prof_info.event_type}.
5395 @item @code{acc_event_info.*.parent_construct}
5396 @itemize
5398 @item
5399 Will be @code{acc_construct_parallel} for all OpenACC compute
5400 constructs as well as many OpenACC Runtime API calls; should be the
5401 one matching the actual construct, or
5402 @code{acc_construct_runtime_api}, respectively.
5404 @item
5405 Will be @code{acc_construct_enter_data} or
5406 @code{acc_construct_exit_data} when processing variable mappings
5407 specified in OpenACC @emph{declare} directives; should be
5408 @code{acc_construct_declare}.
5410 @item
5411 For implicit @code{acc_ev_device_init_start},
5412 @code{acc_ev_device_init_end}, and explicit as well as implicit
5413 @code{acc_ev_alloc}, @code{acc_ev_free},
5414 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5415 @code{acc_ev_enqueue_download_start}, and
5416 @code{acc_ev_enqueue_download_end}, will be
5417 @code{acc_construct_parallel}; should reflect the real parent
5418 construct.
5420 @end itemize
5422 @item @code{acc_event_info.*.implicit}
5423 For @code{acc_ev_alloc}, @code{acc_ev_free},
5424 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
5425 @code{acc_ev_enqueue_download_start}, and
5426 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
5427 also for explicit usage.
5429 @item @code{acc_event_info.data_event.var_name}
5430 Always @code{NULL}; not yet implemented.
5432 @item @code{acc_event_info.data_event.host_ptr}
5433 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
5434 @code{NULL}.
5436 @item @code{typedef union acc_api_info}
5437 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
5438 Information}.  This should obviously be @code{typedef @emph{struct}
5439 acc_api_info}.
5441 @item @code{acc_api_info.device_api}
5442 Possibly not yet implemented correctly for
5443 @code{acc_ev_compute_construct_start},
5444 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
5445 will always be @code{acc_device_api_none} for these event types.
5446 For @code{acc_ev_enter_data_start}, it will be
5447 @code{acc_device_api_none} in some cases.
5449 @item @code{acc_api_info.device_type}
5450 Always the same as @code{acc_prof_info.device_type}.
5452 @item @code{acc_api_info.vendor}
5453 Always @code{-1}; not yet implemented.
5455 @item @code{acc_api_info.device_handle}
5456 Always @code{NULL}; not yet implemented.
5458 @item @code{acc_api_info.context_handle}
5459 Always @code{NULL}; not yet implemented.
5461 @item @code{acc_api_info.async_handle}
5462 Always @code{NULL}; not yet implemented.
5464 @end table
5466 Remarks about certain event types:
5468 @table @asis
5470 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
5471 @itemize
5473 @item
5474 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
5475 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
5476 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
5477 When a compute construct triggers implicit
5478 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
5479 events, they currently aren't @emph{nested within} the corresponding
5480 @code{acc_ev_compute_construct_start} and
5481 @code{acc_ev_compute_construct_end}, but they're currently observed
5482 @emph{before} @code{acc_ev_compute_construct_start}.
5483 It's not clear what to do: the standard asks us provide a lot of
5484 details to the @code{acc_ev_compute_construct_start} callback, without
5485 (implicitly) initializing a device before?
5487 @item
5488 Callbacks for these event types will not be invoked for calls to the
5489 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
5490 It's not clear if they should be.
5492 @end itemize
5494 @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}
5495 @itemize
5497 @item
5498 Callbacks for these event types will also be invoked for OpenACC
5499 @emph{host_data} constructs.
5500 It's not clear if they should be.
5502 @item
5503 Callbacks for these event types will also be invoked when processing
5504 variable mappings specified in OpenACC @emph{declare} directives.
5505 It's not clear if they should be.
5507 @end itemize
5509 @end table
5511 Callbacks for the following event types will be invoked, but dispatch
5512 and information provided therein has not yet been thoroughly reviewed:
5514 @itemize
5515 @item @code{acc_ev_alloc}
5516 @item @code{acc_ev_free}
5517 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
5518 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
5519 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
5520 @end itemize
5522 During device initialization, and finalization, respectively,
5523 callbacks for the following event types will not yet be invoked:
5525 @itemize
5526 @item @code{acc_ev_alloc}
5527 @item @code{acc_ev_free}
5528 @end itemize
5530 Callbacks for the following event types have not yet been implemented,
5531 so currently won't be invoked:
5533 @itemize
5534 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
5535 @item @code{acc_ev_runtime_shutdown}
5536 @item @code{acc_ev_create}, @code{acc_ev_delete}
5537 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
5538 @end itemize
5540 For the following runtime library functions, not all expected
5541 callbacks will be invoked (mostly concerning implicit device
5542 initialization):
5544 @itemize
5545 @item @code{acc_get_num_devices}
5546 @item @code{acc_set_device_type}
5547 @item @code{acc_get_device_type}
5548 @item @code{acc_set_device_num}
5549 @item @code{acc_get_device_num}
5550 @item @code{acc_init}
5551 @item @code{acc_shutdown}
5552 @end itemize
5554 Aside from implicit device initialization, for the following runtime
5555 library functions, no callbacks will be invoked for shared-memory
5556 offloading devices (it's not clear if they should be):
5558 @itemize
5559 @item @code{acc_malloc}
5560 @item @code{acc_free}
5561 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
5562 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
5563 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
5564 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
5565 @item @code{acc_update_device}, @code{acc_update_device_async}
5566 @item @code{acc_update_self}, @code{acc_update_self_async}
5567 @item @code{acc_map_data}, @code{acc_unmap_data}
5568 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
5569 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
5570 @end itemize
5572 @c ---------------------------------------------------------------------
5573 @c OpenMP-Implementation Specifics
5574 @c ---------------------------------------------------------------------
5576 @node OpenMP-Implementation Specifics
5577 @chapter OpenMP-Implementation Specifics
5579 @menu
5580 * Implementation-defined ICV Initialization::
5581 * OpenMP Context Selectors::
5582 * Memory allocation::
5583 @end menu
5585 @node Implementation-defined ICV Initialization
5586 @section Implementation-defined ICV Initialization
5587 @cindex Implementation specific setting
5589 @multitable @columnfractions .30 .70
5590 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
5591 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
5592 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
5593 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
5594 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
5595 @item @var{num-devices-var} @tab Number of non-host devices found
5596 by GCC's run-time library
5597 @item @var{num-procs-var} @tab The number of CPU cores on the
5598 initial device, except that affinity settings might lead to a
5599 smaller number.  On non-host devices, the value of the
5600 @var{nthreads-var} ICV.
5601 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
5602 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
5603 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
5604 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
5605 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
5606 @ref{GOMP_SPINCOUNT}
5607 @end multitable
5609 @node OpenMP Context Selectors
5610 @section OpenMP Context Selectors
5612 @code{vendor} is always @code{gnu}. References are to the GCC manual.
5614 @c NOTE: Only the following selectors have been implemented. To add
5615 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
5616 @c has to be implemented; cf. also PR target/105640.
5617 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
5619 For the host compiler, @code{kind} always matches @code{host}; for the
5620 offloading architectures AMD GCN and Nvidia PTX, @code{kind} always matches
5621 @code{gpu}.  For the x86 family of computers, AMD GCN and Nvidia PTX
5622 the following traits are supported in addition; while OpenMP is supported
5623 on more architectures, GCC currently does not match any @code{arch} or
5624 @code{isa} traits for those.
5626 @multitable @columnfractions .65 .30
5627 @headitem @code{arch} @tab @code{isa}
5628 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
5629       @code{i586}, @code{i686}, @code{ia32}
5630       @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
5631 @item @code{amdgcn}, @code{gcn}
5632       @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
5633       @code{gfx803} is supported as an alias for @code{fiji}.}
5634 @item @code{nvptx}
5635       @tab See @code{-march=} in ``Nvidia PTX Options''
5636 @end multitable
5638 @node Memory allocation
5639 @section Memory allocation
5641 The description below applies to:
5643 @itemize
5644 @item Explicit use of the OpenMP API routines, see
5645       @ref{Memory Management Routines}.
5646 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
5647       constant expression with value @code{omp_default_mem_alloc} and no
5648       @code{align} modifier has been specified. (In that case, the normal
5649       @code{malloc} allocation is used.)
5650 @item Using the @code{allocate} directive for automatic/stack variables, except
5651       when the @code{allocator} clause is a constant expression with value
5652       @code{omp_default_mem_alloc} and no @code{align} clause has been
5653       specified. (In that case, the normal allocation is used: stack allocation
5654       and, sometimes for Fortran, also @code{malloc} [depending on flags such as
5655       @option{-fstack-arrays}].)
5656 @item Using the @code{allocate} directive for variable in static memory is
5657       currently not supported (compile time error).
5658 @item Using the @code{allocators} directive for Fortran pointers and
5659       allocatables is currently not supported (compile time error).
5660 @end itemize
5662 For the available predefined allocators and, as applicable, their associated
5663 predefined memory spaces and for the available traits and their default values,
5664 see @ref{OMP_ALLOCATOR}.  Predefined allocators without an associated memory
5665 space use the @code{omp_default_mem_space} memory space.
5667 For the memory spaces, the following applies:
5668 @itemize
5669 @item @code{omp_default_mem_space} is supported
5670 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
5671 @item @code{omp_low_lat_mem_space} maps to @code{omp_default_mem_space}
5672 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
5673       unless the memkind library is available
5674 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
5675       unless the memkind library is available
5676 @end itemize
5678 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
5679 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
5680 creating memory allocators requesting
5682 @itemize
5683 @item the memory space @code{omp_high_bw_mem_space}
5684 @item the memory space @code{omp_large_cap_mem_space}
5685 @item the @code{partition} trait @code{interleaved}; note that for
5686       @code{omp_large_cap_mem_space} the allocation will not be interleaved
5687 @end itemize
5689 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
5690 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
5691 memory allocators requesting
5693 @itemize
5694 @item the @code{partition} trait @code{nearest}, except when both the
5695 libmemkind library is available and the memory space is either
5696 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
5697 @end itemize
5699 Note that the numa library will round up the allocation size to a multiple of
5700 the system page size; therefore, consider using it only with large data or
5701 by sharing allocations via the @code{pool_size} trait.  Furthermore, the Linux
5702 kernel does not guarantee that an allocation will always be on the nearest NUMA
5703 node nor that after reallocation the same node will be used.  Note additionally
5704 that, on Linux, the default setting of the memory placement policy is to use the
5705 current node; therefore, unless the memory placement policy has been overridden,
5706 the @code{partition} trait @code{environment} (the default) will be effectively
5707 a @code{nearest} allocation.
5709 Additional notes regarding the traits:
5710 @itemize
5711 @item The @code{pinned} trait is unsupported.
5712 @item The default for the @code{pool_size} trait is no pool and for every
5713       (re)allocation the associated library routine is called, which might
5714       internally use a memory pool.
5715 @item For the @code{partition} trait, the partition part size will be the same
5716       as the requested size (i.e. @code{interleaved} or @code{blocked} has no
5717       effect), except for @code{interleaved} when the memkind library is
5718       available.  Furthermore, for @code{nearest} and unless the numa library
5719       is available, the memory might not be on the same NUMA node as thread
5720       that allocated the memory; on Linux, this is in particular the case when
5721       the memory placement policy is set to preferred.
5722 @item The @code{access} trait has no effect such that memory is always
5723       accessible by all threads.
5724 @item The @code{sync_hint} trait has no effect.
5725 @end itemize
5727 @c ---------------------------------------------------------------------
5728 @c Offload-Target Specifics
5729 @c ---------------------------------------------------------------------
5731 @node Offload-Target Specifics
5732 @chapter Offload-Target Specifics
5734 The following sections present notes on the offload-target specifics
5736 @menu
5737 * AMD Radeon::
5738 * nvptx::
5739 @end menu
5741 @node AMD Radeon
5742 @section AMD Radeon (GCN)
5744 On the hardware side, there is the hierarchy (fine to coarse):
5745 @itemize
5746 @item work item (thread)
5747 @item wavefront
5748 @item work group
5749 @item compute unit (CU)
5750 @end itemize
5752 All OpenMP and OpenACC levels are used, i.e.
5753 @itemize
5754 @item OpenMP's simd and OpenACC's vector map to work items (thread)
5755 @item OpenMP's threads (``parallel'') and OpenACC's workers map
5756       to wavefronts
5757 @item OpenMP's teams and OpenACC's gang use a threadpool with the
5758       size of the number of teams or gangs, respectively.
5759 @end itemize
5761 The used sizes are
5762 @itemize
5763 @item Number of teams is the specified @code{num_teams} (OpenMP) or
5764       @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
5765       by two times the number of CU.
5766 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
5767       @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
5768       overrides this if smaller.
5769 @item The wavefront has 102 scalars and 64 vectors
5770 @item Number of workitems is always 64
5771 @item The hardware permits maximally 40 workgroups/CU and
5772       16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
5773 @item 80 scalars registers and 24 vector registers in non-kernel functions
5774       (the chosen procedure-calling API).
5775 @item For the kernel itself: as many as register pressure demands (number of
5776       teams and number of threads, scaled down if registers are exhausted)
5777 @end itemize
5779 The implementation remark:
5780 @itemize
5781 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
5782       using the C library @code{printf} functions and the Fortran
5783       @code{print}/@code{write} statements.
5784 @item Reverse offload regions (i.e. @code{target} regions with
5785       @code{device(ancestor:1)}) are processed serially per @code{target} region
5786       such that the next reverse offload region is only executed after the previous
5787       one returned.
5788 @item OpenMP code that has a @code{requires} directive with
5789       @code{unified_shared_memory} will remove any GCN device from the list of
5790       available devices (``host fallback'').
5791 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
5792       environment variable; the default is 32 kiB per thread.
5793 @end itemize
5797 @node nvptx
5798 @section nvptx
5800 On the hardware side, there is the hierarchy (fine to coarse):
5801 @itemize
5802 @item thread
5803 @item warp
5804 @item thread block
5805 @item streaming multiprocessor
5806 @end itemize
5808 All OpenMP and OpenACC levels are used, i.e.
5809 @itemize
5810 @item OpenMP's simd and OpenACC's vector map to threads
5811 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
5812 @item OpenMP's teams and OpenACC's gang use a threadpool with the
5813       size of the number of teams or gangs, respectively.
5814 @end itemize
5816 The used sizes are
5817 @itemize
5818 @item The @code{warp_size} is always 32
5819 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
5820 @item The number of teams is limited by the number of blocks the device can
5821       host simultaneously.
5822 @end itemize
5824 Additional information can be obtained by setting the environment variable to
5825 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
5826 parameters).
5828 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
5829 which caches the JIT in the user's directory (see CUDA documentation; can be
5830 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
5832 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
5833 options still affect the used PTX ISA code and, thus, the requirements on
5834 CUDA version and hardware.
5836 The implementation remark:
5837 @itemize
5838 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
5839       using the C library @code{printf} functions. Note that the Fortran
5840       @code{print}/@code{write} statements are not supported, yet.
5841 @item Compilation OpenMP code that contains @code{requires reverse_offload}
5842       requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
5843       is not supported.
5844 @item For code containing reverse offload (i.e. @code{target} regions with
5845       @code{device(ancestor:1)}), there is a slight performance penalty
5846       for @emph{all} target regions, consisting mostly of shutdown delay
5847       Per device, reverse offload regions are processed serially such that
5848       the next reverse offload region is only executed after the previous
5849       one returned.
5850 @item OpenMP code that has a @code{requires} directive with
5851       @code{unified_shared_memory} will remove any nvptx device from the
5852       list of available devices (``host fallback'').
5853 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
5854       in the GCC manual.
5855 @item The OpenMP routines @code{omp_target_memcpy_rect} and
5856       @code{omp_target_memcpy_rect_async} and the @code{target update}
5857       directive for non-contiguous list items will use the 2D and 3D
5858       memory-copy functions of the CUDA library.  Higher dimensions will
5859       call those functions in a loop and are therefore supported.
5860 @end itemize
5863 @c ---------------------------------------------------------------------
5864 @c The libgomp ABI
5865 @c ---------------------------------------------------------------------
5867 @node The libgomp ABI
5868 @chapter The libgomp ABI
5870 The following sections present notes on the external ABI as 
5871 presented by libgomp.  Only maintainers should need them.
5873 @menu
5874 * Implementing MASTER construct::
5875 * Implementing CRITICAL construct::
5876 * Implementing ATOMIC construct::
5877 * Implementing FLUSH construct::
5878 * Implementing BARRIER construct::
5879 * Implementing THREADPRIVATE construct::
5880 * Implementing PRIVATE clause::
5881 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
5882 * Implementing REDUCTION clause::
5883 * Implementing PARALLEL construct::
5884 * Implementing FOR construct::
5885 * Implementing ORDERED construct::
5886 * Implementing SECTIONS construct::
5887 * Implementing SINGLE construct::
5888 * Implementing OpenACC's PARALLEL construct::
5889 @end menu
5892 @node Implementing MASTER construct
5893 @section Implementing MASTER construct
5895 @smallexample
5896 if (omp_get_thread_num () == 0)
5897   block
5898 @end smallexample
5900 Alternately, we generate two copies of the parallel subfunction
5901 and only include this in the version run by the primary thread.
5902 Surely this is not worthwhile though...
5906 @node Implementing CRITICAL construct
5907 @section Implementing CRITICAL construct
5909 Without a specified name,
5911 @smallexample
5912   void GOMP_critical_start (void);
5913   void GOMP_critical_end (void);
5914 @end smallexample
5916 so that we don't get COPY relocations from libgomp to the main
5917 application.
5919 With a specified name, use omp_set_lock and omp_unset_lock with
5920 name being transformed into a variable declared like
5922 @smallexample
5923   omp_lock_t gomp_critical_user_<name> __attribute__((common))
5924 @end smallexample
5926 Ideally the ABI would specify that all zero is a valid unlocked
5927 state, and so we wouldn't need to initialize this at
5928 startup.
5932 @node Implementing ATOMIC construct
5933 @section Implementing ATOMIC construct
5935 The target should implement the @code{__sync} builtins.
5937 Failing that we could add
5939 @smallexample
5940   void GOMP_atomic_enter (void)
5941   void GOMP_atomic_exit (void)
5942 @end smallexample
5944 which reuses the regular lock code, but with yet another lock
5945 object private to the library.
5949 @node Implementing FLUSH construct
5950 @section Implementing FLUSH construct
5952 Expands to the @code{__sync_synchronize} builtin.
5956 @node Implementing BARRIER construct
5957 @section Implementing BARRIER construct
5959 @smallexample
5960   void GOMP_barrier (void)
5961 @end smallexample
5964 @node Implementing THREADPRIVATE construct
5965 @section Implementing THREADPRIVATE construct
5967 In _most_ cases we can map this directly to @code{__thread}.  Except
5968 that OMP allows constructors for C++ objects.  We can either
5969 refuse to support this (how often is it used?) or we can 
5970 implement something akin to .ctors.
5972 Even more ideally, this ctor feature is handled by extensions
5973 to the main pthreads library.  Failing that, we can have a set
5974 of entry points to register ctor functions to be called.
5978 @node Implementing PRIVATE clause
5979 @section Implementing PRIVATE clause
5981 In association with a PARALLEL, or within the lexical extent
5982 of a PARALLEL block, the variable becomes a local variable in
5983 the parallel subfunction.
5985 In association with FOR or SECTIONS blocks, create a new
5986 automatic variable within the current function.  This preserves
5987 the semantic of new variable creation.
5991 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
5992 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
5994 This seems simple enough for PARALLEL blocks.  Create a private 
5995 struct for communicating between the parent and subfunction.
5996 In the parent, copy in values for scalar and "small" structs;
5997 copy in addresses for others TREE_ADDRESSABLE types.  In the 
5998 subfunction, copy the value into the local variable.
6000 It is not clear what to do with bare FOR or SECTION blocks.
6001 The only thing I can figure is that we do something like:
6003 @smallexample
6004 #pragma omp for firstprivate(x) lastprivate(y)
6005 for (int i = 0; i < n; ++i)
6006   body;
6007 @end smallexample
6009 which becomes
6011 @smallexample
6013   int x = x, y;
6015   // for stuff
6017   if (i == n)
6018     y = y;
6020 @end smallexample
6022 where the "x=x" and "y=y" assignments actually have different
6023 uids for the two variables, i.e. not something you could write
6024 directly in C.  Presumably this only makes sense if the "outer"
6025 x and y are global variables.
6027 COPYPRIVATE would work the same way, except the structure 
6028 broadcast would have to happen via SINGLE machinery instead.
6032 @node Implementing REDUCTION clause
6033 @section Implementing REDUCTION clause
6035 The private struct mentioned in the previous section should have 
6036 a pointer to an array of the type of the variable, indexed by the 
6037 thread's @var{team_id}.  The thread stores its final value into the 
6038 array, and after the barrier, the primary thread iterates over the
6039 array to collect the values.
6042 @node Implementing PARALLEL construct
6043 @section Implementing PARALLEL construct
6045 @smallexample
6046   #pragma omp parallel
6047   @{
6048     body;
6049   @}
6050 @end smallexample
6052 becomes
6054 @smallexample
6055   void subfunction (void *data)
6056   @{
6057     use data;
6058     body;
6059   @}
6061   setup data;
6062   GOMP_parallel_start (subfunction, &data, num_threads);
6063   subfunction (&data);
6064   GOMP_parallel_end ();
6065 @end smallexample
6067 @smallexample
6068   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
6069 @end smallexample
6071 The @var{FN} argument is the subfunction to be run in parallel.
6073 The @var{DATA} argument is a pointer to a structure used to 
6074 communicate data in and out of the subfunction, as discussed
6075 above with respect to FIRSTPRIVATE et al.
6077 The @var{NUM_THREADS} argument is 1 if an IF clause is present
6078 and false, or the value of the NUM_THREADS clause, if
6079 present, or 0.
6081 The function needs to create the appropriate number of
6082 threads and/or launch them from the dock.  It needs to
6083 create the team structure and assign team ids.
6085 @smallexample
6086   void GOMP_parallel_end (void)
6087 @end smallexample
6089 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
6093 @node Implementing FOR construct
6094 @section Implementing FOR construct
6096 @smallexample
6097   #pragma omp parallel for
6098   for (i = lb; i <= ub; i++)
6099     body;
6100 @end smallexample
6102 becomes
6104 @smallexample
6105   void subfunction (void *data)
6106   @{
6107     long _s0, _e0;
6108     while (GOMP_loop_static_next (&_s0, &_e0))
6109     @{
6110       long _e1 = _e0, i;
6111       for (i = _s0; i < _e1; i++)
6112         body;
6113     @}
6114     GOMP_loop_end_nowait ();
6115   @}
6117   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
6118   subfunction (NULL);
6119   GOMP_parallel_end ();
6120 @end smallexample
6122 @smallexample
6123   #pragma omp for schedule(runtime)
6124   for (i = 0; i < n; i++)
6125     body;
6126 @end smallexample
6128 becomes
6130 @smallexample
6131   @{
6132     long i, _s0, _e0;
6133     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
6134       do @{
6135         long _e1 = _e0;
6136         for (i = _s0, i < _e0; i++)
6137           body;
6138       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
6139     GOMP_loop_end ();
6140   @}
6141 @end smallexample
6143 Note that while it looks like there is trickiness to propagating
6144 a non-constant STEP, there isn't really.  We're explicitly allowed
6145 to evaluate it as many times as we want, and any variables involved
6146 should automatically be handled as PRIVATE or SHARED like any other
6147 variables.  So the expression should remain evaluable in the 
6148 subfunction.  We can also pull it into a local variable if we like,
6149 but since its supposed to remain unchanged, we can also not if we like.
6151 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
6152 able to get away with no work-sharing context at all, since we can
6153 simply perform the arithmetic directly in each thread to divide up
6154 the iterations.  Which would mean that we wouldn't need to call any
6155 of these routines.
6157 There are separate routines for handling loops with an ORDERED
6158 clause.  Bookkeeping for that is non-trivial...
6162 @node Implementing ORDERED construct
6163 @section Implementing ORDERED construct
6165 @smallexample
6166   void GOMP_ordered_start (void)
6167   void GOMP_ordered_end (void)
6168 @end smallexample
6172 @node Implementing SECTIONS construct
6173 @section Implementing SECTIONS construct
6175 A block as 
6177 @smallexample
6178   #pragma omp sections
6179   @{
6180     #pragma omp section
6181     stmt1;
6182     #pragma omp section
6183     stmt2;
6184     #pragma omp section
6185     stmt3;
6186   @}
6187 @end smallexample
6189 becomes
6191 @smallexample
6192   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
6193     switch (i)
6194       @{
6195       case 1:
6196         stmt1;
6197         break;
6198       case 2:
6199         stmt2;
6200         break;
6201       case 3:
6202         stmt3;
6203         break;
6204       @}
6205   GOMP_barrier ();
6206 @end smallexample
6209 @node Implementing SINGLE construct
6210 @section Implementing SINGLE construct
6212 A block like 
6214 @smallexample
6215   #pragma omp single
6216   @{
6217     body;
6218   @}
6219 @end smallexample
6221 becomes
6223 @smallexample
6224   if (GOMP_single_start ())
6225     body;
6226   GOMP_barrier ();
6227 @end smallexample
6229 while 
6231 @smallexample
6232   #pragma omp single copyprivate(x)
6233     body;
6234 @end smallexample
6236 becomes
6238 @smallexample
6239   datap = GOMP_single_copy_start ();
6240   if (datap == NULL)
6241     @{
6242       body;
6243       data.x = x;
6244       GOMP_single_copy_end (&data);
6245     @}
6246   else
6247     x = datap->x;
6248   GOMP_barrier ();
6249 @end smallexample
6253 @node Implementing OpenACC's PARALLEL construct
6254 @section Implementing OpenACC's PARALLEL construct
6256 @smallexample
6257   void GOACC_parallel ()
6258 @end smallexample
6262 @c ---------------------------------------------------------------------
6263 @c Reporting Bugs
6264 @c ---------------------------------------------------------------------
6266 @node Reporting Bugs
6267 @chapter Reporting Bugs
6269 Bugs in the GNU Offloading and Multi Processing Runtime Library should
6270 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
6271 "openacc", or "openmp", or both to the keywords field in the bug
6272 report, as appropriate.
6276 @c ---------------------------------------------------------------------
6277 @c GNU General Public License
6278 @c ---------------------------------------------------------------------
6280 @include gpl_v3.texi
6284 @c ---------------------------------------------------------------------
6285 @c GNU Free Documentation License
6286 @c ---------------------------------------------------------------------
6288 @include fdl.texi
6292 @c ---------------------------------------------------------------------
6293 @c Funding Free Software
6294 @c ---------------------------------------------------------------------
6296 @include funding.texi
6298 @c ---------------------------------------------------------------------
6299 @c Index
6300 @c ---------------------------------------------------------------------
6302 @node Library Index
6303 @unnumbered Library Index
6305 @printindex cp
6307 @bye