task-reduction-1.c 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifdef __cplusplus
  2. extern "C"
  3. #endif
  4. void abort (void);
  5. int a;
  6. long int b = 1;
  7. void
  8. foo (void)
  9. {
  10. int i;
  11. for (i = 0; i < 2; i++)
  12. #pragma omp task in_reduction (+: a) in_reduction (*: b)
  13. {
  14. a += 7;
  15. b *= 2;
  16. }
  17. }
  18. int
  19. main ()
  20. {
  21. int c = 0;
  22. #pragma omp parallel
  23. #pragma omp single
  24. {
  25. long int d = 1;
  26. #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
  27. {
  28. int i;
  29. for (i = 0; i < 4; i++)
  30. #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
  31. {
  32. int j;
  33. a += 7;
  34. b *= 2;
  35. for (j = 0; j < 2; j++)
  36. #pragma omp task in_reduction (+: a, c) in_reduction (*: b, d)
  37. {
  38. a += 7;
  39. b *= 2;
  40. c += 9;
  41. d *= 3;
  42. foo ();
  43. }
  44. c += 9;
  45. d *= 3;
  46. }
  47. }
  48. #define THREEP4 (3L * 3L * 3L * 3L)
  49. if (d != (THREEP4 * THREEP4 * THREEP4))
  50. abort ();
  51. }
  52. if (a != 28 * 7 || b != (1L << 28) || c != 12 * 9)
  53. abort ();
  54. return 0;
  55. }