Commit 32d3f86d authored by Peter Eastman's avatar Peter Eastman
Browse files

Release the Python global interpreter lock during expensive operations

parent 813e8ef6
......@@ -8,4 +8,24 @@
}
}
%exception *::step {
try {
Py_BEGIN_ALLOW_THREADS
$action
Py_END_ALLOW_THREADS
} catch (std::exception &e) {
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
return NULL;
}
}
%exception OpenMM::LocalEnergyMinimizer::minimize {
try {
Py_BEGIN_ALLOW_THREADS
$action
Py_END_ALLOW_THREADS
} catch (std::exception &e) {
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
return NULL;
}
}
......@@ -6,13 +6,16 @@
int getParameters,
int enforcePeriodic,
int groups) {
State state;
Py_BEGIN_ALLOW_THREADS
int types = 0;
if (getPositions) types |= State::Positions;
if (getVelocities) types |= State::Velocities;
if (getForces) types |= State::Forces;
if (getEnergy) types |= State::Energy;
if (getParameters) types |= State::Parameters;
State state = self->getState(types, enforcePeriodic, groups);
state = self->getState(types, enforcePeriodic, groups);
Py_END_ALLOW_THREADS
return _convertStateToLists(state);
}
......@@ -122,13 +125,16 @@ Parameters:
int getParameters,
int enforcePeriodic,
int groups) {
State state;
Py_BEGIN_ALLOW_THREADS
int types = 0;
if (getPositions) types |= State::Positions;
if (getVelocities) types |= State::Velocities;
if (getForces) types |= State::Forces;
if (getEnergy) types |= State::Energy;
if (getParameters) types |= State::Parameters;
State state = self->getState(copy, types, enforcePeriodic, groups);
state = self->getState(copy, types, enforcePeriodic, groups);
Py_END_ALLOW_THREADS
return _convertStateToLists(state);
}
......
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