Commit 4c8750ad authored by peastman's avatar peastman
Browse files

More optimizations to CpuCustomGBForce

parent ea435536
...@@ -46,7 +46,7 @@ private: ...@@ -46,7 +46,7 @@ private:
bool periodic; bool periodic;
const CpuNeighborList* neighborList; const CpuNeighborList* neighborList;
float periodicBoxSize[3]; float periodicBoxSize[3];
float cutoffDistance; float cutoffDistance, cutoffDistance2;
const std::vector<std::set<int> > exclusions; const std::vector<std::set<int> > exclusions;
std::vector<std::string> valueNames; std::vector<std::string> valueNames;
std::vector<CustomGBForce::ComputationType> valueTypes; std::vector<CustomGBForce::ComputationType> valueTypes;
......
...@@ -137,6 +137,7 @@ CpuCustomGBForce::~CpuCustomGBForce() { ...@@ -137,6 +137,7 @@ CpuCustomGBForce::~CpuCustomGBForce() {
void CpuCustomGBForce::setUseCutoff(float distance, const CpuNeighborList& neighbors) { void CpuCustomGBForce::setUseCutoff(float distance, const CpuNeighborList& neighbors) {
cutoff = true; cutoff = true;
cutoffDistance = distance; cutoffDistance = distance;
cutoffDistance2 = distance*distance;
neighborList = &neighbors; neighborList = &neighbors;
} }
...@@ -336,9 +337,9 @@ void CpuCustomGBForce::calculateOnePairValue(int index, int atom1, int atom2, Th ...@@ -336,9 +337,9 @@ void CpuCustomGBForce::calculateOnePairValue(int index, int atom1, int atom2, Th
fvec4 pos2(posq+4*atom2); fvec4 pos2(posq+4*atom2);
float r2; float r2;
getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize); getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize);
float r = sqrtf(r2); if (cutoff && r2 >= cutoffDistance2)
if (cutoff && r >= cutoffDistance)
return; return;
float r = sqrtf(r2);
for (int i = 0; i < (int) paramNames.size(); i++) { for (int i = 0; i < (int) paramNames.size(); i++) {
data.expressionSet.setVariable(data.particleParamIndex[i*2], atomParameters[atom1][i]); data.expressionSet.setVariable(data.particleParamIndex[i*2], atomParameters[atom1][i]);
data.expressionSet.setVariable(data.particleParamIndex[i*2+1], atomParameters[atom2][i]); data.expressionSet.setVariable(data.particleParamIndex[i*2+1], atomParameters[atom2][i]);
...@@ -421,9 +422,9 @@ void CpuCustomGBForce::calculateOnePairEnergyTerm(int index, int atom1, int atom ...@@ -421,9 +422,9 @@ void CpuCustomGBForce::calculateOnePairEnergyTerm(int index, int atom1, int atom
fvec4 pos2(posq+4*atom2); fvec4 pos2(posq+4*atom2);
float r2; float r2;
getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize); getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize);
float r = sqrtf(r2); if (cutoff && r2 >= cutoffDistance2)
if (cutoff && r >= cutoffDistance)
return; return;
float r = sqrtf(r2);
// Record variables for evaluating expressions. // Record variables for evaluating expressions.
...@@ -530,16 +531,21 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat ...@@ -530,16 +531,21 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat
fvec4 pos2(posq+4*atom2); fvec4 pos2(posq+4*atom2);
float r2; float r2;
getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize); getDeltaR(pos2, pos1, deltaR, r2, periodic, boxSize, invBoxSize);
float r = sqrtf(r2); if (cutoff && r2 >= cutoffDistance2)
if (cutoff && r >= cutoffDistance)
return; return;
float r = sqrtf(r2);
// Record variables for evaluating expressions. // Record variables for evaluating expressions.
for (int i = 0; i < (int) paramNames.size(); i++) { for (int i = 0; i < (int) paramNames.size(); i++) {
data.expressionSet.setVariable(data.particleParamIndex[i*2], atomParameters[atom1][i]); data.expressionSet.setVariable(data.particleParamIndex[i*2], atomParameters[atom1][i]);
data.expressionSet.setVariable(data.particleParamIndex[i*2+1], atomParameters[atom2][i]); data.expressionSet.setVariable(data.particleParamIndex[i*2+1], atomParameters[atom2][i]);
data.expressionSet.setVariable(data.paramIndex[i], atomParameters[atom1][i]);
} }
data.expressionSet.setVariable(data.valueIndex[0], values[0][atom1]);
data.expressionSet.setVariable(data.xindex, posq[4*atom1]);
data.expressionSet.setVariable(data.yindex, posq[4*atom1+1]);
data.expressionSet.setVariable(data.zindex, posq[4*atom1+2]);
data.expressionSet.setVariable(data.rindex, r); data.expressionSet.setVariable(data.rindex, r);
data.expressionSet.setVariable(data.particleValueIndex[0], values[0][atom1]); data.expressionSet.setVariable(data.particleValueIndex[0], values[0][atom1]);
data.expressionSet.setVariable(data.particleValueIndex[1], values[0][atom2]); data.expressionSet.setVariable(data.particleValueIndex[1], values[0][atom2]);
...@@ -548,20 +554,15 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat ...@@ -548,20 +554,15 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat
float rinv = 1/r; float rinv = 1/r;
deltaR *= rinv; deltaR *= rinv;
fvec4 f1(0.0f), f2(0.0f);
if (!isExcluded || valueTypes[0] != CustomGBForce::ParticlePair) { if (!isExcluded || valueTypes[0] != CustomGBForce::ParticlePair) {
data.dVdR1[0] = (float) data.valueDerivExpressions[0][0].evaluate(); data.dVdR1[0] = (float) data.valueDerivExpressions[0][0].evaluate();
data.dVdR2[0] = -data.dVdR1[0]; data.dVdR2[0] = -data.dVdR1[0];
(fvec4(forces+4*atom1)-deltaR*(dEdV[0][atom1]*data.dVdR1[0])).store(forces+4*atom1); f1 -= deltaR*(dEdV[0][atom1]*data.dVdR1[0]);
(fvec4(forces+4*atom2)-deltaR*(dEdV[0][atom1]*data.dVdR2[0])).store(forces+4*atom2); f2 -= deltaR*(dEdV[0][atom1]*data.dVdR2[0]);
} }
for (int i = 0; i < (int) paramNames.size(); i++)
data.expressionSet.setVariable(data.paramIndex[i], atomParameters[atom1][i]);
data.expressionSet.setVariable(data.valueIndex[0], values[0][atom1]);
for (int i = 1; i < (int) valueNames.size(); i++) { for (int i = 1; i < (int) valueNames.size(); i++) {
data.expressionSet.setVariable(data.valueIndex[i], values[i][atom1]); data.expressionSet.setVariable(data.valueIndex[i], values[i][atom1]);
data.expressionSet.setVariable(data.xindex, posq[4*atom1]);
data.expressionSet.setVariable(data.yindex, posq[4*atom1+1]);
data.expressionSet.setVariable(data.zindex, posq[4*atom1+2]);
data.dVdR1[i] = 0.0; data.dVdR1[i] = 0.0;
data.dVdR2[i] = 0.0; data.dVdR2[i] = 0.0;
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
...@@ -569,9 +570,11 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat ...@@ -569,9 +570,11 @@ void CpuCustomGBForce::calculateOnePairChainRule(int atom1, int atom2, ThreadDat
data.dVdR1[i] += dVdV*data.dVdR1[j]; data.dVdR1[i] += dVdV*data.dVdR1[j];
data.dVdR2[i] += dVdV*data.dVdR2[j]; data.dVdR2[i] += dVdV*data.dVdR2[j];
} }
(fvec4(forces+4*atom1)-deltaR*(dEdV[i][atom1]*data.dVdR1[i])).store(forces+4*atom1); f1 -= deltaR*(dEdV[i][atom1]*data.dVdR1[i]);
(fvec4(forces+4*atom2)-deltaR*(dEdV[i][atom1]*data.dVdR2[i])).store(forces+4*atom2); f2 -= deltaR*(dEdV[i][atom1]*data.dVdR2[i]);
} }
(fvec4(forces+4*atom1)+f1).store(forces+4*atom1);
(fvec4(forces+4*atom2)+f2).store(forces+4*atom2);
} }
void CpuCustomGBForce::getDeltaR(const fvec4& posI, const fvec4& posJ, fvec4& deltaR, float& r2, bool periodic, const fvec4& boxSize, const fvec4& invBoxSize) const { void CpuCustomGBForce::getDeltaR(const fvec4& posI, const fvec4& posJ, fvec4& deltaR, float& r2, bool periodic, const fvec4& boxSize, const fvec4& invBoxSize) const {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment