Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a few comments that you might find useful.</p> <p>In general I try to avoid accessing the thread number directly (thread_id). Instead of defining arrays with a size equal to the number of threads you should define your variables in the parallel block (this automatically makes them private). Then instead of looping over the number of threads after the parallel block you should use an atomic, critical, or single approach (I'm not sure which is best here). Something like this.</p> <pre><code>Point* farthestPoint; //int distance = *distance_sub[0]; //is this a bug shouldn't distance be a double? double distance = 0 #pragma omp parallel private { Point farthest_sub = input[0]; double distance_sub = 0; #pragma omp for nowait for (int index = 1; index &lt; input.size(); index++){ // for loop code } #pragma omp critical { if (distance &lt; distance_sub){ farthestPoint = farthest_sub; } } #pragma omp barrier //next part of code } </code></pre> <p>One problem you might have now is false sharing. Each thread is trying to write to arrays in the same cache line (e.g. in the array distance_sub[num_threads]). I'm not sure what OpenMP does when you declare the values inside the the parallel block but I suspect that it's more likely to allocate the values to avoid false sharing.</p> <p>Another comment you, should try and avoid calling OpenMP so many times, especially on a small number of elements. There is an overhead with OpenMP. I would try and get as much in one parallel block as possible using a barrier or whatever.</p> <p>Also, in your code you have <code>int distance = *distance_sub[0]</code> is this a bug? Shouldn't distance be a double?</p> <p>Lastly, a pedantic point. I doubt you have 8 cores. You probably have 4 cores and 8 hardware threads due to Intel hyper threading. The distinction can be important.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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