shared-2.C 662 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extern "C" void abort (void);
  2. void
  3. parallel (int a, int b)
  4. {
  5. int bad, LASTPRIV, LASTPRIV_SEC;
  6. int i;
  7. a = b = 3;
  8. bad = 0;
  9. #pragma omp parallel firstprivate (a,b) shared (bad) num_threads (5)
  10. {
  11. if (a != 3 || b != 3)
  12. bad = 1;
  13. #pragma omp for lastprivate (LASTPRIV)
  14. for (i = 0; i < 10; i++)
  15. LASTPRIV = i;
  16. #pragma omp sections lastprivate (LASTPRIV_SEC)
  17. {
  18. #pragma omp section
  19. { LASTPRIV_SEC = 3; }
  20. #pragma omp section
  21. { LASTPRIV_SEC = 42; }
  22. }
  23. }
  24. if (LASTPRIV != 9)
  25. abort ();
  26. if (LASTPRIV_SEC != 42)
  27. abort ();
  28. if (bad)
  29. abort ();
  30. }
  31. int main()
  32. {
  33. parallel (1, 2);
  34. return 0;
  35. }