pr36802-2.c 779 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* PR middle-end/36802 */
  2. extern void abort (void);
  3. extern int omp_set_dynamic (int);
  4. extern void omp_set_nested (int);
  5. extern int omp_get_num_threads (void);
  6. int q;
  7. int
  8. foo (int k)
  9. {
  10. int i = 6, n = 0;
  11. omp_set_dynamic (0);
  12. omp_set_nested (1);
  13. #pragma omp parallel shared (i) num_threads (3)
  14. {
  15. int l;
  16. if (omp_get_num_threads () != 3)
  17. #pragma omp atomic
  18. n += 1;
  19. else
  20. #pragma omp for
  21. for (l = 0; l < 3; l++)
  22. if (k)
  23. #pragma omp atomic
  24. q += i;
  25. else
  26. #pragma omp parallel shared (i) num_threads (4)
  27. {
  28. if (omp_get_num_threads () != 4)
  29. #pragma omp atomic
  30. n += 1;
  31. #pragma omp critical
  32. i += 1;
  33. }
  34. }
  35. if (n == 0 && i != 6 + 3 * 4)
  36. abort ();
  37. return 0;
  38. }
  39. int
  40. main (void)
  41. {
  42. foo (0);
  43. return 0;
  44. }