"openmmapi/src/PythonForce.cpp" did not exist on "74912095a9b4c8ac7d8e8be41d48bc069b1c21a0"
Commit a5bcc4be authored by peastman's avatar peastman
Browse files

Minor optimizations to CPU platform

parent 062a2db0
...@@ -244,6 +244,7 @@ double CpuCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeFo ...@@ -244,6 +244,7 @@ double CpuCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeFo
int numMoved = moved.size(); int numMoved = moved.size();
double cutoff2 = nonbondedCutoff*nonbondedCutoff; double cutoff2 = nonbondedCutoff*nonbondedCutoff;
double paddedCutoff2 = (nonbondedCutoff+padding)*(nonbondedCutoff+padding);
for (int i = 1; i < numMoved && !needRecompute; i++) for (int i = 1; i < numMoved && !needRecompute; i++)
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
RealVec delta = posData[moved[i]]-posData[moved[j]]; RealVec delta = posData[moved[i]]-posData[moved[j]];
...@@ -251,7 +252,7 @@ double CpuCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeFo ...@@ -251,7 +252,7 @@ double CpuCalcNonbondedForceKernel::execute(ContextImpl& context, bool includeFo
// These particles should interact. See if they are in the neighbor list. // These particles should interact. See if they are in the neighbor list.
RealVec oldDelta = lastPositions[moved[i]]-lastPositions[moved[j]]; RealVec oldDelta = lastPositions[moved[i]]-lastPositions[moved[j]];
if (oldDelta.dot(oldDelta) > cutoff2) { if (oldDelta.dot(oldDelta) > paddedCutoff2) {
needRecompute = true; needRecompute = true;
break; break;
} }
......
...@@ -23,8 +23,6 @@ public: ...@@ -23,8 +23,6 @@ public:
int y; int y;
}; };
typedef pair<const float*, int> VoxelItem;
/** /**
* This data structure organizes the particles spatially. It divides them into bins along the x and y axes, * This data structure organizes the particles spatially. It divides them into bins along the x and y axes,
* then sorts each bin along the z axis so ranges can be identified quickly with a binary search. * then sorts each bin along the z axis so ranges can be identified quickly with a binary search.
...@@ -60,7 +58,7 @@ public: ...@@ -60,7 +58,7 @@ public:
*/ */
void insert(const int& atom, const float* location) { void insert(const int& atom, const float* location) {
VoxelIndex voxelIndex = getVoxelIndex(location); VoxelIndex voxelIndex = getVoxelIndex(location);
bins[voxelIndex.x][voxelIndex.y].push_back(make_pair(location[2], VoxelItem(location, atom))); bins[voxelIndex.x][voxelIndex.y].push_back(make_pair(location[2], atom));
} }
/** /**
...@@ -76,7 +74,7 @@ public: ...@@ -76,7 +74,7 @@ public:
* Find the index of the first particle in voxel (x,y) whose z coordinate in >= the specified value. * Find the index of the first particle in voxel (x,y) whose z coordinate in >= the specified value.
*/ */
int findLowerBound(int x, int y, double z) const { int findLowerBound(int x, int y, double z) const {
const vector<pair<float, VoxelItem> >& bin = bins[x][y]; const vector<pair<float, int> >& bin = bins[x][y];
int lower = 0; int lower = 0;
int upper = bin.size(); int upper = bin.size();
while (lower < upper) { while (lower < upper) {
...@@ -93,7 +91,7 @@ public: ...@@ -93,7 +91,7 @@ public:
* Find the index of the first particle in voxel (x,y) whose z coordinate in greater than the specified value. * Find the index of the first particle in voxel (x,y) whose z coordinate in greater than the specified value.
*/ */
int findUpperBound(int x, int y, double z) const { int findUpperBound(int x, int y, double z) const {
const vector<pair<float, VoxelItem> >& bin = bins[x][y]; const vector<pair<float, int> >& bin = bins[x][y];
int lower = 0; int lower = 0;
int upper = bin.size(); int upper = bin.size();
while (lower < upper) { while (lower < upper) {
...@@ -196,13 +194,13 @@ public: ...@@ -196,13 +194,13 @@ public:
for (int range = 0; range < numRanges; range++) { for (int range = 0; range < numRanges; range++) {
for (int item = rangeStart[range]; item < rangeEnd[range]; item++) { for (int item = rangeStart[range]; item < rangeEnd[range]; item++) {
const int sortedIndex = bins[voxelIndex.x][voxelIndex.y][item].second.second; const int sortedIndex = bins[voxelIndex.x][voxelIndex.y][item].second;
// Avoid duplicate entries. // Avoid duplicate entries.
if (sortedIndex >= lastSortedIndex) if (sortedIndex >= lastSortedIndex)
continue; continue;
fvec4 atomPos(bins[voxelIndex.x][voxelIndex.y][item].second.first); fvec4 atomPos(atomLocations+4*sortedAtoms[sortedIndex]);
fvec4 delta = atomPos-centerPos; fvec4 delta = atomPos-centerPos;
if (usePeriodic) { if (usePeriodic) {
fvec4 base = round(delta*invBoxSize)*boxSize; fvec4 base = round(delta*invBoxSize)*boxSize;
...@@ -254,7 +252,7 @@ private: ...@@ -254,7 +252,7 @@ private:
int nx, ny; int nx, ny;
const float* periodicBoxSize; const float* periodicBoxSize;
const bool usePeriodic; const bool usePeriodic;
vector<vector<vector<pair<float, VoxelItem> > > > bins; vector<vector<vector<pair<float, int> > > > bins;
}; };
class CpuNeighborList::ThreadData { class CpuNeighborList::ThreadData {
......
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