]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/omp-par-scope.c
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2017-2020 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Testcase for checking access to variables in a single / outer scope.
22 Make sure that variables not referred to in the parallel section are
23 accessible from the debugger. */
28 static int s1
= -41, s2
= -42, s3
= -43;
29 int i1
= 11, i2
= 12, i3
= 13;
31 #pragma omp parallel num_threads (2) shared (s1, i1) private (s2, i2)
33 int thread_num
= omp_get_thread_num ();
35 s2
= 100 * (thread_num
+ 1) + 2;
39 printf ("single_scope: thread_num=%d, s1=%d, i1=%d, s2=%d, i2=%d\n",
40 thread_num
, s1
, i1
, s2
, i2
);
43 printf ("single_scope: s1=%d, s2=%d, s3=%d, i1=%d, i2=%d, i3=%d\n",
44 s1
, s2
, s3
, i1
, i2
, i3
);
47 static int file_scope_var
= 9876;
49 /* Testcase for checking access to variables from parallel region
50 nested within more than one lexical scope. Of particular interest
51 are variables which are not referenced in the parallel section. */
59 int i11
= 11, i12
= 12;
62 int i21
= -21, i22
= 22;
64 #pragma omp parallel num_threads (2) \
69 int thread_num
= omp_get_thread_num ();
70 i21
= 100 * (thread_num
+ 1) + 21;
73 printf ("multi_scope: thread_num=%d, i01=%d, i11=%d, i21=%d\n",
74 thread_num
, i01
, i11
, i21
);
77 printf ("multi_scope: i01=%d, i02=%d, i11=%d, "
78 "i12=%d, i21=%d, i22=%d\n",
79 i01
, i02
, i11
, i12
, i21
, i22
);
84 /* Nested functions in C is a GNU extension. Some non-GNU compilers
85 define __GNUC__, but they don't support nested functions. So,
86 unfortunately, we can't use that for our test. */
87 #if HAVE_NESTED_FUNCTION_SUPPORT
89 /* Testcase for checking access of variables from within parallel
90 region in a lexically nested function. */
96 int i
= 1, j
= 2, k
= 3;
99 foo (int p
, int q
, int r
)
105 #pragma omp parallel num_threads (2) shared (i, p, x) private (j, q, y)
107 int tn
= omp_get_thread_num ();
113 printf ("nested_func: tn=%d: i=%d, p=%d, x=%d, j=%d, q=%d, y=%d\n",
114 tn
, i
, p
, x
, j
, q
, y
);
121 i
= 101; j
= 102; k
= 103;
126 /* Testcase for checking access to variables from within a nested parallel
130 nested_parallel (void)
137 #pragma omp parallel num_threads (2) private (l)
139 int num
= omp_get_thread_num ();
140 int nthr
= omp_get_num_threads ();
141 int off
= num
* nthr
;
144 #pragma omp parallel num_threads (2) shared (num)
146 int inner_num
= omp_get_thread_num ();
148 printf ("nested_parallel (inner threads): outer thread num = %d, thread num = %d\n", num
, inner_num
);
151 printf ("nested_parallel (outer threads) %d: k = %d, l = %d\n", num
, k
, l
);
156 main (int argc
, char **argv
)
160 #if HAVE_NESTED_FUNCTION_SUPPORT