Commit 0d5e0b55 authored by peastman's avatar peastman
Browse files

Eliminated some unnecessary memory allocation in CpuCustomManyParticleForce

parent 14d3c584
...@@ -199,6 +199,7 @@ public: ...@@ -199,6 +199,7 @@ public:
CompiledExpressionSet expressionSet; CompiledExpressionSet expressionSet;
Lepton::CompiledExpression energyExpression; Lepton::CompiledExpression energyExpression;
std::vector<std::vector<int> > particleParamIndices; std::vector<std::vector<int> > particleParamIndices;
std::vector<int> permutedParticles;
std::vector<std::pair<int, int> > deltaPairs; std::vector<std::pair<int, int> > deltaPairs;
std::vector<ParticleTermInfo> particleTerms; std::vector<ParticleTermInfo> particleTerms;
std::vector<DistanceTermInfo> distanceTerms; std::vector<DistanceTermInfo> distanceTerms;
...@@ -207,6 +208,7 @@ public: ...@@ -207,6 +208,7 @@ public:
AlignedArray<fvec4> delta; AlignedArray<fvec4> delta;
std::vector<float> normDelta; std::vector<float> normDelta;
std::vector<float> norm2Delta; std::vector<float> norm2Delta;
AlignedArray<fvec4> f;
double energy; double energy;
ThreadData(const CustomManyParticleForce& force, Lepton::ParsedExpression& energyExpr, ThreadData(const CustomManyParticleForce& force, Lepton::ParsedExpression& energyExpr,
std::map<std::string, std::vector<int> >& distances, std::map<std::string, std::vector<int> >& angles, std::map<std::string, std::vector<int> >& dihedrals); std::map<std::string, std::vector<int> >& distances, std::map<std::string, std::vector<int> >& angles, std::map<std::string, std::vector<int> >& dihedrals);
......
...@@ -147,6 +147,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr ...@@ -147,6 +147,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
if (useCutoff) { if (useCutoff) {
// Loop over interactions from the neighbor list. // Loop over interactions from the neighbor list.
vector<int> particles;
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1);
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
...@@ -161,7 +162,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr ...@@ -161,7 +162,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
// again later, but the neighbor list also includes padding atoms that it marks as exclusions, so // again later, but the neighbor list also includes padding atoms that it marks as exclusions, so
// we need to remove those now. // we need to remove those now.
vector<int> particles; particles.resize(0);
for (int j = 0; j < numNeighbors; j++) for (int j = 0; j < numNeighbors; j++)
if ((exclusions[j] & (1<<i)) == 0) if ((exclusions[j] & (1<<i)) == 0)
particles.push_back(neighbors[j]); particles.push_back(neighbors[j]);
...@@ -238,7 +239,7 @@ void CpuCustomManyParticleForce::loopOverInteractions(vector<int>& availablePart ...@@ -238,7 +239,7 @@ void CpuCustomManyParticleForce::loopOverInteractions(vector<int>& availablePart
void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, RealOpenMM** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) { void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, RealOpenMM** particleParameters, float* forces, ThreadData& data, const fvec4& boxSize, const fvec4& invBoxSize) {
// Select the ordering to use for the particles. // Select the ordering to use for the particles.
vector<int> permutedParticles(numParticlesPerSet); vector<int>& permutedParticles = data.permutedParticles;
if (particleOrder.size() == 1) { if (particleOrder.size() == 1) {
// There are no filters, so we don't need to worry about ordering. // There are no filters, so we don't need to worry about ordering.
...@@ -297,7 +298,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, RealO ...@@ -297,7 +298,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, RealO
if (includeForces) { if (includeForces) {
// Apply forces based on individual particle coordinates. // Apply forces based on individual particle coordinates.
AlignedArray<fvec4> f(numParticlesPerSet); AlignedArray<fvec4>& f = data.f;
for (int i = 0; i < numParticlesPerSet; i++) for (int i = 0; i < numParticlesPerSet; i++)
f[i] = fvec4(0.0f); f[i] = fvec4(0.0f);
for (int i = 0; i < (int) data.particleTerms.size(); i++) { for (int i = 0; i < (int) data.particleTerms.size(); i++) {
...@@ -444,6 +445,8 @@ CpuCustomManyParticleForce::ThreadData::ThreadData(const CustomManyParticleForce ...@@ -444,6 +445,8 @@ CpuCustomManyParticleForce::ThreadData::ThreadData(const CustomManyParticleForce
int numParticlesPerSet = force.getNumParticlesPerSet(); int numParticlesPerSet = force.getNumParticlesPerSet();
int numPerParticleParameters = force.getNumPerParticleParameters(); int numPerParticleParameters = force.getNumPerParticleParameters();
particleParamIndices.resize(numParticlesPerSet); particleParamIndices.resize(numParticlesPerSet);
permutedParticles.resize(numParticlesPerSet);
f.resize(numParticlesPerSet);
energyExpression = energyExpr.createCompiledExpression(); energyExpression = energyExpr.createCompiledExpression();
expressionSet.registerExpression(energyExpression); expressionSet.registerExpression(energyExpression);
......
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