copyin-3.c 653 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* { dg-do run } */
  2. /* { dg-options "-O2" } */
  3. /* { dg-require-effective-target tls_runtime } */
  4. #include <omp.h>
  5. #include <stdlib.h>
  6. int thr;
  7. #pragma omp threadprivate (thr)
  8. int
  9. test (int l)
  10. {
  11. return l || (thr != omp_get_thread_num () * 2);
  12. }
  13. int
  14. main (void)
  15. {
  16. int l = 0;
  17. omp_set_dynamic (0);
  18. omp_set_num_threads (6);
  19. thr = 8;
  20. /* Broadcast the value to all threads. */
  21. #pragma omp parallel copyin (thr)
  22. ;
  23. #pragma omp parallel reduction (||:l)
  24. {
  25. /* Now test if the broadcast succeeded. */
  26. l = thr != 8;
  27. thr = omp_get_thread_num () * 2;
  28. #pragma omp barrier
  29. l = test (l);
  30. }
  31. if (l)
  32. abort ();
  33. return 0;
  34. }