Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are 4 types of OMP scheduling. They are static, dynamic, runtime and guided. Each scheduling has its advantages. The scheduling is present for better load balancing among the threads.</p> <p>I will give you some example for static and dynamic scheduling. It is similar for the guided as well.</p> <p>The schedule(runtime) clause tells it to set the schedule using the environment variable. The environment variable can be set to any other scheduling type. It can be set by</p> <pre><code>setenv OMP_SCHEDULE “dynamic,5” </code></pre> <p><strong>Static Scheduling</strong></p> <p>Static scheduling is used when you know that each thread will more-or-less do same amount of work at the compile time. </p> <p>For example, the following code can be parallelized using OMP. Let assume that we use only 4 threads. </p> <p>If we are using the default static scheduling and place pragma on the outer for loop, then each thread will do 25% of the outer loop (<em>i</em>) work and eqaul amount of inner loop (<em>j</em>) work Hence, the total amount of work done by each thread is same. Hence, we could simply stick with the default static scheduling to give optimal load balancing.</p> <pre><code>float A[100][100]; for(int i = 0; i &lt; 100; i++) { for(int j = 0; j &lt; 100; j++) { A[i][j] = 1.0f; } } </code></pre> <p><strong>Dynamic Scheduling</strong></p> <p>Dynamic scheduling is used when you know that each thread won't do same amount of work by using static scheduling. </p> <p>Whereas, in this following code, </p> <pre><code>float A[100][100]; for(int i = 0; i &lt; 100; i++) { for(int j = 0; j &lt; i; j++) { A[i][j] = 1.0f; } } </code></pre> <p>The inner loop variable <em>j</em> is dependent on the <em>i</em>. If you use the default static scheduling, the outer loop (<em>i</em>) work might be divided equally between the 4 threads, but the inner loop (<em>j</em>) work will be large for some threads. This means that each thread won't do equal amount of work with static scheduling. Static scheduling won't result in optimal load balancing between threads. Hence we switch to dynamic scheduling (scheduling is done at the run time). This way you can make sure that the code achieves optimal load balance.</p> <p>Note: you can also specify the chunk_size for scheduling. It depends on the loop size.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload