Commit e68027ab authored by peastman's avatar peastman
Browse files

Optimization to CPU PME

parent bf8de1fd
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2013 Stanford University and the Authors. * * Portions copyright (c) 2013-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -350,9 +350,9 @@ void CpuCalcPmeReciprocalForceKernel::initialize(int xsize, int ysize, int zsize ...@@ -350,9 +350,9 @@ void CpuCalcPmeReciprocalForceKernel::initialize(int xsize, int ysize, int zsize
fftwf_init_threads(); fftwf_init_threads();
hasInitializedThreads = true; hasInitializedThreads = true;
} }
gridx = findFFTDimension(xsize); gridx = findFFTDimension(xsize, false);
gridy = findFFTDimension(ysize); gridy = findFFTDimension(ysize, false);
gridz = findFFTDimension(zsize); gridz = findFFTDimension(zsize, true);
this->numParticles = numParticles; this->numParticles = numParticles;
this->alpha = alpha; this->alpha = alpha;
force.resize(4*numParticles); force.resize(4*numParticles);
...@@ -572,12 +572,18 @@ bool CpuCalcPmeReciprocalForceKernel::isProcessorSupported() { ...@@ -572,12 +572,18 @@ bool CpuCalcPmeReciprocalForceKernel::isProcessorSupported() {
return isVec4Supported(); return isVec4Supported();
} }
int CpuCalcPmeReciprocalForceKernel::findFFTDimension(int minimum) { int CpuCalcPmeReciprocalForceKernel::findFFTDimension(int minimum, bool isZ) {
if (minimum < 1) if (minimum < 1)
return 1; return 1;
while (true) { while (true) {
// Attempt to factor the current value. // Attempt to factor the current value.
if (isZ && minimum%2 == 1) {
// Force the last dimension to be even, since this produces better performance in FFTW.
minimum++;
continue;
}
int unfactored = minimum; int unfactored = minimum;
for (int factor = 2; factor < 8; factor++) { for (int factor = 2; factor < 8; factor++) {
while (unfactored > 1 && unfactored%factor == 0) while (unfactored > 1 && unfactored%factor == 0)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2013 Stanford University and the Authors. * * Portions copyright (c) 2013-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -98,7 +98,7 @@ private: ...@@ -98,7 +98,7 @@ private:
/** /**
* Select a size for one grid dimension that FFTW can handle efficiently. * Select a size for one grid dimension that FFTW can handle efficiently.
*/ */
int findFFTDimension(int minimum); int findFFTDimension(int minimum, bool isZ);
static bool hasInitializedThreads; static bool hasInitializedThreads;
static int numThreads; static int numThreads;
int gridx, gridy, gridz, numParticles; int gridx, gridy, gridz, numParticles;
......
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