Search code examples
cloopsparallel-processingopenmp

Can "#pragma omp parallel for " be used inside a loop?


Can "#pragma omp parallel for" be used inside a loop in the following form:

For (i=0;i<...;.i+=1) 
  { #pragma omp parallel for
      for(j=0;j<...;j+=1) 
       { Some code.....} 
  • Will this just parralelize the loop on 'j' ?

Thanks on advence !


Solution

  • Yes, it can be used like that. But compiler directives have to be on a line of their own

    for( ... )
    {
        #pragma omp parallel for
        for( ...
    //..
    

    Also, this will indeed only execute the inner loop in parallel. If you need both loops to execute in parallel you need a second #pragma omp parallel for above the outer loop.