Skip to content

Commit e47dd1f

Browse files
authored
Remove invalid { } after '#pragma omp ... for (#4)
Issue #2 OpenMP's Worksharing-Loop Construct (for C/C++ alias 'omp for') requires that 'for-loops' follow the directive, i.e. adding additional { } around the for loop is not permitted (i.e. no structured block). * utilities/utilities.h (TESTD, TESTD2): Remove { } around the usage of the second ('T') argument. * t-ttdpf-nested-parallel/test.c (main): Avoid { } around outer 'for' loop, passed to TESTD. * t-ttdpfs-nested-parallel/defines.h (NESTED_PARALLEL_FOR): Likewise. * t-ttdpfs-nested-parallel/test.c (main): Likewise. * t-unified-ttdpf-nested-parallel/defines.h (NESTED_PARALLEL_FOR): Likewise. * t-unified-ttdpf-nested-parallel/test.c (main): Likewise. * t-unified-ttdpfs-nested-parallel/defines.h (NESTED_PARALLEL_FOR): * t-unified-ttdpfs-nested-parallel/test.c (main): Likewise. * t-unified-target-large-array/test.c (NESTED_PARALLEL_FOR): Likewise. * t-target-large-array/test.c (Test): Avoid '{ }' around for after the '#pragma omp ... for'. * t-unified-target-large-array/test.c (Test): Likewise. Co-authored-by: Tobias Burnus <[email protected]>
1 parent e1a3a52 commit e47dd1f

File tree

11 files changed

+30
-26
lines changed

11 files changed

+30
-26
lines changed

t-target-large-array/test.c

-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ int Test(int start, int size)
1717
for(i=size; i<N; i++) b[i] = -1;
1818

1919
#pragma omp target parallel for
20-
{
2120
for(int i=start; i<size; i++) b[i] += 1;
22-
}
2321

2422
for(i=0; i<start && errors<25; i++) {
2523
if (b[i] != -1) printf("%4i: before, got %d, expected %d, %d error\n", i, b[i], -1, ++errors);

t-ttdpf-nested-parallel/defines.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#undef NESTED_PARALLEL_FOR
3-
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", { \
3+
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", \
44
for (int idx = 0; idx < tms*th; idx++) { \
55
PRE \
66
_Pragma("omp parallel for if(threads[0] > 1) num_threads(threads[0]) NESTED_PARALLEL_FOR_CLAUSES") \
@@ -13,7 +13,7 @@ _Pragma("omp parallel for schedule(static,9) if(threads[0] > 1) num_threads(thre
1313
X \
1414
POST \
1515
} \
16-
}, VERIFY)
16+
, VERIFY)
1717

1818
#undef SUMS
1919
#define SUMS (4)

t-ttdpf-nested-parallel/test.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int main(void) {
162162
//
163163
// Test: lastprivate clause on omp target teams distribute parallel for with nested parallel.
164164
//
165-
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", {
165+
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)",
166166
for (int idx = 0; idx < tms*th; idx++) {
167167
double q0[1];
168168
double q1[1];
@@ -198,7 +198,7 @@ int main(void) {
198198
}
199199
S[idx] += tmp;
200200
}
201-
}, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
201+
, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
202202

203203
//
204204
// Test: private clause on omp target teams distribute parallel for with nested parallel.
@@ -312,7 +312,7 @@ int main(void) {
312312
// Test: Ensure coalesced scheduling on GPU.
313313
//
314314
if (!cpuExec) {
315-
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", {
315+
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)",
316316
for (int idx = 0; idx < tms*th; idx++) {
317317
S[idx] = 0;
318318
for (int i = 0; i < 96; i++) {
@@ -336,7 +336,7 @@ int main(void) {
336336
}
337337
S[idx] = tmp;
338338
}
339-
}, VERIFY(0, tms*th, S[i], (double) 3 * 95 * 48 ));
339+
, VERIFY(0, tms*th, S[i], (double) 3 * 95 * 48 ));
340340
} else {
341341
DUMP_SUCCESS(1);
342342
}

t-ttdpfs-nested-parallel/defines.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#undef NESTED_PARALLEL_FOR
3-
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", { \
3+
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", \
44
for (int idx = 0; idx < tms*th; idx++) { \
55
PRE \
66
_Pragma("omp parallel for if(threads[0] > 1) num_threads(threads[0]) NESTED_PARALLEL_FOR_CLAUSES") \
@@ -13,7 +13,7 @@ _Pragma("omp parallel for schedule(static,9) if(threads[0] > 1) num_threads(thre
1313
X \
1414
POST \
1515
} \
16-
}, VERIFY)
16+
, VERIFY)
1717

1818
#undef SUMS
1919
#define SUMS (4)

t-ttdpfs-nested-parallel/test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int main(void) {
157157
//
158158
// Test: lastprivate clause on omp target teams distribute parallel for with nested parallel.
159159
//
160-
TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", {
160+
TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)",
161161
for (int idx = 0; idx < tms*th; idx++) {
162162
double q0[1];
163163
double q1[1];
@@ -193,7 +193,7 @@ int main(void) {
193193
}
194194
S[idx] += tmp;
195195
}
196-
}, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
196+
, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
197197

198198
//
199199
// Test: private clause on omp target teams distribute parallel for with nested parallel.

t-unified-target-large-array/test.c

