0
|
1 // { dg-do run }
|
|
2
|
|
3 #include <omp.h>
|
|
4 #include <assert.h>
|
|
5
|
|
6 #define N 10
|
|
7
|
|
8 struct B
|
|
9 {
|
|
10 static int icount;
|
|
11 static int dcount;
|
|
12 static int xcount;
|
|
13
|
|
14 B();
|
|
15 B(const B &);
|
|
16 ~B();
|
|
17 B& operator=(const B &);
|
|
18 void doit();
|
|
19 };
|
|
20
|
|
21 int B::icount;
|
|
22 int B::dcount;
|
|
23 int B::xcount;
|
|
24
|
|
25 B::B()
|
|
26 {
|
|
27 #pragma omp atomic
|
|
28 icount++;
|
|
29 }
|
|
30
|
|
31 B::~B()
|
|
32 {
|
|
33 #pragma omp atomic
|
|
34 dcount++;
|
|
35 }
|
|
36
|
|
37 void B::doit()
|
|
38 {
|
|
39 #pragma omp atomic
|
|
40 xcount++;
|
|
41 }
|
|
42
|
|
43 static int nthreads;
|
|
44
|
|
45 void foo()
|
|
46 {
|
|
47 B b[N];
|
|
48 #pragma omp parallel private(b)
|
|
49 {
|
|
50 #pragma omp master
|
|
51 nthreads = omp_get_num_threads ();
|
|
52 b[0].doit();
|
|
53 }
|
|
54 }
|
|
55
|
|
56 int main()
|
|
57 {
|
|
58 omp_set_dynamic (0);
|
|
59 omp_set_num_threads (4);
|
|
60 foo();
|
|
61
|
|
62 assert (B::xcount == nthreads);
|
|
63 assert (B::icount == (nthreads+1)*N);
|
|
64 assert (B::dcount == (nthreads+1)*N);
|
|
65
|
|
66 return 0;
|
|
67 }
|