Commit aea33abb authored by Peter Eastman's avatar Peter Eastman
Browse files

Added lots of test cases for multi-GPU computation

parent d98bd6b0
...@@ -108,9 +108,41 @@ void testAngles() { ...@@ -108,9 +108,41 @@ void testAngles() {
} }
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomAngleForce* force = new CustomAngleForce("(theta-1.1)^2");
vector<double> params;
for (int i = 2; i < numParticles; i++)
force->addAngle(i-2, i-1, i, params);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, i%2, 0);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testAngles(); testAngles();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -115,10 +115,42 @@ void testManyParameters() { ...@@ -115,10 +115,42 @@ void testManyParameters() {
ASSERT_EQUAL_TOL(f*2.5, state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(f*2.5, state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomBondForce* force = new CustomBondForce(("(r-1.1)^2"));
vector<double> params;
for (int i = 1; i < numParticles; i++)
force->addBond(i-1, i, params);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, 0, 0);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testBonds(); testBonds();
testManyParameters(); testManyParameters();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VerletIntegrator.h" #include "openmm/VerletIntegrator.h"
#include "../src/SimTKUtilities/SimTKOpenMMRealType.h" #include "../src/SimTKUtilities/SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
...@@ -112,10 +113,44 @@ void testManyParameters() { ...@@ -112,10 +113,44 @@ void testManyParameters() {
ASSERT_EQUAL_TOL(0.1*1*1 + 0.2*3*3 + 0.3*3*3, state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(0.1*1*1 + 0.2*3*3 + 0.3*3*3, state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomExternalForce* force = new CustomExternalForce("x^2+y^2+z^2");
vector<double> params;
for (int i = 0; i < numParticles; i++)
force->addParticle(i, params);
system.addForce(force);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(5*genrand_real2(sfmt), 5*genrand_real2(sfmt), 5*genrand_real2(sfmt));
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testForce(); testForce();
testManyParameters(); testManyParameters();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -357,6 +357,39 @@ void testCoulombLennardJones() { ...@@ -357,6 +357,39 @@ void testCoulombLennardJones() {
} }
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomNonbondedForce* force = new CustomNonbondedForce("4*eps*((sigma/r)^12-(sigma/r)^6); sigma=0.5; eps=1");
vector<double> params;
for (int i = 0; i < numParticles; i++)
force->addParticle(params);
system.addForce(force);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(5*genrand_real2(sfmt), 5*genrand_real2(sfmt), 5*genrand_real2(sfmt));
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testSimpleExpression(); testSimpleExpression();
...@@ -367,6 +400,7 @@ int main() { ...@@ -367,6 +400,7 @@ int main() {
testPeriodic(); testPeriodic();
testTabulatedFunction(); testTabulatedFunction();
testCoulombLennardJones(); testCoulombLennardJones();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -147,10 +147,42 @@ void testRange() { ...@@ -147,10 +147,42 @@ void testRange() {
ASSERT(maxAngle <= M_PI); ASSERT(maxAngle <= M_PI);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomTorsionForce* force = new CustomTorsionForce("sin(theta-1.1)");
vector<double> params;
for (int i = 3; i < numParticles; i++)
force->addTorsion(i-3, i-2, i-1, i, params);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, i%2, i%3);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testTorsions(); testTorsions();
testRange(); testRange();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -78,9 +78,40 @@ void testAngles() { ...@@ -78,9 +78,40 @@ void testAngles() {
ASSERT_EQUAL_TOL(0.5*1.1*(PI_M/6)*(PI_M/6) + 0.5*1.2*(PI_M/4)*(PI_M/4), state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(0.5*1.1*(PI_M/6)*(PI_M/6) + 0.5*1.2*(PI_M/4)*(PI_M/4), state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
HarmonicAngleForce* force = new HarmonicAngleForce();
for (int i = 2; i < numParticles; i++)
force->addAngle(i-2, i-1, i, 1.1, i);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, i%2, 0);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testAngles(); testAngles();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "openmm/System.h" #include "openmm/System.h"
#include "openmm/VerletIntegrator.h" #include "openmm/VerletIntegrator.h"
#include <iostream> #include <iostream>
#include <map>
#include <vector> #include <vector>
using namespace OpenMM; using namespace OpenMM;
...@@ -72,9 +73,40 @@ void testBonds() { ...@@ -72,9 +73,40 @@ void testBonds() {
ASSERT_EQUAL_TOL(0.5*0.8*0.5*0.5 + 0.5*0.7*0.2*0.2, state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(0.5*0.8*0.5*0.5 + 0.5*0.7*0.2*0.2, state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
HarmonicBondForce* force = new HarmonicBondForce();
for (int i = 1; i < numParticles; i++)
force->addBond(i-1, i, 1.1, i);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, 0, 0);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testBonds(); testBonds();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -676,6 +676,38 @@ void testDispersionCorrection() { ...@@ -676,6 +676,38 @@ void testDispersionCorrection() {
ASSERT_EQUAL_TOL(expected, energy1-energy2, 1e-4); ASSERT_EQUAL_TOL(expected, energy1-energy2, 1e-4);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
NonbondedForce* force = new NonbondedForce();
for (int i = 0; i < numParticles; i++)
force->addParticle(i%2-0.5, 0.5, 1.0);
system.addForce(force);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(5*genrand_real2(sfmt), 5*genrand_real2(sfmt), 5*genrand_real2(sfmt));
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testCoulomb(); testCoulomb();
...@@ -688,6 +720,7 @@ int main() { ...@@ -688,6 +720,7 @@ int main() {
testBlockInteractions(false); testBlockInteractions(false);
testBlockInteractions(true); testBlockInteractions(true);
testDispersionCorrection(); testDispersionCorrection();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -75,9 +75,40 @@ void testPeriodicTorsions() { ...@@ -75,9 +75,40 @@ void testPeriodicTorsions() {
ASSERT_EQUAL_TOL(1.1*(1+std::cos(2*PI_M/3)), state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(1.1*(1+std::cos(2*PI_M/3)), state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
PeriodicTorsionForce* force = new PeriodicTorsionForce();
for (int i = 3; i < numParticles; i++)
force->addTorsion(i-3, i-2, i-1, i, 2, 1.1, i);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, i%2, i%3);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testPeriodicTorsions(); testPeriodicTorsions();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
...@@ -85,9 +85,40 @@ void testRBTorsions() { ...@@ -85,9 +85,40 @@ void testRBTorsions() {
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), TOL); ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), TOL);
} }
void testParallelComputation() {
OpenCLPlatform platform;
System system;
const int numParticles = 200;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
RBTorsionForce* force = new RBTorsionForce();
for (int i = 3; i < numParticles; i++)
force->addTorsion(i-3, i-2, i-1, i, 2, 0.1*i, 0.5*i, i, 1, 1);
system.addForce(force);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; i++)
positions[i] = Vec3(i, i%2, i%3);
VerletIntegrator integrator1(0.01);
map<string, string> props1;
props1[OpenCLPlatform::OpenCLDeviceIndex()] = "0";
Context context1(system, integrator1, platform, props1);
context1.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
VerletIntegrator integrator2(0.01);
map<string, string> props2;
props2[OpenCLPlatform::OpenCLDeviceIndex()] = "0,0";
Context context2(system, integrator2, platform, props2);
context2.setPositions(positions);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-5);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-5);
}
int main() { int main() {
try { try {
testRBTorsions(); testRBTorsions();
testParallelComputation();
} }
catch(const exception& e) { catch(const exception& e) {
cout << "exception: " << e.what() << endl; cout << "exception: " << e.what() << endl;
......
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