1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2018 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@*
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 * Runtime Library Routines:: The OpenMP runtime application programming
100 * Environment Variables:: Influencing runtime behavior with environment
102 * Enabling OpenACC:: How to enable OpenACC for your
104 * OpenACC Runtime Library Routines:: The OpenACC runtime application
105 programming interface.
106 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
107 environment variables.
108 * CUDA Streams Usage:: Notes on the implementation of
109 asynchronous operations.
110 * OpenACC Library Interoperability:: OpenACC library interoperability with the
111 NVIDIA CUBLAS library.
112 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
113 * Reporting Bugs:: How to report bugs in the GNU Offloading and
114 Multi Processing Runtime Library.
115 * Copying:: GNU general public license says
116 how you can copy and share libgomp.
117 * GNU Free Documentation License::
118 How you can copy and share this manual.
119 * Funding:: How to help assure continued work for free
121 * Library Index:: Index of this documentation.
125 @c ---------------------------------------------------------------------
127 @c ---------------------------------------------------------------------
129 @node Enabling OpenMP
130 @chapter Enabling OpenMP
132 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
133 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
134 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
135 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
136 @code{!$} conditional compilation sentinels in free form and @code{c$},
137 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
138 arranges for automatic linking of the OpenMP runtime library
139 (@ref{Runtime Library Routines}).
141 A complete description of all OpenMP directives accepted may be found in
142 the @uref{https://www.openmp.org, OpenMP Application Program Interface} manual,
146 @c ---------------------------------------------------------------------
147 @c Runtime Library Routines
148 @c ---------------------------------------------------------------------
150 @node Runtime Library Routines
151 @chapter Runtime Library Routines
153 The runtime routines described here are defined by Section 3 of the OpenMP
154 specification in version 4.5. The routines are structured in following
158 Control threads, processors and the parallel environment. They have C
159 linkage, and do not throw exceptions.
161 * omp_get_active_level:: Number of active parallel regions
162 * omp_get_ancestor_thread_num:: Ancestor thread ID
163 * omp_get_cancellation:: Whether cancellation support is enabled
164 * omp_get_default_device:: Get the default device for target regions
165 * omp_get_dynamic:: Dynamic teams setting
166 * omp_get_level:: Number of parallel regions
167 * omp_get_max_active_levels:: Maximum number of active regions
168 * omp_get_max_task_priority:: Maximum task priority value that can be set
169 * omp_get_max_threads:: Maximum number of threads of parallel region
170 * omp_get_nested:: Nested parallel regions
171 * omp_get_num_devices:: Number of target devices
172 * omp_get_num_procs:: Number of processors online
173 * omp_get_num_teams:: Number of teams
174 * omp_get_num_threads:: Size of the active team
175 * omp_get_proc_bind:: Whether theads may be moved between CPUs
176 * omp_get_schedule:: Obtain the runtime scheduling method
177 * omp_get_team_num:: Get team number
178 * omp_get_team_size:: Number of threads in a team
179 * omp_get_thread_limit:: Maximum number of threads
180 * omp_get_thread_num:: Current thread ID
181 * omp_in_parallel:: Whether a parallel region is active
182 * omp_in_final:: Whether in final or included task region
183 * omp_is_initial_device:: Whether executing on the host device
184 * omp_set_default_device:: Set the default device for target regions
185 * omp_set_dynamic:: Enable/disable dynamic teams
186 * omp_set_max_active_levels:: Limits the number of active parallel regions
187 * omp_set_nested:: Enable/disable nested parallel regions
188 * omp_set_num_threads:: Set upper team size limit
189 * omp_set_schedule:: Set the runtime scheduling method
191 Initialize, set, test, unset and destroy simple and nested locks.
193 * omp_init_lock:: Initialize simple lock
194 * omp_set_lock:: Wait for and set simple lock
195 * omp_test_lock:: Test and set simple lock if available
196 * omp_unset_lock:: Unset simple lock
197 * omp_destroy_lock:: Destroy simple lock
198 * omp_init_nest_lock:: Initialize nested lock
199 * omp_set_nest_lock:: Wait for and set simple lock
200 * omp_test_nest_lock:: Test and set nested lock if available
201 * omp_unset_nest_lock:: Unset nested lock
202 * omp_destroy_nest_lock:: Destroy nested lock
204 Portable, thread-based, wall clock timer.
206 * omp_get_wtick:: Get timer precision.
207 * omp_get_wtime:: Elapsed wall clock time.
212 @node omp_get_active_level
213 @section @code{omp_get_active_level} -- Number of parallel regions
215 @item @emph{Description}:
216 This function returns the nesting level for the active parallel blocks,
217 which enclose the calling call.
220 @multitable @columnfractions .20 .80
221 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
224 @item @emph{Fortran}:
225 @multitable @columnfractions .20 .80
226 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
229 @item @emph{See also}:
230 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
232 @item @emph{Reference}:
233 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
238 @node omp_get_ancestor_thread_num
239 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
241 @item @emph{Description}:
242 This function returns the thread identification number for the given
243 nesting level of the current thread. For values of @var{level} outside
244 zero to @code{omp_get_level} -1 is returned; if @var{level} is
245 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
248 @multitable @columnfractions .20 .80
249 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
252 @item @emph{Fortran}:
253 @multitable @columnfractions .20 .80
254 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
255 @item @tab @code{integer level}
258 @item @emph{See also}:
259 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
261 @item @emph{Reference}:
262 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
267 @node omp_get_cancellation
268 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
270 @item @emph{Description}:
271 This function returns @code{true} if cancellation is activated, @code{false}
272 otherwise. Here, @code{true} and @code{false} represent their language-specific
273 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
277 @multitable @columnfractions .20 .80
278 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
281 @item @emph{Fortran}:
282 @multitable @columnfractions .20 .80
283 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
286 @item @emph{See also}:
287 @ref{OMP_CANCELLATION}
289 @item @emph{Reference}:
290 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
295 @node omp_get_default_device
296 @section @code{omp_get_default_device} -- Get the default device for target regions
298 @item @emph{Description}:
299 Get the default device for target regions without device clause.
302 @multitable @columnfractions .20 .80
303 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
306 @item @emph{Fortran}:
307 @multitable @columnfractions .20 .80
308 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
311 @item @emph{See also}:
312 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
314 @item @emph{Reference}:
315 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
320 @node omp_get_dynamic
321 @section @code{omp_get_dynamic} -- Dynamic teams setting
323 @item @emph{Description}:
324 This function returns @code{true} if enabled, @code{false} otherwise.
325 Here, @code{true} and @code{false} represent their language-specific
328 The dynamic team setting may be initialized at startup by the
329 @env{OMP_DYNAMIC} environment variable or at runtime using
330 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
334 @multitable @columnfractions .20 .80
335 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
338 @item @emph{Fortran}:
339 @multitable @columnfractions .20 .80
340 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
343 @item @emph{See also}:
344 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
346 @item @emph{Reference}:
347 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
353 @section @code{omp_get_level} -- Obtain the current nesting level
355 @item @emph{Description}:
356 This function returns the nesting level for the parallel blocks,
357 which enclose the calling call.
360 @multitable @columnfractions .20 .80
361 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
364 @item @emph{Fortran}:
365 @multitable @columnfractions .20 .80
366 @item @emph{Interface}: @tab @code{integer function omp_level()}
369 @item @emph{See also}:
370 @ref{omp_get_active_level}
372 @item @emph{Reference}:
373 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
378 @node omp_get_max_active_levels
379 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
381 @item @emph{Description}:
382 This function obtains the maximum allowed number of nested, active parallel regions.
385 @multitable @columnfractions .20 .80
386 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
389 @item @emph{Fortran}:
390 @multitable @columnfractions .20 .80
391 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
394 @item @emph{See also}:
395 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
397 @item @emph{Reference}:
398 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
402 @node omp_get_max_task_priority
403 @section @code{omp_get_max_task_priority} -- Maximum priority value
404 that can be set for tasks.
406 @item @emph{Description}:
407 This function obtains the maximum allowed priority number for tasks.
410 @multitable @columnfractions .20 .80
411 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
414 @item @emph{Fortran}:
415 @multitable @columnfractions .20 .80
416 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
419 @item @emph{Reference}:
420 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
424 @node omp_get_max_threads
425 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
427 @item @emph{Description}:
428 Return the maximum number of threads used for the current parallel region
429 that does not use the clause @code{num_threads}.
432 @multitable @columnfractions .20 .80
433 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
436 @item @emph{Fortran}:
437 @multitable @columnfractions .20 .80
438 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
441 @item @emph{See also}:
442 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
444 @item @emph{Reference}:
445 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
451 @section @code{omp_get_nested} -- Nested parallel regions
453 @item @emph{Description}:
454 This function returns @code{true} if nested parallel regions are
455 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
456 represent their language-specific counterparts.
458 Nested parallel regions may be initialized at startup by the
459 @env{OMP_NESTED} environment variable or at runtime using
460 @code{omp_set_nested}. If undefined, nested parallel regions are
464 @multitable @columnfractions .20 .80
465 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
468 @item @emph{Fortran}:
469 @multitable @columnfractions .20 .80
470 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
473 @item @emph{See also}:
474 @ref{omp_set_nested}, @ref{OMP_NESTED}
476 @item @emph{Reference}:
477 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
482 @node omp_get_num_devices
483 @section @code{omp_get_num_devices} -- Number of target devices
485 @item @emph{Description}:
486 Returns the number of target devices.
489 @multitable @columnfractions .20 .80
490 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
493 @item @emph{Fortran}:
494 @multitable @columnfractions .20 .80
495 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
498 @item @emph{Reference}:
499 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
504 @node omp_get_num_procs
505 @section @code{omp_get_num_procs} -- Number of processors online
507 @item @emph{Description}:
508 Returns the number of processors online on that device.
511 @multitable @columnfractions .20 .80
512 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
515 @item @emph{Fortran}:
516 @multitable @columnfractions .20 .80
517 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
520 @item @emph{Reference}:
521 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
526 @node omp_get_num_teams
527 @section @code{omp_get_num_teams} -- Number of teams
529 @item @emph{Description}:
530 Returns the number of teams in the current team region.
533 @multitable @columnfractions .20 .80
534 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
537 @item @emph{Fortran}:
538 @multitable @columnfractions .20 .80
539 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
542 @item @emph{Reference}:
543 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
548 @node omp_get_num_threads
549 @section @code{omp_get_num_threads} -- Size of the active team
551 @item @emph{Description}:
552 Returns the number of threads in the current team. In a sequential section of
553 the program @code{omp_get_num_threads} returns 1.
555 The default team size may be initialized at startup by the
556 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
557 of the current team may be set either by the @code{NUM_THREADS}
558 clause or by @code{omp_set_num_threads}. If none of the above were
559 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
560 one thread per CPU online is used.
563 @multitable @columnfractions .20 .80
564 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
567 @item @emph{Fortran}:
568 @multitable @columnfractions .20 .80
569 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
572 @item @emph{See also}:
573 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
575 @item @emph{Reference}:
576 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
581 @node omp_get_proc_bind
582 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
584 @item @emph{Description}:
585 This functions returns the currently active thread affinity policy, which is
586 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
587 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
588 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
591 @multitable @columnfractions .20 .80
592 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
595 @item @emph{Fortran}:
596 @multitable @columnfractions .20 .80
597 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
600 @item @emph{See also}:
601 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
603 @item @emph{Reference}:
604 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
609 @node omp_get_schedule
610 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
612 @item @emph{Description}:
613 Obtain the runtime scheduling method. The @var{kind} argument will be
614 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
615 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
616 @var{chunk_size}, is set to the chunk size.
619 @multitable @columnfractions .20 .80
620 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
623 @item @emph{Fortran}:
624 @multitable @columnfractions .20 .80
625 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
626 @item @tab @code{integer(kind=omp_sched_kind) kind}
627 @item @tab @code{integer chunk_size}
630 @item @emph{See also}:
631 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
633 @item @emph{Reference}:
634 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
639 @node omp_get_team_num
640 @section @code{omp_get_team_num} -- Get team number
642 @item @emph{Description}:
643 Returns the team number of the calling thread.
646 @multitable @columnfractions .20 .80
647 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
650 @item @emph{Fortran}:
651 @multitable @columnfractions .20 .80
652 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
655 @item @emph{Reference}:
656 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
661 @node omp_get_team_size
662 @section @code{omp_get_team_size} -- Number of threads in a team
664 @item @emph{Description}:
665 This function returns the number of threads in a thread team to which
666 either the current thread or its ancestor belongs. For values of @var{level}
667 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
668 1 is returned, and for @code{omp_get_level}, the result is identical
669 to @code{omp_get_num_threads}.
672 @multitable @columnfractions .20 .80
673 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
676 @item @emph{Fortran}:
677 @multitable @columnfractions .20 .80
678 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
679 @item @tab @code{integer level}
682 @item @emph{See also}:
683 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
685 @item @emph{Reference}:
686 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
691 @node omp_get_thread_limit
692 @section @code{omp_get_thread_limit} -- Maximum number of threads
694 @item @emph{Description}:
695 Return the maximum number of threads of the program.
698 @multitable @columnfractions .20 .80
699 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
702 @item @emph{Fortran}:
703 @multitable @columnfractions .20 .80
704 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
707 @item @emph{See also}:
708 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
710 @item @emph{Reference}:
711 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
716 @node omp_get_thread_num
717 @section @code{omp_get_thread_num} -- Current thread ID
719 @item @emph{Description}:
720 Returns a unique thread identification number within the current team.
721 In a sequential parts of the program, @code{omp_get_thread_num}
722 always returns 0. In parallel regions the return value varies
723 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
724 value of the master thread of a team is always 0.
727 @multitable @columnfractions .20 .80
728 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
731 @item @emph{Fortran}:
732 @multitable @columnfractions .20 .80
733 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
736 @item @emph{See also}:
737 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
739 @item @emph{Reference}:
740 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
745 @node omp_in_parallel
746 @section @code{omp_in_parallel} -- Whether a parallel region is active
748 @item @emph{Description}:
749 This function returns @code{true} if currently running in parallel,
750 @code{false} otherwise. Here, @code{true} and @code{false} represent
751 their language-specific counterparts.
754 @multitable @columnfractions .20 .80
755 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
758 @item @emph{Fortran}:
759 @multitable @columnfractions .20 .80
760 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
763 @item @emph{Reference}:
764 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
769 @section @code{omp_in_final} -- Whether in final or included task region
771 @item @emph{Description}:
772 This function returns @code{true} if currently running in a final
773 or included task region, @code{false} otherwise. Here, @code{true}
774 and @code{false} represent their language-specific counterparts.
777 @multitable @columnfractions .20 .80
778 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
781 @item @emph{Fortran}:
782 @multitable @columnfractions .20 .80
783 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
786 @item @emph{Reference}:
787 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
792 @node omp_is_initial_device
793 @section @code{omp_is_initial_device} -- Whether executing on the host device
795 @item @emph{Description}:
796 This function returns @code{true} if currently running on the host device,
797 @code{false} otherwise. Here, @code{true} and @code{false} represent
798 their language-specific counterparts.
801 @multitable @columnfractions .20 .80
802 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
805 @item @emph{Fortran}:
806 @multitable @columnfractions .20 .80
807 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
810 @item @emph{Reference}:
811 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
816 @node omp_set_default_device
817 @section @code{omp_set_default_device} -- Set the default device for target regions
819 @item @emph{Description}:
820 Set the default device for target regions without device clause. The argument
821 shall be a nonnegative device number.
824 @multitable @columnfractions .20 .80
825 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
828 @item @emph{Fortran}:
829 @multitable @columnfractions .20 .80
830 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
831 @item @tab @code{integer device_num}
834 @item @emph{See also}:
835 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
837 @item @emph{Reference}:
838 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
843 @node omp_set_dynamic
844 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
846 @item @emph{Description}:
847 Enable or disable the dynamic adjustment of the number of threads
848 within a team. The function takes the language-specific equivalent
849 of @code{true} and @code{false}, where @code{true} enables dynamic
850 adjustment of team sizes and @code{false} disables it.
853 @multitable @columnfractions .20 .80
854 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
857 @item @emph{Fortran}:
858 @multitable @columnfractions .20 .80
859 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
860 @item @tab @code{logical, intent(in) :: dynamic_threads}
863 @item @emph{See also}:
864 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
866 @item @emph{Reference}:
867 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
872 @node omp_set_max_active_levels
873 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
875 @item @emph{Description}:
876 This function limits the maximum allowed number of nested, active
880 @multitable @columnfractions .20 .80
881 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
884 @item @emph{Fortran}:
885 @multitable @columnfractions .20 .80
886 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
887 @item @tab @code{integer max_levels}
890 @item @emph{See also}:
891 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
893 @item @emph{Reference}:
894 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
900 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
902 @item @emph{Description}:
903 Enable or disable nested parallel regions, i.e., whether team members
904 are allowed to create new teams. The function takes the language-specific
905 equivalent of @code{true} and @code{false}, where @code{true} enables
906 dynamic adjustment of team sizes and @code{false} disables it.
909 @multitable @columnfractions .20 .80
910 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
913 @item @emph{Fortran}:
914 @multitable @columnfractions .20 .80
915 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
916 @item @tab @code{logical, intent(in) :: nested}
919 @item @emph{See also}:
920 @ref{OMP_NESTED}, @ref{omp_get_nested}
922 @item @emph{Reference}:
923 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
928 @node omp_set_num_threads
929 @section @code{omp_set_num_threads} -- Set upper team size limit
931 @item @emph{Description}:
932 Specifies the number of threads used by default in subsequent parallel
933 sections, if those do not specify a @code{num_threads} clause. The
934 argument of @code{omp_set_num_threads} shall be a positive integer.
937 @multitable @columnfractions .20 .80
938 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
941 @item @emph{Fortran}:
942 @multitable @columnfractions .20 .80
943 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
944 @item @tab @code{integer, intent(in) :: num_threads}
947 @item @emph{See also}:
948 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
950 @item @emph{Reference}:
951 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
956 @node omp_set_schedule
957 @section @code{omp_set_schedule} -- Set the runtime scheduling method
959 @item @emph{Description}:
960 Sets the runtime scheduling method. The @var{kind} argument can have the
961 value @code{omp_sched_static}, @code{omp_sched_dynamic},
962 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
963 @code{omp_sched_auto}, the chunk size is set to the value of
964 @var{chunk_size} if positive, or to the default value if zero or negative.
965 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
968 @multitable @columnfractions .20 .80
969 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
972 @item @emph{Fortran}:
973 @multitable @columnfractions .20 .80
974 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
975 @item @tab @code{integer(kind=omp_sched_kind) kind}
976 @item @tab @code{integer chunk_size}
979 @item @emph{See also}:
980 @ref{omp_get_schedule}
983 @item @emph{Reference}:
984 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
990 @section @code{omp_init_lock} -- Initialize simple lock
992 @item @emph{Description}:
993 Initialize a simple lock. After initialization, the lock is in
997 @multitable @columnfractions .20 .80
998 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1001 @item @emph{Fortran}:
1002 @multitable @columnfractions .20 .80
1003 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1004 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1007 @item @emph{See also}:
1008 @ref{omp_destroy_lock}
1010 @item @emph{Reference}:
1011 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1017 @section @code{omp_set_lock} -- Wait for and set simple lock
1019 @item @emph{Description}:
1020 Before setting a simple lock, the lock variable must be initialized by
1021 @code{omp_init_lock}. The calling thread is blocked until the lock
1022 is available. If the lock is already held by the current thread,
1026 @multitable @columnfractions .20 .80
1027 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1030 @item @emph{Fortran}:
1031 @multitable @columnfractions .20 .80
1032 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1033 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1036 @item @emph{See also}:
1037 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1039 @item @emph{Reference}:
1040 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1046 @section @code{omp_test_lock} -- Test and set simple lock if available
1048 @item @emph{Description}:
1049 Before setting a simple lock, the lock variable must be initialized by
1050 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1051 does not block if the lock is not available. This function returns
1052 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1053 @code{false} represent their language-specific counterparts.
1056 @multitable @columnfractions .20 .80
1057 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1060 @item @emph{Fortran}:
1061 @multitable @columnfractions .20 .80
1062 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1063 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1066 @item @emph{See also}:
1067 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1069 @item @emph{Reference}:
1070 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1075 @node omp_unset_lock
1076 @section @code{omp_unset_lock} -- Unset simple lock
1078 @item @emph{Description}:
1079 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1080 or @code{omp_test_lock} before. In addition, the lock must be held by the
1081 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1082 or more threads attempted to set the lock before, one of them is chosen to,
1083 again, set the lock to itself.
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1090 @item @emph{Fortran}:
1091 @multitable @columnfractions .20 .80
1092 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1093 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1096 @item @emph{See also}:
1097 @ref{omp_set_lock}, @ref{omp_test_lock}
1099 @item @emph{Reference}:
1100 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1105 @node omp_destroy_lock
1106 @section @code{omp_destroy_lock} -- Destroy simple lock
1108 @item @emph{Description}:
1109 Destroy a simple lock. In order to be destroyed, a simple lock must be
1110 in the unlocked state.
1113 @multitable @columnfractions .20 .80
1114 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1117 @item @emph{Fortran}:
1118 @multitable @columnfractions .20 .80
1119 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1120 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1123 @item @emph{See also}:
1126 @item @emph{Reference}:
1127 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1132 @node omp_init_nest_lock
1133 @section @code{omp_init_nest_lock} -- Initialize nested lock
1135 @item @emph{Description}:
1136 Initialize a nested lock. After initialization, the lock is in
1137 an unlocked state and the nesting count is set to zero.
1140 @multitable @columnfractions .20 .80
1141 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1144 @item @emph{Fortran}:
1145 @multitable @columnfractions .20 .80
1146 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1147 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1150 @item @emph{See also}:
1151 @ref{omp_destroy_nest_lock}
1153 @item @emph{Reference}:
1154 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1158 @node omp_set_nest_lock
1159 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1161 @item @emph{Description}:
1162 Before setting a nested lock, the lock variable must be initialized by
1163 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1164 is available. If the lock is already held by the current thread, the
1165 nesting count for the lock is incremented.
1168 @multitable @columnfractions .20 .80
1169 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1172 @item @emph{Fortran}:
1173 @multitable @columnfractions .20 .80
1174 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1175 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1178 @item @emph{See also}:
1179 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1181 @item @emph{Reference}:
1182 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1187 @node omp_test_nest_lock
1188 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1190 @item @emph{Description}:
1191 Before setting a nested lock, the lock variable must be initialized by
1192 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1193 @code{omp_test_nest_lock} does not block if the lock is not available.
1194 If the lock is already held by the current thread, the new nesting count
1195 is returned. Otherwise, the return value equals zero.
1198 @multitable @columnfractions .20 .80
1199 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1202 @item @emph{Fortran}:
1203 @multitable @columnfractions .20 .80
1204 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1205 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1209 @item @emph{See also}:
1210 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1212 @item @emph{Reference}:
1213 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1218 @node omp_unset_nest_lock
1219 @section @code{omp_unset_nest_lock} -- Unset nested lock
1221 @item @emph{Description}:
1222 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1223 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1224 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1225 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1226 one of them is chosen to, again, set the lock to itself.
1229 @multitable @columnfractions .20 .80
1230 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1233 @item @emph{Fortran}:
1234 @multitable @columnfractions .20 .80
1235 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1236 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1239 @item @emph{See also}:
1240 @ref{omp_set_nest_lock}
1242 @item @emph{Reference}:
1243 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1248 @node omp_destroy_nest_lock
1249 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1251 @item @emph{Description}:
1252 Destroy a nested lock. In order to be destroyed, a nested lock must be
1253 in the unlocked state and its nesting count must equal zero.
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1260 @item @emph{Fortran}:
1261 @multitable @columnfractions .20 .80
1262 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1263 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1266 @item @emph{See also}:
1269 @item @emph{Reference}:
1270 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1276 @section @code{omp_get_wtick} -- Get timer precision
1278 @item @emph{Description}:
1279 Gets the timer precision, i.e., the number of seconds between two
1280 successive clock ticks.
1283 @multitable @columnfractions .20 .80
1284 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1287 @item @emph{Fortran}:
1288 @multitable @columnfractions .20 .80
1289 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1292 @item @emph{See also}:
1295 @item @emph{Reference}:
1296 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
1302 @section @code{omp_get_wtime} -- Elapsed wall clock time
1304 @item @emph{Description}:
1305 Elapsed wall clock time in seconds. The time is measured per thread, no
1306 guarantee can be made that two distinct threads measure the same time.
1307 Time is measured from some "time in the past", which is an arbitrary time
1308 guaranteed not to change during the execution of the program.
1311 @multitable @columnfractions .20 .80
1312 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1315 @item @emph{Fortran}:
1316 @multitable @columnfractions .20 .80
1317 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1320 @item @emph{See also}:
1323 @item @emph{Reference}:
1324 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
1329 @c ---------------------------------------------------------------------
1330 @c Environment Variables
1331 @c ---------------------------------------------------------------------
1333 @node Environment Variables
1334 @chapter Environment Variables
1336 The environment variables which beginning with @env{OMP_} are defined by
1337 section 4 of the OpenMP specification in version 4.5, while those
1338 beginning with @env{GOMP_} are GNU extensions.
1341 * OMP_CANCELLATION:: Set whether cancellation is activated
1342 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1343 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1344 * OMP_DYNAMIC:: Dynamic adjustment of threads
1345 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1346 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
1347 * OMP_NESTED:: Nested parallel regions
1348 * OMP_NUM_THREADS:: Specifies the number of threads to use
1349 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1350 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1351 * OMP_STACKSIZE:: Set default thread stack size
1352 * OMP_SCHEDULE:: How threads are scheduled
1353 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1354 * OMP_WAIT_POLICY:: How waiting threads are handled
1355 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1356 * GOMP_DEBUG:: Enable debugging output
1357 * GOMP_STACKSIZE:: Set default thread stack size
1358 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1359 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1363 @node OMP_CANCELLATION
1364 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1365 @cindex Environment Variable
1367 @item @emph{Description}:
1368 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1369 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1371 @item @emph{See also}:
1372 @ref{omp_get_cancellation}
1374 @item @emph{Reference}:
1375 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
1380 @node OMP_DISPLAY_ENV
1381 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1382 @cindex Environment Variable
1384 @item @emph{Description}:
1385 If set to @code{TRUE}, the OpenMP version number and the values
1386 associated with the OpenMP environment variables are printed to @code{stderr}.
1387 If set to @code{VERBOSE}, it additionally shows the value of the environment
1388 variables which are GNU extensions. If undefined or set to @code{FALSE},
1389 this information will not be shown.
1392 @item @emph{Reference}:
1393 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
1398 @node OMP_DEFAULT_DEVICE
1399 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1400 @cindex Environment Variable
1402 @item @emph{Description}:
1403 Set to choose the device which is used in a @code{target} region, unless the
1404 value is overridden by @code{omp_set_default_device} or by a @code{device}
1405 clause. The value shall be the nonnegative device number. If no device with
1406 the given device number exists, the code is executed on the host. If unset,
1407 device number 0 will be used.
1410 @item @emph{See also}:
1411 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1413 @item @emph{Reference}:
1414 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
1420 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1421 @cindex Environment Variable
1423 @item @emph{Description}:
1424 Enable or disable the dynamic adjustment of the number of threads
1425 within a team. The value of this environment variable shall be
1426 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1427 disabled by default.
1429 @item @emph{See also}:
1430 @ref{omp_set_dynamic}
1432 @item @emph{Reference}:
1433 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
1438 @node OMP_MAX_ACTIVE_LEVELS
1439 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1440 @cindex Environment Variable
1442 @item @emph{Description}:
1443 Specifies the initial value for the maximum number of nested parallel
1444 regions. The value of this variable shall be a positive integer.
1445 If undefined, the number of active levels is unlimited.
1447 @item @emph{See also}:
1448 @ref{omp_set_max_active_levels}
1450 @item @emph{Reference}:
1451 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
1456 @node OMP_MAX_TASK_PRIORITY
1457 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1458 number that can be set for a task.
1459 @cindex Environment Variable
1461 @item @emph{Description}:
1462 Specifies the initial value for the maximum priority value that can be
1463 set for a task. The value of this variable shall be a non-negative
1464 integer, and zero is allowed. If undefined, the default priority is
1467 @item @emph{See also}:
1468 @ref{omp_get_max_task_priority}
1470 @item @emph{Reference}:
1471 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
1477 @section @env{OMP_NESTED} -- Nested parallel regions
1478 @cindex Environment Variable
1479 @cindex Implementation specific setting
1481 @item @emph{Description}:
1482 Enable or disable nested parallel regions, i.e., whether team members
1483 are allowed to create new teams. The value of this environment variable
1484 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
1485 regions are disabled by default.
1487 @item @emph{See also}:
1488 @ref{omp_set_nested}
1490 @item @emph{Reference}:
1491 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
1496 @node OMP_NUM_THREADS
1497 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1498 @cindex Environment Variable
1499 @cindex Implementation specific setting
1501 @item @emph{Description}:
1502 Specifies the default number of threads to use in parallel regions. The
1503 value of this variable shall be a comma-separated list of positive integers;
1504 the value specified the number of threads to use for the corresponding nested
1505 level. If undefined one thread per CPU is used.
1507 @item @emph{See also}:
1508 @ref{omp_set_num_threads}
1510 @item @emph{Reference}:
1511 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
1517 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1518 @cindex Environment Variable
1520 @item @emph{Description}:
1521 Specifies whether threads may be moved between processors. If set to
1522 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1523 they may be moved. Alternatively, a comma separated list with the
1524 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1525 the thread affinity policy for the corresponding nesting level. With
1526 @code{MASTER} the worker threads are in the same place partition as the
1527 master thread. With @code{CLOSE} those are kept close to the master thread
1528 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
1529 across the place partitions is used.
1531 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1532 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1534 @item @emph{See also}:
1535 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1537 @item @emph{Reference}:
1538 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
1544 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1545 @cindex Environment Variable
1547 @item @emph{Description}:
1548 The thread placement can be either specified using an abstract name or by an
1549 explicit list of the places. The abstract names @code{threads}, @code{cores}
1550 and @code{sockets} can be optionally followed by a positive number in
1551 parentheses, which denotes the how many places shall be created. With
1552 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1553 to a single core with the corresponding number of hardware threads; and with
1554 @code{sockets} the place corresponds to a single socket. The resulting
1555 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1558 Alternatively, the placement can be specified explicitly as comma-separated
1559 list of places. A place is specified by set of nonnegative numbers in curly
1560 braces, denoting the denoting the hardware threads. The hardware threads
1561 belonging to a place can either be specified as comma-separated list of
1562 nonnegative thread numbers or using an interval. Multiple places can also be
1563 either specified by a comma-separated list of places or by an interval. To
1564 specify an interval, a colon followed by the count is placed after after
1565 the hardware thread number or the place. Optionally, the length can be
1566 followed by a colon and the stride number -- otherwise a unit stride is
1567 assumed. For instance, the following specifies the same places list:
1568 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1569 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1571 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1572 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1573 between CPUs following no placement policy.
1575 @item @emph{See also}:
1576 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1577 @ref{OMP_DISPLAY_ENV}
1579 @item @emph{Reference}:
1580 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
1586 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1587 @cindex Environment Variable
1589 @item @emph{Description}:
1590 Set the default thread stack size in kilobytes, unless the number
1591 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1592 case the size is, respectively, in bytes, kilobytes, megabytes
1593 or gigabytes. This is different from @code{pthread_attr_setstacksize}
1594 which gets the number of bytes as an argument. If the stack size cannot
1595 be set due to system constraints, an error is reported and the initial
1596 stack size is left unchanged. If undefined, the stack size is system
1599 @item @emph{Reference}:
1600 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
1606 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1607 @cindex Environment Variable
1608 @cindex Implementation specific setting
1610 @item @emph{Description}:
1611 Allows to specify @code{schedule type} and @code{chunk size}.
1612 The value of the variable shall have the form: @code{type[,chunk]} where
1613 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1614 The optional @code{chunk} size shall be a positive integer. If undefined,
1615 dynamic scheduling and a chunk size of 1 is used.
1617 @item @emph{See also}:
1618 @ref{omp_set_schedule}
1620 @item @emph{Reference}:
1621 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
1626 @node OMP_THREAD_LIMIT
1627 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1628 @cindex Environment Variable
1630 @item @emph{Description}:
1631 Specifies the number of threads to use for the whole program. The
1632 value of this variable shall be a positive integer. If undefined,
1633 the number of threads is not limited.
1635 @item @emph{See also}:
1636 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1638 @item @emph{Reference}:
1639 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
1644 @node OMP_WAIT_POLICY
1645 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1646 @cindex Environment Variable
1648 @item @emph{Description}:
1649 Specifies whether waiting threads should be active or passive. If
1650 the value is @code{PASSIVE}, waiting threads should not consume CPU
1651 power while waiting; while the value is @code{ACTIVE} specifies that
1652 they should. If undefined, threads wait actively for a short time
1653 before waiting passively.
1655 @item @emph{See also}:
1656 @ref{GOMP_SPINCOUNT}
1658 @item @emph{Reference}:
1659 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
1664 @node GOMP_CPU_AFFINITY
1665 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1666 @cindex Environment Variable
1668 @item @emph{Description}:
1669 Binds threads to specific CPUs. The variable should contain a space-separated
1670 or comma-separated list of CPUs. This list may contain different kinds of
1671 entries: either single CPU numbers in any order, a range of CPUs (M-N)
1672 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
1673 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1674 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1675 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1676 and 14 respectively and then start assigning back from the beginning of
1677 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1679 There is no libgomp library routine to determine whether a CPU affinity
1680 specification is in effect. As a workaround, language-specific library
1681 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1682 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1683 environment variable. A defined CPU affinity on startup cannot be changed
1684 or disabled during the runtime of the application.
1686 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1687 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
1688 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1689 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1691 @item @emph{See also}:
1692 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1698 @section @env{GOMP_DEBUG} -- Enable debugging output
1699 @cindex Environment Variable
1701 @item @emph{Description}:
1702 Enable debugging output. The variable should be set to @code{0}
1703 (disabled, also the default if not set), or @code{1} (enabled).
1705 If enabled, some debugging output will be printed during execution.
1706 This is currently not specified in more detail, and subject to change.
1711 @node GOMP_STACKSIZE
1712 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1713 @cindex Environment Variable
1714 @cindex Implementation specific setting
1716 @item @emph{Description}:
1717 Set the default thread stack size in kilobytes. This is different from
1718 @code{pthread_attr_setstacksize} which gets the number of bytes as an
1719 argument. If the stack size cannot be set due to system constraints, an
1720 error is reported and the initial stack size is left unchanged. If undefined,
1721 the stack size is system dependent.
1723 @item @emph{See also}:
1726 @item @emph{Reference}:
1727 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1728 GCC Patches Mailinglist},
1729 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1730 GCC Patches Mailinglist}
1735 @node GOMP_SPINCOUNT
1736 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1737 @cindex Environment Variable
1738 @cindex Implementation specific setting
1740 @item @emph{Description}:
1741 Determines how long a threads waits actively with consuming CPU power
1742 before waiting passively without consuming CPU power. The value may be
1743 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1744 integer which gives the number of spins of the busy-wait loop. The
1745 integer may optionally be followed by the following suffixes acting
1746 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1747 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1748 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1749 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1750 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1751 If there are more OpenMP threads than available CPUs, 1000 and 100
1752 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1753 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1754 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1756 @item @emph{See also}:
1757 @ref{OMP_WAIT_POLICY}
1762 @node GOMP_RTEMS_THREAD_POOLS
1763 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
1764 @cindex Environment Variable
1765 @cindex Implementation specific setting
1767 @item @emph{Description}:
1768 This environment variable is only used on the RTEMS real-time operating system.
1769 It determines the scheduler instance specific thread pools. The format for
1770 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
1771 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
1772 separated by @code{:} where:
1774 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
1776 @item @code{$<priority>} is an optional priority for the worker threads of a
1777 thread pool according to @code{pthread_setschedparam}. In case a priority
1778 value is omitted, then a worker thread will inherit the priority of the OpenMP
1779 master thread that created it. The priority of the worker thread is not
1780 changed after creation, even if a new OpenMP master thread using the worker has
1781 a different priority.
1782 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
1783 RTEMS application configuration.
1785 In case no thread pool configuration is specified for a scheduler instance,
1786 then each OpenMP master thread of this scheduler instance will use its own
1787 dynamically allocated thread pool. To limit the worker thread count of the
1788 thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1789 @item @emph{Example}:
1790 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
1791 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
1792 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
1793 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
1794 one thread pool available. Since no priority is specified for this scheduler
1795 instance, the worker thread inherits the priority of the OpenMP master thread
1796 that created it. In the scheduler instance @code{WRK1} there are three thread
1797 pools available and their worker threads run at priority four.
1802 @c ---------------------------------------------------------------------
1804 @c ---------------------------------------------------------------------
1806 @node Enabling OpenACC
1807 @chapter Enabling OpenACC
1809 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
1810 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
1811 @code{#pragma acc} in C/C++ and @code{!$accp} directives in free form,
1812 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
1813 @code{!$} conditional compilation sentinels in free form and @code{c$},
1814 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
1815 arranges for automatic linking of the OpenACC runtime library
1816 (@ref{OpenACC Runtime Library Routines}).
1818 A complete description of all OpenACC directives accepted may be found in
1819 the @uref{https://www.openacc.org, OpenACC} Application Programming
1820 Interface manual, version 2.0.
1822 Note that this is an experimental feature and subject to
1823 change in future versions of GCC. See
1824 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
1828 @c ---------------------------------------------------------------------
1829 @c OpenACC Runtime Library Routines
1830 @c ---------------------------------------------------------------------
1832 @node OpenACC Runtime Library Routines
1833 @chapter OpenACC Runtime Library Routines
1835 The runtime routines described here are defined by section 3 of the OpenACC
1836 specifications in version 2.0.
1837 They have C linkage, and do not throw exceptions.
1838 Generally, they are available only for the host, with the exception of
1839 @code{acc_on_device}, which is available for both the host and the
1840 acceleration device.
1843 * acc_get_num_devices:: Get number of devices for the given device
1845 * acc_set_device_type:: Set type of device accelerator to use.
1846 * acc_get_device_type:: Get type of device accelerator to be used.
1847 * acc_set_device_num:: Set device number to use.
1848 * acc_get_device_num:: Get device number to be used.
1849 * acc_async_test:: Tests for completion of a specific asynchronous
1851 * acc_async_test_all:: Tests for completion of all asychronous
1853 * acc_wait:: Wait for completion of a specific asynchronous
1855 * acc_wait_all:: Waits for completion of all asyncrhonous
1857 * acc_wait_all_async:: Wait for completion of all asynchronous
1859 * acc_wait_async:: Wait for completion of asynchronous operations.
1860 * acc_init:: Initialize runtime for a specific device type.
1861 * acc_shutdown:: Shuts down the runtime for a specific device
1863 * acc_on_device:: Whether executing on a particular device
1864 * acc_malloc:: Allocate device memory.
1865 * acc_free:: Free device memory.
1866 * acc_copyin:: Allocate device memory and copy host memory to
1868 * acc_present_or_copyin:: If the data is not present on the device,
1869 allocate device memory and copy from host
1871 * acc_create:: Allocate device memory and map it to host
1873 * acc_present_or_create:: If the data is not present on the device,
1874 allocate device memory and map it to host
1876 * acc_copyout:: Copy device memory to host memory.
1877 * acc_delete:: Free device memory.
1878 * acc_update_device:: Update device memory from mapped host memory.
1879 * acc_update_self:: Update host memory from mapped device memory.
1880 * acc_map_data:: Map previously allocated device memory to host
1882 * acc_unmap_data:: Unmap device memory from host memory.
1883 * acc_deviceptr:: Get device pointer associated with specific
1885 * acc_hostptr:: Get host pointer associated with specific
1887 * acc_is_present:: Indiciate whether host variable / array is
1889 * acc_memcpy_to_device:: Copy host memory to device memory.
1890 * acc_memcpy_from_device:: Copy device memory to host memory.
1892 API routines for target platforms.
1894 * acc_get_current_cuda_device:: Get CUDA device handle.
1895 * acc_get_current_cuda_context::Get CUDA context handle.
1896 * acc_get_cuda_stream:: Get CUDA stream handle.
1897 * acc_set_cuda_stream:: Set CUDA stream handle.
1902 @node acc_get_num_devices
1903 @section @code{acc_get_num_devices} -- Get number of devices for given device type
1905 @item @emph{Description}
1906 This function returns a value indicating the number of devices available
1907 for the device type specified in @var{devicetype}.
1910 @multitable @columnfractions .20 .80
1911 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
1914 @item @emph{Fortran}:
1915 @multitable @columnfractions .20 .80
1916 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
1917 @item @tab @code{integer(kind=acc_device_kind) devicetype}
1920 @item @emph{Reference}:
1921 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1927 @node acc_set_device_type
1928 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
1930 @item @emph{Description}
1931 This function indicates to the runtime library which device typr, specified
1932 in @var{devicetype}, to use when executing a parallel or kernels region.
1935 @multitable @columnfractions .20 .80
1936 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
1939 @item @emph{Fortran}:
1940 @multitable @columnfractions .20 .80
1941 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
1942 @item @tab @code{integer(kind=acc_device_kind) devicetype}
1945 @item @emph{Reference}:
1946 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1952 @node acc_get_device_type
1953 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
1955 @item @emph{Description}
1956 This function returns what device type will be used when executing a
1957 parallel or kernels region.
1960 @multitable @columnfractions .20 .80
1961 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
1964 @item @emph{Fortran}:
1965 @multitable @columnfractions .20 .80
1966 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
1967 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
1970 @item @emph{Reference}:
1971 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1977 @node acc_set_device_num
1978 @section @code{acc_set_device_num} -- Set device number to use.
1980 @item @emph{Description}
1981 This function will indicate to the runtime which device number,
1982 specified by @var{num}, associated with the specifed device
1983 type @var{devicetype}.
1986 @multitable @columnfractions .20 .80
1987 @item @emph{Prototype}: @tab @code{acc_set_device_num(int num, acc_device_t devicetype);}
1990 @item @emph{Fortran}:
1991 @multitable @columnfractions .20 .80
1992 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
1993 @item @tab @code{integer devicenum}
1994 @item @tab @code{integer(kind=acc_device_kind) devicetype}
1997 @item @emph{Reference}:
1998 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2004 @node acc_get_device_num
2005 @section @code{acc_get_device_num} -- Get device number to be used.
2007 @item @emph{Description}
2008 This function returns which device number associated with the specified device
2009 type @var{devicetype}, will be used when executing a parallel or kernels
2013 @multitable @columnfractions .20 .80
2014 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2017 @item @emph{Fortran}:
2018 @multitable @columnfractions .20 .80
2019 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2020 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2021 @item @tab @code{integer acc_get_device_num}
2024 @item @emph{Reference}:
2025 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2031 @node acc_async_test
2032 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
2034 @item @emph{Description}
2035 This function tests for completion of the asynchrounous operation specified
2036 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2037 the specified asynchronous operation has completed. While Fortran will return
2038 a @code{true}. If the asynchrounous operation has not completed, C/C++ returns
2039 a zero and Fortran returns a @code{false}.
2042 @multitable @columnfractions .20 .80
2043 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
2046 @item @emph{Fortran}:
2047 @multitable @columnfractions .20 .80
2048 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
2049 @item @tab @code{integer(kind=acc_handle_kind) arg}
2050 @item @tab @code{logical acc_async_test}
2053 @item @emph{Reference}:
2054 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2060 @node acc_async_test_all
2061 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
2063 @item @emph{Description}
2064 This function tests for completion of all asynchrounous operations.
2065 In C/C++, a non-zero value will be returned to indicate all asynchronous
2066 operations have completed. While Fortran will return a @code{true}. If
2067 any asynchronous operation has not completed, C/C++ returns a zero and
2068 Fortran returns a @code{false}.
2071 @multitable @columnfractions .20 .80
2072 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
2075 @item @emph{Fortran}:
2076 @multitable @columnfractions .20 .80
2077 @item @emph{Interface}: @tab @code{function acc_async_test()}
2078 @item @tab @code{logical acc_get_device_num}
2081 @item @emph{Reference}:
2082 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2089 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2091 @item @emph{Description}
2092 This function waits for completion of the asynchronous operation
2093 specified in @var{arg}.
2096 @multitable @columnfractions .20 .80
2097 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
2098 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
2101 @item @emph{Fortran}:
2102 @multitable @columnfractions .20 .80
2103 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
2104 @item @tab @code{integer(acc_handle_kind) arg}
2105 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
2106 @item @tab @code{integer(acc_handle_kind) arg}
2109 @item @emph{Reference}:
2110 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2117 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
2119 @item @emph{Description}
2120 This function waits for the completion of all asynchronous operations.
2123 @multitable @columnfractions .20 .80
2124 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
2125 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
2128 @item @emph{Fortran}:
2129 @multitable @columnfractions .20 .80
2130 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
2131 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
2134 @item @emph{Reference}:
2135 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2141 @node acc_wait_all_async
2142 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
2144 @item @emph{Description}
2145 This function enqueues a wait operation on the queue @var{async} for any
2146 and all asynchronous operations that have been previously enqueued on
2150 @multitable @columnfractions .20 .80
2151 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
2154 @item @emph{Fortran}:
2155 @multitable @columnfractions .20 .80
2156 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
2157 @item @tab @code{integer(acc_handle_kind) async}
2160 @item @emph{Reference}:
2161 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2167 @node acc_wait_async
2168 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2170 @item @emph{Description}
2171 This function enqueues a wait operation on queue @var{async} for any and all
2172 asynchronous operations enqueued on queue @var{arg}.
2175 @multitable @columnfractions .20 .80
2176 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
2179 @item @emph{Fortran}:
2180 @multitable @columnfractions .20 .80
2181 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
2182 @item @tab @code{integer(acc_handle_kind) arg, async}
2185 @item @emph{Reference}:
2186 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2193 @section @code{acc_init} -- Initialize runtime for a specific device type.
2195 @item @emph{Description}
2196 This function initializes the runtime for the device type specified in
2200 @multitable @columnfractions .20 .80
2201 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
2204 @item @emph{Fortran}:
2205 @multitable @columnfractions .20 .80
2206 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
2207 @item @tab @code{integer(acc_device_kind) devicetype}
2210 @item @emph{Reference}:
2211 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2218 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
2220 @item @emph{Description}
2221 This function shuts down the runtime for the device type specified in
2225 @multitable @columnfractions .20 .80
2226 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
2229 @item @emph{Fortran}:
2230 @multitable @columnfractions .20 .80
2231 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
2232 @item @tab @code{integer(acc_device_kind) devicetype}
2235 @item @emph{Reference}:
2236 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2243 @section @code{acc_on_device} -- Whether executing on a particular device
2245 @item @emph{Description}:
2246 This function returns whether the program is executing on a particular
2247 device specified in @var{devicetype}. In C/C++ a non-zero value is
2248 returned to indicate the device is execiting on the specified device type.
2249 In Fortran, @code{true} will be returned. If the program is not executing
2250 on the specified device type C/C++ will return a zero, while Fortran will
2251 return @code{false}.
2254 @multitable @columnfractions .20 .80
2255 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
2258 @item @emph{Fortran}:
2259 @multitable @columnfractions .20 .80
2260 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
2261 @item @tab @code{integer(acc_device_kind) devicetype}
2262 @item @tab @code{logical acc_on_device}
2266 @item @emph{Reference}:
2267 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2274 @section @code{acc_malloc} -- Allocate device memory.
2276 @item @emph{Description}
2277 This function allocates @var{len} bytes of device memory. It returns
2278 the device address of the allocated memory.
2281 @multitable @columnfractions .20 .80
2282 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
2285 @item @emph{Reference}:
2286 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2293 @section @code{acc_free} -- Free device memory.
2295 @item @emph{Description}
2296 Free previously allocated device memory at the device address @code{a}.
2299 @multitable @columnfractions .20 .80
2300 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
2303 @item @emph{Reference}:
2304 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2311 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
2313 @item @emph{Description}
2314 In C/C++, this function allocates @var{len} bytes of device memory
2315 and maps it to the specified host address in @var{a}. The device
2316 address of the newly allocated device memory is returned.
2318 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2319 a contiguous array section. The second form @var{a} specifies a
2320 variable or array element and @var{len} specifies the length in bytes.
2323 @multitable @columnfractions .20 .80
2324 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
2327 @item @emph{Fortran}:
2328 @multitable @columnfractions .20 .80
2329 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
2330 @item @tab @code{type, dimension(:[,:]...) :: a}
2331 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
2332 @item @tab @code{type, dimension(:[,:]...) :: a}
2333 @item @tab @code{integer len}
2336 @item @emph{Reference}:
2337 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2343 @node acc_present_or_copyin
2344 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
2346 @item @emph{Description}
2347 This function tests if the host data specifed by @var{a} and of length
2348 @var{len} is present or not. If it is not present, then device memory
2349 will be allocated and the host memory copied. The device address of
2350 the newly allocated device memory is returned.
2352 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2353 a contiguous array section. The second form @var{a} specifies a variable or
2354 array element and @var{len} specifies the length in bytes.
2357 @multitable @columnfractions .20 .80
2358 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
2359 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
2362 @item @emph{Fortran}:
2363 @multitable @columnfractions .20 .80
2364 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
2365 @item @tab @code{type, dimension(:[,:]...) :: a}
2366 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
2367 @item @tab @code{type, dimension(:[,:]...) :: a}
2368 @item @tab @code{integer len}
2369 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
2370 @item @tab @code{type, dimension(:[,:]...) :: a}
2371 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
2372 @item @tab @code{type, dimension(:[,:]...) :: a}
2373 @item @tab @code{integer len}
2376 @item @emph{Reference}:
2377 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2384 @section @code{acc_create} -- Allocate device memory and map it to host memory.
2386 @item @emph{Description}
2387 This function allocates device memory and maps it to host memory specified
2388 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
2389 the function returns the device address of the allocated device memory.
2391 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2392 a contiguous array section. The second form @var{a} specifies a variable or
2393 array element and @var{len} specifies the length in bytes.
2396 @multitable @columnfractions .20 .80
2397 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
2400 @item @emph{Fortran}:
2401 @multitable @columnfractions .20 .80
2402 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
2403 @item @tab @code{type, dimension(:[,:]...) :: a}
2404 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
2405 @item @tab @code{type, dimension(:[,:]...) :: a}
2406 @item @tab @code{integer len}
2409 @item @emph{Reference}:
2410 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2416 @node acc_present_or_create
2417 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
2419 @item @emph{Description}
2420 This function tests if the host data specifed by @var{a} and of length
2421 @var{len} is present or not. If it is not present, then device memory
2422 will be allocated and mapped to host memory. In C/C++, the device address
2423 of the newly allocated device memory is returned.
2425 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2426 a contiguous array section. The second form @var{a} specifies a variable or
2427 array element and @var{len} specifies the length in bytes.
2431 @multitable @columnfractions .20 .80
2432 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
2433 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
2436 @item @emph{Fortran}:
2437 @multitable @columnfractions .20 .80
2438 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
2439 @item @tab @code{type, dimension(:[,:]...) :: a}
2440 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
2441 @item @tab @code{type, dimension(:[,:]...) :: a}
2442 @item @tab @code{integer len}
2443 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
2444 @item @tab @code{type, dimension(:[,:]...) :: a}
2445 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
2446 @item @tab @code{type, dimension(:[,:]...) :: a}
2447 @item @tab @code{integer len}
2450 @item @emph{Reference}:
2451 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2458 @section @code{acc_copyout} -- Copy device memory to host memory.
2460 @item @emph{Description}
2461 This function copies mapped device memory to host memory which is specified
2462 by host address @var{a} for a length @var{len} bytes in C/C++.
2464 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2465 a contiguous array section. The second form @var{a} specifies a variable or
2466 array element and @var{len} specifies the length in bytes.
2469 @multitable @columnfractions .20 .80
2470 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
2473 @item @emph{Fortran}:
2474 @multitable @columnfractions .20 .80
2475 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
2476 @item @tab @code{type, dimension(:[,:]...) :: a}
2477 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
2478 @item @tab @code{type, dimension(:[,:]...) :: a}
2479 @item @tab @code{integer len}
2482 @item @emph{Reference}:
2483 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2490 @section @code{acc_delete} -- Free device memory.
2492 @item @emph{Description}
2493 This function frees previously allocated device memory specified by
2494 the device address @var{a} and the length of @var{len} bytes.
2496 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2497 a contiguous array section. The second form @var{a} specifies a variable or
2498 array element and @var{len} specifies the length in bytes.
2501 @multitable @columnfractions .20 .80
2502 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
2505 @item @emph{Fortran}:
2506 @multitable @columnfractions .20 .80
2507 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
2508 @item @tab @code{type, dimension(:[,:]...) :: a}
2509 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
2510 @item @tab @code{type, dimension(:[,:]...) :: a}
2511 @item @tab @code{integer len}
2514 @item @emph{Reference}:
2515 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2521 @node acc_update_device
2522 @section @code{acc_update_device} -- Update device memory from mapped host memory.
2524 @item @emph{Description}
2525 This function updates the device copy from the previously mapped host memory.
2526 The host memory is specified with the host address @var{a} and a length of
2529 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2530 a contiguous array section. The second form @var{a} specifies a variable or
2531 array element and @var{len} specifies the length in bytes.
2534 @multitable @columnfractions .20 .80
2535 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
2538 @item @emph{Fortran}:
2539 @multitable @columnfractions .20 .80
2540 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
2541 @item @tab @code{type, dimension(:[,:]...) :: a}
2542 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
2543 @item @tab @code{type, dimension(:[,:]...) :: a}
2544 @item @tab @code{integer len}
2547 @item @emph{Reference}:
2548 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2554 @node acc_update_self
2555 @section @code{acc_update_self} -- Update host memory from mapped device memory.
2557 @item @emph{Description}
2558 This function updates the host copy from the previously mapped device memory.
2559 The host memory is specified with the host address @var{a} and a length of
2562 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2563 a contiguous array section. The second form @var{a} specifies a variable or
2564 array element and @var{len} specifies the length in bytes.
2567 @multitable @columnfractions .20 .80
2568 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
2571 @item @emph{Fortran}:
2572 @multitable @columnfractions .20 .80
2573 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
2574 @item @tab @code{type, dimension(:[,:]...) :: a}
2575 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
2576 @item @tab @code{type, dimension(:[,:]...) :: a}
2577 @item @tab @code{integer len}
2580 @item @emph{Reference}:
2581 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2588 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
2590 @item @emph{Description}
2591 This function maps previously allocated device and host memory. The device
2592 memory is specified with the device address @var{d}. The host memory is
2593 specified with the host address @var{h} and a length of @var{len}.
2596 @multitable @columnfractions .20 .80
2597 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
2600 @item @emph{Reference}:
2601 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2607 @node acc_unmap_data
2608 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
2610 @item @emph{Description}
2611 This function unmaps previously mapped device and host memory. The latter
2612 specified by @var{h}.
2615 @multitable @columnfractions .20 .80
2616 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
2619 @item @emph{Reference}:
2620 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2627 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
2629 @item @emph{Description}
2630 This function returns the device address that has been mapped to the
2631 host address specified by @var{h}.
2634 @multitable @columnfractions .20 .80
2635 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
2638 @item @emph{Reference}:
2639 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2646 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
2648 @item @emph{Description}
2649 This function returns the host address that has been mapped to the
2650 device address specified by @var{d}.
2653 @multitable @columnfractions .20 .80
2654 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
2657 @item @emph{Reference}:
2658 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2664 @node acc_is_present
2665 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
2667 @item @emph{Description}
2668 This function indicates whether the specified host address in @var{a} and a
2669 length of @var{len} bytes is present on the device. In C/C++, a non-zero
2670 value is returned to indicate the presence of the mapped memory on the
2671 device. A zero is returned to indicate the memory is not mapped on the
2674 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2675 a contiguous array section. The second form @var{a} specifies a variable or
2676 array element and @var{len} specifies the length in bytes. If the host
2677 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
2678 a @code{false} is return to indicate the mapped memory is not present.
2681 @multitable @columnfractions .20 .80
2682 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
2685 @item @emph{Fortran}:
2686 @multitable @columnfractions .20 .80
2687 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
2688 @item @tab @code{type, dimension(:[,:]...) :: a}
2689 @item @tab @code{logical acc_is_present}
2690 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
2691 @item @tab @code{type, dimension(:[,:]...) :: a}
2692 @item @tab @code{integer len}
2693 @item @tab @code{logical acc_is_present}
2696 @item @emph{Reference}:
2697 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2703 @node acc_memcpy_to_device
2704 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
2706 @item @emph{Description}
2707 This function copies host memory specified by host address of @var{src} to
2708 device memory specified by the device address @var{dest} for a length of
2712 @multitable @columnfractions .20 .80
2713 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
2716 @item @emph{Reference}:
2717 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2723 @node acc_memcpy_from_device
2724 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
2726 @item @emph{Description}
2727 This function copies host memory specified by host address of @var{src} from
2728 device memory specified by the device address @var{dest} for a length of
2732 @multitable @columnfractions .20 .80
2733 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
2736 @item @emph{Reference}:
2737 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2743 @node acc_get_current_cuda_device
2744 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
2746 @item @emph{Description}
2747 This function returns the CUDA device handle. This handle is the same
2748 as used by the CUDA Runtime or Driver API's.
2751 @multitable @columnfractions .20 .80
2752 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
2755 @item @emph{Reference}:
2756 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2762 @node acc_get_current_cuda_context
2763 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
2765 @item @emph{Description}
2766 This function returns the CUDA context handle. This handle is the same
2767 as used by the CUDA Runtime or Driver API's.
2770 @multitable @columnfractions .20 .80
2771 @item @emph{Prototype}: @tab @code{acc_get_current_cuda_context(void);}
2774 @item @emph{Reference}:
2775 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2781 @node acc_get_cuda_stream
2782 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
2784 @item @emph{Description}
2785 This function returns the CUDA stream handle. This handle is the same
2786 as used by the CUDA Runtime or Driver API's.
2789 @multitable @columnfractions .20 .80
2790 @item @emph{Prototype}: @tab @code{acc_get_cuda_stream(void);}
2793 @item @emph{Reference}:
2794 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2800 @node acc_set_cuda_stream
2801 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
2803 @item @emph{Description}
2804 This function associates the stream handle specified by @var{stream} with
2805 the asynchronous value specified by @var{async}.
2808 @multitable @columnfractions .20 .80
2809 @item @emph{Prototype}: @tab @code{acc_set_cuda_stream(int async void *stream);}
2812 @item @emph{Reference}:
2813 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2819 @c ---------------------------------------------------------------------
2820 @c OpenACC Environment Variables
2821 @c ---------------------------------------------------------------------
2823 @node OpenACC Environment Variables
2824 @chapter OpenACC Environment Variables
2826 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
2827 are defined by section 4 of the OpenACC specification in version 2.0.
2828 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
2838 @node ACC_DEVICE_TYPE
2839 @section @code{ACC_DEVICE_TYPE}
2841 @item @emph{Reference}:
2842 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2848 @node ACC_DEVICE_NUM
2849 @section @code{ACC_DEVICE_NUM}
2851 @item @emph{Reference}:
2852 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2858 @node GCC_ACC_NOTIFY
2859 @section @code{GCC_ACC_NOTIFY}
2861 @item @emph{Description}:
2862 Print debug information pertaining to the accelerator.
2867 @c ---------------------------------------------------------------------
2868 @c CUDA Streams Usage
2869 @c ---------------------------------------------------------------------
2871 @node CUDA Streams Usage
2872 @chapter CUDA Streams Usage
2874 This applies to the @code{nvptx} plugin only.
2876 The library provides elements that perform asynchronous movement of
2877 data and asynchronous operation of computing constructs. This
2878 asynchronous functionality is implemented by making use of CUDA
2879 streams@footnote{See "Stream Management" in "CUDA Driver API",
2880 TRM-06703-001, Version 5.5, for additional information}.
2882 The primary means by that the asychronous functionality is accessed
2883 is through the use of those OpenACC directives which make use of the
2884 @code{async} and @code{wait} clauses. When the @code{async} clause is
2885 first used with a directive, it creates a CUDA stream. If an
2886 @code{async-argument} is used with the @code{async} clause, then the
2887 stream is associated with the specified @code{async-argument}.
2889 Following the creation of an association between a CUDA stream and the
2890 @code{async-argument} of an @code{async} clause, both the @code{wait}
2891 clause and the @code{wait} directive can be used. When either the
2892 clause or directive is used after stream creation, it creates a
2893 rendezvous point whereby execution waits until all operations
2894 associated with the @code{async-argument}, that is, stream, have
2897 Normally, the management of the streams that are created as a result of
2898 using the @code{async} clause, is done without any intervention by the
2899 caller. This implies the association between the @code{async-argument}
2900 and the CUDA stream will be maintained for the lifetime of the program.
2901 However, this association can be changed through the use of the library
2902 function @code{acc_set_cuda_stream}. When the function
2903 @code{acc_set_cuda_stream} is called, the CUDA stream that was
2904 originally associated with the @code{async} clause will be destroyed.
2905 Caution should be taken when changing the association as subsequent
2906 references to the @code{async-argument} refer to a different
2911 @c ---------------------------------------------------------------------
2912 @c OpenACC Library Interoperability
2913 @c ---------------------------------------------------------------------
2915 @node OpenACC Library Interoperability
2916 @chapter OpenACC Library Interoperability
2918 @section Introduction
2920 The OpenACC library uses the CUDA Driver API, and may interact with
2921 programs that use the Runtime library directly, or another library
2922 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
2923 "Interactions with the CUDA Driver API" in
2924 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
2925 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
2926 for additional information on library interoperability.}.
2927 This chapter describes the use cases and what changes are
2928 required in order to use both the OpenACC library and the CUBLAS and Runtime
2929 libraries within a program.
2931 @section First invocation: NVIDIA CUBLAS library API
2933 In this first use case (see below), a function in the CUBLAS library is called
2934 prior to any of the functions in the OpenACC library. More specifically, the
2935 function @code{cublasCreate()}.
2937 When invoked, the function initializes the library and allocates the
2938 hardware resources on the host and the device on behalf of the caller. Once
2939 the initialization and allocation has completed, a handle is returned to the
2940 caller. The OpenACC library also requires initialization and allocation of
2941 hardware resources. Since the CUBLAS library has already allocated the
2942 hardware resources for the device, all that is left to do is to initialize
2943 the OpenACC library and acquire the hardware resources on the host.
2945 Prior to calling the OpenACC function that initializes the library and
2946 allocate the host hardware resources, you need to acquire the device number
2947 that was allocated during the call to @code{cublasCreate()}. The invoking of the
2948 runtime library function @code{cudaGetDevice()} accomplishes this. Once
2949 acquired, the device number is passed along with the device type as
2950 parameters to the OpenACC library function @code{acc_set_device_num()}.
2952 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
2953 library uses the context that was created during the call to
2954 @code{cublasCreate()}. In other words, both libraries will be sharing the
2958 /* Create the handle */
2959 s = cublasCreate(&h);
2960 if (s != CUBLAS_STATUS_SUCCESS)
2962 fprintf(stderr, "cublasCreate failed %d\n", s);
2966 /* Get the device number */
2967 e = cudaGetDevice(&dev);
2968 if (e != cudaSuccess)
2970 fprintf(stderr, "cudaGetDevice failed %d\n", e);
2974 /* Initialize OpenACC library and use device 'dev' */
2975 acc_set_device_num(dev, acc_device_nvidia);
2980 @section First invocation: OpenACC library API
2982 In this second use case (see below), a function in the OpenACC library is
2983 called prior to any of the functions in the CUBLAS library. More specificially,
2984 the function @code{acc_set_device_num()}.
2986 In the use case presented here, the function @code{acc_set_device_num()}
2987 is used to both initialize the OpenACC library and allocate the hardware
2988 resources on the host and the device. In the call to the function, the
2989 call parameters specify which device to use and what device
2990 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
2991 is but one method to initialize the OpenACC library and allocate the
2992 appropriate hardware resources. Other methods are available through the
2993 use of environment variables and these will be discussed in the next section.
2995 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
2996 functions can be called as seen with multiple calls being made to
2997 @code{acc_copyin()}. In addition, calls can be made to functions in the
2998 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
2999 subsequent to the calls to @code{acc_copyin()}.
3000 As seen in the previous use case, a call to @code{cublasCreate()}
3001 initializes the CUBLAS library and allocates the hardware resources on the
3002 host and the device. However, since the device has already been allocated,
3003 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
3004 the appropriate hardware resources on the host. The context that was created
3005 as part of the OpenACC initialization is shared with the CUBLAS library,
3006 similarly to the first use case.
3011 acc_set_device_num(dev, acc_device_nvidia);
3013 /* Copy the first set to the device */
3014 d_X = acc_copyin(&h_X[0], N * sizeof (float));
3017 fprintf(stderr, "copyin error h_X\n");
3021 /* Copy the second set to the device */
3022 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
3025 fprintf(stderr, "copyin error h_Y1\n");
3029 /* Create the handle */
3030 s = cublasCreate(&h);
3031 if (s != CUBLAS_STATUS_SUCCESS)
3033 fprintf(stderr, "cublasCreate failed %d\n", s);
3037 /* Perform saxpy using CUBLAS library function */
3038 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
3039 if (s != CUBLAS_STATUS_SUCCESS)
3041 fprintf(stderr, "cublasSaxpy failed %d\n", s);
3045 /* Copy the results from the device */
3046 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
3051 @section OpenACC library and environment variables
3053 There are two environment variables associated with the OpenACC library
3054 that may be used to control the device type and device number:
3055 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respecively. These two
3056 environement variables can be used as an alternative to calling
3057 @code{acc_set_device_num()}. As seen in the second use case, the device
3058 type and device number were specified using @code{acc_set_device_num()}.
3059 If however, the aforementioned environment variables were set, then the
3060 call to @code{acc_set_device_num()} would not be required.
3063 The use of the environment variables is only relevant when an OpenACC function
3064 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
3065 is called prior to a call to an OpenACC function, then you must call
3066 @code{acc_set_device_num()}@footnote{More complete information
3067 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
3068 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
3069 Application Programming Interface”, Version 2.0.}
3073 @c ---------------------------------------------------------------------
3075 @c ---------------------------------------------------------------------
3077 @node The libgomp ABI
3078 @chapter The libgomp ABI
3080 The following sections present notes on the external ABI as
3081 presented by libgomp. Only maintainers should need them.
3084 * Implementing MASTER construct::
3085 * Implementing CRITICAL construct::
3086 * Implementing ATOMIC construct::
3087 * Implementing FLUSH construct::
3088 * Implementing BARRIER construct::
3089 * Implementing THREADPRIVATE construct::
3090 * Implementing PRIVATE clause::
3091 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
3092 * Implementing REDUCTION clause::
3093 * Implementing PARALLEL construct::
3094 * Implementing FOR construct::
3095 * Implementing ORDERED construct::
3096 * Implementing SECTIONS construct::
3097 * Implementing SINGLE construct::
3098 * Implementing OpenACC's PARALLEL construct::
3102 @node Implementing MASTER construct
3103 @section Implementing MASTER construct
3106 if (omp_get_thread_num () == 0)
3110 Alternately, we generate two copies of the parallel subfunction
3111 and only include this in the version run by the master thread.
3112 Surely this is not worthwhile though...
3116 @node Implementing CRITICAL construct
3117 @section Implementing CRITICAL construct
3119 Without a specified name,
3122 void GOMP_critical_start (void);
3123 void GOMP_critical_end (void);
3126 so that we don't get COPY relocations from libgomp to the main
3129 With a specified name, use omp_set_lock and omp_unset_lock with
3130 name being transformed into a variable declared like
3133 omp_lock_t gomp_critical_user_<name> __attribute__((common))
3136 Ideally the ABI would specify that all zero is a valid unlocked
3137 state, and so we wouldn't need to initialize this at
3142 @node Implementing ATOMIC construct
3143 @section Implementing ATOMIC construct
3145 The target should implement the @code{__sync} builtins.
3147 Failing that we could add
3150 void GOMP_atomic_enter (void)
3151 void GOMP_atomic_exit (void)
3154 which reuses the regular lock code, but with yet another lock
3155 object private to the library.
3159 @node Implementing FLUSH construct
3160 @section Implementing FLUSH construct
3162 Expands to the @code{__sync_synchronize} builtin.
3166 @node Implementing BARRIER construct
3167 @section Implementing BARRIER construct
3170 void GOMP_barrier (void)
3174 @node Implementing THREADPRIVATE construct
3175 @section Implementing THREADPRIVATE construct
3177 In _most_ cases we can map this directly to @code{__thread}. Except
3178 that OMP allows constructors for C++ objects. We can either
3179 refuse to support this (how often is it used?) or we can
3180 implement something akin to .ctors.
3182 Even more ideally, this ctor feature is handled by extensions
3183 to the main pthreads library. Failing that, we can have a set
3184 of entry points to register ctor functions to be called.
3188 @node Implementing PRIVATE clause
3189 @section Implementing PRIVATE clause
3191 In association with a PARALLEL, or within the lexical extent
3192 of a PARALLEL block, the variable becomes a local variable in
3193 the parallel subfunction.
3195 In association with FOR or SECTIONS blocks, create a new
3196 automatic variable within the current function. This preserves
3197 the semantic of new variable creation.
3201 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3202 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3204 This seems simple enough for PARALLEL blocks. Create a private
3205 struct for communicating between the parent and subfunction.
3206 In the parent, copy in values for scalar and "small" structs;
3207 copy in addresses for others TREE_ADDRESSABLE types. In the
3208 subfunction, copy the value into the local variable.
3210 It is not clear what to do with bare FOR or SECTION blocks.
3211 The only thing I can figure is that we do something like:
3214 #pragma omp for firstprivate(x) lastprivate(y)
3215 for (int i = 0; i < n; ++i)
3232 where the "x=x" and "y=y" assignments actually have different
3233 uids for the two variables, i.e. not something you could write
3234 directly in C. Presumably this only makes sense if the "outer"
3235 x and y are global variables.
3237 COPYPRIVATE would work the same way, except the structure
3238 broadcast would have to happen via SINGLE machinery instead.
3242 @node Implementing REDUCTION clause
3243 @section Implementing REDUCTION clause
3245 The private struct mentioned in the previous section should have
3246 a pointer to an array of the type of the variable, indexed by the
3247 thread's @var{team_id}. The thread stores its final value into the
3248 array, and after the barrier, the master thread iterates over the
3249 array to collect the values.
3252 @node Implementing PARALLEL construct
3253 @section Implementing PARALLEL construct
3256 #pragma omp parallel
3265 void subfunction (void *data)
3272 GOMP_parallel_start (subfunction, &data, num_threads);
3273 subfunction (&data);
3274 GOMP_parallel_end ();
3278 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
3281 The @var{FN} argument is the subfunction to be run in parallel.
3283 The @var{DATA} argument is a pointer to a structure used to
3284 communicate data in and out of the subfunction, as discussed
3285 above with respect to FIRSTPRIVATE et al.
3287 The @var{NUM_THREADS} argument is 1 if an IF clause is present
3288 and false, or the value of the NUM_THREADS clause, if
3291 The function needs to create the appropriate number of
3292 threads and/or launch them from the dock. It needs to
3293 create the team structure and assign team ids.
3296 void GOMP_parallel_end (void)
3299 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
3303 @node Implementing FOR construct
3304 @section Implementing FOR construct
3307 #pragma omp parallel for
3308 for (i = lb; i <= ub; i++)
3315 void subfunction (void *data)
3318 while (GOMP_loop_static_next (&_s0, &_e0))
3321 for (i = _s0; i < _e1; i++)
3324 GOMP_loop_end_nowait ();
3327 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
3329 GOMP_parallel_end ();
3333 #pragma omp for schedule(runtime)
3334 for (i = 0; i < n; i++)
3343 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
3346 for (i = _s0, i < _e0; i++)
3348 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
3353 Note that while it looks like there is trickiness to propagating
3354 a non-constant STEP, there isn't really. We're explicitly allowed
3355 to evaluate it as many times as we want, and any variables involved
3356 should automatically be handled as PRIVATE or SHARED like any other
3357 variables. So the expression should remain evaluable in the
3358 subfunction. We can also pull it into a local variable if we like,
3359 but since its supposed to remain unchanged, we can also not if we like.
3361 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
3362 able to get away with no work-sharing context at all, since we can
3363 simply perform the arithmetic directly in each thread to divide up
3364 the iterations. Which would mean that we wouldn't need to call any
3367 There are separate routines for handling loops with an ORDERED
3368 clause. Bookkeeping for that is non-trivial...
3372 @node Implementing ORDERED construct
3373 @section Implementing ORDERED construct
3376 void GOMP_ordered_start (void)
3377 void GOMP_ordered_end (void)
3382 @node Implementing SECTIONS construct
3383 @section Implementing SECTIONS construct
3388 #pragma omp sections
3402 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
3419 @node Implementing SINGLE construct
3420 @section Implementing SINGLE construct
3434 if (GOMP_single_start ())
3442 #pragma omp single copyprivate(x)
3449 datap = GOMP_single_copy_start ();
3454 GOMP_single_copy_end (&data);
3463 @node Implementing OpenACC's PARALLEL construct
3464 @section Implementing OpenACC's PARALLEL construct
3467 void GOACC_parallel ()
3472 @c ---------------------------------------------------------------------
3474 @c ---------------------------------------------------------------------
3476 @node Reporting Bugs
3477 @chapter Reporting Bugs
3479 Bugs in the GNU Offloading and Multi Processing Runtime Library should
3480 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
3481 "openacc", or "openmp", or both to the keywords field in the bug
3482 report, as appropriate.
3486 @c ---------------------------------------------------------------------
3487 @c GNU General Public License
3488 @c ---------------------------------------------------------------------
3490 @include gpl_v3.texi
3494 @c ---------------------------------------------------------------------
3495 @c GNU Free Documentation License
3496 @c ---------------------------------------------------------------------
3502 @c ---------------------------------------------------------------------
3503 @c Funding Free Software
3504 @c ---------------------------------------------------------------------
3506 @include funding.texi
3508 @c ---------------------------------------------------------------------
3510 @c ---------------------------------------------------------------------
3513 @unnumbered Library Index