Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecific thread order in C using GCC and OMP
    text
    copied!<p>I need to make 4 teams with 4 threads each one with contiguous processors. </p> <p>The result I'm expecting is, for example:</p> <pre><code>Team 0 Thread 0 Processor: 0 Team 0 Thread 1 Processor: 1 Team 0 Thread 2 Processor: 2 Team 0 Thread 3 Processor: 3 Team 1 Thread 0 Processor: 4 Team 1 Thread 1 Processor: 5 Team 1 Thread 2 Processor: 6 Team 1 Thread 3 Processor: 7 Team 2 Thread 0 Processor: 8 Team 2 Thread 1 Processor: 9 Team 2 Thread 2 Processor: 10 Team 2 Thread 3 Processor: 11 Team 3 Thread 0 Processor: 12 Team 3 Thread 1 Processor: 13 Team 3 Thread 2 Processor: 14 Team 3 Thread 3 Processor: 15 </code></pre> <p>I can handle Processor Affinity in GCC using the GOMP_CPU_AFFINITY variable.</p> <p>I'm using:</p> <pre><code>#pragma omp parallel num_threads(4) </code></pre> <p>twice in order to get 2 fork levels.</p> <p>At the moment I'm having this order in GOMP_CPU_AFFINITY:</p> <pre><code>0 4 8 12 1 2 3 5 6 7 9 10 11 13 14 15 </code></pre> <p>So the first fork, the "fathers fork", gets:</p> <pre><code>Team 0 Thread 0 Processor: 0 Team 1 Thread 0 Processor: 4 Team 2 Thread 0 Processor: 8 Team 3 Thread 0 Processor: 12 </code></pre> <p>The problem I'm having is that the second group of forks make without any order so, for example I could have this situation (I'm using #pragma omp atomic so only one 'father' can ask for more processors at any time):</p> <pre><code>Team 0 Thread 0 Processor: 0 Team 0 Thread 1 Processor: 5 Team 0 Thread 2 Processor: 6 Team 0 Thread 3 Processor: 7 Team 1 Thread 0 Processor: 4 Team 1 Thread 1 Processor: 13 Team 1 Thread 2 Processor: 14 Team 1 Thread 3 Processor: 15 Team 2 Thread 0 Processor: 8 Team 2 Thread 1 Processor: 1 Team 2 Thread 2 Processor: 2 Team 2 Thread 3 Processor: 3 Team 3 Thread 0 Processor: 12 Team 3 Thread 1 Processor: 9 Team 3 Thread 2 Processor: 10 Team 3 Thread 3 Processor: 11 </code></pre> <p>The question is: Is there any way to make this second petition in order? </p> <p>I think I would have to make some sinchronization method with locks or something... </p> <p>Thanks in advance!</p> <ul> <li>Javier</li> </ul>
 

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