Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's true that OpenMP reduction can't handle such overloaded operators. However, there is an alternative. One way to rewrite a reduction in OpenMP is to use the <code>nowait</code> and <code>atomic</code> paramters. <a href="http://bisqwit.iki.fi/story/howto/openmp/#ReductionClause" rel="nofollow noreferrer">http://bisqwit.iki.fi/story/howto/openmp/#ReductionClause</a> .This is just as fast as the normal way. </p> <p>If you replace <code>atomic</code> with <code>critical</code> you can use more complex overloaded operators. This is not as fast as using <code>atomic</code> but it's still works well in my experience.</p> <p>I did this so I could use operators that operate on 4 or 8 floats at once (with SEE or AVX). <a href="https://stackoverflow.com/questions/15430069/reduction-with-openmp-with-sse-avx">reduction with OpenMP with SSE/AVX</a></p> <p>Edit: I changed your code to reflect what I think would do what you want.</p> <pre><code>void CEnergymulti::forcetwobody(vector&lt;CMolecule*&gt; m_mols,CPnt force0,CPnt torque0) { const int nmol=m_mols.size(); force0.zero(); torque0.zero(); #pragma omp parallel { CPnt force0_private; CPnt torque0_private; force0_private.clear(); torque0_private.clear(); #pragma omp for nowait for(int j=1;j&lt;nmol;j++) { CPnt forcetemp,torquetemp; forcetemp.zero(); torquetemp.zero(); vector&lt;CMolecule*&gt; twomols(2); twomols.clear(); twomols.push_back(m_mols[0]); twomols.push_back(m_mols[j]); CMolecule::polarize_mutual(twomols,false, 1000); twomols[0]-&gt;computeMol_Force_and_Torque(forcetemp,torquetemp); force0_private+=forcetemp; torque0_private+=torquetemp; } #pragma omp critical { force0 += force0_private; torque0 += torque0_private; } } REAL converter=COUL_K*IKbT; force0*=converter; torque0*=converter; return; } </code></pre>
    singulars
    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. 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.
    3. 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