depend-2.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. void
  4. foo (int do_sleep)
  5. {
  6. int a[64], i, *p = a + 4, x = 0;
  7. asm volatile ("" : "+r" (p));
  8. for (i = 0; i < 64; i++)
  9. a[i] = i + 8;
  10. #pragma omp parallel private (i)
  11. {
  12. #pragma omp single nowait
  13. {
  14. for (i = 0; i < 8; i++)
  15. {
  16. #pragma omp task depend(out: a[i * 8 : 4])
  17. a[i * 8] += (i + 2) * 9;
  18. #pragma omp task depend(out: p[i * 8 : 2])
  19. p[i * 8] += (i + 3) * 10;
  20. #pragma omp task depend(out: x)
  21. x = 1;
  22. }
  23. for (i = 0; i < 8; i++)
  24. #pragma omp task depend(in: a[i * 8 : 4]) \
  25. depend(inout: a[i * 8 + 4 : 2]) \
  26. depend(in: a[0 : 4]) depend(in: x)
  27. {
  28. if (a[0] != 8 + 2 * 9 || x != 1)
  29. abort ();
  30. if (a[i * 8] != i * 8 + 8 + (i + 2) * 9)
  31. abort ();
  32. if (a[4 + i * 8] != 4 + i * 8 + 8 + (i + 3) * 10)
  33. abort ();
  34. p[i * 8] += a[i * 8];
  35. }
  36. for (i = 0; i < 8; i++)
  37. #pragma omp task depend(inout: a[i * 8 : 4]) \
  38. depend(in: p[i * 8 : 2]) \
  39. depend(in: p[0 : 2], x)
  40. {
  41. if (p[0] != 4 + 8 + 3 * 10 + 0 + 8 + 2 * 9 || x != 1)
  42. abort ();
  43. if (a[i * 8] != i * 8 + 8 + (i + 2) * 9)
  44. abort ();
  45. if (a[4 + i * 8] != (4 + i * 8 + 8 + (i + 3) * 10
  46. + i * 8 + 8 + (i + 2) * 9))
  47. abort ();
  48. a[i * 8] += 2;
  49. }
  50. for (i = 0; i < 4; i++)
  51. #pragma omp task depend(in: a[i * 16 : 4], a[i * 16 + 8 : 4], x)
  52. {
  53. if (a[i * 16] != i * 16 + 8 + (2 * i + 2) * 9 + 2 || x != 1)
  54. abort ();
  55. if (p[i * 16 + 4] != i * 16 + 8 + 8 + (2 * i + 1 + 2) * 9 + 2)
  56. abort ();
  57. }
  58. }
  59. if (do_sleep)
  60. sleep (1);
  61. }
  62. }
  63. int
  64. main ()
  65. {
  66. foo (1);
  67. foo (0);
  68. return 0;
  69. }