1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2015 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 OpenMP runtime library
37 This manual documents the GNU implementation of the OpenMP API for
38 multi-platform shared-memory parallel programming in C/C++ and Fortran.
40 Published by the Free Software Foundation
41 51 Franklin Street, Fifth Floor
42 Boston, MA 02110-1301 USA
48 @setchapternewpage odd
51 @title The GNU OpenMP Implementation
53 @vskip 0pt plus 1filll
54 @comment For the @value{version-GCC} Version*
56 Published by the Free Software Foundation @*
57 51 Franklin Street, Fifth Floor@*
58 Boston, MA 02110-1301, USA@*
72 This manual documents the usage of libgomp, the GNU implementation of the
73 @uref{http://www.openmp.org, OpenMP} Application Programming Interface (API)
74 for multi-platform shared-memory parallel programming in C/C++ and Fortran.
79 @comment When you add a new menu item, please keep the right hand
80 @comment aligned to the same column. Do not use tabs. This provides
81 @comment better formatting.
84 * Enabling OpenMP:: How to enable OpenMP for your applications.
85 * Runtime Library Routines:: The OpenMP runtime application programming
87 * Environment Variables:: Influencing runtime behavior with environment
89 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
90 * Reporting Bugs:: How to report bugs in GNU OpenMP.
91 * Copying:: GNU general public license says
92 how you can copy and share libgomp.
93 * GNU Free Documentation License::
94 How you can copy and share this manual.
95 * Funding:: How to help assure continued work for free
97 * Library Index:: Index of this documentation.
101 @c ---------------------------------------------------------------------
103 @c ---------------------------------------------------------------------
105 @node Enabling OpenMP
106 @chapter Enabling OpenMP
108 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
109 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
110 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
111 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
112 @code{!$} conditional compilation sentinels in free form and @code{c$},
113 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
114 arranges for automatic linking of the OpenMP runtime library
115 (@ref{Runtime Library Routines}).
117 A complete description of all OpenMP directives accepted may be found in
118 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
122 @c ---------------------------------------------------------------------
123 @c Runtime Library Routines
124 @c ---------------------------------------------------------------------
126 @node Runtime Library Routines
127 @chapter Runtime Library Routines
129 The runtime routines described here are defined by Section 3 of the OpenMP
130 specification in version 4.0. The routines are structured in following
134 Control threads, processors and the parallel environment. They have C
135 linkage, and do not throw exceptions.
137 * omp_get_active_level:: Number of active parallel regions
138 * omp_get_ancestor_thread_num:: Ancestor thread ID
139 * omp_get_cancellation:: Whether cancellation support is enabled
140 * omp_get_default_device:: Get the default device for target regions
141 * omp_get_dynamic:: Dynamic teams setting
142 * omp_get_level:: Number of parallel regions
143 * omp_get_max_active_levels:: Maximum number of active regions
144 * omp_get_max_threads:: Maximum number of threads of parallel region
145 * omp_get_nested:: Nested parallel regions
146 * omp_get_num_devices:: Number of target devices
147 * omp_get_num_procs:: Number of processors online
148 * omp_get_num_teams:: Number of teams
149 * omp_get_num_threads:: Size of the active team
150 * omp_get_proc_bind:: Whether theads may be moved between CPUs
151 * omp_get_schedule:: Obtain the runtime scheduling method
152 * omp_get_team_num:: Get team number
153 * omp_get_team_size:: Number of threads in a team
154 * omp_get_thread_limit:: Maximum number of threads
155 * omp_get_thread_num:: Current thread ID
156 * omp_in_parallel:: Whether a parallel region is active
157 * omp_in_final:: Whether in final or included task region
158 * omp_is_initial_device:: Whether executing on the host device
159 * omp_set_default_device:: Set the default device for target regions
160 * omp_set_dynamic:: Enable/disable dynamic teams
161 * omp_set_max_active_levels:: Limits the number of active parallel regions
162 * omp_set_nested:: Enable/disable nested parallel regions
163 * omp_set_num_threads:: Set upper team size limit
164 * omp_set_schedule:: Set the runtime scheduling method
166 Initialize, set, test, unset and destroy simple and nested locks.
168 * omp_init_lock:: Initialize simple lock
169 * omp_set_lock:: Wait for and set simple lock
170 * omp_test_lock:: Test and set simple lock if available
171 * omp_unset_lock:: Unset simple lock
172 * omp_destroy_lock:: Destroy simple lock
173 * omp_init_nest_lock:: Initialize nested lock
174 * omp_set_nest_lock:: Wait for and set simple lock
175 * omp_test_nest_lock:: Test and set nested lock if available
176 * omp_unset_nest_lock:: Unset nested lock
177 * omp_destroy_nest_lock:: Destroy nested lock
179 Portable, thread-based, wall clock timer.
181 * omp_get_wtick:: Get timer precision.
182 * omp_get_wtime:: Elapsed wall clock time.
187 @node omp_get_active_level
188 @section @code{omp_get_active_level} -- Number of parallel regions
190 @item @emph{Description}:
191 This function returns the nesting level for the active parallel blocks,
192 which enclose the calling call.
195 @multitable @columnfractions .20 .80
196 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
199 @item @emph{Fortran}:
200 @multitable @columnfractions .20 .80
201 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
204 @item @emph{See also}:
205 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
207 @item @emph{Reference}:
208 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
213 @node omp_get_ancestor_thread_num
214 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
216 @item @emph{Description}:
217 This function returns the thread identification number for the given
218 nesting level of the current thread. For values of @var{level} outside
219 zero to @code{omp_get_level} -1 is returned; if @var{level} is
220 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
223 @multitable @columnfractions .20 .80
224 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
227 @item @emph{Fortran}:
228 @multitable @columnfractions .20 .80
229 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
230 @item @tab @code{integer level}
233 @item @emph{See also}:
234 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
236 @item @emph{Reference}:
237 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
242 @node omp_get_cancellation
243 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
245 @item @emph{Description}:
246 This function returns @code{true} if cancellation is activated, @code{false}
247 otherwise. Here, @code{true} and @code{false} represent their language-specific
248 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
252 @multitable @columnfractions .20 .80
253 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
256 @item @emph{Fortran}:
257 @multitable @columnfractions .20 .80
258 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
261 @item @emph{See also}:
262 @ref{OMP_CANCELLATION}
264 @item @emph{Reference}:
265 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
270 @node omp_get_default_device
271 @section @code{omp_get_default_device} -- Get the default device for target regions
273 @item @emph{Description}:
274 Get the default device for target regions without device clause.
277 @multitable @columnfractions .20 .80
278 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
281 @item @emph{Fortran}:
282 @multitable @columnfractions .20 .80
283 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
286 @item @emph{See also}:
287 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
289 @item @emph{Reference}:
290 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
295 @node omp_get_dynamic
296 @section @code{omp_get_dynamic} -- Dynamic teams setting
298 @item @emph{Description}:
299 This function returns @code{true} if enabled, @code{false} otherwise.
300 Here, @code{true} and @code{false} represent their language-specific
303 The dynamic team setting may be initialized at startup by the
304 @env{OMP_DYNAMIC} environment variable or at runtime using
305 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
309 @multitable @columnfractions .20 .80
310 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
313 @item @emph{Fortran}:
314 @multitable @columnfractions .20 .80
315 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
318 @item @emph{See also}:
319 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
321 @item @emph{Reference}:
322 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
328 @section @code{omp_get_level} -- Obtain the current nesting level
330 @item @emph{Description}:
331 This function returns the nesting level for the parallel blocks,
332 which enclose the calling call.
335 @multitable @columnfractions .20 .80
336 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
339 @item @emph{Fortran}:
340 @multitable @columnfractions .20 .80
341 @item @emph{Interface}: @tab @code{integer function omp_level()}
344 @item @emph{See also}:
345 @ref{omp_get_active_level}
347 @item @emph{Reference}:
348 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
353 @node omp_get_max_active_levels
354 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
356 @item @emph{Description}:
357 This function obtains the maximum allowed number of nested, active parallel regions.
360 @multitable @columnfractions .20 .80
361 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
364 @item @emph{Fortran}:
365 @multitable @columnfractions .20 .80
366 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
369 @item @emph{See also}:
370 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
372 @item @emph{Reference}:
373 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
378 @node omp_get_max_threads
379 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
381 @item @emph{Description}:
382 Return the maximum number of threads used for the current parallel region
383 that does not use the clause @code{num_threads}.
386 @multitable @columnfractions .20 .80
387 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
390 @item @emph{Fortran}:
391 @multitable @columnfractions .20 .80
392 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
395 @item @emph{See also}:
396 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
398 @item @emph{Reference}:
399 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
405 @section @code{omp_get_nested} -- Nested parallel regions
407 @item @emph{Description}:
408 This function returns @code{true} if nested parallel regions are
409 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
410 represent their language-specific counterparts.
412 Nested parallel regions may be initialized at startup by the
413 @env{OMP_NESTED} environment variable or at runtime using
414 @code{omp_set_nested}. If undefined, nested parallel regions are
418 @multitable @columnfractions .20 .80
419 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
422 @item @emph{Fortran}:
423 @multitable @columnfractions .20 .80
424 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
427 @item @emph{See also}:
428 @ref{omp_set_nested}, @ref{OMP_NESTED}
430 @item @emph{Reference}:
431 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
436 @node omp_get_num_devices
437 @section @code{omp_get_num_devices} -- Number of target devices
439 @item @emph{Description}:
440 Returns the number of target devices.
443 @multitable @columnfractions .20 .80
444 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
447 @item @emph{Fortran}:
448 @multitable @columnfractions .20 .80
449 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
452 @item @emph{Reference}:
453 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
458 @node omp_get_num_procs
459 @section @code{omp_get_num_procs} -- Number of processors online
461 @item @emph{Description}:
462 Returns the number of processors online on that device.
465 @multitable @columnfractions .20 .80
466 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
469 @item @emph{Fortran}:
470 @multitable @columnfractions .20 .80
471 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
474 @item @emph{Reference}:
475 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
480 @node omp_get_num_teams
481 @section @code{omp_get_num_teams} -- Number of teams
483 @item @emph{Description}:
484 Returns the number of teams in the current team region.
487 @multitable @columnfractions .20 .80
488 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
491 @item @emph{Fortran}:
492 @multitable @columnfractions .20 .80
493 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
496 @item @emph{Reference}:
497 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
502 @node omp_get_num_threads
503 @section @code{omp_get_num_threads} -- Size of the active team
505 @item @emph{Description}:
506 Returns the number of threads in the current team. In a sequential section of
507 the program @code{omp_get_num_threads} returns 1.
509 The default team size may be initialized at startup by the
510 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
511 of the current team may be set either by the @code{NUM_THREADS}
512 clause or by @code{omp_set_num_threads}. If none of the above were
513 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
514 one thread per CPU online is used.
517 @multitable @columnfractions .20 .80
518 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
521 @item @emph{Fortran}:
522 @multitable @columnfractions .20 .80
523 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
526 @item @emph{See also}:
527 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
529 @item @emph{Reference}:
530 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
535 @node omp_get_proc_bind
536 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
538 @item @emph{Description}:
539 This functions returns the currently active thread affinity policy, which is
540 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
541 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
542 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
545 @multitable @columnfractions .20 .80
546 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
549 @item @emph{Fortran}:
550 @multitable @columnfractions .20 .80
551 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
554 @item @emph{See also}:
555 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
557 @item @emph{Reference}:
558 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
563 @node omp_get_schedule
564 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
566 @item @emph{Description}:
567 Obtain the runtime scheduling method. The @var{kind} argument will be
568 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
569 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
570 @var{modifier}, is set to the chunk size.
573 @multitable @columnfractions .20 .80
574 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
577 @item @emph{Fortran}:
578 @multitable @columnfractions .20 .80
579 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
580 @item @tab @code{integer(kind=omp_sched_kind) kind}
581 @item @tab @code{integer modifier}
584 @item @emph{See also}:
585 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
587 @item @emph{Reference}:
588 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
593 @node omp_get_team_num
594 @section @code{omp_get_team_num} -- Get team number
596 @item @emph{Description}:
597 Returns the team number of the calling thread.
600 @multitable @columnfractions .20 .80
601 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
604 @item @emph{Fortran}:
605 @multitable @columnfractions .20 .80
606 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
609 @item @emph{Reference}:
610 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
615 @node omp_get_team_size
616 @section @code{omp_get_team_size} -- Number of threads in a team
618 @item @emph{Description}:
619 This function returns the number of threads in a thread team to which
620 either the current thread or its ancestor belongs. For values of @var{level}
621 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
622 1 is returned, and for @code{omp_get_level}, the result is identical
623 to @code{omp_get_num_threads}.
626 @multitable @columnfractions .20 .80
627 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
630 @item @emph{Fortran}:
631 @multitable @columnfractions .20 .80
632 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
633 @item @tab @code{integer level}
636 @item @emph{See also}:
637 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
639 @item @emph{Reference}:
640 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
645 @node omp_get_thread_limit
646 @section @code{omp_get_thread_limit} -- Maximum number of threads
648 @item @emph{Description}:
649 Return the maximum number of threads of the program.
652 @multitable @columnfractions .20 .80
653 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
656 @item @emph{Fortran}:
657 @multitable @columnfractions .20 .80
658 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
661 @item @emph{See also}:
662 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
664 @item @emph{Reference}:
665 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
670 @node omp_get_thread_num
671 @section @code{omp_get_thread_num} -- Current thread ID
673 @item @emph{Description}:
674 Returns a unique thread identification number within the current team.
675 In a sequential parts of the program, @code{omp_get_thread_num}
676 always returns 0. In parallel regions the return value varies
677 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
678 value of the master thread of a team is always 0.
681 @multitable @columnfractions .20 .80
682 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
685 @item @emph{Fortran}:
686 @multitable @columnfractions .20 .80
687 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
690 @item @emph{See also}:
691 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
693 @item @emph{Reference}:
694 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
699 @node omp_in_parallel
700 @section @code{omp_in_parallel} -- Whether a parallel region is active
702 @item @emph{Description}:
703 This function returns @code{true} if currently running in parallel,
704 @code{false} otherwise. Here, @code{true} and @code{false} represent
705 their language-specific counterparts.
708 @multitable @columnfractions .20 .80
709 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
712 @item @emph{Fortran}:
713 @multitable @columnfractions .20 .80
714 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
717 @item @emph{Reference}:
718 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
723 @section @code{omp_in_final} -- Whether in final or included task region
725 @item @emph{Description}:
726 This function returns @code{true} if currently running in a final
727 or included task region, @code{false} otherwise. Here, @code{true}
728 and @code{false} represent their language-specific counterparts.
731 @multitable @columnfractions .20 .80
732 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
735 @item @emph{Fortran}:
736 @multitable @columnfractions .20 .80
737 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
740 @item @emph{Reference}:
741 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
746 @node omp_is_initial_device
747 @section @code{omp_is_initial_device} -- Whether executing on the host device
749 @item @emph{Description}:
750 This function returns @code{true} if currently running on the host device,
751 @code{false} otherwise. Here, @code{true} and @code{false} represent
752 their language-specific counterparts.
755 @multitable @columnfractions .20 .80
756 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
759 @item @emph{Fortran}:
760 @multitable @columnfractions .20 .80
761 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
764 @item @emph{Reference}:
765 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
770 @node omp_set_default_device
771 @section @code{omp_set_default_device} -- Set the default device for target regions
773 @item @emph{Description}:
774 Set the default device for target regions without device clause. The argument
775 shall be a nonnegative device number.
778 @multitable @columnfractions .20 .80
779 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
782 @item @emph{Fortran}:
783 @multitable @columnfractions .20 .80
784 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
785 @item @tab @code{integer device_num}
788 @item @emph{See also}:
789 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
791 @item @emph{Reference}:
792 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
797 @node omp_set_dynamic
798 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
800 @item @emph{Description}:
801 Enable or disable the dynamic adjustment of the number of threads
802 within a team. The function takes the language-specific equivalent
803 of @code{true} and @code{false}, where @code{true} enables dynamic
804 adjustment of team sizes and @code{false} disables it.
807 @multitable @columnfractions .20 .80
808 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
811 @item @emph{Fortran}:
812 @multitable @columnfractions .20 .80
813 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
814 @item @tab @code{logical, intent(in) :: dynamic_threads}
817 @item @emph{See also}:
818 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
820 @item @emph{Reference}:
821 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
826 @node omp_set_max_active_levels
827 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
829 @item @emph{Description}:
830 This function limits the maximum allowed number of nested, active
834 @multitable @columnfractions .20 .80
835 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
838 @item @emph{Fortran}:
839 @multitable @columnfractions .20 .80
840 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
841 @item @tab @code{integer max_levels}
844 @item @emph{See also}:
845 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
847 @item @emph{Reference}:
848 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
854 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
856 @item @emph{Description}:
857 Enable or disable nested parallel regions, i.e., whether team members
858 are allowed to create new teams. The function takes the language-specific
859 equivalent of @code{true} and @code{false}, where @code{true} enables
860 dynamic adjustment of team sizes and @code{false} disables it.
863 @multitable @columnfractions .20 .80
864 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
867 @item @emph{Fortran}:
868 @multitable @columnfractions .20 .80
869 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
870 @item @tab @code{logical, intent(in) :: nested}
873 @item @emph{See also}:
874 @ref{OMP_NESTED}, @ref{omp_get_nested}
876 @item @emph{Reference}:
877 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
882 @node omp_set_num_threads
883 @section @code{omp_set_num_threads} -- Set upper team size limit
885 @item @emph{Description}:
886 Specifies the number of threads used by default in subsequent parallel
887 sections, if those do not specify a @code{num_threads} clause. The
888 argument of @code{omp_set_num_threads} shall be a positive integer.
891 @multitable @columnfractions .20 .80
892 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
895 @item @emph{Fortran}:
896 @multitable @columnfractions .20 .80
897 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
898 @item @tab @code{integer, intent(in) :: num_threads}
901 @item @emph{See also}:
902 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
904 @item @emph{Reference}:
905 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
910 @node omp_set_schedule
911 @section @code{omp_set_schedule} -- Set the runtime scheduling method
913 @item @emph{Description}:
914 Sets the runtime scheduling method. The @var{kind} argument can have the
915 value @code{omp_sched_static}, @code{omp_sched_dynamic},
916 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
917 @code{omp_sched_auto}, the chunk size is set to the value of
918 @var{modifier} if positive, or to the default value if zero or negative.
919 For @code{omp_sched_auto} the @var{modifier} argument is ignored.
922 @multitable @columnfractions .20 .80
923 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
926 @item @emph{Fortran}:
927 @multitable @columnfractions .20 .80
928 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
929 @item @tab @code{integer(kind=omp_sched_kind) kind}
930 @item @tab @code{integer modifier}
933 @item @emph{See also}:
934 @ref{omp_get_schedule}
937 @item @emph{Reference}:
938 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
944 @section @code{omp_init_lock} -- Initialize simple lock
946 @item @emph{Description}:
947 Initialize a simple lock. After initialization, the lock is in
951 @multitable @columnfractions .20 .80
952 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
955 @item @emph{Fortran}:
956 @multitable @columnfractions .20 .80
957 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
958 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
961 @item @emph{See also}:
962 @ref{omp_destroy_lock}
964 @item @emph{Reference}:
965 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
971 @section @code{omp_set_lock} -- Wait for and set simple lock
973 @item @emph{Description}:
974 Before setting a simple lock, the lock variable must be initialized by
975 @code{omp_init_lock}. The calling thread is blocked until the lock
976 is available. If the lock is already held by the current thread,
980 @multitable @columnfractions .20 .80
981 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
984 @item @emph{Fortran}:
985 @multitable @columnfractions .20 .80
986 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
987 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
990 @item @emph{See also}:
991 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
993 @item @emph{Reference}:
994 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1000 @section @code{omp_test_lock} -- Test and set simple lock if available
1002 @item @emph{Description}:
1003 Before setting a simple lock, the lock variable must be initialized by
1004 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1005 does not block if the lock is not available. This function returns
1006 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1007 @code{false} represent their language-specific counterparts.
1010 @multitable @columnfractions .20 .80
1011 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1014 @item @emph{Fortran}:
1015 @multitable @columnfractions .20 .80
1016 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1017 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1020 @item @emph{See also}:
1021 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1023 @item @emph{Reference}:
1024 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1029 @node omp_unset_lock
1030 @section @code{omp_unset_lock} -- Unset simple lock
1032 @item @emph{Description}:
1033 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1034 or @code{omp_test_lock} before. In addition, the lock must be held by the
1035 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1036 or more threads attempted to set the lock before, one of them is chosen to,
1037 again, set the lock to itself.
1040 @multitable @columnfractions .20 .80
1041 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1044 @item @emph{Fortran}:
1045 @multitable @columnfractions .20 .80
1046 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1047 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1050 @item @emph{See also}:
1051 @ref{omp_set_lock}, @ref{omp_test_lock}
1053 @item @emph{Reference}:
1054 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1059 @node omp_destroy_lock
1060 @section @code{omp_destroy_lock} -- Destroy simple lock
1062 @item @emph{Description}:
1063 Destroy a simple lock. In order to be destroyed, a simple lock must be
1064 in the unlocked state.
1067 @multitable @columnfractions .20 .80
1068 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1071 @item @emph{Fortran}:
1072 @multitable @columnfractions .20 .80
1073 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1074 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1077 @item @emph{See also}:
1080 @item @emph{Reference}:
1081 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1086 @node omp_init_nest_lock
1087 @section @code{omp_init_nest_lock} -- Initialize nested lock
1089 @item @emph{Description}:
1090 Initialize a nested lock. After initialization, the lock is in
1091 an unlocked state and the nesting count is set to zero.
1094 @multitable @columnfractions .20 .80
1095 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1098 @item @emph{Fortran}:
1099 @multitable @columnfractions .20 .80
1100 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1101 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1104 @item @emph{See also}:
1105 @ref{omp_destroy_nest_lock}
1107 @item @emph{Reference}:
1108 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1112 @node omp_set_nest_lock
1113 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1115 @item @emph{Description}:
1116 Before setting a nested lock, the lock variable must be initialized by
1117 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1118 is available. If the lock is already held by the current thread, the
1119 nesting count for the lock is incremented.
1122 @multitable @columnfractions .20 .80
1123 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1126 @item @emph{Fortran}:
1127 @multitable @columnfractions .20 .80
1128 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1129 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1132 @item @emph{See also}:
1133 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1135 @item @emph{Reference}:
1136 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1141 @node omp_test_nest_lock
1142 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1144 @item @emph{Description}:
1145 Before setting a nested lock, the lock variable must be initialized by
1146 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1147 @code{omp_test_nest_lock} does not block if the lock is not available.
1148 If the lock is already held by the current thread, the new nesting count
1149 is returned. Otherwise, the return value equals zero.
1152 @multitable @columnfractions .20 .80
1153 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1156 @item @emph{Fortran}:
1157 @multitable @columnfractions .20 .80
1158 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1159 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1163 @item @emph{See also}:
1164 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1166 @item @emph{Reference}:
1167 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1172 @node omp_unset_nest_lock
1173 @section @code{omp_unset_nest_lock} -- Unset nested lock
1175 @item @emph{Description}:
1176 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1177 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1178 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1179 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1180 one of them is chosen to, again, set the lock to itself.
1183 @multitable @columnfractions .20 .80
1184 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1187 @item @emph{Fortran}:
1188 @multitable @columnfractions .20 .80
1189 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1190 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1193 @item @emph{See also}:
1194 @ref{omp_set_nest_lock}
1196 @item @emph{Reference}:
1197 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1202 @node omp_destroy_nest_lock
1203 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1205 @item @emph{Description}:
1206 Destroy a nested lock. In order to be destroyed, a nested lock must be
1207 in the unlocked state and its nesting count must equal zero.
1210 @multitable @columnfractions .20 .80
1211 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1214 @item @emph{Fortran}:
1215 @multitable @columnfractions .20 .80
1216 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1217 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1220 @item @emph{See also}:
1223 @item @emph{Reference}:
1224 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1230 @section @code{omp_get_wtick} -- Get timer precision
1232 @item @emph{Description}:
1233 Gets the timer precision, i.e., the number of seconds between two
1234 successive clock ticks.
1237 @multitable @columnfractions .20 .80
1238 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1241 @item @emph{Fortran}:
1242 @multitable @columnfractions .20 .80
1243 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1246 @item @emph{See also}:
1249 @item @emph{Reference}:
1250 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1256 @section @code{omp_get_wtime} -- Elapsed wall clock time
1258 @item @emph{Description}:
1259 Elapsed wall clock time in seconds. The time is measured per thread, no
1260 guarantee can be made that two distinct threads measure the same time.
1261 Time is measured from some "time in the past", which is an arbitrary time
1262 guaranteed not to change during the execution of the program.
1265 @multitable @columnfractions .20 .80
1266 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1269 @item @emph{Fortran}:
1270 @multitable @columnfractions .20 .80
1271 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1274 @item @emph{See also}:
1277 @item @emph{Reference}:
1278 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
1283 @c ---------------------------------------------------------------------
1284 @c Environment Variables
1285 @c ---------------------------------------------------------------------
1287 @node Environment Variables
1288 @chapter Environment Variables
1290 The environment variables which beginning with @env{OMP_} are defined by
1291 section 4 of the OpenMP specification in version 4.0, while those
1292 beginning with @env{GOMP_} are GNU extensions.
1295 * OMP_CANCELLATION:: Set whether cancellation is activated
1296 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1297 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1298 * OMP_DYNAMIC:: Dynamic adjustment of threads
1299 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1300 * OMP_NESTED:: Nested parallel regions
1301 * OMP_NUM_THREADS:: Specifies the number of threads to use
1302 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1303 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1304 * OMP_STACKSIZE:: Set default thread stack size
1305 * OMP_SCHEDULE:: How threads are scheduled
1306 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1307 * OMP_WAIT_POLICY:: How waiting threads are handled
1308 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1309 * GOMP_STACKSIZE:: Set default thread stack size
1310 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1314 @node OMP_CANCELLATION
1315 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1316 @cindex Environment Variable
1318 @item @emph{Description}:
1319 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1320 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1322 @item @emph{See also}:
1323 @ref{omp_get_cancellation}
1325 @item @emph{Reference}:
1326 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1331 @node OMP_DISPLAY_ENV
1332 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1333 @cindex Environment Variable
1335 @item @emph{Description}:
1336 If set to @code{TRUE}, the OpenMP version number and the values
1337 associated with the OpenMP environment variables are printed to @code{stderr}.
1338 If set to @code{VERBOSE}, it additionally shows the value of the environment
1339 variables which are GNU extensions. If undefined or set to @code{FALSE},
1340 this information will not be shown.
1343 @item @emph{Reference}:
1344 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
1349 @node OMP_DEFAULT_DEVICE
1350 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1351 @cindex Environment Variable
1353 @item @emph{Description}:
1354 Set to choose the device which is used in a @code{target} region, unless the
1355 value is overridden by @code{omp_set_default_device} or by a @code{device}
1356 clause. The value shall be the nonnegative device number. If no device with
1357 the given device number exists, the code is executed on the host. If unset,
1358 device number 0 will be used.
1361 @item @emph{See also}:
1362 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1364 @item @emph{Reference}:
1365 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1371 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1372 @cindex Environment Variable
1374 @item @emph{Description}:
1375 Enable or disable the dynamic adjustment of the number of threads
1376 within a team. The value of this environment variable shall be
1377 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1378 disabled by default.
1380 @item @emph{See also}:
1381 @ref{omp_set_dynamic}
1383 @item @emph{Reference}:
1384 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
1389 @node OMP_MAX_ACTIVE_LEVELS
1390 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1391 @cindex Environment Variable
1393 @item @emph{Description}:
1394 Specifies the initial value for the maximum number of nested parallel
1395 regions. The value of this variable shall be a positive integer.
1396 If undefined, the number of active levels is unlimited.
1398 @item @emph{See also}:
1399 @ref{omp_set_max_active_levels}
1401 @item @emph{Reference}:
1402 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
1408 @section @env{OMP_NESTED} -- Nested parallel regions
1409 @cindex Environment Variable
1410 @cindex Implementation specific setting
1412 @item @emph{Description}:
1413 Enable or disable nested parallel regions, i.e., whether team members
1414 are allowed to create new teams. The value of this environment variable
1415 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
1416 regions are disabled by default.
1418 @item @emph{See also}:
1419 @ref{omp_set_nested}
1421 @item @emph{Reference}:
1422 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
1427 @node OMP_NUM_THREADS
1428 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1429 @cindex Environment Variable
1430 @cindex Implementation specific setting
1432 @item @emph{Description}:
1433 Specifies the default number of threads to use in parallel regions. The
1434 value of this variable shall be a comma-separated list of positive integers;
1435 the value specified the number of threads to use for the corresponding nested
1436 level. If undefined one thread per CPU is used.
1438 @item @emph{See also}:
1439 @ref{omp_set_num_threads}
1441 @item @emph{Reference}:
1442 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
1448 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1449 @cindex Environment Variable
1451 @item @emph{Description}:
1452 Specifies whether threads may be moved between processors. If set to
1453 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1454 they may be moved. Alternatively, a comma separated list with the
1455 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1456 the thread affinity policy for the corresponding nesting level. With
1457 @code{MASTER} the worker threads are in the same place partition as the
1458 master thread. With @code{CLOSE} those are kept close to the master thread
1459 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
1460 across the place partitions is used.
1462 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1463 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1465 @item @emph{See also}:
1466 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1468 @item @emph{Reference}:
1469 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
1475 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1476 @cindex Environment Variable
1478 @item @emph{Description}:
1479 The thread placement can be either specified using an abstract name or by an
1480 explicit list of the places. The abstract names @code{threads}, @code{cores}
1481 and @code{sockets} can be optionally followed by a positive number in
1482 parentheses, which denotes the how many places shall be created. With
1483 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1484 to a single core with the corresponding number of hardware threads; and with
1485 @code{sockets} the place corresponds to a single socket. The resulting
1486 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1489 Alternatively, the placement can be specified explicitly as comma-separated
1490 list of places. A place is specified by set of nonnegative numbers in curly
1491 braces, denoting the denoting the hardware threads. The hardware threads
1492 belonging to a place can either be specified as comma-separated list of
1493 nonnegative thread numbers or using an interval. Multiple places can also be
1494 either specified by a comma-separated list of places or by an interval. To
1495 specify an interval, a colon followed by the count is placed after after
1496 the hardware thread number or the place. Optionally, the length can be
1497 followed by a colon and the stride number -- otherwise a unit stride is
1498 assumed. For instance, the following specifies the same places list:
1499 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1500 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1502 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1503 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1504 between CPUs following no placement policy.
1506 @item @emph{See also}:
1507 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1508 @ref{OMP_DISPLAY_ENV}
1510 @item @emph{Reference}:
1511 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
1517 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1518 @cindex Environment Variable
1520 @item @emph{Description}:
1521 Set the default thread stack size in kilobytes, unless the number
1522 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1523 case the size is, respectively, in bytes, kilobytes, megabytes
1524 or gigabytes. This is different from @code{pthread_attr_setstacksize}
1525 which gets the number of bytes as an argument. If the stack size cannot
1526 be set due to system constraints, an error is reported and the initial
1527 stack size is left unchanged. If undefined, the stack size is system
1530 @item @emph{Reference}:
1531 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
1537 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1538 @cindex Environment Variable
1539 @cindex Implementation specific setting
1541 @item @emph{Description}:
1542 Allows to specify @code{schedule type} and @code{chunk size}.
1543 The value of the variable shall have the form: @code{type[,chunk]} where
1544 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1545 The optional @code{chunk} size shall be a positive integer. If undefined,
1546 dynamic scheduling and a chunk size of 1 is used.
1548 @item @emph{See also}:
1549 @ref{omp_set_schedule}
1551 @item @emph{Reference}:
1552 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
1557 @node OMP_THREAD_LIMIT
1558 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1559 @cindex Environment Variable
1561 @item @emph{Description}:
1562 Specifies the number of threads to use for the whole program. The
1563 value of this variable shall be a positive integer. If undefined,
1564 the number of threads is not limited.
1566 @item @emph{See also}:
1567 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1569 @item @emph{Reference}:
1570 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
1575 @node OMP_WAIT_POLICY
1576 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1577 @cindex Environment Variable
1579 @item @emph{Description}:
1580 Specifies whether waiting threads should be active or passive. If
1581 the value is @code{PASSIVE}, waiting threads should not consume CPU
1582 power while waiting; while the value is @code{ACTIVE} specifies that
1583 they should. If undefined, threads wait actively for a short time
1584 before waiting passively.
1586 @item @emph{See also}:
1587 @ref{GOMP_SPINCOUNT}
1589 @item @emph{Reference}:
1590 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
1595 @node GOMP_CPU_AFFINITY
1596 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1597 @cindex Environment Variable
1599 @item @emph{Description}:
1600 Binds threads to specific CPUs. The variable should contain a space-separated
1601 or comma-separated list of CPUs. This list may contain different kinds of
1602 entries: either single CPU numbers in any order, a range of CPUs (M-N)
1603 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
1604 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1605 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1606 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1607 and 14 respectively and then start assigning back from the beginning of
1608 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1610 There is no GNU OpenMP library routine to determine whether a CPU affinity
1611 specification is in effect. As a workaround, language-specific library
1612 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1613 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1614 environment variable. A defined CPU affinity on startup cannot be changed
1615 or disabled during the runtime of the application.
1617 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1618 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
1619 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1620 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1622 @item @emph{See also}:
1623 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1628 @node GOMP_STACKSIZE
1629 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1630 @cindex Environment Variable
1631 @cindex Implementation specific setting
1633 @item @emph{Description}:
1634 Set the default thread stack size in kilobytes. This is different from
1635 @code{pthread_attr_setstacksize} which gets the number of bytes as an
1636 argument. If the stack size cannot be set due to system constraints, an
1637 error is reported and the initial stack size is left unchanged. If undefined,
1638 the stack size is system dependent.
1640 @item @emph{See also}:
1643 @item @emph{Reference}:
1644 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1645 GCC Patches Mailinglist},
1646 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1647 GCC Patches Mailinglist}
1652 @node GOMP_SPINCOUNT
1653 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1654 @cindex Environment Variable
1655 @cindex Implementation specific setting
1657 @item @emph{Description}:
1658 Determines how long a threads waits actively with consuming CPU power
1659 before waiting passively without consuming CPU power. The value may be
1660 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1661 integer which gives the number of spins of the busy-wait loop. The
1662 integer may optionally be followed by the following suffixes acting
1663 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1664 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1665 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1666 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1667 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1668 If there are more OpenMP threads than available CPUs, 1000 and 100
1669 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1670 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1671 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1673 @item @emph{See also}:
1674 @ref{OMP_WAIT_POLICY}
1679 @c ---------------------------------------------------------------------
1681 @c ---------------------------------------------------------------------
1683 @node The libgomp ABI
1684 @chapter The libgomp ABI
1686 The following sections present notes on the external ABI as
1687 presented by libgomp. Only maintainers should need them.
1690 * Implementing MASTER construct::
1691 * Implementing CRITICAL construct::
1692 * Implementing ATOMIC construct::
1693 * Implementing FLUSH construct::
1694 * Implementing BARRIER construct::
1695 * Implementing THREADPRIVATE construct::
1696 * Implementing PRIVATE clause::
1697 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
1698 * Implementing REDUCTION clause::
1699 * Implementing PARALLEL construct::
1700 * Implementing FOR construct::
1701 * Implementing ORDERED construct::
1702 * Implementing SECTIONS construct::
1703 * Implementing SINGLE construct::
1707 @node Implementing MASTER construct
1708 @section Implementing MASTER construct
1711 if (omp_get_thread_num () == 0)
1715 Alternately, we generate two copies of the parallel subfunction
1716 and only include this in the version run by the master thread.
1717 Surely this is not worthwhile though...
1721 @node Implementing CRITICAL construct
1722 @section Implementing CRITICAL construct
1724 Without a specified name,
1727 void GOMP_critical_start (void);
1728 void GOMP_critical_end (void);
1731 so that we don't get COPY relocations from libgomp to the main
1734 With a specified name, use omp_set_lock and omp_unset_lock with
1735 name being transformed into a variable declared like
1738 omp_lock_t gomp_critical_user_<name> __attribute__((common))
1741 Ideally the ABI would specify that all zero is a valid unlocked
1742 state, and so we wouldn't need to initialize this at
1747 @node Implementing ATOMIC construct
1748 @section Implementing ATOMIC construct
1750 The target should implement the @code{__sync} builtins.
1752 Failing that we could add
1755 void GOMP_atomic_enter (void)
1756 void GOMP_atomic_exit (void)
1759 which reuses the regular lock code, but with yet another lock
1760 object private to the library.
1764 @node Implementing FLUSH construct
1765 @section Implementing FLUSH construct
1767 Expands to the @code{__sync_synchronize} builtin.
1771 @node Implementing BARRIER construct
1772 @section Implementing BARRIER construct
1775 void GOMP_barrier (void)
1779 @node Implementing THREADPRIVATE construct
1780 @section Implementing THREADPRIVATE construct
1782 In _most_ cases we can map this directly to @code{__thread}. Except
1783 that OMP allows constructors for C++ objects. We can either
1784 refuse to support this (how often is it used?) or we can
1785 implement something akin to .ctors.
1787 Even more ideally, this ctor feature is handled by extensions
1788 to the main pthreads library. Failing that, we can have a set
1789 of entry points to register ctor functions to be called.
1793 @node Implementing PRIVATE clause
1794 @section Implementing PRIVATE clause
1796 In association with a PARALLEL, or within the lexical extent
1797 of a PARALLEL block, the variable becomes a local variable in
1798 the parallel subfunction.
1800 In association with FOR or SECTIONS blocks, create a new
1801 automatic variable within the current function. This preserves
1802 the semantic of new variable creation.
1806 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1807 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1809 This seems simple enough for PARALLEL blocks. Create a private
1810 struct for communicating between the parent and subfunction.
1811 In the parent, copy in values for scalar and "small" structs;
1812 copy in addresses for others TREE_ADDRESSABLE types. In the
1813 subfunction, copy the value into the local variable.
1815 It is not clear what to do with bare FOR or SECTION blocks.
1816 The only thing I can figure is that we do something like:
1819 #pragma omp for firstprivate(x) lastprivate(y)
1820 for (int i = 0; i < n; ++i)
1837 where the "x=x" and "y=y" assignments actually have different
1838 uids for the two variables, i.e. not something you could write
1839 directly in C. Presumably this only makes sense if the "outer"
1840 x and y are global variables.
1842 COPYPRIVATE would work the same way, except the structure
1843 broadcast would have to happen via SINGLE machinery instead.
1847 @node Implementing REDUCTION clause
1848 @section Implementing REDUCTION clause
1850 The private struct mentioned in the previous section should have
1851 a pointer to an array of the type of the variable, indexed by the
1852 thread's @var{team_id}. The thread stores its final value into the
1853 array, and after the barrier, the master thread iterates over the
1854 array to collect the values.
1857 @node Implementing PARALLEL construct
1858 @section Implementing PARALLEL construct
1861 #pragma omp parallel
1870 void subfunction (void *data)
1877 GOMP_parallel_start (subfunction, &data, num_threads);
1878 subfunction (&data);
1879 GOMP_parallel_end ();
1883 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1886 The @var{FN} argument is the subfunction to be run in parallel.
1888 The @var{DATA} argument is a pointer to a structure used to
1889 communicate data in and out of the subfunction, as discussed
1890 above with respect to FIRSTPRIVATE et al.
1892 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1893 and false, or the value of the NUM_THREADS clause, if
1896 The function needs to create the appropriate number of
1897 threads and/or launch them from the dock. It needs to
1898 create the team structure and assign team ids.
1901 void GOMP_parallel_end (void)
1904 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1908 @node Implementing FOR construct
1909 @section Implementing FOR construct
1912 #pragma omp parallel for
1913 for (i = lb; i <= ub; i++)
1920 void subfunction (void *data)
1923 while (GOMP_loop_static_next (&_s0, &_e0))
1926 for (i = _s0; i < _e1; i++)
1929 GOMP_loop_end_nowait ();
1932 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
1934 GOMP_parallel_end ();
1938 #pragma omp for schedule(runtime)
1939 for (i = 0; i < n; i++)
1948 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
1951 for (i = _s0, i < _e0; i++)
1953 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
1958 Note that while it looks like there is trickiness to propagating
1959 a non-constant STEP, there isn't really. We're explicitly allowed
1960 to evaluate it as many times as we want, and any variables involved
1961 should automatically be handled as PRIVATE or SHARED like any other
1962 variables. So the expression should remain evaluable in the
1963 subfunction. We can also pull it into a local variable if we like,
1964 but since its supposed to remain unchanged, we can also not if we like.
1966 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
1967 able to get away with no work-sharing context at all, since we can
1968 simply perform the arithmetic directly in each thread to divide up
1969 the iterations. Which would mean that we wouldn't need to call any
1972 There are separate routines for handling loops with an ORDERED
1973 clause. Bookkeeping for that is non-trivial...
1977 @node Implementing ORDERED construct
1978 @section Implementing ORDERED construct
1981 void GOMP_ordered_start (void)
1982 void GOMP_ordered_end (void)
1987 @node Implementing SECTIONS construct
1988 @section Implementing SECTIONS construct
1993 #pragma omp sections
2007 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2024 @node Implementing SINGLE construct
2025 @section Implementing SINGLE construct
2039 if (GOMP_single_start ())
2047 #pragma omp single copyprivate(x)
2054 datap = GOMP_single_copy_start ();
2059 GOMP_single_copy_end (&data);
2068 @c ---------------------------------------------------------------------
2070 @c ---------------------------------------------------------------------
2072 @node Reporting Bugs
2073 @chapter Reporting Bugs
2075 Bugs in the GNU OpenMP implementation should be reported via
2076 @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. For all cases, please add
2077 "openmp" to the keywords field in the bug report.
2081 @c ---------------------------------------------------------------------
2082 @c GNU General Public License
2083 @c ---------------------------------------------------------------------
2085 @include gpl_v3.texi
2089 @c ---------------------------------------------------------------------
2090 @c GNU Free Documentation License
2091 @c ---------------------------------------------------------------------
2097 @c ---------------------------------------------------------------------
2098 @c Funding Free Software
2099 @c ---------------------------------------------------------------------
2101 @include funding.texi
2103 @c ---------------------------------------------------------------------
2105 @c ---------------------------------------------------------------------
2108 @unnumbered Library Index