fork download
  1. #include <omp.h>
  2. #include <stdio.h>
  3.  
  4. int b;
  5.  
  6. int main()
  7. {
  8. int a = 1;
  9. int c = 3;
  10. b = 2;
  11.  
  12. #pragma omp threadprivate(b)
  13.  
  14. #pragma omp parallel firstprivate(c) num_threads(4)
  15. {
  16. int d = a + c;
  17.  
  18. #pragma omp atomic
  19. c += 1;
  20.  
  21. #pragma omp atomic
  22. a += 2;
  23.  
  24. #pragma omp atomic
  25. d += 3;
  26.  
  27. b = d;
  28.  
  29. printf("a=%d b=%d c=%d d=%d\n", a, b, c, d);
  30. }
  31.  
  32. printf("after: a=%d b=%d c=%d\n", a, b, c);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
a=3 b=7 c=4 d=7
after: a=3 b=7 c=4