summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/taskloop-5.C
blob: eb464467b669a8d5e32a433073a112bae6e63c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <omp.h>

__attribute__((noinline, noclone)) void
foo (int &b)
{
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (b, f)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (!f)
	  {
	    if (b != 2)
	      __builtin_abort ();
	  }
	else if (b != 8 * q)
	  __builtin_abort ();
	b = 8 * q;
	f = true;
      }
  }
  int n;
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (f) lastprivate (b, n)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (f && b != 8 * q)
	  __builtin_abort ();
	b = 8 * q;
	n = q;
	f = true;
      }
  }
  if (b != 8 * n)
    __builtin_abort ();
  b = 9;
#pragma omp parallel
#pragma omp single
  {
    bool f = false;
  #pragma omp taskloop firstprivate (b, f) lastprivate (b, n)
    for (int i = 0; i < 30; i++)
      {
	int q = omp_get_thread_num ();
	if (!f)
	  {
	    if (b != 9)
	      __builtin_abort ();
	  }
	else if (b != 11 * q)
	  __builtin_abort ();
	b = 11 * q;
	n = q;
	f = true;
      }
  }
  if (b != 11 * n)
    __builtin_abort ();
}

int
main ()
{
  int b = 2;
  foo (b);
}