1 // Check that omp atomic is permitted and behaves when strictly nested within
2 // omp target teams. This is an extension to OpenMP 5.2 and is enabled by
5 // RUN: %libomptarget-compile-run-and-check-generic
12 // High parallelism increases our chances of detecting a lack of atomicity.
13 #define NUM_TEAMS_TRY 256
16 // CHECK: update: num_teams=[[#NUM_TEAMS:]]{{$}}
17 // CHECK-NEXT: update: x=[[#NUM_TEAMS]]{{$}}
20 #pragma omp target teams num_teams(NUM_TEAMS_TRY) map(tofrom : x, numTeams)
22 #pragma omp atomic update
24 if (omp_get_team_num() == 0)
25 numTeams
= omp_get_num_teams();
27 printf("update: num_teams=%d\n", numTeams
);
28 printf("update: x=%d\n", x
);
30 // CHECK-NEXT: capture: x=[[#NUM_TEAMS]]{{$}}
31 // CHECK-NEXT: capture: xCapturedCount=[[#NUM_TEAMS]]{{$}}
32 bool xCaptured
[numTeams
];
33 memset(xCaptured
, 0, sizeof xCaptured
);
35 #pragma omp target teams num_teams(NUM_TEAMS_TRY) map(tofrom : x, numTeams)
38 #pragma omp atomic capture
42 printf("capture: x=%d\n", x
);
43 int xCapturedCount
= 0;
44 for (int i
= 0; i
< numTeams
; ++i
) {
48 printf("capture: xCapturedCount=%d\n", xCapturedCount
);