pr81778.c 954 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Minimized from for-5.c. */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. /* Size of array we want to write. */
  5. #define N 32
  6. /* Size of extra space before and after. */
  7. #define CANARY_SIZE (N * 32)
  8. /* Start of array we want to write. */
  9. #define BASE (CANARY_SIZE)
  10. // Total size to be allocated.
  11. #define ALLOC_SIZE (CANARY_SIZE + N + CANARY_SIZE)
  12. #pragma omp declare target
  13. int a[ALLOC_SIZE];
  14. #pragma omp end declare target
  15. int
  16. main (void)
  17. {
  18. /* Use variable step in for loop. */
  19. int s = 1;
  20. #pragma omp target update to(a)
  21. /* Write a[BASE] .. a[BASE + N - 1]. */
  22. #pragma omp target simd
  23. for (int i = N - 1; i > -1; i -= s)
  24. a[BASE + i] = 1;
  25. #pragma omp target update from(a)
  26. for (int i = 0; i < ALLOC_SIZE; i++)
  27. {
  28. int expected = (BASE <= i && i < BASE + N) ? 1 : 0;
  29. if (a[i] == expected)
  30. continue;
  31. printf ("Expected %d, got %d at base[%d]\n", expected, a[i], i - BASE);
  32. abort ();
  33. }
  34. return 0;
  35. }