[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / openmp / runtime / test / teams / teams-atomic.c
blob367355df2e8397b362c29e7806d5acb1439780e7
1 // Check that omp atomic is permitted and behaves when strictly nested within
2 // omp teams. This is an extension to OpenMP 5.2 and is enabled by default.
4 // RUN: %libomp-compile-and-run | FileCheck %s
5 // GCC has really limited OpenMP 5.2 support yet.
6 // UNSUPPORTED: gcc
8 #include <omp.h>
9 #include <stdbool.h>
10 #include <stdio.h>
11 #include <string.h>
13 // High parallelism increases our chances of detecting a lack of atomicity.
14 #define NUM_TEAMS_TRY 256
16 int main() {
17 // CHECK: update: num_teams=[[#NUM_TEAMS:]]{{$}}
18 // CHECK-NEXT: update: x=[[#NUM_TEAMS]]{{$}}
19 int x = 0;
20 int numTeams;
21 #pragma omp teams num_teams(NUM_TEAMS_TRY)
23 #pragma omp atomic update
24 ++x;
25 if (omp_get_team_num() == 0)
26 numTeams = omp_get_num_teams();
28 printf("update: num_teams=%d\n", numTeams);
29 printf("update: x=%d\n", x);
31 // CHECK-NEXT: capture: x=[[#NUM_TEAMS]]{{$}}
32 // CHECK-NEXT: capture: xCapturedCount=[[#NUM_TEAMS]]{{$}}
33 bool xCaptured[numTeams];
34 memset(xCaptured, 0, sizeof xCaptured);
35 x = 0;
36 #pragma omp teams num_teams(NUM_TEAMS_TRY)
38 int v;
39 #pragma omp atomic capture
40 v = x++;
41 xCaptured[v] = true;
43 printf("capture: x=%d\n", x);
44 int xCapturedCount = 0;
45 for (int i = 0; i < numTeams; ++i) {
46 if (xCaptured[i])
47 ++xCapturedCount;
49 printf("capture: xCapturedCount=%d\n", xCapturedCount);
50 return 0;