xref: /llvm-project/offload/test/offloading/bug50022.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-and-run-generic
2 // RUN: %libomptarget-compileoptxx-and-run-generic
3 
4 #include <cassert>
5 #include <iostream>
6 #include <stdexcept>
7 
main(int argc,char * argv[])8 int main(int argc, char *argv[]) {
9   int a = 0;
10   std::cout << "outside a = " << a << " addr " << &a << std::endl;
11 #pragma omp target map(tofrom : a) depend(out : a) nowait
12   {
13     int sum = 0;
14     for (int i = 0; i < 100000; i++)
15       sum++;
16     a = 1;
17   }
18 
19 #pragma omp task depend(inout : a) shared(a)
20   {
21     std::cout << "a = " << a << " addr " << &a << std::endl;
22     if (a != 1)
23       throw std::runtime_error("wrong result!");
24     a = 2;
25   }
26 
27 #pragma omp task depend(inout : a) shared(a)
28   {
29     std::cout << "a = " << a << " addr " << &a << std::endl;
30     if (a != 2)
31       throw std::runtime_error("wrong result!");
32     a = 3;
33   }
34 
35 #pragma omp taskwait
36 
37   assert(a == 3 && "wrong result!");
38 
39   return 0;
40 }
41