reduction-1.C 615 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <omp.h>
  2. #include <stdlib.h>
  3. int
  4. main (void)
  5. {
  6. int i = 0, j = 0, k = ~0;
  7. double d = 1.0;
  8. #pragma omp parallel num_threads(4) reduction(+:i) reduction(*:d) reduction(&:k)
  9. {
  10. if (i != 0 || d != 1.0 || k != ~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. d = i + 1;
  18. k = ~(1 << (2 * 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 (d != (1.0 * 2.0 * 3.0 * 4.0))
  27. abort ();
  28. if (k != (~0 ^ 0x55))
  29. abort ();
  30. }
  31. return 0;
  32. }