omp-parallel-for.c 347 B

123456789101112131415161718192021
  1. extern void abort (void);
  2. int
  3. main()
  4. {
  5. int i, a;
  6. a = 30;
  7. #pragma omp parallel for firstprivate (a) lastprivate (a) \
  8. num_threads (2) schedule(static)
  9. for (i = 0; i < 10; i++)
  10. a = a + i;
  11. /* The thread that owns the last iteration will have computed
  12. 30 + 5 + 6 + 7 + 8 + 9 = 65. */
  13. if (a != 65)
  14. abort ();
  15. return 0;
  16. }