Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between static and dynamic schedule in OpenMP in C

Tags:

c

openmp

I've got two similar codes.

First

#pragma omp parallel for shared(g) private(i) schedule(dynamic, 1)
for(i = (*g).actualNumberOfChromosomes; i < (*g).maxNumberOfChromosomes; i++)
{
    AddCrossoverChromosome(g, i); // it doesnt change actualNumberOfChromosomes
    #pragma omp atomic
    (*g).actualNumberOfChromosomes++;
}

Second

#pragma omp parallel for shared(g) private(i) schedule(static, 1)
for(i = (*g).actualNumberOfChromosomes; i < (*g).maxNumberOfChromosomes; i++)
{
    AddCrossoverChromosome(g, i); // it doesnt change actualNumberOfChromosomes
    #pragma omp atomic
    (*g).actualNumberOfChromosomes++;
}

The only difference is in the first line. First code works fine, but the second one crashes. Why?

Problem is somewhere in actualNumberOfChromosomes, but I would like to understand why, and not just solve this. I could solve this by creating addition variable p and assigning actualNumberOfChromosomes to it and changing the loop so that i was equal to p.

like image 217
Tomek Tarczynski Avatar asked Nov 23 '10 21:11

Tomek Tarczynski


People also ask

What is the difference between static and dynamic scheduling?

A fundamental distinction is made between static and dynamic scheduling. Static schedules are fixed before execution based on the information available at that time, whereas dynamic schedules are determined during runtime.

What is Dynamic scheduling in OpenMP?

Dynamic. The schedule(dynamic, chunk-size) clause of the loop construct specifies that the for loop has the dynamic scheduling type. OpenMP divides the iterations into chunks of size chunk-size . Each thread executes a chunk of iterations and then requests another chunk until there are no more chunks available.

What is schedule static?

The static schedule is characterized by the properties that each thread gets approximately the same number of iterations as any other thread, and each thread can independently determine the iterations assigned to it.

What is Dynamic scheduling?

Dynamic scheduling involves using clever software to manage your field workforce and their workflows, taking into consideration business objectives, staff availability, skills and day-to-day disruptive occurrences. The solution makes the scheduling decisions for you.


1 Answers

The difference between static schedule type and dynamic schedule type is that with static the chunks can be pre-computed as well as decided how to scheduled to threads during compilation itself, whereas with dynamic the same thing is done during run-time.

With the usage of dynamic, it involves some complex mechanisms like deadlock handling mechanism, load handling, etc.

You can get some more info at: http://openmp.blogspot.com.

like image 196
anshu Avatar answered Oct 09 '22 07:10

anshu