我正在尝试使用OpenMP并行化下面函数中的循环。
当我编译代码时,会出现以下提示信息:
我知道变量'force0'和'torque0'不是double或integer类型的数据,而是'CPnt'类型。'CPnt'是一个表示三维向量的类。对于类'CPnt',操作符'+'和'-'已经被重载定义了。因此,我的问题是:OpenMP中的reduction能否处理这样的重载操作符?有没有其他方法在OpenMP中并行化这个循环,而不是对'force0'和'torque0'的每个分量都进行reduction?
非常感谢。
void CEnergymulti::forcetwobody(vector<CMolecule*> m_mols,CPnt force0,CPnt torque0)
{
const int nmol=m_mols.size();
vector<CMolecule*> 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<nmol;j++)
{ twomols.push_back(m_mols[0]);
twomols.push_back(m_mols[j]);
CMolecule::polarize_mutual(twomols,false, 1000);
twomols[0]->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;
}
当我编译代码时,会出现以下提示信息:
EnergyD_multi.cpp: In static member function ‘static void
CEnergymulti::forcetwobody(std::vector<CMolecule*,
std::allocator<CMolecule*> >, CPnt, CPnt)’: EnergyD_multi.cpp:226:
error: ‘torque0’ has invalid type for ‘reduction’
EnergyD_multi.cpp:226: error: ‘force0’ has invalid type for
‘reduction’
我知道变量'force0'和'torque0'不是double或integer类型的数据,而是'CPnt'类型。'CPnt'是一个表示三维向量的类。对于类'CPnt',操作符'+'和'-'已经被重载定义了。因此,我的问题是:OpenMP中的reduction能否处理这样的重载操作符?有没有其他方法在OpenMP中并行化这个循环,而不是对'force0'和'torque0'的每个分量都进行reduction?
非常感谢。