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