Commit 3c8adf0c authored by Peter Eastman's avatar Peter Eastman
Browse files

OpenCL and CUDA tests are run three times, once for each precision model

parent 6f4ec6b6
......@@ -46,10 +46,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testBonds() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -102,7 +103,6 @@ void testBonds() {
}
void testManyParameters() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -136,7 +136,6 @@ void testManyParameters() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -165,8 +164,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testBonds();
testManyParameters();
testParallelComputation();
......
......@@ -49,11 +49,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testBond() {
OpenCLPlatform platform;
// Create a system using a CustomCompoundBondForce.
System customSystem;
......@@ -142,7 +142,6 @@ void testBond() {
}
void testPositionDependence() {
OpenCLPlatform platform;
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
......@@ -168,7 +167,6 @@ void testPositionDependence() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -201,8 +199,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testBond();
testPositionDependence();
testParallelComputation();
......
......@@ -47,10 +47,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testForce() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -100,7 +101,6 @@ void testForce() {
}
void testManyParameters() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
......@@ -131,7 +131,6 @@ void testManyParameters() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -162,8 +161,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testForce();
testManyParameters();
testParallelComputation();
......
......@@ -48,13 +48,14 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testOBC(GBSAOBCForce::NonbondedMethod obcMethod, CustomGBForce::NonbondedMethod customMethod) {
const int numMolecules = 70;
const int numParticles = numMolecules*2;
const double boxSize = 10.0;
OpenCLPlatform platform;
// Create two systems: one with a GBSAOBCForce, and one using a CustomGBForce to implement the same interaction.
......@@ -168,7 +169,6 @@ void testMembrane() {
const int numMolecules = 70;
const int numParticles = numMolecules*2;
const double boxSize = 10.0;
OpenCLPlatform platform;
// Create a system with an implicit membrane.
......@@ -254,7 +254,6 @@ void testMembrane() {
}
void testTabulatedFunction() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -295,7 +294,6 @@ void testTabulatedFunction() {
}
void testMultipleChainRules() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -323,7 +321,6 @@ void testMultipleChainRules() {
}
void testPositionDependence() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -383,7 +380,6 @@ void testPositionDependence() {
}
void testExclusions() {
OpenCLPlatform platform;
for (int i = 0; i < 4; i++) {
System system;
system.addParticle(1.0);
......@@ -449,8 +445,10 @@ void testExclusions() {
}
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testOBC(GBSAOBCForce::NoCutoff, CustomGBForce::NoCutoff);
testOBC(GBSAOBCForce::CutoffNonPeriodic, CustomGBForce::CutoffNonPeriodic);
testOBC(GBSAOBCForce::CutoffPeriodic, CustomGBForce::CutoffPeriodic);
......
......@@ -49,11 +49,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testHbond() {
OpenCLPlatform platform;
// Create a system using a CustomHbondForce.
System customSystem;
......@@ -149,7 +149,6 @@ void testHbond() {
}
void testExclusions() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -176,7 +175,6 @@ void testExclusions() {
}
void testCutoff() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -204,7 +202,6 @@ void testCutoff() {
}
void testCustomFunctions() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -233,8 +230,10 @@ void testCustomFunctions() {
ASSERT_EQUAL_TOL(0.1*2+0.1*2, state.getPotentialEnergy(), TOL);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testHbond();
testExclusions();
testCutoff();
......
......@@ -49,13 +49,14 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
/**
* Test a simple leapfrog integrator on a single bond.
*/
void testSingleBond() {
OpenCLPlatform platform;
System system;
system.addParticle(2.0);
system.addParticle(2.0);
......@@ -100,8 +101,6 @@ void testSingleBond() {
*/
void testConstraints() {
const int numParticles = 8;
const double temp = 500.0;
OpenCLPlatform platform;
System system;
CustomIntegrator integrator(0.002);
integrator.addPerDofVariable("oldx", 0);
......@@ -160,7 +159,6 @@ void testConstraints() {
*/
void testVelocityConstraints() {
const int numParticles = 10;
OpenCLPlatform platform;
System system;
CustomIntegrator integrator(0.002);
integrator.addPerDofVariable("x1", 0);
......@@ -244,7 +242,6 @@ void testWithThermostat() {
const double temp = 100.0;
const double collisionFreq = 10.0;
const int numSteps = 10000;
OpenCLPlatform platform;
System system;
CustomIntegrator integrator(0.005);
integrator.addUpdateContextState();
......@@ -285,7 +282,6 @@ void testWithThermostat() {
* Test a Monte Carlo integrator that uses global variables and depends on energy.
*/
void testMonteCarlo() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -340,7 +336,6 @@ void testMonteCarlo() {
void testSum() {
const int numParticles = 200;
const double boxSize = 10;
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nb = new NonbondedForce();
......@@ -385,7 +380,6 @@ void testSum() {
* Test an integrator that both uses and modifies a context parameter.
*/
void testParameter() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
AndersenThermostat* thermostat = new AndersenThermostat(0.1, 0.1);
......@@ -411,7 +405,6 @@ void testRandomDistributions() {
const int numParticles = 100;
const int numBins = 20;
const int numSteps = 100;
OpenCLPlatform platform;
System system;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
......@@ -479,7 +472,6 @@ void testRandomDistributions() {
void testPerDofVariables() {
const int numParticles = 200;
const double boxSize = 10;
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nb = new NonbondedForce();
......@@ -535,7 +527,6 @@ void testPerDofVariables() {
* Test evaluating force groups separately.
*/
void testForceGroups() {
OpenCLPlatform platform;
System system;
system.addParticle(2.0);
system.addParticle(2.0);
......@@ -611,7 +602,6 @@ void testForceGroups() {
*/
void testRespa() {
const int numParticles = 8;
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 4, 0), Vec3(0, 0, 4));
CustomIntegrator integrator(0.002);
......@@ -662,8 +652,10 @@ void testRespa() {
}
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testSingleBond();
testConstraints();
testVelocityConstraints();
......
......@@ -48,10 +48,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testSimpleExpression() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -74,7 +75,6 @@ void testSimpleExpression() {
}
void testParameters() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -135,7 +135,6 @@ void testParameters() {
}
void testManyParameters() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -174,7 +173,6 @@ void testManyParameters() {
}
void testExclusions() {
OpenCLPlatform platform;
System system;
VerletIntegrator integrator(0.01);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("a*r; a=a1+a2");
......@@ -205,7 +203,6 @@ void testExclusions() {
}
void testCutoff() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -233,7 +230,6 @@ void testCutoff() {
}
void testPeriodic() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -262,7 +258,6 @@ void testPeriodic() {
}
void testTabulatedFunction() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -305,7 +300,6 @@ void testCoulombLennardJones() {
const int numMolecules = 300;
const int numParticles = numMolecules*2;
const double boxSize = 20.0;
OpenCLPlatform platform;
// Create two systems: one with a NonbondedForce, and one using a CustomNonbondedForce to implement the same interaction.
......@@ -377,7 +371,6 @@ void testCoulombLennardJones() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -414,8 +407,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testSimpleExpression();
testParameters();
testManyParameters();
......
......@@ -50,11 +50,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testTorsions() {
OpenCLPlatform platform;
// Create a system using a CustomTorsionForce.
System customSystem;
......@@ -139,7 +139,6 @@ void testTorsions() {
}
void testRange() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -173,7 +172,6 @@ void testRange() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -202,8 +200,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testTorsions();
testRange();
testParallelComputation();
......
......@@ -50,6 +50,8 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testEwaldPME(bool includeExceptions) {
......@@ -61,7 +63,6 @@ void testEwaldPME(bool includeExceptions) {
const double boxSize = 3.00646;
double tol = 1e-5;
OpenCLPlatform cl;
ReferencePlatform reference;
System system;
NonbondedForce* nonbonded = new NonbondedForce();
......@@ -96,7 +97,7 @@ void testEwaldPME(bool includeExceptions) {
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context clContext(system, integrator1, cl);
Context clContext(system, integrator1, platform);
Context referenceContext(system, integrator2, reference);
clContext.setPositions(positions);
referenceContext.setPositions(positions);
......@@ -126,7 +127,7 @@ void testEwaldPME(bool includeExceptions) {
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
VerletIntegrator integrator3(0.01);
Context clContext2(system, integrator3, cl);
Context clContext2(system, integrator3, platform);
clContext2.setPositions(positions);
tol = 1e-2;
......@@ -165,7 +166,7 @@ void testEwaldPME(bool includeExceptions) {
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
VerletIntegrator integrator4(0.01);
Context clContext3(system, integrator4, cl);
Context clContext3(system, integrator4, platform);
clContext3.setPositions(positions);
tol = 1e-2;
......@@ -174,7 +175,6 @@ void testEwaldPME(bool includeExceptions) {
}
void testEwald2Ions() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -220,7 +220,6 @@ void testErrorTolerance(NonbondedForce::NonbondedMethod method) {
positions[i] = Vec3(boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt));
}
force->setNonbondedMethod(method);
OpenCLPlatform platform;
// For various values of the cutoff and error tolerance, see if the actual error is reasonable.
......@@ -253,8 +252,10 @@ void testErrorTolerance(NonbondedForce::NonbondedMethod method) {
}
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testEwaldPME(false);
testEwaldPME(true);
// testEwald2Ions();
......
......@@ -48,31 +48,34 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
template <class Real2>
void testTransform() {
System system;
system.addParticle(0.0);
OpenCLPlatform::PlatformData platformData(system, "", "", "single");
OpenCLPlatform::PlatformData platformData(system, "", "", platform.getPropertyDefaultValue("OpenCLPrecision"));
OpenCLContext& context = *platformData.contexts[0];
context.initialize();
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
int xsize = 32, ysize = 25, zsize = 30;
vector<mm_float2> original(xsize*ysize*zsize);
vector<Real2> original(xsize*ysize*zsize);
vector<t_complex> reference(original.size());
for (int i = 0; i < (int) original.size(); i++) {
mm_float2 value = mm_float2((cl_float) genrand_real2(sfmt), (cl_float) genrand_real2(sfmt));
Real2 value = Real2((cl_float) genrand_real2(sfmt), (cl_float) genrand_real2(sfmt));
original[i] = value;
reference[i] = t_complex(value.x, value.y);
}
OpenCLArray grid1(context, original.size(), sizeof(mm_float2), "grid1");
OpenCLArray grid2(context, original.size(), sizeof(mm_float2), "grid2");
OpenCLArray grid1(context, original.size(), sizeof(Real2), "grid1");
OpenCLArray grid2(context, original.size(), sizeof(Real2), "grid2");
grid1.upload(original);
OpenCLFFT3D fft(context, xsize, ysize, zsize);
// Perform a forward FFT, then verify the result is correct.
fft.execFFT(grid1, grid2, true);
vector<mm_float2> result;
vector<Real2> result;
grid2.download(result);
fftpack_t plan;
fftpack_init_3d(&plan, xsize, ysize, zsize);
......@@ -94,9 +97,14 @@ void testTransform() {
}
}
int main() {
int main(int argc, char* argv[]) {
try {
testTransform();
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
if (platform.getPropertyDefaultValue("OpenCLPrecision") == "double")
testTransform<mm_double2>();
else
testTransform<mm_float2>();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
......
......@@ -49,10 +49,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testSingleParticle() {
OpenCLPlatform platform;
System system;
system.addParticle(2.0);
LangevinIntegrator integrator(0, 0.1, 0.01);
......@@ -87,7 +88,6 @@ void testSingleParticle() {
}
void testCutoffAndPeriodic() {
OpenCLPlatform cl;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -113,7 +113,7 @@ void testCutoffAndPeriodic() {
nonbonded->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
gbsa->setNonbondedMethod(GBSAOBCForce::CutoffNonPeriodic);
Context context(system, integrator, cl);
Context context(system, integrator, platform);
context.setPositions(positions);
State state1 = context.getState(State::Forces);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
......@@ -144,7 +144,6 @@ void testCutoffAndPeriodic() {
}
void testForce(int numParticles, NonbondedForce::NonbondedMethod method, GBSAOBCForce::NonbondedMethod method2) {
OpenCLPlatform cl;
ReferencePlatform reference;
System system;
GBSAOBCForce* gbsa = new GBSAOBCForce();
......@@ -168,7 +167,7 @@ void testForce(int numParticles, NonbondedForce::NonbondedMethod method, GBSAOBC
system.addForce(nonbonded);
LangevinIntegrator integrator1(0, 0.1, 0.01);
LangevinIntegrator integrator2(0, 0.1, 0.01);
Context context(system, integrator1, cl);
Context context(system, integrator1, platform);
Context refContext(system, integrator2, reference);
// Set random (but uniformly distributed) positions for all the particles.
......
......@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */
/**
* This tests the Cuda implementations of GBVIForce, GBSAOBCForce and the softcore versions of
* This tests the OpenCL implementations of GBVIForce, GBSAOBCForce and the softcore versions of
* these forces.
*/
......@@ -2850,7 +2850,7 @@ static int checkRequiredLibsAreAvailable( const StringVector& requiredLibs, cons
void runSystemComparisonTest( System& system1, System& system2,
const std::vector<Vec3>& positions, MapStringToDouble& inputArgumentMap,
const std::string& idString, FILE* log ){
const std::string& idString, const std::string& precision, FILE* log ){
int applyAssert = 0;
int platformId1 = 0;
......@@ -2914,9 +2914,11 @@ void runSystemComparisonTest( System& system1, System& system2,
#if TEST_PLATFORM == TEST_OPENCL_PLATFORM
ReferencePlatform platform1;
OpenCLPlatform platform2;
platform2.setPropertyDefaultValue("OpenCLPrecision", precision);
#elif TEST_PLATFORM == TEST_CUDA_PLATFORM
ReferencePlatform platform1;
CudaPlatform platform2;
platform2.setPropertyDefaultValue("CudaPrecision", precision);
#else
Platform& platform1 = Platform::getPlatformByName( platformName1 );
if( deviceId1 ){
......@@ -3059,7 +3061,7 @@ void serializeSystemAndPositions( System& system, const std::vector<Vec3>& posit
return;
}
void runTests( MapStringToDouble& inputArgumentMap, FILE* log ){
void runTests( MapStringToDouble& inputArgumentMap, const std::string& precision, FILE* log ){
double lambda1 = 1.0;
double lambda2 = 1.0;
......@@ -3327,11 +3329,17 @@ void runTests( MapStringToDouble& inputArgumentMap, FILE* log ){
std::stringstream idString;
idString << "Nb " << nonbondedMethod << " l2 " << std::fixed << setprecision(2) << lambda2;
runSystemComparisonTest( standardSystem, systemCopy, positions, inputArgumentMap, idString.str(), log );
runSystemComparisonTest( standardSystem, systemCopy, positions, inputArgumentMap, idString.str(), precision, log );
}
int main() {
int main(int argc, char* argv[]) {
std::string precision;
if (argc > 1)
precision = std::string(argv[1]);
else
precision = "single";
try {
......@@ -3503,7 +3511,7 @@ int main() {
int wasException = 0;
for( unsigned int kk = 0; kk < vectorOfMapStringToDouble.size() && wasException < 3; kk++ ){
try {
runTests( vectorOfMapStringToDouble[kk], log );
runTests( vectorOfMapStringToDouble[kk], precision, log );
} catch(const exception& e) {
std::stringstream msg;
#if IMPLICIT_SOLVENT == TEST_NONBONDED
......
......@@ -47,10 +47,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testAngles() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -99,7 +100,6 @@ void testAngles() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -127,8 +127,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testAngles();
testParallelComputation();
}
......
......@@ -46,10 +46,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testBonds() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -90,7 +91,6 @@ void testBonds() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -118,8 +118,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testBonds();
testParallelComputation();
}
......
......@@ -48,10 +48,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testSingleBond() {
OpenCLPlatform platform;
System system;
system.addParticle(2.0);
system.addParticle(2.0);
......@@ -97,7 +98,6 @@ void testSingleBond() {
void testTemperature() {
const int numParticles = 8;
const double temp = 100.0;
OpenCLPlatform platform;
System system;
LangevinIntegrator integrator(temp, 2.0, 0.01);
NonbondedForce* forceField = new NonbondedForce();
......@@ -133,7 +133,6 @@ void testConstraints() {
const int numParticles = 8;
const int numConstraints = 5;
const double temp = 100.0;
OpenCLPlatform platform;
System system;
LangevinIntegrator integrator(temp, 2.0, 0.01);
integrator.setConstraintTolerance(1e-5);
......@@ -181,8 +180,6 @@ void testConstraints() {
void testRandomSeed() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
OpenCLPlatform platform;
System system;
LangevinIntegrator integrator(temp, 2.0, 0.01);
NonbondedForce* forceField = new NonbondedForce();
......@@ -237,8 +234,10 @@ void testRandomSeed() {
}
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testSingleBond();
testTemperature();
testConstraints();
......
......@@ -45,6 +45,8 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
void testHarmonicBonds() {
const int numParticles = 10;
System system;
......@@ -64,7 +66,6 @@ void testHarmonicBonds() {
// Minimize it and check that all bonds are at their equilibrium distances.
VerletIntegrator integrator(0.01);
OpenCLPlatform platform;
Context context(system, integrator, platform);
context.setPositions(positions);
LocalEnergyMinimizer::minimize(context, 1e-5);
......@@ -105,7 +106,6 @@ void testLargeSystem() {
// Minimize it and verify that the energy has decreased.
OpenCLPlatform platform;
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
......@@ -167,7 +167,6 @@ void testVirtualSites() {
// Minimize it and verify that the energy has decreased.
OpenCLPlatform platform;
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
......@@ -199,8 +198,10 @@ void testVirtualSites() {
ASSERT(forceNorm < 3*tolerance);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testHarmonicBonds();
testLargeSystem();
testVirtualSites();
......
......@@ -49,8 +49,9 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
void testChangingBoxSize() {
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 5, 0), Vec3(0, 0, 6));
system.addParticle(1.0);
......@@ -100,7 +101,6 @@ void testIdealGas() {
// Create a gas of noninteracting particles.
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(initialLength, 0, 0), Vec3(0, 0.5*initialLength, 0), Vec3(0, 0, 2*initialLength));
vector<Vec3> positions(numParticles);
......@@ -146,7 +146,6 @@ void testRandomSeed() {
const int numParticles = 8;
const double temp = 100.0;
const double pressure = 1.5;
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(8, 0, 0), Vec3(0, 8, 0), Vec3(0, 0, 8));
VerletIntegrator integrator(0.01);
......@@ -219,7 +218,6 @@ void testWater() {
// Create a box of SPC water molecules.
OpenCLPlatform platform;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(gridSize*spacing, 0, 0), Vec3(0, gridSize*spacing, 0), Vec3(0, 0, gridSize*spacing));
NonbondedForce* nonbonded = new NonbondedForce();
......@@ -273,8 +271,10 @@ void testWater() {
ASSERT_USUALLY_EQUAL_TOL(1.0, density, 0.02);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testChangingBoxSize();
testIdealGas();
testRandomSeed();
......
......@@ -52,6 +52,8 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testForces() {
......@@ -78,9 +80,8 @@ void testForces() {
ReferencePlatform ref;
VerletIntegrator integrator1(0.01);
Context context1(system, integrator1, ref);
OpenCLPlatform cl;
VerletIntegrator integrator2(0.01);
Context context2(system, integrator2, cl);
Context context2(system, integrator2, platform);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles);
......@@ -97,8 +98,10 @@ void testForces() {
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), TOL);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testForces();
}
catch(const exception& e) {
......
......@@ -53,10 +53,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testCoulomb() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -79,7 +80,6 @@ void testCoulomb() {
}
void testLJ() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -104,7 +104,6 @@ void testLJ() {
}
void testExclusionsAnd14() {
OpenCLPlatform platform;
System system;
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < 5; ++i) {
......@@ -192,7 +191,6 @@ void testExclusionsAnd14() {
}
void testCutoff() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -229,7 +227,6 @@ void testCutoff() {
}
void testCutoff14() {
OpenCLPlatform platform;
System system;
LangevinIntegrator integrator(0.0, 0.1, 0.01);
NonbondedForce* nonbonded = new NonbondedForce();
......@@ -325,7 +322,6 @@ void testCutoff14() {
}
void testPeriodic() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -366,7 +362,6 @@ void testLargeSystem() {
const double cutoff = 2.0;
const double boxSize = 20.0;
const double tol = 2e-3;
OpenCLPlatform cl;
ReferencePlatform reference;
System system;
for (int i = 0; i < numParticles; i++)
......@@ -404,7 +399,7 @@ void testLargeSystem() {
system.addForce(bonds);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context clContext(system, integrator1, cl);
Context clContext(system, integrator1, platform);
Context referenceContext(system, integrator2, reference);
clContext.setPositions(positions);
clContext.setVelocities(velocities);
......@@ -450,7 +445,6 @@ void testBlockInteractions(bool periodic) {
const int numParticles = blockSize*numBlocks;
const double cutoff = 1.0;
const double boxSize = (periodic ? 5.1 : 1.1);
OpenCLPlatform cl;
System system;
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce();
......@@ -467,7 +461,7 @@ void testBlockInteractions(bool periodic) {
nonbonded->setCutoffDistance(cutoff);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(nonbonded);
Context context(system, integrator, cl);
Context context(system, integrator, platform);
context.setPositions(positions);
ContextImpl* contextImpl = *reinterpret_cast<ContextImpl**>(&context);
OpenCLPlatform::PlatformData& data = *static_cast<OpenCLPlatform::PlatformData*>(contextImpl->getPlatformData());
......@@ -617,7 +611,6 @@ void testDispersionCorrection() {
int numParticles = gridSize*gridSize*gridSize;
double boxSize = gridSize*0.5;
double cutoff = boxSize/3;
OpenCLPlatform platform;
System system;
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce();
......@@ -684,7 +677,6 @@ void testChangingParameters() {
const double cutoff = 2.0;
const double boxSize = 20.0;
const double tol = 2e-3;
OpenCLPlatform cl;
ReferencePlatform reference;
System system;
for (int i = 0; i < numParticles; i++)
......@@ -717,7 +709,7 @@ void testChangingParameters() {
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context clContext(system, integrator1, cl);
Context clContext(system, integrator1, platform);
Context referenceContext(system, integrator2, reference);
clContext.setPositions(positions);
referenceContext.setPositions(positions);
......@@ -750,7 +742,6 @@ void testChangingParameters() {
}
void testParallelComputation(bool useCutoff) {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -809,8 +800,10 @@ void testParallelComputation(bool useCutoff) {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testCoulomb();
testLJ();
testExclusionsAnd14();
......
......@@ -46,10 +46,11 @@
using namespace OpenMM;
using namespace std;
OpenCLPlatform platform;
const double TOL = 1e-5;
void testPeriodicTorsions() {
OpenCLPlatform platform;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
......@@ -93,7 +94,6 @@ void testPeriodicTorsions() {
}
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
......@@ -121,8 +121,10 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() {
int main(int argc, char* argv[]) {
try {
if (argc > 1)
platform.setPropertyDefaultValue("OpenCLPrecision", string(argv[1]));
testPeriodicTorsions();
testParallelComputation();
}
......
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