LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Open MP question

Solved!
Go to solution

Hello,

 

everything is fine, just a question out of curiosity: Smiley Happy

 

using

 

#pragma omp for

 

before a for loop specifies that the iterations of the associated loop will be executed in parallel.

 

My question: Let's assume I have a loop with 10000 iterations and two threads will be generated; will thread one calculate the first 5000 iterations while the second starts at index 5000, or will they operate on odd/even indices, or is it random, or....

 

Thanks!

0 Kudos
Message 1 of 8
(5,959 Views)

Hi Wolfgang,

 

omp for and omp do divide loop iterations (if possible) equally among all threads.

If you exactly want to know, how your loop works, look in the DLL to find out these informations.

 

Bye,

 

Elisa

0 Kudos
Message 2 of 8
(5,910 Views)

Of course I meant the documentation of your DLL.

0 Kudos
Message 3 of 8
(5,906 Views)

ah, so now I am confused...

 

I am writing a program with CVI, adding first steps of MP, so what documentation are you referring to?

0 Kudos
Message 4 of 8
(5,901 Views)

CVI is an developement environment and you use OpenMP as an extern programming language, so I am refering to the documentation of your DLL from OpenMP.

 

Maybe the following link is useful for you, look at the example-code:

http://de.wikipedia.org/wiki/OpenMP

 

Bye,

Elisa

0 Kudos
Message 5 of 8
(5,891 Views)

Hello Elisa,

 

neither Wikipedia nor CVI help address my question (not even the OpenMP Application Program Interface specification), I checked them all before posting Smiley Wink

 

Nevermind, it's an academic question not affecting my project

0 Kudos
Message 6 of 8
(5,885 Views)
Solution
Accepted by Wolfgang

Hi,

 

If you don't specify a schedule using the schedule clause, the default is the static schedule, where the loop iterations are divided into almost equal sizes amongst the threads. So in your example, one thread will execute loop iterations 0 - 4999 and the second thread will execute iterations 5000-9999.  You can always see which thread is executing which iteration by something like this:

 

#omp parallel for
for (int i = 0; i < 10000; i++)
   printf ("Iteration %d executed by thread %d", i, omp_get_thread_num())

Each thread in the parallel region is given an id, with the 'master' thread having id 0. This is returned by omp_get_thread_num(). In the above case the 'chunk size' is 5000.  You can change this by specifying the schedule(static, chuncksize) clause:

 

#omp parallel for schedule (static, 1000)
for (int i = 0; i < 10000; i++)
   printf ("Iteration %d executed by thread %d", i, omp_get_thread_num())

Here, each thread will execute 1000 loop iterations, then pick up the next available 'chunk' of 1000 iterations and so on until all loop iteations are executed.

 

You can also specify dynamic and guided schedules which are useful when the loop iterations are not load balanced. See section 2.5.1 of the OpenMP 2.5 specifcation for more details.

Message 7 of 8
(5,872 Views)

Thanks!

 

Sounds like I could have found out myself Smiley Wink

0 Kudos
Message 8 of 8
(5,865 Views)