OpenMP with nested loops

Use this forum to discuss the book: Using OpenMP - Portable Shared Memory Parallel Programming, by Barbara Chapman, Gabriele Jost and Ruud van der Pas Read the viewtopic.php?f=8&t=465 for book info and to download the examples. Post your feedback about the book and examples to this forum

OpenMP with nested loops

Postby ecdogrul » Fri May 23, 2014 2:48 pm

Figure 5.26 on page 150 of the book shows an efficient way of parallelizing the inner loop. I don't understand why this approach does not create nested threads. With the #pragma omp parallel enclosing the entire loop, I would expect that each thread would run its own nested loop and when #pragma omp for is encountered, each thread would further split into multiple threads. Essentially, wouldn't we end up calculating the entire nested loop as many times as the number of threads? I would appreciate any clarification.

Thanks,
John
ecdogrul
 
Posts: 1
Joined: Fri May 23, 2014 2:25 pm

Re: OpenMP with nested loops

Postby MarkB » Tue Jul 21, 2015 2:11 am

Hi John,

Worksharing directives such as #pragma omp for do not create threads: they share work out between the existing threads in the enclosing parallel region.
(Note that #pragma omp parallel for does create threads, as it is just shorthand for #pragma omp parallel followed by #pragma omp for - this is a common source of confusion).

Hope that helps,
Mark.
MarkB
 
Posts: 758
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP - The Book and Examples

Who is online

Users browsing this forum: No registered users and 1 guest