reduction-4.c 593 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <omp.h>
  2. #include <stdlib.h>
  3. int
  4. main (void)
  5. {
  6. int i = 0, j = 0, k = 0, l = 0;
  7. #pragma omp parallel num_threads(4) reduction(-:i) reduction(|:k) \
  8. reduction(^:l)
  9. {
  10. if (i != 0 || k != 0 || l != 0)
  11. #pragma omp atomic
  12. j |= 1;
  13. if (omp_get_num_threads () != 4)
  14. #pragma omp atomic
  15. j |= 2;
  16. i = omp_get_thread_num ();
  17. k = 1 << (2 * i);
  18. l = 0xea << (3 * i);
  19. }
  20. if (j & 1)
  21. abort ();
  22. if ((j & 2) == 0)
  23. {
  24. if (i != (0 + 1 + 2 + 3))
  25. abort ();
  26. if (k != 0x55)
  27. abort ();
  28. if (l != 0x1e93a)
  29. abort ();
  30. }
  31. return 0;
  32. }