depend-mutexinout-1.c 764 B

12345678910111213141516171819202122232425262728
  1. int
  2. main ()
  3. {
  4. int a, b, c, d;
  5. #pragma omp parallel num_threads (6)
  6. #pragma omp single
  7. {
  8. #pragma omp task depend(out: c)
  9. c = 1;
  10. #pragma omp task depend(out: a)
  11. a = 2;
  12. #pragma omp task depend(out: b)
  13. b = 3;
  14. /* The above 3 tasks can be scheduled in any order. */
  15. #pragma omp task depend(in: a) depend(mutexinoutset: c)
  16. c += a;
  17. #pragma omp task depend(in: b) depend(mutexinoutset: c)
  18. c += b;
  19. /* The above 2 tasks are mutually exclusive and need to wait
  20. for the first and second or first and third tasks respectively. */
  21. #pragma omp task depend(in: c)
  22. d = c;
  23. /* The above task needs to wait for the mutexinoutset tasks. */
  24. }
  25. if (d != 6)
  26. __builtin_abort ();
  27. return 0;
  28. }