task-reduction-12.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. extern
  2. #ifdef __cplusplus
  3. "C"
  4. #endif
  5. void abort (void);
  6. int a, b[3] = { 1, 1, 1 };
  7. unsigned long int c[2] = { ~0UL, ~0UL };
  8. void
  9. bar (int i)
  10. {
  11. #pragma omp task in_reduction (*: b[:3]) in_reduction (&: c[1:]) \
  12. in_reduction (+: a)
  13. {
  14. a += 4;
  15. b[1] *= 4;
  16. c[1] &= ~(1UL << (i + 16));
  17. }
  18. }
  19. void
  20. foo (int x)
  21. {
  22. #pragma omp sections reduction (task, +: a) reduction (task, *: b) \
  23. reduction (task, &: c[1:1])
  24. {
  25. {
  26. a++; b[0] *= 2; bar (2); b[2] *= 3; c[1] &= ~(1UL << 2);
  27. }
  28. #pragma omp section
  29. { b[0] *= 2; bar (4); b[2] *= 3; c[1] &= ~(1UL << 4); a++; }
  30. #pragma omp section
  31. { bar (6); b[2] *= 3; c[1] &= ~(1UL << 6); a++; b[0] *= 2; }
  32. #pragma omp section
  33. { b[2] *= 3; c[1] &= ~(1UL << 8); a++; b[0] *= 2; bar (8); }
  34. #pragma omp section
  35. { c[1] &= ~(1UL << 10); a++; b[0] *= 2; bar (10); b[2] *= 3; }
  36. #pragma omp section
  37. { a++; b[0] *= 2; b[2] *= 3; c[1] &= ~(1UL << 12); bar (12); }
  38. #pragma omp section
  39. if (x)
  40. {
  41. a++; b[0] *= 2; b[2] *= 3; bar (14); c[1] &= ~(1UL << 14);
  42. }
  43. }
  44. }
  45. int
  46. main ()
  47. {
  48. volatile int one = 1;
  49. foo (!one);
  50. if (a != 30 || b[0] != 64 || b[1] != (1 << 12) || b[2] != 3 * 3 * 3 * 3 * 3 * 3
  51. || c[0] != ~0UL || c[1] != ~0x15541554UL)
  52. abort ();
  53. a = 0;
  54. b[0] = 1;
  55. b[1] = 1;
  56. b[2] = 1;
  57. c[1] = ~0UL;
  58. #pragma omp parallel
  59. foo (one);
  60. if (a != 35 || b[0] != 128 || b[1] != (1 << 14) || b[2] != 3 * 3 * 3 * 3 * 3 * 3 * 3
  61. || c[0] != ~0UL || c[1] != ~0x55545554UL)
  62. abort ();
  63. return 0;
  64. }