Link Copied
[cpp]void compute() { // heavy computations } void func() { // in order for this to initiate // a parallel region nested must be enabled // SET OMP_NESTED=TRUE // .or. // omp_set_nested(1); // // when nested disabled, this runs serial // for each of the 2 threads calling func // 4 x compute() using 2 threads. // when nested enabled (read comments inside block) // #pragma omp parallel { // each of 2 threads calling func() picks up // additional threads here // 7 or less depending on options #pragma omp sections { // however you only have 2 sections #pragma omp section compute(); // 1 thread of each team #pragma omp section compute(); // different 1 thread of each team } } } // end result 4 x compute() using 4 threads (when nested enabled) // int main() { #pragma omp parallel { // 8 threads falling through this comment // (assuming OMP_NUM_THREADS 8) #pragma omp sections { #pragma omp section func(); // one of the 8 threads makes this call #pragma omp section func(); // different one the 8 threads makes this call } // the other 6 threads branch around to here } } [/cpp]
Jim Dempsey
[cpp]void compute() { // heavy computations } void func() { // in order for this to initiate // a parallel region nested must be enabled // SET OMP_NESTED=TRUE // .or. // omp_set_nested(1); // // when nested disabled, this runs serial // for each of the 2 threads calling func // 4 x compute() using 2 threads. // when nested enabled (read comments inside block) // #pragma omp parallel { // each of 2 threads calling func() picks up // additional threads here // 7 or less depending on options #pragma omp sections { // however you only have 2 sections #pragma omp section compute(); // 1 thread of each team #pragma omp section compute(); // different 1 thread of each team } } } // end result 4 x compute() using 4 threads (when nested enabled) // int main() { #pragma omp parallel { // 8 threads falling through this comment // (assuming OMP_NUM_THREADS 8) #pragma omp sections { #pragma omp section func(); // one of the 8 threads makes this call #pragma omp section func(); // different one the 8 threads makes this call } // the other 6 threads branch around to here } } [/cpp]
Jim Dempsey
For more complete information about compiler optimizations, see our Optimization Notice.