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
424bfe9c
"platforms/cuda/vscode:/vscode.git/clone" did not exist on "6bfd7ab87a468a3aa41f7eea1e4050e4b2c24f26"
Commit
424bfe9c
authored
Mar 11, 2014
by
peastman
Browse files
Created a property for setting the number of CPU cores to use
parent
55237c86
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
11 deletions
+76
-11
docs/usersguide/library.rst
docs/usersguide/library.rst
+18
-0
openmmapi/include/openmm/internal/ThreadPool.h
openmmapi/include/openmm/internal/ThreadPool.h
+7
-1
openmmapi/src/ThreadPool.cpp
openmmapi/src/ThreadPool.cpp
+5
-3
platforms/cpu/include/CpuPlatform.h
platforms/cpu/include/CpuPlatform.h
+12
-2
platforms/cpu/src/CpuPlatform.cpp
platforms/cpu/src/CpuPlatform.cpp
+34
-5
No files found.
docs/usersguide/library.rst
View file @
424bfe9c
...
@@ -1878,6 +1878,24 @@ values. For example,
...
@@ -1878,6 +1878,24 @@ values. For example,
This
tells
it
to
use
both
devices
0
and
1
,
splitting
the
work
between
them
.
This
tells
it
to
use
both
devices
0
and
1
,
splitting
the
work
between
them
.
CPU
Platform
************
The
CPU
Platform
recognizes
the
following
Platform
-
specific
properties
:
*
CpuThreads
:
This
specifies
the
number
of
CPU
threads
to
use
.
If
you
do
not
specify
this
,
OpenMM
will
select
a
default
number
of
threads
as
follows
:
*
If
an
environment
variable
called
OPENMM_CPU_THREADS
is
set
,
its
value
is
used
as
the
number
of
threads
.
*
Otherwise
,
the
number
of
threads
is
set
to
the
number
of
logical
CPU
cores
in
the
computer
it
is
running
on
.
Usually
the
default
value
works
well
.
This
is
mainly
useful
when
you
are
running
something
else
on
the
computer
at
the
same
time
,
and
you
want
to
prevent
OpenMM
from
monopolizing
all
available
cores
.
..
_using
-
openmm
-
with
-
software
-
written
-
in
-
languages
-
other
-
than
-
c
++:
..
_using
-
openmm
-
with
-
software
-
written
-
in
-
languages
-
other
-
than
-
c
++:
Using
OpenMM
with
Software
Written
in
Languages
Other
than
C
++
Using
OpenMM
with
Software
Written
in
Languages
Other
than
C
++
...
...
openmmapi/include/openmm/internal/ThreadPool.h
View file @
424bfe9c
...
@@ -53,7 +53,13 @@ class OPENMM_EXPORT ThreadPool {
...
@@ -53,7 +53,13 @@ class OPENMM_EXPORT ThreadPool {
public:
public:
class
Task
;
class
Task
;
class
ThreadData
;
class
ThreadData
;
ThreadPool
();
/**
* Create a ThreadPool.
*
* @param numThreads the number of worker threads to create. If this is 0 (the default), the
* number of threads is set equal to the number of logical CPU cores available
*/
ThreadPool
(
int
numThreads
=
0
);
~
ThreadPool
();
~
ThreadPool
();
/**
/**
* Get the number of worker threads in the pool.
* Get the number of worker threads in the pool.
...
...
openmmapi/src/ThreadPool.cpp
View file @
424bfe9c
...
@@ -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: *
* *
* *
...
@@ -60,8 +60,10 @@ static void* threadBody(void* args) {
...
@@ -60,8 +60,10 @@ static void* threadBody(void* args) {
return
0
;
return
0
;
}
}
ThreadPool
::
ThreadPool
()
{
ThreadPool
::
ThreadPool
(
int
numThreads
)
{
if
(
numThreads
<=
0
)
numThreads
=
getNumProcessors
();
numThreads
=
getNumProcessors
();
this
->
numThreads
=
numThreads
;
pthread_cond_init
(
&
startCondition
,
NULL
);
pthread_cond_init
(
&
startCondition
,
NULL
);
pthread_cond_init
(
&
endCondition
,
NULL
);
pthread_cond_init
(
&
endCondition
,
NULL
);
pthread_mutex_init
(
&
lock
,
NULL
);
pthread_mutex_init
(
&
lock
,
NULL
);
...
...
platforms/cpu/include/CpuPlatform.h
View file @
424bfe9c
...
@@ -55,27 +55,37 @@ public:
...
@@ -55,27 +55,37 @@ public:
return
name
;
return
name
;
}
}
double
getSpeed
()
const
;
double
getSpeed
()
const
;
const
std
::
string
&
getPropertyValue
(
const
Context
&
context
,
const
std
::
string
&
property
)
const
;
bool
supportsDoublePrecision
()
const
;
bool
supportsDoublePrecision
()
const
;
static
bool
isProcessorSupported
();
static
bool
isProcessorSupported
();
void
contextCreated
(
ContextImpl
&
context
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
properties
)
const
;
void
contextCreated
(
ContextImpl
&
context
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
properties
)
const
;
void
contextDestroyed
(
ContextImpl
&
context
)
const
;
void
contextDestroyed
(
ContextImpl
&
context
)
const
;
/**
* This is the name of the parameter for selecting the number of threads to use.
*/
static
const
std
::
string
&
CpuThreads
()
{
static
const
std
::
string
key
=
"CpuThreads"
;
return
key
;
}
/**
/**
* We cannot use the standard mechanism for platform data, because that is already used by the superclass.
* We cannot use the standard mechanism for platform data, because that is already used by the superclass.
* Instead, we maintain a table of ContextImpls to PlatformDatas.
* Instead, we maintain a table of ContextImpls to PlatformDatas.
*/
*/
static
PlatformData
&
getPlatformData
(
ContextImpl
&
context
);
static
PlatformData
&
getPlatformData
(
ContextImpl
&
context
);
static
const
PlatformData
&
getPlatformData
(
const
ContextImpl
&
context
);
private:
private:
static
std
::
map
<
ContextImpl
*
,
PlatformData
*>
contextData
;
static
std
::
map
<
const
ContextImpl
*
,
PlatformData
*>
contextData
;
};
};
class
CpuPlatform
::
PlatformData
{
class
CpuPlatform
::
PlatformData
{
public:
public:
PlatformData
(
int
numParticles
);
PlatformData
(
int
numParticles
,
int
numThreads
);
AlignedArray
<
float
>
posq
;
AlignedArray
<
float
>
posq
;
std
::
vector
<
AlignedArray
<
float
>
>
threadForce
;
std
::
vector
<
AlignedArray
<
float
>
>
threadForce
;
ThreadPool
threads
;
ThreadPool
threads
;
bool
isPeriodic
;
bool
isPeriodic
;
CpuRandom
random
;
CpuRandom
random
;
std
::
map
<
std
::
string
,
std
::
string
>
propertyValues
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
platforms/cpu/src/CpuPlatform.cpp
View file @
424bfe9c
...
@@ -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: *
* *
* *
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include "CpuSETTLE.h"
#include "CpuSETTLE.h"
#include "ReferenceConstraints.h"
#include "ReferenceConstraints.h"
#include "openmm/internal/hardware.h"
#include "openmm/internal/hardware.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
...
@@ -53,7 +54,7 @@ extern "C" OPENMM_EXPORT_CPU void registerPlatforms() {
...
@@ -53,7 +54,7 @@ extern "C" OPENMM_EXPORT_CPU void registerPlatforms() {
}
}
#endif
#endif
map
<
ContextImpl
*
,
CpuPlatform
::
PlatformData
*>
CpuPlatform
::
contextData
;
map
<
const
ContextImpl
*
,
CpuPlatform
::
PlatformData
*>
CpuPlatform
::
contextData
;
CpuPlatform
::
CpuPlatform
()
{
CpuPlatform
::
CpuPlatform
()
{
CpuKernelFactory
*
factory
=
new
CpuKernelFactory
();
CpuKernelFactory
*
factory
=
new
CpuKernelFactory
();
...
@@ -63,6 +64,23 @@ CpuPlatform::CpuPlatform() {
...
@@ -63,6 +64,23 @@ CpuPlatform::CpuPlatform() {
registerKernelFactory
(
CalcNonbondedForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcNonbondedForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGBSAOBCForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGBSAOBCForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
platformProperties
.
push_back
(
CpuThreads
());
int
threads
=
getNumProcessors
();
char
*
threadsEnv
=
getenv
(
"OPENMM_CPU_THREADS"
);
if
(
threadsEnv
!=
NULL
)
stringstream
(
threadsEnv
)
>>
threads
;
stringstream
defaultThreads
;
defaultThreads
<<
threads
;
setPropertyDefaultValue
(
CpuThreads
(),
defaultThreads
.
str
());
}
const
string
&
CpuPlatform
::
getPropertyValue
(
const
Context
&
context
,
const
string
&
property
)
const
{
const
ContextImpl
&
impl
=
getContextImpl
(
context
);
const
PlatformData
&
data
=
getPlatformData
(
impl
);
map
<
string
,
string
>::
const_iterator
value
=
data
.
propertyValues
.
find
(
property
);
if
(
value
!=
data
.
propertyValues
.
end
())
return
value
->
second
;
return
ReferencePlatform
::
getPropertyValue
(
context
,
property
);
}
}
double
CpuPlatform
::
getSpeed
()
const
{
double
CpuPlatform
::
getSpeed
()
const
{
...
@@ -87,7 +105,11 @@ bool CpuPlatform::isProcessorSupported() {
...
@@ -87,7 +105,11 @@ bool CpuPlatform::isProcessorSupported() {
void
CpuPlatform
::
contextCreated
(
ContextImpl
&
context
,
const
map
<
string
,
string
>&
properties
)
const
{
void
CpuPlatform
::
contextCreated
(
ContextImpl
&
context
,
const
map
<
string
,
string
>&
properties
)
const
{
ReferencePlatform
::
contextCreated
(
context
,
properties
);
ReferencePlatform
::
contextCreated
(
context
,
properties
);
PlatformData
*
data
=
new
PlatformData
(
context
.
getSystem
().
getNumParticles
());
const
string
&
threadsPropValue
=
(
properties
.
find
(
CpuThreads
())
==
properties
.
end
()
?
getPropertyDefaultValue
(
CpuThreads
())
:
properties
.
find
(
CpuThreads
())
->
second
);
int
numThreads
;
stringstream
(
threadsPropValue
)
>>
numThreads
;
PlatformData
*
data
=
new
PlatformData
(
context
.
getSystem
().
getNumParticles
(),
numThreads
);
contextData
[
&
context
]
=
data
;
contextData
[
&
context
]
=
data
;
ReferenceConstraints
&
constraints
=
*
(
ReferenceConstraints
*
)
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
())
->
constraints
;
ReferenceConstraints
&
constraints
=
*
(
ReferenceConstraints
*
)
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
())
->
constraints
;
if
(
constraints
.
settle
!=
NULL
)
{
if
(
constraints
.
settle
!=
NULL
)
{
...
@@ -107,10 +129,17 @@ CpuPlatform::PlatformData& CpuPlatform::getPlatformData(ContextImpl& context) {
...
@@ -107,10 +129,17 @@ CpuPlatform::PlatformData& CpuPlatform::getPlatformData(ContextImpl& context) {
return
*
contextData
[
&
context
];
return
*
contextData
[
&
context
];
}
}
CpuPlatform
::
PlatformData
::
PlatformData
(
int
numParticles
)
:
posq
(
4
*
numParticles
)
{
const
CpuPlatform
::
PlatformData
&
CpuPlatform
::
getPlatformData
(
const
ContextImpl
&
context
)
{
int
numThreads
=
threads
.
getNumThreads
();
return
*
contextData
[
&
context
];
}
CpuPlatform
::
PlatformData
::
PlatformData
(
int
numParticles
,
int
numThreads
)
:
posq
(
4
*
numParticles
),
threads
(
numThreads
)
{
numThreads
=
threads
.
getNumThreads
();
threadForce
.
resize
(
numThreads
);
threadForce
.
resize
(
numThreads
);
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
threadForce
[
i
].
resize
(
4
*
numParticles
);
threadForce
[
i
].
resize
(
4
*
numParticles
);
isPeriodic
=
false
;
isPeriodic
=
false
;
stringstream
threadsProperty
;
threadsProperty
<<
numThreads
;
propertyValues
[
CpuThreads
()]
=
threadsProperty
.
str
();
}
}
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