Unverified Commit 3d62421b authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Fixed freeze when using multiple GPUs (#3668)

parent dd80fb3f
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2019 Stanford University and the Authors. *
* Portions copyright (c) 2019-2022 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -555,6 +555,10 @@ public:
* Get whether the worker thread has exited.
*/
bool isFinished();
/**
* Get whether the thread invoking this method is the worker thread.
*/
bool isCurrentThread();
/**
* Block until all tasks have finished executing and the worker thread is idle.
*/
......
......@@ -1812,6 +1812,7 @@ public:
double computeForceAndEnergy(bool includeForces, bool includeEnergy, int groups) {
if ((groups&(1<<force->getForceGroup())) == 0)
return 0;
if (!cc.getWorkThread().isCurrentThread())
cc.getWorkThread().flush();
Vec3 a, b, c;
cc.getPeriodicBoxVectors(a, b, c);
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2019-2021 Stanford University and the Authors. *
* Portions copyright (c) 2019-2022 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -716,6 +716,10 @@ bool ComputeContext::WorkThread::isFinished() {
return finished;
}
bool ComputeContext::WorkThread::isCurrentThread() {
return (pthread_self() == thread);
}
void ComputeContext::WorkThread::flush() {
pthread_mutex_lock(&queueLock);
while (!waiting)
......
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