]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/doc/the-libgomp-abi/implementing-parallel-construct.rst
sphinx: copy files from texi2rst-generated repository
[thirdparty/gcc.git] / libgomp / doc / the-libgomp-abi / implementing-parallel-construct.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. _implementing-parallel-construct:
7
8 Implementing PARALLEL construct
9 *******************************
10
11 .. code-block:: c++
12
13 #pragma omp parallel
14 {
15 body;
16 }
17
18 becomes
19
20 .. code-block:: c++
21
22 void subfunction (void *data)
23 {
24 use data;
25 body;
26 }
27
28 setup data;
29 GOMP_parallel_start (subfunction, &data, num_threads);
30 subfunction (&data);
31 GOMP_parallel_end ();
32
33 .. code-block:: c++
34
35 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
36
37 The :samp:`{FN}` argument is the subfunction to be run in parallel.
38
39 The :samp:`{DATA}` argument is a pointer to a structure used to
40 communicate data in and out of the subfunction, as discussed
41 above with respect to FIRSTPRIVATE et al.
42
43 The :samp:`{NUM_THREADS}` argument is 1 if an IF clause is present
44 and false, or the value of the NUM_THREADS clause, if
45 present, or 0.
46
47 The function needs to create the appropriate number of
48 threads and/or launch them from the dock. It needs to
49 create the team structure and assign team ids.
50
51 .. code-block:: c++
52
53 void GOMP_parallel_end (void)
54
55 Tears down the team and returns us to the previous ``omp_in_parallel()`` state.