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