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
a5bcc4be
Commit
a5bcc4be
authored
Oct 24, 2013
by
peastman
Browse files
Minor optimizations to CPU platform
parent
062a2db0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
9 deletions
+8
-9
platforms/cpu/src/CpuKernels.cpp
platforms/cpu/src/CpuKernels.cpp
+2
-1
platforms/cpu/src/CpuNeighborList.cpp
platforms/cpu/src/CpuNeighborList.cpp
+6
-8
No files found.
platforms/cpu/src/CpuKernels.cpp
View file @
a5bcc4be
...
@@ -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
)
>
c
utoff2
)
{
if
(
oldDelta
.
dot
(
oldDelta
)
>
paddedC
utoff2
)
{
needRecompute
=
true
;
needRecompute
=
true
;
break
;
break
;
}
}
...
...
platforms/cpu/src/CpuNeighborList.cpp
View file @
a5bcc4be
...
@@ -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
{
...
...
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