the order of thread runing on for loop

General OpenMP discussion

the order of thread runing on for loop

Postby cluster » Mon Jan 14, 2008 2:27 am

hi all,
I would like to know that when we use
omp_set_num_threads(4);
#pragma omp for schedule(static,2)
for(i=0;i<8;i++)
. ......
thread id is sure or not sure to be as below

i =0 --> thread id =0
i =1 --> thread id =0
i =2 --> thread id =1
i =3 --> thread id =1
i =4 --> thread id =2
i =5 --> thread id =2
i =6 --> thread id =3
i =7 --> thread id =3

or it maybe as below

i =0 --> thread id =3
i =1 --> thread id =3
i =2 --> thread id =1
i =3 --> thread id =1
i =4 --> thread id =2
i =5 --> thread id =2
i =6 --> thread id =0
i =7 --> thread id =0

*** can it chang the oder of thread to execute on the loop ?

thanks so much,
diakala
cluster
 

Re: the order of thread runing on for loop

Postby lfm » Wed Feb 06, 2008 11:32 am

For a loop with 8 iterations and schedule static,2 the loop is divided into 4 chunks of 2 each, and the chunks are assigned to threads in order, so with 4 threads you are guaranteed:
thread 0 iterations 0,1
thread 1 iterations 2,3
thread 2 iterations 4,5
thread 3 iterations 6,7

I hope this answers your question.


Last bumped by Anonymous on Wed Feb 06, 2008 11:32 am.
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 4 guests