Commit d314e695 authored by peastman's avatar peastman
Browse files

Use C++11 style loops

parent 28b79b2f
...@@ -159,8 +159,8 @@ void CpuBondForce::assignBond(int bond, int thread, vector<int>& atomThread, vec ...@@ -159,8 +159,8 @@ void CpuBondForce::assignBond(int bond, int thread, vector<int>& atomThread, vec
if (atom != -1) if (atom != -1)
throw OpenMMException("CpuBondForce: Internal error: atoms assigned to threads incorrectly"); throw OpenMMException("CpuBondForce: Internal error: atoms assigned to threads incorrectly");
atom = thread; atom = thread;
for (set<int>::const_iterator iter = atomBonds[atom].begin(); iter != atomBonds[atom].end(); ++iter) for (int bond : atomBonds[atom])
candidateBonds.push_back(*iter); candidateBonds.push_back(bond);
} }
} }
......
...@@ -577,10 +577,10 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI ...@@ -577,10 +577,10 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI
for (int j = 0; j < atomsInBlock; j++) { for (int j = 0; j < atomsInBlock; j++) {
const set<int>& atomExclusions = (*exclusions)[sortedAtoms[firstIndex+j]]; const set<int>& atomExclusions = (*exclusions)[sortedAtoms[firstIndex+j]];
char mask = 1<<j; char mask = 1<<j;
for (set<int>::const_iterator iter = atomExclusions.begin(); iter != atomExclusions.end(); ++iter) { for (int exclusion : atomExclusions) {
map<int, char>::iterator thisAtomFlags = atomFlags.find(*iter); map<int, char>::iterator thisAtomFlags = atomFlags.find(exclusion);
if (thisAtomFlags == atomFlags.end()) if (thisAtomFlags == atomFlags.end())
atomFlags[*iter] = mask; atomFlags[exclusion] = mask;
else else
thisAtomFlags->second |= mask; thisAtomFlags->second |= mask;
} }
......
...@@ -447,9 +447,9 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex ...@@ -447,9 +447,9 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
fvec4 posI((float) atomCoordinates[i][0], (float) atomCoordinates[i][1], (float) atomCoordinates[i][2], 0.0f); fvec4 posI((float) atomCoordinates[i][0], (float) atomCoordinates[i][1], (float) atomCoordinates[i][2], 0.0f);
float scaledChargeI = (float) (ONE_4PI_EPS0*posq[4*i+3]); float scaledChargeI = (float) (ONE_4PI_EPS0*posq[4*i+3]);
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter) { for (int excluded : exclusions[i]) {
if (*iter > i) { if (excluded > i) {
int j = *iter; int j = excluded;
fvec4 deltaR; fvec4 deltaR;
fvec4 posJ((float) atomCoordinates[j][0], (float) atomCoordinates[j][1], (float) atomCoordinates[j][2], 0.0f); fvec4 posJ((float) atomCoordinates[j][0], (float) atomCoordinates[j][1], (float) atomCoordinates[j][2], 0.0f);
float r2; float r2;
......
...@@ -456,12 +456,12 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express ...@@ -456,12 +456,12 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
vector<bool> hasAssigned(powers.size(), false); vector<bool> hasAssigned(powers.size(), false);
exponents.push_back((int) fabs(exponent)); exponents.push_back((int) fabs(exponent));
names.push_back(name); names.push_back(name);
for (map<int, const ExpressionTreeNode*>::const_iterator iter = powers.begin(); iter != powers.end(); ++iter) { for (auto& power : powers) {
if (iter->first != exponent) { if (power.first != exponent) {
exponents.push_back(iter->first >= 0 ? iter->first : -iter->first); exponents.push_back(power.first >= 0 ? power.first : -power.first);
string name2 = prefix+context.intToString(temps.size()); string name2 = prefix+context.intToString(temps.size());
names.push_back(name2); names.push_back(name2);
temps.push_back(make_pair(*iter->second, name2)); temps.push_back(make_pair(*power.second, name2));
out << tempType << " " << name2 << " = 0.0f;\n"; out << tempType << " " << name2 << " = 0.0f;\n";
} }
} }
......
...@@ -184,8 +184,7 @@ void OpenCLBondedUtilities::initialize(const System& system) { ...@@ -184,8 +184,7 @@ void OpenCLBondedUtilities::initialize(const System& system) {
// Create the kernels. // Create the kernels.
for (vector<vector<int> >::const_iterator iter = forceSets.begin(); iter != forceSets.end(); ++iter) { for (auto& set : forceSets) {
const vector<int>& set = *iter;
int setSize = set.size(); int setSize = set.size();
stringstream s; stringstream s;
s<<"#ifdef SUPPORTS_64_BIT_ATOMICS\n"; s<<"#ifdef SUPPORTS_64_BIT_ATOMICS\n";
......
...@@ -448,12 +448,12 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre ...@@ -448,12 +448,12 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
vector<bool> hasAssigned(powers.size(), false); vector<bool> hasAssigned(powers.size(), false);
exponents.push_back((int) fabs(exponent)); exponents.push_back((int) fabs(exponent));
names.push_back(name); names.push_back(name);
for (map<int, const ExpressionTreeNode*>::const_iterator iter = powers.begin(); iter != powers.end(); ++iter) { for (auto& power : powers) {
if (iter->first != exponent) { if (power.first != exponent) {
exponents.push_back(iter->first >= 0 ? iter->first : -iter->first); exponents.push_back(power.first >= 0 ? power.first : -power.first);
string name2 = prefix+context.intToString(temps.size()); string name2 = prefix+context.intToString(temps.size());
names.push_back(name2); names.push_back(name2);
temps.push_back(make_pair(*iter->second, name2)); temps.push_back(make_pair(*power.second, name2));
out << tempType << " " << name2 << " = 0.0f;\n"; out << tempType << " " << name2 << " = 0.0f;\n";
} }
} }
......
...@@ -127,8 +127,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -127,8 +127,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
// We didn't find one, so look for an angle force field term. // We didn't find one, so look for an angle force field term.
const vector<int>& angleCandidates = atomAngles[atomb]; const vector<int>& angleCandidates = atomAngles[atomb];
for (vector<int>::const_iterator iter = angleCandidates.begin(); iter != angleCandidates.end(); iter++) { for (int candidate : angleCandidates) {
const AngleInfo& angle = angles[*iter]; const AngleInfo& angle = angles[candidate];
if ((angle.atom1 == atoma && angle.atom3 == atomc) || (angle.atom3 == atoma && angle.atom1 == atomc)) { if ((angle.atom1 == atoma && angle.atom3 == atomc) || (angle.atom3 == atoma && angle.atom1 == atomc)) {
matrix[j].push_back(pair<int, double>(k, scale*cos(angle.angle))); matrix[j].push_back(pair<int, double>(k, scale*cos(angle.angle)));
break; break;
......
...@@ -488,10 +488,10 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<Vec3>& a ...@@ -488,10 +488,10 @@ void ReferenceLJCoulombIxn::calculateEwaldIxn(int numberOfAtoms, vector<Vec3>& a
double totalExclusionEnergy = 0.0f; double totalExclusionEnergy = 0.0f;
const double TWO_OVER_SQRT_PI = 2/sqrt(PI_M); const double TWO_OVER_SQRT_PI = 2/sqrt(PI_M);
for (int i = 0; i < numberOfAtoms; i++) for (int i = 0; i < numberOfAtoms; i++)
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter) { for (int exclusion : exclusions[i]) {
if (*iter > i) { if (exclusion > i) {
int ii = i; int ii = i;
int jj = *iter; int jj = exclusion;
double deltaR[2][ReferenceForce::LastDeltaRIndex]; double deltaR[2][ReferenceForce::LastDeltaRIndex];
ReferenceForce::getDeltaR(atomCoordinates[jj], atomCoordinates[ii], deltaR[0]); ReferenceForce::getDeltaR(atomCoordinates[jj], atomCoordinates[ii], deltaR[0]);
......
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