More on Parallel for loop

  • The number of loop iterations cannot be non-deterministic; break, return, exit, goto not allowed inside the for-loop
  • The loop index is private to each thread
  • A reduction variable is special
    • During the for-loop there is a local private copy in each thread
    • At the end of the for-loop, all the local copies are combined together by the reduction operation
  • Unless the nowait clause is used, an implicit barrier synchronization will be added at the end by the compiler
// #pragma omp parallel and #pragma omp for

can be combined into

#pragma omp parallel for