Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look with this:</p> <pre><code>for(int x = 0; x &lt; 4; ++x) #pragma omp parallel for ordered for(int y = 0; y &lt; 4; ++y) #pragma omp ordered cout &lt;&lt; x &lt;&lt; ',' &lt;&lt; y &lt;&lt; " (by thread " &lt;&lt; omp_get_thread_num() &lt;&lt; ')' &lt;&lt; endl; </code></pre> <p>you have:</p> <pre><code>0,0 (by thread 0) 0,1 (by thread 1) 0,2 (by thread 2) 0,3 (by thread 3) 1,0 (by thread 0) 1,1 (by thread 1) 1,2 (by thread 2) 1,3 (by thread 3) </code></pre> <p>Each thread just has to wait for some <code>cout</code> all the work before can be done in parallel. But with:</p> <pre><code>#pragma omp parallel for ordered for(int x = 0; x &lt; 4; ++x) for(int y = 0; y &lt; 4; ++y) #pragma omp ordered cout &lt;&lt; x &lt;&lt; ',' &lt;&lt; y &lt;&lt; " (by thread " &lt;&lt; omp_get_thread_num() &lt;&lt; ')' &lt;&lt; endl; </code></pre> <p>and</p> <pre><code>#pragma omp parallel for collapse(2) ordered for(int x = 0; x &lt; 4; ++x) for(int y = 0; y &lt; 4; ++y) #pragma omp ordered cout &lt;&lt; x &lt;&lt; ',' &lt;&lt; y &lt;&lt; " (by thread " &lt;&lt; omp_get_thread_num() &lt;&lt; ')' &lt;&lt; endl; </code></pre> <p>the situations is:</p> <pre><code>0,0 (by thread 0) 0,1 (by thread 0) 0,2 (by thread 0) 0,3 (by thread 0) 1,0 (by thread 1) 1,1 (by thread 1) 1,2 (by thread 1) 1,3 (by thread 1) 2,0 (by thread 2) 2,1 (by thread 2) 2,2 (by thread 2) 2,3 (by thread 2) 3,0 (by thread 3) 3,1 (by thread 3) 3,2 (by thread 3) 3,3 (by thread 3) </code></pre> <p>So <code>thread 1</code> has to wait for <code>thread 0</code> to finish all its work, before it can <code>cout</code> the first time, and nearly nothing can be done in parallel.</p> <p>Try adding <code>schedule(static,1)</code> to the collapse-version and it should perform at least as good as the first version does.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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