Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
aea33abb
Commit
aea33abb
authored
Jul 07, 2011
by
Peter Eastman
Browse files
Added lots of test cases for multi-GPU computation
parent
d98bd6b0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
323 additions
and
0 deletions
+323
-0
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
+32
-0
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
+32
-0
platforms/opencl/tests/TestOpenCLCustomExternalForce.cpp
platforms/opencl/tests/TestOpenCLCustomExternalForce.cpp
+35
-0
platforms/opencl/tests/TestOpenCLCustomNonbondedForce.cpp
platforms/opencl/tests/TestOpenCLCustomNonbondedForce.cpp
+34
-0
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
+32
-0
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
+31
-0
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
+32
-0
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
+33
-0
platforms/opencl/tests/TestOpenCLPeriodicTorsionForce.cpp
platforms/opencl/tests/TestOpenCLPeriodicTorsionForce.cpp
+31
-0
platforms/opencl/tests/TestOpenCLRBTorsionForce.cpp
platforms/opencl/tests/TestOpenCLRBTorsionForce.cpp
+31
-0
No files found.
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
View file @
aea33abb
...
...
@@ -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
()
{
try
{
testAngles
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
View file @
aea33abb
...
...
@@ -115,10 +115,42 @@ void testManyParameters() {
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
()
{
try
{
testBonds
();
testManyParameters
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLCustomExternalForce.cpp
View file @
aea33abb
...
...
@@ -40,6 +40,7 @@
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "../src/SimTKUtilities/SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
...
...
@@ -112,10 +113,44 @@ void testManyParameters() {
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
()
{
try
{
testForce
();
testManyParameters
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLCustomNonbondedForce.cpp
View file @
aea33abb
...
...
@@ -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
()
{
try
{
testSimpleExpression
();
...
...
@@ -367,6 +400,7 @@ int main() {
testPeriodic
();
testTabulatedFunction
();
testCoulombLennardJones
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
View file @
aea33abb
...
...
@@ -147,10 +147,42 @@ void testRange() {
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
()
{
try
{
testTorsions
();
testRange
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
View file @
aea33abb
...
...
@@ -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
);
}
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
()
{
try
{
testAngles
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
View file @
aea33abb
...
...
@@ -40,6 +40,7 @@
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <iostream>
#include <map>
#include <vector>
using
namespace
OpenMM
;
...
...
@@ -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
);
}
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
()
{
try
{
testBonds
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLNonbondedForce.cpp
View file @
aea33abb
...
...
@@ -676,6 +676,38 @@ void testDispersionCorrection() {
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
()
{
try
{
testCoulomb
();
...
...
@@ -688,6 +720,7 @@ int main() {
testBlockInteractions
(
false
);
testBlockInteractions
(
true
);
testDispersionCorrection
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLPeriodicTorsionForce.cpp
View file @
aea33abb
...
...
@@ -75,9 +75,40 @@ void testPeriodicTorsions() {
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
()
{
try
{
testPeriodicTorsions
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/opencl/tests/TestOpenCLRBTorsionForce.cpp
View file @
aea33abb
...
...
@@ -85,9 +85,40 @@ void testRBTorsions() {
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
()
{
try
{
testRBTorsions
();
testParallelComputation
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment