1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006 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.1 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``GNU General Public License'' and ``Funding
16 Free Software'', the Front-Cover
17 texts being (a) (see below), and with the Back-Cover Texts being (b)
18 (see below). A copy of the license is included in the section entitled
19 ``GNU Free Documentation License''.
21 (a) The FSF's Front-Cover Text is:
25 (b) The FSF's Back-Cover Text is:
27 You have freedom to copy and modify this GNU Manual, like GNU
28 software. Copies published by the Free Software Foundation raise
29 funds for GNU development.
33 @dircategory GNU Libraries
35 * libgomp: (libgomp). GNU OpenMP runtime library
38 This manual documents 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 The GNU OpenMP Implementation
54 @vskip 0pt plus 1filll
55 @comment For the @value{version-GCC} Version*
57 Published by the Free Software Foundation @*
58 51 Franklin Street, Fifth Floor@*
59 Boston, MA 02110-1301, USA@*
73 This manual documents the usage of libgomp, the GNU implementation of the
74 @uref{http://www.openmp.org, OpenMP} Application Programming Interface (API)
75 for multi-platform shared-memory parallel programming in C/C++ and Fortran.
80 @comment When you add a new menu item, please keep the right hand
81 @comment aligned to the same column. Do not use tabs. This provides
82 @comment better formatting.
85 * Enabling OpenMP:: How to enable OpenMP for your applications.
86 * Runtime Library Routines:: The OpenMP runtime application programming
88 * Environment Variables:: Influencing runtime behavior with environment
90 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
91 * Reporting Bugs:: How to report bugs in GNU OpenMP.
92 * Copying:: GNU general public license says
93 how you can copy and share libgomp.
94 * GNU Free Documentation License::
95 How you can copy and share this manual.
96 * Funding:: How to help assure continued work for free
98 * Index:: Index of this documentation.
102 @c ---------------------------------------------------------------------
104 @c ---------------------------------------------------------------------
106 @node Enabling OpenMP
107 @chapter Enabling OpenMP
109 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
110 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
111 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
112 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
113 @code{!$} conditional compilation sentinels in free form and @code{c$},
114 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
115 arranges for automatic linking of the OpenMP runtime library
116 (@ref{Runtime Library Routines}).
118 A complete description of all OpenMP directives accepted may be found in
119 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
123 @c ---------------------------------------------------------------------
124 @c Runtime Library Routines
125 @c ---------------------------------------------------------------------
127 @node Runtime Library Routines
128 @chapter Runtime Library Routines
130 The runtime routines described here are defined by section 3 of the OpenMP
131 specifications in version 2.5.
133 Control threads, processors and the parallel environment.
136 * omp_get_dynamic:: Dynamic teams setting
137 * omp_get_max_threads:: Maximum number of threads
138 * omp_get_nested:: Nested parallel regions
139 * omp_get_num_procs:: Number of processors online
140 * omp_get_num_threads:: Size of the active team
141 * omp_get_thread_num:: Current thread ID
142 * omp_in_parallel:: Whether a parallel region is active
143 * omp_set_dynamic:: Enable/disable dynamic teams
144 * omp_set_nested:: Enable/disable nested parallel regions
145 * omp_set_num_threads:: Set upper team size limit
148 Initialize, set, test, unset and destroy simple and nested locks.
151 * omp_init_lock:: Initialize simple lock
152 * omp_set_lock:: Wait for and set simple lock
153 * omp_test_lock:: Test and set simple lock if available
154 * omp_unset_lock:: Unset simple lock
155 * omp_destroy_lock:: Destroy simple lock
156 * omp_init_nest_lock:: Initialize nested lock
157 * omp_set_nest_lock:: Wait for and set simple lock
158 * omp_test_nest_lock:: Test and set nested lock if available
159 * omp_unset_nest_lock:: Unset nested lock
160 * omp_destroy_nest_lock:: Destroy nested lock
163 Portable, thread-based, wall clock timer.
166 * omp_get_wtick:: Get timer precision.
167 * omp_get_wtime:: Elapsed wall clock time.
170 @node omp_get_dynamic
171 @section @code{omp_get_dynamic} -- Dynamic teams setting
173 @item @emph{Description}:
174 This function returns @code{true} if enabled, @code{false} otherwise.
175 Here, @code{true} and @code{false} represent their language-specific
178 The dynamic team setting may be initialized at startup by the
179 @code{OMP_DYNAMIC} environment variable or at runtime using
180 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
184 @multitable @columnfractions .20 .80
185 @item @emph{Prototype}: @tab @code{int omp_get_dynamic();}
188 @item @emph{Fortran}:
189 @multitable @columnfractions .20 .80
190 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
193 @item @emph{See also}:
194 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
196 @item @emph{Reference}:
197 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.8.
202 @node omp_get_max_threads
203 @section @code{omp_get_max_threads} -- Maximum number of threads
205 @item @emph{Description}:
206 Return the maximum number of threads used for parallel regions that do
207 not use the clause @code{num_threads}.
210 @multitable @columnfractions .20 .80
211 @item @emph{Prototype}: @tab @code{int omp_get_max_threads();}
214 @item @emph{Fortran}:
215 @multitable @columnfractions .20 .80
216 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
219 @item @emph{See also}:
220 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}
222 @item @emph{Reference}:
223 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.3.
229 @section @code{omp_get_nested} -- Nested parallel regions
231 @item @emph{Description}:
232 This function returns @code{true} if nested parallel regions are
233 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
234 represent their language-specific counterparts.
236 Nested parallel regions may be initialized at startup by the
237 @code{OMP_NESTED} environment variable or at runtime using
238 @code{omp_set_nested}. If undefined, nested parallel regions are
242 @multitable @columnfractions .20 .80
243 @item @emph{Prototype}: @tab @code{int omp_get_nested();}
246 @item @emph{Fortran}:
247 @multitable @columnfractions .20 .80
248 @item @emph{Interface}: @tab @code{integer function omp_get_nested()}
251 @item @emph{See also}:
252 @ref{omp_set_nested}, @ref{OMP_NESTED}
254 @item @emph{Reference}:
255 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.10.
260 @node omp_get_num_procs
261 @section @code{omp_get_num_procs} -- Number of processors online
263 @item @emph{Description}:
264 Returns the number of processors online.
267 @multitable @columnfractions .20 .80
268 @item @emph{Prototype}: @tab @code{int omp_get_num_procs();}
271 @item @emph{Fortran}:
272 @multitable @columnfractions .20 .80
273 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
276 @item @emph{Reference}:
277 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.5.
282 @node omp_get_num_threads
283 @section @code{omp_get_num_threads} -- Size of the active team
285 @item @emph{Description}:
286 The number of threads in the current team. In a sequential section of
287 the program @code{omp_get_num_threads} returns 1.
289 The default team size may be initialized at startup by the
290 @code{OMP_NUM_THREADS} environment variable. At runtime, the size
291 of the current team may be set either by the @code{NUM_THREADS}
292 clause or by @code{omp_set_num_threads}. If none of the above were
293 used to define a specific value and @code{OMP_DYNAMIC} is disabled,
294 one thread per CPU online is used.
297 @multitable @columnfractions .20 .80
298 @item @emph{Prototype}: @tab @code{int omp_get_num_threads();}
301 @item @emph{Fortran}:
302 @multitable @columnfractions .20 .80
303 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
306 @item @emph{See also}:
307 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
309 @item @emph{Reference}:
310 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.2.
315 @node omp_get_thread_num
316 @section @code{omp_get_thread_num} -- Current thread ID
318 @item @emph{Description}:
319 Unique thread identification number. In a sequential parts of the program,
320 @code{omp_get_thread_num} always returns 0. In parallel regions the return
321 value varies from 0 to @code{omp_get_max_threads}-1 inclusive. The return
322 value of the master thread of a team is always 0.
325 @multitable @columnfractions .20 .80
326 @item @emph{Prototype}: @tab @code{int omp_get_thread_num();}
329 @item @emph{Fortran}:
330 @multitable @columnfractions .20 .80
331 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
334 @item @emph{See also}:
335 @ref{omp_get_max_threads}
337 @item @emph{Reference}:
338 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.4.
343 @node omp_in_parallel
344 @section @code{omp_in_parallel} -- Whether a parallel region is active
346 @item @emph{Description}:
347 This function returns @code{true} if currently running in parallel,
348 @code{false} otherwise. Here, @code{true} and @code{false} represent
349 their language-specific counterparts.
352 @multitable @columnfractions .20 .80
353 @item @emph{Prototype}: @tab @code{int omp_in_parallel();}
356 @item @emph{Fortran}:
357 @multitable @columnfractions .20 .80
358 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
361 @item @emph{Reference}:
362 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.6.
366 @node omp_set_dynamic
367 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
369 @item @emph{Description}:
370 Enable or disable the dynamic adjustment of the number of threads
371 within a team. The function takes the language-specific equivalent
372 of @code{true} and @code{false}, where @code{true} enables dynamic
373 adjustment of team sizes and @code{false} disables it.
376 @multitable @columnfractions .20 .80
377 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int);}
380 @item @emph{Fortran}:
381 @multitable @columnfractions .20 .80
382 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(set)}
383 @item @tab @code{integer, intent(in) :: set}
386 @item @emph{See also}:
387 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
389 @item @emph{Reference}:
390 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.7.
396 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
398 @item @emph{Description}:
399 Enable or disable nested parallel regions, i.e., whether team members
400 are allowed to create new teams. The function takes the language-specific
401 equivalent of @code{true} and @code{false}, where @code{true} enables
402 dynamic adjustment of team sizes and @code{false} disables it.
405 @multitable @columnfractions .20 .80
406 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int);}
409 @item @emph{Fortran}:
410 @multitable @columnfractions .20 .80
411 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(set)}
412 @item @tab @code{integer, intent(in) :: set}
415 @item @emph{See also}:
416 @ref{OMP_NESTED}, @ref{omp_get_nested}
418 @item @emph{Reference}:
419 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.9.
424 @node omp_set_num_threads
425 @section @code{omp_set_num_threads} -- Set upper team size limit
427 @item @emph{Description}:
428 Specifies the number of threads used by default in subsequent parallel
429 sections, if those do not specify a @code{num_threads} clause. The
430 argument of @code{omp_set_num_threads} shall be a positive integer.
433 @multitable @columnfractions .20 .80
434 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int);}
437 @item @emph{Fortran}:
438 @multitable @columnfractions .20 .80
439 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(set)}
440 @item @tab @code{integer, intent(in) :: set}
443 @item @emph{See also}:
444 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
446 @item @emph{Reference}:
447 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.1.
453 @section @code{omp_init_lock} -- Initialize simple lock
455 @item @emph{Description}:
456 Initialize a simple lock. After initialization, the lock is in
460 @multitable @columnfractions .20 .80
461 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
464 @item @emph{Fortran}:
465 @multitable @columnfractions .20 .80
466 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(lock)}
467 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
470 @item @emph{See also}:
471 @ref{omp_destroy_lock}
473 @item @emph{Reference}:
474 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.1.
480 @section @code{omp_set_lock} -- Wait for and set simple lock
482 @item @emph{Description}:
483 Before setting a simple lock, the lock variable must be initialized by
484 @code{omp_init_lock}. The calling thread is blocked until the lock
485 is available. If the lock is already held by the current thread,
489 @multitable @columnfractions .20 .80
490 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
493 @item @emph{Fortran}:
494 @multitable @columnfractions .20 .80
495 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(lock)}
496 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
499 @item @emph{See also}:
500 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
502 @item @emph{Reference}:
503 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.3.
509 @section @code{omp_test_lock} -- Test and set simple lock if available
511 @item @emph{Description}:
512 Before setting a simple lock, the lock variable must be initialized by
513 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
514 does not block if the lock is not available. This function returns
515 @code{true} upon success,@code{false} otherwise. Here, @code{true} and
516 @code{false} represent their language-specific counterparts.
519 @multitable @columnfractions .20 .80
520 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
523 @item @emph{Fortran}:
524 @multitable @columnfractions .20 .80
525 @item @emph{Interface}: @tab @code{subroutine omp_test_lock(lock)}
526 @item @tab @code{logical(omp_logical_kind) :: omp_test_lock}
527 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
530 @item @emph{See also}:
531 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
533 @item @emph{Reference}:
534 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.5.
540 @section @code{omp_unset_lock} -- Unset simple lock
542 @item @emph{Description}:
543 A simple lock about to be unset must have been locked by @code{omp_set_lock}
544 or @code{omp_test_lock} before. In addition, the lock must be held by the
545 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
546 ore more threads attempted to set the lock before, one of them is chosen to,
547 again, set the lock for itself.
550 @multitable @columnfractions .20 .80
551 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
554 @item @emph{Fortran}:
555 @multitable @columnfractions .20 .80
556 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(lock)}
557 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
560 @item @emph{See also}:
561 @ref{omp_set_lock}, @ref{omp_test_lock}
563 @item @emph{Reference}:
564 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.4.
569 @node omp_destroy_lock
570 @section @code{omp_destroy_lock} -- Destroy simple lock
572 @item @emph{Description}:
573 Destroy a simple lock. In order to be destroyed, a simple lock must be
574 in the unlocked state.
577 @multitable @columnfractions .20 .80
578 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *);}
581 @item @emph{Fortran}:
582 @multitable @columnfractions .20 .80
583 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(lock)}
584 @item @tab @code{integer(omp_lock_kind), intent(inout) :: lock}
587 @item @emph{See also}:
590 @item @emph{Reference}:
591 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.2.
596 @node omp_init_nest_lock
597 @section @code{omp_init_nest_lock} -- Initialize nested lock
599 @item @emph{Description}:
600 Initialize a nested lock. After initialization, the lock is in
601 an unlocked state and the nesting count is set to zero.
604 @multitable @columnfractions .20 .80
605 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
608 @item @emph{Fortran}:
609 @multitable @columnfractions .20 .80
610 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(lock)}
611 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
614 @item @emph{See also}:
615 @ref{omp_destroy_nest_lock}
617 @item @emph{Reference}:
618 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.1.
622 @node omp_set_nest_lock
623 @section @code{omp_set_nest_lock} -- Wait for and set simple lock
625 @item @emph{Description}:
626 Before setting a nested lock, the lock variable must be initialized by
627 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
628 is available. If the lock is already held by the current thread, the
629 nesting count for the lock in incremented.
632 @multitable @columnfractions .20 .80
633 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
636 @item @emph{Fortran}:
637 @multitable @columnfractions .20 .80
638 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(lock)}
639 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
642 @item @emph{See also}:
643 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
645 @item @emph{Reference}:
646 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.3.
651 @node omp_test_nest_lock
652 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
654 @item @emph{Description}:
655 Before setting a nested lock, the lock variable must be initialized by
656 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
657 @code{omp_test_nest_lock} does not block if the lock is not available.
658 If the lock is already held by the current thread, the new nesting count
659 is returned. Otherwise, the return value equals zero.
662 @multitable @columnfractions .20 .80
663 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
666 @item @emph{Fortran}:
667 @multitable @columnfractions .20 .80
668 @item @emph{Interface}: @tab @code{integer function omp_test_nest_lock(lock)}
669 @item @tab @code{integer(omp_integer_kind) :: omp_test_nest_lock}
670 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: lock}
674 @item @emph{See also}:
675 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
677 @item @emph{Reference}:
678 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.5.
683 @node omp_unset_nest_lock
684 @section @code{omp_unset_nest_lock} -- Unset nested lock
686 @item @emph{Description}:
687 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
688 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
689 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
690 lock becomes unlocked. If one ore more threads attempted to set the lock before,
691 one of them is chosen to, again, set the lock for itself.
694 @multitable @columnfractions .20 .80
695 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
698 @item @emph{Fortran}:
699 @multitable @columnfractions .20 .80
700 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(lock)}
701 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
704 @item @emph{See also}:
705 @ref{omp_set_nest_lock}
707 @item @emph{Reference}:
708 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.4.
713 @node omp_destroy_nest_lock
714 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
716 @item @emph{Description}:
717 Destroy a nested lock. In order to be destroyed, a nested lock must be
718 in the unlocked state and its nesting count must equal zero.
721 @multitable @columnfractions .20 .80
722 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
725 @item @emph{Fortran}:
726 @multitable @columnfractions .20 .80
727 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(lock)}
728 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: lock}
731 @item @emph{See also}:
734 @item @emph{Reference}:
735 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.2.
741 @section @code{omp_get_wtick} -- Get timer precision
743 @item @emph{Description}:
744 Gets the timer precision, i.e., the number of seconds between two
745 successive clock ticks.
748 @multitable @columnfractions .20 .80
749 @item @emph{Prototype}: @tab @code{double omp_get_wtick();}
752 @item @emph{Fortran}:
753 @multitable @columnfractions .20 .80
754 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
757 @item @emph{See also}:
760 @item @emph{Reference}:
761 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.4.2.
767 @section @code{omp_get_wtime} -- Elapsed wall clock time
769 @item @emph{Description}:
770 Elapsed wall clock time in seconds. The time is measured per thread, no
771 guarantee can bee made that two distinct threads measure the same time.
772 Time is measured from some "time in the past". On POSIX compliant systems
773 the seconds since the Epoch (00:00:00 UTC, January 1, 1970) are returned.
776 @multitable @columnfractions .20 .80
777 @item @emph{Prototype}: @tab @code{double omp_get_wtime();}
780 @item @emph{Fortran}:
781 @multitable @columnfractions .20 .80
782 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
785 @item @emph{See also}:
788 @item @emph{Reference}:
789 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.4.1.
794 @c ---------------------------------------------------------------------
795 @c Environment Variables
796 @c ---------------------------------------------------------------------
798 @node Environment Variables
799 @chapter Environment Variables
801 The variables @env{OMP_DYNAMIC}, @env{OMP_NESTED}, @env{OMP_NUM_THREADS} and
802 @env{OMP_SCHEDULE} are defined by section 4 of the OpenMP specifications in
803 version 2.5, while @env{GOMP_CPU_AFFINITY} and @env{GOMP_STACKSIZE} are GNU
807 * OMP_DYNAMIC:: Dynamic adjustment of threads
808 * OMP_NESTED:: Nested parallel regions
809 * OMP_NUM_THREADS:: Specifies the number of threads to use
810 * OMP_SCHEDULE:: How threads are scheduled
811 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
812 * GOMP_STACKSIZE:: Set default thread stack size
817 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
818 @cindex Environment Variable
819 @cindex Implementation specific setting
821 @item @emph{Description}:
822 Enable or disable the dynamic adjustment of the number of threads
823 within a team. The value of this environment variable shall be
824 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
827 @item @emph{See also}:
828 @ref{omp_set_dynamic}
830 @item @emph{Reference}:
831 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.3
837 @section @env{OMP_NESTED} -- Nested parallel regions
838 @cindex Environment Variable
839 @cindex Implementation specific setting
841 @item @emph{Description}:
842 Enable or disable nested parallel regions, i.e., whether team members
843 are allowed to create new teams. The value of this environment variable
844 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
845 regions are disabled by default.
847 @item @emph{See also}:
850 @item @emph{Reference}:
851 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.4
856 @node OMP_NUM_THREADS
857 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
858 @cindex Environment Variable
859 @cindex Implementation specific setting
861 @item @emph{Description}:
862 Specifies the default number of threads to use in parallel regions. The
863 value of this variable shall be positive integer. If undefined one thread
864 per CPU online is used.
866 @item @emph{See also}:
867 @ref{omp_set_num_threads}
869 @item @emph{Reference}:
870 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.2
876 @section @env{OMP_SCHEDULE} -- How threads are scheduled
877 @cindex Environment Variable
878 @cindex Implementation specific setting
880 @item @emph{Description}:
881 Allows to specify @code{schedule type} and @code{chunk size}.
882 The value of the variable shall have the form: @code{type[,chunk]} where
883 @code{type} is one of @code{static}, @code{dynamic} or @code{guided}.
884 The optional @code{chunk size} shall be a positive integer. If undefined,
885 dynamic scheduling and a chunk size of 1 is used.
887 @item @emph{Reference}:
888 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, sections 2.5.1 and 4.1
893 @node GOMP_CPU_AFFINITY
894 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
895 @cindex Environment Variable
897 @item @emph{Description}:
898 A patch for this extension has been submitted, but was not yet applied at the
901 @item @emph{Reference}:
902 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00982.html,
903 GCC Patches Mailinglist}
904 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01133.html,
905 GCC Patches Mailinglist}
911 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
912 @cindex Environment Variable
913 @cindex Implementation specific setting
915 @item @emph{Description}:
916 Set the default thread stack size in kilobytes. This is in opposition
917 to @code{pthread_attr_setstacksize} which gets the number of bytes as an
918 argument. If the stacksize can not be set due to system constraints, an
919 error is reported and the initial stacksize is left unchanged. If undefined,
920 the stack size is system dependent.
922 @item @emph{Reference}:
923 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
924 GCC Patches Mailinglist},
925 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
926 GCC Patches Mailinglist}
931 @c ---------------------------------------------------------------------
933 @c ---------------------------------------------------------------------
935 @node The libgomp ABI
936 @chapter The libgomp ABI
938 The following sections present notes on the external ABI as
939 presented by libgomp. Only maintainers should need them.
942 * Implementing MASTER construct::
943 * Implementing CRITICAL construct::
944 * Implementing ATOMIC construct::
945 * Implementing FLUSH construct::
946 * Implementing BARRIER construct::
947 * Implementing THREADPRIVATE construct::
948 * Implementing PRIVATE clause::
949 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
950 * Implementing REDUCTION clause::
951 * Implementing PARALLEL construct::
952 * Implementing FOR construct::
953 * Implementing ORDERED construct::
954 * Implementing SECTIONS construct::
955 * Implementing SINGLE construct::
959 @node Implementing MASTER construct
960 @section Implementing MASTER construct
963 if (omp_get_thread_num () == 0)
967 Alternately, we generate two copies of the parallel subfunction
968 and only include this in the version run by the master thread.
969 Surely that's not worthwhile though...
973 @node Implementing CRITICAL construct
974 @section Implementing CRITICAL construct
976 Without a specified name,
979 void GOMP_critical_start (void);
980 void GOMP_critical_end (void);
983 so that we don't get COPY relocations from libgomp to the main
986 With a specified name, use omp_set_lock and omp_unset_lock with
987 name being transformed into a variable declared like
990 omp_lock_t gomp_critical_user_<name> __attribute__((common))
993 Ideally the ABI would specify that all zero is a valid unlocked
994 state, and so we wouldn't actually need to initialize this at
999 @node Implementing ATOMIC construct
1000 @section Implementing ATOMIC construct
1002 The target should implement the @code{__sync} builtins.
1004 Failing that we could add
1007 void GOMP_atomic_enter (void)
1008 void GOMP_atomic_exit (void)
1011 which reuses the regular lock code, but with yet another lock
1012 object private to the library.
1016 @node Implementing FLUSH construct
1017 @section Implementing FLUSH construct
1019 Expands to the @code{__sync_synchronize} builtin.
1023 @node Implementing BARRIER construct
1024 @section Implementing BARRIER construct
1027 void GOMP_barrier (void)
1031 @node Implementing THREADPRIVATE construct
1032 @section Implementing THREADPRIVATE construct
1034 In _most_ cases we can map this directly to @code{__thread}. Except
1035 that OMP allows constructors for C++ objects. We can either
1036 refuse to support this (how often is it used?) or we can
1037 implement something akin to .ctors.
1039 Even more ideally, this ctor feature is handled by extensions
1040 to the main pthreads library. Failing that, we can have a set
1041 of entry points to register ctor functions to be called.
1045 @node Implementing PRIVATE clause
1046 @section Implementing PRIVATE clause
1048 In association with a PARALLEL, or within the lexical extent
1049 of a PARALLEL block, the variable becomes a local variable in
1050 the parallel subfunction.
1052 In association with FOR or SECTIONS blocks, create a new
1053 automatic variable within the current function. This preserves
1054 the semantic of new variable creation.
1058 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1059 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1061 Seems simple enough for PARALLEL blocks. Create a private
1062 struct for communicating between parent and subfunction.
1063 In the parent, copy in values for scalar and "small" structs;
1064 copy in addresses for others TREE_ADDRESSABLE types. In the
1065 subfunction, copy the value into the local variable.
1067 Not clear at all what to do with bare FOR or SECTION blocks.
1068 The only thing I can figure is that we do something like
1071 #pragma omp for firstprivate(x) lastprivate(y)
1072 for (int i = 0; i < n; ++i)
1089 where the "x=x" and "y=y" assignments actually have different
1090 uids for the two variables, i.e. not something you could write
1091 directly in C. Presumably this only makes sense if the "outer"
1092 x and y are global variables.
1094 COPYPRIVATE would work the same way, except the structure
1095 broadcast would have to happen via SINGLE machinery instead.
1099 @node Implementing REDUCTION clause
1100 @section Implementing REDUCTION clause
1102 The private struct mentioned in the previous section should have
1103 a pointer to an array of the type of the variable, indexed by the
1104 thread's @var{team_id}. The thread stores its final value into the
1105 array, and after the barrier the master thread iterates over the
1106 array to collect the values.
1109 @node Implementing PARALLEL construct
1110 @section Implementing PARALLEL construct
1113 #pragma omp parallel
1122 void subfunction (void *data)
1129 GOMP_parallel_start (subfunction, &data, num_threads);
1130 subfunction (&data);
1131 GOMP_parallel_end ();
1135 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1138 The @var{FN} argument is the subfunction to be run in parallel.
1140 The @var{DATA} argument is a pointer to a structure used to
1141 communicate data in and out of the subfunction, as discussed
1142 above with respect to FIRSTPRIVATE et al.
1144 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1145 and false, or the value of the NUM_THREADS clause, if
1148 The function needs to create the appropriate number of
1149 threads and/or launch them from the dock. It needs to
1150 create the team structure and assign team ids.
1153 void GOMP_parallel_end (void)
1156 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1160 @node Implementing FOR construct
1161 @section Implementing FOR construct
1164 #pragma omp parallel for
1165 for (i = lb; i <= ub; i++)
1172 void subfunction (void *data)
1175 while (GOMP_loop_static_next (&_s0, &_e0))
1178 for (i = _s0; i < _e1; i++)
1181 GOMP_loop_end_nowait ();
1184 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
1186 GOMP_parallel_end ();
1190 #pragma omp for schedule(runtime)
1191 for (i = 0; i < n; i++)
1200 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
1203 for (i = _s0, i < _e0; i++)
1205 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
1210 Note that while it looks like there is trickyness to propagating
1211 a non-constant STEP, there isn't really. We're explicitly allowed
1212 to evaluate it as many times as we want, and any variables involved
1213 should automatically be handled as PRIVATE or SHARED like any other
1214 variables. So the expression should remain evaluable in the
1215 subfunction. We can also pull it into a local variable if we like,
1216 but since its supposed to remain unchanged, we can also not if we like.
1218 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
1219 able to get away with no work-sharing context at all, since we can
1220 simply perform the arithmetic directly in each thread to divide up
1221 the iterations. Which would mean that we wouldn't need to call any
1224 There are separate routines for handling loops with an ORDERED
1225 clause. Bookkeeping for that is non-trivial...
1229 @node Implementing ORDERED construct
1230 @section Implementing ORDERED construct
1233 void GOMP_ordered_start (void)
1234 void GOMP_ordered_end (void)
1239 @node Implementing SECTIONS construct
1240 @section Implementing SECTIONS construct
1245 #pragma omp sections
1259 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
1276 @node Implementing SINGLE construct
1277 @section Implementing SINGLE construct
1291 if (GOMP_single_start ())
1299 #pragma omp single copyprivate(x)
1306 datap = GOMP_single_copy_start ();
1311 GOMP_single_copy_end (&data);
1320 @c ---------------------------------------------------------------------
1322 @c ---------------------------------------------------------------------
1324 @node Reporting Bugs
1325 @chapter Reporting Bugs
1327 Bugs in the GNU OpenMP implementation should be reported via
1328 @uref{http://gcc.gnu.org/bugzilla/, bugzilla}. In all cases, please add
1329 "openmp" to the keywords field in the bug report.
1333 @c ---------------------------------------------------------------------
1334 @c GNU General Public License
1335 @c ---------------------------------------------------------------------
1341 @c ---------------------------------------------------------------------
1342 @c GNU Free Documentation License
1343 @c ---------------------------------------------------------------------
1349 @c ---------------------------------------------------------------------
1350 @c Funding Free Software
1351 @c ---------------------------------------------------------------------
1353 @include funding.texi
1355 @c ---------------------------------------------------------------------
1357 @c ---------------------------------------------------------------------