reduction-15.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. extern void abort (void);
  2. int a[16], b[16], c[16], d[5][2];
  3. __attribute__((noinline, noclone)) void
  4. foo (int x, int y)
  5. {
  6. int i;
  7. #pragma omp for schedule (static, 1) reduction (+:a[:3])
  8. for (i = 0; i < 64; i++)
  9. {
  10. a[0] += i;
  11. a[1] += 2 * i;
  12. a[2] += 3 * i;
  13. }
  14. #pragma omp for schedule (guided) reduction (+:b[4:3])
  15. for (i = 0; i < 64; i++)
  16. {
  17. b[4] += i;
  18. b[5] += 2 * i;
  19. b[6] += 3 * i;
  20. }
  21. #pragma omp for schedule (static) reduction (+:c[x:4])
  22. for (i = 0; i < 64; i++)
  23. {
  24. c[9] += i;
  25. c[10] += 2 * i;
  26. c[11] += 3 * i;
  27. c[12] += 4 * i;
  28. }
  29. #pragma omp for reduction (+:d[x - 8:2][y:])
  30. for (i = 0; i < 64; i++)
  31. {
  32. d[1][0] += i;
  33. d[1][1] += 2 * i;
  34. d[2][0] += 3 * i;
  35. d[2][1] += 4 * i;
  36. }
  37. }
  38. int
  39. main ()
  40. {
  41. int i;
  42. #pragma omp parallel
  43. foo (9, 0);
  44. for (i = 0; i < 16; i++)
  45. if (a[i] != (i < 3 ? 64 * 63 / 2 * (i + 1) : 0)
  46. || b[i] != ((i >= 4 && i < 7) ? 64 * 63 / 2 * (i - 3) : 0)
  47. || c[i] != ((i >= 9 && i < 13) ? 64 * 63 / 2 * (i - 8) : 0))
  48. abort ();
  49. for (i = 0; i < 5; i++)
  50. if (d[i][0] != ((i && i <= 2) ? 64 * 63 / 2 * (2 * i - 1) : 0)
  51. || d[i][1] != ((i && i <= 2) ? 64 * 63 / 2 * (2 * i) : 0))
  52. abort ();
  53. return 0;
  54. }