task-reduction-11.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 (unsigned long long int x, unsigned long long int y, unsigned long long int z)
  21. {
  22. unsigned long long int i;
  23. #pragma omp for schedule(runtime) reduction (task, +: a) \
  24. reduction (task, *: b) reduction (task, &: c[1:1])
  25. for (i = x; i < y; i += z)
  26. {
  27. a++;
  28. b[0] *= 2;
  29. bar (i);
  30. b[2] *= 3;
  31. c[1] &= ~(1UL << i);
  32. }
  33. }
  34. int
  35. main ()
  36. {
  37. volatile int two = 2;
  38. foo (two, 7 * two, two);
  39. if (a != 30 || b[0] != 64 || b[1] != (1 << 12) || b[2] != 3 * 3 * 3 * 3 * 3 * 3
  40. || c[0] != ~0UL || c[1] != ~0x15541554UL)
  41. abort ();
  42. a = 0;
  43. b[0] = 1;
  44. b[1] = 1;
  45. b[2] = 1;
  46. c[1] = ~0UL;
  47. #pragma omp parallel
  48. foo (two, 8 * two, two);
  49. if (a != 35 || b[0] != 128 || b[1] != (1 << 14) || b[2] != 3 * 3 * 3 * 3 * 3 * 3 * 3
  50. || c[0] != ~0UL || c[1] != ~0x55545554UL)
  51. abort ();
  52. return 0;
  53. }