"openmmapi/src/PythonForce.cpp" did not exist on "58b094cec72f74db91e131277804e82e168c16e0"
Commit 72bfef12 authored by peastman's avatar peastman
Browse files

Replaced gmx_atomic with C++ atomic

parent e72a4e8c
This diff is collapsed.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "openmm/internal/CompiledExpressionSet.h" #include "openmm/internal/CompiledExpressionSet.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include <atomic>
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -63,7 +64,7 @@ private: ...@@ -63,7 +64,7 @@ private:
const std::map<std::string, double>* globalParameters; const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce; std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy; bool includeForce, includeEnergy;
void* atomicCounter; std::atomic<int> atomicCounter;
/** /**
* This routine contains the code executed by each thread. * This routine contains the code executed by each thread.
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include "lepton/CompiledExpression.h" #include "lepton/CompiledExpression.h"
#include "lepton/ParsedExpression.h" #include "lepton/ParsedExpression.h"
#include <atomic>
#include <map> #include <map>
#include <set> #include <set>
#include <utility> #include <utility>
...@@ -69,7 +70,7 @@ private: ...@@ -69,7 +70,7 @@ private:
const std::map<std::string, double>* globalParameters; const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce; std::vector<AlignedArray<float> >* threadForce;
bool includeForces, includeEnergy; bool includeForces, includeEnergy;
void* atomicCounter; std::atomic<int> atomicCounter;
/** /**
* This routine contains the code executed by each thread. * This routine contains the code executed by each thread.
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "openmm/internal/CompiledExpressionSet.h" #include "openmm/internal/CompiledExpressionSet.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include <atomic>
#include <map> #include <map>
#include <set> #include <set>
#include <utility> #include <utility>
...@@ -147,7 +148,7 @@ private: ...@@ -147,7 +148,7 @@ private:
const std::map<std::string, double>* globalParameters; const std::map<std::string, double>* globalParameters;
std::vector<AlignedArray<float> >* threadForce; std::vector<AlignedArray<float> >* threadForce;
bool includeForce, includeEnergy; bool includeForce, includeEnergy;
void* atomicCounter; std::atomic<int> atomicCounter;
/** /**
* This routine contains the code executed by each thread. * This routine contains the code executed by each thread.
......
/* Portions copyright (c) 2006-2017 Stanford University and Simbios. /* Portions copyright (c) 2006-2018 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "AlignedArray.h" #include "AlignedArray.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include <atomic>
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -112,7 +113,7 @@ private: ...@@ -112,7 +113,7 @@ private:
float const* posq; float const* posq;
std::vector<AlignedArray<float> >* threadForce; std::vector<AlignedArray<float> >* threadForce;
bool includeEnergy; bool includeEnergy;
void* atomicCounter; std::atomic<int> atomicCounter;
static const int NUM_TABLE_POINTS; static const int NUM_TABLE_POINTS;
static const float TABLE_MIN; static const float TABLE_MIN;
......
...@@ -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) 2016-2017 Stanford University and the Authors. * * Portions copyright (c) 2016-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -91,7 +91,7 @@ private: ...@@ -91,7 +91,7 @@ private:
Vec3 const* positions; Vec3 const* positions;
std::vector<AlignedArray<float> >* threadForce; std::vector<AlignedArray<float> >* threadForce;
Vec3* boxVectors; Vec3* boxVectors;
void* atomicCounter; std::atomic<int> atomicCounter;
void computeEllipsoidFrames(const std::vector<Vec3>& positions); void computeEllipsoidFrames(const std::vector<Vec3>& positions);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2017 Stanford University and the Authors. * * Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#include "AlignedArray.h" #include "AlignedArray.h"
#include "openmm/Vec3.h" #include "openmm/Vec3.h"
#include "windowsExportCpu.h" #include "windowsExportCpu.h"
#include "openmm/internal/gmx_atomic.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include <atomic>
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -75,7 +75,7 @@ private: ...@@ -75,7 +75,7 @@ private:
int numAtoms; int numAtoms;
bool usePeriodic; bool usePeriodic;
float maxDistance; float maxDistance;
gmx_atomic_t atomicCounter; std::atomic<int> atomicCounter;
}; };
} // namespace OpenMM } // namespace OpenMM
......
/* Portions copyright (c) 2006-2017 Stanford University and Simbios. /* Portions copyright (c) 2006-2018 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "ReferencePairIxn.h" #include "ReferencePairIxn.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include <atomic>
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -200,7 +201,7 @@ protected: ...@@ -200,7 +201,7 @@ protected:
bool includeEnergy; bool includeEnergy;
float inverseRcut6; float inverseRcut6;
float inverseRcut6Expterm; float inverseRcut6Expterm;
void* atomicCounter; std::atomic<int> atomicCounter;
static const float TWO_OVER_SQRT_PI; static const float TWO_OVER_SQRT_PI;
static const int NUM_TABLE_POINTS; static const int NUM_TABLE_POINTS;
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "CpuCustomGBForce.h" #include "CpuCustomGBForce.h"
#include "openmm/internal/gmx_atomic.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -191,13 +190,11 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto ...@@ -191,13 +190,11 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto
this->includeForce = includeForce; this->includeForce = includeForce;
this->includeEnergy = includeEnergy; this->includeEnergy = includeEnergy;
threadEnergy.resize(threads.getNumThreads()); threadEnergy.resize(threads.getNumThreads());
gmx_atomic_t counter;
this->atomicCounter = &counter;
// Calculate the first computed value. // Calculate the first computed value.
auto task = [&] (ThreadPool& threads, int threadIndex) { threadComputeForce(threads, threadIndex); }; auto task = [&] (ThreadPool& threads, int threadIndex) { threadComputeForce(threads, threadIndex); };
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.execute(task); threads.execute(task);
threads.waitForThreads(); threads.waitForThreads();
...@@ -217,7 +214,7 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto ...@@ -217,7 +214,7 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto
// Calculate the energy terms. // Calculate the energy terms.
for (int i = 0; i < (int) threadData[0]->energyExpressions.size(); i++) { for (int i = 0; i < (int) threadData[0]->energyExpressions.size(); i++) {
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.execute(task); threads.execute(task);
threads.waitForThreads(); threads.waitForThreads();
} }
...@@ -229,7 +226,7 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto ...@@ -229,7 +226,7 @@ void CpuCustomGBForce::calculateIxn(int numberOfAtoms, float* posq, vector<vecto
// Apply the chain rule to evaluate forces. // Apply the chain rule to evaluate forces.
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); threads.waitForThreads();
...@@ -361,7 +358,7 @@ void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, i ...@@ -361,7 +358,7 @@ void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, i
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = atomicCounter++;
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
break; break;
const int blockSize = neighborList->getBlockSize(); const int blockSize = neighborList->getBlockSize();
...@@ -386,7 +383,7 @@ void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, i ...@@ -386,7 +383,7 @@ void CpuCustomGBForce::calculateParticlePairValue(int index, ThreadData& data, i
// Perform an O(N^2) loop over all atom pairs. // Perform an O(N^2) loop over all atom pairs.
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numAtoms) if (i >= numAtoms)
break; break;
for (int j = i+1; j < numAtoms; j++) { for (int j = i+1; j < numAtoms; j++) {
...@@ -456,7 +453,7 @@ void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& da ...@@ -456,7 +453,7 @@ void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& da
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = atomicCounter++;
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
break; break;
const int blockSize = neighborList->getBlockSize(); const int blockSize = neighborList->getBlockSize();
...@@ -480,7 +477,7 @@ void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& da ...@@ -480,7 +477,7 @@ void CpuCustomGBForce::calculateParticlePairEnergyTerm(int index, ThreadData& da
// Perform an O(N^2) loop over all atom pairs. // Perform an O(N^2) loop over all atom pairs.
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numAtoms) if (i >= numAtoms)
break; break;
for (int j = i+1; j < numAtoms; j++) { for (int j = i+1; j < numAtoms; j++) {
...@@ -543,7 +540,7 @@ void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms, ...@@ -543,7 +540,7 @@ void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms,
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = atomicCounter++;
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
break; break;
const int blockSize = neighborList->getBlockSize(); const int blockSize = neighborList->getBlockSize();
...@@ -567,7 +564,7 @@ void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms, ...@@ -567,7 +564,7 @@ void CpuCustomGBForce::calculateChainRuleForces(ThreadData& data, int numAtoms,
// Perform an O(N^2) loop over all atom pairs. // Perform an O(N^2) loop over all atom pairs.
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numAtoms) if (i >= numAtoms)
break; break;
for (int j = i+1; j < numAtoms; j++) { for (int j = i+1; j < numAtoms; j++) {
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "ReferenceTabulatedFunction.h" #include "ReferenceTabulatedFunction.h"
#include "openmm/internal/CustomManyParticleForceImpl.h" #include "openmm/internal/CustomManyParticleForceImpl.h"
#include "lepton/CustomFunction.h" #include "lepton/CustomFunction.h"
#include "openmm/internal/gmx_atomic.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -99,9 +98,7 @@ void CpuCustomManyParticleForce::calculateIxn(AlignedArray<float>& posq, vector< ...@@ -99,9 +98,7 @@ void CpuCustomManyParticleForce::calculateIxn(AlignedArray<float>& posq, vector<
this->threadForce = &threadForce; this->threadForce = &threadForce;
this->includeForces = includeForces; this->includeForces = includeForces;
this->includeEnergy = includeEnergy; this->includeEnergy = includeEnergy;
gmx_atomic_t counter; atomicCounter = 0;
gmx_atomic_set(&counter, 0);
this->atomicCounter = &counter;
if (useCutoff) { if (useCutoff) {
// Construct a neighbor list. We use CpuNeighborList to do this, but then copy the result // Construct a neighbor list. We use CpuNeighborList to do this, but then copy the result
// into a new data structure. This is needed because in UniqueCentralParticle mode, the // into a new data structure. This is needed because in UniqueCentralParticle mode, the
...@@ -156,7 +153,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr ...@@ -156,7 +153,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
// Loop over interactions from the neighbor list. // Loop over interactions from the neighbor list.
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numParticles) if (i >= numParticles)
break; break;
particleIndices[0] = i; particleIndices[0] = i;
...@@ -170,7 +167,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr ...@@ -170,7 +167,7 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
particles[i] = i; particles[i] = i;
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numParticles) if (i >= numParticles)
break; break;
particleIndices[0] = i; particleIndices[0] = i;
......
/* Portions copyright (c) 2009-2017 Stanford University and Simbios. /* Portions copyright (c) 2009-2018 Stanford University and Simbios.
* Contributors: Peter Eastman * Contributors: Peter Eastman
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "CpuCustomNonbondedForce.h" #include "CpuCustomNonbondedForce.h"
#include "openmm/internal/gmx_atomic.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -134,9 +133,7 @@ void CpuCustomNonbondedForce::calculatePairIxn(int numberOfAtoms, float* posq, v ...@@ -134,9 +133,7 @@ void CpuCustomNonbondedForce::calculatePairIxn(int numberOfAtoms, float* posq, v
this->includeForce = includeForce; this->includeForce = includeForce;
this->includeEnergy = includeEnergy; this->includeEnergy = includeEnergy;
threadEnergy.resize(threads.getNumThreads()); threadEnergy.resize(threads.getNumThreads());
gmx_atomic_t counter; atomicCounter = 0;
gmx_atomic_set(&counter, 0);
this->atomicCounter = &counter;
// Signal the threads to start running and wait for them to finish. // Signal the threads to start running and wait for them to finish.
...@@ -177,7 +174,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread ...@@ -177,7 +174,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread
// The user has specified interaction groups, so compute only the requested interactions. // The user has specified interaction groups, so compute only the requested interactions.
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= groupInteractions.size()) if (i >= groupInteractions.size())
break; break;
int atom1 = groupInteractions[i].first; int atom1 = groupInteractions[i].first;
...@@ -193,7 +190,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread ...@@ -193,7 +190,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread
// We are using a cutoff, so get the interactions from the neighbor list. // We are using a cutoff, so get the interactions from the neighbor list.
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = atomicCounter++;
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
break; break;
const int blockSize = neighborList->getBlockSize(); const int blockSize = neighborList->getBlockSize();
...@@ -219,7 +216,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread ...@@ -219,7 +216,7 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread
// Every particle interacts with every other one. // Every particle interacts with every other one.
while (true) { while (true) {
int ii = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int ii = atomicCounter++;
if (ii >= numberOfAtoms) if (ii >= numberOfAtoms)
break; break;
for (int jj = ii+1; jj < numberOfAtoms; jj++) { for (int jj = ii+1; jj < numberOfAtoms; jj++) {
......
/* Portions copyright (c) 2006-2017 Stanford University and Simbios. /* Portions copyright (c) 2006-2018 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "CpuGBSAOBCForce.h" #include "CpuGBSAOBCForce.h"
#include "SimTKOpenMMRealType.h" #include "SimTKOpenMMRealType.h"
#include "openmm/internal/vectorize.h" #include "openmm/internal/vectorize.h"
#include "openmm/internal/gmx_atomic.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
...@@ -95,21 +94,19 @@ void CpuGBSAOBCForce::computeForce(const AlignedArray<float>& posq, vector<Align ...@@ -95,21 +94,19 @@ void CpuGBSAOBCForce::computeForce(const AlignedArray<float>& posq, vector<Align
threadBornForces.resize(numThreads); threadBornForces.resize(numThreads);
for (int i = 0; i < numThreads; i++) for (int i = 0; i < numThreads; i++)
threadBornForces[i].resize(particleParams.size()+3); threadBornForces[i].resize(particleParams.size()+3);
gmx_atomic_t counter;
this->atomicCounter = &counter;
// Signal the threads to start running and wait for them to finish. // Signal the threads to start running and wait for them to finish.
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.execute([&] (ThreadPool& threads, int threadIndex) { threadComputeForce(threads, threadIndex); }); threads.execute([&] (ThreadPool& threads, int threadIndex) { threadComputeForce(threads, threadIndex); });
threads.waitForThreads(); // Compute Born radii threads.waitForThreads(); // Compute Born radii
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); // Compute surface area term threads.waitForThreads(); // Compute surface area term
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); // First loop threads.waitForThreads(); // First loop
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); // Second loop threads.waitForThreads(); // Second loop
...@@ -138,7 +135,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) { ...@@ -138,7 +135,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) {
// Calculate Born radii // Calculate Born radii
while (true) { while (true) {
int blockStart = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 4); int blockStart = atomicCounter.fetch_add(4);
if (blockStart >= numParticles) if (blockStart >= numParticles)
break; break;
int numInBlock = min(4, numParticles-blockStart); int numInBlock = min(4, numParticles-blockStart);
...@@ -215,7 +212,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) { ...@@ -215,7 +212,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) {
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
bornForces[i] = 0.0f; bornForces[i] = 0.0f;
while (true) { while (true) {
int atomI = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int atomI = atomicCounter++;
if (atomI >= numParticles) if (atomI >= numParticles)
break; break;
if (bornRadii[atomI] > 0) { if (bornRadii[atomI] > 0) {
...@@ -240,7 +237,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) { ...@@ -240,7 +237,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) {
else else
preFactor = 0.0f; preFactor = 0.0f;
while (true) { while (true) {
int blockStart = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 4); int blockStart = atomicCounter.fetch_add(4);
if (blockStart >= numParticles) if (blockStart >= numParticles)
break; break;
int numInBlock = min(4, numParticles-blockStart); int numInBlock = min(4, numParticles-blockStart);
...@@ -318,7 +315,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) { ...@@ -318,7 +315,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) {
// Second loop of Born energy computation. // Second loop of Born energy computation.
while (true) { while (true) {
int blockStart = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 4); int blockStart = atomicCounter.fetch_add(4);
if (blockStart >= numParticles) if (blockStart >= numParticles)
break; break;
fvec4 bornForce(0.0f); fvec4 bornForce(0.0f);
......
...@@ -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) 2016-2017 Stanford University and the Authors. * * Portions copyright (c) 2016-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/GayBerneForce.h" #include "openmm/GayBerneForce.h"
#include "openmm/internal/gmx_atomic.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
...@@ -120,9 +119,7 @@ double CpuGayBerneForce::calculateForce(const vector<Vec3>& positions, std::vect ...@@ -120,9 +119,7 @@ double CpuGayBerneForce::calculateForce(const vector<Vec3>& positions, std::vect
this->boxVectors = boxVectors; this->boxVectors = boxVectors;
threadEnergy.resize(numThreads); threadEnergy.resize(numThreads);
threadTorque.resize(numThreads); threadTorque.resize(numThreads);
gmx_atomic_t counter; atomicCounter = 0;
gmx_atomic_set(&counter, 0);
this->atomicCounter = &counter;
// Signal the threads to compute the pairwise interactions. // Signal the threads to compute the pairwise interactions.
...@@ -131,7 +128,7 @@ double CpuGayBerneForce::calculateForce(const vector<Vec3>& positions, std::vect ...@@ -131,7 +128,7 @@ double CpuGayBerneForce::calculateForce(const vector<Vec3>& positions, std::vect
// Signal the threads to compute exceptions. // Signal the threads to compute exceptions.
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); threads.waitForThreads();
...@@ -162,7 +159,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex, ...@@ -162,7 +159,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex,
if (neighborList == NULL) { if (neighborList == NULL) {
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numParticles) if (i >= numParticles)
break; break;
if (particles[i].sqrtEpsilon == 0.0f) if (particles[i].sqrtEpsilon == 0.0f)
...@@ -180,7 +177,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex, ...@@ -180,7 +177,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex,
} }
else { else {
while (true) { while (true) {
int blockIndex = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int blockIndex = atomicCounter++;
if (blockIndex >= neighborList->getNumBlocks()) if (blockIndex >= neighborList->getNumBlocks())
break; break;
const int blockSize = neighborList->getBlockSize(); const int blockSize = neighborList->getBlockSize();
...@@ -211,7 +208,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex, ...@@ -211,7 +208,7 @@ void CpuGayBerneForce::threadComputeForce(ThreadPool& threads, int threadIndex,
int numExceptions = exceptions.size(); int numExceptions = exceptions.size();
const int groupSize = max(1, numExceptions/(10*numThreads)); const int groupSize = max(1, numExceptions/(10*numThreads));
while (true) { while (true) {
int start = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), groupSize); int start = atomicCounter.fetch_add(groupSize);
if (start >= numExceptions) if (start >= numExceptions)
break; break;
int end = min(start+groupSize, numExceptions); int end = min(start+groupSize, numExceptions);
......
...@@ -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-2017 Stanford University and the Authors. * * Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -476,7 +476,7 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float ...@@ -476,7 +476,7 @@ void CpuNeighborList::computeNeighborList(int numAtoms, const AlignedArray<float
// Signal the threads to start running and wait for them to finish. // Signal the threads to start running and wait for them to finish.
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); threads.waitForThreads();
...@@ -538,7 +538,7 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI ...@@ -538,7 +538,7 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI
vector<float> blockAtomX(blockSize), blockAtomY(blockSize), blockAtomZ(blockSize); vector<float> blockAtomX(blockSize), blockAtomY(blockSize), blockAtomZ(blockSize);
vector<VoxelIndex> atomVoxelIndex; vector<VoxelIndex> atomVoxelIndex;
while (true) { while (true) {
int i = gmx_atomic_fetch_add(&atomicCounter, 1); int i = atomicCounter++;
if (i >= numBlocks) if (i >= numBlocks)
break; break;
......
/* Portions copyright (c) 2006-2017 Stanford University and Simbios. /* Portions copyright (c) 2006-2018 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "CpuNonbondedForce.h" #include "CpuNonbondedForce.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
#include "ReferencePME.h" #include "ReferencePME.h"
#include "openmm/internal/gmx_atomic.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
...@@ -389,9 +388,7 @@ void CpuNonbondedForce::calculateDirectIxn(int numberOfAtoms, float* posq, const ...@@ -389,9 +388,7 @@ void CpuNonbondedForce::calculateDirectIxn(int numberOfAtoms, float* posq, const
this->threadForce = &threadForce; this->threadForce = &threadForce;
includeEnergy = (totalEnergy != NULL); includeEnergy = (totalEnergy != NULL);
threadEnergy.resize(threads.getNumThreads()); threadEnergy.resize(threads.getNumThreads());
gmx_atomic_t counter; atomicCounter = 0;
gmx_atomic_set(&counter, 0);
this->atomicCounter = &counter;
// Signal the threads to start running and wait for them to finish. // Signal the threads to start running and wait for them to finish.
...@@ -401,7 +398,7 @@ void CpuNonbondedForce::calculateDirectIxn(int numberOfAtoms, float* posq, const ...@@ -401,7 +398,7 @@ void CpuNonbondedForce::calculateDirectIxn(int numberOfAtoms, float* posq, const
// Signal the threads to subtract the exclusions. // Signal the threads to subtract the exclusions.
if (ewald || pme) { if (ewald || pme) {
gmx_atomic_set(&counter, 0); atomicCounter = 0;
threads.resumeThreads(); threads.resumeThreads();
threads.waitForThreads(); threads.waitForThreads();
} }
...@@ -429,7 +426,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex ...@@ -429,7 +426,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
if (ewald || pme || ljpme) { if (ewald || pme || ljpme) {
// Compute the interactions from the neighbor list. // Compute the interactions from the neighbor list.
while (true) { while (true) {
int nextBlock = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int nextBlock = atomicCounter++;
if (nextBlock >= neighborList->getNumBlocks()) if (nextBlock >= neighborList->getNumBlocks())
break; break;
calculateBlockEwaldIxn(nextBlock, forces, energyPtr, boxSize, invBoxSize); calculateBlockEwaldIxn(nextBlock, forces, energyPtr, boxSize, invBoxSize);
...@@ -440,7 +437,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex ...@@ -440,7 +437,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
threads.syncThreads(); threads.syncThreads();
const int groupSize = max(1, numberOfAtoms/(10*numThreads)); const int groupSize = max(1, numberOfAtoms/(10*numThreads));
while (true) { while (true) {
int start = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), groupSize); int start = atomicCounter.fetch_add(groupSize);
if (start >= numberOfAtoms) if (start >= numberOfAtoms)
break; break;
int end = min(start+groupSize, numberOfAtoms); int end = min(start+groupSize, numberOfAtoms);
...@@ -490,7 +487,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex ...@@ -490,7 +487,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
// Compute the interactions from the neighbor list. // Compute the interactions from the neighbor list.
while (true) { while (true) {
int nextBlock = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int nextBlock = atomicCounter++;
if (nextBlock >= neighborList->getNumBlocks()) if (nextBlock >= neighborList->getNumBlocks())
break; break;
calculateBlockIxn(nextBlock, forces, energyPtr, boxSize, invBoxSize); calculateBlockIxn(nextBlock, forces, energyPtr, boxSize, invBoxSize);
...@@ -500,7 +497,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex ...@@ -500,7 +497,7 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
// Loop over all atom pairs // Loop over all atom pairs
while (true) { while (true) {
int i = gmx_atomic_fetch_add(reinterpret_cast<gmx_atomic_t*>(atomicCounter), 1); int i = atomicCounter++;
if (i >= numberOfAtoms) if (i >= numberOfAtoms)
break; break;
for (int j = i+1; j < numberOfAtoms; j++) for (int j = i+1; j < numberOfAtoms; j++)
......
...@@ -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-2017 Stanford University and the Authors. * * Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "CpuSETTLE.h" #include "CpuSETTLE.h"
#include "openmm/internal/gmx_atomic.h" #include <atomic>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
...@@ -61,11 +61,11 @@ CpuSETTLE::~CpuSETTLE() { ...@@ -61,11 +61,11 @@ CpuSETTLE::~CpuSETTLE() {
} }
void CpuSETTLE::apply(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3>& atomCoordinatesP, vector<double>& inverseMasses, double tolerance) { void CpuSETTLE::apply(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3>& atomCoordinatesP, vector<double>& inverseMasses, double tolerance) {
gmx_atomic_t atomicCounter; atomic<int> atomicCounter;
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.execute([&] (ThreadPool& threads, int threadIndex) { threads.execute([&] (ThreadPool& threads, int threadIndex) {
while (true) { while (true) {
int index = gmx_atomic_fetch_add(&atomicCounter, 1); int index = atomicCounter++;
if (index >= threadSettle.size()) if (index >= threadSettle.size())
break; break;
threadSettle[index]->apply(atomCoordinates, atomCoordinatesP, inverseMasses, tolerance); threadSettle[index]->apply(atomCoordinates, atomCoordinatesP, inverseMasses, tolerance);
...@@ -75,11 +75,11 @@ void CpuSETTLE::apply(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3 ...@@ -75,11 +75,11 @@ void CpuSETTLE::apply(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3
} }
void CpuSETTLE::applyToVelocities(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3>& velocities, vector<double>& inverseMasses, double tolerance) { void CpuSETTLE::applyToVelocities(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3>& velocities, vector<double>& inverseMasses, double tolerance) {
gmx_atomic_t atomicCounter; atomic<int> atomicCounter;
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.execute([&] (ThreadPool& threads, int threadIndex) { threads.execute([&] (ThreadPool& threads, int threadIndex) {
while (true) { while (true) {
int index = gmx_atomic_fetch_add(&atomicCounter, 1); int index = atomicCounter++;
if (index >= threadSettle.size()) if (index >= threadSettle.size())
break; break;
threadSettle[index]->applyToVelocities(atomCoordinates, velocities, inverseMasses, tolerance); threadSettle[index]->applyToVelocities(atomCoordinates, velocities, inverseMasses, tolerance);
......
...@@ -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-2017 Stanford University and the Authors. * * Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -52,7 +52,7 @@ bool CpuCalcDispersionPmeReciprocalForceKernel::hasInitializedThreads = false; ...@@ -52,7 +52,7 @@ bool CpuCalcDispersionPmeReciprocalForceKernel::hasInitializedThreads = false;
int CpuCalcDispersionPmeReciprocalForceKernel::numThreads = 0; int CpuCalcDispersionPmeReciprocalForceKernel::numThreads = 0;
static void spreadCharge(float* posq, float* grid, int gridx, int gridy, int gridz, int numParticles, Vec3* periodicBoxVectors, Vec3* recipBoxVectors, static void spreadCharge(float* posq, float* grid, int gridx, int gridy, int gridz, int numParticles, Vec3* periodicBoxVectors, Vec3* recipBoxVectors,
gmx_atomic_t& atomicCounter, const float epsilonFactor, int threadIndex, int numThreads, bool deterministic) { atomic<int>& atomicCounter, const float epsilonFactor, int threadIndex, int numThreads, bool deterministic) {
float temp[4]; float temp[4];
fvec4 boxSize((float) periodicBoxVectors[0][0], (float) periodicBoxVectors[1][1], (float) periodicBoxVectors[2][2], 0); fvec4 boxSize((float) periodicBoxVectors[0][0], (float) periodicBoxVectors[1][1], (float) periodicBoxVectors[2][2], 0);
fvec4 invBoxSize((float) recipBoxVectors[0][0], (float) recipBoxVectors[1][1], (float) recipBoxVectors[2][2], 0); fvec4 invBoxSize((float) recipBoxVectors[0][0], (float) recipBoxVectors[1][1], (float) recipBoxVectors[2][2], 0);
...@@ -69,7 +69,7 @@ static void spreadCharge(float* posq, float* grid, int gridx, int gridy, int gri ...@@ -69,7 +69,7 @@ static void spreadCharge(float* posq, float* grid, int gridx, int gridy, int gri
int i = threadIndex; int i = threadIndex;
while (true) { while (true) {
if (!deterministic) if (!deterministic)
i = gmx_atomic_fetch_add(&atomicCounter, 1); i = atomicCounter++;
if (i >= numParticles) if (i >= numParticles)
break; break;
...@@ -310,7 +310,7 @@ static void reciprocalConvolution(int start, int end, fftwf_complex* grid, vecto ...@@ -310,7 +310,7 @@ static void reciprocalConvolution(int start, int end, fftwf_complex* grid, vecto
} }
} }
static void interpolateForces(float* posq, float* force, float* grid, int gridx, int gridy, int gridz, int numParticles, Vec3* periodicBoxVectors, Vec3* recipBoxVectors, gmx_atomic_t& atomicCounter, const float epsilonFactor) { static void interpolateForces(float* posq, float* force, float* grid, int gridx, int gridy, int gridz, int numParticles, Vec3* periodicBoxVectors, Vec3* recipBoxVectors, atomic<int>& atomicCounter, const float epsilonFactor) {
fvec4 boxSize((float) periodicBoxVectors[0][0], (float) periodicBoxVectors[1][1], (float) periodicBoxVectors[2][2], 0); fvec4 boxSize((float) periodicBoxVectors[0][0], (float) periodicBoxVectors[1][1], (float) periodicBoxVectors[2][2], 0);
fvec4 invBoxSize((float) recipBoxVectors[0][0], (float) recipBoxVectors[1][1], (float) recipBoxVectors[2][2], 0); fvec4 invBoxSize((float) recipBoxVectors[0][0], (float) recipBoxVectors[1][1], (float) recipBoxVectors[2][2], 0);
fvec4 recipBoxVec0((float) recipBoxVectors[0][0], (float) recipBoxVectors[0][1], (float) recipBoxVectors[0][2], 0); fvec4 recipBoxVec0((float) recipBoxVectors[0][0], (float) recipBoxVectors[0][1], (float) recipBoxVectors[0][2], 0);
...@@ -321,7 +321,7 @@ static void interpolateForces(float* posq, float* force, float* grid, int gridx, ...@@ -321,7 +321,7 @@ static void interpolateForces(float* posq, float* force, float* grid, int gridx,
fvec4 one(1); fvec4 one(1);
fvec4 scale(1.0f/(PME_ORDER-1)); fvec4 scale(1.0f/(PME_ORDER-1));
while (true) { while (true) {
int i = gmx_atomic_fetch_add(&atomicCounter, 1); int i = atomicCounter++;
if (i >= numParticles) if (i >= numParticles)
break; break;
...@@ -545,7 +545,7 @@ void CpuCalcPmeReciprocalForceKernel::runMainThread() { ...@@ -545,7 +545,7 @@ void CpuCalcPmeReciprocalForceKernel::runMainThread() {
if (isDeleted) if (isDeleted)
break; break;
posq = io->getPosq(); posq = io->getPosq();
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.execute([&] (ThreadPool& threads, int threadIndex) { runWorkerThread(threads, threadIndex); }); // Signal threads to perform charge spreading. threads.execute([&] (ThreadPool& threads, int threadIndex) { runWorkerThread(threads, threadIndex); }); // Signal threads to perform charge spreading.
threads.waitForThreads(); threads.waitForThreads();
threads.resumeThreads(); // Signal threads to sum the charge grids. threads.resumeThreads(); // Signal threads to sum the charge grids.
...@@ -564,7 +564,7 @@ void CpuCalcPmeReciprocalForceKernel::runMainThread() { ...@@ -564,7 +564,7 @@ void CpuCalcPmeReciprocalForceKernel::runMainThread() {
threads.resumeThreads(); // Signal threads to perform reciprocal convolution. threads.resumeThreads(); // Signal threads to perform reciprocal convolution.
threads.waitForThreads(); threads.waitForThreads();
fftwf_execute_dft_c2r(backwardFFT, complexGrid, realGrid); fftwf_execute_dft_c2r(backwardFFT, complexGrid, realGrid);
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.resumeThreads(); // Signal threads to interpolate forces. threads.resumeThreads(); // Signal threads to interpolate forces.
threads.waitForThreads(); threads.waitForThreads();
isFinished = true; isFinished = true;
...@@ -837,7 +837,7 @@ void CpuCalcDispersionPmeReciprocalForceKernel::runMainThread() { ...@@ -837,7 +837,7 @@ void CpuCalcDispersionPmeReciprocalForceKernel::runMainThread() {
break; break;
posq = io->getPosq(); posq = io->getPosq();
ComputeTask task(*this); ComputeTask task(*this);
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.execute(task); // Signal threads to perform charge spreading. threads.execute(task); // Signal threads to perform charge spreading.
threads.waitForThreads(); threads.waitForThreads();
threads.resumeThreads(); // Signal threads to sum the charge grids. threads.resumeThreads(); // Signal threads to sum the charge grids.
...@@ -856,7 +856,7 @@ void CpuCalcDispersionPmeReciprocalForceKernel::runMainThread() { ...@@ -856,7 +856,7 @@ void CpuCalcDispersionPmeReciprocalForceKernel::runMainThread() {
threads.resumeThreads(); // Signal threads to perform reciprocal convolution. threads.resumeThreads(); // Signal threads to perform reciprocal convolution.
threads.waitForThreads(); threads.waitForThreads();
fftwf_execute_dft_c2r(backwardFFT, complexGrid, realGrid); fftwf_execute_dft_c2r(backwardFFT, complexGrid, realGrid);
gmx_atomic_set(&atomicCounter, 0); atomicCounter = 0;
threads.resumeThreads(); // Signal threads to interpolate forces. threads.resumeThreads(); // Signal threads to interpolate forces.
threads.waitForThreads(); threads.waitForThreads();
isFinished = true; isFinished = true;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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-2017 Stanford University and the Authors. * * Portions copyright (c) 2013-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
#include "internal/windowsExportPme.h" #include "internal/windowsExportPme.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include "openmm/Vec3.h" #include "openmm/Vec3.h"
#include "openmm/internal/gmx_atomic.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include <atomic>
#include <fftw3.h> #include <fftw3.h>
#include <pthread.h> #include <pthread.h>
#include <vector> #include <vector>
...@@ -132,7 +132,7 @@ private: ...@@ -132,7 +132,7 @@ private:
float* posq; float* posq;
Vec3 periodicBoxVectors[3], recipBoxVectors[3]; Vec3 periodicBoxVectors[3], recipBoxVectors[3];
bool includeEnergy; bool includeEnergy;
gmx_atomic_t atomicCounter; std::atomic<int> atomicCounter;
}; };
...@@ -226,7 +226,7 @@ private: ...@@ -226,7 +226,7 @@ private:
float* posq; float* posq;
Vec3 periodicBoxVectors[3], recipBoxVectors[3]; Vec3 periodicBoxVectors[3], recipBoxVectors[3];
bool includeEnergy; bool includeEnergy;
gmx_atomic_t atomicCounter; std::atomic<int> atomicCounter;
}; };
} // namespace OpenMM } // namespace OpenMM
......
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