-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ int Test(int start, int size)
1919
for(i=size; i<N; i++) b[i] = -1;
2020

2121
#pragma omp target parallel for
22-
{
2322
for(int i=start; i<size; i++) b[i] += 1;
24-
}
2523

2624
for(i=0; i<start && errors<25; i++) {
2725
if (b[i] != -1) printf("%4i: before, got %d, expected %d, %d error\n", i, b[i], -1, ++errors);

t-unified-ttdpf-nested-parallel/defines.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#undef NESTED_PARALLEL_FOR
3-
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", { \
3+
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", \
44
for (int idx = 0; idx < tms*th; idx++) { \
55
PRE \
66
_Pragma("omp parallel for if(threads[0] > 1) num_threads(threads[0]) NESTED_PARALLEL_FOR_CLAUSES") \
@@ -13,7 +13,7 @@ _Pragma("omp parallel for schedule(static,9) if(threads[0] > 1) num_threads(thre
1313
X \
1414
POST \
1515
} \
16-
}, VERIFY)
16+
, VERIFY)
1717

1818
#undef SUMS
1919
#define SUMS (4)

t-unified-ttdpf-nested-parallel/test.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int main(void) {
164164
//
165165
// Test: lastprivate clause on omp target teams distribute parallel for with nested parallel.
166166
//
167-
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", {
167+
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)",
168168
for (int idx = 0; idx < tms*th; idx++) {
169169
double q0[1];
170170
double q1[1];
@@ -200,7 +200,7 @@ int main(void) {
200200
}
201201
S[idx] += tmp;
202202
}
203-
}, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
203+
, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
204204

205205
//
206206
// Test: private clause on omp target teams distribute parallel for with nested parallel.
@@ -314,7 +314,7 @@ int main(void) {
314314
// Test: Ensure coalesced scheduling on GPU.
315315
//
316316
if (!cpuExec) {
317-
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)", {
317+
TESTD("omp target teams distribute parallel for num_teams(tms) num_threads(th)",
318318
for (int idx = 0; idx < tms*th; idx++) {
319319
S[idx] = 0;
320320
for (int i = 0; i < 96; i++) {
@@ -338,7 +338,7 @@ int main(void) {
338338
}
339339
S[idx] = tmp;
340340
}
341-
}, VERIFY(0, tms*th, S[i], (double) 3 * 95 * 48 ));
341+
, VERIFY(0, tms*th, S[i], (double) 3 * 95 * 48 ));
342342
} else {
343343
DUMP_SUCCESS(1);
344344
}

t-unified-ttdpfs-nested-parallel/defines.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#undef NESTED_PARALLEL_FOR
3-
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", { \
3+
#define NESTED_PARALLEL_FOR(PRE,X,POST,VERIFY) TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", \
44
for (int idx = 0; idx < tms*th; idx++) { \
55
PRE \
66
_Pragma("omp parallel for if(threads[0] > 1) num_threads(threads[0]) NESTED_PARALLEL_FOR_CLAUSES") \
@@ -13,7 +13,7 @@ _Pragma("omp parallel for schedule(static,9) if(threads[0] > 1) num_threads(thre
1313
X \
1414
POST \
1515
} \
16-
}, VERIFY)
16+
, VERIFY)
1717

1818
#undef SUMS
1919
#define SUMS (4)

t-unified-ttdpfs-nested-parallel/test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int main(void) {
159159
//
160160
// Test: lastprivate clause on omp target teams distribute parallel for with nested parallel.
161161
//
162-
TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)", {
162+
TESTD("omp target teams distribute parallel for dist_schedule(static,2) num_teams(tms) num_threads(th)",
163163
for (int idx = 0; idx < tms*th; idx++) {
164164
double q0[1];
165165
double q1[1];
@@ -195,7 +195,7 @@ int main(void) {
195195
}
196196
S[idx] += tmp;
197197
}
198-
}, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
198+
, VERIFY(0, tms*th, S[i], (double) 2 * (N + (N/2*(N+1))) ));
199199

200200
//
201201
// Test: private clause on omp target teams distribute parallel for with nested parallel.

utilities/utilities.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@
7171
printf ("Succeeded\n"); \
7272
}
7373

74+
/* NOTE: If needed for the pragram 'T' needs to add '{ }'; they are not
75+
added unconditionally as, e.g., for '#pragma omp ... for', no '{}'
76+
are permitted. */
77+
7478
#define TESTD(D, T, V) { \
7579
int fail = 0; \
7680
int trial; \
7781
for (int trial = 0; trial < TRIALS && fail == 0; trial++) { \
7882
_Pragma(D) \
79-
{T} \
83+
T \
8084
V \
8185
} \
8286
if (fail) { \
@@ -86,13 +90,17 @@
8690
} \
8791
}
8892

93+
/* NOTE: If needed for the pragram 'T' needs to add '{ }'; they are not
94+
added unconditionally as, e.g., for '#pragma omp ... for', no '{}'
95+
are permitted. */
96+
8997
#define TESTD2(D, PRE, T, POST, V) { \
9098
int fail = 0; \
9199
int trial; \
92100
for (int trial = 0; trial < TRIALS && fail == 0; trial++) { \
93101
PRE \
94102
_Pragma(D) \
95-
{T} \
103+
T \
96104
POST \
97105
V \
98106
} \

0 commit comments

Comments
 (0)