* c-c++-common/attr-simd-3.c: Requires pthreads.
[gcc.git] / libgomp / libgomp.texi
1 \input texinfo @c -*-texinfo-*-
2
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
7
8
9 @copying
10 Copyright @copyright{} 2006-2015 Free Software Foundation, Inc.
11
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''.
19
20 (a) The FSF's Front-Cover Text is:
21
22 A GNU Manual
23
24 (b) The FSF's Back-Cover Text is:
25
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.
29 @end copying
30
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
36
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
40 Fortran.
41
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
45
46 @insertcopying
47 @end ifinfo
48
49
50 @setchapternewpage odd
51
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
65
66 @summarycontents
67 @contents
68 @page
69
70
71 @node Top
72 @top Introduction
73 @cindex Introduction
74
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++
82 and Fortran.
83
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.
88
89
90
91 @comment
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.
95 @comment
96 @menu
97 * Enabling OpenMP:: How to enable OpenMP for your applications.
98 * Runtime Library Routines:: The OpenMP runtime application programming
99 interface.
100 * Environment Variables:: Influencing runtime behavior with environment
101 variables.
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
110 software.
111 * Library Index:: Index of this documentation.
112 @end menu
113
114
115 @c ---------------------------------------------------------------------
116 @c Enabling OpenMP
117 @c ---------------------------------------------------------------------
118
119 @node Enabling OpenMP
120 @chapter Enabling OpenMP
121
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}).
130
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,
133 version 4.5.
134
135
136 @c ---------------------------------------------------------------------
137 @c Runtime Library Routines
138 @c ---------------------------------------------------------------------
139
140 @node Runtime Library Routines
141 @chapter Runtime Library Routines
142
143 The runtime routines described here are defined by Section 3 of the OpenMP
144 specification in version 4.5. The routines are structured in following
145 three parts:
146
147 @menu
148 Control threads, processors and the parallel environment. They have C
149 linkage, and do not throw exceptions.
150
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_task_priority:: Maximum task priority value that can be set
159 * omp_get_max_threads:: Maximum number of threads of parallel region
160 * omp_get_nested:: Nested parallel regions
161 * omp_get_num_devices:: Number of target devices
162 * omp_get_num_procs:: Number of processors online
163 * omp_get_num_teams:: Number of teams
164 * omp_get_num_threads:: Size of the active team
165 * omp_get_proc_bind:: Whether theads may be moved between CPUs
166 * omp_get_schedule:: Obtain the runtime scheduling method
167 * omp_get_team_num:: Get team number
168 * omp_get_team_size:: Number of threads in a team
169 * omp_get_thread_limit:: Maximum number of threads
170 * omp_get_thread_num:: Current thread ID
171 * omp_in_parallel:: Whether a parallel region is active
172 * omp_in_final:: Whether in final or included task region
173 * omp_is_initial_device:: Whether executing on the host device
174 * omp_set_default_device:: Set the default device for target regions
175 * omp_set_dynamic:: Enable/disable dynamic teams
176 * omp_set_max_active_levels:: Limits the number of active parallel regions
177 * omp_set_nested:: Enable/disable nested parallel regions
178 * omp_set_num_threads:: Set upper team size limit
179 * omp_set_schedule:: Set the runtime scheduling method
180
181 Initialize, set, test, unset and destroy simple and nested locks.
182
183 * omp_init_lock:: Initialize simple lock
184 * omp_set_lock:: Wait for and set simple lock
185 * omp_test_lock:: Test and set simple lock if available
186 * omp_unset_lock:: Unset simple lock
187 * omp_destroy_lock:: Destroy simple lock
188 * omp_init_nest_lock:: Initialize nested lock
189 * omp_set_nest_lock:: Wait for and set simple lock
190 * omp_test_nest_lock:: Test and set nested lock if available
191 * omp_unset_nest_lock:: Unset nested lock
192 * omp_destroy_nest_lock:: Destroy nested lock
193
194 Portable, thread-based, wall clock timer.
195
196 * omp_get_wtick:: Get timer precision.
197 * omp_get_wtime:: Elapsed wall clock time.
198 @end menu
199
200
201
202 @node omp_get_active_level
203 @section @code{omp_get_active_level} -- Number of parallel regions
204 @table @asis
205 @item @emph{Description}:
206 This function returns the nesting level for the active parallel blocks,
207 which enclose the calling call.
208
209 @item @emph{C/C++}
210 @multitable @columnfractions .20 .80
211 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
212 @end multitable
213
214 @item @emph{Fortran}:
215 @multitable @columnfractions .20 .80
216 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
217 @end multitable
218
219 @item @emph{See also}:
220 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
221
222 @item @emph{Reference}:
223 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.20.
224 @end table
225
226
227
228 @node omp_get_ancestor_thread_num
229 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
230 @table @asis
231 @item @emph{Description}:
232 This function returns the thread identification number for the given
233 nesting level of the current thread. For values of @var{level} outside
234 zero to @code{omp_get_level} -1 is returned; if @var{level} is
235 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
236
237 @item @emph{C/C++}
238 @multitable @columnfractions .20 .80
239 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
240 @end multitable
241
242 @item @emph{Fortran}:
243 @multitable @columnfractions .20 .80
244 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
245 @item @tab @code{integer level}
246 @end multitable
247
248 @item @emph{See also}:
249 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
250
251 @item @emph{Reference}:
252 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.18.
253 @end table
254
255
256
257 @node omp_get_cancellation
258 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
259 @table @asis
260 @item @emph{Description}:
261 This function returns @code{true} if cancellation is activated, @code{false}
262 otherwise. Here, @code{true} and @code{false} represent their language-specific
263 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
264 deactivated.
265
266 @item @emph{C/C++}:
267 @multitable @columnfractions .20 .80
268 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
269 @end multitable
270
271 @item @emph{Fortran}:
272 @multitable @columnfractions .20 .80
273 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
274 @end multitable
275
276 @item @emph{See also}:
277 @ref{OMP_CANCELLATION}
278
279 @item @emph{Reference}:
280 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.9.
281 @end table
282
283
284
285 @node omp_get_default_device
286 @section @code{omp_get_default_device} -- Get the default device for target regions
287 @table @asis
288 @item @emph{Description}:
289 Get the default device for target regions without device clause.
290
291 @item @emph{C/C++}:
292 @multitable @columnfractions .20 .80
293 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
294 @end multitable
295
296 @item @emph{Fortran}:
297 @multitable @columnfractions .20 .80
298 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
299 @end multitable
300
301 @item @emph{See also}:
302 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
303
304 @item @emph{Reference}:
305 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.30.
306 @end table
307
308
309
310 @node omp_get_dynamic
311 @section @code{omp_get_dynamic} -- Dynamic teams setting
312 @table @asis
313 @item @emph{Description}:
314 This function returns @code{true} if enabled, @code{false} otherwise.
315 Here, @code{true} and @code{false} represent their language-specific
316 counterparts.
317
318 The dynamic team setting may be initialized at startup by the
319 @env{OMP_DYNAMIC} environment variable or at runtime using
320 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
321 disabled by default.
322
323 @item @emph{C/C++}:
324 @multitable @columnfractions .20 .80
325 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
326 @end multitable
327
328 @item @emph{Fortran}:
329 @multitable @columnfractions .20 .80
330 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
331 @end multitable
332
333 @item @emph{See also}:
334 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
335
336 @item @emph{Reference}:
337 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.8.
338 @end table
339
340
341
342 @node omp_get_level
343 @section @code{omp_get_level} -- Obtain the current nesting level
344 @table @asis
345 @item @emph{Description}:
346 This function returns the nesting level for the parallel blocks,
347 which enclose the calling call.
348
349 @item @emph{C/C++}
350 @multitable @columnfractions .20 .80
351 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
352 @end multitable
353
354 @item @emph{Fortran}:
355 @multitable @columnfractions .20 .80
356 @item @emph{Interface}: @tab @code{integer function omp_level()}
357 @end multitable
358
359 @item @emph{See also}:
360 @ref{omp_get_active_level}
361
362 @item @emph{Reference}:
363 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.17.
364 @end table
365
366
367
368 @node omp_get_max_active_levels
369 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
370 @table @asis
371 @item @emph{Description}:
372 This function obtains the maximum allowed number of nested, active parallel regions.
373
374 @item @emph{C/C++}
375 @multitable @columnfractions .20 .80
376 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
377 @end multitable
378
379 @item @emph{Fortran}:
380 @multitable @columnfractions .20 .80
381 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
382 @end multitable
383
384 @item @emph{See also}:
385 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
386
387 @item @emph{Reference}:
388 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.16.
389 @end table
390
391
392 @node omp_get_max_task_priority
393 @section @code{omp_get_max_task_priority} -- Maximum priority value
394 that can be set for tasks.
395 @table @asis
396 @item @emph{Description}:
397 This function obtains the maximum allowed priority number for tasks.
398
399 @item @emph{C/C++}
400 @multitable @columnfractions .20 .80
401 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
402 @end multitable
403
404 @item @emph{Fortran}:
405 @multitable @columnfractions .20 .80
406 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
407 @end multitable
408
409 @item @emph{Reference}:
410 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
411 @end table
412
413
414 @node omp_get_max_threads
415 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
416 @table @asis
417 @item @emph{Description}:
418 Return the maximum number of threads used for the current parallel region
419 that does not use the clause @code{num_threads}.
420
421 @item @emph{C/C++}:
422 @multitable @columnfractions .20 .80
423 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
424 @end multitable
425
426 @item @emph{Fortran}:
427 @multitable @columnfractions .20 .80
428 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
429 @end multitable
430
431 @item @emph{See also}:
432 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
433
434 @item @emph{Reference}:
435 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.3.
436 @end table
437
438
439
440 @node omp_get_nested
441 @section @code{omp_get_nested} -- Nested parallel regions
442 @table @asis
443 @item @emph{Description}:
444 This function returns @code{true} if nested parallel regions are
445 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
446 represent their language-specific counterparts.
447
448 Nested parallel regions may be initialized at startup by the
449 @env{OMP_NESTED} environment variable or at runtime using
450 @code{omp_set_nested}. If undefined, nested parallel regions are
451 disabled by default.
452
453 @item @emph{C/C++}:
454 @multitable @columnfractions .20 .80
455 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
456 @end multitable
457
458 @item @emph{Fortran}:
459 @multitable @columnfractions .20 .80
460 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
461 @end multitable
462
463 @item @emph{See also}:
464 @ref{omp_set_nested}, @ref{OMP_NESTED}
465
466 @item @emph{Reference}:
467 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.11.
468 @end table
469
470
471
472 @node omp_get_num_devices
473 @section @code{omp_get_num_devices} -- Number of target devices
474 @table @asis
475 @item @emph{Description}:
476 Returns the number of target devices.
477
478 @item @emph{C/C++}:
479 @multitable @columnfractions .20 .80
480 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
481 @end multitable
482
483 @item @emph{Fortran}:
484 @multitable @columnfractions .20 .80
485 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
486 @end multitable
487
488 @item @emph{Reference}:
489 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.31.
490 @end table
491
492
493
494 @node omp_get_num_procs
495 @section @code{omp_get_num_procs} -- Number of processors online
496 @table @asis
497 @item @emph{Description}:
498 Returns the number of processors online on that device.
499
500 @item @emph{C/C++}:
501 @multitable @columnfractions .20 .80
502 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
503 @end multitable
504
505 @item @emph{Fortran}:
506 @multitable @columnfractions .20 .80
507 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
508 @end multitable
509
510 @item @emph{Reference}:
511 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.5.
512 @end table
513
514
515
516 @node omp_get_num_teams
517 @section @code{omp_get_num_teams} -- Number of teams
518 @table @asis
519 @item @emph{Description}:
520 Returns the number of teams in the current team region.
521
522 @item @emph{C/C++}:
523 @multitable @columnfractions .20 .80
524 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
525 @end multitable
526
527 @item @emph{Fortran}:
528 @multitable @columnfractions .20 .80
529 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
530 @end multitable
531
532 @item @emph{Reference}:
533 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.32.
534 @end table
535
536
537
538 @node omp_get_num_threads
539 @section @code{omp_get_num_threads} -- Size of the active team
540 @table @asis
541 @item @emph{Description}:
542 Returns the number of threads in the current team. In a sequential section of
543 the program @code{omp_get_num_threads} returns 1.
544
545 The default team size may be initialized at startup by the
546 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
547 of the current team may be set either by the @code{NUM_THREADS}
548 clause or by @code{omp_set_num_threads}. If none of the above were
549 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
550 one thread per CPU online is used.
551
552 @item @emph{C/C++}:
553 @multitable @columnfractions .20 .80
554 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
555 @end multitable
556
557 @item @emph{Fortran}:
558 @multitable @columnfractions .20 .80
559 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
560 @end multitable
561
562 @item @emph{See also}:
563 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
564
565 @item @emph{Reference}:
566 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.2.
567 @end table
568
569
570
571 @node omp_get_proc_bind
572 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
573 @table @asis
574 @item @emph{Description}:
575 This functions returns the currently active thread affinity policy, which is
576 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
577 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
578 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
579
580 @item @emph{C/C++}:
581 @multitable @columnfractions .20 .80
582 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
583 @end multitable
584
585 @item @emph{Fortran}:
586 @multitable @columnfractions .20 .80
587 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
588 @end multitable
589
590 @item @emph{See also}:
591 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
592
593 @item @emph{Reference}:
594 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.22.
595 @end table
596
597
598
599 @node omp_get_schedule
600 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
601 @table @asis
602 @item @emph{Description}:
603 Obtain the runtime scheduling method. The @var{kind} argument will be
604 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
605 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
606 @var{chunk_size}, is set to the chunk size.
607
608 @item @emph{C/C++}
609 @multitable @columnfractions .20 .80
610 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
611 @end multitable
612
613 @item @emph{Fortran}:
614 @multitable @columnfractions .20 .80
615 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
616 @item @tab @code{integer(kind=omp_sched_kind) kind}
617 @item @tab @code{integer chunk_size}
618 @end multitable
619
620 @item @emph{See also}:
621 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
622
623 @item @emph{Reference}:
624 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.13.
625 @end table
626
627
628
629 @node omp_get_team_num
630 @section @code{omp_get_team_num} -- Get team number
631 @table @asis
632 @item @emph{Description}:
633 Returns the team number of the calling thread.
634
635 @item @emph{C/C++}:
636 @multitable @columnfractions .20 .80
637 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
638 @end multitable
639
640 @item @emph{Fortran}:
641 @multitable @columnfractions .20 .80
642 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
643 @end multitable
644
645 @item @emph{Reference}:
646 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.33.
647 @end table
648
649
650
651 @node omp_get_team_size
652 @section @code{omp_get_team_size} -- Number of threads in a team
653 @table @asis
654 @item @emph{Description}:
655 This function returns the number of threads in a thread team to which
656 either the current thread or its ancestor belongs. For values of @var{level}
657 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
658 1 is returned, and for @code{omp_get_level}, the result is identical
659 to @code{omp_get_num_threads}.
660
661 @item @emph{C/C++}:
662 @multitable @columnfractions .20 .80
663 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
664 @end multitable
665
666 @item @emph{Fortran}:
667 @multitable @columnfractions .20 .80
668 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
669 @item @tab @code{integer level}
670 @end multitable
671
672 @item @emph{See also}:
673 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
674
675 @item @emph{Reference}:
676 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.19.
677 @end table
678
679
680
681 @node omp_get_thread_limit
682 @section @code{omp_get_thread_limit} -- Maximum number of threads
683 @table @asis
684 @item @emph{Description}:
685 Return the maximum number of threads of the program.
686
687 @item @emph{C/C++}:
688 @multitable @columnfractions .20 .80
689 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
690 @end multitable
691
692 @item @emph{Fortran}:
693 @multitable @columnfractions .20 .80
694 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
695 @end multitable
696
697 @item @emph{See also}:
698 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
699
700 @item @emph{Reference}:
701 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.14.
702 @end table
703
704
705
706 @node omp_get_thread_num
707 @section @code{omp_get_thread_num} -- Current thread ID
708 @table @asis
709 @item @emph{Description}:
710 Returns a unique thread identification number within the current team.
711 In a sequential parts of the program, @code{omp_get_thread_num}
712 always returns 0. In parallel regions the return value varies
713 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
714 value of the master thread of a team is always 0.
715
716 @item @emph{C/C++}:
717 @multitable @columnfractions .20 .80
718 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
719 @end multitable
720
721 @item @emph{Fortran}:
722 @multitable @columnfractions .20 .80
723 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
724 @end multitable
725
726 @item @emph{See also}:
727 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
728
729 @item @emph{Reference}:
730 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.4.
731 @end table
732
733
734
735 @node omp_in_parallel
736 @section @code{omp_in_parallel} -- Whether a parallel region is active
737 @table @asis
738 @item @emph{Description}:
739 This function returns @code{true} if currently running in parallel,
740 @code{false} otherwise. Here, @code{true} and @code{false} represent
741 their language-specific counterparts.
742
743 @item @emph{C/C++}:
744 @multitable @columnfractions .20 .80
745 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
746 @end multitable
747
748 @item @emph{Fortran}:
749 @multitable @columnfractions .20 .80
750 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
751 @end multitable
752
753 @item @emph{Reference}:
754 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.6.
755 @end table
756
757
758 @node omp_in_final
759 @section @code{omp_in_final} -- Whether in final or included task region
760 @table @asis
761 @item @emph{Description}:
762 This function returns @code{true} if currently running in a final
763 or included task region, @code{false} otherwise. Here, @code{true}
764 and @code{false} represent their language-specific counterparts.
765
766 @item @emph{C/C++}:
767 @multitable @columnfractions .20 .80
768 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
769 @end multitable
770
771 @item @emph{Fortran}:
772 @multitable @columnfractions .20 .80
773 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
774 @end multitable
775
776 @item @emph{Reference}:
777 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.21.
778 @end table
779
780
781
782 @node omp_is_initial_device
783 @section @code{omp_is_initial_device} -- Whether executing on the host device
784 @table @asis
785 @item @emph{Description}:
786 This function returns @code{true} if currently running on the host device,
787 @code{false} otherwise. Here, @code{true} and @code{false} represent
788 their language-specific counterparts.
789
790 @item @emph{C/C++}:
791 @multitable @columnfractions .20 .80
792 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
793 @end multitable
794
795 @item @emph{Fortran}:
796 @multitable @columnfractions .20 .80
797 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
798 @end multitable
799
800 @item @emph{Reference}:
801 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.34.
802 @end table
803
804
805
806 @node omp_set_default_device
807 @section @code{omp_set_default_device} -- Set the default device for target regions
808 @table @asis
809 @item @emph{Description}:
810 Set the default device for target regions without device clause. The argument
811 shall be a nonnegative device number.
812
813 @item @emph{C/C++}:
814 @multitable @columnfractions .20 .80
815 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
816 @end multitable
817
818 @item @emph{Fortran}:
819 @multitable @columnfractions .20 .80
820 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
821 @item @tab @code{integer device_num}
822 @end multitable
823
824 @item @emph{See also}:
825 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
826
827 @item @emph{Reference}:
828 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
829 @end table
830
831
832
833 @node omp_set_dynamic
834 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
835 @table @asis
836 @item @emph{Description}:
837 Enable or disable the dynamic adjustment of the number of threads
838 within a team. The function takes the language-specific equivalent
839 of @code{true} and @code{false}, where @code{true} enables dynamic
840 adjustment of team sizes and @code{false} disables it.
841
842 @item @emph{C/C++}:
843 @multitable @columnfractions .20 .80
844 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
845 @end multitable
846
847 @item @emph{Fortran}:
848 @multitable @columnfractions .20 .80
849 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
850 @item @tab @code{logical, intent(in) :: dynamic_threads}
851 @end multitable
852
853 @item @emph{See also}:
854 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
855
856 @item @emph{Reference}:
857 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.7.
858 @end table
859
860
861
862 @node omp_set_max_active_levels
863 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
864 @table @asis
865 @item @emph{Description}:
866 This function limits the maximum allowed number of nested, active
867 parallel regions.
868
869 @item @emph{C/C++}
870 @multitable @columnfractions .20 .80
871 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
872 @end multitable
873
874 @item @emph{Fortran}:
875 @multitable @columnfractions .20 .80
876 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
877 @item @tab @code{integer max_levels}
878 @end multitable
879
880 @item @emph{See also}:
881 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
882
883 @item @emph{Reference}:
884 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.15.
885 @end table
886
887
888
889 @node omp_set_nested
890 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
891 @table @asis
892 @item @emph{Description}:
893 Enable or disable nested parallel regions, i.e., whether team members
894 are allowed to create new teams. The function takes the language-specific
895 equivalent of @code{true} and @code{false}, where @code{true} enables
896 dynamic adjustment of team sizes and @code{false} disables it.
897
898 @item @emph{C/C++}:
899 @multitable @columnfractions .20 .80
900 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
901 @end multitable
902
903 @item @emph{Fortran}:
904 @multitable @columnfractions .20 .80
905 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
906 @item @tab @code{logical, intent(in) :: nested}
907 @end multitable
908
909 @item @emph{See also}:
910 @ref{OMP_NESTED}, @ref{omp_get_nested}
911
912 @item @emph{Reference}:
913 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.10.
914 @end table
915
916
917
918 @node omp_set_num_threads
919 @section @code{omp_set_num_threads} -- Set upper team size limit
920 @table @asis
921 @item @emph{Description}:
922 Specifies the number of threads used by default in subsequent parallel
923 sections, if those do not specify a @code{num_threads} clause. The
924 argument of @code{omp_set_num_threads} shall be a positive integer.
925
926 @item @emph{C/C++}:
927 @multitable @columnfractions .20 .80
928 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
929 @end multitable
930
931 @item @emph{Fortran}:
932 @multitable @columnfractions .20 .80
933 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
934 @item @tab @code{integer, intent(in) :: num_threads}
935 @end multitable
936
937 @item @emph{See also}:
938 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
939
940 @item @emph{Reference}:
941 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.1.
942 @end table
943
944
945
946 @node omp_set_schedule
947 @section @code{omp_set_schedule} -- Set the runtime scheduling method
948 @table @asis
949 @item @emph{Description}:
950 Sets the runtime scheduling method. The @var{kind} argument can have the
951 value @code{omp_sched_static}, @code{omp_sched_dynamic},
952 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
953 @code{omp_sched_auto}, the chunk size is set to the value of
954 @var{chunk_size} if positive, or to the default value if zero or negative.
955 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
956
957 @item @emph{C/C++}
958 @multitable @columnfractions .20 .80
959 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
960 @end multitable
961
962 @item @emph{Fortran}:
963 @multitable @columnfractions .20 .80
964 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
965 @item @tab @code{integer(kind=omp_sched_kind) kind}
966 @item @tab @code{integer chunk_size}
967 @end multitable
968
969 @item @emph{See also}:
970 @ref{omp_get_schedule}
971 @ref{OMP_SCHEDULE}
972
973 @item @emph{Reference}:
974 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.12.
975 @end table
976
977
978
979 @node omp_init_lock
980 @section @code{omp_init_lock} -- Initialize simple lock
981 @table @asis
982 @item @emph{Description}:
983 Initialize a simple lock. After initialization, the lock is in
984 an unlocked state.
985
986 @item @emph{C/C++}:
987 @multitable @columnfractions .20 .80
988 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
989 @end multitable
990
991 @item @emph{Fortran}:
992 @multitable @columnfractions .20 .80
993 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
994 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
995 @end multitable
996
997 @item @emph{See also}:
998 @ref{omp_destroy_lock}
999
1000 @item @emph{Reference}:
1001 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1002 @end table
1003
1004
1005
1006 @node omp_set_lock
1007 @section @code{omp_set_lock} -- Wait for and set simple lock
1008 @table @asis
1009 @item @emph{Description}:
1010 Before setting a simple lock, the lock variable must be initialized by
1011 @code{omp_init_lock}. The calling thread is blocked until the lock
1012 is available. If the lock is already held by the current thread,
1013 a deadlock occurs.
1014
1015 @item @emph{C/C++}:
1016 @multitable @columnfractions .20 .80
1017 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1018 @end multitable
1019
1020 @item @emph{Fortran}:
1021 @multitable @columnfractions .20 .80
1022 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1023 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1024 @end multitable
1025
1026 @item @emph{See also}:
1027 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1028
1029 @item @emph{Reference}:
1030 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1031 @end table
1032
1033
1034
1035 @node omp_test_lock
1036 @section @code{omp_test_lock} -- Test and set simple lock if available
1037 @table @asis
1038 @item @emph{Description}:
1039 Before setting a simple lock, the lock variable must be initialized by
1040 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1041 does not block if the lock is not available. This function returns
1042 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1043 @code{false} represent their language-specific counterparts.
1044
1045 @item @emph{C/C++}:
1046 @multitable @columnfractions .20 .80
1047 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1048 @end multitable
1049
1050 @item @emph{Fortran}:
1051 @multitable @columnfractions .20 .80
1052 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1053 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1054 @end multitable
1055
1056 @item @emph{See also}:
1057 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1058
1059 @item @emph{Reference}:
1060 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1061 @end table
1062
1063
1064
1065 @node omp_unset_lock
1066 @section @code{omp_unset_lock} -- Unset simple lock
1067 @table @asis
1068 @item @emph{Description}:
1069 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1070 or @code{omp_test_lock} before. In addition, the lock must be held by the
1071 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1072 or more threads attempted to set the lock before, one of them is chosen to,
1073 again, set the lock to itself.
1074
1075 @item @emph{C/C++}:
1076 @multitable @columnfractions .20 .80
1077 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1078 @end multitable
1079
1080 @item @emph{Fortran}:
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1083 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1084 @end multitable
1085
1086 @item @emph{See also}:
1087 @ref{omp_set_lock}, @ref{omp_test_lock}
1088
1089 @item @emph{Reference}:
1090 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1091 @end table
1092
1093
1094
1095 @node omp_destroy_lock
1096 @section @code{omp_destroy_lock} -- Destroy simple lock
1097 @table @asis
1098 @item @emph{Description}:
1099 Destroy a simple lock. In order to be destroyed, a simple lock must be
1100 in the unlocked state.
1101
1102 @item @emph{C/C++}:
1103 @multitable @columnfractions .20 .80
1104 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1105 @end multitable
1106
1107 @item @emph{Fortran}:
1108 @multitable @columnfractions .20 .80
1109 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1110 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1111 @end multitable
1112
1113 @item @emph{See also}:
1114 @ref{omp_init_lock}
1115
1116 @item @emph{Reference}:
1117 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1118 @end table
1119
1120
1121
1122 @node omp_init_nest_lock
1123 @section @code{omp_init_nest_lock} -- Initialize nested lock
1124 @table @asis
1125 @item @emph{Description}:
1126 Initialize a nested lock. After initialization, the lock is in
1127 an unlocked state and the nesting count is set to zero.
1128
1129 @item @emph{C/C++}:
1130 @multitable @columnfractions .20 .80
1131 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1132 @end multitable
1133
1134 @item @emph{Fortran}:
1135 @multitable @columnfractions .20 .80
1136 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1137 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1138 @end multitable
1139
1140 @item @emph{See also}:
1141 @ref{omp_destroy_nest_lock}
1142
1143 @item @emph{Reference}:
1144 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1145 @end table
1146
1147
1148 @node omp_set_nest_lock
1149 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1150 @table @asis
1151 @item @emph{Description}:
1152 Before setting a nested lock, the lock variable must be initialized by
1153 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1154 is available. If the lock is already held by the current thread, the
1155 nesting count for the lock is incremented.
1156
1157 @item @emph{C/C++}:
1158 @multitable @columnfractions .20 .80
1159 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1160 @end multitable
1161
1162 @item @emph{Fortran}:
1163 @multitable @columnfractions .20 .80
1164 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1165 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1166 @end multitable
1167
1168 @item @emph{See also}:
1169 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1170
1171 @item @emph{Reference}:
1172 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1173 @end table
1174
1175
1176
1177 @node omp_test_nest_lock
1178 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1179 @table @asis
1180 @item @emph{Description}:
1181 Before setting a nested lock, the lock variable must be initialized by
1182 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1183 @code{omp_test_nest_lock} does not block if the lock is not available.
1184 If the lock is already held by the current thread, the new nesting count
1185 is returned. Otherwise, the return value equals zero.
1186
1187 @item @emph{C/C++}:
1188 @multitable @columnfractions .20 .80
1189 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1190 @end multitable
1191
1192 @item @emph{Fortran}:
1193 @multitable @columnfractions .20 .80
1194 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1195 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1196 @end multitable
1197
1198
1199 @item @emph{See also}:
1200 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1201
1202 @item @emph{Reference}:
1203 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1204 @end table
1205
1206
1207
1208 @node omp_unset_nest_lock
1209 @section @code{omp_unset_nest_lock} -- Unset nested lock
1210 @table @asis
1211 @item @emph{Description}:
1212 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1213 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1214 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1215 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1216 one of them is chosen to, again, set the lock to itself.
1217
1218 @item @emph{C/C++}:
1219 @multitable @columnfractions .20 .80
1220 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1221 @end multitable
1222
1223 @item @emph{Fortran}:
1224 @multitable @columnfractions .20 .80
1225 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1226 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1227 @end multitable
1228
1229 @item @emph{See also}:
1230 @ref{omp_set_nest_lock}
1231
1232 @item @emph{Reference}:
1233 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1234 @end table
1235
1236
1237
1238 @node omp_destroy_nest_lock
1239 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1240 @table @asis
1241 @item @emph{Description}:
1242 Destroy a nested lock. In order to be destroyed, a nested lock must be
1243 in the unlocked state and its nesting count must equal zero.
1244
1245 @item @emph{C/C++}:
1246 @multitable @columnfractions .20 .80
1247 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1248 @end multitable
1249
1250 @item @emph{Fortran}:
1251 @multitable @columnfractions .20 .80
1252 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1253 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1254 @end multitable
1255
1256 @item @emph{See also}:
1257 @ref{omp_init_lock}
1258
1259 @item @emph{Reference}:
1260 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1261 @end table
1262
1263
1264
1265 @node omp_get_wtick
1266 @section @code{omp_get_wtick} -- Get timer precision
1267 @table @asis
1268 @item @emph{Description}:
1269 Gets the timer precision, i.e., the number of seconds between two
1270 successive clock ticks.
1271
1272 @item @emph{C/C++}:
1273 @multitable @columnfractions .20 .80
1274 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1275 @end multitable
1276
1277 @item @emph{Fortran}:
1278 @multitable @columnfractions .20 .80
1279 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1280 @end multitable
1281
1282 @item @emph{See also}:
1283 @ref{omp_get_wtime}
1284
1285 @item @emph{Reference}:
1286 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.2.
1287 @end table
1288
1289
1290
1291 @node omp_get_wtime
1292 @section @code{omp_get_wtime} -- Elapsed wall clock time
1293 @table @asis
1294 @item @emph{Description}:
1295 Elapsed wall clock time in seconds. The time is measured per thread, no
1296 guarantee can be made that two distinct threads measure the same time.
1297 Time is measured from some "time in the past", which is an arbitrary time
1298 guaranteed not to change during the execution of the program.
1299
1300 @item @emph{C/C++}:
1301 @multitable @columnfractions .20 .80
1302 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1303 @end multitable
1304
1305 @item @emph{Fortran}:
1306 @multitable @columnfractions .20 .80
1307 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1308 @end multitable
1309
1310 @item @emph{See also}:
1311 @ref{omp_get_wtick}
1312
1313 @item @emph{Reference}:
1314 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.1.
1315 @end table
1316
1317
1318
1319 @c ---------------------------------------------------------------------
1320 @c Environment Variables
1321 @c ---------------------------------------------------------------------
1322
1323 @node Environment Variables
1324 @chapter Environment Variables
1325
1326 The environment variables which beginning with @env{OMP_} are defined by
1327 section 4 of the OpenMP specification in version 4.5, while those
1328 beginning with @env{GOMP_} are GNU extensions.
1329
1330 @menu
1331 * OMP_CANCELLATION:: Set whether cancellation is activated
1332 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1333 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1334 * OMP_DYNAMIC:: Dynamic adjustment of threads
1335 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1336 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
1337 * OMP_NESTED:: Nested parallel regions
1338 * OMP_NUM_THREADS:: Specifies the number of threads to use
1339 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1340 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1341 * OMP_STACKSIZE:: Set default thread stack size
1342 * OMP_SCHEDULE:: How threads are scheduled
1343 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1344 * OMP_WAIT_POLICY:: How waiting threads are handled
1345 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1346 * GOMP_DEBUG:: Enable debugging output
1347 * GOMP_STACKSIZE:: Set default thread stack size
1348 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1349 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1350 @end menu
1351
1352
1353 @node OMP_CANCELLATION
1354 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1355 @cindex Environment Variable
1356 @table @asis
1357 @item @emph{Description}:
1358 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1359 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1360
1361 @item @emph{See also}:
1362 @ref{omp_get_cancellation}
1363
1364 @item @emph{Reference}:
1365 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.11
1366 @end table
1367
1368
1369
1370 @node OMP_DISPLAY_ENV
1371 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1372 @cindex Environment Variable
1373 @table @asis
1374 @item @emph{Description}:
1375 If set to @code{TRUE}, the OpenMP version number and the values
1376 associated with the OpenMP environment variables are printed to @code{stderr}.
1377 If set to @code{VERBOSE}, it additionally shows the value of the environment
1378 variables which are GNU extensions. If undefined or set to @code{FALSE},
1379 this information will not be shown.
1380
1381
1382 @item @emph{Reference}:
1383 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.12
1384 @end table
1385
1386
1387
1388 @node OMP_DEFAULT_DEVICE
1389 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1390 @cindex Environment Variable
1391 @table @asis
1392 @item @emph{Description}:
1393 Set to choose the device which is used in a @code{target} region, unless the
1394 value is overridden by @code{omp_set_default_device} or by a @code{device}
1395 clause. The value shall be the nonnegative device number. If no device with
1396 the given device number exists, the code is executed on the host. If unset,
1397 device number 0 will be used.
1398
1399
1400 @item @emph{See also}:
1401 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1402
1403 @item @emph{Reference}:
1404 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.13
1405 @end table
1406
1407
1408
1409 @node OMP_DYNAMIC
1410 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1411 @cindex Environment Variable
1412 @table @asis
1413 @item @emph{Description}:
1414 Enable or disable the dynamic adjustment of the number of threads
1415 within a team. The value of this environment variable shall be
1416 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1417 disabled by default.
1418
1419 @item @emph{See also}:
1420 @ref{omp_set_dynamic}
1421
1422 @item @emph{Reference}:
1423 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.3
1424 @end table
1425
1426
1427
1428 @node OMP_MAX_ACTIVE_LEVELS
1429 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1430 @cindex Environment Variable
1431 @table @asis
1432 @item @emph{Description}:
1433 Specifies the initial value for the maximum number of nested parallel
1434 regions. The value of this variable shall be a positive integer.
1435 If undefined, the number of active levels is unlimited.
1436
1437 @item @emph{See also}:
1438 @ref{omp_set_max_active_levels}
1439
1440 @item @emph{Reference}:
1441 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.9
1442 @end table
1443
1444
1445
1446 @node OMP_MAX_TASK_PRIORITY
1447 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1448 number that can be set for a task.
1449 @cindex Environment Variable
1450 @table @asis
1451 @item @emph{Description}:
1452 Specifies the initial value for the maximum priority value that can be
1453 set for a task. The value of this variable shall be a non-negative
1454 integer, and zero is allowed. If undefined, the default priority is
1455 0.
1456
1457 @item @emph{See also}:
1458 @ref{omp_get_max_task_priority}
1459
1460 @item @emph{Reference}:
1461 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.14
1462 @end table
1463
1464
1465
1466 @node OMP_NESTED
1467 @section @env{OMP_NESTED} -- Nested parallel regions
1468 @cindex Environment Variable
1469 @cindex Implementation specific setting
1470 @table @asis
1471 @item @emph{Description}:
1472 Enable or disable nested parallel regions, i.e., whether team members
1473 are allowed to create new teams. The value of this environment variable
1474 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
1475 regions are disabled by default.
1476
1477 @item @emph{See also}:
1478 @ref{omp_set_nested}
1479
1480 @item @emph{Reference}:
1481 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.6
1482 @end table
1483
1484
1485
1486 @node OMP_NUM_THREADS
1487 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1488 @cindex Environment Variable
1489 @cindex Implementation specific setting
1490 @table @asis
1491 @item @emph{Description}:
1492 Specifies the default number of threads to use in parallel regions. The
1493 value of this variable shall be a comma-separated list of positive integers;
1494 the value specified the number of threads to use for the corresponding nested
1495 level. If undefined one thread per CPU is used.
1496
1497 @item @emph{See also}:
1498 @ref{omp_set_num_threads}
1499
1500 @item @emph{Reference}:
1501 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.2
1502 @end table
1503
1504
1505
1506 @node OMP_PROC_BIND
1507 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1508 @cindex Environment Variable
1509 @table @asis
1510 @item @emph{Description}:
1511 Specifies whether threads may be moved between processors. If set to
1512 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1513 they may be moved. Alternatively, a comma separated list with the
1514 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1515 the thread affinity policy for the corresponding nesting level. With
1516 @code{MASTER} the worker threads are in the same place partition as the
1517 master thread. With @code{CLOSE} those are kept close to the master thread
1518 in contiguous place partitions. And with @code{SPREAD} a sparse distribution
1519 across the place partitions is used.
1520
1521 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1522 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1523
1524 @item @emph{See also}:
1525 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1526
1527 @item @emph{Reference}:
1528 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.4
1529 @end table
1530
1531
1532
1533 @node OMP_PLACES
1534 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1535 @cindex Environment Variable
1536 @table @asis
1537 @item @emph{Description}:
1538 The thread placement can be either specified using an abstract name or by an
1539 explicit list of the places. The abstract names @code{threads}, @code{cores}
1540 and @code{sockets} can be optionally followed by a positive number in
1541 parentheses, which denotes the how many places shall be created. With
1542 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1543 to a single core with the corresponding number of hardware threads; and with
1544 @code{sockets} the place corresponds to a single socket. The resulting
1545 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1546 variable.
1547
1548 Alternatively, the placement can be specified explicitly as comma-separated
1549 list of places. A place is specified by set of nonnegative numbers in curly
1550 braces, denoting the denoting the hardware threads. The hardware threads
1551 belonging to a place can either be specified as comma-separated list of
1552 nonnegative thread numbers or using an interval. Multiple places can also be
1553 either specified by a comma-separated list of places or by an interval. To
1554 specify an interval, a colon followed by the count is placed after after
1555 the hardware thread number or the place. Optionally, the length can be
1556 followed by a colon and the stride number -- otherwise a unit stride is
1557 assumed. For instance, the following specifies the same places list:
1558 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1559 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1560
1561 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1562 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1563 between CPUs following no placement policy.
1564
1565 @item @emph{See also}:
1566 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1567 @ref{OMP_DISPLAY_ENV}
1568
1569 @item @emph{Reference}:
1570 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.5
1571 @end table
1572
1573
1574
1575 @node OMP_STACKSIZE
1576 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1577 @cindex Environment Variable
1578 @table @asis
1579 @item @emph{Description}:
1580 Set the default thread stack size in kilobytes, unless the number
1581 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1582 case the size is, respectively, in bytes, kilobytes, megabytes
1583 or gigabytes. This is different from @code{pthread_attr_setstacksize}
1584 which gets the number of bytes as an argument. If the stack size cannot
1585 be set due to system constraints, an error is reported and the initial
1586 stack size is left unchanged. If undefined, the stack size is system
1587 dependent.
1588
1589 @item @emph{Reference}:
1590 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.7
1591 @end table
1592
1593
1594
1595 @node OMP_SCHEDULE
1596 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1597 @cindex Environment Variable
1598 @cindex Implementation specific setting
1599 @table @asis
1600 @item @emph{Description}:
1601 Allows to specify @code{schedule type} and @code{chunk size}.
1602 The value of the variable shall have the form: @code{type[,chunk]} where
1603 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1604 The optional @code{chunk} size shall be a positive integer. If undefined,
1605 dynamic scheduling and a chunk size of 1 is used.
1606
1607 @item @emph{See also}:
1608 @ref{omp_set_schedule}
1609
1610 @item @emph{Reference}:
1611 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
1612 @end table
1613
1614
1615
1616 @node OMP_THREAD_LIMIT
1617 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1618 @cindex Environment Variable
1619 @table @asis
1620 @item @emph{Description}:
1621 Specifies the number of threads to use for the whole program. The
1622 value of this variable shall be a positive integer. If undefined,
1623 the number of threads is not limited.
1624
1625 @item @emph{See also}:
1626 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1627
1628 @item @emph{Reference}:
1629 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.10
1630 @end table
1631
1632
1633
1634 @node OMP_WAIT_POLICY
1635 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1636 @cindex Environment Variable
1637 @table @asis
1638 @item @emph{Description}:
1639 Specifies whether waiting threads should be active or passive. If
1640 the value is @code{PASSIVE}, waiting threads should not consume CPU
1641 power while waiting; while the value is @code{ACTIVE} specifies that
1642 they should. If undefined, threads wait actively for a short time
1643 before waiting passively.
1644
1645 @item @emph{See also}:
1646 @ref{GOMP_SPINCOUNT}
1647
1648 @item @emph{Reference}:
1649 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.8
1650 @end table
1651
1652
1653
1654 @node GOMP_CPU_AFFINITY
1655 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1656 @cindex Environment Variable
1657 @table @asis
1658 @item @emph{Description}:
1659 Binds threads to specific CPUs. The variable should contain a space-separated
1660 or comma-separated list of CPUs. This list may contain different kinds of
1661 entries: either single CPU numbers in any order, a range of CPUs (M-N)
1662 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
1663 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1664 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1665 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1666 and 14 respectively and then start assigning back from the beginning of
1667 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1668
1669 There is no libgomp library routine to determine whether a CPU affinity
1670 specification is in effect. As a workaround, language-specific library
1671 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1672 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1673 environment variable. A defined CPU affinity on startup cannot be changed
1674 or disabled during the runtime of the application.
1675
1676 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1677 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
1678 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1679 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1680
1681 @item @emph{See also}:
1682 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1683 @end table
1684
1685
1686
1687 @node GOMP_DEBUG
1688 @section @env{GOMP_DEBUG} -- Enable debugging output
1689 @cindex Environment Variable
1690 @table @asis
1691 @item @emph{Description}:
1692 Enable debugging output. The variable should be set to @code{0}
1693 (disabled, also the default if not set), or @code{1} (enabled).
1694
1695 If enabled, some debugging output will be printed during execution.
1696 This is currently not specified in more detail, and subject to change.
1697 @end table
1698
1699
1700
1701 @node GOMP_STACKSIZE
1702 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1703 @cindex Environment Variable
1704 @cindex Implementation specific setting
1705 @table @asis
1706 @item @emph{Description}:
1707 Set the default thread stack size in kilobytes. This is different from
1708 @code{pthread_attr_setstacksize} which gets the number of bytes as an
1709 argument. If the stack size cannot be set due to system constraints, an
1710 error is reported and the initial stack size is left unchanged. If undefined,
1711 the stack size is system dependent.
1712
1713 @item @emph{See also}:
1714 @ref{OMP_STACKSIZE}
1715
1716 @item @emph{Reference}:
1717 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1718 GCC Patches Mailinglist},
1719 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1720 GCC Patches Mailinglist}
1721 @end table
1722
1723
1724
1725 @node GOMP_SPINCOUNT
1726 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1727 @cindex Environment Variable
1728 @cindex Implementation specific setting
1729 @table @asis
1730 @item @emph{Description}:
1731 Determines how long a threads waits actively with consuming CPU power
1732 before waiting passively without consuming CPU power. The value may be
1733 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1734 integer which gives the number of spins of the busy-wait loop. The
1735 integer may optionally be followed by the following suffixes acting
1736 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1737 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1738 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1739 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1740 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1741 If there are more OpenMP threads than available CPUs, 1000 and 100
1742 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1743 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1744 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1745
1746 @item @emph{See also}:
1747 @ref{OMP_WAIT_POLICY}
1748 @end table
1749
1750
1751
1752 @node GOMP_RTEMS_THREAD_POOLS
1753 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
1754 @cindex Environment Variable
1755 @cindex Implementation specific setting
1756 @table @asis
1757 @item @emph{Description}:
1758 This environment variable is only used on the RTEMS real-time operating system.
1759 It determines the scheduler instance specific thread pools. The format for
1760 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
1761 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
1762 separated by @code{:} where:
1763 @itemize @bullet
1764 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
1765 instance.
1766 @item @code{$<priority>} is an optional priority for the worker threads of a
1767 thread pool according to @code{pthread_setschedparam}. In case a priority
1768 value is omitted, then a worker thread will inherit the priority of the OpenMP
1769 master thread that created it. The priority of the worker thread is not
1770 changed after creation, even if a new OpenMP master thread using the worker has
1771 a different priority.
1772 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
1773 RTEMS application configuration.
1774 @end itemize
1775 In case no thread pool configuration is specified for a scheduler instance,
1776 then each OpenMP master thread of this scheduler instance will use its own
1777 dynamically allocated thread pool. To limit the worker thread count of the
1778 thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1779 @item @emph{Example}:
1780 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
1781 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
1782 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
1783 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
1784 one thread pool available. Since no priority is specified for this scheduler
1785 instance, the worker thread inherits the priority of the OpenMP master thread
1786 that created it. In the scheduler instance @code{WRK1} there are three thread
1787 pools available and their worker threads run at priority four.
1788 @end table
1789
1790
1791
1792 @c ---------------------------------------------------------------------
1793 @c The libgomp ABI
1794 @c ---------------------------------------------------------------------
1795
1796 @node The libgomp ABI
1797 @chapter The libgomp ABI
1798
1799 The following sections present notes on the external ABI as
1800 presented by libgomp. Only maintainers should need them.
1801
1802 @menu
1803 * Implementing MASTER construct::
1804 * Implementing CRITICAL construct::
1805 * Implementing ATOMIC construct::
1806 * Implementing FLUSH construct::
1807 * Implementing BARRIER construct::
1808 * Implementing THREADPRIVATE construct::
1809 * Implementing PRIVATE clause::
1810 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
1811 * Implementing REDUCTION clause::
1812 * Implementing PARALLEL construct::
1813 * Implementing FOR construct::
1814 * Implementing ORDERED construct::
1815 * Implementing SECTIONS construct::
1816 * Implementing SINGLE construct::
1817 @end menu
1818
1819
1820 @node Implementing MASTER construct
1821 @section Implementing MASTER construct
1822
1823 @smallexample
1824 if (omp_get_thread_num () == 0)
1825 block
1826 @end smallexample
1827
1828 Alternately, we generate two copies of the parallel subfunction
1829 and only include this in the version run by the master thread.
1830 Surely this is not worthwhile though...
1831
1832
1833
1834 @node Implementing CRITICAL construct
1835 @section Implementing CRITICAL construct
1836
1837 Without a specified name,
1838
1839 @smallexample
1840 void GOMP_critical_start (void);
1841 void GOMP_critical_end (void);
1842 @end smallexample
1843
1844 so that we don't get COPY relocations from libgomp to the main
1845 application.
1846
1847 With a specified name, use omp_set_lock and omp_unset_lock with
1848 name being transformed into a variable declared like
1849
1850 @smallexample
1851 omp_lock_t gomp_critical_user_<name> __attribute__((common))
1852 @end smallexample
1853
1854 Ideally the ABI would specify that all zero is a valid unlocked
1855 state, and so we wouldn't need to initialize this at
1856 startup.
1857
1858
1859
1860 @node Implementing ATOMIC construct
1861 @section Implementing ATOMIC construct
1862
1863 The target should implement the @code{__sync} builtins.
1864
1865 Failing that we could add
1866
1867 @smallexample
1868 void GOMP_atomic_enter (void)
1869 void GOMP_atomic_exit (void)
1870 @end smallexample
1871
1872 which reuses the regular lock code, but with yet another lock
1873 object private to the library.
1874
1875
1876
1877 @node Implementing FLUSH construct
1878 @section Implementing FLUSH construct
1879
1880 Expands to the @code{__sync_synchronize} builtin.
1881
1882
1883
1884 @node Implementing BARRIER construct
1885 @section Implementing BARRIER construct
1886
1887 @smallexample
1888 void GOMP_barrier (void)
1889 @end smallexample
1890
1891
1892 @node Implementing THREADPRIVATE construct
1893 @section Implementing THREADPRIVATE construct
1894
1895 In _most_ cases we can map this directly to @code{__thread}. Except
1896 that OMP allows constructors for C++ objects. We can either
1897 refuse to support this (how often is it used?) or we can
1898 implement something akin to .ctors.
1899
1900 Even more ideally, this ctor feature is handled by extensions
1901 to the main pthreads library. Failing that, we can have a set
1902 of entry points to register ctor functions to be called.
1903
1904
1905
1906 @node Implementing PRIVATE clause
1907 @section Implementing PRIVATE clause
1908
1909 In association with a PARALLEL, or within the lexical extent
1910 of a PARALLEL block, the variable becomes a local variable in
1911 the parallel subfunction.
1912
1913 In association with FOR or SECTIONS blocks, create a new
1914 automatic variable within the current function. This preserves
1915 the semantic of new variable creation.
1916
1917
1918
1919 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1920 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1921
1922 This seems simple enough for PARALLEL blocks. Create a private
1923 struct for communicating between the parent and subfunction.
1924 In the parent, copy in values for scalar and "small" structs;
1925 copy in addresses for others TREE_ADDRESSABLE types. In the
1926 subfunction, copy the value into the local variable.
1927
1928 It is not clear what to do with bare FOR or SECTION blocks.
1929 The only thing I can figure is that we do something like:
1930
1931 @smallexample
1932 #pragma omp for firstprivate(x) lastprivate(y)
1933 for (int i = 0; i < n; ++i)
1934 body;
1935 @end smallexample
1936
1937 which becomes
1938
1939 @smallexample
1940 @{
1941 int x = x, y;
1942
1943 // for stuff
1944
1945 if (i == n)
1946 y = y;
1947 @}
1948 @end smallexample
1949
1950 where the "x=x" and "y=y" assignments actually have different
1951 uids for the two variables, i.e. not something you could write
1952 directly in C. Presumably this only makes sense if the "outer"
1953 x and y are global variables.
1954
1955 COPYPRIVATE would work the same way, except the structure
1956 broadcast would have to happen via SINGLE machinery instead.
1957
1958
1959
1960 @node Implementing REDUCTION clause
1961 @section Implementing REDUCTION clause
1962
1963 The private struct mentioned in the previous section should have
1964 a pointer to an array of the type of the variable, indexed by the
1965 thread's @var{team_id}. The thread stores its final value into the
1966 array, and after the barrier, the master thread iterates over the
1967 array to collect the values.
1968
1969
1970 @node Implementing PARALLEL construct
1971 @section Implementing PARALLEL construct
1972
1973 @smallexample
1974 #pragma omp parallel
1975 @{
1976 body;
1977 @}
1978 @end smallexample
1979
1980 becomes
1981
1982 @smallexample
1983 void subfunction (void *data)
1984 @{
1985 use data;
1986 body;
1987 @}
1988
1989 setup data;
1990 GOMP_parallel_start (subfunction, &data, num_threads);
1991 subfunction (&data);
1992 GOMP_parallel_end ();
1993 @end smallexample
1994
1995 @smallexample
1996 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1997 @end smallexample
1998
1999 The @var{FN} argument is the subfunction to be run in parallel.
2000
2001 The @var{DATA} argument is a pointer to a structure used to
2002 communicate data in and out of the subfunction, as discussed
2003 above with respect to FIRSTPRIVATE et al.
2004
2005 The @var{NUM_THREADS} argument is 1 if an IF clause is present
2006 and false, or the value of the NUM_THREADS clause, if
2007 present, or 0.
2008
2009 The function needs to create the appropriate number of
2010 threads and/or launch them from the dock. It needs to
2011 create the team structure and assign team ids.
2012
2013 @smallexample
2014 void GOMP_parallel_end (void)
2015 @end smallexample
2016
2017 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
2018
2019
2020
2021 @node Implementing FOR construct
2022 @section Implementing FOR construct
2023
2024 @smallexample
2025 #pragma omp parallel for
2026 for (i = lb; i <= ub; i++)
2027 body;
2028 @end smallexample
2029
2030 becomes
2031
2032 @smallexample
2033 void subfunction (void *data)
2034 @{
2035 long _s0, _e0;
2036 while (GOMP_loop_static_next (&_s0, &_e0))
2037 @{
2038 long _e1 = _e0, i;
2039 for (i = _s0; i < _e1; i++)
2040 body;
2041 @}
2042 GOMP_loop_end_nowait ();
2043 @}
2044
2045 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
2046 subfunction (NULL);
2047 GOMP_parallel_end ();
2048 @end smallexample
2049
2050 @smallexample
2051 #pragma omp for schedule(runtime)
2052 for (i = 0; i < n; i++)
2053 body;
2054 @end smallexample
2055
2056 becomes
2057
2058 @smallexample
2059 @{
2060 long i, _s0, _e0;
2061 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
2062 do @{
2063 long _e1 = _e0;
2064 for (i = _s0, i < _e0; i++)
2065 body;
2066 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
2067 GOMP_loop_end ();
2068 @}
2069 @end smallexample
2070
2071 Note that while it looks like there is trickiness to propagating
2072 a non-constant STEP, there isn't really. We're explicitly allowed
2073 to evaluate it as many times as we want, and any variables involved
2074 should automatically be handled as PRIVATE or SHARED like any other
2075 variables. So the expression should remain evaluable in the
2076 subfunction. We can also pull it into a local variable if we like,
2077 but since its supposed to remain unchanged, we can also not if we like.
2078
2079 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
2080 able to get away with no work-sharing context at all, since we can
2081 simply perform the arithmetic directly in each thread to divide up
2082 the iterations. Which would mean that we wouldn't need to call any
2083 of these routines.
2084
2085 There are separate routines for handling loops with an ORDERED
2086 clause. Bookkeeping for that is non-trivial...
2087
2088
2089
2090 @node Implementing ORDERED construct
2091 @section Implementing ORDERED construct
2092
2093 @smallexample
2094 void GOMP_ordered_start (void)
2095 void GOMP_ordered_end (void)
2096 @end smallexample
2097
2098
2099
2100 @node Implementing SECTIONS construct
2101 @section Implementing SECTIONS construct
2102
2103 A block as
2104
2105 @smallexample
2106 #pragma omp sections
2107 @{
2108 #pragma omp section
2109 stmt1;
2110 #pragma omp section
2111 stmt2;
2112 #pragma omp section
2113 stmt3;
2114 @}
2115 @end smallexample
2116
2117 becomes
2118
2119 @smallexample
2120 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2121 switch (i)
2122 @{
2123 case 1:
2124 stmt1;
2125 break;
2126 case 2:
2127 stmt2;
2128 break;
2129 case 3:
2130 stmt3;
2131 break;
2132 @}
2133 GOMP_barrier ();
2134 @end smallexample
2135
2136
2137 @node Implementing SINGLE construct
2138 @section Implementing SINGLE construct
2139
2140 A block like
2141
2142 @smallexample
2143 #pragma omp single
2144 @{
2145 body;
2146 @}
2147 @end smallexample
2148
2149 becomes
2150
2151 @smallexample
2152 if (GOMP_single_start ())
2153 body;
2154 GOMP_barrier ();
2155 @end smallexample
2156
2157 while
2158
2159 @smallexample
2160 #pragma omp single copyprivate(x)
2161 body;
2162 @end smallexample
2163
2164 becomes
2165
2166 @smallexample
2167 datap = GOMP_single_copy_start ();
2168 if (datap == NULL)
2169 @{
2170 body;
2171 data.x = x;
2172 GOMP_single_copy_end (&data);
2173 @}
2174 else
2175 x = datap->x;
2176 GOMP_barrier ();
2177 @end smallexample
2178
2179
2180
2181 @c ---------------------------------------------------------------------
2182 @c Reporting Bugs
2183 @c ---------------------------------------------------------------------
2184
2185 @node Reporting Bugs
2186 @chapter Reporting Bugs
2187
2188 Bugs in the GNU Offloading and Multi Processing Runtime Library should
2189 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
2190 "openacc", or "openmp", or both to the keywords field in the bug
2191 report, as appropriate.
2192
2193
2194
2195 @c ---------------------------------------------------------------------
2196 @c GNU General Public License
2197 @c ---------------------------------------------------------------------
2198
2199 @include gpl_v3.texi
2200
2201
2202
2203 @c ---------------------------------------------------------------------
2204 @c GNU Free Documentation License
2205 @c ---------------------------------------------------------------------
2206
2207 @include fdl.texi
2208
2209
2210
2211 @c ---------------------------------------------------------------------
2212 @c Funding Free Software
2213 @c ---------------------------------------------------------------------
2214
2215 @include funding.texi
2216
2217 @c ---------------------------------------------------------------------
2218 @c Index
2219 @c ---------------------------------------------------------------------
2220
2221 @node Library Index
2222 @unnumbered Library Index
2223
2224 @printindex cp
2225
2226 @bye