fork download
  1. #include <stdio.h>
  2. #include <omp.h>
  3.  
  4. int main() {
  5. int var = 13;
  6. #pragma omp parallel firstprivate(var)
  7. {
  8. printf("Inside parallel region: var = %d\n", var); // var = 13 for each thread
  9. var = var + 5; // Each thread's private var is modified, but the main var remains unchanged
  10. }
  11. printf("After exiting parallel region: var = %d\n", var); // var = 13 (no changes outside)
  12. return 0;
  13. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Inside parallel region: var = 13
After exiting parallel region: var = 18