[Omp] Subroutines inside parallel block

Ruud van der Pas Ruud.Vanderpas at Sun.COM
Tue Apr 12 19:00:38 PDT 2005


Hi Patricia,

I assume you use it like this:

#pragma omp parallel
{
       <some other code>

  #pragma omp for
     for (i=0; i<n; i++)
     {
        sort();
     }
}

When the threads encouter the "omp for", they will each handle
a subset out of the total number of iterations to be done, but
there will never be more than 5 calls to "sort" going on in
parallel (assuming you're using 5 threads).

There won't be additional threads created if "sort" does not
contain another parallel region. This is the so-called nested
parallelism; a feature that may or may not be supported by an
OpenMP implementation.

I hope this helps clarifying the situation.

Kind regards,
Ruud
----------------------------------------------------------------
Senior Staff Engineer             Email: ruud.vanderpas at sun.com
Scalable Systems Group            Phone: +31-33-4515000 (x15920)
Sun Microsystems                  Fax  : +31-33-4515001
----------------------------------------------------------------

>   Hello,
> 
>      I'm trying to parallelize a block of code where a
> call to a subroutine appears inside of it. However I
> wonder what really happens when there is a dynamic
> extension (a subroutine inside a parallel region). I
> don't know if the subroutine is executed in parallel.
> And , if does so, wich threads participate on the
> execution of it? Perhaps as soon as entering at the
> subroutine, another group of threads is created.
>      Assuming the particular case where I have
> something of this kind:
> 
> #pragma omp for
>    for (i=0; i<n; i++)
>    {
>       sort();    
>    }
>       In this case, when each thread (let's to say 5
> in total) invoque the sort routine, it's create
> anouther group of threads so as to execute sort for
> each one?
> 
>   I appreciate your help,
> 
> Patricia B. Sampaio
> ------------------------------------
> Federal University of Rio de Janeiro
> 
> 
> 	
> 	
> 		
> Yahoo! Acesso Grátis - Internet rápida e grátis. 
> Instale o discador agora! http://br.acesso.yahoo.com/
> 
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org




More information about the Omp mailing list