summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/pr33880.c
blob: 5d719cd635dfee18155092d2623415d8c128fea8 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* PR middle-end/33880 */
/* { dg-do run } */

extern void abort (void);

void
test1 (void)
{
  int i = 0, j = 0;
  void bar (void)
  {
    i++;
    j++;
  }
  bar ();
  #pragma omp parallel for num_threads(4)
    for (i = 0; i < 100; i++)
      #pragma omp atomic
	j += 1;
  if (j != 101)
    abort ();
  #pragma omp parallel for lastprivate(i) num_threads(2)
    for (i = 0; i < 100; i++)
      #pragma omp atomic
	j += 1;
  if (i != 100)
    abort ();
  i = 3;
  bar ();
  if (j != 202)
    abort ();
  if (i != 4)
    abort ();
}

void
test2 (void)
{
  int i = -1, j = 99, k, l = 9, m = 0;
  void bar (void)
  {
    i++;
    j++;
    l++;
    m++;
  }
  bar ();
  #pragma omp parallel for num_threads(4)
    for (k = i; k < j; k += l)
      #pragma omp atomic
	m += 1;
  bar ();
  if (i != 1 || j != 101 || l != 11 || m != 12)
    abort ();
}

void
test3 (void)
{
  int i, j, k, l, m;
  void bar (void)
  {
  #pragma omp parallel for num_threads(4)
    for (i = j; i < k; i += l)
      #pragma omp atomic
        m += 1;
  }
  void baz (void)
  {
  #pragma omp parallel for num_threads(2) lastprivate(i)
    for (i = j; i < k * 2; i += l / 2)
      #pragma omp atomic
        m += 1;
  }
  i = 7;
  j = 0;
  k = 100;
  l = 2;
  m = 0;
  bar ();
  if (j != 0 || k != 100 || l != 2 || m != 50)
    abort ();
  baz ();
  if (i != 200 || j != 0 || k != 100 || l != 2 || m != 250)
    abort ();
}

void
test4 (void)
{
  int i, j, k, l, m = 0;
  int foo (void)
  {
    return j;
  }
  int bar (void)
  {
    return k;
  }
  int baz (void)
  {
    return l;
  }
  j = 0;
  k = 1000;
  l = 2;
  #pragma omp parallel for num_threads(8) lastprivate(i)
  for (i = foo (); i < bar (); i += baz ())
    #pragma omp atomic
      m += 1;
  if (i != 1000 || m != 500 || j != 0 || k != 1000 || l != 2)
    abort ();
}

int
main (void)
{
  test1 ();
  test2 ();
  test3 ();
  test4 ();
  return 0;
}