[Omp] About iteration determination for #omp for

Diego Novillo dnovillo at redhat.com
Sat Nov 12 09:37:00 PST 2005


On Saturday 12 November 2005 12:18, NovaElf wrote:

> Does each thread do some calculation to find out which slices of the
> iterations it should be taking? Since the calculation can only be done
> on entry to the #omp for construct, and there is no barrier on entry,
> any thread can arrive first, so it seems impossible for one thread to be
> handling that job.
>
The computations depend on what type of scheduling you selected.  For 
static scheduling, the iteration space for each thread will be the same 
regardless of what thread gets there first.  For the dynamic, runtime 
schedule, the library will naturally synchronize the threads as they 
request more iterations to perform.

> A second question is, the #omp for loop has some loop invariant
> restrictions. However, if I purposely violate those restrictions, will
> it result in compile time error or will it only result in incorrect
> execution?
>
Implementation defined.  In some cases, it will do what you expect, in 
others it will abort.  Some compilers may even emit a warning or error.  
In GCC, we try to diagnose some invalid uses, but not all.




More information about the Omp mailing list