Commit ea435536 authored by peastman's avatar peastman
Browse files

Very minor optimization to CpuCustomGBForce

parent 6a4ac837
......@@ -70,18 +70,6 @@ private:
* This routine contains the code executed by each thread.
*/
void threadComputeForce(ThreadPool& threads, int threadIndex);
/**
* Calculate a computed value of type SingleParticle
*
* @param index the index of the value to compute
* @param data workspace for the current thread
* @param numAtoms number of atoms
* @param posq atom coordinates
* @param atomParameters atomParameters[atomIndex][paramterIndex]
*/
void calculateSingleParticleValue(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters);
/**
* Calculate a computed value that is based on particle pairs
......
......@@ -231,20 +231,24 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
calculateParticlePairValue(0, data, numberOfAtoms, posq, atomParameters, false, boxSize, invBoxSize);
threads.syncThreads();
// Sum the first computed value.
// Sum the first computed value and calculate the remaining ones.
int numValues = valueTypes.size();
for (int atom = data.firstAtom; atom < data.lastAtom; atom++) {
float sum = 0.0f;
for (int j = 0; j < (int) threadData.size(); j++)
sum += threadData[j]->value0[atom];
values[0][atom] = sum;
data.expressionSet.setVariable(data.xindex, posq[4*atom]);
data.expressionSet.setVariable(data.yindex, posq[4*atom+1]);
data.expressionSet.setVariable(data.zindex, posq[4*atom+2]);
for (int j = 0; j < (int) paramNames.size(); j++)
data.expressionSet.setVariable(data.paramIndex[j], atomParameters[atom][j]);
for (int i = 1; i < numValues; i++) {
data.expressionSet.setVariable(data.valueIndex[i-1], values[i-1][atom]);
values[i][atom] = (float) data.valueExpressions[i].evaluate();
}
}
// Calculate the remaining computed values.
int numValues = valueTypes.size();
for (int i = 1; i < numValues; i++)
calculateSingleParticleValue(i, data, numberOfAtoms, posq, atomParameters);
threads.syncThreads();
// Now calculate the energy and its derivatives.
......@@ -279,19 +283,6 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
calculateChainRuleForces(data, numberOfAtoms, posq, atomParameters, forces, boxSize, invBoxSize);
}
void CpuCustomGBForce::calculateSingleParticleValue(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters) {
for (int i = data.firstAtom; i < data.lastAtom; i++) {
data.expressionSet.setVariable(data.xindex, posq[4*i]);
data.expressionSet.setVariable(data.yindex, posq[4*i+1]);
data.expressionSet.setVariable(data.zindex, posq[4*i+2]);
for (int j = 0; j < (int) paramNames.size(); j++)
data.expressionSet.setVariable(data.paramIndex[j], atomParameters[i][j]);
for (int j = 0; j < index; j++)
data.expressionSet.setVariable(data.valueIndex[j], values[j][i]);
values[index][i] = (float) data.valueExpressions[index].evaluate();
}
}
void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, int numAtoms, float* posq, RealOpenMM** atomParameters,
bool useExclusions, const fvec4& boxSize, const fvec4& invBoxSize) {
for (int i = 0; i < numAtoms; i++)
......
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