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 Offloading and Multi Processing Runtime Library.
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library. This is the GNU implementation of the OpenMP API for
39 multi-platform shared-memory parallel programming in C/C++ and Fortran.
41 Published by the Free Software Foundation
42 51 Franklin Street, Fifth Floor
43 Boston, MA 02110-1301 USA
49 @setchapternewpage odd
52 @title GNU Offloading and Multi Processing Runtime Library
53 @subtitle The GNU 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 Offloading and
75 Multi Processing Runtime Library. This is the GNU implementation of the
76 @uref{http://www.openmp.org, OpenMP} Application Programming Interface (API)
77 for multi-platform shared-memory parallel programming in C/C++ and Fortran.
79 Originally, libgomp was known as the GNU OpenMP Runtime Library.
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 OpenMP:: How to enable OpenMP for your applications.
90 * Runtime Library Routines:: The OpenMP runtime application programming
92 * Environment Variables:: Influencing runtime behavior with environment
94 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
95 * Reporting Bugs:: How to report bugs in the GNU Offloading and
96 Multi Processing Runtime Library.
97 * Copying:: GNU general public license says
98 how you can copy and share libgomp.
99 * GNU Free Documentation License::
100 How you can copy and share this manual.
101 * Funding:: How to help assure continued work for free
103 * Library Index:: Index of this documentation.
107 @c ---------------------------------------------------------------------
109 @c ---------------------------------------------------------------------
111 @node Enabling OpenMP
112 @chapter Enabling OpenMP
114 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
115 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
116 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
117 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
118 @code{!$} conditional compilation sentinels in free form and @code{c$},
119 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
120 arranges for automatic linking of the OpenMP runtime library
121 (@ref{Runtime Library Routines}).
123 A complete description of all OpenMP directives accepted may be found in
124 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
128 @c ---------------------------------------------------------------------
129 @c Runtime Library Routines
130 @c ---------------------------------------------------------------------
132 @node Runtime Library Routines
133 @chapter Runtime Library Routines
135 The runtime routines described here are defined by Section 3 of the OpenMP
136 specification in version 4.0. The routines are structured in following
140 Control threads, processors and the parallel environment. They have C
141 linkage, and do not throw exceptions.
143 * omp_get_active_level:: Number of active parallel regions
144 * omp_get_ancestor_thread_num:: Ancestor thread ID
145 * omp_get_cancellation:: Whether cancellation support is enabled
146 * omp_get_default_device:: Get the default device for target regions
147 * omp_get_dynamic:: Dynamic teams setting
148 * omp_get_level:: Number of parallel regions
149 * omp_get_max_active_levels:: Maximum number of active regions
150 * omp_get_max_threads:: Maximum number of threads of parallel region
151 * omp_get_nested:: Nested parallel regions
152 * omp_get_num_devices:: Number of target devices
153 * omp_get_num_procs:: Number of processors online
154 * omp_get_num_teams:: Number of teams
155 * omp_get_num_threads:: Size of the active team
156 * omp_get_proc_bind:: Whether theads may be moved between CPUs
157 * omp_get_schedule:: Obtain the runtime scheduling method
158 * omp_get_team_num:: Get team number
159 * omp_get_team_size:: Number of threads in a team
160 * omp_get_thread_limit:: Maximum number of threads
161 * omp_get_thread_num:: Current thread ID
162 * omp_in_parallel:: Whether a parallel region is active
163 * omp_in_final:: Whether in final or included task region
164 * omp_is_initial_device:: Whether executing on the host device
165 * omp_set_default_device:: Set the default device for target regions
166 * omp_set_dynamic:: Enable/disable dynamic teams
167 * omp_set_max_active_levels:: Limits the number of active parallel regions
168 * omp_set_nested:: Enable/disable nested parallel regions
169 * omp_set_num_threads:: Set upper team size limit
170 * omp_set_schedule:: Set the runtime scheduling method
172 Initialize, set, test, unset and destroy simple and nested locks.
174 * omp_init_lock:: Initialize simple lock
175 * omp_set_lock:: Wait for and set simple lock
176 * omp_test_lock:: Test and set simple lock if available
177 * omp_unset_lock:: Unset simple lock
178 * omp_destroy_lock:: Destroy simple lock
179 * omp_init_nest_lock:: Initialize nested lock
180 * omp_set_nest_lock:: Wait for and set simple lock
181 * omp_test_nest_lock:: Test and set nested lock if available
182 * omp_unset_nest_lock:: Unset nested lock
183 * omp_destroy_nest_lock:: Destroy nested lock
185 Portable, thread-based, wall clock timer.
187 * omp_get_wtick:: Get timer precision.
188 * omp_get_wtime:: Elapsed wall clock time.
193 @node omp_get_active_level
194 @section @code{omp_get_active_level} -- Number of parallel regions
196 @item @emph{Description}:
197 This function returns the nesting level for the active parallel blocks,
198 which enclose the calling call.
201 @multitable @columnfractions .20 .80
202 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
205 @item @emph{Fortran}:
206 @multitable @columnfractions .20 .80
207 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
210 @item @emph{See also}:
211 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
213 @item @emph{Reference}:
214 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
219 @node omp_get_ancestor_thread_num
220 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
222 @item @emph{Description}:
223 This function returns the thread identification number for the given
224 nesting level of the current thread. For values of @var{level} outside
225 zero to @code{omp_get_level} -1 is returned; if @var{level} is
226 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
229 @multitable @columnfractions .20 .80
230 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
233 @item @emph{Fortran}:
234 @multitable @columnfractions .20 .80
235 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
236 @item @tab @code{integer level}
239 @item @emph{See also}:
240 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
242 @item @emph{Reference}:
243 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
248 @node omp_get_cancellation
249 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
251 @item @emph{Description}:
252 This function returns @code{true} if cancellation is activated, @code{false}
253 otherwise. Here, @code{true} and @code{false} represent their language-specific
254 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
258 @multitable @columnfractions .20 .80
259 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
262 @item @emph{Fortran}:
263 @multitable @columnfractions .20 .80
264 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
267 @item @emph{See also}:
268 @ref{OMP_CANCELLATION}
270 @item @emph{Reference}:
271 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
276 @node omp_get_default_device
277 @section @code{omp_get_default_device} -- Get the default device for target regions
279 @item @emph{Description}:
280 Get the default device for target regions without device clause.
283 @multitable @columnfractions .20 .80
284 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
287 @item @emph{Fortran}:
288 @multitable @columnfractions .20 .80
289 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
292 @item @emph{See also}:
293 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
295 @item @emph{Reference}:
296 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
301 @node omp_get_dynamic
302 @section @code{omp_get_dynamic} -- Dynamic teams setting
304 @item @emph{Description}:
305 This function returns @code{true} if enabled, @code{false} otherwise.
306 Here, @code{true} and @code{false} represent their language-specific
309 The dynamic team setting may be initialized at startup by the
310 @env{OMP_DYNAMIC} environment variable or at runtime using
311 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
315 @multitable @columnfractions .20 .80
316 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
319 @item @emph{Fortran}:
320 @multitable @columnfractions .20 .80
321 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
324 @item @emph{See also}:
325 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
327 @item @emph{Reference}:
328 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
334 @section @code{omp_get_level} -- Obtain the current nesting level
336 @item @emph{Description}:
337 This function returns the nesting level for the parallel blocks,
338 which enclose the calling call.
341 @multitable @columnfractions .20 .80
342 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
345 @item @emph{Fortran}:
346 @multitable @columnfractions .20 .80
347 @item @emph{Interface}: @tab @code{integer function omp_level()}
350 @item @emph{See also}:
351 @ref{omp_get_active_level}
353 @item @emph{Reference}:
354 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
359 @node omp_get_max_active_levels
360 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
362 @item @emph{Description}:
363 This function obtains the maximum allowed number of nested, active parallel regions.
366 @multitable @columnfractions .20 .80
367 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
370 @item @emph{Fortran}:
371 @multitable @columnfractions .20 .80
372 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
375 @item @emph{See also}:
376 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
378 @item @emph{Reference}:
379 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
384 @node omp_get_max_threads
385 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
387 @item @emph{Description}:
388 Return the maximum number of threads used for the current parallel region
389 that does not use the clause @code{num_threads}.
392 @multitable @columnfractions .20 .80
393 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
396 @item @emph{Fortran}:
397 @multitable @columnfractions .20 .80
398 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
401 @item @emph{See also}:
402 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
404 @item @emph{Reference}:
405 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
411 @section @code{omp_get_nested} -- Nested parallel regions
413 @item @emph{Description}:
414 This function returns @code{true} if nested parallel regions are
415 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
416 represent their language-specific counterparts.
418 Nested parallel regions may be initialized at startup by the
419 @env{OMP_NESTED} environment variable or at runtime using
420 @code{omp_set_nested}. If undefined, nested parallel regions are
424 @multitable @columnfractions .20 .80
425 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
428 @item @emph{Fortran}:
429 @multitable @columnfractions .20 .80
430 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
433 @item @emph{See also}:
434 @ref{omp_set_nested}, @ref{OMP_NESTED}
436 @item @emph{Reference}:
437 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
442 @node omp_get_num_devices
443 @section @code{omp_get_num_devices} -- Number of target devices
445 @item @emph{Description}:
446 Returns the number of target devices.
449 @multitable @columnfractions .20 .80
450 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
453 @item @emph{Fortran}:
454 @multitable @columnfractions .20 .80
455 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
458 @item @emph{Reference}:
459 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
464 @node omp_get_num_procs
465 @section @code{omp_get_num_procs} -- Number of processors online
467 @item @emph{Description}:
468 Returns the number of processors online on that device.
471 @multitable @columnfractions .20 .80
472 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
475 @item @emph{Fortran}:
476 @multitable @columnfractions .20 .80
477 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
480 @item @emph{Reference}:
481 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
486 @node omp_get_num_teams
487 @section @code{omp_get_num_teams} -- Number of teams
489 @item @emph{Description}:
490 Returns the number of teams in the current team region.
493 @multitable @columnfractions .20 .80
494 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
497 @item @emph{Fortran}:
498 @multitable @columnfractions .20 .80
499 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
502 @item @emph{Reference}:
503 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
508 @node omp_get_num_threads
509 @section @code{omp_get_num_threads} -- Size of the active team
511 @item @emph{Description}:
512 Returns the number of threads in the current team. In a sequential section of
513 the program @code{omp_get_num_threads} returns 1.
515 The default team size may be initialized at startup by the
516 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
517 of the current team may be set either by the @code{NUM_THREADS}
518 clause or by @code{omp_set_num_threads}. If none of the above were
519 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
520 one thread per CPU online is used.
523 @multitable @columnfractions .20 .80
524 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
527 @item @emph{Fortran}:
528 @multitable @columnfractions .20 .80
529 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
532 @item @emph{See also}:
533 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
535 @item @emph{Reference}:
536 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
541 @node omp_get_proc_bind
542 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
544 @item @emph{Description}:
545 This functions returns the currently active thread affinity policy, which is
546 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
547 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
548 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
551 @multitable @columnfractions .20 .80
552 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
555 @item @emph{Fortran}:
556 @multitable @columnfractions .20 .80
557 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
560 @item @emph{See also}:
561 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
563 @item @emph{Reference}:
564 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
569 @node omp_get_schedule
570 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
572 @item @emph{Description}:
573 Obtain the runtime scheduling method. The @var{kind} argument will be
574 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
575 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
576 @var{modifier}, is set to the chunk size.
579 @multitable @columnfractions .20 .80
580 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
583 @item @emph{Fortran}:
584 @multitable @columnfractions .20 .80
585 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
586 @item @tab @code{integer(kind=omp_sched_kind) kind}
587 @item @tab @code{integer modifier}
590 @item @emph{See also}:
591 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
593 @item @emph{Reference}:
594 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
599 @node omp_get_team_num
600 @section @code{omp_get_team_num} -- Get team number
602 @item @emph{Description}:
603 Returns the team number of the calling thread.
606 @multitable @columnfractions .20 .80
607 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
610 @item @emph{Fortran}:
611 @multitable @columnfractions .20 .80
612 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
615 @item @emph{Reference}:
616 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
621 @node omp_get_team_size
622 @section @code{omp_get_team_size} -- Number of threads in a team
624 @item @emph{Description}:
625 This function returns the number of threads in a thread team to which
626 either the current thread or its ancestor belongs. For values of @var{level}
627 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
628 1 is returned, and for @code{omp_get_level}, the result is identical
629 to @code{omp_get_num_threads}.
632 @multitable @columnfractions .20 .80
633 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
636 @item @emph{Fortran}:
637 @multitable @columnfractions .20 .80
638 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
639 @item @tab @code{integer level}
642 @item @emph{See also}:
643 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
645 @item @emph{Reference}:
646 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
651 @node omp_get_thread_limit
652 @section @code{omp_get_thread_limit} -- Maximum number of threads
654 @item @emph{Description}:
655 Return the maximum number of threads of the program.
658 @multitable @columnfractions .20 .80
659 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
662 @item @emph{Fortran}:
663 @multitable @columnfractions .20 .80
664 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
667 @item @emph{See also}:
668 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
670 @item @emph{Reference}:
671 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
676 @node omp_get_thread_num
677 @section @code{omp_get_thread_num} -- Current thread ID
679 @item @emph{Description}:
680 Returns a unique thread identification number within the current team.
681 In a sequential parts of the program, @code{omp_get_thread_num}
682 always returns 0. In parallel regions the return value varies
683 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
684 value of the master thread of a team is always 0.
687 @multitable @columnfractions .20 .80
688 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
691 @item @emph{Fortran}:
692 @multitable @columnfractions .20 .80
693 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
696 @item @emph{See also}:
697 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
699 @item @emph{Reference}:
700 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
705 @node omp_in_parallel
706 @section @code{omp_in_parallel} -- Whether a parallel region is active
708 @item @emph{Description}:
709 This function returns @code{true} if currently running in parallel,
710 @code{false} otherwise. Here, @code{true} and @code{false} represent
711 their language-specific counterparts.
714 @multitable @columnfractions .20 .80
715 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
718 @item @emph{Fortran}:
719 @multitable @columnfractions .20 .80
720 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
723 @item @emph{Reference}:
724 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
729 @section @code{omp_in_final} -- Whether in final or included task region
731 @item @emph{Description}:
732 This function returns @code{true} if currently running in a final
733 or included task region, @code{false} otherwise. Here, @code{true}
734 and @code{false} represent their language-specific counterparts.
737 @multitable @columnfractions .20 .80
738 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
741 @item @emph{Fortran}:
742 @multitable @columnfractions .20 .80
743 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
746 @item @emph{Reference}:
747 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
752 @node omp_is_initial_device
753 @section @code{omp_is_initial_device} -- Whether executing on the host device
755 @item @emph{Description}:
756 This function returns @code{true} if currently running on the host device,
757 @code{false} otherwise. Here, @code{true} and @code{false} represent
758 their language-specific counterparts.
761 @multitable @columnfractions .20 .80
762 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
765 @item @emph{Fortran}:
766 @multitable @columnfractions .20 .80
767 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
770 @item @emph{Reference}:
771 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
776 @node omp_set_default_device
777 @section @code{omp_set_default_device} -- Set the default device for target regions
779 @item @emph{Description}:
780 Set the default device for target regions without device clause. The argument
781 shall be a nonnegative device number.
784 @multitable @columnfractions .20 .80
785 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
788 @item @emph{Fortran}:
789 @multitable @columnfractions .20 .80
790 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
791 @item @tab @code{integer device_num}
794 @item @emph{See also}:
795 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
797 @item @emph{Reference}:
798 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
803 @node omp_set_dynamic
804 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
806 @item @emph{Description}:
807 Enable or disable the dynamic adjustment of the number of threads
808 within a team. The function takes the language-specific equivalent
809 of @code{true} and @code{false}, where @code{true} enables dynamic
810 adjustment of team sizes and @code{false} disables it.
813 @multitable @columnfractions .20 .80
814 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
817 @item @emph{Fortran}:
818 @multitable @columnfractions .20 .80
819 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
820 @item @tab @code{logical, intent(in) :: dynamic_threads}
823 @item @emph{See also}:
824 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
826 @item @emph{Reference}:
827 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
832 @node omp_set_max_active_levels
833 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
835 @item @emph{Description}:
836 This function limits the maximum allowed number of nested, active
840 @multitable @columnfractions .20 .80
841 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
844 @item @emph{Fortran}:
845 @multitable @columnfractions .20 .80
846 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
847 @item @tab @code{integer max_levels}
850 @item @emph{See also}:
851 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
853 @item @emph{Reference}:
854 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
860 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
862 @item @emph{Description}:
863 Enable or disable nested parallel regions, i.e., whether team members
864 are allowed to create new teams. The function takes the language-specific
865 equivalent of @code{true} and @code{false}, where @code{true} enables
866 dynamic adjustment of team sizes and @code{false} disables it.
869 @multitable @columnfractions .20 .80
870 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
873 @item @emph{Fortran}:
874 @multitable @columnfractions .20 .80
875 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
876 @item @tab @code{logical, intent(in) :: nested}
879 @item @emph{See also}:
880 @ref{OMP_NESTED}, @ref{omp_get_nested}
882 @item @emph{Reference}:
883 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
888 @node omp_set_num_threads
889 @section @code{omp_set_num_threads} -- Set upper team size limit
891 @item @emph{Description}:
892 Specifies the number of threads used by default in subsequent parallel
893 sections, if those do not specify a @code{num_threads} clause. The
894 argument of @code{omp_set_num_threads} shall be a positive integer.
897 @multitable @columnfractions .20 .80
898 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
901 @item @emph{Fortran}:
902 @multitable @columnfractions .20 .80
903 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
904 @item @tab @code{integer, intent(in) :: num_threads}
907 @item @emph{See also}:
908 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
910 @item @emph{Reference}:
911 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
916 @node omp_set_schedule
917 @section @code{omp_set_schedule} -- Set the runtime scheduling method
919 @item @emph{Description}:
920 Sets the runtime scheduling method. The @var{kind} argument can have the
921 value @code{omp_sched_static}, @code{omp_sched_dynamic},
922 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
923 @code{omp_sched_auto}, the chunk size is set to the value of
924 @var{modifier} if positive, or to the default value if zero or negative.
925 For @code{omp_sched_auto} the @var{modifier} argument is ignored.
928 @multitable @columnfractions .20 .80
929 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
932 @item @emph{Fortran}:
933 @multitable @columnfractions .20 .80
934 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
935 @item @tab @code{integer(kind=omp_sched_kind) kind}
936 @item @tab @code{integer modifier}
939 @item @emph{See also}:
940 @ref{omp_get_schedule}
943 @item @emph{Reference}:
944 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
950 @section @code{omp_init_lock} -- Initialize simple lock
952 @item @emph{Description}:
953 Initialize a simple lock. After initialization, the lock is in
957 @multitable @columnfractions .20 .80
958 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
961 @item @emph{Fortran}:
962 @multitable @columnfractions .20 .80
963 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
964 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
967 @item @emph{See also}:
968 @ref{omp_destroy_lock}
970 @item @emph{Reference}:
971 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
977 @section @code{omp_set_lock} -- Wait for and set simple lock
979 @item @emph{Description}:
980 Before setting a simple lock, the lock variable must be initialized by
981 @code{omp_init_lock}. The calling thread is blocked until the lock
982 is available. If the lock is already held by the current thread,
986 @multitable @columnfractions .20 .80
987 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
990 @item @emph{Fortran}:
991 @multitable @columnfractions .20 .80
992 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
993 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
996 @item @emph{See also}:
997 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
999 @item @emph{Reference}:
1000 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1006 @section @code{omp_test_lock} -- Test and set simple lock if available
1008 @item @emph{Description}:
1009 Before setting a simple lock, the lock variable must be initialized by
1010 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1011 does not block if the lock is not available. This function returns
1012 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1013 @code{false} represent their language-specific counterparts.
1016 @multitable @columnfractions .20 .80
1017 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1020 @item @emph{Fortran}:
1021 @multitable @columnfractions .20 .80
1022 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1023 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1026 @item @emph{See also}:
1027 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1029 @item @emph{Reference}:
1030 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1035 @node omp_unset_lock
1036 @section @code{omp_unset_lock} -- Unset simple lock
1038 @item @emph{Description}:
1039 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1040 or @code{omp_test_lock} before. In addition, the lock must be held by the
1041 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1042 or more threads attempted to set the lock before, one of them is chosen to,
1043 again, set the lock to itself.
1046 @multitable @columnfractions .20 .80
1047 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1050 @item @emph{Fortran}:
1051 @multitable @columnfractions .20 .80
1052 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1053 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1056 @item @emph{See also}:
1057 @ref{omp_set_lock}, @ref{omp_test_lock}
1059 @item @emph{Reference}:
1060 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1065 @node omp_destroy_lock
1066 @section @code{omp_destroy_lock} -- Destroy simple lock
1068 @item @emph{Description}:
1069 Destroy a simple lock. In order to be destroyed, a simple lock must be
1070 in the unlocked state.
1073 @multitable @columnfractions .20 .80
1074 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1077 @item @emph{Fortran}:
1078 @multitable @columnfractions .20 .80
1079 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1080 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1083 @item @emph{See also}:
1086 @item @emph{Reference}:
1087 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1092 @node omp_init_nest_lock
1093 @section @code{omp_init_nest_lock} -- Initialize nested lock
1095 @item @emph{Description}:
1096 Initialize a nested lock. After initialization, the lock is in
1097 an unlocked state and the nesting count is set to zero.
1100 @multitable @columnfractions .20 .80
1101 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1104 @item @emph{Fortran}:
1105 @multitable @columnfractions .20 .80
1106 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1107 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1110 @item @emph{See also}:
1111 @ref{omp_destroy_nest_lock}
1113 @item @emph{Reference}:
1114 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1118 @node omp_set_nest_lock
1119 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1121 @item @emph{Description}:
1122 Before setting a nested lock, the lock variable must be initialized by
1123 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1124 is available. If the lock is already held by the current thread, the
1125 nesting count for the lock is incremented.
1128 @multitable @columnfractions .20 .80
1129 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1132 @item @emph{Fortran}:
1133 @multitable @columnfractions .20 .80
1134 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1135 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1138 @item @emph{See also}:
1139 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1141 @item @emph{Reference}:
1142 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1147 @node omp_test_nest_lock
1148 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1150 @item @emph{Description}:
1151 Before setting a nested lock, the lock variable must be initialized by
1152 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1153 @code{omp_test_nest_lock} does not block if the lock is not available.
1154 If the lock is already held by the current thread, the new nesting count
1155 is returned. Otherwise, the return value equals zero.
1158 @multitable @columnfractions .20 .80
1159 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1162 @item @emph{Fortran}:
1163 @multitable @columnfractions .20 .80
1164 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1165 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1169 @item @emph{See also}:
1170 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1172 @item @emph{Reference}:
1173 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1178 @node omp_unset_nest_lock
1179 @section @code{omp_unset_nest_lock} -- Unset nested lock
1181 @item @emph{Description}:
1182 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1183 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1184 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1185 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1186 one of them is chosen to, again, set the lock to itself.
1189 @multitable @columnfractions .20 .80
1190 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1193 @item @emph{Fortran}:
1194 @multitable @columnfractions .20 .80
1195 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1196 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1199 @item @emph{See also}:
1200 @ref{omp_set_nest_lock}
1202 @item @emph{Reference}:
1203 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1208 @node omp_destroy_nest_lock
1209 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1211 @item @emph{Description}:
1212 Destroy a nested lock. In order to be destroyed, a nested lock must be
1213 in the unlocked state and its nesting count must equal zero.
1216 @multitable @columnfractions .20 .80
1217 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1220 @item @emph{Fortran}:
1221 @multitable @columnfractions .20 .80
1222 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1223 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1226 @item @emph{See also}:
1229 @item @emph{Reference}:
1230 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1236 @section @code{omp_get_wtick} -- Get timer precision
1238 @item @emph{Description}:
1239 Gets the timer precision, i.e., the number of seconds between two
1240 successive clock ticks.
1243 @multitable @columnfractions .20 .80
1244 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1247 @item @emph{Fortran}:
1248 @multitable @columnfractions .20 .80
1249 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1252 @item @emph{See also}:
1255 @item @emph{Reference}:
1256 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1262 @section @code{omp_get_wtime} -- Elapsed wall clock time
1264 @item @emph{Description}:
1265 Elapsed wall clock time in seconds. The time is measured per thread, no
1266 guarantee can be made that two distinct threads measure the same time.
1267 Time is measured from some "time in the past", which is an arbitrary time
1268 guaranteed not to change during the execution of the program.
1271 @multitable @columnfractions .20 .80
1272 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1275 @item @emph{Fortran}:
1276 @multitable @columnfractions .20 .80
1277 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1280 @item @emph{See also}:
1283 @item @emph{Reference}:
1284 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
1289 @c ---------------------------------------------------------------------
1290 @c Environment Variables
1291 @c ---------------------------------------------------------------------
1293 @node Environment Variables
1294 @chapter Environment Variables
1296 The environment variables which beginning with @env{OMP_} are defined by
1297 section 4 of the OpenMP specification in version 4.0, while those
1298 beginning with @env{GOMP_} are GNU extensions.
1301 * OMP_CANCELLATION:: Set whether cancellation is activated
1302 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1303 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1304 * OMP_DYNAMIC:: Dynamic adjustment of threads
1305 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1306 * OMP_NESTED:: Nested parallel regions
1307 * OMP_NUM_THREADS:: Specifies the number of threads to use
1308 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1309 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1310 * OMP_STACKSIZE:: Set default thread stack size
1311 * OMP_SCHEDULE:: How threads are scheduled
1312 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1313 * OMP_WAIT_POLICY:: How waiting threads are handled
1314 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1315 * GOMP_STACKSIZE:: Set default thread stack size
1316 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1320 @node OMP_CANCELLATION
1321 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1322 @cindex Environment Variable
1324 @item @emph{Description}:
1325 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1326 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1328 @item @emph{See also}:
1329 @ref{omp_get_cancellation}
1331 @item @emph{Reference}:
1332 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1337 @node OMP_DISPLAY_ENV
1338 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1339 @cindex Environment Variable
1341 @item @emph{Description}:
1342 If set to @code{TRUE}, the OpenMP version number and the values
1343 associated with the OpenMP environment variables are printed to @code{stderr}.
1344 If set to @code{VERBOSE}, it additionally shows the value of the environment
1345 variables which are GNU extensions. If undefined or set to @code{FALSE},
1346 this information will not be shown.
1349 @item @emph{Reference}:
1350 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
1355 @node OMP_DEFAULT_DEVICE
1356 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1357 @cindex Environment Variable
1359 @item @emph{Description}:
1360 Set to choose the device which is used in a @code{target} region, unless the
1361 value is overridden by @code{omp_set_default_device} or by a @code{device}
1362 clause. The value shall be the nonnegative device number. If no device with
1363 the given device number exists, the code is executed on the host. If unset,
1364 device number 0 will be used.
1367 @item @emph{See also}:
1368 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1370 @item @emph{Reference}:
1371 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1377 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1378 @cindex Environment Variable
1380 @item @emph{Description}:
1381 Enable or disable the dynamic adjustment of the number of threads
1382 within a team. The value of this environment variable shall be
1383 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1384 disabled by default.
1386 @item @emph{See also}:
1387 @ref{omp_set_dynamic}
1389 @item @emph{Reference}:
1390 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
1395 @node OMP_MAX_ACTIVE_LEVELS
1396 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1397 @cindex Environment Variable
1399 @item @emph{Description}:
1400 Specifies the initial value for the maximum number of nested parallel
1401 regions. The value of this variable shall be a positive integer.
1402 If undefined, the number of active levels is unlimited.
1404 @item @emph{See also}:
1405 @ref{omp_set_max_active_levels}
1407 @item @emph{Reference}:
1408 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
1414 @section @env{OMP_NESTED} -- Nested parallel regions
1415 @cindex Environment Variable
1416 @cindex Implementation specific setting
1418 @item @emph{Description}:
1419 Enable or disable nested parallel regions, i.e., whether team members
1420 are allowed to create new teams. The value of this environment variable
1421 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
1422 regions are disabled by default.
1424 @item @emph{See also}:
1425 @ref{omp_set_nested}
1427 @item @emph{Reference}:
1428 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
1433 @node OMP_NUM_THREADS
1434 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1435 @cindex Environment Variable
1436 @cindex Implementation specific setting
1438 @item @emph{Description}:
1439 Specifies the default number of threads to use in parallel regions. The
1440 value of this variable shall be a comma-separated list of positive integers;
1441 the value specified the number of threads to use for the corresponding nested
1442 level. If undefined one thread per CPU is used.
1444 @item @emph{See also}:
1445 @ref{omp_set_num_threads}
1447 @item @emph{Reference}:
1448 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
1454 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1455 @cindex Environment Variable
1457 @item @emph{Description}:
1458 Specifies whether threads may be moved between processors. If set to
1459 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1460 they may be moved. Alternatively, a comma separated list with the
1461 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1462 the thread affinity policy for the corresponding nesting level. With
1463 @code{MASTER} the worker threads are in the same place partition as the
1464 master thread. With @code{CLOSE} those are kept close to the master thread
1465 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
1466 across the place partitions is used.
1468 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1469 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1471 @item @emph{See also}:
1472 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1474 @item @emph{Reference}:
1475 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
1481 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1482 @cindex Environment Variable
1484 @item @emph{Description}:
1485 The thread placement can be either specified using an abstract name or by an
1486 explicit list of the places. The abstract names @code{threads}, @code{cores}
1487 and @code{sockets} can be optionally followed by a positive number in
1488 parentheses, which denotes the how many places shall be created. With
1489 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1490 to a single core with the corresponding number of hardware threads; and with
1491 @code{sockets} the place corresponds to a single socket. The resulting
1492 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1495 Alternatively, the placement can be specified explicitly as comma-separated
1496 list of places. A place is specified by set of nonnegative numbers in curly
1497 braces, denoting the denoting the hardware threads. The hardware threads
1498 belonging to a place can either be specified as comma-separated list of
1499 nonnegative thread numbers or using an interval. Multiple places can also be
1500 either specified by a comma-separated list of places or by an interval. To
1501 specify an interval, a colon followed by the count is placed after after
1502 the hardware thread number or the place. Optionally, the length can be
1503 followed by a colon and the stride number -- otherwise a unit stride is
1504 assumed. For instance, the following specifies the same places list:
1505 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1506 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1508 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1509 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1510 between CPUs following no placement policy.
1512 @item @emph{See also}:
1513 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1514 @ref{OMP_DISPLAY_ENV}
1516 @item @emph{Reference}:
1517 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
1523 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1524 @cindex Environment Variable
1526 @item @emph{Description}:
1527 Set the default thread stack size in kilobytes, unless the number
1528 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1529 case the size is, respectively, in bytes, kilobytes, megabytes
1530 or gigabytes. This is different from @code{pthread_attr_setstacksize}
1531 which gets the number of bytes as an argument. If the stack size cannot
1532 be set due to system constraints, an error is reported and the initial
1533 stack size is left unchanged. If undefined, the stack size is system
1536 @item @emph{Reference}:
1537 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
1543 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1544 @cindex Environment Variable
1545 @cindex Implementation specific setting
1547 @item @emph{Description}:
1548 Allows to specify @code{schedule type} and @code{chunk size}.
1549 The value of the variable shall have the form: @code{type[,chunk]} where
1550 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1551 The optional @code{chunk} size shall be a positive integer. If undefined,
1552 dynamic scheduling and a chunk size of 1 is used.
1554 @item @emph{See also}:
1555 @ref{omp_set_schedule}
1557 @item @emph{Reference}:
1558 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
1563 @node OMP_THREAD_LIMIT
1564 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1565 @cindex Environment Variable
1567 @item @emph{Description}:
1568 Specifies the number of threads to use for the whole program. The
1569 value of this variable shall be a positive integer. If undefined,
1570 the number of threads is not limited.
1572 @item @emph{See also}:
1573 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1575 @item @emph{Reference}:
1576 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
1581 @node OMP_WAIT_POLICY
1582 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1583 @cindex Environment Variable
1585 @item @emph{Description}:
1586 Specifies whether waiting threads should be active or passive. If
1587 the value is @code{PASSIVE}, waiting threads should not consume CPU
1588 power while waiting; while the value is @code{ACTIVE} specifies that
1589 they should. If undefined, threads wait actively for a short time
1590 before waiting passively.
1592 @item @emph{See also}:
1593 @ref{GOMP_SPINCOUNT}
1595 @item @emph{Reference}:
1596 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
1601 @node GOMP_CPU_AFFINITY
1602 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1603 @cindex Environment Variable
1605 @item @emph{Description}:
1606 Binds threads to specific CPUs. The variable should contain a space-separated
1607 or comma-separated list of CPUs. This list may contain different kinds of
1608 entries: either single CPU numbers in any order, a range of CPUs (M-N)
1609 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
1610 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1611 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1612 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1613 and 14 respectively and then start assigning back from the beginning of
1614 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1616 There is no libgomp library routine to determine whether a CPU affinity
1617 specification is in effect. As a workaround, language-specific library
1618 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1619 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1620 environment variable. A defined CPU affinity on startup cannot be changed
1621 or disabled during the runtime of the application.
1623 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1624 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
1625 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1626 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1628 @item @emph{See also}:
1629 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1634 @node GOMP_STACKSIZE
1635 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1636 @cindex Environment Variable
1637 @cindex Implementation specific setting
1639 @item @emph{Description}:
1640 Set the default thread stack size in kilobytes. This is different from
1641 @code{pthread_attr_setstacksize} which gets the number of bytes as an
1642 argument. If the stack size cannot be set due to system constraints, an
1643 error is reported and the initial stack size is left unchanged. If undefined,
1644 the stack size is system dependent.
1646 @item @emph{See also}:
1649 @item @emph{Reference}:
1650 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1651 GCC Patches Mailinglist},
1652 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1653 GCC Patches Mailinglist}
1658 @node GOMP_SPINCOUNT
1659 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1660 @cindex Environment Variable
1661 @cindex Implementation specific setting
1663 @item @emph{Description}:
1664 Determines how long a threads waits actively with consuming CPU power
1665 before waiting passively without consuming CPU power. The value may be
1666 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1667 integer which gives the number of spins of the busy-wait loop. The
1668 integer may optionally be followed by the following suffixes acting
1669 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1670 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1671 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1672 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1673 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1674 If there are more OpenMP threads than available CPUs, 1000 and 100
1675 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1676 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1677 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1679 @item @emph{See also}:
1680 @ref{OMP_WAIT_POLICY}
1685 @c ---------------------------------------------------------------------
1687 @c ---------------------------------------------------------------------
1689 @node The libgomp ABI
1690 @chapter The libgomp ABI
1692 The following sections present notes on the external ABI as
1693 presented by libgomp. Only maintainers should need them.
1696 * Implementing MASTER construct::
1697 * Implementing CRITICAL construct::
1698 * Implementing ATOMIC construct::
1699 * Implementing FLUSH construct::
1700 * Implementing BARRIER construct::
1701 * Implementing THREADPRIVATE construct::
1702 * Implementing PRIVATE clause::
1703 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
1704 * Implementing REDUCTION clause::
1705 * Implementing PARALLEL construct::
1706 * Implementing FOR construct::
1707 * Implementing ORDERED construct::
1708 * Implementing SECTIONS construct::
1709 * Implementing SINGLE construct::
1713 @node Implementing MASTER construct
1714 @section Implementing MASTER construct
1717 if (omp_get_thread_num () == 0)
1721 Alternately, we generate two copies of the parallel subfunction
1722 and only include this in the version run by the master thread.
1723 Surely this is not worthwhile though...
1727 @node Implementing CRITICAL construct
1728 @section Implementing CRITICAL construct
1730 Without a specified name,
1733 void GOMP_critical_start (void);
1734 void GOMP_critical_end (void);
1737 so that we don't get COPY relocations from libgomp to the main
1740 With a specified name, use omp_set_lock and omp_unset_lock with
1741 name being transformed into a variable declared like
1744 omp_lock_t gomp_critical_user_<name> __attribute__((common))
1747 Ideally the ABI would specify that all zero is a valid unlocked
1748 state, and so we wouldn't need to initialize this at
1753 @node Implementing ATOMIC construct
1754 @section Implementing ATOMIC construct
1756 The target should implement the @code{__sync} builtins.
1758 Failing that we could add
1761 void GOMP_atomic_enter (void)
1762 void GOMP_atomic_exit (void)
1765 which reuses the regular lock code, but with yet another lock
1766 object private to the library.
1770 @node Implementing FLUSH construct
1771 @section Implementing FLUSH construct
1773 Expands to the @code{__sync_synchronize} builtin.
1777 @node Implementing BARRIER construct
1778 @section Implementing BARRIER construct
1781 void GOMP_barrier (void)
1785 @node Implementing THREADPRIVATE construct
1786 @section Implementing THREADPRIVATE construct
1788 In _most_ cases we can map this directly to @code{__thread}. Except
1789 that OMP allows constructors for C++ objects. We can either
1790 refuse to support this (how often is it used?) or we can
1791 implement something akin to .ctors.
1793 Even more ideally, this ctor feature is handled by extensions
1794 to the main pthreads library. Failing that, we can have a set
1795 of entry points to register ctor functions to be called.
1799 @node Implementing PRIVATE clause
1800 @section Implementing PRIVATE clause
1802 In association with a PARALLEL, or within the lexical extent
1803 of a PARALLEL block, the variable becomes a local variable in
1804 the parallel subfunction.
1806 In association with FOR or SECTIONS blocks, create a new
1807 automatic variable within the current function. This preserves
1808 the semantic of new variable creation.
1812 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1813 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1815 This seems simple enough for PARALLEL blocks. Create a private
1816 struct for communicating between the parent and subfunction.
1817 In the parent, copy in values for scalar and "small" structs;
1818 copy in addresses for others TREE_ADDRESSABLE types. In the
1819 subfunction, copy the value into the local variable.
1821 It is not clear what to do with bare FOR or SECTION blocks.
1822 The only thing I can figure is that we do something like:
1825 #pragma omp for firstprivate(x) lastprivate(y)
1826 for (int i = 0; i < n; ++i)
1843 where the "x=x" and "y=y" assignments actually have different
1844 uids for the two variables, i.e. not something you could write
1845 directly in C. Presumably this only makes sense if the "outer"
1846 x and y are global variables.
1848 COPYPRIVATE would work the same way, except the structure
1849 broadcast would have to happen via SINGLE machinery instead.
1853 @node Implementing REDUCTION clause
1854 @section Implementing REDUCTION clause
1856 The private struct mentioned in the previous section should have
1857 a pointer to an array of the type of the variable, indexed by the
1858 thread's @var{team_id}. The thread stores its final value into the
1859 array, and after the barrier, the master thread iterates over the
1860 array to collect the values.
1863 @node Implementing PARALLEL construct
1864 @section Implementing PARALLEL construct
1867 #pragma omp parallel
1876 void subfunction (void *data)
1883 GOMP_parallel_start (subfunction, &data, num_threads);
1884 subfunction (&data);
1885 GOMP_parallel_end ();
1889 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1892 The @var{FN} argument is the subfunction to be run in parallel.
1894 The @var{DATA} argument is a pointer to a structure used to
1895 communicate data in and out of the subfunction, as discussed
1896 above with respect to FIRSTPRIVATE et al.
1898 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1899 and false, or the value of the NUM_THREADS clause, if
1902 The function needs to create the appropriate number of
1903 threads and/or launch them from the dock. It needs to
1904 create the team structure and assign team ids.
1907 void GOMP_parallel_end (void)
1910 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1914 @node Implementing FOR construct
1915 @section Implementing FOR construct
1918 #pragma omp parallel for
1919 for (i = lb; i <= ub; i++)
1926 void subfunction (void *data)
1929 while (GOMP_loop_static_next (&_s0, &_e0))
1932 for (i = _s0; i < _e1; i++)
1935 GOMP_loop_end_nowait ();
1938 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
1940 GOMP_parallel_end ();
1944 #pragma omp for schedule(runtime)
1945 for (i = 0; i < n; i++)
1954 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
1957 for (i = _s0, i < _e0; i++)
1959 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
1964 Note that while it looks like there is trickiness to propagating
1965 a non-constant STEP, there isn't really. We're explicitly allowed
1966 to evaluate it as many times as we want, and any variables involved
1967 should automatically be handled as PRIVATE or SHARED like any other
1968 variables. So the expression should remain evaluable in the
1969 subfunction. We can also pull it into a local variable if we like,
1970 but since its supposed to remain unchanged, we can also not if we like.
1972 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
1973 able to get away with no work-sharing context at all, since we can
1974 simply perform the arithmetic directly in each thread to divide up
1975 the iterations. Which would mean that we wouldn't need to call any
1978 There are separate routines for handling loops with an ORDERED
1979 clause. Bookkeeping for that is non-trivial...
1983 @node Implementing ORDERED construct
1984 @section Implementing ORDERED construct
1987 void GOMP_ordered_start (void)
1988 void GOMP_ordered_end (void)
1993 @node Implementing SECTIONS construct
1994 @section Implementing SECTIONS construct
1999 #pragma omp sections
2013 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2030 @node Implementing SINGLE construct
2031 @section Implementing SINGLE construct
2045 if (GOMP_single_start ())
2053 #pragma omp single copyprivate(x)
2060 datap = GOMP_single_copy_start ();
2065 GOMP_single_copy_end (&data);
2074 @c ---------------------------------------------------------------------
2076 @c ---------------------------------------------------------------------
2078 @node Reporting Bugs
2079 @chapter Reporting Bugs
2081 Bugs in the GNU Offloading and Multi Processing Runtime Library should
2082 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
2083 "openmp" to the keywords field in the bug report.
2087 @c ---------------------------------------------------------------------
2088 @c GNU General Public License
2089 @c ---------------------------------------------------------------------
2091 @include gpl_v3.texi
2095 @c ---------------------------------------------------------------------
2096 @c GNU Free Documentation License
2097 @c ---------------------------------------------------------------------
2103 @c ---------------------------------------------------------------------
2104 @c Funding Free Software
2105 @c ---------------------------------------------------------------------
2107 @include funding.texi
2109 @c ---------------------------------------------------------------------
2111 @c ---------------------------------------------------------------------
2114 @unnumbered Library Index