1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2014 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 OpenACC and OpenMP runtime library
37 This manual documents the GNU implementation of the OpenACC API for
38 offloading of code to accelerator devices in C/C++ and Fortran and
39 the GNU implementation of the OpenMP API for
40 multi-platform shared-memory parallel programming in C/C++ and Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title The GNU OpenACC and OpenMP Implementation
55 @vskip 0pt plus 1filll
56 @comment For the @value{version-GCC} Version*
58 Published by the Free Software Foundation @*
59 51 Franklin Street, Fifth Floor@*
60 Boston, MA 02110-1301, USA@*
74 This manual documents the usage of libgomp, the GNU implementation of the
75 @uref{http://www.openacc.org/, OpenACC} Application Programming Interface (API)
76 for offloading of code to accelerator devices in C/C++ and Fortran, and
77 the GNU implementation of the
78 @uref{http://www.openmp.org, OpenMP} Application Programming Interface (API)
79 for multi-platform shared-memory parallel programming in C/C++ and Fortran.
84 @comment When you add a new menu item, please keep the right hand
85 @comment aligned to the same column. Do not use tabs. This provides
86 @comment better formatting.
89 * Enabling OpenACC:: How to enable OpenACC for your
91 * OpenACC Runtime Library Routines:: The OpenACC runtime application
92 programming interface.
93 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
94 environment variables.
95 * OpenACC Library Interoperability:: OpenACC library interoperability with the
96 NVIDIA CUBLAS library.
97 * Enabling OpenMP:: How to enable OpenMP for your
99 * OpenMP Runtime Library Routines: Runtime Library Routines.
100 The OpenMP runtime application programming
102 * OpenMP Environment Variables: Environment Variables.
103 Influencing OpenMP runtime behavior with
104 environment variables.
105 * The libgomp ABI:: Notes on the external libgomp ABI.
106 * Reporting Bugs:: How to report bugs.
107 * Copying:: GNU general public license says how you
108 can copy and share libgomp.
109 * GNU Free Documentation License:: How you can copy and share this manual.
110 * Funding:: How to help assure continued work for free
112 * Library Index:: Index of this documentation.
117 @c ---------------------------------------------------------------------
119 @c ---------------------------------------------------------------------
121 @node Enabling OpenACC
122 @chapter Enabling OpenACC
124 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
125 flag @command{-fopenacc} must be specified. This enables OpenACC, and
126 arranges for automatic linking of the OpenACC runtime library
127 (@ref{Runtime Library Routines}).
129 A complete description of all OpenACC directives accepted may be found in
130 the @uref{http://www.openacc.org/, OpenMP Application Programming
131 Interface} manual, version 2.0.
134 @c ---------------------------------------------------------------------
135 @c OpenACC Runtime Library Routines
136 @c ---------------------------------------------------------------------
138 @node OpenACC Runtime Library Routines
139 @chapter OpenACC Runtime Library Routines
141 The runtime routines described here are defined by section 3 of the OpenACC
142 specifications in version 2.0.
143 They have C linkage, and do not throw exceptions.
144 Generally, they are available only for the host, with the exception of
145 @code{acc_on_device}, which is available for both the host and the
149 * acc_get_num_devices:: Get number of devices for the given device type
150 * acc_set_device_type::
151 * acc_get_device_type::
152 * acc_set_device_num::
153 * acc_get_device_num::
156 * acc_on_device:: Whether executing on a particular device
160 * acc_present_or_copyin::
162 * acc_present_or_create::
165 * acc_update_device::
172 * acc_memcpy_to_device::
173 * acc_memcpy_from_device::
176 API routines for target platforms.
179 * acc_get_current_cuda_device::
180 * acc_get_current_cuda_context::
181 * acc_get_cuda_stream::
182 * acc_set_cuda_stream::
187 @node acc_get_num_devices
188 @section @code{acc_get_num_devices} -- Get number of devices for given device type
190 @item @emph{Description}
191 This routine returns a value indicating the
192 number of devices available for the given device type. It determines
193 the number of devices in a @emph{passive} manner. In other words, it
194 does not alter the state within the runtime environment aside from
195 possibly initializing an uninitialized device. This aspect allows
196 the routine to be called without concern for altering the interaction
197 with an attached accelerator device.
199 @item @emph{Reference}:
200 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
206 @node acc_set_device_type
207 @section @code{acc_set_device_type}
209 @item @emph{Reference}:
210 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
216 @node acc_get_device_type
217 @section @code{acc_get_device_type}
219 @item @emph{Reference}:
220 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
226 @node acc_set_device_num
227 @section @code{acc_set_device_num}
229 @item @emph{Reference}:
230 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
236 @node acc_get_device_num
237 @section @code{acc_get_device_num}
239 @item @emph{Reference}:
240 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
247 @section @code{acc_init}
249 @item @emph{Reference}:
250 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
257 @section @code{acc_shutdown}
259 @item @emph{Reference}:
260 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
267 @section @code{acc_on_device} -- Whether executing on a particular device
269 @item @emph{Description}:
270 This routine tells the program whether it is executing on a particular
271 device. Based on the argument passed, GCC tries to evaluate this to a
272 constant at compile time, but library functions are also provided, for
273 both the host and the acceleration device.
275 @item @emph{Reference}:
276 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
283 @section @code{acc_malloc}
285 @item @emph{Reference}:
286 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
293 @section @code{acc_free}
295 @item @emph{Reference}:
296 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
303 @section @code{acc_copyin}
305 @item @emph{Reference}:
306 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
312 @node acc_present_or_copyin
313 @section @code{acc_present_or_copyin}
315 @item @emph{Reference}:
316 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
323 @section @code{acc_create}
325 @item @emph{Reference}:
326 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
332 @node acc_present_or_create
333 @section @code{acc_present_or_create}
335 @item @emph{Reference}:
336 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
343 @section @code{acc_copyout}
345 @item @emph{Reference}:
346 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
353 @section @code{acc_delete}
355 @item @emph{Reference}:
356 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
362 @node acc_update_device
363 @section @code{acc_update_device}
365 @item @emph{Reference}:
366 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
372 @node acc_update_self
373 @section @code{acc_update_self}
375 @item @emph{Reference}:
376 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
383 @section @code{acc_map_data}
385 @item @emph{Reference}:
386 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
393 @section @code{acc_unmap_data}
395 @item @emph{Reference}:
396 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
403 @section @code{acc_deviceptr}
405 @item @emph{Reference}:
406 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
413 @section @code{acc_hostptr}
415 @item @emph{Reference}:
416 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
423 @section @code{acc_is_present}
425 @item @emph{Reference}:
426 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
432 @node acc_memcpy_to_device
433 @section @code{acc_memcpy_to_device}
435 @item @emph{Reference}:
436 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
442 @node acc_memcpy_from_device
443 @section @code{acc_memcpy_from_device}
445 @item @emph{Reference}:
446 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
452 @node acc_get_current_cuda_device
453 @section @code{acc_get_current_cuda_device}
455 @item @emph{Reference}:
456 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
462 @node acc_get_current_cuda_context
463 @section @code{acc_get_current_cuda_context}
465 @item @emph{Reference}:
466 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
472 @node acc_get_cuda_stream
473 @section @code{acc_get_cuda_stream}
475 @item @emph{Reference}:
476 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
482 @node acc_set_cuda_stream
483 @section @code{acc_set_cuda_stream}
485 @item @emph{Reference}:
486 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
492 @c ---------------------------------------------------------------------
493 @c OpenACC Environment Variables
494 @c ---------------------------------------------------------------------
496 @node OpenACC Environment Variables
497 @chapter OpenACC Environment Variables
499 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
500 are defined by section 4 of the OpenACC specification in version 2.0.
501 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
511 @node ACC_DEVICE_TYPE
512 @section @code{ACC_DEVICE_TYPE}
514 @item @emph{Reference}:
515 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
522 @section @code{ACC_DEVICE_NUM}
524 @item @emph{Reference}:
525 @uref{http://www.openacc.org/, OpenACC specification v2.0}, section
532 @section @code{GCC_ACC_NOTIFY}
534 @item @emph{Description}:
535 Print debug information pertaining to the accelerator.
539 @c ---------------------------------------------------------------------
540 @c OpenACC Library Interoperability
541 @c ---------------------------------------------------------------------
543 @node OpenACC Library Interoperability
544 @chapter OpenACC Library Interoperability
546 @section Introduction
548 As the OpenACC library is built using the CUDA Driver API, the question has
549 arisen on what impact does using the OpenACC library have on a program that
550 uses the Runtime library, or a library based on the Runtime library, e.g.,
551 CUBLAS@footnote{Seee section 2.26, "Interactions with the CUDA Driver API" in
552 "CUDA Runtime API", Version 5.5, July 2013 and section 2.27, "VDPAU
553 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
554 July 2013, for additional information on library interoperability.}.
555 This chapter will describe the use cases and what changes are
556 required in order to use both the OpenACC library and the CUBLAS and Runtime
557 libraries within a program.
559 @section First invocation: NVIDIA CUBLAS library API
561 In this first use case (see below), a function in the CUBLAS library is called
562 prior to any of the functions in the OpenACC library. More specifically, the
563 function @code{cublasCreate()}.
565 When invoked, the function will initialize the library and allocate the
566 hardware resources on the host and the device on behalf of the caller. Once
567 the initialization and allocation has completed, a handle is returned to the
568 caller. The OpenACC library also requires initialization and allocation of
569 hardware resources. Since the CUBLAS library has already allocated the
570 hardware resources for the device, all that is left to do is to initialize
571 the OpenACC library and acquire the hardware resources on the host.
573 Prior to calling the OpenACC function that will initialize the library and
574 allocate the host hardware resources, one needs to acquire the device number
575 that was allocated during the call to @code{cublasCreate()}. The invoking of the
576 runtime library function @code{cudaGetDevice()} will accomplish this. Once
577 acquired, the device number is passed along with the device type as
578 parameters to the OpenACC library function @code{acc_set_device_num()}.
580 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
581 library will be using the context that was created during the call to
582 @code{cublasCreate()}. In other words, both libraries will be sharing the
586 /* Create the handle */
587 s = cublasCreate(&h);
588 if (s != CUBLAS_STATUS_SUCCESS)
590 fprintf(stderr, "cublasCreate failed %d\n", s);
594 /* Get the device number */
595 e = cudaGetDevice(&dev);
596 if (e != cudaSuccess)
598 fprintf(stderr, "cudaGetDevice failed %d\n", e);
602 /* Initialize OpenACC library and use device 'dev' */
603 acc_set_device_num(dev, acc_device_nvidia);
608 @section First invocation: OpenACC library API
610 In this second use case (see below), a function in the OpenACC library is
611 called prior to any of the functions in the CUBLAS library. More specificially,
612 the function acc_set_device_num().
614 In the use case presented here, the function @code{acc_set_device_num()}
615 is used to both initialize the OpenACC library and allocate the hardware
616 resources on the host and the device. In the call to the function, the
617 call parameters specify which device to use, i.e., 'dev', and what device
618 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
619 is but one method to initialize the OpenACC library and allocate the
620 appropriate hardware resources. Other methods are available through the
621 use of environment variables and these will be discussed in the next section.
623 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
624 functions can be called as seen with multiple calls being made to
625 @code{acc_copyin()}. In addition, calls can be made to functions in the
626 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
627 subsequent to the calls to @code{acc_copyin()}.
628 As seen in the previous use case, a call to @code{cublasCreate()} will
629 initialize the CUBLAS library and allocate the hardware resources on the
630 host and the device. However, since the device has already been allocated,
631 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
632 the appropriate hardware resources on the host. The context that was created
633 as part of the OpenACC initialization will be shared with the CUBLAS library,
634 similarly to the first use case.
639 acc_set_device_num(dev, acc_device_nvidia);
641 /* Copy the first set to the device */
642 d_X = acc_copyin(&h_X[0], N * sizeof (float));
645 fprintf(stderr, "copyin error h_X\n");
649 /* Copy the second set to the device */
650 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
653 fprintf(stderr, "copyin error h_Y1\n");
657 /* Create the handle */
658 s = cublasCreate(&h);
659 if (s != CUBLAS_STATUS_SUCCESS)
661 fprintf(stderr, "cublasCreate failed %d\n", s);
665 /* Perform saxpy using CUBLAS library function */
666 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
667 if (s != CUBLAS_STATUS_SUCCESS)
669 fprintf(stderr, "cublasSaxpy failed %d\n", s);
673 /* Copy the results from the device */
674 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
680 @section OpenACC library and environment variables
682 There are two environment variables associated with the OpenACC library that
683 may be used to control the device type and device number.
684 Namely, @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}. In the second
685 use case, the device type and device number were specified using
686 @code{acc_set_device_num()}. However, @env{ACC_DEVICE_TYPE} and
687 @env{ACC_DEVICE_NUM} could have been defined and the call to
688 @code{acc_set_device_num()} would be not be required. At the time of the
689 call to @code{acc_copyin()}, these two environment variables would be
690 sampled and their values used.
692 The use of the environment variables is only relevant when an OpenACC function
693 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
694 is called prior to a call to an OpenACC function, then a call to
695 @code{acc_set_device_num()}, must be done@footnote{More complete information
696 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
697 sections 4.1 and 4.2 of the “The OpenACC
698 Application Programming Interface”, Version 2.0, June, 2013.}.
702 @c ---------------------------------------------------------------------
704 @c ---------------------------------------------------------------------
706 @node Enabling OpenMP
707 @chapter Enabling OpenMP
709 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
710 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
711 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
712 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
713 @code{!$} conditional compilation sentinels in free form and @code{c$},
714 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
715 arranges for automatic linking of the OpenMP runtime library
716 (@ref{Runtime Library Routines}).
718 A complete description of all OpenMP directives accepted may be found in
719 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
723 @c ---------------------------------------------------------------------
724 @c OpenMP Runtime Library Routines
725 @c ---------------------------------------------------------------------
727 @node Runtime Library Routines
728 @chapter OpenMP Runtime Library Routines
730 The runtime routines described here are defined by Section 3 of the OpenMP
731 specification in version 4.0. The routines are structured in following
735 Control threads, processors and the parallel environment. They have C
736 linkage, and do not throw exceptions.
738 * omp_get_active_level:: Number of active parallel regions
739 * omp_get_ancestor_thread_num:: Ancestor thread ID
740 * omp_get_cancellation:: Whether cancellation support is enabled
741 * omp_get_default_device:: Get the default device for target regions
742 * omp_get_dynamic:: Dynamic teams setting
743 * omp_get_level:: Number of parallel regions
744 * omp_get_max_active_levels:: Maximum number of active regions
745 * omp_get_max_threads:: Maximum number of threads of parallel region
746 * omp_get_nested:: Nested parallel regions
747 * omp_get_num_devices:: Number of target devices
748 * omp_get_num_procs:: Number of processors online
749 * omp_get_num_teams:: Number of teams
750 * omp_get_num_threads:: Size of the active team
751 * omp_get_proc_bind:: Whether theads may be moved between CPUs
752 * omp_get_schedule:: Obtain the runtime scheduling method
753 * omp_get_team_num:: Get team number
754 * omp_get_team_size:: Number of threads in a team
755 * omp_get_thread_limit:: Maximum number of threads
756 * omp_get_thread_num:: Current thread ID
757 * omp_in_parallel:: Whether a parallel region is active
758 * omp_in_final:: Whether in final or included task region
759 * omp_is_initial_device:: Whether executing on the host device
760 * omp_set_default_device:: Set the default device for target regions
761 * omp_set_dynamic:: Enable/disable dynamic teams
762 * omp_set_max_active_levels:: Limits the number of active parallel regions
763 * omp_set_nested:: Enable/disable nested parallel regions
764 * omp_set_num_threads:: Set upper team size limit
765 * omp_set_schedule:: Set the runtime scheduling method
767 Initialize, set, test, unset and destroy simple and nested locks.
769 * omp_init_lock:: Initialize simple lock
770 * omp_set_lock:: Wait for and set simple lock
771 * omp_test_lock:: Test and set simple lock if available
772 * omp_unset_lock:: Unset simple lock
773 * omp_destroy_lock:: Destroy simple lock
774 * omp_init_nest_lock:: Initialize nested lock
775 * omp_set_nest_lock:: Wait for and set simple lock
776 * omp_test_nest_lock:: Test and set nested lock if available
777 * omp_unset_nest_lock:: Unset nested lock
778 * omp_destroy_nest_lock:: Destroy nested lock
780 Portable, thread-based, wall clock timer.
782 * omp_get_wtick:: Get timer precision.
783 * omp_get_wtime:: Elapsed wall clock time.
788 @node omp_get_active_level
789 @section @code{omp_get_active_level} -- Number of parallel regions
791 @item @emph{Description}:
792 This function returns the nesting level for the active parallel blocks,
793 which enclose the calling call.
796 @multitable @columnfractions .20 .80
797 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
800 @item @emph{Fortran}:
801 @multitable @columnfractions .20 .80
802 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
805 @item @emph{See also}:
806 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
808 @item @emph{Reference}:
809 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
814 @node omp_get_ancestor_thread_num
815 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
817 @item @emph{Description}:
818 This function returns the thread identification number for the given
819 nesting level of the current thread. For values of @var{level} outside
820 zero to @code{omp_get_level} -1 is returned; if @var{level} is
821 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
824 @multitable @columnfractions .20 .80
825 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
828 @item @emph{Fortran}:
829 @multitable @columnfractions .20 .80
830 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
831 @item @tab @code{integer level}
834 @item @emph{See also}:
835 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
837 @item @emph{Reference}:
838 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
843 @node omp_get_cancellation
844 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
846 @item @emph{Description}:
847 This function returns @code{true} if cancellation is activated, @code{false}
848 otherwise. Here, @code{true} and @code{false} represent their language-specific
849 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
853 @multitable @columnfractions .20 .80
854 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
857 @item @emph{Fortran}:
858 @multitable @columnfractions .20 .80
859 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
862 @item @emph{See also}:
863 @ref{OMP_CANCELLATION}
865 @item @emph{Reference}:
866 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
871 @node omp_get_default_device
872 @section @code{omp_get_default_device} -- Get the default device for target regions
874 @item @emph{Description}:
875 Get the default device for target regions without device clause.
878 @multitable @columnfractions .20 .80
879 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
882 @item @emph{Fortran}:
883 @multitable @columnfractions .20 .80
884 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
887 @item @emph{See also}:
888 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
890 @item @emph{Reference}:
891 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
896 @node omp_get_dynamic
897 @section @code{omp_get_dynamic} -- Dynamic teams setting
899 @item @emph{Description}:
900 This function returns @code{true} if enabled, @code{false} otherwise.
901 Here, @code{true} and @code{false} represent their language-specific
904 The dynamic team setting may be initialized at startup by the
905 @env{OMP_DYNAMIC} environment variable or at runtime using
906 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
910 @multitable @columnfractions .20 .80
911 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
914 @item @emph{Fortran}:
915 @multitable @columnfractions .20 .80
916 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
919 @item @emph{See also}:
920 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
922 @item @emph{Reference}:
923 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
929 @section @code{omp_get_level} -- Obtain the current nesting level
931 @item @emph{Description}:
932 This function returns the nesting level for the parallel blocks,
933 which enclose the calling call.
936 @multitable @columnfractions .20 .80
937 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
940 @item @emph{Fortran}:
941 @multitable @columnfractions .20 .80
942 @item @emph{Interface}: @tab @code{integer function omp_level()}
945 @item @emph{See also}:
946 @ref{omp_get_active_level}
948 @item @emph{Reference}:
949 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
954 @node omp_get_max_active_levels
955 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
957 @item @emph{Description}:
958 This function obtains the maximum allowed number of nested, active parallel regions.
961 @multitable @columnfractions .20 .80
962 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
965 @item @emph{Fortran}:
966 @multitable @columnfractions .20 .80
967 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
970 @item @emph{See also}:
971 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
973 @item @emph{Reference}:
974 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
979 @node omp_get_max_threads
980 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
982 @item @emph{Description}:
983 Return the maximum number of threads used for the current parallel region
984 that does not use the clause @code{num_threads}.
987 @multitable @columnfractions .20 .80
988 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
991 @item @emph{Fortran}:
992 @multitable @columnfractions .20 .80
993 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
996 @item @emph{See also}:
997 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
999 @item @emph{Reference}:
1000 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
1005 @node omp_get_nested
1006 @section @code{omp_get_nested} -- Nested parallel regions
1008 @item @emph{Description}:
1009 This function returns @code{true} if nested parallel regions are
1010 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
1011 represent their language-specific counterparts.
1013 Nested parallel regions may be initialized at startup by the
1014 @env{OMP_NESTED} environment variable or at runtime using
1015 @code{omp_set_nested}. If undefined, nested parallel regions are
1016 disabled by default.
1019 @multitable @columnfractions .20 .80
1020 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
1023 @item @emph{Fortran}:
1024 @multitable @columnfractions .20 .80
1025 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
1028 @item @emph{See also}:
1029 @ref{omp_set_nested}, @ref{OMP_NESTED}
1031 @item @emph{Reference}:
1032 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
1037 @node omp_get_num_devices
1038 @section @code{omp_get_num_devices} -- Number of target devices
1040 @item @emph{Description}:
1041 Returns the number of target devices.
1044 @multitable @columnfractions .20 .80
1045 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1048 @item @emph{Fortran}:
1049 @multitable @columnfractions .20 .80
1050 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1053 @item @emph{Reference}:
1054 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
1059 @node omp_get_num_procs
1060 @section @code{omp_get_num_procs} -- Number of processors online
1062 @item @emph{Description}:
1063 Returns the number of processors online on that device.
1066 @multitable @columnfractions .20 .80
1067 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1070 @item @emph{Fortran}:
1071 @multitable @columnfractions .20 .80
1072 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1075 @item @emph{Reference}:
1076 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
1081 @node omp_get_num_teams
1082 @section @code{omp_get_num_teams} -- Number of teams
1084 @item @emph{Description}:
1085 Returns the number of teams in the current team region.
1088 @multitable @columnfractions .20 .80
1089 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1092 @item @emph{Fortran}:
1093 @multitable @columnfractions .20 .80
1094 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1097 @item @emph{Reference}:
1098 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
1103 @node omp_get_num_threads
1104 @section @code{omp_get_num_threads} -- Size of the active team
1106 @item @emph{Description}:
1107 Returns the number of threads in the current team. In a sequential section of
1108 the program @code{omp_get_num_threads} returns 1.
1110 The default team size may be initialized at startup by the
1111 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
1112 of the current team may be set either by the @code{NUM_THREADS}
1113 clause or by @code{omp_set_num_threads}. If none of the above were
1114 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
1115 one thread per CPU online is used.
1118 @multitable @columnfractions .20 .80
1119 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
1122 @item @emph{Fortran}:
1123 @multitable @columnfractions .20 .80
1124 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
1127 @item @emph{See also}:
1128 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
1130 @item @emph{Reference}:
1131 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
1136 @node omp_get_proc_bind
1137 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
1139 @item @emph{Description}:
1140 This functions returns the currently active thread affinity policy, which is
1141 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1142 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
1143 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
1146 @multitable @columnfractions .20 .80
1147 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1150 @item @emph{Fortran}:
1151 @multitable @columnfractions .20 .80
1152 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1155 @item @emph{See also}:
1156 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1158 @item @emph{Reference}:
1159 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
1164 @node omp_get_schedule
1165 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
1167 @item @emph{Description}:
1168 Obtain the runtime scheduling method. The @var{kind} argument will be
1169 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
1170 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
1171 @var{modifier}, is set to the chunk size.
1174 @multitable @columnfractions .20 .80
1175 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
1178 @item @emph{Fortran}:
1179 @multitable @columnfractions .20 .80
1180 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
1181 @item @tab @code{integer(kind=omp_sched_kind) kind}
1182 @item @tab @code{integer modifier}
1185 @item @emph{See also}:
1186 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1188 @item @emph{Reference}:
1189 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
1194 @node omp_get_team_num
1195 @section @code{omp_get_team_num} -- Get team number
1197 @item @emph{Description}:
1198 Returns the team number of the calling thread.
1201 @multitable @columnfractions .20 .80
1202 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1205 @item @emph{Fortran}:
1206 @multitable @columnfractions .20 .80
1207 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1210 @item @emph{Reference}:
1211 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
1216 @node omp_get_team_size
1217 @section @code{omp_get_team_size} -- Number of threads in a team
1219 @item @emph{Description}:
1220 This function returns the number of threads in a thread team to which
1221 either the current thread or its ancestor belongs. For values of @var{level}
1222 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1223 1 is returned, and for @code{omp_get_level}, the result is identical
1224 to @code{omp_get_num_threads}.
1227 @multitable @columnfractions .20 .80
1228 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1231 @item @emph{Fortran}:
1232 @multitable @columnfractions .20 .80
1233 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1234 @item @tab @code{integer level}
1237 @item @emph{See also}:
1238 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1240 @item @emph{Reference}:
1241 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
1246 @node omp_get_thread_limit
1247 @section @code{omp_get_thread_limit} -- Maximum number of threads
1249 @item @emph{Description}:
1250 Return the maximum number of threads of the program.
1253 @multitable @columnfractions .20 .80
1254 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1257 @item @emph{Fortran}:
1258 @multitable @columnfractions .20 .80
1259 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1262 @item @emph{See also}:
1263 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1265 @item @emph{Reference}:
1266 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
1271 @node omp_get_thread_num
1272 @section @code{omp_get_thread_num} -- Current thread ID
1274 @item @emph{Description}:
1275 Returns a unique thread identification number within the current team.
1276 In a sequential parts of the program, @code{omp_get_thread_num}
1277 always returns 0. In parallel regions the return value varies
1278 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
1279 value of the master thread of a team is always 0.
1282 @multitable @columnfractions .20 .80
1283 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
1286 @item @emph{Fortran}:
1287 @multitable @columnfractions .20 .80
1288 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
1291 @item @emph{See also}:
1292 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
1294 @item @emph{Reference}:
1295 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
1300 @node omp_in_parallel
1301 @section @code{omp_in_parallel} -- Whether a parallel region is active
1303 @item @emph{Description}:
1304 This function returns @code{true} if currently running in parallel,
1305 @code{false} otherwise. Here, @code{true} and @code{false} represent
1306 their language-specific counterparts.
1309 @multitable @columnfractions .20 .80
1310 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
1313 @item @emph{Fortran}:
1314 @multitable @columnfractions .20 .80
1315 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
1318 @item @emph{Reference}:
1319 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
1324 @section @code{omp_in_final} -- Whether in final or included task region
1326 @item @emph{Description}:
1327 This function returns @code{true} if currently running in a final
1328 or included task region, @code{false} otherwise. Here, @code{true}
1329 and @code{false} represent their language-specific counterparts.
1332 @multitable @columnfractions .20 .80
1333 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1336 @item @emph{Fortran}:
1337 @multitable @columnfractions .20 .80
1338 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1341 @item @emph{Reference}:
1342 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
1347 @node omp_is_initial_device
1348 @section @code{omp_is_initial_device} -- Whether executing on the host device
1350 @item @emph{Description}:
1351 This function returns @code{true} if currently running on the host device,
1352 @code{false} otherwise. Here, @code{true} and @code{false} represent
1353 their language-specific counterparts.
1356 @multitable @columnfractions .20 .80
1357 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1360 @item @emph{Fortran}:
1361 @multitable @columnfractions .20 .80
1362 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1365 @item @emph{Reference}:
1366 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
1371 @node omp_set_default_device
1372 @section @code{omp_set_default_device} -- Set the default device for target regions
1374 @item @emph{Description}:
1375 Set the default device for target regions without device clause. The argument
1376 shall be a nonnegative device number.
1379 @multitable @columnfractions .20 .80
1380 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1383 @item @emph{Fortran}:
1384 @multitable @columnfractions .20 .80
1385 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1386 @item @tab @code{integer device_num}
1389 @item @emph{See also}:
1390 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1392 @item @emph{Reference}:
1393 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
1398 @node omp_set_dynamic
1399 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
1401 @item @emph{Description}:
1402 Enable or disable the dynamic adjustment of the number of threads
1403 within a team. The function takes the language-specific equivalent
1404 of @code{true} and @code{false}, where @code{true} enables dynamic
1405 adjustment of team sizes and @code{false} disables it.
1408 @multitable @columnfractions .20 .80
1409 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
1412 @item @emph{Fortran}:
1413 @multitable @columnfractions .20 .80
1414 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
1415 @item @tab @code{logical, intent(in) :: dynamic_threads}
1418 @item @emph{See also}:
1419 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
1421 @item @emph{Reference}:
1422 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
1427 @node omp_set_max_active_levels
1428 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1430 @item @emph{Description}:
1431 This function limits the maximum allowed number of nested, active
1435 @multitable @columnfractions .20 .80
1436 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1439 @item @emph{Fortran}:
1440 @multitable @columnfractions .20 .80
1441 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1442 @item @tab @code{integer max_levels}
1445 @item @emph{See also}:
1446 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
1448 @item @emph{Reference}:
1449 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
1454 @node omp_set_nested
1455 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
1457 @item @emph{Description}:
1458 Enable or disable nested parallel regions, i.e., whether team members
1459 are allowed to create new teams. The function takes the language-specific
1460 equivalent of @code{true} and @code{false}, where @code{true} enables
1461 dynamic adjustment of team sizes and @code{false} disables it.
1464 @multitable @columnfractions .20 .80
1465 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
1468 @item @emph{Fortran}:
1469 @multitable @columnfractions .20 .80
1470 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
1471 @item @tab @code{logical, intent(in) :: nested}
1474 @item @emph{See also}:
1475 @ref{OMP_NESTED}, @ref{omp_get_nested}
1477 @item @emph{Reference}:
1478 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
1483 @node omp_set_num_threads
1484 @section @code{omp_set_num_threads} -- Set upper team size limit
1486 @item @emph{Description}:
1487 Specifies the number of threads used by default in subsequent parallel
1488 sections, if those do not specify a @code{num_threads} clause. The
1489 argument of @code{omp_set_num_threads} shall be a positive integer.
1492 @multitable @columnfractions .20 .80
1493 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
1496 @item @emph{Fortran}:
1497 @multitable @columnfractions .20 .80
1498 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
1499 @item @tab @code{integer, intent(in) :: num_threads}
1502 @item @emph{See also}:
1503 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
1505 @item @emph{Reference}:
1506 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
1511 @node omp_set_schedule
1512 @section @code{omp_set_schedule} -- Set the runtime scheduling method
1514 @item @emph{Description}:
1515 Sets the runtime scheduling method. The @var{kind} argument can have the
1516 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1517 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1518 @code{omp_sched_auto}, the chunk size is set to the value of
1519 @var{modifier} if positive, or to the default value if zero or negative.
1520 For @code{omp_sched_auto} the @var{modifier} argument is ignored.
1523 @multitable @columnfractions .20 .80
1524 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
1527 @item @emph{Fortran}:
1528 @multitable @columnfractions .20 .80
1529 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
1530 @item @tab @code{integer(kind=omp_sched_kind) kind}
1531 @item @tab @code{integer modifier}
1534 @item @emph{See also}:
1535 @ref{omp_get_schedule}
1538 @item @emph{Reference}:
1539 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
1545 @section @code{omp_init_lock} -- Initialize simple lock
1547 @item @emph{Description}:
1548 Initialize a simple lock. After initialization, the lock is in
1552 @multitable @columnfractions .20 .80
1553 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1556 @item @emph{Fortran}:
1557 @multitable @columnfractions .20 .80
1558 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1559 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1562 @item @emph{See also}:
1563 @ref{omp_destroy_lock}
1565 @item @emph{Reference}:
1566 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1572 @section @code{omp_set_lock} -- Wait for and set simple lock
1574 @item @emph{Description}:
1575 Before setting a simple lock, the lock variable must be initialized by
1576 @code{omp_init_lock}. The calling thread is blocked until the lock
1577 is available. If the lock is already held by the current thread,
1581 @multitable @columnfractions .20 .80
1582 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1585 @item @emph{Fortran}:
1586 @multitable @columnfractions .20 .80
1587 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1588 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1591 @item @emph{See also}:
1592 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1594 @item @emph{Reference}:
1595 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1601 @section @code{omp_test_lock} -- Test and set simple lock if available
1603 @item @emph{Description}:
1604 Before setting a simple lock, the lock variable must be initialized by
1605 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1606 does not block if the lock is not available. This function returns
1607 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1608 @code{false} represent their language-specific counterparts.
1611 @multitable @columnfractions .20 .80
1612 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1615 @item @emph{Fortran}:
1616 @multitable @columnfractions .20 .80
1617 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1618 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1621 @item @emph{See also}:
1622 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1624 @item @emph{Reference}:
1625 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1630 @node omp_unset_lock
1631 @section @code{omp_unset_lock} -- Unset simple lock
1633 @item @emph{Description}:
1634 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1635 or @code{omp_test_lock} before. In addition, the lock must be held by the
1636 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1637 or more threads attempted to set the lock before, one of them is chosen to,
1638 again, set the lock to itself.
1641 @multitable @columnfractions .20 .80
1642 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1645 @item @emph{Fortran}:
1646 @multitable @columnfractions .20 .80
1647 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1648 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1651 @item @emph{See also}:
1652 @ref{omp_set_lock}, @ref{omp_test_lock}
1654 @item @emph{Reference}:
1655 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1660 @node omp_destroy_lock
1661 @section @code{omp_destroy_lock} -- Destroy simple lock
1663 @item @emph{Description}:
1664 Destroy a simple lock. In order to be destroyed, a simple lock must be
1665 in the unlocked state.
1668 @multitable @columnfractions .20 .80
1669 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1672 @item @emph{Fortran}:
1673 @multitable @columnfractions .20 .80
1674 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1675 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1678 @item @emph{See also}:
1681 @item @emph{Reference}:
1682 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1687 @node omp_init_nest_lock
1688 @section @code{omp_init_nest_lock} -- Initialize nested lock
1690 @item @emph{Description}:
1691 Initialize a nested lock. After initialization, the lock is in
1692 an unlocked state and the nesting count is set to zero.
1695 @multitable @columnfractions .20 .80
1696 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1699 @item @emph{Fortran}:
1700 @multitable @columnfractions .20 .80
1701 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1702 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1705 @item @emph{See also}:
1706 @ref{omp_destroy_nest_lock}
1708 @item @emph{Reference}:
1709 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1713 @node omp_set_nest_lock
1714 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1716 @item @emph{Description}:
1717 Before setting a nested lock, the lock variable must be initialized by
1718 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1719 is available. If the lock is already held by the current thread, the
1720 nesting count for the lock is incremented.
1723 @multitable @columnfractions .20 .80
1724 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1727 @item @emph{Fortran}:
1728 @multitable @columnfractions .20 .80
1729 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1730 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1733 @item @emph{See also}:
1734 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1736 @item @emph{Reference}:
1737 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1742 @node omp_test_nest_lock
1743 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1745 @item @emph{Description}:
1746 Before setting a nested lock, the lock variable must be initialized by
1747 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1748 @code{omp_test_nest_lock} does not block if the lock is not available.
1749 If the lock is already held by the current thread, the new nesting count
1750 is returned. Otherwise, the return value equals zero.
1753 @multitable @columnfractions .20 .80
1754 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1757 @item @emph{Fortran}:
1758 @multitable @columnfractions .20 .80
1759 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1760 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1764 @item @emph{See also}:
1765 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1767 @item @emph{Reference}:
1768 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1773 @node omp_unset_nest_lock
1774 @section @code{omp_unset_nest_lock} -- Unset nested lock
1776 @item @emph{Description}:
1777 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1778 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1779 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1780 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1781 one of them is chosen to, again, set the lock to itself.
1784 @multitable @columnfractions .20 .80
1785 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1788 @item @emph{Fortran}:
1789 @multitable @columnfractions .20 .80
1790 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1791 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1794 @item @emph{See also}:
1795 @ref{omp_set_nest_lock}
1797 @item @emph{Reference}:
1798 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1803 @node omp_destroy_nest_lock
1804 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1806 @item @emph{Description}:
1807 Destroy a nested lock. In order to be destroyed, a nested lock must be
1808 in the unlocked state and its nesting count must equal zero.
1811 @multitable @columnfractions .20 .80
1812 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1815 @item @emph{Fortran}:
1816 @multitable @columnfractions .20 .80
1817 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1818 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1821 @item @emph{See also}:
1824 @item @emph{Reference}:
1825 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1831 @section @code{omp_get_wtick} -- Get timer precision
1833 @item @emph{Description}:
1834 Gets the timer precision, i.e., the number of seconds between two
1835 successive clock ticks.
1838 @multitable @columnfractions .20 .80
1839 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1842 @item @emph{Fortran}:
1843 @multitable @columnfractions .20 .80
1844 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1847 @item @emph{See also}:
1850 @item @emph{Reference}:
1851 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1857 @section @code{omp_get_wtime} -- Elapsed wall clock time
1859 @item @emph{Description}:
1860 Elapsed wall clock time in seconds. The time is measured per thread, no
1861 guarantee can be made that two distinct threads measure the same time.
1862 Time is measured from some "time in the past", which is an arbitrary time
1863 guaranteed not to change during the execution of the program.
1866 @multitable @columnfractions .20 .80
1867 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1870 @item @emph{Fortran}:
1871 @multitable @columnfractions .20 .80
1872 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1875 @item @emph{See also}:
1878 @item @emph{Reference}:
1879 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
1884 @c ---------------------------------------------------------------------
1885 @c OpenMP Environment Variables
1886 @c ---------------------------------------------------------------------
1888 @node Environment Variables
1889 @chapter OpenMP Environment Variables
1891 The environment variables which beginning with @env{OMP_} are defined by
1892 section 4 of the OpenMP specification in version 4.0, while those
1893 beginning with @env{GOMP_} are GNU extensions.
1896 * OMP_CANCELLATION:: Set whether cancellation is activated
1897 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1898 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1899 * OMP_DYNAMIC:: Dynamic adjustment of threads
1900 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1901 * OMP_NESTED:: Nested parallel regions
1902 * OMP_NUM_THREADS:: Specifies the number of threads to use
1903 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1904 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1905 * OMP_STACKSIZE:: Set default thread stack size
1906 * OMP_SCHEDULE:: How threads are scheduled
1907 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1908 * OMP_WAIT_POLICY:: How waiting threads are handled
1909 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1910 * GOMP_STACKSIZE:: Set default thread stack size
1911 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1915 @node OMP_CANCELLATION
1916 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1917 @cindex Environment Variable
1919 @item @emph{Description}:
1920 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1921 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1923 @item @emph{See also}:
1924 @ref{omp_get_cancellation}
1926 @item @emph{Reference}:
1927 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1932 @node OMP_DISPLAY_ENV
1933 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1934 @cindex Environment Variable
1936 @item @emph{Description}:
1937 If set to @code{TRUE}, the OpenMP version number and the values
1938 associated with the OpenMP environment variables are printed to @code{stderr}.
1939 If set to @code{VERBOSE}, it additionally shows the value of the environment
1940 variables which are GNU extensions. If undefined or set to @code{FALSE},
1941 this information will not be shown.
1944 @item @emph{Reference}:
1945 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
1950 @node OMP_DEFAULT_DEVICE
1951 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1952 @cindex Environment Variable
1954 @item @emph{Description}:
1955 Set to choose the device which is used in a @code{target} region, unless the
1956 value is overridden by @code{omp_set_default_device} or by a @code{device}
1957 clause. The value shall be the nonnegative device number. If no device with
1958 the given device number exists, the code is executed on the host. If unset,
1959 device number 0 will be used.
1962 @item @emph{See also}:
1963 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1965 @item @emph{Reference}:
1966 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1972 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1973 @cindex Environment Variable
1975 @item @emph{Description}:
1976 Enable or disable the dynamic adjustment of the number of threads
1977 within a team. The value of this environment variable shall be
1978 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1979 disabled by default.
1981 @item @emph{See also}:
1982 @ref{omp_set_dynamic}
1984 @item @emph{Reference}:
1985 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
1990 @node OMP_MAX_ACTIVE_LEVELS
1991 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1992 @cindex Environment Variable
1994 @item @emph{Description}:
1995 Specifies the initial value for the maximum number of nested parallel
1996 regions. The value of this variable shall be a positive integer.
1997 If undefined, the number of active levels is unlimited.
1999 @item @emph{See also}:
2000 @ref{omp_set_max_active_levels}
2002 @item @emph{Reference}:
2003 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
2009 @section @env{OMP_NESTED} -- Nested parallel regions
2010 @cindex Environment Variable
2011 @cindex Implementation specific setting
2013 @item @emph{Description}:
2014 Enable or disable nested parallel regions, i.e., whether team members
2015 are allowed to create new teams. The value of this environment variable
2016 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
2017 regions are disabled by default.
2019 @item @emph{See also}:
2020 @ref{omp_set_nested}
2022 @item @emph{Reference}:
2023 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
2028 @node OMP_NUM_THREADS
2029 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
2030 @cindex Environment Variable
2031 @cindex Implementation specific setting
2033 @item @emph{Description}:
2034 Specifies the default number of threads to use in parallel regions. The
2035 value of this variable shall be a comma-separated list of positive integers;
2036 the value specified the number of threads to use for the corresponding nested
2037 level. If undefined one thread per CPU is used.
2039 @item @emph{See also}:
2040 @ref{omp_set_num_threads}
2042 @item @emph{Reference}:
2043 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
2049 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
2050 @cindex Environment Variable
2052 @item @emph{Description}:
2053 Specifies whether threads may be moved between processors. If set to
2054 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
2055 they may be moved. Alternatively, a comma separated list with the
2056 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
2057 the thread affinity policy for the corresponding nesting level. With
2058 @code{MASTER} the worker threads are in the same place partition as the
2059 master thread. With @code{CLOSE} those are kept close to the master thread
2060 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
2061 across the place partitions is used.
2063 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
2064 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
2066 @item @emph{See also}:
2067 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
2069 @item @emph{Reference}:
2070 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
2076 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
2077 @cindex Environment Variable
2079 @item @emph{Description}:
2080 The thread placement can be either specified using an abstract name or by an
2081 explicit list of the places. The abstract names @code{threads}, @code{cores}
2082 and @code{sockets} can be optionally followed by a positive number in
2083 parentheses, which denotes the how many places shall be created. With
2084 @code{threads} each place corresponds to a single hardware thread; @code{cores}
2085 to a single core with the corresponding number of hardware threads; and with
2086 @code{sockets} the place corresponds to a single socket. The resulting
2087 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
2090 Alternatively, the placement can be specified explicitly as comma-separated
2091 list of places. A place is specified by set of nonnegative numbers in curly
2092 braces, denoting the denoting the hardware threads. The hardware threads
2093 belonging to a place can either be specified as comma-separated list of
2094 nonnegative thread numbers or using an interval. Multiple places can also be
2095 either specified by a comma-separated list of places or by an interval. To
2096 specify an interval, a colon followed by the count is placed after after
2097 the hardware thread number or the place. Optionally, the length can be
2098 followed by a colon and the stride number -- otherwise a unit stride is
2099 assumed. For instance, the following specifies the same places list:
2100 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
2101 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
2103 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
2104 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
2105 between CPUs following no placement policy.
2107 @item @emph{See also}:
2108 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
2109 @ref{OMP_DISPLAY_ENV}
2111 @item @emph{Reference}:
2112 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
2118 @section @env{OMP_STACKSIZE} -- Set default thread stack size
2119 @cindex Environment Variable
2121 @item @emph{Description}:
2122 Set the default thread stack size in kilobytes, unless the number
2123 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
2124 case the size is, respectively, in bytes, kilobytes, megabytes
2125 or gigabytes. This is different from @code{pthread_attr_setstacksize}
2126 which gets the number of bytes as an argument. If the stack size cannot
2127 be set due to system constraints, an error is reported and the initial
2128 stack size is left unchanged. If undefined, the stack size is system
2131 @item @emph{Reference}:
2132 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
2138 @section @env{OMP_SCHEDULE} -- How threads are scheduled
2139 @cindex Environment Variable
2140 @cindex Implementation specific setting
2142 @item @emph{Description}:
2143 Allows to specify @code{schedule type} and @code{chunk size}.
2144 The value of the variable shall have the form: @code{type[,chunk]} where
2145 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
2146 The optional @code{chunk} size shall be a positive integer. If undefined,
2147 dynamic scheduling and a chunk size of 1 is used.
2149 @item @emph{See also}:
2150 @ref{omp_set_schedule}
2152 @item @emph{Reference}:
2153 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
2158 @node OMP_THREAD_LIMIT
2159 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
2160 @cindex Environment Variable
2162 @item @emph{Description}:
2163 Specifies the number of threads to use for the whole program. The
2164 value of this variable shall be a positive integer. If undefined,
2165 the number of threads is not limited.
2167 @item @emph{See also}:
2168 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
2170 @item @emph{Reference}:
2171 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
2176 @node OMP_WAIT_POLICY
2177 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
2178 @cindex Environment Variable
2180 @item @emph{Description}:
2181 Specifies whether waiting threads should be active or passive. If
2182 the value is @code{PASSIVE}, waiting threads should not consume CPU
2183 power while waiting; while the value is @code{ACTIVE} specifies that
2184 they should. If undefined, threads wait actively for a short time
2185 before waiting passively.
2187 @item @emph{See also}:
2188 @ref{GOMP_SPINCOUNT}
2190 @item @emph{Reference}:
2191 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
2196 @node GOMP_CPU_AFFINITY
2197 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
2198 @cindex Environment Variable
2200 @item @emph{Description}:
2201 Binds threads to specific CPUs. The variable should contain a space-separated
2202 or comma-separated list of CPUs. This list may contain different kinds of
2203 entries: either single CPU numbers in any order, a range of CPUs (M-N)
2204 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
2205 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
2206 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
2207 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
2208 and 14 respectively and then start assigning back from the beginning of
2209 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
2211 There is no GNU OpenMP library routine to determine whether a CPU affinity
2212 specification is in effect. As a workaround, language-specific library
2213 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
2214 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
2215 environment variable. A defined CPU affinity on startup cannot be changed
2216 or disabled during the runtime of the application.
2218 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
2219 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
2220 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
2221 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
2223 @item @emph{See also}:
2224 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
2229 @node GOMP_STACKSIZE
2230 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
2231 @cindex Environment Variable
2232 @cindex Implementation specific setting
2234 @item @emph{Description}:
2235 Set the default thread stack size in kilobytes. This is different from
2236 @code{pthread_attr_setstacksize} which gets the number of bytes as an
2237 argument. If the stack size cannot be set due to system constraints, an
2238 error is reported and the initial stack size is left unchanged. If undefined,
2239 the stack size is system dependent.
2241 @item @emph{See also}:
2244 @item @emph{Reference}:
2245 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
2246 GCC Patches Mailinglist},
2247 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
2248 GCC Patches Mailinglist}
2253 @node GOMP_SPINCOUNT
2254 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
2255 @cindex Environment Variable
2256 @cindex Implementation specific setting
2258 @item @emph{Description}:
2259 Determines how long a threads waits actively with consuming CPU power
2260 before waiting passively without consuming CPU power. The value may be
2261 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
2262 integer which gives the number of spins of the busy-wait loop. The
2263 integer may optionally be followed by the following suffixes acting
2264 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
2265 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
2266 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
2267 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
2268 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
2269 If there are more OpenMP threads than available CPUs, 1000 and 100
2270 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
2271 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
2272 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
2274 @item @emph{See also}:
2275 @ref{OMP_WAIT_POLICY}
2280 @c ---------------------------------------------------------------------
2282 @c ---------------------------------------------------------------------
2284 @node The libgomp ABI
2285 @chapter The libgomp ABI
2287 The following sections present notes on the external ABI as
2288 presented by libgomp. Only maintainers should need them.
2291 * Implementing MASTER construct::
2292 * Implementing CRITICAL construct::
2293 * Implementing ATOMIC construct::
2294 * Implementing FLUSH construct::
2295 * Implementing BARRIER construct::
2296 * Implementing THREADPRIVATE construct::
2297 * Implementing PRIVATE clause::
2298 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
2299 * Implementing REDUCTION clause::
2300 * Implementing PARALLEL construct::
2301 * Implementing FOR construct::
2302 * Implementing ORDERED construct::
2303 * Implementing SECTIONS construct::
2304 * Implementing SINGLE construct::
2305 * Implementing OpenACC's PARALLEL construct::
2309 @node Implementing MASTER construct
2310 @section Implementing MASTER construct
2313 if (omp_get_thread_num () == 0)
2317 Alternately, we generate two copies of the parallel subfunction
2318 and only include this in the version run by the master thread.
2319 Surely this is not worthwhile though...
2323 @node Implementing CRITICAL construct
2324 @section Implementing CRITICAL construct
2326 Without a specified name,
2329 void GOMP_critical_start (void);
2330 void GOMP_critical_end (void);
2333 so that we don't get COPY relocations from libgomp to the main
2336 With a specified name, use omp_set_lock and omp_unset_lock with
2337 name being transformed into a variable declared like
2340 omp_lock_t gomp_critical_user_<name> __attribute__((common))
2343 Ideally the ABI would specify that all zero is a valid unlocked
2344 state, and so we wouldn't need to initialize this at
2349 @node Implementing ATOMIC construct
2350 @section Implementing ATOMIC construct
2352 The target should implement the @code{__sync} builtins.
2354 Failing that we could add
2357 void GOMP_atomic_enter (void)
2358 void GOMP_atomic_exit (void)
2361 which reuses the regular lock code, but with yet another lock
2362 object private to the library.
2366 @node Implementing FLUSH construct
2367 @section Implementing FLUSH construct
2369 Expands to the @code{__sync_synchronize} builtin.
2373 @node Implementing BARRIER construct
2374 @section Implementing BARRIER construct
2377 void GOMP_barrier (void)
2381 @node Implementing THREADPRIVATE construct
2382 @section Implementing THREADPRIVATE construct
2384 In _most_ cases we can map this directly to @code{__thread}. Except
2385 that OMP allows constructors for C++ objects. We can either
2386 refuse to support this (how often is it used?) or we can
2387 implement something akin to .ctors.
2389 Even more ideally, this ctor feature is handled by extensions
2390 to the main pthreads library. Failing that, we can have a set
2391 of entry points to register ctor functions to be called.
2395 @node Implementing PRIVATE clause
2396 @section Implementing PRIVATE clause
2398 In association with a PARALLEL, or within the lexical extent
2399 of a PARALLEL block, the variable becomes a local variable in
2400 the parallel subfunction.
2402 In association with FOR or SECTIONS blocks, create a new
2403 automatic variable within the current function. This preserves
2404 the semantic of new variable creation.
2408 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
2409 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
2411 This seems simple enough for PARALLEL blocks. Create a private
2412 struct for communicating between the parent and subfunction.
2413 In the parent, copy in values for scalar and "small" structs;
2414 copy in addresses for others TREE_ADDRESSABLE types. In the
2415 subfunction, copy the value into the local variable.
2417 It is not clear what to do with bare FOR or SECTION blocks.
2418 The only thing I can figure is that we do something like:
2421 #pragma omp for firstprivate(x) lastprivate(y)
2422 for (int i = 0; i < n; ++i)
2439 where the "x=x" and "y=y" assignments actually have different
2440 uids for the two variables, i.e. not something you could write
2441 directly in C. Presumably this only makes sense if the "outer"
2442 x and y are global variables.
2444 COPYPRIVATE would work the same way, except the structure
2445 broadcast would have to happen via SINGLE machinery instead.
2449 @node Implementing REDUCTION clause
2450 @section Implementing REDUCTION clause
2452 The private struct mentioned in the previous section should have
2453 a pointer to an array of the type of the variable, indexed by the
2454 thread's @var{team_id}. The thread stores its final value into the
2455 array, and after the barrier, the master thread iterates over the
2456 array to collect the values.
2459 @node Implementing PARALLEL construct
2460 @section Implementing PARALLEL construct
2463 #pragma omp parallel
2472 void subfunction (void *data)
2479 GOMP_parallel_start (subfunction, &data, num_threads);
2480 subfunction (&data);
2481 GOMP_parallel_end ();
2485 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
2488 The @var{FN} argument is the subfunction to be run in parallel.
2490 The @var{DATA} argument is a pointer to a structure used to
2491 communicate data in and out of the subfunction, as discussed
2492 above with respect to FIRSTPRIVATE et al.
2494 The @var{NUM_THREADS} argument is 1 if an IF clause is present
2495 and false, or the value of the NUM_THREADS clause, if
2498 The function needs to create the appropriate number of
2499 threads and/or launch them from the dock. It needs to
2500 create the team structure and assign team ids.
2503 void GOMP_parallel_end (void)
2506 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
2510 @node Implementing FOR construct
2511 @section Implementing FOR construct
2514 #pragma omp parallel for
2515 for (i = lb; i <= ub; i++)
2522 void subfunction (void *data)
2525 while (GOMP_loop_static_next (&_s0, &_e0))
2528 for (i = _s0; i < _e1; i++)
2531 GOMP_loop_end_nowait ();
2534 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
2536 GOMP_parallel_end ();
2540 #pragma omp for schedule(runtime)
2541 for (i = 0; i < n; i++)
2550 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
2553 for (i = _s0, i < _e0; i++)
2555 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
2560 Note that while it looks like there is trickiness to propagating
2561 a non-constant STEP, there isn't really. We're explicitly allowed
2562 to evaluate it as many times as we want, and any variables involved
2563 should automatically be handled as PRIVATE or SHARED like any other
2564 variables. So the expression should remain evaluable in the
2565 subfunction. We can also pull it into a local variable if we like,
2566 but since its supposed to remain unchanged, we can also not if we like.
2568 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
2569 able to get away with no work-sharing context at all, since we can
2570 simply perform the arithmetic directly in each thread to divide up
2571 the iterations. Which would mean that we wouldn't need to call any
2574 There are separate routines for handling loops with an ORDERED
2575 clause. Bookkeeping for that is non-trivial...
2579 @node Implementing ORDERED construct
2580 @section Implementing ORDERED construct
2583 void GOMP_ordered_start (void)
2584 void GOMP_ordered_end (void)
2589 @node Implementing SECTIONS construct
2590 @section Implementing SECTIONS construct
2595 #pragma omp sections
2609 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2626 @node Implementing SINGLE construct
2627 @section Implementing SINGLE construct
2641 if (GOMP_single_start ())
2649 #pragma omp single copyprivate(x)
2656 datap = GOMP_single_copy_start ();
2661 GOMP_single_copy_end (&data);
2670 @node Implementing OpenACC's PARALLEL construct
2671 @section Implementing OpenACC's PARALLEL construct
2674 void GOACC_parallel ()
2679 @c ---------------------------------------------------------------------
2681 @c ---------------------------------------------------------------------
2683 @node Reporting Bugs
2684 @chapter Reporting Bugs
2686 Bugs in the GNU OpenACC or OpenMP implementation should be reported via
2687 @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. For OpenMP cases, please add
2688 "openmp" to the keywords field in the bug report.
2692 @c ---------------------------------------------------------------------
2693 @c GNU General Public License
2694 @c ---------------------------------------------------------------------
2696 @include gpl_v3.texi
2700 @c ---------------------------------------------------------------------
2701 @c GNU Free Documentation License
2702 @c ---------------------------------------------------------------------
2708 @c ---------------------------------------------------------------------
2709 @c Funding Free Software
2710 @c ---------------------------------------------------------------------
2712 @include funding.texi
2714 @c ---------------------------------------------------------------------
2716 @c ---------------------------------------------------------------------
2719 @unnumbered Library Index