Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenMP reduction with overloaded operator
    text
    copied!<p>I'm trying to parallelize the loop in the following function with OpenMP</p> <pre><code> void CEnergymulti::forcetwobody(vector&lt;CMolecule*&gt; m_mols,CPnt force0,CPnt torque0) { const int nmol=m_mols.size(); vector&lt;CMolecule*&gt; twomols(2); CPnt forcetemp,torquetemp; twomols.clear(); force0.zero(); torque0.zero(); forcetemp.zero(); torquetemp.zero(); #pragma omp parallel for reduction(+:force0,torque0) private(twomols) for(int j=1;j&lt;nmol;j++) { 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+=forcetemp; torque0+=torquetemp; forcetemp.zero(); torquetemp.zero(); twomols.clear(); } REAL converter=COUL_K*IKbT; force0*=converter; torque0*=converter; return; } </code></pre> <p>When I compile the code, it gives the following message:</p> <pre><code>EnergyD_multi.cpp: In static member function ‘static void CEnergymulti::forcetwobody(std::vector&lt;CMolecule*, std::allocator&lt;CMolecule*&gt; &gt;, CPnt, CPnt)’: EnergyD_multi.cpp:226: error: ‘torque0’ has invalid type for ‘reduction’ EnergyD_multi.cpp:226: error: ‘force0’ has invalid type for ‘reduction’ </code></pre> <p>I understand that variables 'force0' and 'torque0' are neither double or integer type of data, but of type 'CPnt', a class that is defined to represent three-dimensional vectors in space. For class 'CPnt', operator '+' and '-' have already been defined by operator overloading. So my questions is: is it true that reduction in OpenMP cannot handle such overloaded operators? Is there any alternate ways to parallelize this loop with OpenMP without doing reduction on each component of 'force0' and 'torque0'? </p> <p>Thanks a lot.</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