Skip to content

Commit

Permalink
[OpenMP] [test] Fix target_thread_limit.cpp to not assume 4 or more c…
Browse files Browse the repository at this point in the history
…ores

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
  • Loading branch information
mstorsjo committed Sep 1, 2023
1 parent a23b9b7 commit c2019c4
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions openmp/runtime/test/target/target_thread_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ int main(void) {
#pragma omp target thread_limit(tl)
{
printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
int count = 0;
// OMP51: target: thread_limit = 4
// check whether thread_limit is honoured
#pragma omp parallel
{ printf("\ntarget: parallel"); }
// OMP51: target: parallel
// OMP51: target: parallel
// OMP51: target: parallel
// OMP51: target: parallel
// OMP51-NOT: target: parallel
#pragma omp parallel reduction(+:count)
{ count++; }
printf("\ntarget: parallel: count = %d", count);
// OMP51: target: parallel: count = {{(1|2|3|4)$}}

// check whether num_threads is honoured
#pragma omp parallel num_threads(2)
Expand Down Expand Up @@ -70,13 +68,12 @@ int main(void) {
#pragma omp target thread_limit(3)
{
printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
int count = 0;
// OMP51: second target: thread_limit = 3
#pragma omp parallel
{ printf("\nsecond target: parallel"); }
// OMP51: second target: parallel
// OMP51: second target: parallel
// OMP51: second target: parallel
// OMP51-NOT: second target: parallel
#pragma omp parallel reduction(+:count)
{ count++; }
printf("\nsecond target: parallel: count = %d", count);
// OMP51: second target: parallel: count = {{(1|2|3)$}}
}

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

0 comments on commit c2019c4

Please sign in to comment.