1 // RUN: %compile-run-and-check 2 3 #include <omp.h> 4 #include <stdio.h> 5 main(int argc,char * argv[])6int main(int argc, char *argv[]) { 7 int data, out, flag = 0; 8 #pragma omp target teams num_teams(2) map(tofrom \ 9 : out) map(to \ 10 : data, flag) \ 11 thread_limit(1) 12 #pragma omp parallel num_threads(1) 13 { 14 if (omp_get_team_num() == 0) { 15 /* Write to the data buffer that will be read by thread in team 1 */ 16 data = 42; 17 /* Flush data to thread in team 1 */ 18 #pragma omp barrier 19 /* Set flag to release thread in team 1 */ 20 #pragma omp atomic write 21 flag = 1; 22 } else if (omp_get_team_num() == 1) { 23 /* Loop until we see the update to the flag */ 24 int val; 25 do { 26 #pragma omp atomic read 27 val = flag; 28 } while (val < 1); 29 out = data; 30 #pragma omp barrier 31 } 32 } 33 // CHECK: out=42. 34 /* Value of out will be 42 */ 35 printf("out=%d.\n", out); 36 return !(out == 42); 37 } 38