scope-1.c 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifdef __cplusplus
  2. extern "C"
  3. #endif
  4. void abort ();
  5. int
  6. main ()
  7. {
  8. int a[64] = {};
  9. int r = 0, r2 = 0, i;
  10. #pragma omp parallel
  11. {
  12. #pragma omp scope nowait
  13. #pragma omp scope nowait
  14. #pragma omp for
  15. for (i = 0; i < 64; i++)
  16. a[i] += 1;
  17. #pragma omp scope reduction(+: r) nowait
  18. {
  19. #pragma omp for nowait
  20. for (i = 0; i < 64; i++)
  21. {
  22. r += i;
  23. if (a[i] != 1)
  24. abort ();
  25. }
  26. #pragma omp barrier
  27. }
  28. #pragma omp barrier
  29. if (r != 64 * 63 / 2)
  30. abort ();
  31. #pragma omp scope nowait private (i)
  32. #pragma omp scope reduction(+: r2)
  33. {
  34. #pragma omp for nowait
  35. for (i = 0; i < 64; i++)
  36. {
  37. r2 += 2 * i;
  38. a[i] += i;
  39. }
  40. }
  41. if (r2 != 64 * 63)
  42. abort ();
  43. #pragma omp for nowait
  44. for (i = 0; i < 64; i++)
  45. if (a[i] != i + 1)
  46. abort ();
  47. }
  48. return 0;
  49. }