aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c
blob: 8900a4e070da1d7ccc5b31427485e92e02e844d8 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* Test behavior of 'firstprivate' lexically vs. dynamically nested inside a
   'data' region.  */

#include <stdlib.h>


#define VERIFY(x) \
  do { \
    if (!(x)) \
      abort (); \
  } while (0);


/* This is basically and extended version of 't2' from 'firstprivate-1.c'.  */

int lexically_nested_val = 2;

static void
lexically_nested ()
{
#pragma acc data \
  copy (lexically_nested_val)
  {
    VERIFY (lexically_nested_val == 2);

#pragma acc parallel \
  present (lexically_nested_val)
    {
      VERIFY (lexically_nested_val == 2);

      /* This updates the device copy, or shared variable.  */
      lexically_nested_val = 7;
    }

#if ACC_MEM_SHARED
    VERIFY (lexically_nested_val == 7);
#else
    VERIFY (lexically_nested_val == 2);
#endif

    /* This only updates the local/shared variable, but not the device
       copy.  */
    lexically_nested_val = 5;

#pragma acc parallel \
    firstprivate (lexically_nested_val)
      {
#if 1 /* Current behavior.  */
	/* The 'firstprivate' copy is initialized from the device copy, or
	   shared variable.  */
# if ACC_MEM_SHARED
	VERIFY (lexically_nested_val == 5);
# else
	VERIFY (lexically_nested_val == 7);
# endif
#else /* Expected behavior per PR92036.  */
	/* The 'firstprivate' copy is initialized from the local thread.  */
	VERIFY (lexically_nested_val == 5);
#endif

	/* This updates the 'firstprivate' copy only, but not the shared
	   variable.  */
	lexically_nested_val = 9;
      }

    VERIFY (lexically_nested_val == 5);
  }
  /* If not shared, the device copy has now been copied back.  */

#if ACC_MEM_SHARED
  VERIFY (lexically_nested_val == 5);
#else
  VERIFY (lexically_nested_val == 7);
#endif
}


int dynamically_nested_val = 2;

/* Same as above, but compute construct 1 broken out, so no longer lexically
   nested inside 'data' region.  */

static void
dynamically_nested_compute_1 ()
{
#pragma acc parallel \
  present (dynamically_nested_val)
  {
    VERIFY (dynamically_nested_val == 2);

    /* This updates the device copy, or shared variable.  */
    dynamically_nested_val = 7;
  }
}

/* Same as above, but compute construct 2 broken out, so no longer lexically
   nested inside 'data' region.  */

static void
dynamically_nested_compute_2 ()
{
#pragma acc parallel \
  firstprivate (dynamically_nested_val)
    {
#if 1 /* Current behavior.  */
      /* The 'firstprivate' copy is initialized from the device copy, or shared
	 variable.  */
# if ACC_MEM_SHARED
      VERIFY (dynamically_nested_val == 5);
# else
      VERIFY (dynamically_nested_val == 7);
# endif
#else /* Expected behavior per PR92036.  */
      /* The 'firstprivate' copy is initialized from the local thread.  */
      VERIFY (dynamically_nested_val == 5);
#endif

      /* This updates the 'firstprivate' copy only, but not the shared
	 variable.  */
      dynamically_nested_val = 9;
    }
}

static void
dynamically_nested ()
{
#pragma acc data \
  copy (dynamically_nested_val)
  {
    VERIFY (dynamically_nested_val == 2);

    dynamically_nested_compute_1 ();

#if ACC_MEM_SHARED
    VERIFY (dynamically_nested_val == 7);
#else
    VERIFY (dynamically_nested_val == 2);
#endif

    /* This only updates the local/shared variable, but not the device
       copy.  */
    dynamically_nested_val = 5;

    dynamically_nested_compute_2 ();

    VERIFY (dynamically_nested_val == 5);
  }
  /* If not shared, the device copy has now been copied back.  */

#if ACC_MEM_SHARED
  VERIFY (dynamically_nested_val == 5);
#else
  VERIFY (dynamically_nested_val == 7);
#endif
}


int
main()
{
  lexically_nested ();
  dynamically_nested ();

  return 0;
}