Commit 91d56f74 authored by Peter Eastman's avatar Peter Eastman
Browse files

Prevent deadlock using CustomCPPForceImpl with multiple GPUs

parent 3b8df952
......@@ -8245,15 +8245,29 @@ void CommonCalcCustomCPPForceKernel::initialize(const System& system, CustomCPPF
addForcesKernel->addArg(cc.getLongForceBuffer());
addForcesKernel->addArg(cc.getAtomIndexArray());
forceGroupFlag = (1<<force.getOwner().getForceGroup());
if (cc.getNumContexts() == 1) {
cc.addPreComputation(new StartCalculationPreComputation(*this));
cc.addPostComputation(new AddForcesPostComputation(*this));
}
}
double CommonCalcCustomCPPForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
if (cc.getNumContexts() == 1) {
// This method does nothing. The actual calculation is started by the pre-computation, continued on
// the worker thread, and finished by the post-computation.
return 0;
}
// When using multiple GPUs, this method is itself called from the worker thread.
// Submitting additional tasks and waiting for them to complete would lead to
// a deadlock.
if (cc.getContextIndex() != 0)
return 0.0;
contextImpl.getPositions(positionsVec);
executeOnWorkerThread(includeForces);
return addForces(includeForces, includeEnergy, -1);
}
void CommonCalcCustomCPPForceKernel::beginComputation(bool includeForces, bool includeEnergy, int groups) {
......@@ -8290,6 +8304,7 @@ double CommonCalcCustomCPPForceKernel::addForces(bool includeForces, bool includ
// Wait until executeOnWorkerThread() is finished.
if (cc.getNumContexts() == 1)
cc.getWorkThread().flush();
// Add in the forces.
......
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