1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2023 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below). A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
24 (b) The FSF's Back-Cover Text is:
26 You have freedom to copy and modify this GNU Manual, like GNU
27 software. Copies published by the Free Software Foundation raise
28 funds for GNU development.
32 @dircategory GNU Libraries
34 * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library. This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
71 @node Top, Enabling OpenMP
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library. This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
84 Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
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.
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
102 * OpenMP Environment Variables: Environment Variables.
103 Influencing OpenMP runtime behavior with
104 environment variables.
105 * Enabling OpenACC:: How to enable OpenACC for your
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
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
128 * Library Index:: Index of this documentation.
132 @c ---------------------------------------------------------------------
134 @c ---------------------------------------------------------------------
136 @node Enabling OpenMP
137 @chapter Enabling OpenMP
139 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
140 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
141 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
142 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
143 @code{!$} conditional compilation sentinels in free form and @code{c$},
144 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
145 arranges for automatic linking of the OpenMP runtime library
146 (@ref{Runtime Library Routines}).
148 A complete description of all OpenMP directives may be found in the
149 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
150 See also @ref{OpenMP Implementation Status}.
153 @c ---------------------------------------------------------------------
154 @c OpenMP Implementation Status
155 @c ---------------------------------------------------------------------
157 @node OpenMP Implementation Status
158 @chapter OpenMP Implementation Status
161 * OpenMP 4.5:: Feature completion status to 4.5 specification
162 * OpenMP 5.0:: Feature completion status to 5.0 specification
163 * OpenMP 5.1:: Feature completion status to 5.1 specification
164 * OpenMP 5.2:: Feature completion status to 5.2 specification
165 * OpenMP Technical Report 11:: Feature completion status to first 6.0 preview
168 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
169 parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
170 the value @code{201511} (i.e. OpenMP 4.5).
175 The OpenMP 4.5 specification is fully supported.
180 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
181 @c This list is sorted as in OpenMP 5.1's B.3 not as in OpenMP 5.0's B.2
183 @multitable @columnfractions .60 .10 .25
184 @headitem Description @tab Status @tab Comments
185 @item Array shaping @tab N @tab
186 @item Array sections with non-unit strides in C and C++ @tab N @tab
187 @item Iterators @tab Y @tab
188 @item @code{metadirective} directive @tab N @tab
189 @item @code{declare variant} directive
190 @tab P @tab @emph{simd} traits not handled correctly
191 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
192 env variable @tab Y @tab
193 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
194 @item @code{requires} directive @tab P
195 @tab complete but no non-host device provides @code{unified_shared_memory}
196 @item @code{teams} construct outside an enclosing target region @tab Y @tab
197 @item Non-rectangular loop nests @tab P
198 @tab Full support for C/C++, partial for Fortran
199 (@uref{https://gcc.gnu.org/PR110735,PR110735})
200 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
201 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
202 constructs @tab Y @tab
203 @item Collapse of associated loops that are imperfectly nested loops @tab Y @tab
204 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
205 @code{simd} construct @tab Y @tab
206 @item @code{atomic} constructs in @code{simd} @tab Y @tab
207 @item @code{loop} construct @tab Y @tab
208 @item @code{order(concurrent)} clause @tab Y @tab
209 @item @code{scan} directive and @code{in_scan} modifier for the
210 @code{reduction} clause @tab Y @tab
211 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
212 @item @code{in_reduction} clause on @code{target} constructs @tab P
213 @tab @code{nowait} only stub
214 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
215 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
216 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
217 @item @code{detach} clause to @code{task} construct @tab Y @tab
218 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
219 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
220 and @code{taskloop simd} constructs @tab Y @tab
221 @item @code{taskloop} construct cancelable by @code{cancel} construct
223 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
225 @item Predefined memory spaces, memory allocators, allocator traits
226 @tab Y @tab See also @ref{Memory allocation}
227 @item Memory management routines @tab Y @tab
228 @item @code{allocate} directive @tab N @tab
229 @item @code{allocate} clause @tab P @tab Initial support
230 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
231 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
232 @item Implicit declare target directive @tab Y @tab
233 @item Discontiguous array section with @code{target update} construct
235 @item C/C++'s lvalue expressions in @code{to}, @code{from}
236 and @code{map} clauses @tab N @tab
237 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
238 @item Nested @code{declare target} directive @tab Y @tab
239 @item Combined @code{master} constructs @tab Y @tab
240 @item @code{depend} clause on @code{taskwait} @tab Y @tab
241 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
243 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
244 @item @code{depobj} construct and depend objects @tab Y @tab
245 @item Lock hints were renamed to synchronization hints @tab Y @tab
246 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
247 @item Map-order clarifications @tab P @tab
248 @item @code{close} @emph{map-type-modifier} @tab Y @tab
249 @item Mapping C/C++ pointer variables and to assign the address of
250 device memory mapped by an array section @tab P @tab
251 @item Mapping of Fortran pointer and allocatable variables, including pointer
252 and allocatable components of variables
253 @tab P @tab Mapping of vars with allocatable components unsupported
254 @item @code{defaultmap} extensions @tab Y @tab
255 @item @code{declare mapper} directive @tab N @tab
256 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
257 @item Runtime routines and environment variables to display runtime thread
258 affinity information @tab Y @tab
259 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
261 @item @code{omp_get_device_num} runtime routine @tab Y @tab
262 @item OMPT interface @tab N @tab
263 @item OMPD interface @tab N @tab
266 @unnumberedsubsec Other new OpenMP 5.0 features
268 @multitable @columnfractions .60 .10 .25
269 @headitem Description @tab Status @tab Comments
270 @item Supporting C++'s range-based for loop @tab Y @tab
277 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
279 @multitable @columnfractions .60 .10 .25
280 @headitem Description @tab Status @tab Comments
281 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
282 @item @code{omp_all_memory} reserved locator @tab Y @tab
283 @item @emph{target_device trait} in OpenMP Context @tab N @tab
284 @item @code{target_device} selector set in context selectors @tab N @tab
285 @item C/C++'s @code{declare variant} directive: elision support of
286 preprocessed code @tab N @tab
287 @item @code{declare variant}: new clauses @code{adjust_args} and
288 @code{append_args} @tab N @tab
289 @item @code{dispatch} construct @tab N @tab
290 @item device-specific ICV settings with environment variables @tab Y @tab
291 @item @code{assume} and @code{assumes} directives @tab Y @tab
292 @item @code{nothing} directive @tab Y @tab
293 @item @code{error} directive @tab Y @tab
294 @item @code{masked} construct @tab Y @tab
295 @item @code{scope} directive @tab Y @tab
296 @item Loop transformation constructs @tab N @tab
297 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
298 clauses of the @code{taskloop} construct @tab Y @tab
299 @item @code{align} clause in @code{allocate} directive @tab N @tab
300 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
301 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
302 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
303 @item Iterators in @code{target update} motion clauses and @code{map}
305 @item Indirect calls to the device version of a procedure or function in
306 @code{target} regions @tab N @tab
307 @item @code{interop} directive @tab N @tab
308 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
309 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
310 @item Extensions to the @code{atomic} directive @tab Y @tab
311 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
312 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
313 @item @code{private} and @code{firstprivate} argument to @code{default}
314 clause in C and C++ @tab Y @tab
315 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
316 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
317 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
319 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
320 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
321 runtime routines @tab Y @tab
322 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
323 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
324 @code{omp_aligned_calloc} runtime routines @tab Y @tab
325 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
326 @code{omp_atv_default} changed @tab Y @tab
327 @item @code{omp_display_env} runtime routine @tab Y @tab
328 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
329 @item @code{ompt_sync_region_t} enum additions @tab N @tab
330 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
331 and @code{ompt_state_wait_barrier_teams} @tab N @tab
332 @item @code{ompt_callback_target_data_op_emi_t},
333 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
334 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
335 @item @code{ompt_callback_error_t} type @tab N @tab
336 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
337 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
338 variables @tab Y @tab
341 @unnumberedsubsec Other new OpenMP 5.1 features
343 @multitable @columnfractions .60 .10 .25
344 @headitem Description @tab Status @tab Comments
345 @item Support of strictly structured blocks in Fortran @tab Y @tab
346 @item Support of structured block sequences in C/C++ @tab Y @tab
347 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
349 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
350 @item Pointer predetermined firstprivate getting initialized
351 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
352 @item For Fortran, diagnose placing declarative before/between @code{USE},
353 @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
354 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
355 @item @code{indirect} clause in @code{declare target} @tab N @tab
356 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
357 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
365 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
367 @multitable @columnfractions .60 .10 .25
368 @headitem Description @tab Status @tab Comments
369 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
371 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
373 @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
374 sentinel as C/C++ pragma and C++ attributes are warned for with
375 @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
376 (enabled by default), respectively; for Fortran free-source code, there is
377 a warning enabled by default and, for fixed-source code, the @code{omx}
378 sentinel is warned for with with @code{-Wsurprising} (enabled by
379 @code{-Wall}). Unknown clauses are always rejected with an error.}
380 @item Clauses on @code{end} directive can be on directive @tab Y @tab
381 @item @code{destroy} clause with destroy-var argument on @code{depobj}
383 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
385 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
386 @item Deprecation of minus operator for reductions @tab N @tab
387 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
388 @item @code{declare mapper} with iterator and @code{present} modifiers
390 @item If a matching mapped list item is not found in the data environment, the
391 pointer retains its original value @tab Y @tab
392 @item New @code{enter} clause as alias for @code{to} on declare target directive
394 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
395 @item Extended list of directives permitted in Fortran pure procedures
397 @item New @code{allocators} directive for Fortran @tab N @tab
398 @item Deprecation of @code{allocate} directive for Fortran
399 allocatables/pointers @tab N @tab
400 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
401 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
403 @item Deprecation of traits array following the allocator_handle expression in
404 @code{uses_allocators} @tab N @tab
405 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
407 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
408 @item Deprecation of delimited form of @code{declare target} @tab N @tab
409 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
410 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
412 @item @code{ompt_callback_work} @tab N @tab
413 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
415 @item New @code{doacross} clause as alias for @code{depend} with
416 @code{source}/@code{sink} modifier @tab Y @tab
417 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
419 @item @code{omp_cur_iteration} keyword @tab Y @tab
422 @unnumberedsubsec Other new OpenMP 5.2 features
424 @multitable @columnfractions .60 .10 .25
425 @headitem Description @tab Status @tab Comments
426 @item For Fortran, optional comma between directive and clause @tab N @tab
427 @item Conforming device numbers and @code{omp_initial_device} and
428 @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
429 @item Initial value of @var{default-device-var} ICV with
430 @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
431 @item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
432 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
433 of the @code{interop} construct @tab N @tab
437 @node OpenMP Technical Report 11
438 @section OpenMP Technical Report 11
440 Technical Report (TR) 11 is the first preview for OpenMP 6.0.
442 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
443 @multitable @columnfractions .60 .10 .25
444 @item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
445 @tab N/A @tab Backward compatibility
446 @item The @code{decl} attribute was added to the C++ attribute syntax
448 @item @code{_ALL} suffix to the device-scope environment variables
449 @tab P @tab Host device number wrongly accepted
450 @item For Fortran, @emph{locator list} can be also function reference with
451 data pointer result @tab N @tab
452 @item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
454 @item Implicit reduction identifiers of C++ classes
456 @item Change of the @emph{map-type} property from @emph{ultimate} to
457 @emph{default} @tab N @tab
458 @item Concept of @emph{assumed-size arrays} in C and C++
460 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
462 @item @code{groupprivate} directive @tab N @tab
463 @item @code{local} clause to declare target directive @tab N @tab
464 @item @code{part_size} allocator trait @tab N @tab
465 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
468 @item @code{access} allocator trait changes @tab N @tab
469 @item Extension of @code{interop} operation of @code{append_args}, allowing all
470 modifiers of the @code{init} clause
472 @item @code{interop} clause to @code{dispatch} @tab N @tab
473 @item @code{apply} code to loop-transforming constructs @tab N @tab
474 @item @code{omp_curr_progress_width} identifier @tab N @tab
475 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
476 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
477 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
478 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
479 @item Routines for obtaining memory spaces/allocators for shared/device memory
481 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
482 @item @code{omp_get_submemspace} routine @tab N @tab
483 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
484 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
485 @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
486 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
489 @unnumberedsubsec Other new TR 11 features
490 @multitable @columnfractions .60 .10 .25
491 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
492 @item Mapping lambda captures @tab N @tab
493 @item For Fortran, atomic compare with storing the comparison result
499 @c ---------------------------------------------------------------------
500 @c OpenMP Runtime Library Routines
501 @c ---------------------------------------------------------------------
503 @node Runtime Library Routines
504 @chapter OpenMP Runtime Library Routines
506 The runtime routines described here are defined by Section 18 of the OpenMP
507 specification in version 5.2.
510 * Thread Team Routines::
511 * Thread Affinity Routines::
512 * Teams Region Routines::
514 @c * Resource Relinquishing Routines::
515 * Device Information Routines::
516 @c * Device Memory Routines::
520 @c * Interoperability Routines::
521 * Memory Management Routines::
522 @c * Tool Control Routine::
523 @c * Environment Display Routine::
528 @node Thread Team Routines
529 @section Thread Team Routines
531 Routines controlling threads in the current contention group.
532 They have C linkage and do not throw exceptions.
535 * omp_set_num_threads:: Set upper team size limit
536 * omp_get_num_threads:: Size of the active team
537 * omp_get_max_threads:: Maximum number of threads of parallel region
538 * omp_get_thread_num:: Current thread ID
539 * omp_in_parallel:: Whether a parallel region is active
540 * omp_set_dynamic:: Enable/disable dynamic teams
541 * omp_get_dynamic:: Dynamic teams setting
542 * omp_get_cancellation:: Whether cancellation support is enabled
543 * omp_set_nested:: Enable/disable nested parallel regions
544 * omp_get_nested:: Nested parallel regions
545 * omp_set_schedule:: Set the runtime scheduling method
546 * omp_get_schedule:: Obtain the runtime scheduling method
547 * omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
548 * omp_get_supported_active_levels:: Maximum number of active regions supported
549 * omp_set_max_active_levels:: Limits the number of active parallel regions
550 * omp_get_max_active_levels:: Current maximum number of active regions
551 * omp_get_level:: Number of parallel regions
552 * omp_get_ancestor_thread_num:: Ancestor thread ID
553 * omp_get_team_size:: Number of threads in a team
554 * omp_get_active_level:: Number of active parallel regions
559 @node omp_set_num_threads
560 @subsection @code{omp_set_num_threads} -- Set upper team size limit
562 @item @emph{Description}:
563 Specifies the number of threads used by default in subsequent parallel
564 sections, if those do not specify a @code{num_threads} clause. The
565 argument of @code{omp_set_num_threads} shall be a positive integer.
568 @multitable @columnfractions .20 .80
569 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
572 @item @emph{Fortran}:
573 @multitable @columnfractions .20 .80
574 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
575 @item @tab @code{integer, intent(in) :: num_threads}
578 @item @emph{See also}:
579 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
581 @item @emph{Reference}:
582 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
587 @node omp_get_num_threads
588 @subsection @code{omp_get_num_threads} -- Size of the active team
590 @item @emph{Description}:
591 Returns the number of threads in the current team. In a sequential section of
592 the program @code{omp_get_num_threads} returns 1.
594 The default team size may be initialized at startup by the
595 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
596 of the current team may be set either by the @code{NUM_THREADS}
597 clause or by @code{omp_set_num_threads}. If none of the above were
598 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
599 one thread per CPU online is used.
602 @multitable @columnfractions .20 .80
603 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
606 @item @emph{Fortran}:
607 @multitable @columnfractions .20 .80
608 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
611 @item @emph{See also}:
612 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
614 @item @emph{Reference}:
615 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
620 @node omp_get_max_threads
621 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
623 @item @emph{Description}:
624 Return the maximum number of threads used for the current parallel region
625 that does not use the clause @code{num_threads}.
628 @multitable @columnfractions .20 .80
629 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
632 @item @emph{Fortran}:
633 @multitable @columnfractions .20 .80
634 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
637 @item @emph{See also}:
638 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
640 @item @emph{Reference}:
641 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
646 @node omp_get_thread_num
647 @subsection @code{omp_get_thread_num} -- Current thread ID
649 @item @emph{Description}:
650 Returns a unique thread identification number within the current team.
651 In a sequential parts of the program, @code{omp_get_thread_num}
652 always returns 0. In parallel regions the return value varies
653 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
654 value of the primary thread of a team is always 0.
657 @multitable @columnfractions .20 .80
658 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
661 @item @emph{Fortran}:
662 @multitable @columnfractions .20 .80
663 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
666 @item @emph{See also}:
667 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
669 @item @emph{Reference}:
670 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
675 @node omp_in_parallel
676 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
678 @item @emph{Description}:
679 This function returns @code{true} if currently running in parallel,
680 @code{false} otherwise. Here, @code{true} and @code{false} represent
681 their language-specific counterparts.
684 @multitable @columnfractions .20 .80
685 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
688 @item @emph{Fortran}:
689 @multitable @columnfractions .20 .80
690 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
693 @item @emph{Reference}:
694 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
698 @node omp_set_dynamic
699 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
701 @item @emph{Description}:
702 Enable or disable the dynamic adjustment of the number of threads
703 within a team. The function takes the language-specific equivalent
704 of @code{true} and @code{false}, where @code{true} enables dynamic
705 adjustment of team sizes and @code{false} disables it.
708 @multitable @columnfractions .20 .80
709 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
712 @item @emph{Fortran}:
713 @multitable @columnfractions .20 .80
714 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
715 @item @tab @code{logical, intent(in) :: dynamic_threads}
718 @item @emph{See also}:
719 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
721 @item @emph{Reference}:
722 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
727 @node omp_get_dynamic
728 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
730 @item @emph{Description}:
731 This function returns @code{true} if enabled, @code{false} otherwise.
732 Here, @code{true} and @code{false} represent their language-specific
735 The dynamic team setting may be initialized at startup by the
736 @env{OMP_DYNAMIC} environment variable or at runtime using
737 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
741 @multitable @columnfractions .20 .80
742 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
745 @item @emph{Fortran}:
746 @multitable @columnfractions .20 .80
747 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
750 @item @emph{See also}:
751 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
753 @item @emph{Reference}:
754 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
759 @node omp_get_cancellation
760 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
762 @item @emph{Description}:
763 This function returns @code{true} if cancellation is activated, @code{false}
764 otherwise. Here, @code{true} and @code{false} represent their language-specific
765 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
769 @multitable @columnfractions .20 .80
770 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
773 @item @emph{Fortran}:
774 @multitable @columnfractions .20 .80
775 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
778 @item @emph{See also}:
779 @ref{OMP_CANCELLATION}
781 @item @emph{Reference}:
782 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
788 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
790 @item @emph{Description}:
791 Enable or disable nested parallel regions, i.e., whether team members
792 are allowed to create new teams. The function takes the language-specific
793 equivalent of @code{true} and @code{false}, where @code{true} enables
794 dynamic adjustment of team sizes and @code{false} disables it.
796 Enabling nested parallel regions will also set the maximum number of
797 active nested regions to the maximum supported. Disabling nested parallel
798 regions will set the maximum number of active nested regions to one.
800 Note that the @code{omp_set_nested} API routine was deprecated
801 in the OpenMP specification 5.2 in favor of @code{omp_set_max_active_levels}.
804 @multitable @columnfractions .20 .80
805 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
808 @item @emph{Fortran}:
809 @multitable @columnfractions .20 .80
810 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
811 @item @tab @code{logical, intent(in) :: nested}
814 @item @emph{See also}:
815 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
816 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
818 @item @emph{Reference}:
819 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
825 @subsection @code{omp_get_nested} -- Nested parallel regions
827 @item @emph{Description}:
828 This function returns @code{true} if nested parallel regions are
829 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
830 represent their language-specific counterparts.
832 The state of nested parallel regions at startup depends on several
833 environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
834 and is set to greater than one, then nested parallel regions will be
835 enabled. If not defined, then the value of the @env{OMP_NESTED}
836 environment variable will be followed if defined. If neither are
837 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
838 are defined with a list of more than one value, then nested parallel
839 regions are enabled. If none of these are defined, then nested parallel
840 regions are disabled by default.
842 Nested parallel regions can be enabled or disabled at runtime using
843 @code{omp_set_nested}, or by setting the maximum number of nested
844 regions with @code{omp_set_max_active_levels} to one to disable, or
847 Note that the @code{omp_get_nested} API routine was deprecated
848 in the OpenMP specification 5.2 in favor of @code{omp_get_max_active_levels}.
851 @multitable @columnfractions .20 .80
852 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
855 @item @emph{Fortran}:
856 @multitable @columnfractions .20 .80
857 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
860 @item @emph{See also}:
861 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
862 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
864 @item @emph{Reference}:
865 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
870 @node omp_set_schedule
871 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
873 @item @emph{Description}:
874 Sets the runtime scheduling method. The @var{kind} argument can have the
875 value @code{omp_sched_static}, @code{omp_sched_dynamic},
876 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
877 @code{omp_sched_auto}, the chunk size is set to the value of
878 @var{chunk_size} if positive, or to the default value if zero or negative.
879 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
882 @multitable @columnfractions .20 .80
883 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
886 @item @emph{Fortran}:
887 @multitable @columnfractions .20 .80
888 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
889 @item @tab @code{integer(kind=omp_sched_kind) kind}
890 @item @tab @code{integer chunk_size}
893 @item @emph{See also}:
894 @ref{omp_get_schedule}
897 @item @emph{Reference}:
898 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
903 @node omp_get_schedule
904 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
906 @item @emph{Description}:
907 Obtain the runtime scheduling method. The @var{kind} argument will be
908 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
909 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
910 @var{chunk_size}, is set to the chunk size.
913 @multitable @columnfractions .20 .80
914 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
917 @item @emph{Fortran}:
918 @multitable @columnfractions .20 .80
919 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
920 @item @tab @code{integer(kind=omp_sched_kind) kind}
921 @item @tab @code{integer chunk_size}
924 @item @emph{See also}:
925 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
927 @item @emph{Reference}:
928 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
932 @node omp_get_teams_thread_limit
933 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
935 @item @emph{Description}:
936 Return the maximum number of threads that will be able to participate in
937 each team created by a teams construct.
940 @multitable @columnfractions .20 .80
941 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
944 @item @emph{Fortran}:
945 @multitable @columnfractions .20 .80
946 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
949 @item @emph{See also}:
950 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
952 @item @emph{Reference}:
953 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
958 @node omp_get_supported_active_levels
959 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
961 @item @emph{Description}:
962 This function returns the maximum number of nested, active parallel regions
963 supported by this implementation.
966 @multitable @columnfractions .20 .80
967 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
970 @item @emph{Fortran}:
971 @multitable @columnfractions .20 .80
972 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
975 @item @emph{See also}:
976 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
978 @item @emph{Reference}:
979 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
984 @node omp_set_max_active_levels
985 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
987 @item @emph{Description}:
988 This function limits the maximum allowed number of nested, active
989 parallel regions. @var{max_levels} must be less or equal to
990 the value returned by @code{omp_get_supported_active_levels}.
993 @multitable @columnfractions .20 .80
994 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
997 @item @emph{Fortran}:
998 @multitable @columnfractions .20 .80
999 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1000 @item @tab @code{integer max_levels}
1003 @item @emph{See also}:
1004 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1005 @ref{omp_get_supported_active_levels}
1007 @item @emph{Reference}:
1008 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1013 @node omp_get_max_active_levels
1014 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1016 @item @emph{Description}:
1017 This function obtains the maximum allowed number of nested, active parallel regions.
1020 @multitable @columnfractions .20 .80
1021 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1024 @item @emph{Fortran}:
1025 @multitable @columnfractions .20 .80
1026 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1029 @item @emph{See also}:
1030 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1032 @item @emph{Reference}:
1033 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1038 @subsection @code{omp_get_level} -- Obtain the current nesting level
1040 @item @emph{Description}:
1041 This function returns the nesting level for the parallel blocks,
1042 which enclose the calling call.
1045 @multitable @columnfractions .20 .80
1046 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1049 @item @emph{Fortran}:
1050 @multitable @columnfractions .20 .80
1051 @item @emph{Interface}: @tab @code{integer function omp_level()}
1054 @item @emph{See also}:
1055 @ref{omp_get_active_level}
1057 @item @emph{Reference}:
1058 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1063 @node omp_get_ancestor_thread_num
1064 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1066 @item @emph{Description}:
1067 This function returns the thread identification number for the given
1068 nesting level of the current thread. For values of @var{level} outside
1069 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1070 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1073 @multitable @columnfractions .20 .80
1074 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1077 @item @emph{Fortran}:
1078 @multitable @columnfractions .20 .80
1079 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1080 @item @tab @code{integer level}
1083 @item @emph{See also}:
1084 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1086 @item @emph{Reference}:
1087 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1092 @node omp_get_team_size
1093 @subsection @code{omp_get_team_size} -- Number of threads in a team
1095 @item @emph{Description}:
1096 This function returns the number of threads in a thread team to which
1097 either the current thread or its ancestor belongs. For values of @var{level}
1098 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1099 1 is returned, and for @code{omp_get_level}, the result is identical
1100 to @code{omp_get_num_threads}.
1103 @multitable @columnfractions .20 .80
1104 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1107 @item @emph{Fortran}:
1108 @multitable @columnfractions .20 .80
1109 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1110 @item @tab @code{integer level}
1113 @item @emph{See also}:
1114 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1116 @item @emph{Reference}:
1117 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1122 @node omp_get_active_level
1123 @subsection @code{omp_get_active_level} -- Number of parallel regions
1125 @item @emph{Description}:
1126 This function returns the nesting level for the active parallel blocks,
1127 which enclose the calling call.
1130 @multitable @columnfractions .20 .80
1131 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1134 @item @emph{Fortran}:
1135 @multitable @columnfractions .20 .80
1136 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1139 @item @emph{See also}:
1140 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1142 @item @emph{Reference}:
1143 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1148 @node Thread Affinity Routines
1149 @section Thread Affinity Routines
1151 Routines controlling and accessing thread-affinity policies.
1152 They have C linkage and do not throw exceptions.
1155 * omp_get_proc_bind:: Whether threads may be moved between CPUs
1156 @c * omp_get_num_places:: <fixme>
1157 @c * omp_get_place_num_procs:: <fixme>
1158 @c * omp_get_place_proc_ids:: <fixme>
1159 @c * omp_get_place_num:: <fixme>
1160 @c * omp_get_partition_num_places:: <fixme>
1161 @c * omp_get_partition_place_nums:: <fixme>
1162 @c * omp_set_affinity_format:: <fixme>
1163 @c * omp_get_affinity_format:: <fixme>
1164 @c * omp_display_affinity:: <fixme>
1165 @c * omp_capture_affinity:: <fixme>
1170 @node omp_get_proc_bind
1171 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1173 @item @emph{Description}:
1174 This functions returns the currently active thread affinity policy, which is
1175 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1176 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1177 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1178 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1181 @multitable @columnfractions .20 .80
1182 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1185 @item @emph{Fortran}:
1186 @multitable @columnfractions .20 .80
1187 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1190 @item @emph{See also}:
1191 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1193 @item @emph{Reference}:
1194 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1199 @node Teams Region Routines
1200 @section Teams Region Routines
1202 Routines controlling the league of teams that are executed in a @code{teams}
1203 region. They have C linkage and do not throw exceptions.
1206 * omp_get_num_teams:: Number of teams
1207 * omp_get_team_num:: Get team number
1208 * omp_set_num_teams:: Set upper teams limit for teams region
1209 * omp_get_max_teams:: Maximum number of teams for teams region
1210 * omp_set_teams_thread_limit:: Set upper thread limit for teams construct
1211 * omp_get_thread_limit:: Maximum number of threads
1216 @node omp_get_num_teams
1217 @subsection @code{omp_get_num_teams} -- Number of teams
1219 @item @emph{Description}:
1220 Returns the number of teams in the current team region.
1223 @multitable @columnfractions .20 .80
1224 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1227 @item @emph{Fortran}:
1228 @multitable @columnfractions .20 .80
1229 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1232 @item @emph{Reference}:
1233 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1238 @node omp_get_team_num
1239 @subsection @code{omp_get_team_num} -- Get team number
1241 @item @emph{Description}:
1242 Returns the team number of the calling thread.
1245 @multitable @columnfractions .20 .80
1246 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1249 @item @emph{Fortran}:
1250 @multitable @columnfractions .20 .80
1251 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1254 @item @emph{Reference}:
1255 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1260 @node omp_set_num_teams
1261 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1263 @item @emph{Description}:
1264 Specifies the upper bound for number of teams created by the teams construct
1265 which does not specify a @code{num_teams} clause. The
1266 argument of @code{omp_set_num_teams} shall be a positive integer.
1269 @multitable @columnfractions .20 .80
1270 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1273 @item @emph{Fortran}:
1274 @multitable @columnfractions .20 .80
1275 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1276 @item @tab @code{integer, intent(in) :: num_teams}
1279 @item @emph{See also}:
1280 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1282 @item @emph{Reference}:
1283 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1288 @node omp_get_max_teams
1289 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1291 @item @emph{Description}:
1292 Return the maximum number of teams used for the teams region
1293 that does not use the clause @code{num_teams}.
1296 @multitable @columnfractions .20 .80
1297 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1300 @item @emph{Fortran}:
1301 @multitable @columnfractions .20 .80
1302 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1305 @item @emph{See also}:
1306 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1308 @item @emph{Reference}:
1309 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1314 @node omp_set_teams_thread_limit
1315 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1317 @item @emph{Description}:
1318 Specifies the upper bound for number of threads that will be available
1319 for each team created by the teams construct which does not specify a
1320 @code{thread_limit} clause. The argument of
1321 @code{omp_set_teams_thread_limit} shall be a positive integer.
1324 @multitable @columnfractions .20 .80
1325 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1328 @item @emph{Fortran}:
1329 @multitable @columnfractions .20 .80
1330 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1331 @item @tab @code{integer, intent(in) :: thread_limit}
1334 @item @emph{See also}:
1335 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1337 @item @emph{Reference}:
1338 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1343 @node omp_get_thread_limit
1344 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1346 @item @emph{Description}:
1347 Return the maximum number of threads of the program.
1350 @multitable @columnfractions .20 .80
1351 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1354 @item @emph{Fortran}:
1355 @multitable @columnfractions .20 .80
1356 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1359 @item @emph{See also}:
1360 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1362 @item @emph{Reference}:
1363 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1368 @node Tasking Routines
1369 @section Tasking Routines
1371 Routines relating to explicit tasks.
1372 They have C linkage and do not throw exceptions.
1375 * omp_get_max_task_priority:: Maximum task priority value that can be set
1376 * omp_in_explicit_task:: Whether a given task is an explicit task
1377 * omp_in_final:: Whether in final or included task region
1382 @node omp_get_max_task_priority
1383 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1384 that can be set for tasks.
1386 @item @emph{Description}:
1387 This function obtains the maximum allowed priority number for tasks.
1390 @multitable @columnfractions .20 .80
1391 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1394 @item @emph{Fortran}:
1395 @multitable @columnfractions .20 .80
1396 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1399 @item @emph{Reference}:
1400 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1405 @node omp_in_explicit_task
1406 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1408 @item @emph{Description}:
1409 The function returns the @var{explicit-task-var} ICV; it returns true when the
1410 encountering task was generated by a task-generating construct such as
1411 @code{target}, @code{task} or @code{taskloop}. Otherwise, the encountering task
1412 is in an implicit task region such as generated by the implicit or explicit
1413 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1416 @multitable @columnfractions .20 .80
1417 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1420 @item @emph{Fortran}:
1421 @multitable @columnfractions .20 .80
1422 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1425 @item @emph{Reference}:
1426 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1432 @subsection @code{omp_in_final} -- Whether in final or included task region
1434 @item @emph{Description}:
1435 This function returns @code{true} if currently running in a final
1436 or included task region, @code{false} otherwise. Here, @code{true}
1437 and @code{false} represent their language-specific counterparts.
1440 @multitable @columnfractions .20 .80
1441 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1444 @item @emph{Fortran}:
1445 @multitable @columnfractions .20 .80
1446 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1449 @item @emph{Reference}:
1450 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1455 @c @node Resource Relinquishing Routines
1456 @c @section Resource Relinquishing Routines
1458 @c Routines releasing resources used by the OpenMP runtime.
1459 @c They have C linkage and do not throw exceptions.
1462 @c * omp_pause_resource:: <fixme>
1463 @c * omp_pause_resource_all:: <fixme>
1466 @node Device Information Routines
1467 @section Device Information Routines
1469 Routines related to devices available to an OpenMP program.
1470 They have C linkage and do not throw exceptions.
1473 * omp_get_num_procs:: Number of processors online
1474 @c * omp_get_max_progress_width:: <fixme>/TR11
1475 * omp_set_default_device:: Set the default device for target regions
1476 * omp_get_default_device:: Get the default device for target regions
1477 * omp_get_num_devices:: Number of target devices
1478 * omp_get_device_num:: Get device that current thread is running on
1479 * omp_is_initial_device:: Whether executing on the host device
1480 * omp_get_initial_device:: Device number of host device
1485 @node omp_get_num_procs
1486 @subsection @code{omp_get_num_procs} -- Number of processors online
1488 @item @emph{Description}:
1489 Returns the number of processors online on that device.
1492 @multitable @columnfractions .20 .80
1493 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1496 @item @emph{Fortran}:
1497 @multitable @columnfractions .20 .80
1498 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1501 @item @emph{Reference}:
1502 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1507 @node omp_set_default_device
1508 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1510 @item @emph{Description}:
1511 Set the default device for target regions without device clause. The argument
1512 shall be a nonnegative device number.
1515 @multitable @columnfractions .20 .80
1516 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1519 @item @emph{Fortran}:
1520 @multitable @columnfractions .20 .80
1521 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1522 @item @tab @code{integer device_num}
1525 @item @emph{See also}:
1526 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1528 @item @emph{Reference}:
1529 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1534 @node omp_get_default_device
1535 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1537 @item @emph{Description}:
1538 Get the default device for target regions without device clause.
1541 @multitable @columnfractions .20 .80
1542 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1545 @item @emph{Fortran}:
1546 @multitable @columnfractions .20 .80
1547 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1550 @item @emph{See also}:
1551 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
1553 @item @emph{Reference}:
1554 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1559 @node omp_get_num_devices
1560 @subsection @code{omp_get_num_devices} -- Number of target devices
1562 @item @emph{Description}:
1563 Returns the number of target devices.
1566 @multitable @columnfractions .20 .80
1567 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1570 @item @emph{Fortran}:
1571 @multitable @columnfractions .20 .80
1572 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1575 @item @emph{Reference}:
1576 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1581 @node omp_get_device_num
1582 @subsection @code{omp_get_device_num} -- Return device number of current device
1584 @item @emph{Description}:
1585 This function returns a device number that represents the device that the
1586 current thread is executing on. For OpenMP 5.0, this must be equal to the
1587 value returned by the @code{omp_get_initial_device} function when called
1591 @multitable @columnfractions .20 .80
1592 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1595 @item @emph{Fortran}:
1596 @multitable @columnfractions .20 .80
1597 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1600 @item @emph{See also}:
1601 @ref{omp_get_initial_device}
1603 @item @emph{Reference}:
1604 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1609 @node omp_is_initial_device
1610 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1612 @item @emph{Description}:
1613 This function returns @code{true} if currently running on the host device,
1614 @code{false} otherwise. Here, @code{true} and @code{false} represent
1615 their language-specific counterparts.
1618 @multitable @columnfractions .20 .80
1619 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1622 @item @emph{Fortran}:
1623 @multitable @columnfractions .20 .80
1624 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1627 @item @emph{Reference}:
1628 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1633 @node omp_get_initial_device
1634 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1636 @item @emph{Description}:
1637 This function returns a device number that represents the host device.
1638 For OpenMP 5.1, this must be equal to the value returned by the
1639 @code{omp_get_num_devices} function.
1642 @multitable @columnfractions .20 .80
1643 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1646 @item @emph{Fortran}:
1647 @multitable @columnfractions .20 .80
1648 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1651 @item @emph{See also}:
1652 @ref{omp_get_num_devices}
1654 @item @emph{Reference}:
1655 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1660 @c @node Device Memory Routines
1661 @c @section Device Memory Routines
1663 @c Routines related to memory allocation and managing corresponding
1664 @c pointers on devices. They have C linkage and do not throw exceptions.
1667 @c * omp_target_alloc:: <fixme>
1668 @c * omp_target_free:: <fixme>
1669 @c * omp_target_is_present:: <fixme>
1670 @c * omp_target_is_accessible:: <fixme>
1671 @c * omp_target_memcpy:: <fixme>
1672 @c * omp_target_memcpy_rect:: <fixme>
1673 @c * omp_target_memcpy_async:: <fixme>
1674 @c * omp_target_memcpy_rect_async:: <fixme>
1675 @c * omp_target_associate_ptr:: <fixme>
1676 @c * omp_target_disassociate_ptr:: <fixme>
1677 @c * omp_get_mapped_ptr:: <fixme>
1681 @section Lock Routines
1683 Initialize, set, test, unset and destroy simple and nested locks.
1684 The routines have C linkage and do not throw exceptions.
1687 * omp_init_lock:: Initialize simple lock
1688 * omp_init_nest_lock:: Initialize nested lock
1689 @c * omp_init_lock_with_hint:: <fixme>
1690 @c * omp_init_nest_lock_with_hint:: <fixme>
1691 * omp_destroy_lock:: Destroy simple lock
1692 * omp_destroy_nest_lock:: Destroy nested lock
1693 * omp_set_lock:: Wait for and set simple lock
1694 * omp_set_nest_lock:: Wait for and set simple lock
1695 * omp_unset_lock:: Unset simple lock
1696 * omp_unset_nest_lock:: Unset nested lock
1697 * omp_test_lock:: Test and set simple lock if available
1698 * omp_test_nest_lock:: Test and set nested lock if available
1704 @subsection @code{omp_init_lock} -- Initialize simple lock
1706 @item @emph{Description}:
1707 Initialize a simple lock. After initialization, the lock is in
1711 @multitable @columnfractions .20 .80
1712 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1715 @item @emph{Fortran}:
1716 @multitable @columnfractions .20 .80
1717 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1718 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1721 @item @emph{See also}:
1722 @ref{omp_destroy_lock}
1724 @item @emph{Reference}:
1725 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1730 @node omp_init_nest_lock
1731 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
1733 @item @emph{Description}:
1734 Initialize a nested lock. After initialization, the lock is in
1735 an unlocked state and the nesting count is set to zero.
1738 @multitable @columnfractions .20 .80
1739 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1742 @item @emph{Fortran}:
1743 @multitable @columnfractions .20 .80
1744 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1745 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1748 @item @emph{See also}:
1749 @ref{omp_destroy_nest_lock}
1751 @item @emph{Reference}:
1752 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1757 @node omp_destroy_lock
1758 @subsection @code{omp_destroy_lock} -- Destroy simple lock
1760 @item @emph{Description}:
1761 Destroy a simple lock. In order to be destroyed, a simple lock must be
1762 in the unlocked state.
1765 @multitable @columnfractions .20 .80
1766 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1769 @item @emph{Fortran}:
1770 @multitable @columnfractions .20 .80
1771 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1772 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1775 @item @emph{See also}:
1778 @item @emph{Reference}:
1779 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1784 @node omp_destroy_nest_lock
1785 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
1787 @item @emph{Description}:
1788 Destroy a nested lock. In order to be destroyed, a nested lock must be
1789 in the unlocked state and its nesting count must equal zero.
1792 @multitable @columnfractions .20 .80
1793 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1796 @item @emph{Fortran}:
1797 @multitable @columnfractions .20 .80
1798 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1799 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1802 @item @emph{See also}:
1805 @item @emph{Reference}:
1806 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1812 @subsection @code{omp_set_lock} -- Wait for and set simple lock
1814 @item @emph{Description}:
1815 Before setting a simple lock, the lock variable must be initialized by
1816 @code{omp_init_lock}. The calling thread is blocked until the lock
1817 is available. If the lock is already held by the current thread,
1821 @multitable @columnfractions .20 .80
1822 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1825 @item @emph{Fortran}:
1826 @multitable @columnfractions .20 .80
1827 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1828 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1831 @item @emph{See also}:
1832 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1834 @item @emph{Reference}:
1835 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1840 @node omp_set_nest_lock
1841 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
1843 @item @emph{Description}:
1844 Before setting a nested lock, the lock variable must be initialized by
1845 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1846 is available. If the lock is already held by the current thread, the
1847 nesting count for the lock is incremented.
1850 @multitable @columnfractions .20 .80
1851 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1854 @item @emph{Fortran}:
1855 @multitable @columnfractions .20 .80
1856 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1857 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1860 @item @emph{See also}:
1861 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1863 @item @emph{Reference}:
1864 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1869 @node omp_unset_lock
1870 @subsection @code{omp_unset_lock} -- Unset simple lock
1872 @item @emph{Description}:
1873 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1874 or @code{omp_test_lock} before. In addition, the lock must be held by the
1875 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1876 or more threads attempted to set the lock before, one of them is chosen to,
1877 again, set the lock to itself.
1880 @multitable @columnfractions .20 .80
1881 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1884 @item @emph{Fortran}:
1885 @multitable @columnfractions .20 .80
1886 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1887 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1890 @item @emph{See also}:
1891 @ref{omp_set_lock}, @ref{omp_test_lock}
1893 @item @emph{Reference}:
1894 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1899 @node omp_unset_nest_lock
1900 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
1902 @item @emph{Description}:
1903 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1904 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1905 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1906 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1907 one of them is chosen to, again, set the lock to itself.
1910 @multitable @columnfractions .20 .80
1911 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1914 @item @emph{Fortran}:
1915 @multitable @columnfractions .20 .80
1916 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1917 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1920 @item @emph{See also}:
1921 @ref{omp_set_nest_lock}
1923 @item @emph{Reference}:
1924 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1930 @subsection @code{omp_test_lock} -- Test and set simple lock if available
1932 @item @emph{Description}:
1933 Before setting a simple lock, the lock variable must be initialized by
1934 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1935 does not block if the lock is not available. This function returns
1936 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1937 @code{false} represent their language-specific counterparts.
1940 @multitable @columnfractions .20 .80
1941 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1944 @item @emph{Fortran}:
1945 @multitable @columnfractions .20 .80
1946 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1947 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1950 @item @emph{See also}:
1951 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1953 @item @emph{Reference}:
1954 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1959 @node omp_test_nest_lock
1960 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
1962 @item @emph{Description}:
1963 Before setting a nested lock, the lock variable must be initialized by
1964 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1965 @code{omp_test_nest_lock} does not block if the lock is not available.
1966 If the lock is already held by the current thread, the new nesting count
1967 is returned. Otherwise, the return value equals zero.
1970 @multitable @columnfractions .20 .80
1971 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1974 @item @emph{Fortran}:
1975 @multitable @columnfractions .20 .80
1976 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1977 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1981 @item @emph{See also}:
1982 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1984 @item @emph{Reference}:
1985 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1990 @node Timing Routines
1991 @section Timing Routines
1993 Portable, thread-based, wall clock timer.
1994 The routines have C linkage and do not throw exceptions.
1997 * omp_get_wtick:: Get timer precision.
1998 * omp_get_wtime:: Elapsed wall clock time.
2004 @subsection @code{omp_get_wtick} -- Get timer precision
2006 @item @emph{Description}:
2007 Gets the timer precision, i.e., the number of seconds between two
2008 successive clock ticks.
2011 @multitable @columnfractions .20 .80
2012 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2015 @item @emph{Fortran}:
2016 @multitable @columnfractions .20 .80
2017 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2020 @item @emph{See also}:
2023 @item @emph{Reference}:
2024 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2030 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2032 @item @emph{Description}:
2033 Elapsed wall clock time in seconds. The time is measured per thread, no
2034 guarantee can be made that two distinct threads measure the same time.
2035 Time is measured from some "time in the past", which is an arbitrary time
2036 guaranteed not to change during the execution of the program.
2039 @multitable @columnfractions .20 .80
2040 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2043 @item @emph{Fortran}:
2044 @multitable @columnfractions .20 .80
2045 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2048 @item @emph{See also}:
2051 @item @emph{Reference}:
2052 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2058 @section Event Routine
2060 Support for event objects.
2061 The routine has C linkage and do not throw exceptions.
2064 * omp_fulfill_event:: Fulfill and destroy an OpenMP event.
2069 @node omp_fulfill_event
2070 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2072 @item @emph{Description}:
2073 Fulfill the event associated with the event handle argument. Currently, it
2074 is only used to fulfill events generated by detach clauses on task
2075 constructs - the effect of fulfilling the event is to allow the task to
2078 The result of calling @code{omp_fulfill_event} with an event handle other
2079 than that generated by a detach clause is undefined. Calling it with an
2080 event handle that has already been fulfilled is also undefined.
2083 @multitable @columnfractions .20 .80
2084 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2087 @item @emph{Fortran}:
2088 @multitable @columnfractions .20 .80
2089 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2090 @item @tab @code{integer (kind=omp_event_handle_kind) :: event}
2093 @item @emph{Reference}:
2094 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2099 @c @node Interoperability Routines
2100 @c @section Interoperability Routines
2102 @c Routines to obtain properties from an @code{omp_interop_t} object.
2103 @c They have C linkage and do not throw exceptions.
2106 @c * omp_get_num_interop_properties:: <fixme>
2107 @c * omp_get_interop_int:: <fixme>
2108 @c * omp_get_interop_ptr:: <fixme>
2109 @c * omp_get_interop_str:: <fixme>
2110 @c * omp_get_interop_name:: <fixme>
2111 @c * omp_get_interop_type_desc:: <fixme>
2112 @c * omp_get_interop_rc_desc:: <fixme>
2115 @node Memory Management Routines
2116 @section Memory Management Routines
2118 Routines to manage and allocate memory on the current device.
2119 They have C linkage and do not throw exceptions.
2122 * omp_init_allocator:: Create an allocator
2123 * omp_destroy_allocator:: Destroy an allocator
2124 * omp_set_default_allocator:: Set the default allocator
2125 * omp_get_default_allocator:: Get the default allocator
2126 @c * omp_alloc:: <fixme>
2127 @c * omp_aligned_alloc:: <fixme>
2128 @c * omp_free:: <fixme>
2129 @c * omp_calloc:: <fixme>
2130 @c * omp_aligned_calloc:: <fixme>
2131 @c * omp_realloc:: <fixme>
2132 @c * omp_get_memspace_num_resources:: <fixme>/TR11
2133 @c * omp_get_submemspace:: <fixme>/TR11
2138 @node omp_init_allocator
2139 @subsection @code{omp_init_allocator} -- Create an allocator
2141 @item @emph{Description}:
2142 Create an allocator that uses the specified memory space and has the specified
2143 traits; if an allocator that fulfills the requirements cannot be created,
2144 @code{omp_null_allocator} is returned.
2146 The predefined memory spaces and available traits can be found at
2147 @ref{OMP_ALLOCATOR}, where the trait names have to be be prefixed by
2148 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
2149 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
2150 may be used as trait value to specify that the default value should be used.
2153 @multitable @columnfractions .20 .80
2154 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
2155 @item @tab @code{ omp_memspace_handle_t memspace,}
2156 @item @tab @code{ int ntraits,}
2157 @item @tab @code{ const omp_alloctrait_t traits[]);}
2160 @item @emph{Fortran}:
2161 @multitable @columnfractions .20 .80
2162 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
2163 @item @tab @code{integer (kind=omp_allocator_handle_kind) :: omp_init_allocator}
2164 @item @tab @code{integer (kind=omp_memspace_handle_kind), intent(in) :: memspace}
2165 @item @tab @code{integer, intent(in) :: ntraits}
2166 @item @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
2169 @item @emph{See also}:
2170 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
2172 @item @emph{Reference}:
2173 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
2178 @node omp_destroy_allocator
2179 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
2181 @item @emph{Description}:
2182 Releases all resources used by a memory allocator, which must not represent
2183 a predefined memory allocator. Accessing memory after its allocator has been
2184 destroyed has unspecified behavior. Passing @code{omp_null_allocator} to the
2185 routine is permitted but will have no effect.
2189 @multitable @columnfractions .20 .80
2190 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
2193 @item @emph{Fortran}:
2194 @multitable @columnfractions .20 .80
2195 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
2196 @item @tab @code{integer (kind=omp_allocator_handle_kind), intent(in) :: allocator}
2199 @item @emph{See also}:
2200 @ref{omp_init_allocator}
2202 @item @emph{Reference}:
2203 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
2208 @node omp_set_default_allocator
2209 @subsection @code{omp_set_default_allocator} -- Set the default allocator
2211 @item @emph{Description}:
2212 Sets the default allocator that is used when no allocator has been specified
2213 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2214 routine is invoked with the @code{omp_null_allocator} allocator.
2217 @multitable @columnfractions .20 .80
2218 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
2221 @item @emph{Fortran}:
2222 @multitable @columnfractions .20 .80
2223 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
2224 @item @tab @code{integer (kind=omp_allocator_handle_kind), intent(in) :: allocator}
2227 @item @emph{See also}:
2228 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
2229 @ref{Memory allocation}
2231 @item @emph{Reference}:
2232 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
2237 @node omp_get_default_allocator
2238 @subsection @code{omp_get_default_allocator} -- Get the default allocator
2240 @item @emph{Description}:
2241 The routine returns the default allocator that is used when no allocator has
2242 been specified in the @code{allocate} or @code{allocator} clause or if an
2243 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
2246 @multitable @columnfractions .20 .80
2247 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
2250 @item @emph{Fortran}:
2251 @multitable @columnfractions .20 .80
2252 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
2253 @item @tab @code{integer (kind=omp_allocator_handle_kind) :: omp_get_default_allocator}
2256 @item @emph{See also}:
2257 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
2259 @item @emph{Reference}:
2260 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
2265 @c @node Tool Control Routine
2269 @c @node Environment Display Routine
2270 @c @section Environment Display Routine
2272 @c Routine to display the OpenMP number and the initial value of ICVs.
2273 @c It has C linkage and do not throw exceptions.
2276 @c * omp_display_env:: <fixme>
2279 @c ---------------------------------------------------------------------
2280 @c OpenMP Environment Variables
2281 @c ---------------------------------------------------------------------
2283 @node Environment Variables
2284 @chapter OpenMP Environment Variables
2286 The environment variables which beginning with @env{OMP_} are defined by
2287 section 4 of the OpenMP specification in version 4.5 or in a later version
2288 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
2289 Most @env{OMP_} environment variables have an associated internal control
2292 For any OpenMP environment variable that sets an ICV and is neither
2293 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
2294 device-specific environment variables exist. For them, the environment
2295 variable without suffix affects the host. The suffix @code{_DEV_} followed
2296 by a non-negative device number less that the number of available devices sets
2297 the ICV for the corresponding device. The suffix @code{_DEV} sets the ICV
2298 of all non-host devices for which a device-specific corresponding environment
2299 variable has not been set while the @code{_ALL} suffix sets the ICV of all
2300 host and non-host devices for which a more specific corresponding environment
2301 variable is not set.
2304 * OMP_ALLOCATOR:: Set the default allocator
2305 * OMP_AFFINITY_FORMAT:: Set the format string used for affinity display
2306 * OMP_CANCELLATION:: Set whether cancellation is activated
2307 * OMP_DISPLAY_AFFINITY:: Display thread affinity information
2308 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
2309 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
2310 * OMP_DYNAMIC:: Dynamic adjustment of threads
2311 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
2312 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
2313 * OMP_NESTED:: Nested parallel regions
2314 * OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
2315 * OMP_NUM_THREADS:: Specifies the number of threads to use
2316 * OMP_PROC_BIND:: Whether threads may be moved between CPUs
2317 * OMP_PLACES:: Specifies on which CPUs the threads should be placed
2318 * OMP_STACKSIZE:: Set default thread stack size
2319 * OMP_SCHEDULE:: How threads are scheduled
2320 * OMP_TARGET_OFFLOAD:: Controls offloading behaviour
2321 * OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
2322 * OMP_THREAD_LIMIT:: Set the maximum number of threads
2323 * OMP_WAIT_POLICY:: How waiting threads are handled
2324 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
2325 * GOMP_DEBUG:: Enable debugging output
2326 * GOMP_STACKSIZE:: Set default thread stack size
2327 * GOMP_SPINCOUNT:: Set the busy-wait spin count
2328 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
2333 @section @env{OMP_ALLOCATOR} -- Set the default allocator
2334 @cindex Environment Variable
2336 @item @emph{ICV:} @var{def-allocator-var}
2337 @item @emph{Scope:} data environment
2338 @item @emph{Description}:
2339 Sets the default allocator that is used when no allocator has been specified
2340 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
2341 routine is invoked with the @code{omp_null_allocator} allocator.
2342 If unset, @code{omp_default_mem_alloc} is used.
2344 The value can either be a predefined allocator or a predefined memory space
2345 or a predefined memory space followed by a colon and a comma-separated list
2346 of memory trait and value pairs, separated by @code{=}.
2348 Note: The corresponding device environment variables are currently not
2349 supported. Therefore, the non-host @var{def-allocator-var} ICVs are always
2350 initialized to @code{omp_default_mem_alloc}. However, on all devices,
2351 the @code{omp_set_default_allocator} API routine can be used to change
2354 @multitable @columnfractions .45 .45
2355 @headitem Predefined allocators @tab Associated predefined memory spaces
2356 @item omp_default_mem_alloc @tab omp_default_mem_space
2357 @item omp_large_cap_mem_alloc @tab omp_large_cap_mem_space
2358 @item omp_const_mem_alloc @tab omp_const_mem_space
2359 @item omp_high_bw_mem_alloc @tab omp_high_bw_mem_space
2360 @item omp_low_lat_mem_alloc @tab omp_low_lat_mem_space
2361 @item omp_cgroup_mem_alloc @tab --
2362 @item omp_pteam_mem_alloc @tab --
2363 @item omp_thread_mem_alloc @tab --
2366 The predefined allocators use the default values for the traits,
2367 as listed below. Except that the last three allocators have the
2368 @code{access} trait set to @code{cgroup}, @code{pteam}, and
2369 @code{thread}, respectively.
2371 @multitable @columnfractions .25 .40 .25
2372 @headitem Trait @tab Allowed values @tab Default value
2373 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
2374 @code{serialized}, @code{private}
2375 @tab @code{contended}
2376 @item @code{alignment} @tab Positive integer being a power of two
2378 @item @code{access} @tab @code{all}, @code{cgroup},
2379 @code{pteam}, @code{thread}
2381 @item @code{pool_size} @tab Positive integer
2382 @tab See @ref{Memory allocation}
2383 @item @code{fallback} @tab @code{default_mem_fb}, @code{null_fb},
2384 @code{abort_fb}, @code{allocator_fb}
2386 @item @code{fb_data} @tab @emph{unsupported as it needs an allocator handle}
2388 @item @code{pinned} @tab @code{true}, @code{false}
2390 @item @code{partition} @tab @code{environment}, @code{nearest},
2391 @code{blocked}, @code{interleaved}
2392 @tab @code{environment}
2395 For the @code{fallback} trait, the default value is @code{null_fb} for the
2396 @code{omp_default_mem_alloc} allocator and any allocator that is associated
2397 with device memory; for all other other allocators, it is @code{default_mem_fb}
2402 OMP_ALLOCATOR=omp_high_bw_mem_alloc
2403 OMP_ALLOCATOR=omp_large_cap_mem_space
2404 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
2407 @item @emph{See also}:
2408 @ref{Memory allocation}, @ref{omp_get_default_allocator},
2409 @ref{omp_set_default_allocator}
2411 @item @emph{Reference}:
2412 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
2417 @node OMP_AFFINITY_FORMAT
2418 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
2419 @cindex Environment Variable
2421 @item @emph{ICV:} @var{affinity-format-var}
2422 @item @emph{Scope:} device
2423 @item @emph{Description}:
2424 Sets the format string used when displaying OpenMP thread affinity information.
2425 Special values are output using @code{%} followed by an optional size
2426 specification and then either the single-character field type or its long
2427 name enclosed in curly braces; using @code{%%} will display a literal percent.
2428 The size specification consists of an optional @code{0.} or @code{.} followed
2429 by a positive integer, specifying the minimal width of the output. With
2430 @code{0.} and numerical values, the output is padded with zeros on the left;
2431 with @code{.}, the output is padded by spaces on the left; otherwise, the
2432 output is padded by spaces on the right. If unset, the value is
2433 ``@code{level %L thread %i affinity %A}''.
2435 Supported field types are:
2437 @multitable @columnfractions .10 .25 .60
2438 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
2439 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
2440 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
2441 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
2442 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
2443 @item a @tab ancestor_tnum
2444 @tab value returned by
2445 @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
2446 @item H @tab host @tab name of the host that executes the thread
2447 @item P @tab process_id @tab process identifier
2448 @item i @tab native_thread_id @tab native thread identifier
2449 @item A @tab thread_affinity
2450 @tab comma separated list of integer values or ranges, representing the
2451 processors on which a process might execute, subject to affinity
2455 For instance, after setting
2458 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
2461 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
2462 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
2463 might display the following:
2466 00!0! 1!4; 0;01;0;1;0-11
2467 00!3! 1!4; 0;01;0;1;0-11
2468 00!2! 1!4; 0;01;0;1;0-11
2469 00!1! 1!4; 0;01;0;1;0-11
2472 @item @emph{See also}:
2473 @ref{OMP_DISPLAY_AFFINITY}
2475 @item @emph{Reference}:
2476 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
2481 @node OMP_CANCELLATION
2482 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
2483 @cindex Environment Variable
2485 @item @emph{ICV:} @var{cancel-var}
2486 @item @emph{Scope:} global
2487 @item @emph{Description}:
2488 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
2489 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
2491 @item @emph{See also}:
2492 @ref{omp_get_cancellation}
2494 @item @emph{Reference}:
2495 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
2500 @node OMP_DISPLAY_AFFINITY
2501 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
2502 @cindex Environment Variable
2504 @item @emph{ICV:} @var{display-affinity-var}
2505 @item @emph{Scope:} global
2506 @item @emph{Description}:
2507 If set to @code{FALSE} or if unset, affinity displaying is disabled.
2508 If set to @code{TRUE}, the runtime will display affinity information about
2509 OpenMP threads in a parallel region upon entering the region and every time
2512 @item @emph{See also}:
2513 @ref{OMP_AFFINITY_FORMAT}
2515 @item @emph{Reference}:
2516 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
2522 @node OMP_DISPLAY_ENV
2523 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
2524 @cindex Environment Variable
2526 @item @emph{ICV:} none
2527 @item @emph{Scope:} not applicable
2528 @item @emph{Description}:
2529 If set to @code{TRUE}, the OpenMP version number and the values
2530 associated with the OpenMP environment variables are printed to @code{stderr}.
2531 If set to @code{VERBOSE}, it additionally shows the value of the environment
2532 variables which are GNU extensions. If undefined or set to @code{FALSE},
2533 this information will not be shown.
2536 @item @emph{Reference}:
2537 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
2542 @node OMP_DEFAULT_DEVICE
2543 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
2544 @cindex Environment Variable
2546 @item @emph{ICV:} @var{default-device-var}
2547 @item @emph{Scope:} data environment
2548 @item @emph{Description}:
2549 Set to choose the device which is used in a @code{target} region, unless the
2550 value is overridden by @code{omp_set_default_device} or by a @code{device}
2551 clause. The value shall be the nonnegative device number. If no device with
2552 the given device number exists, the code is executed on the host. If unset,
2553 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
2554 available, it is set to @code{omp_invalid_device}. Otherwise, if unset,
2555 device number 0 will be used.
2558 @item @emph{See also}:
2559 @ref{omp_get_default_device}, @ref{omp_set_default_device},
2561 @item @emph{Reference}:
2562 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
2568 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
2569 @cindex Environment Variable
2571 @item @emph{ICV:} @var{dyn-var}
2572 @item @emph{Scope:} global
2573 @item @emph{Description}:
2574 Enable or disable the dynamic adjustment of the number of threads
2575 within a team. The value of this environment variable shall be
2576 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
2577 disabled by default.
2579 @item @emph{See also}:
2580 @ref{omp_set_dynamic}
2582 @item @emph{Reference}:
2583 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
2588 @node OMP_MAX_ACTIVE_LEVELS
2589 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
2590 @cindex Environment Variable
2592 @item @emph{ICV:} @var{max-active-levels-var}
2593 @item @emph{Scope:} data environment
2594 @item @emph{Description}:
2595 Specifies the initial value for the maximum number of nested parallel
2596 regions. The value of this variable shall be a positive integer.
2597 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
2598 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
2599 a list with more than one item, the maximum number of nested parallel
2600 regions will be initialized to the largest number supported, otherwise
2601 it will be set to one.
2603 @item @emph{See also}:
2604 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
2605 @ref{OMP_NUM_THREADS}
2608 @item @emph{Reference}:
2609 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
2614 @node OMP_MAX_TASK_PRIORITY
2615 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
2616 number that can be set for a task.
2617 @cindex Environment Variable
2619 @item @emph{ICV:} @var{max-task-priority-var}
2620 @item @emph{Scope:} global
2621 @item @emph{Description}:
2622 Specifies the initial value for the maximum priority value that can be
2623 set for a task. The value of this variable shall be a non-negative
2624 integer, and zero is allowed. If undefined, the default priority is
2627 @item @emph{See also}:
2628 @ref{omp_get_max_task_priority}
2630 @item @emph{Reference}:
2631 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
2637 @section @env{OMP_NESTED} -- Nested parallel regions
2638 @cindex Environment Variable
2639 @cindex Implementation specific setting
2641 @item @emph{ICV:} @var{max-active-levels-var}
2642 @item @emph{Scope:} data environment
2643 @item @emph{Description}:
2644 Enable or disable nested parallel regions, i.e., whether team members
2645 are allowed to create new teams. The value of this environment variable
2646 shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
2647 of maximum active nested regions supported will by default be set to the
2648 maximum supported, otherwise it will be set to one. If
2649 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting will override this
2650 setting. If both are undefined, nested parallel regions are enabled if
2651 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
2652 more than one item, otherwise they are disabled by default.
2654 Note that the @code{OMP_NESTED} environment variable was deprecated in
2655 the OpenMP specification 5.2 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
2657 @item @emph{See also}:
2658 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
2659 @ref{OMP_MAX_ACTIVE_LEVELS}
2661 @item @emph{Reference}:
2662 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
2668 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
2669 @cindex Environment Variable
2671 @item @emph{ICV:} @var{nteams-var}
2672 @item @emph{Scope:} device
2673 @item @emph{Description}:
2674 Specifies the upper bound for number of teams to use in teams regions
2675 without explicit @code{num_teams} clause. The value of this variable shall
2676 be a positive integer. If undefined it defaults to 0 which means
2677 implementation defined upper bound.
2679 @item @emph{See also}:
2680 @ref{omp_set_num_teams}
2682 @item @emph{Reference}:
2683 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
2688 @node OMP_NUM_THREADS
2689 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
2690 @cindex Environment Variable
2691 @cindex Implementation specific setting
2693 @item @emph{ICV:} @var{nthreads-var}
2694 @item @emph{Scope:} data environment
2695 @item @emph{Description}:
2696 Specifies the default number of threads to use in parallel regions. The
2697 value of this variable shall be a comma-separated list of positive integers;
2698 the value specifies the number of threads to use for the corresponding nested
2699 level. Specifying more than one item in the list will automatically enable
2700 nesting by default. If undefined one thread per CPU is used.
2702 When a list with more than value is specified, it also affects the
2703 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
2705 @item @emph{See also}:
2706 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
2708 @item @emph{Reference}:
2709 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
2715 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
2716 @cindex Environment Variable
2718 @item @emph{ICV:} @var{bind-var}
2719 @item @emph{Scope:} data environment
2720 @item @emph{Description}:
2721 Specifies whether threads may be moved between processors. If set to
2722 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
2723 they may be moved. Alternatively, a comma separated list with the
2724 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
2725 be used to specify the thread affinity policy for the corresponding nesting
2726 level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
2727 same place partition as the primary thread. With @code{CLOSE} those are
2728 kept close to the primary thread in contiguous place partitions. And
2729 with @code{SPREAD} a sparse distribution
2730 across the place partitions is used. Specifying more than one item in the
2731 list will automatically enable nesting by default.
2733 When a list is specified, it also affects the @var{max-active-levels-var} ICV
2734 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
2736 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
2737 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
2739 @item @emph{See also}:
2740 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
2741 @ref{OMP_MAX_ACTIVE_LEVELS}
2743 @item @emph{Reference}:
2744 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
2750 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
2751 @cindex Environment Variable
2753 @item @emph{ICV:} @var{place-partition-var}
2754 @item @emph{Scope:} implicit tasks
2755 @item @emph{Description}:
2756 The thread placement can be either specified using an abstract name or by an
2757 explicit list of the places. The abstract names @code{threads}, @code{cores},
2758 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
2759 followed by a positive number in parentheses, which denotes the how many places
2760 shall be created. With @code{threads} each place corresponds to a single
2761 hardware thread; @code{cores} to a single core with the corresponding number of
2762 hardware threads; with @code{sockets} the place corresponds to a single
2763 socket; with @code{ll_caches} to a set of cores that shares the last level
2764 cache on the device; and @code{numa_domains} to a set of cores for which their
2765 closest memory on the device is the same memory and at a similar distance from
2766 the cores. The resulting placement can be shown by setting the
2767 @env{OMP_DISPLAY_ENV} environment variable.
2769 Alternatively, the placement can be specified explicitly as comma-separated
2770 list of places. A place is specified by set of nonnegative numbers in curly
2771 braces, denoting the hardware threads. The curly braces can be omitted
2772 when only a single number has been specified. The hardware threads
2773 belonging to a place can either be specified as comma-separated list of
2774 nonnegative thread numbers or using an interval. Multiple places can also be
2775 either specified by a comma-separated list of places or by an interval. To
2776 specify an interval, a colon followed by the count is placed after
2777 the hardware thread number or the place. Optionally, the length can be
2778 followed by a colon and the stride number -- otherwise a unit stride is
2779 assumed. Placing an exclamation mark (@code{!}) directly before a curly
2780 brace or numbers inside the curly braces (excluding intervals) will
2781 exclude those hardware threads.
2783 For instance, the following specifies the same places list:
2784 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
2785 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
2787 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
2788 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
2789 between CPUs following no placement policy.
2791 @item @emph{See also}:
2792 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
2793 @ref{OMP_DISPLAY_ENV}
2795 @item @emph{Reference}:
2796 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
2802 @section @env{OMP_STACKSIZE} -- Set default thread stack size
2803 @cindex Environment Variable
2805 @item @emph{ICV:} @var{stacksize-var}
2806 @item @emph{Scope:} device
2807 @item @emph{Description}:
2808 Set the default thread stack size in kilobytes, unless the number
2809 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
2810 case the size is, respectively, in bytes, kilobytes, megabytes
2811 or gigabytes. This is different from @code{pthread_attr_setstacksize}
2812 which gets the number of bytes as an argument. If the stack size cannot
2813 be set due to system constraints, an error is reported and the initial
2814 stack size is left unchanged. If undefined, the stack size is system
2817 @item @emph{See also}:
2818 @ref{GOMP_STACKSIZE}
2820 @item @emph{Reference}:
2821 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
2827 @section @env{OMP_SCHEDULE} -- How threads are scheduled
2828 @cindex Environment Variable
2829 @cindex Implementation specific setting
2831 @item @emph{ICV:} @var{run-sched-var}
2832 @item @emph{Scope:} data environment
2833 @item @emph{Description}:
2834 Allows to specify @code{schedule type} and @code{chunk size}.
2835 The value of the variable shall have the form: @code{type[,chunk]} where
2836 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
2837 The optional @code{chunk} size shall be a positive integer. If undefined,
2838 dynamic scheduling and a chunk size of 1 is used.
2840 @item @emph{See also}:
2841 @ref{omp_set_schedule}
2843 @item @emph{Reference}:
2844 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
2849 @node OMP_TARGET_OFFLOAD
2850 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behaviour
2851 @cindex Environment Variable
2852 @cindex Implementation specific setting
2854 @item @emph{ICV:} @var{target-offload-var}
2855 @item @emph{Scope:} global
2856 @item @emph{Description}:
2857 Specifies the behaviour with regard to offloading code to a device. This
2858 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
2861 If set to @code{MANDATORY}, the program will terminate with an error if
2862 the offload device is not present or is not supported. If set to
2863 @code{DISABLED}, then offloading is disabled and all code will run on the
2864 host. If set to @code{DEFAULT}, the program will try offloading to the
2865 device first, then fall back to running code on the host if it cannot.
2867 If undefined, then the program will behave as if @code{DEFAULT} was set.
2869 @item @emph{Reference}:
2870 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.17
2875 @node OMP_TEAMS_THREAD_LIMIT
2876 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
2877 @cindex Environment Variable
2879 @item @emph{ICV:} @var{teams-thread-limit-var}
2880 @item @emph{Scope:} device
2881 @item @emph{Description}:
2882 Specifies an upper bound for the number of threads to use by each contention
2883 group created by a teams construct without explicit @code{thread_limit}
2884 clause. The value of this variable shall be a positive integer. If undefined,
2885 the value of 0 is used which stands for an implementation defined upper
2888 @item @emph{See also}:
2889 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
2891 @item @emph{Reference}:
2892 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
2897 @node OMP_THREAD_LIMIT
2898 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
2899 @cindex Environment Variable
2901 @item @emph{ICV:} @var{thread-limit-var}
2902 @item @emph{Scope:} data environment
2903 @item @emph{Description}:
2904 Specifies the number of threads to use for the whole program. The
2905 value of this variable shall be a positive integer. If undefined,
2906 the number of threads is not limited.
2908 @item @emph{See also}:
2909 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
2911 @item @emph{Reference}:
2912 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
2917 @node OMP_WAIT_POLICY
2918 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
2919 @cindex Environment Variable
2921 @item @emph{Description}:
2922 Specifies whether waiting threads should be active or passive. If
2923 the value is @code{PASSIVE}, waiting threads should not consume CPU
2924 power while waiting; while the value is @code{ACTIVE} specifies that
2925 they should. If undefined, threads wait actively for a short time
2926 before waiting passively.
2928 @item @emph{See also}:
2929 @ref{GOMP_SPINCOUNT}
2931 @item @emph{Reference}:
2932 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
2937 @node GOMP_CPU_AFFINITY
2938 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
2939 @cindex Environment Variable
2941 @item @emph{Description}:
2942 Binds threads to specific CPUs. The variable should contain a space-separated
2943 or comma-separated list of CPUs. This list may contain different kinds of
2944 entries: either single CPU numbers in any order, a range of CPUs (M-N)
2945 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
2946 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
2947 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
2948 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
2949 and 14 respectively and then start assigning back from the beginning of
2950 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
2952 There is no libgomp library routine to determine whether a CPU affinity
2953 specification is in effect. As a workaround, language-specific library
2954 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
2955 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
2956 environment variable. A defined CPU affinity on startup cannot be changed
2957 or disabled during the runtime of the application.
2959 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
2960 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
2961 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
2962 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
2964 @item @emph{See also}:
2965 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
2971 @section @env{GOMP_DEBUG} -- Enable debugging output
2972 @cindex Environment Variable
2974 @item @emph{Description}:
2975 Enable debugging output. The variable should be set to @code{0}
2976 (disabled, also the default if not set), or @code{1} (enabled).
2978 If enabled, some debugging output will be printed during execution.
2979 This is currently not specified in more detail, and subject to change.
2984 @node GOMP_STACKSIZE
2985 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
2986 @cindex Environment Variable
2987 @cindex Implementation specific setting
2989 @item @emph{Description}:
2990 Set the default thread stack size in kilobytes. This is different from
2991 @code{pthread_attr_setstacksize} which gets the number of bytes as an
2992 argument. If the stack size cannot be set due to system constraints, an
2993 error is reported and the initial stack size is left unchanged. If undefined,
2994 the stack size is system dependent.
2996 @item @emph{See also}:
2999 @item @emph{Reference}:
3000 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
3001 GCC Patches Mailinglist},
3002 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
3003 GCC Patches Mailinglist}
3008 @node GOMP_SPINCOUNT
3009 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
3010 @cindex Environment Variable
3011 @cindex Implementation specific setting
3013 @item @emph{Description}:
3014 Determines how long a threads waits actively with consuming CPU power
3015 before waiting passively without consuming CPU power. The value may be
3016 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
3017 integer which gives the number of spins of the busy-wait loop. The
3018 integer may optionally be followed by the following suffixes acting
3019 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
3020 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
3021 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
3022 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
3023 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
3024 If there are more OpenMP threads than available CPUs, 1000 and 100
3025 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
3026 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
3027 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
3029 @item @emph{See also}:
3030 @ref{OMP_WAIT_POLICY}
3035 @node GOMP_RTEMS_THREAD_POOLS
3036 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
3037 @cindex Environment Variable
3038 @cindex Implementation specific setting
3040 @item @emph{Description}:
3041 This environment variable is only used on the RTEMS real-time operating system.
3042 It determines the scheduler instance specific thread pools. The format for
3043 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
3044 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
3045 separated by @code{:} where:
3047 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
3049 @item @code{$<priority>} is an optional priority for the worker threads of a
3050 thread pool according to @code{pthread_setschedparam}. In case a priority
3051 value is omitted, then a worker thread will inherit the priority of the OpenMP
3052 primary thread that created it. The priority of the worker thread is not
3053 changed after creation, even if a new OpenMP primary thread using the worker has
3054 a different priority.
3055 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
3056 RTEMS application configuration.
3058 In case no thread pool configuration is specified for a scheduler instance,
3059 then each OpenMP primary thread of this scheduler instance will use its own
3060 dynamically allocated thread pool. To limit the worker thread count of the
3061 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
3062 @item @emph{Example}:
3063 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
3064 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
3065 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
3066 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
3067 one thread pool available. Since no priority is specified for this scheduler
3068 instance, the worker thread inherits the priority of the OpenMP primary thread
3069 that created it. In the scheduler instance @code{WRK1} there are three thread
3070 pools available and their worker threads run at priority four.
3075 @c ---------------------------------------------------------------------
3077 @c ---------------------------------------------------------------------
3079 @node Enabling OpenACC
3080 @chapter Enabling OpenACC
3082 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
3083 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
3084 @code{#pragma acc} in C/C++ and @code{!$acc} directives in free form,
3085 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
3086 @code{!$} conditional compilation sentinels in free form and @code{c$},
3087 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
3088 arranges for automatic linking of the OpenACC runtime library
3089 (@ref{OpenACC Runtime Library Routines}).
3091 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
3093 A complete description of all OpenACC directives accepted may be found in
3094 the @uref{https://www.openacc.org, OpenACC} Application Programming
3095 Interface manual, version 2.6.
3099 @c ---------------------------------------------------------------------
3100 @c OpenACC Runtime Library Routines
3101 @c ---------------------------------------------------------------------
3103 @node OpenACC Runtime Library Routines
3104 @chapter OpenACC Runtime Library Routines
3106 The runtime routines described here are defined by section 3 of the OpenACC
3107 specifications in version 2.6.
3108 They have C linkage, and do not throw exceptions.
3109 Generally, they are available only for the host, with the exception of
3110 @code{acc_on_device}, which is available for both the host and the
3111 acceleration device.
3114 * acc_get_num_devices:: Get number of devices for the given device
3116 * acc_set_device_type:: Set type of device accelerator to use.
3117 * acc_get_device_type:: Get type of device accelerator to be used.
3118 * acc_set_device_num:: Set device number to use.
3119 * acc_get_device_num:: Get device number to be used.
3120 * acc_get_property:: Get device property.
3121 * acc_async_test:: Tests for completion of a specific asynchronous
3123 * acc_async_test_all:: Tests for completion of all asynchronous
3125 * acc_wait:: Wait for completion of a specific asynchronous
3127 * acc_wait_all:: Waits for completion of all asynchronous
3129 * acc_wait_all_async:: Wait for completion of all asynchronous
3131 * acc_wait_async:: Wait for completion of asynchronous operations.
3132 * acc_init:: Initialize runtime for a specific device type.
3133 * acc_shutdown:: Shuts down the runtime for a specific device
3135 * acc_on_device:: Whether executing on a particular device
3136 * acc_malloc:: Allocate device memory.
3137 * acc_free:: Free device memory.
3138 * acc_copyin:: Allocate device memory and copy host memory to
3140 * acc_present_or_copyin:: If the data is not present on the device,
3141 allocate device memory and copy from host
3143 * acc_create:: Allocate device memory and map it to host
3145 * acc_present_or_create:: If the data is not present on the device,
3146 allocate device memory and map it to host
3148 * acc_copyout:: Copy device memory to host memory.
3149 * acc_delete:: Free device memory.
3150 * acc_update_device:: Update device memory from mapped host memory.
3151 * acc_update_self:: Update host memory from mapped device memory.
3152 * acc_map_data:: Map previously allocated device memory to host
3154 * acc_unmap_data:: Unmap device memory from host memory.
3155 * acc_deviceptr:: Get device pointer associated with specific
3157 * acc_hostptr:: Get host pointer associated with specific
3159 * acc_is_present:: Indicate whether host variable / array is
3161 * acc_memcpy_to_device:: Copy host memory to device memory.
3162 * acc_memcpy_from_device:: Copy device memory to host memory.
3163 * acc_attach:: Let device pointer point to device-pointer target.
3164 * acc_detach:: Let device pointer point to host-pointer target.
3166 API routines for target platforms.
3168 * acc_get_current_cuda_device:: Get CUDA device handle.
3169 * acc_get_current_cuda_context::Get CUDA context handle.
3170 * acc_get_cuda_stream:: Get CUDA stream handle.
3171 * acc_set_cuda_stream:: Set CUDA stream handle.
3173 API routines for the OpenACC Profiling Interface.
3175 * acc_prof_register:: Register callbacks.
3176 * acc_prof_unregister:: Unregister callbacks.
3177 * acc_prof_lookup:: Obtain inquiry functions.
3178 * acc_register_library:: Library registration.
3183 @node acc_get_num_devices
3184 @section @code{acc_get_num_devices} -- Get number of devices for given device type
3186 @item @emph{Description}
3187 This function returns a value indicating the number of devices available
3188 for the device type specified in @var{devicetype}.
3191 @multitable @columnfractions .20 .80
3192 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
3195 @item @emph{Fortran}:
3196 @multitable @columnfractions .20 .80
3197 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
3198 @item @tab @code{integer(kind=acc_device_kind) devicetype}
3201 @item @emph{Reference}:
3202 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3208 @node acc_set_device_type
3209 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
3211 @item @emph{Description}
3212 This function indicates to the runtime library which device type, specified
3213 in @var{devicetype}, to use when executing a parallel or kernels region.
3216 @multitable @columnfractions .20 .80
3217 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
3220 @item @emph{Fortran}:
3221 @multitable @columnfractions .20 .80
3222 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
3223 @item @tab @code{integer(kind=acc_device_kind) devicetype}
3226 @item @emph{Reference}:
3227 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3233 @node acc_get_device_type
3234 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
3236 @item @emph{Description}
3237 This function returns what device type will be used when executing a
3238 parallel or kernels region.
3240 This function returns @code{acc_device_none} if
3241 @code{acc_get_device_type} is called from
3242 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
3243 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
3244 Interface}), that is, if the device is currently being initialized.
3247 @multitable @columnfractions .20 .80
3248 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
3251 @item @emph{Fortran}:
3252 @multitable @columnfractions .20 .80
3253 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
3254 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
3257 @item @emph{Reference}:
3258 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3264 @node acc_set_device_num
3265 @section @code{acc_set_device_num} -- Set device number to use.
3267 @item @emph{Description}
3268 This function will indicate to the runtime which device number,
3269 specified by @var{devicenum}, associated with the specified device
3270 type @var{devicetype}.
3273 @multitable @columnfractions .20 .80
3274 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
3277 @item @emph{Fortran}:
3278 @multitable @columnfractions .20 .80
3279 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
3280 @item @tab @code{integer devicenum}
3281 @item @tab @code{integer(kind=acc_device_kind) devicetype}
3284 @item @emph{Reference}:
3285 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3291 @node acc_get_device_num
3292 @section @code{acc_get_device_num} -- Get device number to be used.
3294 @item @emph{Description}
3295 This function returns which device number associated with the specified device
3296 type @var{devicetype}, will be used when executing a parallel or kernels
3300 @multitable @columnfractions .20 .80
3301 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
3304 @item @emph{Fortran}:
3305 @multitable @columnfractions .20 .80
3306 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
3307 @item @tab @code{integer(kind=acc_device_kind) devicetype}
3308 @item @tab @code{integer acc_get_device_num}
3311 @item @emph{Reference}:
3312 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3318 @node acc_get_property
3319 @section @code{acc_get_property} -- Get device property.
3320 @cindex acc_get_property
3321 @cindex acc_get_property_string
3323 @item @emph{Description}
3324 These routines return the value of the specified @var{property} for the
3325 device being queried according to @var{devicenum} and @var{devicetype}.
3326 Integer-valued and string-valued properties are returned by
3327 @code{acc_get_property} and @code{acc_get_property_string} respectively.
3328 The Fortran @code{acc_get_property_string} subroutine returns the string
3329 retrieved in its fourth argument while the remaining entry points are
3330 functions, which pass the return value as their result.
3332 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
3333 modified the interface introduced in OpenACC 2.6. The kind-value parameter
3334 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
3335 for consistency and the return type of the @code{acc_get_property} function is
3336 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
3337 The parameter @code{acc_device_property} will continue to be provided,
3338 but might be removed in a future version of GCC.
3341 @multitable @columnfractions .20 .80
3342 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
3343 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
3346 @item @emph{Fortran}:
3347 @multitable @columnfractions .20 .80
3348 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
3349 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
3350 @item @tab @code{use ISO_C_Binding, only: c_size_t}
3351 @item @tab @code{integer devicenum}
3352 @item @tab @code{integer(kind=acc_device_kind) devicetype}
3353 @item @tab @code{integer(kind=acc_device_property_kind) property}
3354 @item @tab @code{integer(kind=c_size_t) acc_get_property}
3355 @item @tab @code{character(*) string}
3358 @item @emph{Reference}:
3359 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3365 @node acc_async_test
3366 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
3368 @item @emph{Description}
3369 This function tests for completion of the asynchronous operation specified
3370 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
3371 the specified asynchronous operation has completed. While Fortran will return
3372 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
3373 a zero and Fortran returns a @code{false}.
3376 @multitable @columnfractions .20 .80
3377 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
3380 @item @emph{Fortran}:
3381 @multitable @columnfractions .20 .80
3382 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
3383 @item @tab @code{integer(kind=acc_handle_kind) arg}
3384 @item @tab @code{logical acc_async_test}
3387 @item @emph{Reference}:
3388 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3394 @node acc_async_test_all
3395 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
3397 @item @emph{Description}
3398 This function tests for completion of all asynchronous operations.
3399 In C/C++, a non-zero value will be returned to indicate all asynchronous
3400 operations have completed. While Fortran will return a @code{true}. If
3401 any asynchronous operation has not completed, C/C++ returns a zero and
3402 Fortran returns a @code{false}.
3405 @multitable @columnfractions .20 .80
3406 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
3409 @item @emph{Fortran}:
3410 @multitable @columnfractions .20 .80
3411 @item @emph{Interface}: @tab @code{function acc_async_test()}
3412 @item @tab @code{logical acc_get_device_num}
3415 @item @emph{Reference}:
3416 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3423 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
3425 @item @emph{Description}
3426 This function waits for completion of the asynchronous operation
3427 specified in @var{arg}.
3430 @multitable @columnfractions .20 .80
3431 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
3432 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
3435 @item @emph{Fortran}:
3436 @multitable @columnfractions .20 .80
3437 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
3438 @item @tab @code{integer(acc_handle_kind) arg}
3439 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
3440 @item @tab @code{integer(acc_handle_kind) arg}
3443 @item @emph{Reference}:
3444 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3451 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
3453 @item @emph{Description}
3454 This function waits for the completion of all asynchronous operations.
3457 @multitable @columnfractions .20 .80
3458 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
3459 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
3462 @item @emph{Fortran}:
3463 @multitable @columnfractions .20 .80
3464 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
3465 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
3468 @item @emph{Reference}:
3469 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3475 @node acc_wait_all_async
3476 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
3478 @item @emph{Description}
3479 This function enqueues a wait operation on the queue @var{async} for any
3480 and all asynchronous operations that have been previously enqueued on
3484 @multitable @columnfractions .20 .80
3485 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
3488 @item @emph{Fortran}:
3489 @multitable @columnfractions .20 .80
3490 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
3491 @item @tab @code{integer(acc_handle_kind) async}
3494 @item @emph{Reference}:
3495 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3501 @node acc_wait_async
3502 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
3504 @item @emph{Description}
3505 This function enqueues a wait operation on queue @var{async} for any and all
3506 asynchronous operations enqueued on queue @var{arg}.
3509 @multitable @columnfractions .20 .80
3510 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
3513 @item @emph{Fortran}:
3514 @multitable @columnfractions .20 .80
3515 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
3516 @item @tab @code{integer(acc_handle_kind) arg, async}
3519 @item @emph{Reference}:
3520 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3527 @section @code{acc_init} -- Initialize runtime for a specific device type.
3529 @item @emph{Description}
3530 This function initializes the runtime for the device type specified in
3534 @multitable @columnfractions .20 .80
3535 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
3538 @item @emph{Fortran}:
3539 @multitable @columnfractions .20 .80
3540 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
3541 @item @tab @code{integer(acc_device_kind) devicetype}
3544 @item @emph{Reference}:
3545 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3552 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
3554 @item @emph{Description}
3555 This function shuts down the runtime for the device type specified in
3559 @multitable @columnfractions .20 .80
3560 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
3563 @item @emph{Fortran}:
3564 @multitable @columnfractions .20 .80
3565 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
3566 @item @tab @code{integer(acc_device_kind) devicetype}
3569 @item @emph{Reference}:
3570 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3577 @section @code{acc_on_device} -- Whether executing on a particular device
3579 @item @emph{Description}:
3580 This function returns whether the program is executing on a particular
3581 device specified in @var{devicetype}. In C/C++ a non-zero value is
3582 returned to indicate the device is executing on the specified device type.
3583 In Fortran, @code{true} will be returned. If the program is not executing
3584 on the specified device type C/C++ will return a zero, while Fortran will
3585 return @code{false}.
3588 @multitable @columnfractions .20 .80
3589 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
3592 @item @emph{Fortran}:
3593 @multitable @columnfractions .20 .80
3594 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
3595 @item @tab @code{integer(acc_device_kind) devicetype}
3596 @item @tab @code{logical acc_on_device}
3600 @item @emph{Reference}:
3601 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3608 @section @code{acc_malloc} -- Allocate device memory.
3610 @item @emph{Description}
3611 This function allocates @var{len} bytes of device memory. It returns
3612 the device address of the allocated memory.
3615 @multitable @columnfractions .20 .80
3616 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
3619 @item @emph{Reference}:
3620 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3627 @section @code{acc_free} -- Free device memory.
3629 @item @emph{Description}
3630 Free previously allocated device memory at the device address @code{a}.
3633 @multitable @columnfractions .20 .80
3634 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
3637 @item @emph{Reference}:
3638 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3645 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
3647 @item @emph{Description}
3648 In C/C++, this function allocates @var{len} bytes of device memory
3649 and maps it to the specified host address in @var{a}. The device
3650 address of the newly allocated device memory is returned.
3652 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3653 a contiguous array section. The second form @var{a} specifies a
3654 variable or array element and @var{len} specifies the length in bytes.
3657 @multitable @columnfractions .20 .80
3658 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
3659 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
3662 @item @emph{Fortran}:
3663 @multitable @columnfractions .20 .80
3664 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
3665 @item @tab @code{type, dimension(:[,:]...) :: a}
3666 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
3667 @item @tab @code{type, dimension(:[,:]...) :: a}
3668 @item @tab @code{integer len}
3669 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
3670 @item @tab @code{type, dimension(:[,:]...) :: a}
3671 @item @tab @code{integer(acc_handle_kind) :: async}
3672 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
3673 @item @tab @code{type, dimension(:[,:]...) :: a}
3674 @item @tab @code{integer len}
3675 @item @tab @code{integer(acc_handle_kind) :: async}
3678 @item @emph{Reference}:
3679 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3685 @node acc_present_or_copyin
3686 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
3688 @item @emph{Description}
3689 This function tests if the host data specified by @var{a} and of length
3690 @var{len} is present or not. If it is not present, then device memory
3691 will be allocated and the host memory copied. The device address of
3692 the newly allocated device memory is returned.
3694 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3695 a contiguous array section. The second form @var{a} specifies a variable or
3696 array element and @var{len} specifies the length in bytes.
3698 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
3699 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
3702 @multitable @columnfractions .20 .80
3703 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
3704 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
3707 @item @emph{Fortran}:
3708 @multitable @columnfractions .20 .80
3709 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
3710 @item @tab @code{type, dimension(:[,:]...) :: a}
3711 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
3712 @item @tab @code{type, dimension(:[,:]...) :: a}
3713 @item @tab @code{integer len}
3714 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
3715 @item @tab @code{type, dimension(:[,:]...) :: a}
3716 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
3717 @item @tab @code{type, dimension(:[,:]...) :: a}
3718 @item @tab @code{integer len}
3721 @item @emph{Reference}:
3722 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3729 @section @code{acc_create} -- Allocate device memory and map it to host memory.
3731 @item @emph{Description}
3732 This function allocates device memory and maps it to host memory specified
3733 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
3734 the function returns the device address of the allocated device memory.
3736 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3737 a contiguous array section. The second form @var{a} specifies a variable or
3738 array element and @var{len} specifies the length in bytes.
3741 @multitable @columnfractions .20 .80
3742 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
3743 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
3746 @item @emph{Fortran}:
3747 @multitable @columnfractions .20 .80
3748 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
3749 @item @tab @code{type, dimension(:[,:]...) :: a}
3750 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
3751 @item @tab @code{type, dimension(:[,:]...) :: a}
3752 @item @tab @code{integer len}
3753 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
3754 @item @tab @code{type, dimension(:[,:]...) :: a}
3755 @item @tab @code{integer(acc_handle_kind) :: async}
3756 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
3757 @item @tab @code{type, dimension(:[,:]...) :: a}
3758 @item @tab @code{integer len}
3759 @item @tab @code{integer(acc_handle_kind) :: async}
3762 @item @emph{Reference}:
3763 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3769 @node acc_present_or_create
3770 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
3772 @item @emph{Description}
3773 This function tests if the host data specified by @var{a} and of length
3774 @var{len} is present or not. If it is not present, then device memory
3775 will be allocated and mapped to host memory. In C/C++, the device address
3776 of the newly allocated device memory is returned.
3778 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3779 a contiguous array section. The second form @var{a} specifies a variable or
3780 array element and @var{len} specifies the length in bytes.
3782 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
3783 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
3786 @multitable @columnfractions .20 .80
3787 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
3788 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
3791 @item @emph{Fortran}:
3792 @multitable @columnfractions .20 .80
3793 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
3794 @item @tab @code{type, dimension(:[,:]...) :: a}
3795 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
3796 @item @tab @code{type, dimension(:[,:]...) :: a}
3797 @item @tab @code{integer len}
3798 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
3799 @item @tab @code{type, dimension(:[,:]...) :: a}
3800 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
3801 @item @tab @code{type, dimension(:[,:]...) :: a}
3802 @item @tab @code{integer len}
3805 @item @emph{Reference}:
3806 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3813 @section @code{acc_copyout} -- Copy device memory to host memory.
3815 @item @emph{Description}
3816 This function copies mapped device memory to host memory which is specified
3817 by host address @var{a} for a length @var{len} bytes in C/C++.
3819 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3820 a contiguous array section. The second form @var{a} specifies a variable or
3821 array element and @var{len} specifies the length in bytes.
3824 @multitable @columnfractions .20 .80
3825 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
3826 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
3827 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
3828 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
3831 @item @emph{Fortran}:
3832 @multitable @columnfractions .20 .80
3833 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
3834 @item @tab @code{type, dimension(:[,:]...) :: a}
3835 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
3836 @item @tab @code{type, dimension(:[,:]...) :: a}
3837 @item @tab @code{integer len}
3838 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
3839 @item @tab @code{type, dimension(:[,:]...) :: a}
3840 @item @tab @code{integer(acc_handle_kind) :: async}
3841 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
3842 @item @tab @code{type, dimension(:[,:]...) :: a}
3843 @item @tab @code{integer len}
3844 @item @tab @code{integer(acc_handle_kind) :: async}
3845 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
3846 @item @tab @code{type, dimension(:[,:]...) :: a}
3847 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
3848 @item @tab @code{type, dimension(:[,:]...) :: a}
3849 @item @tab @code{integer len}
3850 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
3851 @item @tab @code{type, dimension(:[,:]...) :: a}
3852 @item @tab @code{integer(acc_handle_kind) :: async}
3853 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
3854 @item @tab @code{type, dimension(:[,:]...) :: a}
3855 @item @tab @code{integer len}
3856 @item @tab @code{integer(acc_handle_kind) :: async}
3859 @item @emph{Reference}:
3860 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3867 @section @code{acc_delete} -- Free device memory.
3869 @item @emph{Description}
3870 This function frees previously allocated device memory specified by
3871 the device address @var{a} and the length of @var{len} bytes.
3873 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3874 a contiguous array section. The second form @var{a} specifies a variable or
3875 array element and @var{len} specifies the length in bytes.
3878 @multitable @columnfractions .20 .80
3879 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
3880 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
3881 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
3882 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
3885 @item @emph{Fortran}:
3886 @multitable @columnfractions .20 .80
3887 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
3888 @item @tab @code{type, dimension(:[,:]...) :: a}
3889 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
3890 @item @tab @code{type, dimension(:[,:]...) :: a}
3891 @item @tab @code{integer len}
3892 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
3893 @item @tab @code{type, dimension(:[,:]...) :: a}
3894 @item @tab @code{integer(acc_handle_kind) :: async}
3895 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
3896 @item @tab @code{type, dimension(:[,:]...) :: a}
3897 @item @tab @code{integer len}
3898 @item @tab @code{integer(acc_handle_kind) :: async}
3899 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
3900 @item @tab @code{type, dimension(:[,:]...) :: a}
3901 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
3902 @item @tab @code{type, dimension(:[,:]...) :: a}
3903 @item @tab @code{integer len}
3904 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
3905 @item @tab @code{type, dimension(:[,:]...) :: a}
3906 @item @tab @code{integer(acc_handle_kind) :: async}
3907 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
3908 @item @tab @code{type, dimension(:[,:]...) :: a}
3909 @item @tab @code{integer len}
3910 @item @tab @code{integer(acc_handle_kind) :: async}
3913 @item @emph{Reference}:
3914 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3920 @node acc_update_device
3921 @section @code{acc_update_device} -- Update device memory from mapped host memory.
3923 @item @emph{Description}
3924 This function updates the device copy from the previously mapped host memory.
3925 The host memory is specified with the host address @var{a} and a length of
3928 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3929 a contiguous array section. The second form @var{a} specifies a variable or
3930 array element and @var{len} specifies the length in bytes.
3933 @multitable @columnfractions .20 .80
3934 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
3935 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
3938 @item @emph{Fortran}:
3939 @multitable @columnfractions .20 .80
3940 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
3941 @item @tab @code{type, dimension(:[,:]...) :: a}
3942 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
3943 @item @tab @code{type, dimension(:[,:]...) :: a}
3944 @item @tab @code{integer len}
3945 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
3946 @item @tab @code{type, dimension(:[,:]...) :: a}
3947 @item @tab @code{integer(acc_handle_kind) :: async}
3948 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
3949 @item @tab @code{type, dimension(:[,:]...) :: a}
3950 @item @tab @code{integer len}
3951 @item @tab @code{integer(acc_handle_kind) :: async}
3954 @item @emph{Reference}:
3955 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3961 @node acc_update_self
3962 @section @code{acc_update_self} -- Update host memory from mapped device memory.
3964 @item @emph{Description}
3965 This function updates the host copy from the previously mapped device memory.
3966 The host memory is specified with the host address @var{a} and a length of
3969 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3970 a contiguous array section. The second form @var{a} specifies a variable or
3971 array element and @var{len} specifies the length in bytes.
3974 @multitable @columnfractions .20 .80
3975 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
3976 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
3979 @item @emph{Fortran}:
3980 @multitable @columnfractions .20 .80
3981 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
3982 @item @tab @code{type, dimension(:[,:]...) :: a}
3983 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
3984 @item @tab @code{type, dimension(:[,:]...) :: a}
3985 @item @tab @code{integer len}
3986 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
3987 @item @tab @code{type, dimension(:[,:]...) :: a}
3988 @item @tab @code{integer(acc_handle_kind) :: async}
3989 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
3990 @item @tab @code{type, dimension(:[,:]...) :: a}
3991 @item @tab @code{integer len}
3992 @item @tab @code{integer(acc_handle_kind) :: async}
3995 @item @emph{Reference}:
3996 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4003 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
4005 @item @emph{Description}
4006 This function maps previously allocated device and host memory. The device
4007 memory is specified with the device address @var{d}. The host memory is
4008 specified with the host address @var{h} and a length of @var{len}.
4011 @multitable @columnfractions .20 .80
4012 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
4015 @item @emph{Reference}:
4016 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4022 @node acc_unmap_data
4023 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
4025 @item @emph{Description}
4026 This function unmaps previously mapped device and host memory. The latter
4027 specified by @var{h}.
4030 @multitable @columnfractions .20 .80
4031 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
4034 @item @emph{Reference}:
4035 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4042 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
4044 @item @emph{Description}
4045 This function returns the device address that has been mapped to the
4046 host address specified by @var{h}.
4049 @multitable @columnfractions .20 .80
4050 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
4053 @item @emph{Reference}:
4054 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4061 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
4063 @item @emph{Description}
4064 This function returns the host address that has been mapped to the
4065 device address specified by @var{d}.
4068 @multitable @columnfractions .20 .80
4069 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
4072 @item @emph{Reference}:
4073 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4079 @node acc_is_present
4080 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
4082 @item @emph{Description}
4083 This function indicates whether the specified host address in @var{a} and a
4084 length of @var{len} bytes is present on the device. In C/C++, a non-zero
4085 value is returned to indicate the presence of the mapped memory on the
4086 device. A zero is returned to indicate the memory is not mapped on the
4089 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4090 a contiguous array section. The second form @var{a} specifies a variable or
4091 array element and @var{len} specifies the length in bytes. If the host
4092 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
4093 a @code{false} is return to indicate the mapped memory is not present.
4096 @multitable @columnfractions .20 .80
4097 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
4100 @item @emph{Fortran}:
4101 @multitable @columnfractions .20 .80
4102 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
4103 @item @tab @code{type, dimension(:[,:]...) :: a}
4104 @item @tab @code{logical acc_is_present}
4105 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
4106 @item @tab @code{type, dimension(:[,:]...) :: a}
4107 @item @tab @code{integer len}
4108 @item @tab @code{logical acc_is_present}
4111 @item @emph{Reference}:
4112 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4118 @node acc_memcpy_to_device
4119 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
4121 @item @emph{Description}
4122 This function copies host memory specified by host address of @var{src} to
4123 device memory specified by the device address @var{dest} for a length of
4127 @multitable @columnfractions .20 .80
4128 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
4131 @item @emph{Reference}:
4132 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4138 @node acc_memcpy_from_device
4139 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
4141 @item @emph{Description}
4142 This function copies host memory specified by host address of @var{src} from
4143 device memory specified by the device address @var{dest} for a length of
4147 @multitable @columnfractions .20 .80
4148 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
4151 @item @emph{Reference}:
4152 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4159 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
4161 @item @emph{Description}
4162 This function updates a pointer on the device from pointing to a host-pointer
4163 address to pointing to the corresponding device data.
4166 @multitable @columnfractions .20 .80
4167 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
4168 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
4171 @item @emph{Reference}:
4172 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4179 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
4181 @item @emph{Description}
4182 This function updates a pointer on the device from pointing to a device-pointer
4183 address to pointing to the corresponding host data.
4186 @multitable @columnfractions .20 .80
4187 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
4188 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
4189 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
4190 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
4193 @item @emph{Reference}:
4194 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4200 @node acc_get_current_cuda_device
4201 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
4203 @item @emph{Description}
4204 This function returns the CUDA device handle. This handle is the same
4205 as used by the CUDA Runtime or Driver API's.
4208 @multitable @columnfractions .20 .80
4209 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
4212 @item @emph{Reference}:
4213 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4219 @node acc_get_current_cuda_context
4220 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
4222 @item @emph{Description}
4223 This function returns the CUDA context handle. This handle is the same
4224 as used by the CUDA Runtime or Driver API's.
4227 @multitable @columnfractions .20 .80
4228 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
4231 @item @emph{Reference}:
4232 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4238 @node acc_get_cuda_stream
4239 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
4241 @item @emph{Description}
4242 This function returns the CUDA stream handle for the queue @var{async}.
4243 This handle is the same as used by the CUDA Runtime or Driver API's.
4246 @multitable @columnfractions .20 .80
4247 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
4250 @item @emph{Reference}:
4251 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4257 @node acc_set_cuda_stream
4258 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
4260 @item @emph{Description}
4261 This function associates the stream handle specified by @var{stream} with
4262 the queue @var{async}.
4264 This cannot be used to change the stream handle associated with
4265 @code{acc_async_sync}.
4267 The return value is not specified.
4270 @multitable @columnfractions .20 .80
4271 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
4274 @item @emph{Reference}:
4275 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4281 @node acc_prof_register
4282 @section @code{acc_prof_register} -- Register callbacks.
4284 @item @emph{Description}:
4285 This function registers callbacks.
4288 @multitable @columnfractions .20 .80
4289 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
4292 @item @emph{See also}:
4293 @ref{OpenACC Profiling Interface}
4295 @item @emph{Reference}:
4296 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4302 @node acc_prof_unregister
4303 @section @code{acc_prof_unregister} -- Unregister callbacks.
4305 @item @emph{Description}:
4306 This function unregisters callbacks.
4309 @multitable @columnfractions .20 .80
4310 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
4313 @item @emph{See also}:
4314 @ref{OpenACC Profiling Interface}
4316 @item @emph{Reference}:
4317 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4323 @node acc_prof_lookup
4324 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
4326 @item @emph{Description}:
4327 Function to obtain inquiry functions.
4330 @multitable @columnfractions .20 .80
4331 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
4334 @item @emph{See also}:
4335 @ref{OpenACC Profiling Interface}
4337 @item @emph{Reference}:
4338 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4344 @node acc_register_library
4345 @section @code{acc_register_library} -- Library registration.
4347 @item @emph{Description}:
4348 Function for library registration.
4351 @multitable @columnfractions .20 .80
4352 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
4355 @item @emph{See also}:
4356 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
4358 @item @emph{Reference}:
4359 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4365 @c ---------------------------------------------------------------------
4366 @c OpenACC Environment Variables
4367 @c ---------------------------------------------------------------------
4369 @node OpenACC Environment Variables
4370 @chapter OpenACC Environment Variables
4372 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
4373 are defined by section 4 of the OpenACC specification in version 2.0.
4374 The variable @env{ACC_PROFLIB}
4375 is defined by section 4 of the OpenACC specification in version 2.6.
4376 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
4387 @node ACC_DEVICE_TYPE
4388 @section @code{ACC_DEVICE_TYPE}
4390 @item @emph{Reference}:
4391 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4397 @node ACC_DEVICE_NUM
4398 @section @code{ACC_DEVICE_NUM}
4400 @item @emph{Reference}:
4401 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4408 @section @code{ACC_PROFLIB}
4410 @item @emph{See also}:
4411 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
4413 @item @emph{Reference}:
4414 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4420 @node GCC_ACC_NOTIFY
4421 @section @code{GCC_ACC_NOTIFY}
4423 @item @emph{Description}:
4424 Print debug information pertaining to the accelerator.
4429 @c ---------------------------------------------------------------------
4430 @c CUDA Streams Usage
4431 @c ---------------------------------------------------------------------
4433 @node CUDA Streams Usage
4434 @chapter CUDA Streams Usage
4436 This applies to the @code{nvptx} plugin only.
4438 The library provides elements that perform asynchronous movement of
4439 data and asynchronous operation of computing constructs. This
4440 asynchronous functionality is implemented by making use of CUDA
4441 streams@footnote{See "Stream Management" in "CUDA Driver API",
4442 TRM-06703-001, Version 5.5, for additional information}.
4444 The primary means by that the asynchronous functionality is accessed
4445 is through the use of those OpenACC directives which make use of the
4446 @code{async} and @code{wait} clauses. When the @code{async} clause is
4447 first used with a directive, it creates a CUDA stream. If an
4448 @code{async-argument} is used with the @code{async} clause, then the
4449 stream is associated with the specified @code{async-argument}.
4451 Following the creation of an association between a CUDA stream and the
4452 @code{async-argument} of an @code{async} clause, both the @code{wait}
4453 clause and the @code{wait} directive can be used. When either the
4454 clause or directive is used after stream creation, it creates a
4455 rendezvous point whereby execution waits until all operations
4456 associated with the @code{async-argument}, that is, stream, have
4459 Normally, the management of the streams that are created as a result of
4460 using the @code{async} clause, is done without any intervention by the
4461 caller. This implies the association between the @code{async-argument}
4462 and the CUDA stream will be maintained for the lifetime of the program.
4463 However, this association can be changed through the use of the library
4464 function @code{acc_set_cuda_stream}. When the function
4465 @code{acc_set_cuda_stream} is called, the CUDA stream that was
4466 originally associated with the @code{async} clause will be destroyed.
4467 Caution should be taken when changing the association as subsequent
4468 references to the @code{async-argument} refer to a different
4473 @c ---------------------------------------------------------------------
4474 @c OpenACC Library Interoperability
4475 @c ---------------------------------------------------------------------
4477 @node OpenACC Library Interoperability
4478 @chapter OpenACC Library Interoperability
4480 @section Introduction
4482 The OpenACC library uses the CUDA Driver API, and may interact with
4483 programs that use the Runtime library directly, or another library
4484 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
4485 "Interactions with the CUDA Driver API" in
4486 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
4487 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
4488 for additional information on library interoperability.}.
4489 This chapter describes the use cases and what changes are
4490 required in order to use both the OpenACC library and the CUBLAS and Runtime
4491 libraries within a program.
4493 @section First invocation: NVIDIA CUBLAS library API
4495 In this first use case (see below), a function in the CUBLAS library is called
4496 prior to any of the functions in the OpenACC library. More specifically, the
4497 function @code{cublasCreate()}.
4499 When invoked, the function initializes the library and allocates the
4500 hardware resources on the host and the device on behalf of the caller. Once
4501 the initialization and allocation has completed, a handle is returned to the
4502 caller. The OpenACC library also requires initialization and allocation of
4503 hardware resources. Since the CUBLAS library has already allocated the
4504 hardware resources for the device, all that is left to do is to initialize
4505 the OpenACC library and acquire the hardware resources on the host.
4507 Prior to calling the OpenACC function that initializes the library and
4508 allocate the host hardware resources, you need to acquire the device number
4509 that was allocated during the call to @code{cublasCreate()}. The invoking of the
4510 runtime library function @code{cudaGetDevice()} accomplishes this. Once
4511 acquired, the device number is passed along with the device type as
4512 parameters to the OpenACC library function @code{acc_set_device_num()}.
4514 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
4515 library uses the context that was created during the call to
4516 @code{cublasCreate()}. In other words, both libraries will be sharing the
4520 /* Create the handle */
4521 s = cublasCreate(&h);
4522 if (s != CUBLAS_STATUS_SUCCESS)
4524 fprintf(stderr, "cublasCreate failed %d\n", s);
4528 /* Get the device number */
4529 e = cudaGetDevice(&dev);
4530 if (e != cudaSuccess)
4532 fprintf(stderr, "cudaGetDevice failed %d\n", e);
4536 /* Initialize OpenACC library and use device 'dev' */
4537 acc_set_device_num(dev, acc_device_nvidia);
4542 @section First invocation: OpenACC library API
4544 In this second use case (see below), a function in the OpenACC library is
4545 called prior to any of the functions in the CUBLAS library. More specifically,
4546 the function @code{acc_set_device_num()}.
4548 In the use case presented here, the function @code{acc_set_device_num()}
4549 is used to both initialize the OpenACC library and allocate the hardware
4550 resources on the host and the device. In the call to the function, the
4551 call parameters specify which device to use and what device
4552 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
4553 is but one method to initialize the OpenACC library and allocate the
4554 appropriate hardware resources. Other methods are available through the
4555 use of environment variables and these will be discussed in the next section.
4557 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
4558 functions can be called as seen with multiple calls being made to
4559 @code{acc_copyin()}. In addition, calls can be made to functions in the
4560 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
4561 subsequent to the calls to @code{acc_copyin()}.
4562 As seen in the previous use case, a call to @code{cublasCreate()}
4563 initializes the CUBLAS library and allocates the hardware resources on the
4564 host and the device. However, since the device has already been allocated,
4565 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
4566 the appropriate hardware resources on the host. The context that was created
4567 as part of the OpenACC initialization is shared with the CUBLAS library,
4568 similarly to the first use case.
4573 acc_set_device_num(dev, acc_device_nvidia);
4575 /* Copy the first set to the device */
4576 d_X = acc_copyin(&h_X[0], N * sizeof (float));
4579 fprintf(stderr, "copyin error h_X\n");
4583 /* Copy the second set to the device */
4584 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
4587 fprintf(stderr, "copyin error h_Y1\n");
4591 /* Create the handle */
4592 s = cublasCreate(&h);
4593 if (s != CUBLAS_STATUS_SUCCESS)
4595 fprintf(stderr, "cublasCreate failed %d\n", s);
4599 /* Perform saxpy using CUBLAS library function */
4600 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
4601 if (s != CUBLAS_STATUS_SUCCESS)
4603 fprintf(stderr, "cublasSaxpy failed %d\n", s);
4607 /* Copy the results from the device */
4608 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
4613 @section OpenACC library and environment variables
4615 There are two environment variables associated with the OpenACC library
4616 that may be used to control the device type and device number:
4617 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
4618 environment variables can be used as an alternative to calling
4619 @code{acc_set_device_num()}. As seen in the second use case, the device
4620 type and device number were specified using @code{acc_set_device_num()}.
4621 If however, the aforementioned environment variables were set, then the
4622 call to @code{acc_set_device_num()} would not be required.
4625 The use of the environment variables is only relevant when an OpenACC function
4626 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
4627 is called prior to a call to an OpenACC function, then you must call
4628 @code{acc_set_device_num()}@footnote{More complete information
4629 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
4630 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
4631 Application Programming Interface”, Version 2.6.}
4635 @c ---------------------------------------------------------------------
4636 @c OpenACC Profiling Interface
4637 @c ---------------------------------------------------------------------
4639 @node OpenACC Profiling Interface
4640 @chapter OpenACC Profiling Interface
4642 @section Implementation Status and Implementation-Defined Behavior
4644 We're implementing the OpenACC Profiling Interface as defined by the
4645 OpenACC 2.6 specification. We're clarifying some aspects here as
4646 @emph{implementation-defined behavior}, while they're still under
4647 discussion within the OpenACC Technical Committee.
4649 This implementation is tuned to keep the performance impact as low as
4650 possible for the (very common) case that the Profiling Interface is
4651 not enabled. This is relevant, as the Profiling Interface affects all
4652 the @emph{hot} code paths (in the target code, not in the offloaded
4653 code). Users of the OpenACC Profiling Interface can be expected to
4654 understand that performance will be impacted to some degree once the
4655 Profiling Interface has gotten enabled: for example, because of the
4656 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
4657 every event that has been registered.
4659 We're not yet accounting for the fact that @cite{OpenACC events may
4660 occur during event processing}.
4661 We just handle one case specially, as required by CUDA 9.0
4662 @command{nvprof}, that @code{acc_get_device_type}
4663 (@ref{acc_get_device_type})) may be called from
4664 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4667 We're not yet implementing initialization via a
4668 @code{acc_register_library} function that is either statically linked
4669 in, or dynamically via @env{LD_PRELOAD}.
4670 Initialization via @code{acc_register_library} functions dynamically
4671 loaded via the @env{ACC_PROFLIB} environment variable does work, as
4672 does directly calling @code{acc_prof_register},
4673 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
4675 As currently there are no inquiry functions defined, calls to
4676 @code{acc_prof_lookup} will always return @code{NULL}.
4678 There aren't separate @emph{start}, @emph{stop} events defined for the
4679 event types @code{acc_ev_create}, @code{acc_ev_delete},
4680 @code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
4681 should be triggered before or after the actual device-specific call is
4682 made. We trigger them after.
4684 Remarks about data provided to callbacks:
4688 @item @code{acc_prof_info.event_type}
4689 It's not clear if for @emph{nested} event callbacks (for example,
4690 @code{acc_ev_enqueue_launch_start} as part of a parent compute
4691 construct), this should be set for the nested event
4692 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
4693 construct should remain (@code{acc_ev_compute_construct_start}). In
4694 this implementation, the value will generally correspond to the
4695 innermost nested event type.
4697 @item @code{acc_prof_info.device_type}
4701 For @code{acc_ev_compute_construct_start}, and in presence of an
4702 @code{if} clause with @emph{false} argument, this will still refer to
4703 the offloading device type.
4704 It's not clear if that's the expected behavior.
4707 Complementary to the item before, for
4708 @code{acc_ev_compute_construct_end}, this is set to
4709 @code{acc_device_host} in presence of an @code{if} clause with
4710 @emph{false} argument.
4711 It's not clear if that's the expected behavior.
4715 @item @code{acc_prof_info.thread_id}
4716 Always @code{-1}; not yet implemented.
4718 @item @code{acc_prof_info.async}
4722 Not yet implemented correctly for
4723 @code{acc_ev_compute_construct_start}.
4726 In a compute construct, for host-fallback
4727 execution/@code{acc_device_host} it will always be
4728 @code{acc_async_sync}.
4729 It's not clear if that's the expected behavior.
4732 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
4733 it will always be @code{acc_async_sync}.
4734 It's not clear if that's the expected behavior.
4738 @item @code{acc_prof_info.async_queue}
4739 There is no @cite{limited number of asynchronous queues} in libgomp.
4740 This will always have the same value as @code{acc_prof_info.async}.
4742 @item @code{acc_prof_info.src_file}
4743 Always @code{NULL}; not yet implemented.
4745 @item @code{acc_prof_info.func_name}
4746 Always @code{NULL}; not yet implemented.
4748 @item @code{acc_prof_info.line_no}
4749 Always @code{-1}; not yet implemented.
4751 @item @code{acc_prof_info.end_line_no}
4752 Always @code{-1}; not yet implemented.
4754 @item @code{acc_prof_info.func_line_no}
4755 Always @code{-1}; not yet implemented.
4757 @item @code{acc_prof_info.func_end_line_no}
4758 Always @code{-1}; not yet implemented.
4760 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
4761 Relating to @code{acc_prof_info.event_type} discussed above, in this
4762 implementation, this will always be the same value as
4763 @code{acc_prof_info.event_type}.
4765 @item @code{acc_event_info.*.parent_construct}
4769 Will be @code{acc_construct_parallel} for all OpenACC compute
4770 constructs as well as many OpenACC Runtime API calls; should be the
4771 one matching the actual construct, or
4772 @code{acc_construct_runtime_api}, respectively.
4775 Will be @code{acc_construct_enter_data} or
4776 @code{acc_construct_exit_data} when processing variable mappings
4777 specified in OpenACC @emph{declare} directives; should be
4778 @code{acc_construct_declare}.
4781 For implicit @code{acc_ev_device_init_start},
4782 @code{acc_ev_device_init_end}, and explicit as well as implicit
4783 @code{acc_ev_alloc}, @code{acc_ev_free},
4784 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4785 @code{acc_ev_enqueue_download_start}, and
4786 @code{acc_ev_enqueue_download_end}, will be
4787 @code{acc_construct_parallel}; should reflect the real parent
4792 @item @code{acc_event_info.*.implicit}
4793 For @code{acc_ev_alloc}, @code{acc_ev_free},
4794 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4795 @code{acc_ev_enqueue_download_start}, and
4796 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
4797 also for explicit usage.
4799 @item @code{acc_event_info.data_event.var_name}
4800 Always @code{NULL}; not yet implemented.
4802 @item @code{acc_event_info.data_event.host_ptr}
4803 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
4806 @item @code{typedef union acc_api_info}
4807 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
4808 Information}. This should obviously be @code{typedef @emph{struct}
4811 @item @code{acc_api_info.device_api}
4812 Possibly not yet implemented correctly for
4813 @code{acc_ev_compute_construct_start},
4814 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
4815 will always be @code{acc_device_api_none} for these event types.
4816 For @code{acc_ev_enter_data_start}, it will be
4817 @code{acc_device_api_none} in some cases.
4819 @item @code{acc_api_info.device_type}
4820 Always the same as @code{acc_prof_info.device_type}.
4822 @item @code{acc_api_info.vendor}
4823 Always @code{-1}; not yet implemented.
4825 @item @code{acc_api_info.device_handle}
4826 Always @code{NULL}; not yet implemented.
4828 @item @code{acc_api_info.context_handle}
4829 Always @code{NULL}; not yet implemented.
4831 @item @code{acc_api_info.async_handle}
4832 Always @code{NULL}; not yet implemented.
4836 Remarks about certain event types:
4840 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4844 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
4845 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
4846 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
4847 When a compute construct triggers implicit
4848 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
4849 events, they currently aren't @emph{nested within} the corresponding
4850 @code{acc_ev_compute_construct_start} and
4851 @code{acc_ev_compute_construct_end}, but they're currently observed
4852 @emph{before} @code{acc_ev_compute_construct_start}.
4853 It's not clear what to do: the standard asks us provide a lot of
4854 details to the @code{acc_ev_compute_construct_start} callback, without
4855 (implicitly) initializing a device before?
4858 Callbacks for these event types will not be invoked for calls to the
4859 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
4860 It's not clear if they should be.
4864 @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}
4868 Callbacks for these event types will also be invoked for OpenACC
4869 @emph{host_data} constructs.
4870 It's not clear if they should be.
4873 Callbacks for these event types will also be invoked when processing
4874 variable mappings specified in OpenACC @emph{declare} directives.
4875 It's not clear if they should be.
4881 Callbacks for the following event types will be invoked, but dispatch
4882 and information provided therein has not yet been thoroughly reviewed:
4885 @item @code{acc_ev_alloc}
4886 @item @code{acc_ev_free}
4887 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
4888 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
4889 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
4892 During device initialization, and finalization, respectively,
4893 callbacks for the following event types will not yet be invoked:
4896 @item @code{acc_ev_alloc}
4897 @item @code{acc_ev_free}
4900 Callbacks for the following event types have not yet been implemented,
4901 so currently won't be invoked:
4904 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
4905 @item @code{acc_ev_runtime_shutdown}
4906 @item @code{acc_ev_create}, @code{acc_ev_delete}
4907 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
4910 For the following runtime library functions, not all expected
4911 callbacks will be invoked (mostly concerning implicit device
4915 @item @code{acc_get_num_devices}
4916 @item @code{acc_set_device_type}
4917 @item @code{acc_get_device_type}
4918 @item @code{acc_set_device_num}
4919 @item @code{acc_get_device_num}
4920 @item @code{acc_init}
4921 @item @code{acc_shutdown}
4924 Aside from implicit device initialization, for the following runtime
4925 library functions, no callbacks will be invoked for shared-memory
4926 offloading devices (it's not clear if they should be):
4929 @item @code{acc_malloc}
4930 @item @code{acc_free}
4931 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
4932 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
4933 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
4934 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
4935 @item @code{acc_update_device}, @code{acc_update_device_async}
4936 @item @code{acc_update_self}, @code{acc_update_self_async}
4937 @item @code{acc_map_data}, @code{acc_unmap_data}
4938 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
4939 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
4942 @c ---------------------------------------------------------------------
4943 @c OpenMP-Implementation Specifics
4944 @c ---------------------------------------------------------------------
4946 @node OpenMP-Implementation Specifics
4947 @chapter OpenMP-Implementation Specifics
4950 * Implementation-defined ICV Initialization::
4951 * OpenMP Context Selectors::
4952 * Memory allocation::
4955 @node Implementation-defined ICV Initialization
4956 @section Implementation-defined ICV Initialization
4957 @cindex Implementation specific setting
4959 @multitable @columnfractions .30 .70
4960 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
4961 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
4962 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
4963 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
4964 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
4965 @item @var{num-devices-var} @tab Number of non-host devices found
4966 by GCC's run-time library
4967 @item @var{num-procs-var} @tab The number of CPU cores on the
4968 initial device, except that affinity settings might lead to a
4969 smaller number. On non-host devices, the value of the
4970 @var{nthreads-var} ICV.
4971 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
4972 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
4973 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
4974 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
4975 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
4976 @ref{GOMP_SPINCOUNT}
4979 @node OpenMP Context Selectors
4980 @section OpenMP Context Selectors
4982 @code{vendor} is always @code{gnu}. References are to the GCC manual.
4984 @multitable @columnfractions .60 .10 .25
4985 @headitem @code{arch} @tab @code{kind} @tab @code{isa}
4986 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
4987 @code{i586}, @code{i686}, @code{ia32}
4989 @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
4990 @item @code{amdgcn}, @code{gcn}
4992 @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
4993 @code{gfx803} is supported as an alias for @code{fiji}.}
4996 @tab See @code{-march=} in ``Nvidia PTX Options''
4999 @node Memory allocation
5000 @section Memory allocation
5002 For the available predefined allocators and, as applicable, their associated
5003 predefined memory spaces and for the available traits and their default values,
5004 see @ref{OMP_ALLOCATOR}. Predefined allocators without an associated memory
5005 space use the @code{omp_default_mem_space} memory space.
5007 For the memory spaces, the following applies:
5009 @item @code{omp_default_mem_space} is supported
5010 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
5011 @item @code{omp_low_lat_mem_space} maps to @code{omp_default_mem_space}
5012 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
5013 unless the memkind library is available
5014 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
5015 unless the memkind library is available
5018 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
5019 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
5020 creating memory allocators requesting
5023 @item the memory space @code{omp_high_bw_mem_space}
5024 @item the memory space @code{omp_large_cap_mem_space}
5025 @item the @code{partition} trait @code{interleaved}; note that for
5026 @code{omp_large_cap_mem_space} the allocation will not be interleaved
5029 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
5030 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
5031 memory allocators requesting
5034 @item the @code{partition} trait @code{nearest}, except when both the
5035 libmemkind library is available and the memory space is either
5036 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
5039 Note that the numa library will round up the allocation size to a multiple of
5040 the system page size; therefore, consider using it only with large data or
5041 by sharing allocations via the @code{pool_size} trait. Furthermore, the Linux
5042 kernel does not guarantee that an allocation will always be on the nearest NUMA
5043 node nor that after reallocation the same node will be used. Note additionally
5044 that, on Linux, the default setting of the memory placement policy is to use the
5045 current node; therefore, unless the memory placement policy has been overridden,
5046 the @code{partition} trait @code{environment} (the default) will be effectively
5047 a @code{nearest} allocation.
5049 Additional notes regarding the traits:
5051 @item The @code{pinned} trait is unsupported.
5052 @item The default for the @code{pool_size} trait is no pool and for every
5053 (re)allocation the associated library routine is called, which might
5054 internally use a memory pool.
5055 @item For the @code{partition} trait, the partition part size will be the same
5056 as the requested size (i.e. @code{interleaved} or @code{blocked} has no
5057 effect), except for @code{interleaved} when the memkind library is
5058 available. Furthermore, for @code{nearest} and unless the numa library
5059 is available, the memory might not be on the same NUMA node as thread
5060 that allocated the memory; on Linux, this is in particular the case when
5061 the memory placement policy is set to preferred.
5062 @item The @code{access} trait has no effect such that memory is always
5063 accessible by all threads.
5064 @item The @code{sync_hint} trait has no effect.
5067 @c ---------------------------------------------------------------------
5068 @c Offload-Target Specifics
5069 @c ---------------------------------------------------------------------
5071 @node Offload-Target Specifics
5072 @chapter Offload-Target Specifics
5074 The following sections present notes on the offload-target specifics
5082 @section AMD Radeon (GCN)
5084 On the hardware side, there is the hierarchy (fine to coarse):
5086 @item work item (thread)
5089 @item compute unit (CU)
5092 All OpenMP and OpenACC levels are used, i.e.
5094 @item OpenMP's simd and OpenACC's vector map to work items (thread)
5095 @item OpenMP's threads (``parallel'') and OpenACC's workers map
5097 @item OpenMP's teams and OpenACC's gang use a threadpool with the
5098 size of the number of teams or gangs, respectively.
5103 @item Number of teams is the specified @code{num_teams} (OpenMP) or
5104 @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
5105 by two times the number of CU.
5106 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
5107 @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
5108 overrides this if smaller.
5109 @item The wavefront has 102 scalars and 64 vectors
5110 @item Number of workitems is always 64
5111 @item The hardware permits maximally 40 workgroups/CU and
5112 16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
5113 @item 80 scalars registers and 24 vector registers in non-kernel functions
5114 (the chosen procedure-calling API).
5115 @item For the kernel itself: as many as register pressure demands (number of
5116 teams and number of threads, scaled down if registers are exhausted)
5119 The implementation remark:
5121 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
5122 using the C library @code{printf} functions and the Fortran
5123 @code{print}/@code{write} statements.
5124 @item Reverse offload regions (i.e. @code{target} regions with
5125 @code{device(ancestor:1)}) are processed serially per @code{target} region
5126 such that the next reverse offload region is only executed after the previous
5128 @item OpenMP code that has a @code{requires} directive with
5129 @code{unified_shared_memory} will remove any GCN device from the list of
5130 available devices (``host fallback'').
5131 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
5132 environment variable; the default is 32 kiB per thread.
5140 On the hardware side, there is the hierarchy (fine to coarse):
5145 @item streaming multiprocessor
5148 All OpenMP and OpenACC levels are used, i.e.
5150 @item OpenMP's simd and OpenACC's vector map to threads
5151 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
5152 @item OpenMP's teams and OpenACC's gang use a threadpool with the
5153 size of the number of teams or gangs, respectively.
5158 @item The @code{warp_size} is always 32
5159 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
5160 @item The number of teams is limited by the number of blocks the device can
5161 host simultaneously.
5164 Additional information can be obtained by setting the environment variable to
5165 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
5168 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
5169 which caches the JIT in the user's directory (see CUDA documentation; can be
5170 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
5172 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
5173 options still affect the used PTX ISA code and, thus, the requirements on
5174 CUDA version and hardware.
5176 The implementation remark:
5178 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
5179 using the C library @code{printf} functions. Note that the Fortran
5180 @code{print}/@code{write} statements are not supported, yet.
5181 @item Compilation OpenMP code that contains @code{requires reverse_offload}
5182 requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
5184 @item For code containing reverse offload (i.e. @code{target} regions with
5185 @code{device(ancestor:1)}), there is a slight performance penalty
5186 for @emph{all} target regions, consisting mostly of shutdown delay
5187 Per device, reverse offload regions are processed serially such that
5188 the next reverse offload region is only executed after the previous
5190 @item OpenMP code that has a @code{requires} directive with
5191 @code{unified_shared_memory} will remove any nvptx device from the
5192 list of available devices (``host fallback'').
5193 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
5195 @item The OpenMP routines @code{omp_target_memcpy_rect} and
5196 @code{omp_target_memcpy_rect_async} and the @code{target update}
5197 directive for non-contiguous list items will use the 2D and 3D
5198 memory-copy functions of the CUDA library. Higher dimensions will
5199 call those functions in a loop and are therefore supported.
5203 @c ---------------------------------------------------------------------
5205 @c ---------------------------------------------------------------------
5207 @node The libgomp ABI
5208 @chapter The libgomp ABI
5210 The following sections present notes on the external ABI as
5211 presented by libgomp. Only maintainers should need them.
5214 * Implementing MASTER construct::
5215 * Implementing CRITICAL construct::
5216 * Implementing ATOMIC construct::
5217 * Implementing FLUSH construct::
5218 * Implementing BARRIER construct::
5219 * Implementing THREADPRIVATE construct::
5220 * Implementing PRIVATE clause::
5221 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
5222 * Implementing REDUCTION clause::
5223 * Implementing PARALLEL construct::
5224 * Implementing FOR construct::
5225 * Implementing ORDERED construct::
5226 * Implementing SECTIONS construct::
5227 * Implementing SINGLE construct::
5228 * Implementing OpenACC's PARALLEL construct::
5232 @node Implementing MASTER construct
5233 @section Implementing MASTER construct
5236 if (omp_get_thread_num () == 0)
5240 Alternately, we generate two copies of the parallel subfunction
5241 and only include this in the version run by the primary thread.
5242 Surely this is not worthwhile though...
5246 @node Implementing CRITICAL construct
5247 @section Implementing CRITICAL construct
5249 Without a specified name,
5252 void GOMP_critical_start (void);
5253 void GOMP_critical_end (void);
5256 so that we don't get COPY relocations from libgomp to the main
5259 With a specified name, use omp_set_lock and omp_unset_lock with
5260 name being transformed into a variable declared like
5263 omp_lock_t gomp_critical_user_<name> __attribute__((common))
5266 Ideally the ABI would specify that all zero is a valid unlocked
5267 state, and so we wouldn't need to initialize this at
5272 @node Implementing ATOMIC construct
5273 @section Implementing ATOMIC construct
5275 The target should implement the @code{__sync} builtins.
5277 Failing that we could add
5280 void GOMP_atomic_enter (void)
5281 void GOMP_atomic_exit (void)
5284 which reuses the regular lock code, but with yet another lock
5285 object private to the library.
5289 @node Implementing FLUSH construct
5290 @section Implementing FLUSH construct
5292 Expands to the @code{__sync_synchronize} builtin.
5296 @node Implementing BARRIER construct
5297 @section Implementing BARRIER construct
5300 void GOMP_barrier (void)
5304 @node Implementing THREADPRIVATE construct
5305 @section Implementing THREADPRIVATE construct
5307 In _most_ cases we can map this directly to @code{__thread}. Except
5308 that OMP allows constructors for C++ objects. We can either
5309 refuse to support this (how often is it used?) or we can
5310 implement something akin to .ctors.
5312 Even more ideally, this ctor feature is handled by extensions
5313 to the main pthreads library. Failing that, we can have a set
5314 of entry points to register ctor functions to be called.
5318 @node Implementing PRIVATE clause
5319 @section Implementing PRIVATE clause
5321 In association with a PARALLEL, or within the lexical extent
5322 of a PARALLEL block, the variable becomes a local variable in
5323 the parallel subfunction.
5325 In association with FOR or SECTIONS blocks, create a new
5326 automatic variable within the current function. This preserves
5327 the semantic of new variable creation.
5331 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
5332 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
5334 This seems simple enough for PARALLEL blocks. Create a private
5335 struct for communicating between the parent and subfunction.
5336 In the parent, copy in values for scalar and "small" structs;
5337 copy in addresses for others TREE_ADDRESSABLE types. In the
5338 subfunction, copy the value into the local variable.
5340 It is not clear what to do with bare FOR or SECTION blocks.
5341 The only thing I can figure is that we do something like:
5344 #pragma omp for firstprivate(x) lastprivate(y)
5345 for (int i = 0; i < n; ++i)
5362 where the "x=x" and "y=y" assignments actually have different
5363 uids for the two variables, i.e. not something you could write
5364 directly in C. Presumably this only makes sense if the "outer"
5365 x and y are global variables.
5367 COPYPRIVATE would work the same way, except the structure
5368 broadcast would have to happen via SINGLE machinery instead.
5372 @node Implementing REDUCTION clause
5373 @section Implementing REDUCTION clause
5375 The private struct mentioned in the previous section should have
5376 a pointer to an array of the type of the variable, indexed by the
5377 thread's @var{team_id}. The thread stores its final value into the
5378 array, and after the barrier, the primary thread iterates over the
5379 array to collect the values.
5382 @node Implementing PARALLEL construct
5383 @section Implementing PARALLEL construct
5386 #pragma omp parallel
5395 void subfunction (void *data)
5402 GOMP_parallel_start (subfunction, &data, num_threads);
5403 subfunction (&data);
5404 GOMP_parallel_end ();
5408 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
5411 The @var{FN} argument is the subfunction to be run in parallel.
5413 The @var{DATA} argument is a pointer to a structure used to
5414 communicate data in and out of the subfunction, as discussed
5415 above with respect to FIRSTPRIVATE et al.
5417 The @var{NUM_THREADS} argument is 1 if an IF clause is present
5418 and false, or the value of the NUM_THREADS clause, if
5421 The function needs to create the appropriate number of
5422 threads and/or launch them from the dock. It needs to
5423 create the team structure and assign team ids.
5426 void GOMP_parallel_end (void)
5429 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
5433 @node Implementing FOR construct
5434 @section Implementing FOR construct
5437 #pragma omp parallel for
5438 for (i = lb; i <= ub; i++)
5445 void subfunction (void *data)
5448 while (GOMP_loop_static_next (&_s0, &_e0))
5451 for (i = _s0; i < _e1; i++)
5454 GOMP_loop_end_nowait ();
5457 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
5459 GOMP_parallel_end ();
5463 #pragma omp for schedule(runtime)
5464 for (i = 0; i < n; i++)
5473 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
5476 for (i = _s0, i < _e0; i++)
5478 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
5483 Note that while it looks like there is trickiness to propagating
5484 a non-constant STEP, there isn't really. We're explicitly allowed
5485 to evaluate it as many times as we want, and any variables involved
5486 should automatically be handled as PRIVATE or SHARED like any other
5487 variables. So the expression should remain evaluable in the
5488 subfunction. We can also pull it into a local variable if we like,
5489 but since its supposed to remain unchanged, we can also not if we like.
5491 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
5492 able to get away with no work-sharing context at all, since we can
5493 simply perform the arithmetic directly in each thread to divide up
5494 the iterations. Which would mean that we wouldn't need to call any
5497 There are separate routines for handling loops with an ORDERED
5498 clause. Bookkeeping for that is non-trivial...
5502 @node Implementing ORDERED construct
5503 @section Implementing ORDERED construct
5506 void GOMP_ordered_start (void)
5507 void GOMP_ordered_end (void)
5512 @node Implementing SECTIONS construct
5513 @section Implementing SECTIONS construct
5518 #pragma omp sections
5532 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
5549 @node Implementing SINGLE construct
5550 @section Implementing SINGLE construct
5564 if (GOMP_single_start ())
5572 #pragma omp single copyprivate(x)
5579 datap = GOMP_single_copy_start ();
5584 GOMP_single_copy_end (&data);
5593 @node Implementing OpenACC's PARALLEL construct
5594 @section Implementing OpenACC's PARALLEL construct
5597 void GOACC_parallel ()
5602 @c ---------------------------------------------------------------------
5604 @c ---------------------------------------------------------------------
5606 @node Reporting Bugs
5607 @chapter Reporting Bugs
5609 Bugs in the GNU Offloading and Multi Processing Runtime Library should
5610 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
5611 "openacc", or "openmp", or both to the keywords field in the bug
5612 report, as appropriate.
5616 @c ---------------------------------------------------------------------
5617 @c GNU General Public License
5618 @c ---------------------------------------------------------------------
5620 @include gpl_v3.texi
5624 @c ---------------------------------------------------------------------
5625 @c GNU Free Documentation License
5626 @c ---------------------------------------------------------------------
5632 @c ---------------------------------------------------------------------
5633 @c Funding Free Software
5634 @c ---------------------------------------------------------------------
5636 @include funding.texi
5638 @c ---------------------------------------------------------------------
5640 @c ---------------------------------------------------------------------
5643 @unnumbered Library Index