Skip to content

Commit c2019c4

Browse files
committed
[OpenMP] [test] Fix target_thread_limit.cpp to not assume 4 or more cores
Previously, the test ran a section with #pragma omp target thread_limit(4) and expected it to execute exactly 4 times, even though it would in practice execute min(cores, 4) times. Increment a counter and check that it executed 1-4 times. Differential Revision: https://reviews.llvm.org/D159311
1 parent a23b9b7 commit c2019c4

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

openmp/runtime/test/target/target_thread_limit.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ int main(void) {
1818
#pragma omp target thread_limit(tl)
1919
{
2020
printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
21+
int count = 0;
2122
// OMP51: target: thread_limit = 4
2223
// check whether thread_limit is honoured
23-
#pragma omp parallel
24-
{ printf("\ntarget: parallel"); }
25-
// OMP51: target: parallel
26-
// OMP51: target: parallel
27-
// OMP51: target: parallel
28-
// OMP51: target: parallel
29-
// OMP51-NOT: target: parallel
24+
#pragma omp parallel reduction(+:count)
25+
{ count++; }
26+
printf("\ntarget: parallel: count = %d", count);
27+
// OMP51: target: parallel: count = {{(1|2|3|4)$}}
3028

3129
// check whether num_threads is honoured
3230
#pragma omp parallel num_threads(2)
@@ -70,13 +68,12 @@ int main(void) {
7068
#pragma omp target thread_limit(3)
7169
{
7270
printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
71+
int count = 0;
7372
// OMP51: second target: thread_limit = 3
74-
#pragma omp parallel
75-
{ printf("\nsecond target: parallel"); }
76-
// OMP51: second target: parallel
77-
// OMP51: second target: parallel
78-
// OMP51: second target: parallel
79-
// OMP51-NOT: second target: parallel
73+
#pragma omp parallel reduction(+:count)
74+
{ count++; }
75+
printf("\nsecond target: parallel: count = %d", count);
76+
// OMP51: second target: parallel: count = {{(1|2|3)$}}
8077
}
8178

8279
// confirm that thread_limit's effects are limited to target region

0 commit comments

Comments
 (0)