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 and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library. This includes the GNU
77 implementation of the @uref{http://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{http://www.openacc.org/, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
84 Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
92 @comment When you add a new menu item, please keep the right hand
93 @comment aligned to the same column. Do not use tabs. This provides
94 @comment better formatting.
97 * Enabling OpenMP:: How to enable OpenMP for your applications.
98 * Runtime Library Routines:: The OpenMP runtime application programming
100 * Environment Variables:: Influencing runtime behavior with environment
102 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
103 * Reporting Bugs:: How to report bugs in the GNU Offloading and
104 Multi Processing Runtime Library.
105 * Copying:: GNU general public license says
106 how you can copy and share libgomp.
107 * GNU Free Documentation License::
108 How you can copy and share this manual.
109 * Funding:: How to help assure continued work for free
111 * Library Index:: Index of this documentation.
115 @c ---------------------------------------------------------------------
117 @c ---------------------------------------------------------------------
119 @node Enabling OpenMP
120 @chapter Enabling OpenMP
122 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
123 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
124 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
125 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
126 @code{!$} conditional compilation sentinels in free form and @code{c$},
127 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
128 arranges for automatic linking of the OpenMP runtime library
129 (@ref{Runtime Library Routines}).
131 A complete description of all OpenMP directives accepted may be found in
132 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
136 @c ---------------------------------------------------------------------
137 @c Runtime Library Routines
138 @c ---------------------------------------------------------------------
140 @node Runtime Library Routines
141 @chapter Runtime Library Routines
143 The runtime routines described here are defined by Section 3 of the OpenMP
144 specification in version 4.0. The routines are structured in following
148 Control threads, processors and the parallel environment. They have C
149 linkage, and do not throw exceptions.
151 * omp_get_active_level:: Number of active parallel regions
152 * omp_get_ancestor_thread_num:: Ancestor thread ID
153 * omp_get_cancellation:: Whether cancellation support is enabled
154 * omp_get_default_device:: Get the default device for target regions
155 * omp_get_dynamic:: Dynamic teams setting
156 * omp_get_level:: Number of parallel regions
157 * omp_get_max_active_levels:: Maximum number of active regions
158 * omp_get_max_threads:: Maximum number of threads of parallel region
159 * omp_get_nested:: Nested parallel regions
160 * omp_get_num_devices:: Number of target devices
161 * omp_get_num_procs:: Number of processors online
162 * omp_get_num_teams:: Number of teams
163 * omp_get_num_threads:: Size of the active team
164 * omp_get_proc_bind:: Whether theads may be moved between CPUs
165 * omp_get_schedule:: Obtain the runtime scheduling method
166 * omp_get_team_num:: Get team number
167 * omp_get_team_size:: Number of threads in a team
168 * omp_get_thread_limit:: Maximum number of threads
169 * omp_get_thread_num:: Current thread ID
170 * omp_in_parallel:: Whether a parallel region is active
171 * omp_in_final:: Whether in final or included task region
172 * omp_is_initial_device:: Whether executing on the host device
173 * omp_set_default_device:: Set the default device for target regions
174 * omp_set_dynamic:: Enable/disable dynamic teams
175 * omp_set_max_active_levels:: Limits the number of active parallel regions
176 * omp_set_nested:: Enable/disable nested parallel regions
177 * omp_set_num_threads:: Set upper team size limit
178 * omp_set_schedule:: Set the runtime scheduling method
180 Initialize, set, test, unset and destroy simple and nested locks.
182 * omp_init_lock:: Initialize simple lock
183 * omp_set_lock:: Wait for and set simple lock
184 * omp_test_lock:: Test and set simple lock if available
185 * omp_unset_lock:: Unset simple lock
186 * omp_destroy_lock:: Destroy simple lock
187 * omp_init_nest_lock:: Initialize nested lock
188 * omp_set_nest_lock:: Wait for and set simple lock
189 * omp_test_nest_lock:: Test and set nested lock if available
190 * omp_unset_nest_lock:: Unset nested lock
191 * omp_destroy_nest_lock:: Destroy nested lock
193 Portable, thread-based, wall clock timer.
195 * omp_get_wtick:: Get timer precision.
196 * omp_get_wtime:: Elapsed wall clock time.
201 @node omp_get_active_level
202 @section @code{omp_get_active_level} -- Number of parallel regions
204 @item @emph{Description}:
205 This function returns the nesting level for the active parallel blocks,
206 which enclose the calling call.
209 @multitable @columnfractions .20 .80
210 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
213 @item @emph{Fortran}:
214 @multitable @columnfractions .20 .80
215 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
218 @item @emph{See also}:
219 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
221 @item @emph{Reference}:
222 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
227 @node omp_get_ancestor_thread_num
228 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
230 @item @emph{Description}:
231 This function returns the thread identification number for the given
232 nesting level of the current thread. For values of @var{level} outside
233 zero to @code{omp_get_level} -1 is returned; if @var{level} is
234 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
237 @multitable @columnfractions .20 .80
238 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
241 @item @emph{Fortran}:
242 @multitable @columnfractions .20 .80
243 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
244 @item @tab @code{integer level}
247 @item @emph{See also}:
248 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
250 @item @emph{Reference}:
251 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
256 @node omp_get_cancellation
257 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
259 @item @emph{Description}:
260 This function returns @code{true} if cancellation is activated, @code{false}
261 otherwise. Here, @code{true} and @code{false} represent their language-specific
262 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
266 @multitable @columnfractions .20 .80
267 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
270 @item @emph{Fortran}:
271 @multitable @columnfractions .20 .80
272 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
275 @item @emph{See also}:
276 @ref{OMP_CANCELLATION}
278 @item @emph{Reference}:
279 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
284 @node omp_get_default_device
285 @section @code{omp_get_default_device} -- Get the default device for target regions
287 @item @emph{Description}:
288 Get the default device for target regions without device clause.
291 @multitable @columnfractions .20 .80
292 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
295 @item @emph{Fortran}:
296 @multitable @columnfractions .20 .80
297 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
300 @item @emph{See also}:
301 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
303 @item @emph{Reference}:
304 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
309 @node omp_get_dynamic
310 @section @code{omp_get_dynamic} -- Dynamic teams setting
312 @item @emph{Description}:
313 This function returns @code{true} if enabled, @code{false} otherwise.
314 Here, @code{true} and @code{false} represent their language-specific
317 The dynamic team setting may be initialized at startup by the
318 @env{OMP_DYNAMIC} environment variable or at runtime using
319 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
323 @multitable @columnfractions .20 .80
324 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
327 @item @emph{Fortran}:
328 @multitable @columnfractions .20 .80
329 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
332 @item @emph{See also}:
333 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
335 @item @emph{Reference}:
336 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
342 @section @code{omp_get_level} -- Obtain the current nesting level
344 @item @emph{Description}:
345 This function returns the nesting level for the parallel blocks,
346 which enclose the calling call.
349 @multitable @columnfractions .20 .80
350 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
353 @item @emph{Fortran}:
354 @multitable @columnfractions .20 .80
355 @item @emph{Interface}: @tab @code{integer function omp_level()}
358 @item @emph{See also}:
359 @ref{omp_get_active_level}
361 @item @emph{Reference}:
362 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
367 @node omp_get_max_active_levels
368 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
370 @item @emph{Description}:
371 This function obtains the maximum allowed number of nested, active parallel regions.
374 @multitable @columnfractions .20 .80
375 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
378 @item @emph{Fortran}:
379 @multitable @columnfractions .20 .80
380 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
383 @item @emph{See also}:
384 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
386 @item @emph{Reference}:
387 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
392 @node omp_get_max_threads
393 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
395 @item @emph{Description}:
396 Return the maximum number of threads used for the current parallel region
397 that does not use the clause @code{num_threads}.
400 @multitable @columnfractions .20 .80
401 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
404 @item @emph{Fortran}:
405 @multitable @columnfractions .20 .80
406 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
409 @item @emph{See also}:
410 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
412 @item @emph{Reference}:
413 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
419 @section @code{omp_get_nested} -- Nested parallel regions
421 @item @emph{Description}:
422 This function returns @code{true} if nested parallel regions are
423 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
424 represent their language-specific counterparts.
426 Nested parallel regions may be initialized at startup by the
427 @env{OMP_NESTED} environment variable or at runtime using
428 @code{omp_set_nested}. If undefined, nested parallel regions are
432 @multitable @columnfractions .20 .80
433 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
436 @item @emph{Fortran}:
437 @multitable @columnfractions .20 .80
438 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
441 @item @emph{See also}:
442 @ref{omp_set_nested}, @ref{OMP_NESTED}
444 @item @emph{Reference}:
445 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
450 @node omp_get_num_devices
451 @section @code{omp_get_num_devices} -- Number of target devices
453 @item @emph{Description}:
454 Returns the number of target devices.
457 @multitable @columnfractions .20 .80
458 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
461 @item @emph{Fortran}:
462 @multitable @columnfractions .20 .80
463 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
466 @item @emph{Reference}:
467 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
472 @node omp_get_num_procs
473 @section @code{omp_get_num_procs} -- Number of processors online
475 @item @emph{Description}:
476 Returns the number of processors online on that device.
479 @multitable @columnfractions .20 .80
480 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
483 @item @emph{Fortran}:
484 @multitable @columnfractions .20 .80
485 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
488 @item @emph{Reference}:
489 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
494 @node omp_get_num_teams
495 @section @code{omp_get_num_teams} -- Number of teams
497 @item @emph{Description}:
498 Returns the number of teams in the current team region.
501 @multitable @columnfractions .20 .80
502 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
505 @item @emph{Fortran}:
506 @multitable @columnfractions .20 .80
507 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
510 @item @emph{Reference}:
511 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
516 @node omp_get_num_threads
517 @section @code{omp_get_num_threads} -- Size of the active team
519 @item @emph{Description}:
520 Returns the number of threads in the current team. In a sequential section of
521 the program @code{omp_get_num_threads} returns 1.
523 The default team size may be initialized at startup by the
524 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
525 of the current team may be set either by the @code{NUM_THREADS}
526 clause or by @code{omp_set_num_threads}. If none of the above were
527 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
528 one thread per CPU online is used.
531 @multitable @columnfractions .20 .80
532 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
535 @item @emph{Fortran}:
536 @multitable @columnfractions .20 .80
537 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
540 @item @emph{See also}:
541 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
543 @item @emph{Reference}:
544 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
549 @node omp_get_proc_bind
550 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
552 @item @emph{Description}:
553 This functions returns the currently active thread affinity policy, which is
554 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
555 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
556 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
559 @multitable @columnfractions .20 .80
560 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
563 @item @emph{Fortran}:
564 @multitable @columnfractions .20 .80
565 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
568 @item @emph{See also}:
569 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
571 @item @emph{Reference}:
572 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
577 @node omp_get_schedule
578 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
580 @item @emph{Description}:
581 Obtain the runtime scheduling method. The @var{kind} argument will be
582 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
583 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
584 @var{modifier}, is set to the chunk size.
587 @multitable @columnfractions .20 .80
588 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
591 @item @emph{Fortran}:
592 @multitable @columnfractions .20 .80
593 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
594 @item @tab @code{integer(kind=omp_sched_kind) kind}
595 @item @tab @code{integer modifier}
598 @item @emph{See also}:
599 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
601 @item @emph{Reference}:
602 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
607 @node omp_get_team_num
608 @section @code{omp_get_team_num} -- Get team number
610 @item @emph{Description}:
611 Returns the team number of the calling thread.
614 @multitable @columnfractions .20 .80
615 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
618 @item @emph{Fortran}:
619 @multitable @columnfractions .20 .80
620 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
623 @item @emph{Reference}:
624 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
629 @node omp_get_team_size
630 @section @code{omp_get_team_size} -- Number of threads in a team
632 @item @emph{Description}:
633 This function returns the number of threads in a thread team to which
634 either the current thread or its ancestor belongs. For values of @var{level}
635 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
636 1 is returned, and for @code{omp_get_level}, the result is identical
637 to @code{omp_get_num_threads}.
640 @multitable @columnfractions .20 .80
641 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
644 @item @emph{Fortran}:
645 @multitable @columnfractions .20 .80
646 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
647 @item @tab @code{integer level}
650 @item @emph{See also}:
651 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
653 @item @emph{Reference}:
654 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
659 @node omp_get_thread_limit
660 @section @code{omp_get_thread_limit} -- Maximum number of threads
662 @item @emph{Description}:
663 Return the maximum number of threads of the program.
666 @multitable @columnfractions .20 .80
667 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
670 @item @emph{Fortran}:
671 @multitable @columnfractions .20 .80
672 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
675 @item @emph{See also}:
676 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
678 @item @emph{Reference}:
679 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
684 @node omp_get_thread_num
685 @section @code{omp_get_thread_num} -- Current thread ID
687 @item @emph{Description}:
688 Returns a unique thread identification number within the current team.
689 In a sequential parts of the program, @code{omp_get_thread_num}
690 always returns 0. In parallel regions the return value varies
691 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
692 value of the master thread of a team is always 0.
695 @multitable @columnfractions .20 .80
696 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
699 @item @emph{Fortran}:
700 @multitable @columnfractions .20 .80
701 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
704 @item @emph{See also}:
705 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
707 @item @emph{Reference}:
708 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
713 @node omp_in_parallel
714 @section @code{omp_in_parallel} -- Whether a parallel region is active
716 @item @emph{Description}:
717 This function returns @code{true} if currently running in parallel,
718 @code{false} otherwise. Here, @code{true} and @code{false} represent
719 their language-specific counterparts.
722 @multitable @columnfractions .20 .80
723 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
726 @item @emph{Fortran}:
727 @multitable @columnfractions .20 .80
728 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
731 @item @emph{Reference}:
732 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
737 @section @code{omp_in_final} -- Whether in final or included task region
739 @item @emph{Description}:
740 This function returns @code{true} if currently running in a final
741 or included task region, @code{false} otherwise. Here, @code{true}
742 and @code{false} represent their language-specific counterparts.
745 @multitable @columnfractions .20 .80
746 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
749 @item @emph{Fortran}:
750 @multitable @columnfractions .20 .80
751 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
754 @item @emph{Reference}:
755 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
760 @node omp_is_initial_device
761 @section @code{omp_is_initial_device} -- Whether executing on the host device
763 @item @emph{Description}:
764 This function returns @code{true} if currently running on the host device,
765 @code{false} otherwise. Here, @code{true} and @code{false} represent
766 their language-specific counterparts.
769 @multitable @columnfractions .20 .80
770 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
773 @item @emph{Fortran}:
774 @multitable @columnfractions .20 .80
775 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
778 @item @emph{Reference}:
779 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
784 @node omp_set_default_device
785 @section @code{omp_set_default_device} -- Set the default device for target regions
787 @item @emph{Description}:
788 Set the default device for target regions without device clause. The argument
789 shall be a nonnegative device number.
792 @multitable @columnfractions .20 .80
793 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
796 @item @emph{Fortran}:
797 @multitable @columnfractions .20 .80
798 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
799 @item @tab @code{integer device_num}
802 @item @emph{See also}:
803 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
805 @item @emph{Reference}:
806 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
811 @node omp_set_dynamic
812 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
814 @item @emph{Description}:
815 Enable or disable the dynamic adjustment of the number of threads
816 within a team. The function takes the language-specific equivalent
817 of @code{true} and @code{false}, where @code{true} enables dynamic
818 adjustment of team sizes and @code{false} disables it.
821 @multitable @columnfractions .20 .80
822 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
825 @item @emph{Fortran}:
826 @multitable @columnfractions .20 .80
827 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
828 @item @tab @code{logical, intent(in) :: dynamic_threads}
831 @item @emph{See also}:
832 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
834 @item @emph{Reference}:
835 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
840 @node omp_set_max_active_levels
841 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
843 @item @emph{Description}:
844 This function limits the maximum allowed number of nested, active
848 @multitable @columnfractions .20 .80
849 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
852 @item @emph{Fortran}:
853 @multitable @columnfractions .20 .80
854 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
855 @item @tab @code{integer max_levels}
858 @item @emph{See also}:
859 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
861 @item @emph{Reference}:
862 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
868 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
870 @item @emph{Description}:
871 Enable or disable nested parallel regions, i.e., whether team members
872 are allowed to create new teams. The function takes the language-specific
873 equivalent of @code{true} and @code{false}, where @code{true} enables
874 dynamic adjustment of team sizes and @code{false} disables it.
877 @multitable @columnfractions .20 .80
878 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
881 @item @emph{Fortran}:
882 @multitable @columnfractions .20 .80
883 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
884 @item @tab @code{logical, intent(in) :: nested}
887 @item @emph{See also}:
888 @ref{OMP_NESTED}, @ref{omp_get_nested}
890 @item @emph{Reference}:
891 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
896 @node omp_set_num_threads
897 @section @code{omp_set_num_threads} -- Set upper team size limit
899 @item @emph{Description}:
900 Specifies the number of threads used by default in subsequent parallel
901 sections, if those do not specify a @code{num_threads} clause. The
902 argument of @code{omp_set_num_threads} shall be a positive integer.
905 @multitable @columnfractions .20 .80
906 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
909 @item @emph{Fortran}:
910 @multitable @columnfractions .20 .80
911 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
912 @item @tab @code{integer, intent(in) :: num_threads}
915 @item @emph{See also}:
916 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
918 @item @emph{Reference}:
919 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
924 @node omp_set_schedule
925 @section @code{omp_set_schedule} -- Set the runtime scheduling method
927 @item @emph{Description}:
928 Sets the runtime scheduling method. The @var{kind} argument can have the
929 value @code{omp_sched_static}, @code{omp_sched_dynamic},
930 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
931 @code{omp_sched_auto}, the chunk size is set to the value of
932 @var{modifier} if positive, or to the default value if zero or negative.
933 For @code{omp_sched_auto} the @var{modifier} argument is ignored.
936 @multitable @columnfractions .20 .80
937 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
940 @item @emph{Fortran}:
941 @multitable @columnfractions .20 .80
942 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
943 @item @tab @code{integer(kind=omp_sched_kind) kind}
944 @item @tab @code{integer modifier}
947 @item @emph{See also}:
948 @ref{omp_get_schedule}
951 @item @emph{Reference}:
952 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
958 @section @code{omp_init_lock} -- Initialize simple lock
960 @item @emph{Description}:
961 Initialize a simple lock. After initialization, the lock is in
965 @multitable @columnfractions .20 .80
966 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
969 @item @emph{Fortran}:
970 @multitable @columnfractions .20 .80
971 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
972 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
975 @item @emph{See also}:
976 @ref{omp_destroy_lock}
978 @item @emph{Reference}:
979 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
985 @section @code{omp_set_lock} -- Wait for and set simple lock
987 @item @emph{Description}:
988 Before setting a simple lock, the lock variable must be initialized by
989 @code{omp_init_lock}. The calling thread is blocked until the lock
990 is available. If the lock is already held by the current thread,
994 @multitable @columnfractions .20 .80
995 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
998 @item @emph{Fortran}:
999 @multitable @columnfractions .20 .80
1000 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1001 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1004 @item @emph{See also}:
1005 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1007 @item @emph{Reference}:
1008 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1014 @section @code{omp_test_lock} -- Test and set simple lock if available
1016 @item @emph{Description}:
1017 Before setting a simple lock, the lock variable must be initialized by
1018 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1019 does not block if the lock is not available. This function returns
1020 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1021 @code{false} represent their language-specific counterparts.
1024 @multitable @columnfractions .20 .80
1025 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1028 @item @emph{Fortran}:
1029 @multitable @columnfractions .20 .80
1030 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1031 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1034 @item @emph{See also}:
1035 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1037 @item @emph{Reference}:
1038 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1043 @node omp_unset_lock
1044 @section @code{omp_unset_lock} -- Unset simple lock
1046 @item @emph{Description}:
1047 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1048 or @code{omp_test_lock} before. In addition, the lock must be held by the
1049 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1050 or more threads attempted to set the lock before, one of them is chosen to,
1051 again, set the lock to itself.
1054 @multitable @columnfractions .20 .80
1055 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1058 @item @emph{Fortran}:
1059 @multitable @columnfractions .20 .80
1060 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1061 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1064 @item @emph{See also}:
1065 @ref{omp_set_lock}, @ref{omp_test_lock}
1067 @item @emph{Reference}:
1068 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1073 @node omp_destroy_lock
1074 @section @code{omp_destroy_lock} -- Destroy simple lock
1076 @item @emph{Description}:
1077 Destroy a simple lock. In order to be destroyed, a simple lock must be
1078 in the unlocked state.
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1085 @item @emph{Fortran}:
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1088 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1091 @item @emph{See also}:
1094 @item @emph{Reference}:
1095 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1100 @node omp_init_nest_lock
1101 @section @code{omp_init_nest_lock} -- Initialize nested lock
1103 @item @emph{Description}:
1104 Initialize a nested lock. After initialization, the lock is in
1105 an unlocked state and the nesting count is set to zero.
1108 @multitable @columnfractions .20 .80
1109 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1112 @item @emph{Fortran}:
1113 @multitable @columnfractions .20 .80
1114 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1115 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1118 @item @emph{See also}:
1119 @ref{omp_destroy_nest_lock}
1121 @item @emph{Reference}:
1122 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1126 @node omp_set_nest_lock
1127 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1129 @item @emph{Description}:
1130 Before setting a nested lock, the lock variable must be initialized by
1131 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1132 is available. If the lock is already held by the current thread, the
1133 nesting count for the lock is incremented.
1136 @multitable @columnfractions .20 .80
1137 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1140 @item @emph{Fortran}:
1141 @multitable @columnfractions .20 .80
1142 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1143 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1146 @item @emph{See also}:
1147 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1149 @item @emph{Reference}:
1150 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1155 @node omp_test_nest_lock
1156 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1158 @item @emph{Description}:
1159 Before setting a nested lock, the lock variable must be initialized by
1160 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1161 @code{omp_test_nest_lock} does not block if the lock is not available.
1162 If the lock is already held by the current thread, the new nesting count
1163 is returned. Otherwise, the return value equals zero.
1166 @multitable @columnfractions .20 .80
1167 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1170 @item @emph{Fortran}:
1171 @multitable @columnfractions .20 .80
1172 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1173 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1177 @item @emph{See also}:
1178 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1180 @item @emph{Reference}:
1181 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1186 @node omp_unset_nest_lock
1187 @section @code{omp_unset_nest_lock} -- Unset nested lock
1189 @item @emph{Description}:
1190 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1191 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1192 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1193 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1194 one of them is chosen to, again, set the lock to itself.
1197 @multitable @columnfractions .20 .80
1198 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1201 @item @emph{Fortran}:
1202 @multitable @columnfractions .20 .80
1203 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1204 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1207 @item @emph{See also}:
1208 @ref{omp_set_nest_lock}
1210 @item @emph{Reference}:
1211 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1216 @node omp_destroy_nest_lock
1217 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1219 @item @emph{Description}:
1220 Destroy a nested lock. In order to be destroyed, a nested lock must be
1221 in the unlocked state and its nesting count must equal zero.
1224 @multitable @columnfractions .20 .80
1225 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1228 @item @emph{Fortran}:
1229 @multitable @columnfractions .20 .80
1230 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1231 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1234 @item @emph{See also}:
1237 @item @emph{Reference}:
1238 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1244 @section @code{omp_get_wtick} -- Get timer precision
1246 @item @emph{Description}:
1247 Gets the timer precision, i.e., the number of seconds between two
1248 successive clock ticks.
1251 @multitable @columnfractions .20 .80
1252 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1255 @item @emph{Fortran}:
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1260 @item @emph{See also}:
1263 @item @emph{Reference}:
1264 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1270 @section @code{omp_get_wtime} -- Elapsed wall clock time
1272 @item @emph{Description}:
1273 Elapsed wall clock time in seconds. The time is measured per thread, no
1274 guarantee can be made that two distinct threads measure the same time.
1275 Time is measured from some "time in the past", which is an arbitrary time
1276 guaranteed not to change during the execution of the program.
1279 @multitable @columnfractions .20 .80
1280 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1283 @item @emph{Fortran}:
1284 @multitable @columnfractions .20 .80
1285 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1288 @item @emph{See also}:
1291 @item @emph{Reference}:
1292 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
1297 @c ---------------------------------------------------------------------
1298 @c Environment Variables
1299 @c ---------------------------------------------------------------------
1301 @node Environment Variables
1302 @chapter Environment Variables
1304 The environment variables which beginning with @env{OMP_} are defined by
1305 section 4 of the OpenMP specification in version 4.0, while those
1306 beginning with @env{GOMP_} are GNU extensions.
1309 * OMP_CANCELLATION:: Set whether cancellation is activated
1310 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1311 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1312 * OMP_DYNAMIC:: Dynamic adjustment of threads
1313 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1314 * OMP_NESTED:: Nested parallel regions
1315 * OMP_NUM_THREADS:: Specifies the number of threads to use
1316 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1317 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1318 * OMP_STACKSIZE:: Set default thread stack size
1319 * OMP_SCHEDULE:: How threads are scheduled
1320 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1321 * OMP_WAIT_POLICY:: How waiting threads are handled
1322 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1323 * GOMP_DEBUG:: Enable debugging output
1324 * GOMP_STACKSIZE:: Set default thread stack size
1325 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1329 @node OMP_CANCELLATION
1330 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1331 @cindex Environment Variable
1333 @item @emph{Description}:
1334 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1335 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1337 @item @emph{See also}:
1338 @ref{omp_get_cancellation}
1340 @item @emph{Reference}:
1341 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1346 @node OMP_DISPLAY_ENV
1347 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1348 @cindex Environment Variable
1350 @item @emph{Description}:
1351 If set to @code{TRUE}, the OpenMP version number and the values
1352 associated with the OpenMP environment variables are printed to @code{stderr}.
1353 If set to @code{VERBOSE}, it additionally shows the value of the environment
1354 variables which are GNU extensions. If undefined or set to @code{FALSE},
1355 this information will not be shown.
1358 @item @emph{Reference}:
1359 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
1364 @node OMP_DEFAULT_DEVICE
1365 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1366 @cindex Environment Variable
1368 @item @emph{Description}:
1369 Set to choose the device which is used in a @code{target} region, unless the
1370 value is overridden by @code{omp_set_default_device} or by a @code{device}
1371 clause. The value shall be the nonnegative device number. If no device with
1372 the given device number exists, the code is executed on the host. If unset,
1373 device number 0 will be used.
1376 @item @emph{See also}:
1377 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1379 @item @emph{Reference}:
1380 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1386 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1387 @cindex Environment Variable
1389 @item @emph{Description}:
1390 Enable or disable the dynamic adjustment of the number of threads
1391 within a team. The value of this environment variable shall be
1392 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1393 disabled by default.
1395 @item @emph{See also}:
1396 @ref{omp_set_dynamic}
1398 @item @emph{Reference}:
1399 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
1404 @node OMP_MAX_ACTIVE_LEVELS
1405 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1406 @cindex Environment Variable
1408 @item @emph{Description}:
1409 Specifies the initial value for the maximum number of nested parallel
1410 regions. The value of this variable shall be a positive integer.
1411 If undefined, the number of active levels is unlimited.
1413 @item @emph{See also}:
1414 @ref{omp_set_max_active_levels}
1416 @item @emph{Reference}:
1417 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
1423 @section @env{OMP_NESTED} -- Nested parallel regions
1424 @cindex Environment Variable
1425 @cindex Implementation specific setting
1427 @item @emph{Description}:
1428 Enable or disable nested parallel regions, i.e., whether team members
1429 are allowed to create new teams. The value of this environment variable
1430 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
1431 regions are disabled by default.
1433 @item @emph{See also}:
1434 @ref{omp_set_nested}
1436 @item @emph{Reference}:
1437 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
1442 @node OMP_NUM_THREADS
1443 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1444 @cindex Environment Variable
1445 @cindex Implementation specific setting
1447 @item @emph{Description}:
1448 Specifies the default number of threads to use in parallel regions. The
1449 value of this variable shall be a comma-separated list of positive integers;
1450 the value specified the number of threads to use for the corresponding nested
1451 level. If undefined one thread per CPU is used.
1453 @item @emph{See also}:
1454 @ref{omp_set_num_threads}
1456 @item @emph{Reference}:
1457 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
1463 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1464 @cindex Environment Variable
1466 @item @emph{Description}:
1467 Specifies whether threads may be moved between processors. If set to
1468 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1469 they may be moved. Alternatively, a comma separated list with the
1470 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1471 the thread affinity policy for the corresponding nesting level. With
1472 @code{MASTER} the worker threads are in the same place partition as the
1473 master thread. With @code{CLOSE} those are kept close to the master thread
1474 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
1475 across the place partitions is used.
1477 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1478 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1480 @item @emph{See also}:
1481 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1483 @item @emph{Reference}:
1484 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
1490 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1491 @cindex Environment Variable
1493 @item @emph{Description}:
1494 The thread placement can be either specified using an abstract name or by an
1495 explicit list of the places. The abstract names @code{threads}, @code{cores}
1496 and @code{sockets} can be optionally followed by a positive number in
1497 parentheses, which denotes the how many places shall be created. With
1498 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1499 to a single core with the corresponding number of hardware threads; and with
1500 @code{sockets} the place corresponds to a single socket. The resulting
1501 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1504 Alternatively, the placement can be specified explicitly as comma-separated
1505 list of places. A place is specified by set of nonnegative numbers in curly
1506 braces, denoting the denoting the hardware threads. The hardware threads
1507 belonging to a place can either be specified as comma-separated list of
1508 nonnegative thread numbers or using an interval. Multiple places can also be
1509 either specified by a comma-separated list of places or by an interval. To
1510 specify an interval, a colon followed by the count is placed after after
1511 the hardware thread number or the place. Optionally, the length can be
1512 followed by a colon and the stride number -- otherwise a unit stride is
1513 assumed. For instance, the following specifies the same places list:
1514 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1515 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1517 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1518 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1519 between CPUs following no placement policy.
1521 @item @emph{See also}:
1522 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1523 @ref{OMP_DISPLAY_ENV}
1525 @item @emph{Reference}:
1526 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
1532 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1533 @cindex Environment Variable
1535 @item @emph{Description}:
1536 Set the default thread stack size in kilobytes, unless the number
1537 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1538 case the size is, respectively, in bytes, kilobytes, megabytes
1539 or gigabytes. This is different from @code{pthread_attr_setstacksize}
1540 which gets the number of bytes as an argument. If the stack size cannot
1541 be set due to system constraints, an error is reported and the initial
1542 stack size is left unchanged. If undefined, the stack size is system
1545 @item @emph{Reference}:
1546 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
1552 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1553 @cindex Environment Variable
1554 @cindex Implementation specific setting
1556 @item @emph{Description}:
1557 Allows to specify @code{schedule type} and @code{chunk size}.
1558 The value of the variable shall have the form: @code{type[,chunk]} where
1559 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1560 The optional @code{chunk} size shall be a positive integer. If undefined,
1561 dynamic scheduling and a chunk size of 1 is used.
1563 @item @emph{See also}:
1564 @ref{omp_set_schedule}
1566 @item @emph{Reference}:
1567 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
1572 @node OMP_THREAD_LIMIT
1573 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1574 @cindex Environment Variable
1576 @item @emph{Description}:
1577 Specifies the number of threads to use for the whole program. The
1578 value of this variable shall be a positive integer. If undefined,
1579 the number of threads is not limited.
1581 @item @emph{See also}:
1582 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1584 @item @emph{Reference}:
1585 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
1590 @node OMP_WAIT_POLICY
1591 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1592 @cindex Environment Variable
1594 @item @emph{Description}:
1595 Specifies whether waiting threads should be active or passive. If
1596 the value is @code{PASSIVE}, waiting threads should not consume CPU
1597 power while waiting; while the value is @code{ACTIVE} specifies that
1598 they should. If undefined, threads wait actively for a short time
1599 before waiting passively.
1601 @item @emph{See also}:
1602 @ref{GOMP_SPINCOUNT}
1604 @item @emph{Reference}:
1605 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
1610 @node GOMP_CPU_AFFINITY
1611 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1612 @cindex Environment Variable
1614 @item @emph{Description}:
1615 Binds threads to specific CPUs. The variable should contain a space-separated
1616 or comma-separated list of CPUs. This list may contain different kinds of
1617 entries: either single CPU numbers in any order, a range of CPUs (M-N)
1618 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
1619 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1620 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1621 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1622 and 14 respectively and then start assigning back from the beginning of
1623 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1625 There is no libgomp library routine to determine whether a CPU affinity
1626 specification is in effect. As a workaround, language-specific library
1627 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1628 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1629 environment variable. A defined CPU affinity on startup cannot be changed
1630 or disabled during the runtime of the application.
1632 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1633 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
1634 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1635 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1637 @item @emph{See also}:
1638 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1644 @section @env{GOMP_DEBUG} -- Enable debugging output
1645 @cindex Environment Variable
1647 @item @emph{Description}:
1648 Enable debugging output. The variable should be set to @code{0}
1649 (disabled, also the default if not set), or @code{1} (enabled).
1651 If enabled, some debugging output will be printed during execution.
1652 This is currently not specified in more detail, and subject to change.
1657 @node GOMP_STACKSIZE
1658 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1659 @cindex Environment Variable
1660 @cindex Implementation specific setting
1662 @item @emph{Description}:
1663 Set the default thread stack size in kilobytes. This is different from
1664 @code{pthread_attr_setstacksize} which gets the number of bytes as an
1665 argument. If the stack size cannot be set due to system constraints, an
1666 error is reported and the initial stack size is left unchanged. If undefined,
1667 the stack size is system dependent.
1669 @item @emph{See also}:
1672 @item @emph{Reference}:
1673 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1674 GCC Patches Mailinglist},
1675 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1676 GCC Patches Mailinglist}
1681 @node GOMP_SPINCOUNT
1682 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1683 @cindex Environment Variable
1684 @cindex Implementation specific setting
1686 @item @emph{Description}:
1687 Determines how long a threads waits actively with consuming CPU power
1688 before waiting passively without consuming CPU power. The value may be
1689 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1690 integer which gives the number of spins of the busy-wait loop. The
1691 integer may optionally be followed by the following suffixes acting
1692 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1693 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1694 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1695 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1696 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1697 If there are more OpenMP threads than available CPUs, 1000 and 100
1698 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1699 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1700 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1702 @item @emph{See also}:
1703 @ref{OMP_WAIT_POLICY}
1708 @c ---------------------------------------------------------------------
1710 @c ---------------------------------------------------------------------
1712 @node The libgomp ABI
1713 @chapter The libgomp ABI
1715 The following sections present notes on the external ABI as
1716 presented by libgomp. Only maintainers should need them.
1719 * Implementing MASTER construct::
1720 * Implementing CRITICAL construct::
1721 * Implementing ATOMIC construct::
1722 * Implementing FLUSH construct::
1723 * Implementing BARRIER construct::
1724 * Implementing THREADPRIVATE construct::
1725 * Implementing PRIVATE clause::
1726 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
1727 * Implementing REDUCTION clause::
1728 * Implementing PARALLEL construct::
1729 * Implementing FOR construct::
1730 * Implementing ORDERED construct::
1731 * Implementing SECTIONS construct::
1732 * Implementing SINGLE construct::
1736 @node Implementing MASTER construct
1737 @section Implementing MASTER construct
1740 if (omp_get_thread_num () == 0)
1744 Alternately, we generate two copies of the parallel subfunction
1745 and only include this in the version run by the master thread.
1746 Surely this is not worthwhile though...
1750 @node Implementing CRITICAL construct
1751 @section Implementing CRITICAL construct
1753 Without a specified name,
1756 void GOMP_critical_start (void);
1757 void GOMP_critical_end (void);
1760 so that we don't get COPY relocations from libgomp to the main
1763 With a specified name, use omp_set_lock and omp_unset_lock with
1764 name being transformed into a variable declared like
1767 omp_lock_t gomp_critical_user_<name> __attribute__((common))
1770 Ideally the ABI would specify that all zero is a valid unlocked
1771 state, and so we wouldn't need to initialize this at
1776 @node Implementing ATOMIC construct
1777 @section Implementing ATOMIC construct
1779 The target should implement the @code{__sync} builtins.
1781 Failing that we could add
1784 void GOMP_atomic_enter (void)
1785 void GOMP_atomic_exit (void)
1788 which reuses the regular lock code, but with yet another lock
1789 object private to the library.
1793 @node Implementing FLUSH construct
1794 @section Implementing FLUSH construct
1796 Expands to the @code{__sync_synchronize} builtin.
1800 @node Implementing BARRIER construct
1801 @section Implementing BARRIER construct
1804 void GOMP_barrier (void)
1808 @node Implementing THREADPRIVATE construct
1809 @section Implementing THREADPRIVATE construct
1811 In _most_ cases we can map this directly to @code{__thread}. Except
1812 that OMP allows constructors for C++ objects. We can either
1813 refuse to support this (how often is it used?) or we can
1814 implement something akin to .ctors.
1816 Even more ideally, this ctor feature is handled by extensions
1817 to the main pthreads library. Failing that, we can have a set
1818 of entry points to register ctor functions to be called.
1822 @node Implementing PRIVATE clause
1823 @section Implementing PRIVATE clause
1825 In association with a PARALLEL, or within the lexical extent
1826 of a PARALLEL block, the variable becomes a local variable in
1827 the parallel subfunction.
1829 In association with FOR or SECTIONS blocks, create a new
1830 automatic variable within the current function. This preserves
1831 the semantic of new variable creation.
1835 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1836 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1838 This seems simple enough for PARALLEL blocks. Create a private
1839 struct for communicating between the parent and subfunction.
1840 In the parent, copy in values for scalar and "small" structs;
1841 copy in addresses for others TREE_ADDRESSABLE types. In the
1842 subfunction, copy the value into the local variable.
1844 It is not clear what to do with bare FOR or SECTION blocks.
1845 The only thing I can figure is that we do something like:
1848 #pragma omp for firstprivate(x) lastprivate(y)
1849 for (int i = 0; i < n; ++i)
1866 where the "x=x" and "y=y" assignments actually have different
1867 uids for the two variables, i.e. not something you could write
1868 directly in C. Presumably this only makes sense if the "outer"
1869 x and y are global variables.
1871 COPYPRIVATE would work the same way, except the structure
1872 broadcast would have to happen via SINGLE machinery instead.
1876 @node Implementing REDUCTION clause
1877 @section Implementing REDUCTION clause
1879 The private struct mentioned in the previous section should have
1880 a pointer to an array of the type of the variable, indexed by the
1881 thread's @var{team_id}. The thread stores its final value into the
1882 array, and after the barrier, the master thread iterates over the
1883 array to collect the values.
1886 @node Implementing PARALLEL construct
1887 @section Implementing PARALLEL construct
1890 #pragma omp parallel
1899 void subfunction (void *data)
1906 GOMP_parallel_start (subfunction, &data, num_threads);
1907 subfunction (&data);
1908 GOMP_parallel_end ();
1912 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1915 The @var{FN} argument is the subfunction to be run in parallel.
1917 The @var{DATA} argument is a pointer to a structure used to
1918 communicate data in and out of the subfunction, as discussed
1919 above with respect to FIRSTPRIVATE et al.
1921 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1922 and false, or the value of the NUM_THREADS clause, if
1925 The function needs to create the appropriate number of
1926 threads and/or launch them from the dock. It needs to
1927 create the team structure and assign team ids.
1930 void GOMP_parallel_end (void)
1933 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1937 @node Implementing FOR construct
1938 @section Implementing FOR construct
1941 #pragma omp parallel for
1942 for (i = lb; i <= ub; i++)
1949 void subfunction (void *data)
1952 while (GOMP_loop_static_next (&_s0, &_e0))
1955 for (i = _s0; i < _e1; i++)
1958 GOMP_loop_end_nowait ();
1961 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
1963 GOMP_parallel_end ();
1967 #pragma omp for schedule(runtime)
1968 for (i = 0; i < n; i++)
1977 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
1980 for (i = _s0, i < _e0; i++)
1982 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
1987 Note that while it looks like there is trickiness to propagating
1988 a non-constant STEP, there isn't really. We're explicitly allowed
1989 to evaluate it as many times as we want, and any variables involved
1990 should automatically be handled as PRIVATE or SHARED like any other
1991 variables. So the expression should remain evaluable in the
1992 subfunction. We can also pull it into a local variable if we like,
1993 but since its supposed to remain unchanged, we can also not if we like.
1995 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
1996 able to get away with no work-sharing context at all, since we can
1997 simply perform the arithmetic directly in each thread to divide up
1998 the iterations. Which would mean that we wouldn't need to call any
2001 There are separate routines for handling loops with an ORDERED
2002 clause. Bookkeeping for that is non-trivial...
2006 @node Implementing ORDERED construct
2007 @section Implementing ORDERED construct
2010 void GOMP_ordered_start (void)
2011 void GOMP_ordered_end (void)
2016 @node Implementing SECTIONS construct
2017 @section Implementing SECTIONS construct
2022 #pragma omp sections
2036 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2053 @node Implementing SINGLE construct
2054 @section Implementing SINGLE construct
2068 if (GOMP_single_start ())
2076 #pragma omp single copyprivate(x)
2083 datap = GOMP_single_copy_start ();
2088 GOMP_single_copy_end (&data);
2097 @c ---------------------------------------------------------------------
2099 @c ---------------------------------------------------------------------
2101 @node Reporting Bugs
2102 @chapter Reporting Bugs
2104 Bugs in the GNU Offloading and Multi Processing Runtime Library should
2105 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
2106 "openacc", or "openmp", or both to the keywords field in the bug
2107 report, as appropriate.
2111 @c ---------------------------------------------------------------------
2112 @c GNU General Public License
2113 @c ---------------------------------------------------------------------
2115 @include gpl_v3.texi
2119 @c ---------------------------------------------------------------------
2120 @c GNU Free Documentation License
2121 @c ---------------------------------------------------------------------
2127 @c ---------------------------------------------------------------------
2128 @c Funding Free Software
2129 @c ---------------------------------------------------------------------
2131 @include funding.texi
2133 @c ---------------------------------------------------------------------
2135 @c ---------------------------------------------------------------------
2138 @unnumbered Library Index