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 @emph{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
192 env variable @tab Y @tab
193 @item Nested-parallel changes to @emph{max-active-levels-var} ICV @tab Y @tab
194 @item @code{requires} directive @tab P
195 @tab complete but no non-host devices 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 @tab Full support for C/C++, partial for Fortran
198 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
199 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
200 constructs @tab Y @tab
201 @item Collapse of associated loops that are imperfectly nested loops @tab N @tab
202 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
203 @code{simd} construct @tab Y @tab
204 @item @code{atomic} constructs in @code{simd} @tab Y @tab
205 @item @code{loop} construct @tab Y @tab
206 @item @code{order(concurrent)} clause @tab Y @tab
207 @item @code{scan} directive and @code{in_scan} modifier for the
208 @code{reduction} clause @tab Y @tab
209 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
210 @item @code{in_reduction} clause on @code{target} constructs @tab P
211 @tab @code{nowait} only stub
212 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
213 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
214 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
215 @item @code{detach} clause to @code{task} construct @tab Y @tab
216 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
217 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
218 and @code{taskloop simd} constructs @tab Y @tab
219 @item @code{taskloop} construct cancelable by @code{cancel} construct
221 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
223 @item Predefined memory spaces, memory allocators, allocator traits
224 @tab Y @tab Some are only stubs
225 @item Memory management routines @tab Y @tab
226 @item @code{allocate} directive @tab N @tab
227 @item @code{allocate} clause @tab P @tab Initial support
228 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
229 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
230 @item Implicit declare target directive @tab Y @tab
231 @item Discontiguous array section with @code{target update} construct
233 @item C/C++'s lvalue expressions in @code{to}, @code{from}
234 and @code{map} clauses @tab N @tab
235 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
236 @item Nested @code{declare target} directive @tab Y @tab
237 @item Combined @code{master} constructs @tab Y @tab
238 @item @code{depend} clause on @code{taskwait} @tab Y @tab
239 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
241 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
242 @item @code{depobj} construct and depend objects @tab Y @tab
243 @item Lock hints were renamed to synchronization hints @tab Y @tab
244 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
245 @item Map-order clarifications @tab P @tab
246 @item @code{close} @emph{map-type-modifier} @tab Y @tab
247 @item Mapping C/C++ pointer variables and to assign the address of
248 device memory mapped by an array section @tab P @tab
249 @item Mapping of Fortran pointer and allocatable variables, including pointer
250 and allocatable components of variables
251 @tab P @tab Mapping of vars with allocatable components unsupported
252 @item @code{defaultmap} extensions @tab Y @tab
253 @item @code{declare mapper} directive @tab N @tab
254 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
255 @item Runtime routines and environment variables to display runtime thread
256 affinity information @tab Y @tab
257 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
259 @item @code{omp_get_device_num} runtime routine @tab Y @tab
260 @item OMPT interface @tab N @tab
261 @item OMPD interface @tab N @tab
264 @unnumberedsubsec Other new OpenMP 5.0 features
266 @multitable @columnfractions .60 .10 .25
267 @headitem Description @tab Status @tab Comments
268 @item Supporting C++'s range-based for loop @tab Y @tab
275 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
277 @multitable @columnfractions .60 .10 .25
278 @headitem Description @tab Status @tab Comments
279 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
280 @item @code{omp_all_memory} reserved locator @tab Y @tab
281 @item @emph{target_device trait} in OpenMP Context @tab N @tab
282 @item @code{target_device} selector set in context selectors @tab N @tab
283 @item C/C++'s @code{declare variant} directive: elision support of
284 preprocessed code @tab N @tab
285 @item @code{declare variant}: new clauses @code{adjust_args} and
286 @code{append_args} @tab N @tab
287 @item @code{dispatch} construct @tab N @tab
288 @item device-specific ICV settings with environment variables @tab Y @tab
289 @item @code{assume} and @code{assumes} directives @tab Y @tab
290 @item @code{nothing} directive @tab Y @tab
291 @item @code{error} directive @tab Y @tab
292 @item @code{masked} construct @tab Y @tab
293 @item @code{scope} directive @tab Y @tab
294 @item Loop transformation constructs @tab N @tab
295 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
296 clauses of the @code{taskloop} construct @tab Y @tab
297 @item @code{align} clause in @code{allocate} directive @tab N @tab
298 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
299 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
300 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
301 @item Iterators in @code{target update} motion clauses and @code{map}
303 @item Indirect calls to the device version of a procedure or function in
304 @code{target} regions @tab N @tab
305 @item @code{interop} directive @tab N @tab
306 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
307 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
308 @item Extensions to the @code{atomic} directive @tab Y @tab
309 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
310 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
311 @item @code{private} and @code{firstprivate} argument to @code{default}
312 clause in C and C++ @tab Y @tab
313 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
314 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
315 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
317 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
318 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
319 runtime routines @tab Y @tab
320 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
321 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
322 @code{omp_aligned_calloc} runtime routines @tab Y @tab
323 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
324 @code{omp_atv_default} changed @tab Y @tab
325 @item @code{omp_display_env} runtime routine @tab Y @tab
326 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
327 @item @code{ompt_sync_region_t} enum additions @tab N @tab
328 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
329 and @code{ompt_state_wait_barrier_teams} @tab N @tab
330 @item @code{ompt_callback_target_data_op_emi_t},
331 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
332 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
333 @item @code{ompt_callback_error_t} type @tab N @tab
334 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
335 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
336 variables @tab Y @tab
339 @unnumberedsubsec Other new OpenMP 5.1 features
341 @multitable @columnfractions .60 .10 .25
342 @headitem Description @tab Status @tab Comments
343 @item Support of strictly structured blocks in Fortran @tab Y @tab
344 @item Support of structured block sequences in C/C++ @tab Y @tab
345 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
347 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
348 @item Pointer predetermined firstprivate getting initialized
349 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
350 @item For Fortran, diagnose placing declarative before/between @code{USE},
351 @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
352 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
353 @item @code{indirect} clause in @code{declare target} @tab N @tab
354 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
355 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
363 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
365 @multitable @columnfractions .60 .10 .25
366 @headitem Description @tab Status @tab Comments
367 @item @code{omp_in_explicit_task} routine and @emph{explicit-task-var} ICV
369 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
371 @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
372 sentinel as C/C++ pragma and C++ attributes are warned for with
373 @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
374 (enabled by default), respectively; for Fortran free-source code, there is
375 a warning enabled by default and, for fixed-source code, the @code{omx}
376 sentinel is warned for with with @code{-Wsurprising} (enabled by
377 @code{-Wall}). Unknown clauses are always rejected with an error.}
378 @item Clauses on @code{end} directive can be on directive @tab Y @tab
379 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
381 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
382 @item Deprecation of minus operator for reductions @tab N @tab
383 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
384 @item @code{declare mapper} with iterator and @code{present} modifiers
386 @item If a matching mapped list item is not found in the data environment, the
387 pointer retains its original value @tab N @tab
388 @item New @code{enter} clause as alias for @code{to} on declare target directive
390 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
391 @item Extended list of directives permitted in Fortran pure procedures
393 @item New @code{allocators} directive for Fortran @tab N @tab
394 @item Deprecation of @code{allocate} directive for Fortran
395 allocatables/pointers @tab N @tab
396 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
397 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
399 @item Deprecation of traits array following the allocator_handle expression in
400 @code{uses_allocators} @tab N @tab
401 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
403 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
404 @item Deprecation of delimited form of @code{declare target} @tab N @tab
405 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
406 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
408 @item @code{ompt_callback_work} @tab N @tab
409 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
411 @item New @code{doacross} clause as alias for @code{depend} with
412 @code{source}/@code{sink} modifier @tab Y @tab
413 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
415 @item @code{omp_cur_iteration} keyword @tab Y @tab
418 @unnumberedsubsec Other new OpenMP 5.2 features
420 @multitable @columnfractions .60 .10 .25
421 @headitem Description @tab Status @tab Comments
422 @item For Fortran, optional comma between directive and clause @tab N @tab
423 @item Conforming device numbers and @code{omp_initial_device} and
424 @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
425 @item Initial value of @emph{default-device-var} ICV with
426 @code{OMP_TARGET_OFFLOAD=mandatory} @tab N @tab
427 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
428 of the @code{interop} construct @tab N @tab
432 @node OpenMP Technical Report 11
433 @section OpenMP Technical Report 11
435 Technical Report (TR) 11 is the first preview for OpenMP 6.0.
437 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
438 @multitable @columnfractions .60 .10 .25
439 @item Features deprecated in versions 5.2, 5.1 and 5.0 were removed
440 @tab N/A @tab Backward compatibility
441 @item The @code{decl} attribute was added to the C++ attribute syntax
443 @item @code{_ALL} suffix to the device-scope environment variables
444 @tab P @tab Host device number wrongly accepted
445 @item For Fortran, @emph{locator list} can be also function reference with
446 data pointer result @tab N @tab
447 @item Ref-count change for @code{use_device_ptr}/@code{use_device_addr}
449 @item Implicit reduction identifiers of C++ classes
451 @item Change of the @emph{map-type} property from @emph{ultimate} to
452 @emph{default} @tab N @tab
453 @item Concept of @emph{assumed-size arrays} in C and C++
455 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
457 @item @code{groupprivate} directive @tab N @tab
458 @item @code{local} clause to declare target directive @tab N @tab
459 @item @code{part_size} allocator trait @tab N @tab
460 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
463 @item @code{access} allocator trait changes @tab N @tab
464 @item Extension of @code{interop} operation of @code{append_args}, allowing all
465 modifiers of the @code{init} clause
467 @item @code{interop} clause to @code{dispatch} @tab N @tab
468 @item @code{apply} code to loop-transforming constructs @tab N @tab
469 @item @code{omp_curr_progress_width} identifier @tab N @tab
470 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
471 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
472 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
473 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
474 @item Routines for obtaining memory spaces/allocators for shared/device memory
476 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
477 @item @code{omp_get_submemspace} routine @tab N @tab
478 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
479 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
480 @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
481 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
484 @unnumberedsubsec Other new TR 11 features
485 @multitable @columnfractions .60 .10 .25
486 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
487 @item Mapping lambda captures @tab N @tab
488 @item For Fortran, atomic compare with storing the comparison result
490 @item @code{aligned} clause changes for @code{simd} and @code{declare simd}
496 @c ---------------------------------------------------------------------
497 @c OpenMP Runtime Library Routines
498 @c ---------------------------------------------------------------------
500 @node Runtime Library Routines
501 @chapter OpenMP Runtime Library Routines
503 The runtime routines described here are defined by Section 3 of the OpenMP
504 specification in version 4.5. The routines are structured in following
508 Control threads, processors and the parallel environment. They have C
509 linkage, and do not throw exceptions.
511 * omp_get_active_level:: Number of active parallel regions
512 * omp_get_ancestor_thread_num:: Ancestor thread ID
513 * omp_get_cancellation:: Whether cancellation support is enabled
514 * omp_get_default_device:: Get the default device for target regions
515 * omp_get_device_num:: Get device that current thread is running on
516 * omp_get_dynamic:: Dynamic teams setting
517 * omp_get_initial_device:: Device number of host device
518 * omp_get_level:: Number of parallel regions
519 * omp_get_max_active_levels:: Current maximum number of active regions
520 * omp_get_max_task_priority:: Maximum task priority value that can be set
521 * omp_get_max_teams:: Maximum number of teams for teams region
522 * omp_get_max_threads:: Maximum number of threads of parallel region
523 * omp_get_nested:: Nested parallel regions
524 * omp_get_num_devices:: Number of target devices
525 * omp_get_num_procs:: Number of processors online
526 * omp_get_num_teams:: Number of teams
527 * omp_get_num_threads:: Size of the active team
528 * omp_get_proc_bind:: Whether threads may be moved between CPUs
529 * omp_get_schedule:: Obtain the runtime scheduling method
530 * omp_get_supported_active_levels:: Maximum number of active regions supported
531 * omp_get_team_num:: Get team number
532 * omp_get_team_size:: Number of threads in a team
533 * omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
534 * omp_get_thread_limit:: Maximum number of threads
535 * omp_get_thread_num:: Current thread ID
536 * omp_in_parallel:: Whether a parallel region is active
537 * omp_in_final:: Whether in final or included task region
538 * omp_is_initial_device:: Whether executing on the host device
539 * omp_set_default_device:: Set the default device for target regions
540 * omp_set_dynamic:: Enable/disable dynamic teams
541 * omp_set_max_active_levels:: Limits the number of active parallel regions
542 * omp_set_nested:: Enable/disable nested parallel regions
543 * omp_set_num_teams:: Set upper teams limit for teams region
544 * omp_set_num_threads:: Set upper team size limit
545 * omp_set_schedule:: Set the runtime scheduling method
546 * omp_set_teams_thread_limit:: Set upper thread limit for teams construct
548 Initialize, set, test, unset and destroy simple and nested locks.
550 * omp_init_lock:: Initialize simple lock
551 * omp_set_lock:: Wait for and set simple lock
552 * omp_test_lock:: Test and set simple lock if available
553 * omp_unset_lock:: Unset simple lock
554 * omp_destroy_lock:: Destroy simple lock
555 * omp_init_nest_lock:: Initialize nested lock
556 * omp_set_nest_lock:: Wait for and set simple lock
557 * omp_test_nest_lock:: Test and set nested lock if available
558 * omp_unset_nest_lock:: Unset nested lock
559 * omp_destroy_nest_lock:: Destroy nested lock
561 Portable, thread-based, wall clock timer.
563 * omp_get_wtick:: Get timer precision.
564 * omp_get_wtime:: Elapsed wall clock time.
566 Support for event objects.
568 * omp_fulfill_event:: Fulfill and destroy an OpenMP event.
573 @node omp_get_active_level
574 @section @code{omp_get_active_level} -- Number of parallel regions
576 @item @emph{Description}:
577 This function returns the nesting level for the active parallel blocks,
578 which enclose the calling call.
581 @multitable @columnfractions .20 .80
582 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
585 @item @emph{Fortran}:
586 @multitable @columnfractions .20 .80
587 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
590 @item @emph{See also}:
591 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
593 @item @emph{Reference}:
594 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
599 @node omp_get_ancestor_thread_num
600 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
602 @item @emph{Description}:
603 This function returns the thread identification number for the given
604 nesting level of the current thread. For values of @var{level} outside
605 zero to @code{omp_get_level} -1 is returned; if @var{level} is
606 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
609 @multitable @columnfractions .20 .80
610 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
613 @item @emph{Fortran}:
614 @multitable @columnfractions .20 .80
615 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
616 @item @tab @code{integer level}
619 @item @emph{See also}:
620 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
622 @item @emph{Reference}:
623 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
628 @node omp_get_cancellation
629 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
631 @item @emph{Description}:
632 This function returns @code{true} if cancellation is activated, @code{false}
633 otherwise. Here, @code{true} and @code{false} represent their language-specific
634 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
638 @multitable @columnfractions .20 .80
639 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
642 @item @emph{Fortran}:
643 @multitable @columnfractions .20 .80
644 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
647 @item @emph{See also}:
648 @ref{OMP_CANCELLATION}
650 @item @emph{Reference}:
651 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
656 @node omp_get_default_device
657 @section @code{omp_get_default_device} -- Get the default device for target regions
659 @item @emph{Description}:
660 Get the default device for target regions without device clause.
663 @multitable @columnfractions .20 .80
664 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
667 @item @emph{Fortran}:
668 @multitable @columnfractions .20 .80
669 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
672 @item @emph{See also}:
673 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
675 @item @emph{Reference}:
676 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
681 @node omp_get_device_num
682 @section @code{omp_get_device_num} -- Return device number of current device
684 @item @emph{Description}:
685 This function returns a device number that represents the device that the
686 current thread is executing on. For OpenMP 5.0, this must be equal to the
687 value returned by the @code{omp_get_initial_device} function when called
691 @multitable @columnfractions .20 .80
692 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
695 @item @emph{Fortran}:
696 @multitable @columnfractions .20 .80
697 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
700 @item @emph{See also}:
701 @ref{omp_get_initial_device}
703 @item @emph{Reference}:
704 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
709 @node omp_get_dynamic
710 @section @code{omp_get_dynamic} -- Dynamic teams setting
712 @item @emph{Description}:
713 This function returns @code{true} if enabled, @code{false} otherwise.
714 Here, @code{true} and @code{false} represent their language-specific
717 The dynamic team setting may be initialized at startup by the
718 @env{OMP_DYNAMIC} environment variable or at runtime using
719 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
723 @multitable @columnfractions .20 .80
724 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
727 @item @emph{Fortran}:
728 @multitable @columnfractions .20 .80
729 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
732 @item @emph{See also}:
733 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
735 @item @emph{Reference}:
736 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
741 @node omp_get_initial_device
742 @section @code{omp_get_initial_device} -- Return device number of initial device
744 @item @emph{Description}:
745 This function returns a device number that represents the host device.
746 For OpenMP 5.1, this must be equal to the value returned by the
747 @code{omp_get_num_devices} function.
750 @multitable @columnfractions .20 .80
751 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
754 @item @emph{Fortran}:
755 @multitable @columnfractions .20 .80
756 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
759 @item @emph{See also}:
760 @ref{omp_get_num_devices}
762 @item @emph{Reference}:
763 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
769 @section @code{omp_get_level} -- Obtain the current nesting level
771 @item @emph{Description}:
772 This function returns the nesting level for the parallel blocks,
773 which enclose the calling call.
776 @multitable @columnfractions .20 .80
777 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
780 @item @emph{Fortran}:
781 @multitable @columnfractions .20 .80
782 @item @emph{Interface}: @tab @code{integer function omp_level()}
785 @item @emph{See also}:
786 @ref{omp_get_active_level}
788 @item @emph{Reference}:
789 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
794 @node omp_get_max_active_levels
795 @section @code{omp_get_max_active_levels} -- Current maximum number of active regions
797 @item @emph{Description}:
798 This function obtains the maximum allowed number of nested, active parallel regions.
801 @multitable @columnfractions .20 .80
802 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
805 @item @emph{Fortran}:
806 @multitable @columnfractions .20 .80
807 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
810 @item @emph{See also}:
811 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
813 @item @emph{Reference}:
814 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
818 @node omp_get_max_task_priority
819 @section @code{omp_get_max_task_priority} -- Maximum priority value
820 that can be set for tasks.
822 @item @emph{Description}:
823 This function obtains the maximum allowed priority number for tasks.
826 @multitable @columnfractions .20 .80
827 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
830 @item @emph{Fortran}:
831 @multitable @columnfractions .20 .80
832 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
835 @item @emph{Reference}:
836 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
840 @node omp_get_max_teams
841 @section @code{omp_get_max_teams} -- Maximum number of teams of teams region
843 @item @emph{Description}:
844 Return the maximum number of teams used for the teams region
845 that does not use the clause @code{num_teams}.
848 @multitable @columnfractions .20 .80
849 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
852 @item @emph{Fortran}:
853 @multitable @columnfractions .20 .80
854 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
857 @item @emph{See also}:
858 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
860 @item @emph{Reference}:
861 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
866 @node omp_get_max_threads
867 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
869 @item @emph{Description}:
870 Return the maximum number of threads used for the current parallel region
871 that does not use the clause @code{num_threads}.
874 @multitable @columnfractions .20 .80
875 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
878 @item @emph{Fortran}:
879 @multitable @columnfractions .20 .80
880 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
883 @item @emph{See also}:
884 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
886 @item @emph{Reference}:
887 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
893 @section @code{omp_get_nested} -- Nested parallel regions
895 @item @emph{Description}:
896 This function returns @code{true} if nested parallel regions are
897 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
898 represent their language-specific counterparts.
900 The state of nested parallel regions at startup depends on several
901 environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
902 and is set to greater than one, then nested parallel regions will be
903 enabled. If not defined, then the value of the @env{OMP_NESTED}
904 environment variable will be followed if defined. If neither are
905 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
906 are defined with a list of more than one value, then nested parallel
907 regions are enabled. If none of these are defined, then nested parallel
908 regions are disabled by default.
910 Nested parallel regions can be enabled or disabled at runtime using
911 @code{omp_set_nested}, or by setting the maximum number of nested
912 regions with @code{omp_set_max_active_levels} to one to disable, or
916 @multitable @columnfractions .20 .80
917 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
920 @item @emph{Fortran}:
921 @multitable @columnfractions .20 .80
922 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
925 @item @emph{See also}:
926 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
927 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
929 @item @emph{Reference}:
930 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
935 @node omp_get_num_devices
936 @section @code{omp_get_num_devices} -- Number of target devices
938 @item @emph{Description}:
939 Returns the number of target devices.
942 @multitable @columnfractions .20 .80
943 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
946 @item @emph{Fortran}:
947 @multitable @columnfractions .20 .80
948 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
951 @item @emph{Reference}:
952 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
957 @node omp_get_num_procs
958 @section @code{omp_get_num_procs} -- Number of processors online
960 @item @emph{Description}:
961 Returns the number of processors online on that device.
964 @multitable @columnfractions .20 .80
965 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
968 @item @emph{Fortran}:
969 @multitable @columnfractions .20 .80
970 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
973 @item @emph{Reference}:
974 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
979 @node omp_get_num_teams
980 @section @code{omp_get_num_teams} -- Number of teams
982 @item @emph{Description}:
983 Returns the number of teams in the current team region.
986 @multitable @columnfractions .20 .80
987 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
990 @item @emph{Fortran}:
991 @multitable @columnfractions .20 .80
992 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
995 @item @emph{Reference}:
996 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1001 @node omp_get_num_threads
1002 @section @code{omp_get_num_threads} -- Size of the active team
1004 @item @emph{Description}:
1005 Returns the number of threads in the current team. In a sequential section of
1006 the program @code{omp_get_num_threads} returns 1.
1008 The default team size may be initialized at startup by the
1009 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
1010 of the current team may be set either by the @code{NUM_THREADS}
1011 clause or by @code{omp_set_num_threads}. If none of the above were
1012 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
1013 one thread per CPU online is used.
1016 @multitable @columnfractions .20 .80
1017 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
1020 @item @emph{Fortran}:
1021 @multitable @columnfractions .20 .80
1022 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
1025 @item @emph{See also}:
1026 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
1028 @item @emph{Reference}:
1029 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
1034 @node omp_get_proc_bind
1035 @section @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1037 @item @emph{Description}:
1038 This functions returns the currently active thread affinity policy, which is
1039 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1040 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1041 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1042 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1045 @multitable @columnfractions .20 .80
1046 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1049 @item @emph{Fortran}:
1050 @multitable @columnfractions .20 .80
1051 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1054 @item @emph{See also}:
1055 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1057 @item @emph{Reference}:
1058 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1063 @node omp_get_schedule
1064 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
1066 @item @emph{Description}:
1067 Obtain the runtime scheduling method. The @var{kind} argument will be
1068 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
1069 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
1070 @var{chunk_size}, is set to the chunk size.
1073 @multitable @columnfractions .20 .80
1074 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1077 @item @emph{Fortran}:
1078 @multitable @columnfractions .20 .80
1079 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1080 @item @tab @code{integer(kind=omp_sched_kind) kind}
1081 @item @tab @code{integer chunk_size}
1084 @item @emph{See also}:
1085 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1087 @item @emph{Reference}:
1088 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1092 @node omp_get_supported_active_levels
1093 @section @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1095 @item @emph{Description}:
1096 This function returns the maximum number of nested, active parallel regions
1097 supported by this implementation.
1100 @multitable @columnfractions .20 .80
1101 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1104 @item @emph{Fortran}:
1105 @multitable @columnfractions .20 .80
1106 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1109 @item @emph{See also}:
1110 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1112 @item @emph{Reference}:
1113 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1118 @node omp_get_team_num
1119 @section @code{omp_get_team_num} -- Get team number
1121 @item @emph{Description}:
1122 Returns the team number of the calling thread.
1125 @multitable @columnfractions .20 .80
1126 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1129 @item @emph{Fortran}:
1130 @multitable @columnfractions .20 .80
1131 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1134 @item @emph{Reference}:
1135 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1140 @node omp_get_team_size
1141 @section @code{omp_get_team_size} -- Number of threads in a team
1143 @item @emph{Description}:
1144 This function returns the number of threads in a thread team to which
1145 either the current thread or its ancestor belongs. For values of @var{level}
1146 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1147 1 is returned, and for @code{omp_get_level}, the result is identical
1148 to @code{omp_get_num_threads}.
1151 @multitable @columnfractions .20 .80
1152 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1155 @item @emph{Fortran}:
1156 @multitable @columnfractions .20 .80
1157 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1158 @item @tab @code{integer level}
1161 @item @emph{See also}:
1162 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1164 @item @emph{Reference}:
1165 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1170 @node omp_get_teams_thread_limit
1171 @section @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1173 @item @emph{Description}:
1174 Return the maximum number of threads that will be able to participate in
1175 each team created by a teams construct.
1178 @multitable @columnfractions .20 .80
1179 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1182 @item @emph{Fortran}:
1183 @multitable @columnfractions .20 .80
1184 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1187 @item @emph{See also}:
1188 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1190 @item @emph{Reference}:
1191 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1196 @node omp_get_thread_limit
1197 @section @code{omp_get_thread_limit} -- Maximum number of threads
1199 @item @emph{Description}:
1200 Return the maximum number of threads of the program.
1203 @multitable @columnfractions .20 .80
1204 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1207 @item @emph{Fortran}:
1208 @multitable @columnfractions .20 .80
1209 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1212 @item @emph{See also}:
1213 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1215 @item @emph{Reference}:
1216 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1221 @node omp_get_thread_num
1222 @section @code{omp_get_thread_num} -- Current thread ID
1224 @item @emph{Description}:
1225 Returns a unique thread identification number within the current team.
1226 In a sequential parts of the program, @code{omp_get_thread_num}
1227 always returns 0. In parallel regions the return value varies
1228 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
1229 value of the primary thread of a team is always 0.
1232 @multitable @columnfractions .20 .80
1233 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
1236 @item @emph{Fortran}:
1237 @multitable @columnfractions .20 .80
1238 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
1241 @item @emph{See also}:
1242 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
1244 @item @emph{Reference}:
1245 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
1250 @node omp_in_parallel
1251 @section @code{omp_in_parallel} -- Whether a parallel region is active
1253 @item @emph{Description}:
1254 This function returns @code{true} if currently running in parallel,
1255 @code{false} otherwise. Here, @code{true} and @code{false} represent
1256 their language-specific counterparts.
1259 @multitable @columnfractions .20 .80
1260 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
1263 @item @emph{Fortran}:
1264 @multitable @columnfractions .20 .80
1265 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
1268 @item @emph{Reference}:
1269 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
1274 @section @code{omp_in_final} -- Whether in final or included task region
1276 @item @emph{Description}:
1277 This function returns @code{true} if currently running in a final
1278 or included task region, @code{false} otherwise. Here, @code{true}
1279 and @code{false} represent their language-specific counterparts.
1282 @multitable @columnfractions .20 .80
1283 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1286 @item @emph{Fortran}:
1287 @multitable @columnfractions .20 .80
1288 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1291 @item @emph{Reference}:
1292 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1297 @node omp_is_initial_device
1298 @section @code{omp_is_initial_device} -- Whether executing on the host device
1300 @item @emph{Description}:
1301 This function returns @code{true} if currently running on the host device,
1302 @code{false} otherwise. Here, @code{true} and @code{false} represent
1303 their language-specific counterparts.
1306 @multitable @columnfractions .20 .80
1307 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1310 @item @emph{Fortran}:
1311 @multitable @columnfractions .20 .80
1312 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1315 @item @emph{Reference}:
1316 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1321 @node omp_set_default_device
1322 @section @code{omp_set_default_device} -- Set the default device for target regions
1324 @item @emph{Description}:
1325 Set the default device for target regions without device clause. The argument
1326 shall be a nonnegative device number.
1329 @multitable @columnfractions .20 .80
1330 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1333 @item @emph{Fortran}:
1334 @multitable @columnfractions .20 .80
1335 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1336 @item @tab @code{integer device_num}
1339 @item @emph{See also}:
1340 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1342 @item @emph{Reference}:
1343 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1348 @node omp_set_dynamic
1349 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
1351 @item @emph{Description}:
1352 Enable or disable the dynamic adjustment of the number of threads
1353 within a team. The function takes the language-specific equivalent
1354 of @code{true} and @code{false}, where @code{true} enables dynamic
1355 adjustment of team sizes and @code{false} disables it.
1358 @multitable @columnfractions .20 .80
1359 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
1362 @item @emph{Fortran}:
1363 @multitable @columnfractions .20 .80
1364 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
1365 @item @tab @code{logical, intent(in) :: dynamic_threads}
1368 @item @emph{See also}:
1369 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
1371 @item @emph{Reference}:
1372 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
1377 @node omp_set_max_active_levels
1378 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1380 @item @emph{Description}:
1381 This function limits the maximum allowed number of nested, active
1382 parallel regions. @var{max_levels} must be less or equal to
1383 the value returned by @code{omp_get_supported_active_levels}.
1386 @multitable @columnfractions .20 .80
1387 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1390 @item @emph{Fortran}:
1391 @multitable @columnfractions .20 .80
1392 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1393 @item @tab @code{integer max_levels}
1396 @item @emph{See also}:
1397 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1398 @ref{omp_get_supported_active_levels}
1400 @item @emph{Reference}:
1401 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1406 @node omp_set_nested
1407 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
1409 @item @emph{Description}:
1410 Enable or disable nested parallel regions, i.e., whether team members
1411 are allowed to create new teams. The function takes the language-specific
1412 equivalent of @code{true} and @code{false}, where @code{true} enables
1413 dynamic adjustment of team sizes and @code{false} disables it.
1415 Enabling nested parallel regions will also set the maximum number of
1416 active nested regions to the maximum supported. Disabling nested parallel
1417 regions will set the maximum number of active nested regions to one.
1420 @multitable @columnfractions .20 .80
1421 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
1424 @item @emph{Fortran}:
1425 @multitable @columnfractions .20 .80
1426 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
1427 @item @tab @code{logical, intent(in) :: nested}
1430 @item @emph{See also}:
1431 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
1432 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1434 @item @emph{Reference}:
1435 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
1440 @node omp_set_num_teams
1441 @section @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1443 @item @emph{Description}:
1444 Specifies the upper bound for number of teams created by the teams construct
1445 which does not specify a @code{num_teams} clause. The
1446 argument of @code{omp_set_num_teams} shall be a positive integer.
1449 @multitable @columnfractions .20 .80
1450 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1453 @item @emph{Fortran}:
1454 @multitable @columnfractions .20 .80
1455 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1456 @item @tab @code{integer, intent(in) :: num_teams}
1459 @item @emph{See also}:
1460 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1462 @item @emph{Reference}:
1463 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1468 @node omp_set_num_threads
1469 @section @code{omp_set_num_threads} -- Set upper team size limit
1471 @item @emph{Description}:
1472 Specifies the number of threads used by default in subsequent parallel
1473 sections, if those do not specify a @code{num_threads} clause. The
1474 argument of @code{omp_set_num_threads} shall be a positive integer.
1477 @multitable @columnfractions .20 .80
1478 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
1481 @item @emph{Fortran}:
1482 @multitable @columnfractions .20 .80
1483 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
1484 @item @tab @code{integer, intent(in) :: num_threads}
1487 @item @emph{See also}:
1488 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
1490 @item @emph{Reference}:
1491 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
1496 @node omp_set_schedule
1497 @section @code{omp_set_schedule} -- Set the runtime scheduling method
1499 @item @emph{Description}:
1500 Sets the runtime scheduling method. The @var{kind} argument can have the
1501 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1502 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1503 @code{omp_sched_auto}, the chunk size is set to the value of
1504 @var{chunk_size} if positive, or to the default value if zero or negative.
1505 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1508 @multitable @columnfractions .20 .80
1509 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1512 @item @emph{Fortran}:
1513 @multitable @columnfractions .20 .80
1514 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1515 @item @tab @code{integer(kind=omp_sched_kind) kind}
1516 @item @tab @code{integer chunk_size}
1519 @item @emph{See also}:
1520 @ref{omp_get_schedule}
1523 @item @emph{Reference}:
1524 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1529 @node omp_set_teams_thread_limit
1530 @section @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1532 @item @emph{Description}:
1533 Specifies the upper bound for number of threads that will be available
1534 for each team created by the teams construct which does not specify a
1535 @code{thread_limit} clause. The argument of
1536 @code{omp_set_teams_thread_limit} shall be a positive integer.
1539 @multitable @columnfractions .20 .80
1540 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1543 @item @emph{Fortran}:
1544 @multitable @columnfractions .20 .80
1545 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1546 @item @tab @code{integer, intent(in) :: thread_limit}
1549 @item @emph{See also}:
1550 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1552 @item @emph{Reference}:
1553 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1559 @section @code{omp_init_lock} -- Initialize simple lock
1561 @item @emph{Description}:
1562 Initialize a simple lock. After initialization, the lock is in
1566 @multitable @columnfractions .20 .80
1567 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1570 @item @emph{Fortran}:
1571 @multitable @columnfractions .20 .80
1572 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1573 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1576 @item @emph{See also}:
1577 @ref{omp_destroy_lock}
1579 @item @emph{Reference}:
1580 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1586 @section @code{omp_set_lock} -- Wait for and set simple lock
1588 @item @emph{Description}:
1589 Before setting a simple lock, the lock variable must be initialized by
1590 @code{omp_init_lock}. The calling thread is blocked until the lock
1591 is available. If the lock is already held by the current thread,
1595 @multitable @columnfractions .20 .80
1596 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1599 @item @emph{Fortran}:
1600 @multitable @columnfractions .20 .80
1601 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1602 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1605 @item @emph{See also}:
1606 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1608 @item @emph{Reference}:
1609 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1615 @section @code{omp_test_lock} -- Test and set simple lock if available
1617 @item @emph{Description}:
1618 Before setting a simple lock, the lock variable must be initialized by
1619 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1620 does not block if the lock is not available. This function returns
1621 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1622 @code{false} represent their language-specific counterparts.
1625 @multitable @columnfractions .20 .80
1626 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1629 @item @emph{Fortran}:
1630 @multitable @columnfractions .20 .80
1631 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1632 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1635 @item @emph{See also}:
1636 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1638 @item @emph{Reference}:
1639 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1644 @node omp_unset_lock
1645 @section @code{omp_unset_lock} -- Unset simple lock
1647 @item @emph{Description}:
1648 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1649 or @code{omp_test_lock} before. In addition, the lock must be held by the
1650 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1651 or more threads attempted to set the lock before, one of them is chosen to,
1652 again, set the lock to itself.
1655 @multitable @columnfractions .20 .80
1656 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1659 @item @emph{Fortran}:
1660 @multitable @columnfractions .20 .80
1661 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1662 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1665 @item @emph{See also}:
1666 @ref{omp_set_lock}, @ref{omp_test_lock}
1668 @item @emph{Reference}:
1669 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1674 @node omp_destroy_lock
1675 @section @code{omp_destroy_lock} -- Destroy simple lock
1677 @item @emph{Description}:
1678 Destroy a simple lock. In order to be destroyed, a simple lock must be
1679 in the unlocked state.
1682 @multitable @columnfractions .20 .80
1683 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1686 @item @emph{Fortran}:
1687 @multitable @columnfractions .20 .80
1688 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1689 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1692 @item @emph{See also}:
1695 @item @emph{Reference}:
1696 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1701 @node omp_init_nest_lock
1702 @section @code{omp_init_nest_lock} -- Initialize nested lock
1704 @item @emph{Description}:
1705 Initialize a nested lock. After initialization, the lock is in
1706 an unlocked state and the nesting count is set to zero.
1709 @multitable @columnfractions .20 .80
1710 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1713 @item @emph{Fortran}:
1714 @multitable @columnfractions .20 .80
1715 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1716 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1719 @item @emph{See also}:
1720 @ref{omp_destroy_nest_lock}
1722 @item @emph{Reference}:
1723 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1727 @node omp_set_nest_lock
1728 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1730 @item @emph{Description}:
1731 Before setting a nested lock, the lock variable must be initialized by
1732 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1733 is available. If the lock is already held by the current thread, the
1734 nesting count for the lock is incremented.
1737 @multitable @columnfractions .20 .80
1738 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1741 @item @emph{Fortran}:
1742 @multitable @columnfractions .20 .80
1743 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1744 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1747 @item @emph{See also}:
1748 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1750 @item @emph{Reference}:
1751 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1756 @node omp_test_nest_lock
1757 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1759 @item @emph{Description}:
1760 Before setting a nested lock, the lock variable must be initialized by
1761 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1762 @code{omp_test_nest_lock} does not block if the lock is not available.
1763 If the lock is already held by the current thread, the new nesting count
1764 is returned. Otherwise, the return value equals zero.
1767 @multitable @columnfractions .20 .80
1768 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1771 @item @emph{Fortran}:
1772 @multitable @columnfractions .20 .80
1773 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1774 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1778 @item @emph{See also}:
1779 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1781 @item @emph{Reference}:
1782 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1787 @node omp_unset_nest_lock
1788 @section @code{omp_unset_nest_lock} -- Unset nested lock
1790 @item @emph{Description}:
1791 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1792 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1793 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1794 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1795 one of them is chosen to, again, set the lock to itself.
1798 @multitable @columnfractions .20 .80
1799 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1802 @item @emph{Fortran}:
1803 @multitable @columnfractions .20 .80
1804 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1805 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1808 @item @emph{See also}:
1809 @ref{omp_set_nest_lock}
1811 @item @emph{Reference}:
1812 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1817 @node omp_destroy_nest_lock
1818 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1820 @item @emph{Description}:
1821 Destroy a nested lock. In order to be destroyed, a nested lock must be
1822 in the unlocked state and its nesting count must equal zero.
1825 @multitable @columnfractions .20 .80
1826 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1829 @item @emph{Fortran}:
1830 @multitable @columnfractions .20 .80
1831 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1832 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1835 @item @emph{See also}:
1838 @item @emph{Reference}:
1839 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1845 @section @code{omp_get_wtick} -- Get timer precision
1847 @item @emph{Description}:
1848 Gets the timer precision, i.e., the number of seconds between two
1849 successive clock ticks.
1852 @multitable @columnfractions .20 .80
1853 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1856 @item @emph{Fortran}:
1857 @multitable @columnfractions .20 .80
1858 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1861 @item @emph{See also}:
1864 @item @emph{Reference}:
1865 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
1871 @section @code{omp_get_wtime} -- Elapsed wall clock time
1873 @item @emph{Description}:
1874 Elapsed wall clock time in seconds. The time is measured per thread, no
1875 guarantee can be made that two distinct threads measure the same time.
1876 Time is measured from some "time in the past", which is an arbitrary time
1877 guaranteed not to change during the execution of the program.
1880 @multitable @columnfractions .20 .80
1881 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1884 @item @emph{Fortran}:
1885 @multitable @columnfractions .20 .80
1886 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1889 @item @emph{See also}:
1892 @item @emph{Reference}:
1893 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
1898 @node omp_fulfill_event
1899 @section @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
1901 @item @emph{Description}:
1902 Fulfill the event associated with the event handle argument. Currently, it
1903 is only used to fulfill events generated by detach clauses on task
1904 constructs - the effect of fulfilling the event is to allow the task to
1907 The result of calling @code{omp_fulfill_event} with an event handle other
1908 than that generated by a detach clause is undefined. Calling it with an
1909 event handle that has already been fulfilled is also undefined.
1912 @multitable @columnfractions .20 .80
1913 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
1916 @item @emph{Fortran}:
1917 @multitable @columnfractions .20 .80
1918 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
1919 @item @tab @code{integer (kind=omp_event_handle_kind) :: event}
1922 @item @emph{Reference}:
1923 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
1928 @c ---------------------------------------------------------------------
1929 @c OpenMP Environment Variables
1930 @c ---------------------------------------------------------------------
1932 @node Environment Variables
1933 @chapter OpenMP Environment Variables
1935 The environment variables which beginning with @env{OMP_} are defined by
1936 section 4 of the OpenMP specification in version 4.5, while those
1937 beginning with @env{GOMP_} are GNU extensions.
1940 * OMP_CANCELLATION:: Set whether cancellation is activated
1941 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1942 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1943 * OMP_DYNAMIC:: Dynamic adjustment of threads
1944 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1945 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
1946 * OMP_NESTED:: Nested parallel regions
1947 * OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
1948 * OMP_NUM_THREADS:: Specifies the number of threads to use
1949 * OMP_PROC_BIND:: Whether threads may be moved between CPUs
1950 * OMP_PLACES:: Specifies on which CPUs the threads should be placed
1951 * OMP_STACKSIZE:: Set default thread stack size
1952 * OMP_SCHEDULE:: How threads are scheduled
1953 * OMP_TARGET_OFFLOAD:: Controls offloading behaviour
1954 * OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
1955 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1956 * OMP_WAIT_POLICY:: How waiting threads are handled
1957 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1958 * GOMP_DEBUG:: Enable debugging output
1959 * GOMP_STACKSIZE:: Set default thread stack size
1960 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1961 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1965 @node OMP_CANCELLATION
1966 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1967 @cindex Environment Variable
1969 @item @emph{Description}:
1970 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1971 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1973 @item @emph{See also}:
1974 @ref{omp_get_cancellation}
1976 @item @emph{Reference}:
1977 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
1982 @node OMP_DISPLAY_ENV
1983 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1984 @cindex Environment Variable
1986 @item @emph{Description}:
1987 If set to @code{TRUE}, the OpenMP version number and the values
1988 associated with the OpenMP environment variables are printed to @code{stderr}.
1989 If set to @code{VERBOSE}, it additionally shows the value of the environment
1990 variables which are GNU extensions. If undefined or set to @code{FALSE},
1991 this information will not be shown.
1994 @item @emph{Reference}:
1995 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
2000 @node OMP_DEFAULT_DEVICE
2001 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
2002 @cindex Environment Variable
2004 @item @emph{Description}:
2005 Set to choose the device which is used in a @code{target} region, unless the
2006 value is overridden by @code{omp_set_default_device} or by a @code{device}
2007 clause. The value shall be the nonnegative device number. If no device with
2008 the given device number exists, the code is executed on the host. If unset,
2009 device number 0 will be used.
2012 @item @emph{See also}:
2013 @ref{omp_get_default_device}, @ref{omp_set_default_device},
2015 @item @emph{Reference}:
2016 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
2022 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
2023 @cindex Environment Variable
2025 @item @emph{Description}:
2026 Enable or disable the dynamic adjustment of the number of threads
2027 within a team. The value of this environment variable shall be
2028 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
2029 disabled by default.
2031 @item @emph{See also}:
2032 @ref{omp_set_dynamic}
2034 @item @emph{Reference}:
2035 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
2040 @node OMP_MAX_ACTIVE_LEVELS
2041 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
2042 @cindex Environment Variable
2044 @item @emph{Description}:
2045 Specifies the initial value for the maximum number of nested parallel
2046 regions. The value of this variable shall be a positive integer.
2047 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
2048 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
2049 a list with more than one item, the maximum number of nested parallel
2050 regions will be initialized to the largest number supported, otherwise
2051 it will be set to one.
2053 @item @emph{See also}:
2054 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}
2056 @item @emph{Reference}:
2057 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
2062 @node OMP_MAX_TASK_PRIORITY
2063 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
2064 number that can be set for a task.
2065 @cindex Environment Variable
2067 @item @emph{Description}:
2068 Specifies the initial value for the maximum priority value that can be
2069 set for a task. The value of this variable shall be a non-negative
2070 integer, and zero is allowed. If undefined, the default priority is
2073 @item @emph{See also}:
2074 @ref{omp_get_max_task_priority}
2076 @item @emph{Reference}:
2077 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
2083 @section @env{OMP_NESTED} -- Nested parallel regions
2084 @cindex Environment Variable
2085 @cindex Implementation specific setting
2087 @item @emph{Description}:
2088 Enable or disable nested parallel regions, i.e., whether team members
2089 are allowed to create new teams. The value of this environment variable
2090 shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
2091 of maximum active nested regions supported will by default be set to the
2092 maximum supported, otherwise it will be set to one. If
2093 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting will override this
2094 setting. If both are undefined, nested parallel regions are enabled if
2095 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
2096 more than one item, otherwise they are disabled by default.
2098 @item @emph{See also}:
2099 @ref{omp_set_max_active_levels}, @ref{omp_set_nested}
2101 @item @emph{Reference}:
2102 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
2108 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
2109 @cindex Environment Variable
2111 @item @emph{Description}:
2112 Specifies the upper bound for number of teams to use in teams regions
2113 without explicit @code{num_teams} clause. The value of this variable shall
2114 be a positive integer. If undefined it defaults to 0 which means
2115 implementation defined upper bound.
2117 @item @emph{See also}:
2118 @ref{omp_set_num_teams}
2120 @item @emph{Reference}:
2121 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
2126 @node OMP_NUM_THREADS
2127 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
2128 @cindex Environment Variable
2129 @cindex Implementation specific setting
2131 @item @emph{Description}:
2132 Specifies the default number of threads to use in parallel regions. The
2133 value of this variable shall be a comma-separated list of positive integers;
2134 the value specifies the number of threads to use for the corresponding nested
2135 level. Specifying more than one item in the list will automatically enable
2136 nesting by default. If undefined one thread per CPU is used.
2138 @item @emph{See also}:
2139 @ref{omp_set_num_threads}, @ref{OMP_NESTED}
2141 @item @emph{Reference}:
2142 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
2148 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
2149 @cindex Environment Variable
2151 @item @emph{Description}:
2152 Specifies whether threads may be moved between processors. If set to
2153 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
2154 they may be moved. Alternatively, a comma separated list with the
2155 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
2156 be used to specify the thread affinity policy for the corresponding nesting
2157 level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
2158 same place partition as the primary thread. With @code{CLOSE} those are
2159 kept close to the primary thread in contiguous place partitions. And
2160 with @code{SPREAD} a sparse distribution
2161 across the place partitions is used. Specifying more than one item in the
2162 list will automatically enable nesting by default.
2164 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
2165 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
2167 @item @emph{See also}:
2168 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY},
2169 @ref{OMP_NESTED}, @ref{OMP_PLACES}
2171 @item @emph{Reference}:
2172 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
2178 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
2179 @cindex Environment Variable
2181 @item @emph{Description}:
2182 The thread placement can be either specified using an abstract name or by an
2183 explicit list of the places. The abstract names @code{threads}, @code{cores},
2184 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
2185 followed by a positive number in parentheses, which denotes the how many places
2186 shall be created. With @code{threads} each place corresponds to a single
2187 hardware thread; @code{cores} to a single core with the corresponding number of
2188 hardware threads; with @code{sockets} the place corresponds to a single
2189 socket; with @code{ll_caches} to a set of cores that shares the last level
2190 cache on the device; and @code{numa_domains} to a set of cores for which their
2191 closest memory on the device is the same memory and at a similar distance from
2192 the cores. The resulting placement can be shown by setting the
2193 @env{OMP_DISPLAY_ENV} environment variable.
2195 Alternatively, the placement can be specified explicitly as comma-separated
2196 list of places. A place is specified by set of nonnegative numbers in curly
2197 braces, denoting the hardware threads. The curly braces can be omitted
2198 when only a single number has been specified. The hardware threads
2199 belonging to a place can either be specified as comma-separated list of
2200 nonnegative thread numbers or using an interval. Multiple places can also be
2201 either specified by a comma-separated list of places or by an interval. To
2202 specify an interval, a colon followed by the count is placed after
2203 the hardware thread number or the place. Optionally, the length can be
2204 followed by a colon and the stride number -- otherwise a unit stride is
2205 assumed. Placing an exclamation mark (@code{!}) directly before a curly
2206 brace or numbers inside the curly braces (excluding intervals) will
2207 exclude those hardware threads.
2209 For instance, the following specifies the same places list:
2210 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
2211 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
2213 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
2214 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
2215 between CPUs following no placement policy.
2217 @item @emph{See also}:
2218 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
2219 @ref{OMP_DISPLAY_ENV}
2221 @item @emph{Reference}:
2222 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
2228 @section @env{OMP_STACKSIZE} -- Set default thread stack size
2229 @cindex Environment Variable
2231 @item @emph{Description}:
2232 Set the default thread stack size in kilobytes, unless the number
2233 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
2234 case the size is, respectively, in bytes, kilobytes, megabytes
2235 or gigabytes. This is different from @code{pthread_attr_setstacksize}
2236 which gets the number of bytes as an argument. If the stack size cannot
2237 be set due to system constraints, an error is reported and the initial
2238 stack size is left unchanged. If undefined, the stack size is system
2241 @item @emph{Reference}:
2242 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
2248 @section @env{OMP_SCHEDULE} -- How threads are scheduled
2249 @cindex Environment Variable
2250 @cindex Implementation specific setting
2252 @item @emph{Description}:
2253 Allows to specify @code{schedule type} and @code{chunk size}.
2254 The value of the variable shall have the form: @code{type[,chunk]} where
2255 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
2256 The optional @code{chunk} size shall be a positive integer. If undefined,
2257 dynamic scheduling and a chunk size of 1 is used.
2259 @item @emph{See also}:
2260 @ref{omp_set_schedule}
2262 @item @emph{Reference}:
2263 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
2268 @node OMP_TARGET_OFFLOAD
2269 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behaviour
2270 @cindex Environment Variable
2271 @cindex Implementation specific setting
2273 @item @emph{Description}:
2274 Specifies the behaviour with regard to offloading code to a device. This
2275 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
2278 If set to @code{MANDATORY}, the program will terminate with an error if
2279 the offload device is not present or is not supported. If set to
2280 @code{DISABLED}, then offloading is disabled and all code will run on the
2281 host. If set to @code{DEFAULT}, the program will try offloading to the
2282 device first, then fall back to running code on the host if it cannot.
2284 If undefined, then the program will behave as if @code{DEFAULT} was set.
2286 @item @emph{Reference}:
2287 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.17
2292 @node OMP_TEAMS_THREAD_LIMIT
2293 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
2294 @cindex Environment Variable
2296 @item @emph{Description}:
2297 Specifies an upper bound for the number of threads to use by each contention
2298 group created by a teams construct without explicit @code{thread_limit}
2299 clause. The value of this variable shall be a positive integer. If undefined,
2300 the value of 0 is used which stands for an implementation defined upper
2303 @item @emph{See also}:
2304 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
2306 @item @emph{Reference}:
2307 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
2312 @node OMP_THREAD_LIMIT
2313 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
2314 @cindex Environment Variable
2316 @item @emph{Description}:
2317 Specifies the number of threads to use for the whole program. The
2318 value of this variable shall be a positive integer. If undefined,
2319 the number of threads is not limited.
2321 @item @emph{See also}:
2322 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
2324 @item @emph{Reference}:
2325 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
2330 @node OMP_WAIT_POLICY
2331 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
2332 @cindex Environment Variable
2334 @item @emph{Description}:
2335 Specifies whether waiting threads should be active or passive. If
2336 the value is @code{PASSIVE}, waiting threads should not consume CPU
2337 power while waiting; while the value is @code{ACTIVE} specifies that
2338 they should. If undefined, threads wait actively for a short time
2339 before waiting passively.
2341 @item @emph{See also}:
2342 @ref{GOMP_SPINCOUNT}
2344 @item @emph{Reference}:
2345 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
2350 @node GOMP_CPU_AFFINITY
2351 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
2352 @cindex Environment Variable
2354 @item @emph{Description}:
2355 Binds threads to specific CPUs. The variable should contain a space-separated
2356 or comma-separated list of CPUs. This list may contain different kinds of
2357 entries: either single CPU numbers in any order, a range of CPUs (M-N)
2358 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
2359 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
2360 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
2361 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
2362 and 14 respectively and then start assigning back from the beginning of
2363 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
2365 There is no libgomp library routine to determine whether a CPU affinity
2366 specification is in effect. As a workaround, language-specific library
2367 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
2368 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
2369 environment variable. A defined CPU affinity on startup cannot be changed
2370 or disabled during the runtime of the application.
2372 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
2373 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
2374 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
2375 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
2377 @item @emph{See also}:
2378 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
2384 @section @env{GOMP_DEBUG} -- Enable debugging output
2385 @cindex Environment Variable
2387 @item @emph{Description}:
2388 Enable debugging output. The variable should be set to @code{0}
2389 (disabled, also the default if not set), or @code{1} (enabled).
2391 If enabled, some debugging output will be printed during execution.
2392 This is currently not specified in more detail, and subject to change.
2397 @node GOMP_STACKSIZE
2398 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
2399 @cindex Environment Variable
2400 @cindex Implementation specific setting
2402 @item @emph{Description}:
2403 Set the default thread stack size in kilobytes. This is different from
2404 @code{pthread_attr_setstacksize} which gets the number of bytes as an
2405 argument. If the stack size cannot be set due to system constraints, an
2406 error is reported and the initial stack size is left unchanged. If undefined,
2407 the stack size is system dependent.
2409 @item @emph{See also}:
2412 @item @emph{Reference}:
2413 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
2414 GCC Patches Mailinglist},
2415 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
2416 GCC Patches Mailinglist}
2421 @node GOMP_SPINCOUNT
2422 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
2423 @cindex Environment Variable
2424 @cindex Implementation specific setting
2426 @item @emph{Description}:
2427 Determines how long a threads waits actively with consuming CPU power
2428 before waiting passively without consuming CPU power. The value may be
2429 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
2430 integer which gives the number of spins of the busy-wait loop. The
2431 integer may optionally be followed by the following suffixes acting
2432 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
2433 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
2434 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
2435 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
2436 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
2437 If there are more OpenMP threads than available CPUs, 1000 and 100
2438 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
2439 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
2440 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
2442 @item @emph{See also}:
2443 @ref{OMP_WAIT_POLICY}
2448 @node GOMP_RTEMS_THREAD_POOLS
2449 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
2450 @cindex Environment Variable
2451 @cindex Implementation specific setting
2453 @item @emph{Description}:
2454 This environment variable is only used on the RTEMS real-time operating system.
2455 It determines the scheduler instance specific thread pools. The format for
2456 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
2457 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
2458 separated by @code{:} where:
2460 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
2462 @item @code{$<priority>} is an optional priority for the worker threads of a
2463 thread pool according to @code{pthread_setschedparam}. In case a priority
2464 value is omitted, then a worker thread will inherit the priority of the OpenMP
2465 primary thread that created it. The priority of the worker thread is not
2466 changed after creation, even if a new OpenMP primary thread using the worker has
2467 a different priority.
2468 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
2469 RTEMS application configuration.
2471 In case no thread pool configuration is specified for a scheduler instance,
2472 then each OpenMP primary thread of this scheduler instance will use its own
2473 dynamically allocated thread pool. To limit the worker thread count of the
2474 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
2475 @item @emph{Example}:
2476 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
2477 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
2478 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
2479 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
2480 one thread pool available. Since no priority is specified for this scheduler
2481 instance, the worker thread inherits the priority of the OpenMP primary thread
2482 that created it. In the scheduler instance @code{WRK1} there are three thread
2483 pools available and their worker threads run at priority four.
2488 @c ---------------------------------------------------------------------
2490 @c ---------------------------------------------------------------------
2492 @node Enabling OpenACC
2493 @chapter Enabling OpenACC
2495 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
2496 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
2497 @code{#pragma acc} in C/C++ and @code{!$acc} directives in free form,
2498 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
2499 @code{!$} conditional compilation sentinels in free form and @code{c$},
2500 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
2501 arranges for automatic linking of the OpenACC runtime library
2502 (@ref{OpenACC Runtime Library Routines}).
2504 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
2506 A complete description of all OpenACC directives accepted may be found in
2507 the @uref{https://www.openacc.org, OpenACC} Application Programming
2508 Interface manual, version 2.6.
2512 @c ---------------------------------------------------------------------
2513 @c OpenACC Runtime Library Routines
2514 @c ---------------------------------------------------------------------
2516 @node OpenACC Runtime Library Routines
2517 @chapter OpenACC Runtime Library Routines
2519 The runtime routines described here are defined by section 3 of the OpenACC
2520 specifications in version 2.6.
2521 They have C linkage, and do not throw exceptions.
2522 Generally, they are available only for the host, with the exception of
2523 @code{acc_on_device}, which is available for both the host and the
2524 acceleration device.
2527 * acc_get_num_devices:: Get number of devices for the given device
2529 * acc_set_device_type:: Set type of device accelerator to use.
2530 * acc_get_device_type:: Get type of device accelerator to be used.
2531 * acc_set_device_num:: Set device number to use.
2532 * acc_get_device_num:: Get device number to be used.
2533 * acc_get_property:: Get device property.
2534 * acc_async_test:: Tests for completion of a specific asynchronous
2536 * acc_async_test_all:: Tests for completion of all asynchronous
2538 * acc_wait:: Wait for completion of a specific asynchronous
2540 * acc_wait_all:: Waits for completion of all asynchronous
2542 * acc_wait_all_async:: Wait for completion of all asynchronous
2544 * acc_wait_async:: Wait for completion of asynchronous operations.
2545 * acc_init:: Initialize runtime for a specific device type.
2546 * acc_shutdown:: Shuts down the runtime for a specific device
2548 * acc_on_device:: Whether executing on a particular device
2549 * acc_malloc:: Allocate device memory.
2550 * acc_free:: Free device memory.
2551 * acc_copyin:: Allocate device memory and copy host memory to
2553 * acc_present_or_copyin:: If the data is not present on the device,
2554 allocate device memory and copy from host
2556 * acc_create:: Allocate device memory and map it to host
2558 * acc_present_or_create:: If the data is not present on the device,
2559 allocate device memory and map it to host
2561 * acc_copyout:: Copy device memory to host memory.
2562 * acc_delete:: Free device memory.
2563 * acc_update_device:: Update device memory from mapped host memory.
2564 * acc_update_self:: Update host memory from mapped device memory.
2565 * acc_map_data:: Map previously allocated device memory to host
2567 * acc_unmap_data:: Unmap device memory from host memory.
2568 * acc_deviceptr:: Get device pointer associated with specific
2570 * acc_hostptr:: Get host pointer associated with specific
2572 * acc_is_present:: Indicate whether host variable / array is
2574 * acc_memcpy_to_device:: Copy host memory to device memory.
2575 * acc_memcpy_from_device:: Copy device memory to host memory.
2576 * acc_attach:: Let device pointer point to device-pointer target.
2577 * acc_detach:: Let device pointer point to host-pointer target.
2579 API routines for target platforms.
2581 * acc_get_current_cuda_device:: Get CUDA device handle.
2582 * acc_get_current_cuda_context::Get CUDA context handle.
2583 * acc_get_cuda_stream:: Get CUDA stream handle.
2584 * acc_set_cuda_stream:: Set CUDA stream handle.
2586 API routines for the OpenACC Profiling Interface.
2588 * acc_prof_register:: Register callbacks.
2589 * acc_prof_unregister:: Unregister callbacks.
2590 * acc_prof_lookup:: Obtain inquiry functions.
2591 * acc_register_library:: Library registration.
2596 @node acc_get_num_devices
2597 @section @code{acc_get_num_devices} -- Get number of devices for given device type
2599 @item @emph{Description}
2600 This function returns a value indicating the number of devices available
2601 for the device type specified in @var{devicetype}.
2604 @multitable @columnfractions .20 .80
2605 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
2608 @item @emph{Fortran}:
2609 @multitable @columnfractions .20 .80
2610 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
2611 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2614 @item @emph{Reference}:
2615 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2621 @node acc_set_device_type
2622 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
2624 @item @emph{Description}
2625 This function indicates to the runtime library which device type, specified
2626 in @var{devicetype}, to use when executing a parallel or kernels region.
2629 @multitable @columnfractions .20 .80
2630 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
2633 @item @emph{Fortran}:
2634 @multitable @columnfractions .20 .80
2635 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
2636 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2639 @item @emph{Reference}:
2640 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2646 @node acc_get_device_type
2647 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
2649 @item @emph{Description}
2650 This function returns what device type will be used when executing a
2651 parallel or kernels region.
2653 This function returns @code{acc_device_none} if
2654 @code{acc_get_device_type} is called from
2655 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
2656 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
2657 Interface}), that is, if the device is currently being initialized.
2660 @multitable @columnfractions .20 .80
2661 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
2664 @item @emph{Fortran}:
2665 @multitable @columnfractions .20 .80
2666 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
2667 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
2670 @item @emph{Reference}:
2671 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2677 @node acc_set_device_num
2678 @section @code{acc_set_device_num} -- Set device number to use.
2680 @item @emph{Description}
2681 This function will indicate to the runtime which device number,
2682 specified by @var{devicenum}, associated with the specified device
2683 type @var{devicetype}.
2686 @multitable @columnfractions .20 .80
2687 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
2690 @item @emph{Fortran}:
2691 @multitable @columnfractions .20 .80
2692 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
2693 @item @tab @code{integer devicenum}
2694 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2697 @item @emph{Reference}:
2698 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2704 @node acc_get_device_num
2705 @section @code{acc_get_device_num} -- Get device number to be used.
2707 @item @emph{Description}
2708 This function returns which device number associated with the specified device
2709 type @var{devicetype}, will be used when executing a parallel or kernels
2713 @multitable @columnfractions .20 .80
2714 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2717 @item @emph{Fortran}:
2718 @multitable @columnfractions .20 .80
2719 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2720 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2721 @item @tab @code{integer acc_get_device_num}
2724 @item @emph{Reference}:
2725 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2731 @node acc_get_property
2732 @section @code{acc_get_property} -- Get device property.
2733 @cindex acc_get_property
2734 @cindex acc_get_property_string
2736 @item @emph{Description}
2737 These routines return the value of the specified @var{property} for the
2738 device being queried according to @var{devicenum} and @var{devicetype}.
2739 Integer-valued and string-valued properties are returned by
2740 @code{acc_get_property} and @code{acc_get_property_string} respectively.
2741 The Fortran @code{acc_get_property_string} subroutine returns the string
2742 retrieved in its fourth argument while the remaining entry points are
2743 functions, which pass the return value as their result.
2745 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
2746 modified the interface introduced in OpenACC 2.6. The kind-value parameter
2747 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
2748 for consistency and the return type of the @code{acc_get_property} function is
2749 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
2750 The parameter @code{acc_device_property} will continue to be provided,
2751 but might be removed in a future version of GCC.
2754 @multitable @columnfractions .20 .80
2755 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2756 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2759 @item @emph{Fortran}:
2760 @multitable @columnfractions .20 .80
2761 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
2762 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
2763 @item @tab @code{use ISO_C_Binding, only: c_size_t}
2764 @item @tab @code{integer devicenum}
2765 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2766 @item @tab @code{integer(kind=acc_device_property_kind) property}
2767 @item @tab @code{integer(kind=c_size_t) acc_get_property}
2768 @item @tab @code{character(*) string}
2771 @item @emph{Reference}:
2772 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2778 @node acc_async_test
2779 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
2781 @item @emph{Description}
2782 This function tests for completion of the asynchronous operation specified
2783 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2784 the specified asynchronous operation has completed. While Fortran will return
2785 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
2786 a zero and Fortran returns a @code{false}.
2789 @multitable @columnfractions .20 .80
2790 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
2793 @item @emph{Fortran}:
2794 @multitable @columnfractions .20 .80
2795 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
2796 @item @tab @code{integer(kind=acc_handle_kind) arg}
2797 @item @tab @code{logical acc_async_test}
2800 @item @emph{Reference}:
2801 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2807 @node acc_async_test_all
2808 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
2810 @item @emph{Description}
2811 This function tests for completion of all asynchronous operations.
2812 In C/C++, a non-zero value will be returned to indicate all asynchronous
2813 operations have completed. While Fortran will return a @code{true}. If
2814 any asynchronous operation has not completed, C/C++ returns a zero and
2815 Fortran returns a @code{false}.
2818 @multitable @columnfractions .20 .80
2819 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
2822 @item @emph{Fortran}:
2823 @multitable @columnfractions .20 .80
2824 @item @emph{Interface}: @tab @code{function acc_async_test()}
2825 @item @tab @code{logical acc_get_device_num}
2828 @item @emph{Reference}:
2829 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2836 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2838 @item @emph{Description}
2839 This function waits for completion of the asynchronous operation
2840 specified in @var{arg}.
2843 @multitable @columnfractions .20 .80
2844 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
2845 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
2848 @item @emph{Fortran}:
2849 @multitable @columnfractions .20 .80
2850 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
2851 @item @tab @code{integer(acc_handle_kind) arg}
2852 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
2853 @item @tab @code{integer(acc_handle_kind) arg}
2856 @item @emph{Reference}:
2857 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2864 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
2866 @item @emph{Description}
2867 This function waits for the completion of all asynchronous operations.
2870 @multitable @columnfractions .20 .80
2871 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
2872 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
2875 @item @emph{Fortran}:
2876 @multitable @columnfractions .20 .80
2877 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
2878 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
2881 @item @emph{Reference}:
2882 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2888 @node acc_wait_all_async
2889 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
2891 @item @emph{Description}
2892 This function enqueues a wait operation on the queue @var{async} for any
2893 and all asynchronous operations that have been previously enqueued on
2897 @multitable @columnfractions .20 .80
2898 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
2901 @item @emph{Fortran}:
2902 @multitable @columnfractions .20 .80
2903 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
2904 @item @tab @code{integer(acc_handle_kind) async}
2907 @item @emph{Reference}:
2908 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2914 @node acc_wait_async
2915 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2917 @item @emph{Description}
2918 This function enqueues a wait operation on queue @var{async} for any and all
2919 asynchronous operations enqueued on queue @var{arg}.
2922 @multitable @columnfractions .20 .80
2923 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
2926 @item @emph{Fortran}:
2927 @multitable @columnfractions .20 .80
2928 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
2929 @item @tab @code{integer(acc_handle_kind) arg, async}
2932 @item @emph{Reference}:
2933 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2940 @section @code{acc_init} -- Initialize runtime for a specific device type.
2942 @item @emph{Description}
2943 This function initializes the runtime for the device type specified in
2947 @multitable @columnfractions .20 .80
2948 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
2951 @item @emph{Fortran}:
2952 @multitable @columnfractions .20 .80
2953 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
2954 @item @tab @code{integer(acc_device_kind) devicetype}
2957 @item @emph{Reference}:
2958 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2965 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
2967 @item @emph{Description}
2968 This function shuts down the runtime for the device type specified in
2972 @multitable @columnfractions .20 .80
2973 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
2976 @item @emph{Fortran}:
2977 @multitable @columnfractions .20 .80
2978 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
2979 @item @tab @code{integer(acc_device_kind) devicetype}
2982 @item @emph{Reference}:
2983 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2990 @section @code{acc_on_device} -- Whether executing on a particular device
2992 @item @emph{Description}:
2993 This function returns whether the program is executing on a particular
2994 device specified in @var{devicetype}. In C/C++ a non-zero value is
2995 returned to indicate the device is executing on the specified device type.
2996 In Fortran, @code{true} will be returned. If the program is not executing
2997 on the specified device type C/C++ will return a zero, while Fortran will
2998 return @code{false}.
3001 @multitable @columnfractions .20 .80
3002 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
3005 @item @emph{Fortran}:
3006 @multitable @columnfractions .20 .80
3007 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
3008 @item @tab @code{integer(acc_device_kind) devicetype}
3009 @item @tab @code{logical acc_on_device}
3013 @item @emph{Reference}:
3014 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3021 @section @code{acc_malloc} -- Allocate device memory.
3023 @item @emph{Description}
3024 This function allocates @var{len} bytes of device memory. It returns
3025 the device address of the allocated memory.
3028 @multitable @columnfractions .20 .80
3029 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
3032 @item @emph{Reference}:
3033 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3040 @section @code{acc_free} -- Free device memory.
3042 @item @emph{Description}
3043 Free previously allocated device memory at the device address @code{a}.
3046 @multitable @columnfractions .20 .80
3047 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
3050 @item @emph{Reference}:
3051 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3058 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
3060 @item @emph{Description}
3061 In C/C++, this function allocates @var{len} bytes of device memory
3062 and maps it to the specified host address in @var{a}. The device
3063 address of the newly allocated device memory is returned.
3065 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3066 a contiguous array section. The second form @var{a} specifies a
3067 variable or array element and @var{len} specifies the length in bytes.
3070 @multitable @columnfractions .20 .80
3071 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
3072 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
3075 @item @emph{Fortran}:
3076 @multitable @columnfractions .20 .80
3077 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
3078 @item @tab @code{type, dimension(:[,:]...) :: a}
3079 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
3080 @item @tab @code{type, dimension(:[,:]...) :: a}
3081 @item @tab @code{integer len}
3082 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
3083 @item @tab @code{type, dimension(:[,:]...) :: a}
3084 @item @tab @code{integer(acc_handle_kind) :: async}
3085 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
3086 @item @tab @code{type, dimension(:[,:]...) :: a}
3087 @item @tab @code{integer len}
3088 @item @tab @code{integer(acc_handle_kind) :: async}
3091 @item @emph{Reference}:
3092 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3098 @node acc_present_or_copyin
3099 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
3101 @item @emph{Description}
3102 This function tests if the host data specified by @var{a} and of length
3103 @var{len} is present or not. If it is not present, then device memory
3104 will be allocated and the host memory copied. The device address of
3105 the newly allocated device memory is returned.
3107 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3108 a contiguous array section. The second form @var{a} specifies a variable or
3109 array element and @var{len} specifies the length in bytes.
3111 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
3112 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
3115 @multitable @columnfractions .20 .80
3116 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
3117 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
3120 @item @emph{Fortran}:
3121 @multitable @columnfractions .20 .80
3122 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
3123 @item @tab @code{type, dimension(:[,:]...) :: a}
3124 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
3125 @item @tab @code{type, dimension(:[,:]...) :: a}
3126 @item @tab @code{integer len}
3127 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
3128 @item @tab @code{type, dimension(:[,:]...) :: a}
3129 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
3130 @item @tab @code{type, dimension(:[,:]...) :: a}
3131 @item @tab @code{integer len}
3134 @item @emph{Reference}:
3135 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3142 @section @code{acc_create} -- Allocate device memory and map it to host memory.
3144 @item @emph{Description}
3145 This function allocates device memory and maps it to host memory specified
3146 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
3147 the function returns the device address of the allocated device memory.
3149 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3150 a contiguous array section. The second form @var{a} specifies a variable or
3151 array element and @var{len} specifies the length in bytes.
3154 @multitable @columnfractions .20 .80
3155 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
3156 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
3159 @item @emph{Fortran}:
3160 @multitable @columnfractions .20 .80
3161 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
3162 @item @tab @code{type, dimension(:[,:]...) :: a}
3163 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
3164 @item @tab @code{type, dimension(:[,:]...) :: a}
3165 @item @tab @code{integer len}
3166 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
3167 @item @tab @code{type, dimension(:[,:]...) :: a}
3168 @item @tab @code{integer(acc_handle_kind) :: async}
3169 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
3170 @item @tab @code{type, dimension(:[,:]...) :: a}
3171 @item @tab @code{integer len}
3172 @item @tab @code{integer(acc_handle_kind) :: async}
3175 @item @emph{Reference}:
3176 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3182 @node acc_present_or_create
3183 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
3185 @item @emph{Description}
3186 This function tests if the host data specified by @var{a} and of length
3187 @var{len} is present or not. If it is not present, then device memory
3188 will be allocated and mapped to host memory. In C/C++, the device address
3189 of the newly allocated device memory is returned.
3191 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3192 a contiguous array section. The second form @var{a} specifies a variable or
3193 array element and @var{len} specifies the length in bytes.
3195 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
3196 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
3199 @multitable @columnfractions .20 .80
3200 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
3201 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
3204 @item @emph{Fortran}:
3205 @multitable @columnfractions .20 .80
3206 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
3207 @item @tab @code{type, dimension(:[,:]...) :: a}
3208 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
3209 @item @tab @code{type, dimension(:[,:]...) :: a}
3210 @item @tab @code{integer len}
3211 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
3212 @item @tab @code{type, dimension(:[,:]...) :: a}
3213 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
3214 @item @tab @code{type, dimension(:[,:]...) :: a}
3215 @item @tab @code{integer len}
3218 @item @emph{Reference}:
3219 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3226 @section @code{acc_copyout} -- Copy device memory to host memory.
3228 @item @emph{Description}
3229 This function copies mapped device memory to host memory which is specified
3230 by host address @var{a} for a length @var{len} bytes in C/C++.
3232 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3233 a contiguous array section. The second form @var{a} specifies a variable or
3234 array element and @var{len} specifies the length in bytes.
3237 @multitable @columnfractions .20 .80
3238 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
3239 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
3240 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
3241 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
3244 @item @emph{Fortran}:
3245 @multitable @columnfractions .20 .80
3246 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
3247 @item @tab @code{type, dimension(:[,:]...) :: a}
3248 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
3249 @item @tab @code{type, dimension(:[,:]...) :: a}
3250 @item @tab @code{integer len}
3251 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
3252 @item @tab @code{type, dimension(:[,:]...) :: a}
3253 @item @tab @code{integer(acc_handle_kind) :: async}
3254 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
3255 @item @tab @code{type, dimension(:[,:]...) :: a}
3256 @item @tab @code{integer len}
3257 @item @tab @code{integer(acc_handle_kind) :: async}
3258 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
3259 @item @tab @code{type, dimension(:[,:]...) :: a}
3260 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
3261 @item @tab @code{type, dimension(:[,:]...) :: a}
3262 @item @tab @code{integer len}
3263 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
3264 @item @tab @code{type, dimension(:[,:]...) :: a}
3265 @item @tab @code{integer(acc_handle_kind) :: async}
3266 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
3267 @item @tab @code{type, dimension(:[,:]...) :: a}
3268 @item @tab @code{integer len}
3269 @item @tab @code{integer(acc_handle_kind) :: async}
3272 @item @emph{Reference}:
3273 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3280 @section @code{acc_delete} -- Free device memory.
3282 @item @emph{Description}
3283 This function frees previously allocated device memory specified by
3284 the device address @var{a} and the length of @var{len} bytes.
3286 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3287 a contiguous array section. The second form @var{a} specifies a variable or
3288 array element and @var{len} specifies the length in bytes.
3291 @multitable @columnfractions .20 .80
3292 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
3293 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
3294 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
3295 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
3298 @item @emph{Fortran}:
3299 @multitable @columnfractions .20 .80
3300 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
3301 @item @tab @code{type, dimension(:[,:]...) :: a}
3302 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
3303 @item @tab @code{type, dimension(:[,:]...) :: a}
3304 @item @tab @code{integer len}
3305 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
3306 @item @tab @code{type, dimension(:[,:]...) :: a}
3307 @item @tab @code{integer(acc_handle_kind) :: async}
3308 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
3309 @item @tab @code{type, dimension(:[,:]...) :: a}
3310 @item @tab @code{integer len}
3311 @item @tab @code{integer(acc_handle_kind) :: async}
3312 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
3313 @item @tab @code{type, dimension(:[,:]...) :: a}
3314 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
3315 @item @tab @code{type, dimension(:[,:]...) :: a}
3316 @item @tab @code{integer len}
3317 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
3318 @item @tab @code{type, dimension(:[,:]...) :: a}
3319 @item @tab @code{integer(acc_handle_kind) :: async}
3320 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
3321 @item @tab @code{type, dimension(:[,:]...) :: a}
3322 @item @tab @code{integer len}
3323 @item @tab @code{integer(acc_handle_kind) :: async}
3326 @item @emph{Reference}:
3327 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3333 @node acc_update_device
3334 @section @code{acc_update_device} -- Update device memory from mapped host memory.
3336 @item @emph{Description}
3337 This function updates the device copy from the previously mapped host memory.
3338 The host memory is specified with the host address @var{a} and a length of
3341 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3342 a contiguous array section. The second form @var{a} specifies a variable or
3343 array element and @var{len} specifies the length in bytes.
3346 @multitable @columnfractions .20 .80
3347 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
3348 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
3351 @item @emph{Fortran}:
3352 @multitable @columnfractions .20 .80
3353 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
3354 @item @tab @code{type, dimension(:[,:]...) :: a}
3355 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
3356 @item @tab @code{type, dimension(:[,:]...) :: a}
3357 @item @tab @code{integer len}
3358 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
3359 @item @tab @code{type, dimension(:[,:]...) :: a}
3360 @item @tab @code{integer(acc_handle_kind) :: async}
3361 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
3362 @item @tab @code{type, dimension(:[,:]...) :: a}
3363 @item @tab @code{integer len}
3364 @item @tab @code{integer(acc_handle_kind) :: async}
3367 @item @emph{Reference}:
3368 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3374 @node acc_update_self
3375 @section @code{acc_update_self} -- Update host memory from mapped device memory.
3377 @item @emph{Description}
3378 This function updates the host copy from the previously mapped device memory.
3379 The host memory is specified with the host address @var{a} and a length of
3382 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3383 a contiguous array section. The second form @var{a} specifies a variable or
3384 array element and @var{len} specifies the length in bytes.
3387 @multitable @columnfractions .20 .80
3388 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
3389 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
3392 @item @emph{Fortran}:
3393 @multitable @columnfractions .20 .80
3394 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
3395 @item @tab @code{type, dimension(:[,:]...) :: a}
3396 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
3397 @item @tab @code{type, dimension(:[,:]...) :: a}
3398 @item @tab @code{integer len}
3399 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
3400 @item @tab @code{type, dimension(:[,:]...) :: a}
3401 @item @tab @code{integer(acc_handle_kind) :: async}
3402 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
3403 @item @tab @code{type, dimension(:[,:]...) :: a}
3404 @item @tab @code{integer len}
3405 @item @tab @code{integer(acc_handle_kind) :: async}
3408 @item @emph{Reference}:
3409 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3416 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
3418 @item @emph{Description}
3419 This function maps previously allocated device and host memory. The device
3420 memory is specified with the device address @var{d}. The host memory is
3421 specified with the host address @var{h} and a length of @var{len}.
3424 @multitable @columnfractions .20 .80
3425 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
3428 @item @emph{Reference}:
3429 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3435 @node acc_unmap_data
3436 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
3438 @item @emph{Description}
3439 This function unmaps previously mapped device and host memory. The latter
3440 specified by @var{h}.
3443 @multitable @columnfractions .20 .80
3444 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
3447 @item @emph{Reference}:
3448 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3455 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
3457 @item @emph{Description}
3458 This function returns the device address that has been mapped to the
3459 host address specified by @var{h}.
3462 @multitable @columnfractions .20 .80
3463 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
3466 @item @emph{Reference}:
3467 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3474 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
3476 @item @emph{Description}
3477 This function returns the host address that has been mapped to the
3478 device address specified by @var{d}.
3481 @multitable @columnfractions .20 .80
3482 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
3485 @item @emph{Reference}:
3486 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3492 @node acc_is_present
3493 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
3495 @item @emph{Description}
3496 This function indicates whether the specified host address in @var{a} and a
3497 length of @var{len} bytes is present on the device. In C/C++, a non-zero
3498 value is returned to indicate the presence of the mapped memory on the
3499 device. A zero is returned to indicate the memory is not mapped on the
3502 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3503 a contiguous array section. The second form @var{a} specifies a variable or
3504 array element and @var{len} specifies the length in bytes. If the host
3505 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
3506 a @code{false} is return to indicate the mapped memory is not present.
3509 @multitable @columnfractions .20 .80
3510 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
3513 @item @emph{Fortran}:
3514 @multitable @columnfractions .20 .80
3515 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
3516 @item @tab @code{type, dimension(:[,:]...) :: a}
3517 @item @tab @code{logical acc_is_present}
3518 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
3519 @item @tab @code{type, dimension(:[,:]...) :: a}
3520 @item @tab @code{integer len}
3521 @item @tab @code{logical acc_is_present}
3524 @item @emph{Reference}:
3525 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3531 @node acc_memcpy_to_device
3532 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
3534 @item @emph{Description}
3535 This function copies host memory specified by host address of @var{src} to
3536 device memory specified by the device address @var{dest} for a length of
3540 @multitable @columnfractions .20 .80
3541 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
3544 @item @emph{Reference}:
3545 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3551 @node acc_memcpy_from_device
3552 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
3554 @item @emph{Description}
3555 This function copies host memory specified by host address of @var{src} from
3556 device memory specified by the device address @var{dest} for a length of
3560 @multitable @columnfractions .20 .80
3561 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
3564 @item @emph{Reference}:
3565 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3572 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
3574 @item @emph{Description}
3575 This function updates a pointer on the device from pointing to a host-pointer
3576 address to pointing to the corresponding device data.
3579 @multitable @columnfractions .20 .80
3580 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
3581 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
3584 @item @emph{Reference}:
3585 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3592 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
3594 @item @emph{Description}
3595 This function updates a pointer on the device from pointing to a device-pointer
3596 address to pointing to the corresponding host data.
3599 @multitable @columnfractions .20 .80
3600 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
3601 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
3602 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
3603 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
3606 @item @emph{Reference}:
3607 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3613 @node acc_get_current_cuda_device
3614 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
3616 @item @emph{Description}
3617 This function returns the CUDA device handle. This handle is the same
3618 as used by the CUDA Runtime or Driver API's.
3621 @multitable @columnfractions .20 .80
3622 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
3625 @item @emph{Reference}:
3626 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3632 @node acc_get_current_cuda_context
3633 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
3635 @item @emph{Description}
3636 This function returns the CUDA context handle. This handle is the same
3637 as used by the CUDA Runtime or Driver API's.
3640 @multitable @columnfractions .20 .80
3641 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
3644 @item @emph{Reference}:
3645 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3651 @node acc_get_cuda_stream
3652 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
3654 @item @emph{Description}
3655 This function returns the CUDA stream handle for the queue @var{async}.
3656 This handle is the same as used by the CUDA Runtime or Driver API's.
3659 @multitable @columnfractions .20 .80
3660 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
3663 @item @emph{Reference}:
3664 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3670 @node acc_set_cuda_stream
3671 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
3673 @item @emph{Description}
3674 This function associates the stream handle specified by @var{stream} with
3675 the queue @var{async}.
3677 This cannot be used to change the stream handle associated with
3678 @code{acc_async_sync}.
3680 The return value is not specified.
3683 @multitable @columnfractions .20 .80
3684 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
3687 @item @emph{Reference}:
3688 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3694 @node acc_prof_register
3695 @section @code{acc_prof_register} -- Register callbacks.
3697 @item @emph{Description}:
3698 This function registers callbacks.
3701 @multitable @columnfractions .20 .80
3702 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
3705 @item @emph{See also}:
3706 @ref{OpenACC Profiling Interface}
3708 @item @emph{Reference}:
3709 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3715 @node acc_prof_unregister
3716 @section @code{acc_prof_unregister} -- Unregister callbacks.
3718 @item @emph{Description}:
3719 This function unregisters callbacks.
3722 @multitable @columnfractions .20 .80
3723 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
3726 @item @emph{See also}:
3727 @ref{OpenACC Profiling Interface}
3729 @item @emph{Reference}:
3730 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3736 @node acc_prof_lookup
3737 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
3739 @item @emph{Description}:
3740 Function to obtain inquiry functions.
3743 @multitable @columnfractions .20 .80
3744 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
3747 @item @emph{See also}:
3748 @ref{OpenACC Profiling Interface}
3750 @item @emph{Reference}:
3751 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3757 @node acc_register_library
3758 @section @code{acc_register_library} -- Library registration.
3760 @item @emph{Description}:
3761 Function for library registration.
3764 @multitable @columnfractions .20 .80
3765 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
3768 @item @emph{See also}:
3769 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
3771 @item @emph{Reference}:
3772 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3778 @c ---------------------------------------------------------------------
3779 @c OpenACC Environment Variables
3780 @c ---------------------------------------------------------------------
3782 @node OpenACC Environment Variables
3783 @chapter OpenACC Environment Variables
3785 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
3786 are defined by section 4 of the OpenACC specification in version 2.0.
3787 The variable @env{ACC_PROFLIB}
3788 is defined by section 4 of the OpenACC specification in version 2.6.
3789 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
3800 @node ACC_DEVICE_TYPE
3801 @section @code{ACC_DEVICE_TYPE}
3803 @item @emph{Reference}:
3804 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3810 @node ACC_DEVICE_NUM
3811 @section @code{ACC_DEVICE_NUM}
3813 @item @emph{Reference}:
3814 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3821 @section @code{ACC_PROFLIB}
3823 @item @emph{See also}:
3824 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
3826 @item @emph{Reference}:
3827 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3833 @node GCC_ACC_NOTIFY
3834 @section @code{GCC_ACC_NOTIFY}
3836 @item @emph{Description}:
3837 Print debug information pertaining to the accelerator.
3842 @c ---------------------------------------------------------------------
3843 @c CUDA Streams Usage
3844 @c ---------------------------------------------------------------------
3846 @node CUDA Streams Usage
3847 @chapter CUDA Streams Usage
3849 This applies to the @code{nvptx} plugin only.
3851 The library provides elements that perform asynchronous movement of
3852 data and asynchronous operation of computing constructs. This
3853 asynchronous functionality is implemented by making use of CUDA
3854 streams@footnote{See "Stream Management" in "CUDA Driver API",
3855 TRM-06703-001, Version 5.5, for additional information}.
3857 The primary means by that the asynchronous functionality is accessed
3858 is through the use of those OpenACC directives which make use of the
3859 @code{async} and @code{wait} clauses. When the @code{async} clause is
3860 first used with a directive, it creates a CUDA stream. If an
3861 @code{async-argument} is used with the @code{async} clause, then the
3862 stream is associated with the specified @code{async-argument}.
3864 Following the creation of an association between a CUDA stream and the
3865 @code{async-argument} of an @code{async} clause, both the @code{wait}
3866 clause and the @code{wait} directive can be used. When either the
3867 clause or directive is used after stream creation, it creates a
3868 rendezvous point whereby execution waits until all operations
3869 associated with the @code{async-argument}, that is, stream, have
3872 Normally, the management of the streams that are created as a result of
3873 using the @code{async} clause, is done without any intervention by the
3874 caller. This implies the association between the @code{async-argument}
3875 and the CUDA stream will be maintained for the lifetime of the program.
3876 However, this association can be changed through the use of the library
3877 function @code{acc_set_cuda_stream}. When the function
3878 @code{acc_set_cuda_stream} is called, the CUDA stream that was
3879 originally associated with the @code{async} clause will be destroyed.
3880 Caution should be taken when changing the association as subsequent
3881 references to the @code{async-argument} refer to a different
3886 @c ---------------------------------------------------------------------
3887 @c OpenACC Library Interoperability
3888 @c ---------------------------------------------------------------------
3890 @node OpenACC Library Interoperability
3891 @chapter OpenACC Library Interoperability
3893 @section Introduction
3895 The OpenACC library uses the CUDA Driver API, and may interact with
3896 programs that use the Runtime library directly, or another library
3897 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
3898 "Interactions with the CUDA Driver API" in
3899 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
3900 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
3901 for additional information on library interoperability.}.
3902 This chapter describes the use cases and what changes are
3903 required in order to use both the OpenACC library and the CUBLAS and Runtime
3904 libraries within a program.
3906 @section First invocation: NVIDIA CUBLAS library API
3908 In this first use case (see below), a function in the CUBLAS library is called
3909 prior to any of the functions in the OpenACC library. More specifically, the
3910 function @code{cublasCreate()}.
3912 When invoked, the function initializes the library and allocates the
3913 hardware resources on the host and the device on behalf of the caller. Once
3914 the initialization and allocation has completed, a handle is returned to the
3915 caller. The OpenACC library also requires initialization and allocation of
3916 hardware resources. Since the CUBLAS library has already allocated the
3917 hardware resources for the device, all that is left to do is to initialize
3918 the OpenACC library and acquire the hardware resources on the host.
3920 Prior to calling the OpenACC function that initializes the library and
3921 allocate the host hardware resources, you need to acquire the device number
3922 that was allocated during the call to @code{cublasCreate()}. The invoking of the
3923 runtime library function @code{cudaGetDevice()} accomplishes this. Once
3924 acquired, the device number is passed along with the device type as
3925 parameters to the OpenACC library function @code{acc_set_device_num()}.
3927 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
3928 library uses the context that was created during the call to
3929 @code{cublasCreate()}. In other words, both libraries will be sharing the
3933 /* Create the handle */
3934 s = cublasCreate(&h);
3935 if (s != CUBLAS_STATUS_SUCCESS)
3937 fprintf(stderr, "cublasCreate failed %d\n", s);
3941 /* Get the device number */
3942 e = cudaGetDevice(&dev);
3943 if (e != cudaSuccess)
3945 fprintf(stderr, "cudaGetDevice failed %d\n", e);
3949 /* Initialize OpenACC library and use device 'dev' */
3950 acc_set_device_num(dev, acc_device_nvidia);
3955 @section First invocation: OpenACC library API
3957 In this second use case (see below), a function in the OpenACC library is
3958 called prior to any of the functions in the CUBLAS library. More specifically,
3959 the function @code{acc_set_device_num()}.
3961 In the use case presented here, the function @code{acc_set_device_num()}
3962 is used to both initialize the OpenACC library and allocate the hardware
3963 resources on the host and the device. In the call to the function, the
3964 call parameters specify which device to use and what device
3965 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
3966 is but one method to initialize the OpenACC library and allocate the
3967 appropriate hardware resources. Other methods are available through the
3968 use of environment variables and these will be discussed in the next section.
3970 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
3971 functions can be called as seen with multiple calls being made to
3972 @code{acc_copyin()}. In addition, calls can be made to functions in the
3973 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
3974 subsequent to the calls to @code{acc_copyin()}.
3975 As seen in the previous use case, a call to @code{cublasCreate()}
3976 initializes the CUBLAS library and allocates the hardware resources on the
3977 host and the device. However, since the device has already been allocated,
3978 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
3979 the appropriate hardware resources on the host. The context that was created
3980 as part of the OpenACC initialization is shared with the CUBLAS library,
3981 similarly to the first use case.
3986 acc_set_device_num(dev, acc_device_nvidia);
3988 /* Copy the first set to the device */
3989 d_X = acc_copyin(&h_X[0], N * sizeof (float));
3992 fprintf(stderr, "copyin error h_X\n");
3996 /* Copy the second set to the device */
3997 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
4000 fprintf(stderr, "copyin error h_Y1\n");
4004 /* Create the handle */
4005 s = cublasCreate(&h);
4006 if (s != CUBLAS_STATUS_SUCCESS)
4008 fprintf(stderr, "cublasCreate failed %d\n", s);
4012 /* Perform saxpy using CUBLAS library function */
4013 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
4014 if (s != CUBLAS_STATUS_SUCCESS)
4016 fprintf(stderr, "cublasSaxpy failed %d\n", s);
4020 /* Copy the results from the device */
4021 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
4026 @section OpenACC library and environment variables
4028 There are two environment variables associated with the OpenACC library
4029 that may be used to control the device type and device number:
4030 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
4031 environment variables can be used as an alternative to calling
4032 @code{acc_set_device_num()}. As seen in the second use case, the device
4033 type and device number were specified using @code{acc_set_device_num()}.
4034 If however, the aforementioned environment variables were set, then the
4035 call to @code{acc_set_device_num()} would not be required.
4038 The use of the environment variables is only relevant when an OpenACC function
4039 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
4040 is called prior to a call to an OpenACC function, then you must call
4041 @code{acc_set_device_num()}@footnote{More complete information
4042 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
4043 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
4044 Application Programming Interface”, Version 2.6.}
4048 @c ---------------------------------------------------------------------
4049 @c OpenACC Profiling Interface
4050 @c ---------------------------------------------------------------------
4052 @node OpenACC Profiling Interface
4053 @chapter OpenACC Profiling Interface
4055 @section Implementation Status and Implementation-Defined Behavior
4057 We're implementing the OpenACC Profiling Interface as defined by the
4058 OpenACC 2.6 specification. We're clarifying some aspects here as
4059 @emph{implementation-defined behavior}, while they're still under
4060 discussion within the OpenACC Technical Committee.
4062 This implementation is tuned to keep the performance impact as low as
4063 possible for the (very common) case that the Profiling Interface is
4064 not enabled. This is relevant, as the Profiling Interface affects all
4065 the @emph{hot} code paths (in the target code, not in the offloaded
4066 code). Users of the OpenACC Profiling Interface can be expected to
4067 understand that performance will be impacted to some degree once the
4068 Profiling Interface has gotten enabled: for example, because of the
4069 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
4070 every event that has been registered.
4072 We're not yet accounting for the fact that @cite{OpenACC events may
4073 occur during event processing}.
4074 We just handle one case specially, as required by CUDA 9.0
4075 @command{nvprof}, that @code{acc_get_device_type}
4076 (@ref{acc_get_device_type})) may be called from
4077 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4080 We're not yet implementing initialization via a
4081 @code{acc_register_library} function that is either statically linked
4082 in, or dynamically via @env{LD_PRELOAD}.
4083 Initialization via @code{acc_register_library} functions dynamically
4084 loaded via the @env{ACC_PROFLIB} environment variable does work, as
4085 does directly calling @code{acc_prof_register},
4086 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
4088 As currently there are no inquiry functions defined, calls to
4089 @code{acc_prof_lookup} will always return @code{NULL}.
4091 There aren't separate @emph{start}, @emph{stop} events defined for the
4092 event types @code{acc_ev_create}, @code{acc_ev_delete},
4093 @code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
4094 should be triggered before or after the actual device-specific call is
4095 made. We trigger them after.
4097 Remarks about data provided to callbacks:
4101 @item @code{acc_prof_info.event_type}
4102 It's not clear if for @emph{nested} event callbacks (for example,
4103 @code{acc_ev_enqueue_launch_start} as part of a parent compute
4104 construct), this should be set for the nested event
4105 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
4106 construct should remain (@code{acc_ev_compute_construct_start}). In
4107 this implementation, the value will generally correspond to the
4108 innermost nested event type.
4110 @item @code{acc_prof_info.device_type}
4114 For @code{acc_ev_compute_construct_start}, and in presence of an
4115 @code{if} clause with @emph{false} argument, this will still refer to
4116 the offloading device type.
4117 It's not clear if that's the expected behavior.
4120 Complementary to the item before, for
4121 @code{acc_ev_compute_construct_end}, this is set to
4122 @code{acc_device_host} in presence of an @code{if} clause with
4123 @emph{false} argument.
4124 It's not clear if that's the expected behavior.
4128 @item @code{acc_prof_info.thread_id}
4129 Always @code{-1}; not yet implemented.
4131 @item @code{acc_prof_info.async}
4135 Not yet implemented correctly for
4136 @code{acc_ev_compute_construct_start}.
4139 In a compute construct, for host-fallback
4140 execution/@code{acc_device_host} it will always be
4141 @code{acc_async_sync}.
4142 It's not clear if that's the expected behavior.
4145 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
4146 it will always be @code{acc_async_sync}.
4147 It's not clear if that's the expected behavior.
4151 @item @code{acc_prof_info.async_queue}
4152 There is no @cite{limited number of asynchronous queues} in libgomp.
4153 This will always have the same value as @code{acc_prof_info.async}.
4155 @item @code{acc_prof_info.src_file}
4156 Always @code{NULL}; not yet implemented.
4158 @item @code{acc_prof_info.func_name}
4159 Always @code{NULL}; not yet implemented.
4161 @item @code{acc_prof_info.line_no}
4162 Always @code{-1}; not yet implemented.
4164 @item @code{acc_prof_info.end_line_no}
4165 Always @code{-1}; not yet implemented.
4167 @item @code{acc_prof_info.func_line_no}
4168 Always @code{-1}; not yet implemented.
4170 @item @code{acc_prof_info.func_end_line_no}
4171 Always @code{-1}; not yet implemented.
4173 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
4174 Relating to @code{acc_prof_info.event_type} discussed above, in this
4175 implementation, this will always be the same value as
4176 @code{acc_prof_info.event_type}.
4178 @item @code{acc_event_info.*.parent_construct}
4182 Will be @code{acc_construct_parallel} for all OpenACC compute
4183 constructs as well as many OpenACC Runtime API calls; should be the
4184 one matching the actual construct, or
4185 @code{acc_construct_runtime_api}, respectively.
4188 Will be @code{acc_construct_enter_data} or
4189 @code{acc_construct_exit_data} when processing variable mappings
4190 specified in OpenACC @emph{declare} directives; should be
4191 @code{acc_construct_declare}.
4194 For implicit @code{acc_ev_device_init_start},
4195 @code{acc_ev_device_init_end}, and explicit as well as implicit
4196 @code{acc_ev_alloc}, @code{acc_ev_free},
4197 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4198 @code{acc_ev_enqueue_download_start}, and
4199 @code{acc_ev_enqueue_download_end}, will be
4200 @code{acc_construct_parallel}; should reflect the real parent
4205 @item @code{acc_event_info.*.implicit}
4206 For @code{acc_ev_alloc}, @code{acc_ev_free},
4207 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4208 @code{acc_ev_enqueue_download_start}, and
4209 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
4210 also for explicit usage.
4212 @item @code{acc_event_info.data_event.var_name}
4213 Always @code{NULL}; not yet implemented.
4215 @item @code{acc_event_info.data_event.host_ptr}
4216 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
4219 @item @code{typedef union acc_api_info}
4220 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
4221 Information}. This should obviously be @code{typedef @emph{struct}
4224 @item @code{acc_api_info.device_api}
4225 Possibly not yet implemented correctly for
4226 @code{acc_ev_compute_construct_start},
4227 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
4228 will always be @code{acc_device_api_none} for these event types.
4229 For @code{acc_ev_enter_data_start}, it will be
4230 @code{acc_device_api_none} in some cases.
4232 @item @code{acc_api_info.device_type}
4233 Always the same as @code{acc_prof_info.device_type}.
4235 @item @code{acc_api_info.vendor}
4236 Always @code{-1}; not yet implemented.
4238 @item @code{acc_api_info.device_handle}
4239 Always @code{NULL}; not yet implemented.
4241 @item @code{acc_api_info.context_handle}
4242 Always @code{NULL}; not yet implemented.
4244 @item @code{acc_api_info.async_handle}
4245 Always @code{NULL}; not yet implemented.
4249 Remarks about certain event types:
4253 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4257 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
4258 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
4259 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
4260 When a compute construct triggers implicit
4261 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
4262 events, they currently aren't @emph{nested within} the corresponding
4263 @code{acc_ev_compute_construct_start} and
4264 @code{acc_ev_compute_construct_end}, but they're currently observed
4265 @emph{before} @code{acc_ev_compute_construct_start}.
4266 It's not clear what to do: the standard asks us provide a lot of
4267 details to the @code{acc_ev_compute_construct_start} callback, without
4268 (implicitly) initializing a device before?
4271 Callbacks for these event types will not be invoked for calls to the
4272 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
4273 It's not clear if they should be.
4277 @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}
4281 Callbacks for these event types will also be invoked for OpenACC
4282 @emph{host_data} constructs.
4283 It's not clear if they should be.
4286 Callbacks for these event types will also be invoked when processing
4287 variable mappings specified in OpenACC @emph{declare} directives.
4288 It's not clear if they should be.
4294 Callbacks for the following event types will be invoked, but dispatch
4295 and information provided therein has not yet been thoroughly reviewed:
4298 @item @code{acc_ev_alloc}
4299 @item @code{acc_ev_free}
4300 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
4301 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
4302 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
4305 During device initialization, and finalization, respectively,
4306 callbacks for the following event types will not yet be invoked:
4309 @item @code{acc_ev_alloc}
4310 @item @code{acc_ev_free}
4313 Callbacks for the following event types have not yet been implemented,
4314 so currently won't be invoked:
4317 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
4318 @item @code{acc_ev_runtime_shutdown}
4319 @item @code{acc_ev_create}, @code{acc_ev_delete}
4320 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
4323 For the following runtime library functions, not all expected
4324 callbacks will be invoked (mostly concerning implicit device
4328 @item @code{acc_get_num_devices}
4329 @item @code{acc_set_device_type}
4330 @item @code{acc_get_device_type}
4331 @item @code{acc_set_device_num}
4332 @item @code{acc_get_device_num}
4333 @item @code{acc_init}
4334 @item @code{acc_shutdown}
4337 Aside from implicit device initialization, for the following runtime
4338 library functions, no callbacks will be invoked for shared-memory
4339 offloading devices (it's not clear if they should be):
4342 @item @code{acc_malloc}
4343 @item @code{acc_free}
4344 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
4345 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
4346 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
4347 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
4348 @item @code{acc_update_device}, @code{acc_update_device_async}
4349 @item @code{acc_update_self}, @code{acc_update_self_async}
4350 @item @code{acc_map_data}, @code{acc_unmap_data}
4351 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
4352 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
4355 @c ---------------------------------------------------------------------
4356 @c OpenMP-Implementation Specifics
4357 @c ---------------------------------------------------------------------
4359 @node OpenMP-Implementation Specifics
4360 @chapter OpenMP-Implementation Specifics
4363 * OpenMP Context Selectors::
4364 * Memory allocation with libmemkind::
4367 @node OpenMP Context Selectors
4368 @section OpenMP Context Selectors
4370 @code{vendor} is always @code{gnu}. References are to the GCC manual.
4372 @multitable @columnfractions .60 .10 .25
4373 @headitem @code{arch} @tab @code{kind} @tab @code{isa}
4374 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
4375 @code{i586}, @code{i686}, @code{ia32}
4377 @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
4378 @item @code{amdgcn}, @code{gcn}
4380 @tab See @code{-march=} in ``AMD GCN Options''@footnote{Additionally,
4381 @code{gfx803} is supported as an alias for @code{fiji}.}
4384 @tab See @code{-march=} in ``Nvidia PTX Options''
4387 @node Memory allocation with libmemkind
4388 @section Memory allocation with libmemkind
4390 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
4391 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
4392 creating memory allocators requesting
4395 @item the memory space @code{omp_high_bw_mem_space}
4396 @item the memory space @code{omp_large_cap_mem_space}
4397 @item the partition trait @code{omp_atv_interleaved}
4401 @c ---------------------------------------------------------------------
4402 @c Offload-Target Specifics
4403 @c ---------------------------------------------------------------------
4405 @node Offload-Target Specifics
4406 @chapter Offload-Target Specifics
4408 The following sections present notes on the offload-target specifics
4416 @section AMD Radeon (GCN)
4418 On the hardware side, there is the hierarchy (fine to coarse):
4420 @item work item (thread)
4423 @item compute unit (CU)
4426 All OpenMP and OpenACC levels are used, i.e.
4428 @item OpenMP's simd and OpenACC's vector map to work items (thread)
4429 @item OpenMP's threads (``parallel'') and OpenACC's workers map
4431 @item OpenMP's teams and OpenACC's gang use a threadpool with the
4432 size of the number of teams or gangs, respectively.
4437 @item Number of teams is the specified @code{num_teams} (OpenMP) or
4438 @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
4439 by two times the number of CU.
4440 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
4441 @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
4442 overrides this if smaller.
4443 @item The wavefront has 102 scalars and 64 vectors
4444 @item Number of workitems is always 64
4445 @item The hardware permits maximally 40 workgroups/CU and
4446 16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
4447 @item 80 scalars registers and 24 vector registers in non-kernel functions
4448 (the chosen procedure-calling API).
4449 @item For the kernel itself: as many as register pressure demands (number of
4450 teams and number of threads, scaled down if registers are exhausted)
4453 The implementation remark:
4455 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
4456 using the C library @code{printf} functions and the Fortran
4457 @code{print}/@code{write} statements.
4458 @item Reverse offload regions (i.e. @code{target} regions with
4459 @code{device(ancestor:1)}) are processed serially per @code{target} region
4460 such that the next reverse offload region is only executed after the previous
4462 @item OpenMP code that has a @code{requires} directive with
4463 @code{unified_shared_memory} will remove any GCN device from the list of
4464 available devices (``host fallback'').
4465 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
4466 environment variable; the default is 32 kiB per thread.
4474 On the hardware side, there is the hierarchy (fine to coarse):
4479 @item streaming multiprocessor
4482 All OpenMP and OpenACC levels are used, i.e.
4484 @item OpenMP's simd and OpenACC's vector map to threads
4485 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
4486 @item OpenMP's teams and OpenACC's gang use a threadpool with the
4487 size of the number of teams or gangs, respectively.
4492 @item The @code{warp_size} is always 32
4493 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
4494 @item The number of teams is limited by the number of blocks the device can
4495 host simultaneously.
4498 Additional information can be obtained by setting the environment variable to
4499 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
4502 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
4503 which caches the JIT in the user's directory (see CUDA documentation; can be
4504 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
4506 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
4507 options still affect the used PTX ISA code and, thus, the requirements on
4508 CUDA version and hardware.
4510 The implementation remark:
4512 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
4513 using the C library @code{printf} functions. Note that the Fortran
4514 @code{print}/@code{write} statements are not supported, yet.
4515 @item Compilation OpenMP code that contains @code{requires reverse_offload}
4516 requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
4518 @item For code containing reverse offload (i.e. @code{target} regions with
4519 @code{device(ancestor:1)}), there is a slight performance penalty
4520 for @emph{all} target regions, consisting mostly of shutdown delay
4521 Per device, reverse offload regions are processed serially such that
4522 the next reverse offload region is only executed after the previous
4524 @item OpenMP code that has a @code{requires} directive with
4525 @code{unified_shared_memory} will remove any nvptx device from the
4526 list of available devices (``host fallback'').
4530 @c ---------------------------------------------------------------------
4532 @c ---------------------------------------------------------------------
4534 @node The libgomp ABI
4535 @chapter The libgomp ABI
4537 The following sections present notes on the external ABI as
4538 presented by libgomp. Only maintainers should need them.
4541 * Implementing MASTER construct::
4542 * Implementing CRITICAL construct::
4543 * Implementing ATOMIC construct::
4544 * Implementing FLUSH construct::
4545 * Implementing BARRIER construct::
4546 * Implementing THREADPRIVATE construct::
4547 * Implementing PRIVATE clause::
4548 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
4549 * Implementing REDUCTION clause::
4550 * Implementing PARALLEL construct::
4551 * Implementing FOR construct::
4552 * Implementing ORDERED construct::
4553 * Implementing SECTIONS construct::
4554 * Implementing SINGLE construct::
4555 * Implementing OpenACC's PARALLEL construct::
4559 @node Implementing MASTER construct
4560 @section Implementing MASTER construct
4563 if (omp_get_thread_num () == 0)
4567 Alternately, we generate two copies of the parallel subfunction
4568 and only include this in the version run by the primary thread.
4569 Surely this is not worthwhile though...
4573 @node Implementing CRITICAL construct
4574 @section Implementing CRITICAL construct
4576 Without a specified name,
4579 void GOMP_critical_start (void);
4580 void GOMP_critical_end (void);
4583 so that we don't get COPY relocations from libgomp to the main
4586 With a specified name, use omp_set_lock and omp_unset_lock with
4587 name being transformed into a variable declared like
4590 omp_lock_t gomp_critical_user_<name> __attribute__((common))
4593 Ideally the ABI would specify that all zero is a valid unlocked
4594 state, and so we wouldn't need to initialize this at
4599 @node Implementing ATOMIC construct
4600 @section Implementing ATOMIC construct
4602 The target should implement the @code{__sync} builtins.
4604 Failing that we could add
4607 void GOMP_atomic_enter (void)
4608 void GOMP_atomic_exit (void)
4611 which reuses the regular lock code, but with yet another lock
4612 object private to the library.
4616 @node Implementing FLUSH construct
4617 @section Implementing FLUSH construct
4619 Expands to the @code{__sync_synchronize} builtin.
4623 @node Implementing BARRIER construct
4624 @section Implementing BARRIER construct
4627 void GOMP_barrier (void)
4631 @node Implementing THREADPRIVATE construct
4632 @section Implementing THREADPRIVATE construct
4634 In _most_ cases we can map this directly to @code{__thread}. Except
4635 that OMP allows constructors for C++ objects. We can either
4636 refuse to support this (how often is it used?) or we can
4637 implement something akin to .ctors.
4639 Even more ideally, this ctor feature is handled by extensions
4640 to the main pthreads library. Failing that, we can have a set
4641 of entry points to register ctor functions to be called.
4645 @node Implementing PRIVATE clause
4646 @section Implementing PRIVATE clause
4648 In association with a PARALLEL, or within the lexical extent
4649 of a PARALLEL block, the variable becomes a local variable in
4650 the parallel subfunction.
4652 In association with FOR or SECTIONS blocks, create a new
4653 automatic variable within the current function. This preserves
4654 the semantic of new variable creation.
4658 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4659 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4661 This seems simple enough for PARALLEL blocks. Create a private
4662 struct for communicating between the parent and subfunction.
4663 In the parent, copy in values for scalar and "small" structs;
4664 copy in addresses for others TREE_ADDRESSABLE types. In the
4665 subfunction, copy the value into the local variable.
4667 It is not clear what to do with bare FOR or SECTION blocks.
4668 The only thing I can figure is that we do something like:
4671 #pragma omp for firstprivate(x) lastprivate(y)
4672 for (int i = 0; i < n; ++i)
4689 where the "x=x" and "y=y" assignments actually have different
4690 uids for the two variables, i.e. not something you could write
4691 directly in C. Presumably this only makes sense if the "outer"
4692 x and y are global variables.
4694 COPYPRIVATE would work the same way, except the structure
4695 broadcast would have to happen via SINGLE machinery instead.
4699 @node Implementing REDUCTION clause
4700 @section Implementing REDUCTION clause
4702 The private struct mentioned in the previous section should have
4703 a pointer to an array of the type of the variable, indexed by the
4704 thread's @var{team_id}. The thread stores its final value into the
4705 array, and after the barrier, the primary thread iterates over the
4706 array to collect the values.
4709 @node Implementing PARALLEL construct
4710 @section Implementing PARALLEL construct
4713 #pragma omp parallel
4722 void subfunction (void *data)
4729 GOMP_parallel_start (subfunction, &data, num_threads);
4730 subfunction (&data);
4731 GOMP_parallel_end ();
4735 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
4738 The @var{FN} argument is the subfunction to be run in parallel.
4740 The @var{DATA} argument is a pointer to a structure used to
4741 communicate data in and out of the subfunction, as discussed
4742 above with respect to FIRSTPRIVATE et al.
4744 The @var{NUM_THREADS} argument is 1 if an IF clause is present
4745 and false, or the value of the NUM_THREADS clause, if
4748 The function needs to create the appropriate number of
4749 threads and/or launch them from the dock. It needs to
4750 create the team structure and assign team ids.
4753 void GOMP_parallel_end (void)
4756 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
4760 @node Implementing FOR construct
4761 @section Implementing FOR construct
4764 #pragma omp parallel for
4765 for (i = lb; i <= ub; i++)
4772 void subfunction (void *data)
4775 while (GOMP_loop_static_next (&_s0, &_e0))
4778 for (i = _s0; i < _e1; i++)
4781 GOMP_loop_end_nowait ();
4784 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
4786 GOMP_parallel_end ();
4790 #pragma omp for schedule(runtime)
4791 for (i = 0; i < n; i++)
4800 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
4803 for (i = _s0, i < _e0; i++)
4805 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
4810 Note that while it looks like there is trickiness to propagating
4811 a non-constant STEP, there isn't really. We're explicitly allowed
4812 to evaluate it as many times as we want, and any variables involved
4813 should automatically be handled as PRIVATE or SHARED like any other
4814 variables. So the expression should remain evaluable in the
4815 subfunction. We can also pull it into a local variable if we like,
4816 but since its supposed to remain unchanged, we can also not if we like.
4818 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
4819 able to get away with no work-sharing context at all, since we can
4820 simply perform the arithmetic directly in each thread to divide up
4821 the iterations. Which would mean that we wouldn't need to call any
4824 There are separate routines for handling loops with an ORDERED
4825 clause. Bookkeeping for that is non-trivial...
4829 @node Implementing ORDERED construct
4830 @section Implementing ORDERED construct
4833 void GOMP_ordered_start (void)
4834 void GOMP_ordered_end (void)
4839 @node Implementing SECTIONS construct
4840 @section Implementing SECTIONS construct
4845 #pragma omp sections
4859 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
4876 @node Implementing SINGLE construct
4877 @section Implementing SINGLE construct
4891 if (GOMP_single_start ())
4899 #pragma omp single copyprivate(x)
4906 datap = GOMP_single_copy_start ();
4911 GOMP_single_copy_end (&data);
4920 @node Implementing OpenACC's PARALLEL construct
4921 @section Implementing OpenACC's PARALLEL construct
4924 void GOACC_parallel ()
4929 @c ---------------------------------------------------------------------
4931 @c ---------------------------------------------------------------------
4933 @node Reporting Bugs
4934 @chapter Reporting Bugs
4936 Bugs in the GNU Offloading and Multi Processing Runtime Library should
4937 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
4938 "openacc", or "openmp", or both to the keywords field in the bug
4939 report, as appropriate.
4943 @c ---------------------------------------------------------------------
4944 @c GNU General Public License
4945 @c ---------------------------------------------------------------------
4947 @include gpl_v3.texi
4951 @c ---------------------------------------------------------------------
4952 @c GNU Free Documentation License
4953 @c ---------------------------------------------------------------------
4959 @c ---------------------------------------------------------------------
4960 @c Funding Free Software
4961 @c ---------------------------------------------------------------------
4963 @include funding.texi
4965 @c ---------------------------------------------------------------------
4967 @c ---------------------------------------------------------------------
4970 @unnumbered Library Index