From: Roland Schulz Date: Wed, 6 Feb 2019 00:08:49 +0000 (-0800) Subject: Revert size to be unsigned for ArrayRef X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=55c76c88c4d65b5f2e9da8cda311bb4e90691980;p=alexxy%2Fgromacs.git Revert size to be unsigned for ArrayRef Given the decision for std::span to be signed this became inconsistent with future C++ while already being inconsistent with std::vector. The goal of the original change, to have signed variables for all arithmetic including loop indices, can be achieve by using ssize everwhere arithmethic is used. ssize is both available as free function (also for std::vector) and member function. Related #2826 Change-Id: Icc5d0f9561c610cbce34c575d268171e9890ca9c --- diff --git a/docs/dev-manual/language-features.rst b/docs/dev-manual/language-features.rst index 0caf0b7163..9967416dfc 100644 --- a/docs/dev-manual/language-features.rst +++ b/docs/dev-manual/language-features.rst @@ -62,6 +62,8 @@ a release. ``dynamic_cast``. For emphasizing type (e.g. intentional integer division) use constructor syntax. For creating real constants use the user-defined literal _real (e.g. 2.5_real instead of static_cast(2.5)). +* Use signed integers for arithmetic (including loop indices). Use ssize + (available as free function and member of ArrayRef) to avoid casting. * Avoid overloading functions unless all variants really do the same thing, just with different types. Instead, consider making the function names more descriptive. diff --git a/src/gromacs/awh/biasstate.cpp b/src/gromacs/awh/biasstate.cpp index 26ac4af4f3..8145e4d5e6 100644 --- a/src/gromacs/awh/biasstate.cpp +++ b/src/gromacs/awh/biasstate.cpp @@ -77,7 +77,7 @@ namespace gmx void BiasState::getPmf(gmx::ArrayRef pmf) const { - GMX_ASSERT(pmf.size() == index(points_.size()), "pmf should have the size of the bias grid"); + GMX_ASSERT(pmf.size() == points_.size(), "pmf should have the size of the bias grid"); /* The PMF is just the negative of the log of the sampled PMF histogram. * Points with zero target weight are ignored, they will mostly contain noise. @@ -171,7 +171,7 @@ void sumPmf(gmx::ArrayRef pointState, /* Take log again to get (non-normalized) PMF */ double normFac = 1.0/numSharedUpdate; - for (gmx::index i = 0; i < pointState.size(); i++) + for (gmx::index i = 0; i < pointState.ssize(); i++) { if (pointState[i].inTargetRegion()) { @@ -493,7 +493,7 @@ double BiasState::moveUmbrella(const std::vector &dimParams, at steps when the reference value has been moved. E.g. if the ref. value is set every step to (coord dvalue +/- delta) would give zero force. */ - for (gmx::index d = 0; d < biasForce.size(); d++) + for (gmx::index d = 0; d < biasForce.ssize(); d++) { /* Average of the current and new force */ biasForce[d] = 0.5*(biasForce[d] + newForce[d]); @@ -796,7 +796,7 @@ void labelCoveredPoints(const std::vector &visited, int coverRadius, gmx::ArrayRef covered) { - GMX_ASSERT(covered.size() >= numPoints, "covered should be at least as large as the grid"); + GMX_ASSERT(covered.ssize() >= numPoints, "covered should be at least as large as the grid"); bool haveFirstNotVisited = false; int firstNotVisited = -1; diff --git a/src/gromacs/awh/biaswriter.cpp b/src/gromacs/awh/biaswriter.cpp index d31ac315c1..e6e605ea4e 100644 --- a/src/gromacs/awh/biaswriter.cpp +++ b/src/gromacs/awh/biaswriter.cpp @@ -221,14 +221,14 @@ static void normalizeBlock(AwhEnergyBlock *block, const Bias &bias) break; case Normalization::FreeEnergy: /* Normalize free energy values by subtracting the minimum value */ - for (gmx::index index = 0; index < data.size(); index++) + for (gmx::index index = 0; index < data.ssize(); index++) { if (bias.state().points()[index].inTargetRegion() && data[index] < minValue) { minValue = data[index]; } } - for (gmx::index index = 0; index < data.size(); index++) + for (gmx::index index = 0; index < data.ssize(); index++) { if (bias.state().points()[index].inTargetRegion()) { @@ -263,7 +263,7 @@ void BiasWriter::transferMetaDataToWriter(gmx::index metaDataIndex, const Bias &bias) { gmx::ArrayRef data = block_[getVarStartBlock(AwhOutputEntryType::MetaData)].data(); - GMX_ASSERT(metaDataIndex < data.size(), "Attempt to transfer AWH meta data to block for index out of range"); + GMX_ASSERT(metaDataIndex < data.ssize(), "Attempt to transfer AWH meta data to block for index out of range"); /* Transfer the point data of this variable to the right block(s) */ switch (metaDataType) diff --git a/src/gromacs/awh/coordstate.cpp b/src/gromacs/awh/coordstate.cpp index 8173431b96..29ebe7d7c3 100644 --- a/src/gromacs/awh/coordstate.cpp +++ b/src/gromacs/awh/coordstate.cpp @@ -109,7 +109,7 @@ int getSampleFromDistribution(ArrayRef distr, cumulativeDistribution[0] = distr[0]; - for (gmx::index i = 1; i < distr.size(); i++) + for (gmx::index i = 1; i < distr.ssize(); i++) { cumulativeDistribution[i] = cumulativeDistribution[i - 1] + distr[i]; } diff --git a/src/gromacs/awh/correlationhistory.cpp b/src/gromacs/awh/correlationhistory.cpp index 195e3d265e..aa36bb3e5c 100644 --- a/src/gromacs/awh/correlationhistory.cpp +++ b/src/gromacs/awh/correlationhistory.cpp @@ -134,7 +134,7 @@ void updateCorrelationGridHistory(CorrelationGridHistory *correlationGridHistory } } - GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.size(), "We should store exactly as many elements as the buffer size"); + GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.ssize(), "We should store exactly as many elements as the buffer size"); } void CorrelationBlockData::restoreFromHistory(const CorrelationBlockDataHistory &blockHistory, diff --git a/src/gromacs/awh/correlationtensor.h b/src/gromacs/awh/correlationtensor.h index 0072d49b94..6d2716e5d6 100644 --- a/src/gromacs/awh/correlationtensor.h +++ b/src/gromacs/awh/correlationtensor.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -116,7 +116,7 @@ class CorrelationBlockData void addData(double weight, gmx::ArrayRef data) { - GMX_ASSERT(data.size() == gmx::index(coordData_.size()), "Size of data should match the size of coordData"); + GMX_ASSERT(data.size() == coordData_.size(), "Size of data should match the size of coordData"); blockSumWeight_ += weight; blockSumSquareWeight_ += weight*weight; diff --git a/src/gromacs/awh/tests/biasstate.cpp b/src/gromacs/awh/tests/biasstate.cpp index 2d65d5be68..1dae643d0f 100644 --- a/src/gromacs/awh/tests/biasstate.cpp +++ b/src/gromacs/awh/tests/biasstate.cpp @@ -159,7 +159,7 @@ TEST_P(BiasStateTest, InitializesFromFile) * The target is (index + 1)/120. */ double msdPmf = 0; - for (index i = 0; i < points.size(); i++) + for (index i = 0; i < points.ssize(); i++) { msdPmf += gmx::square(points[i].logPmfSum() - points[0].logPmfSum() + 0.5*i) / points.size(); EXPECT_DOUBLE_EQ(points[i].target(), (i + 1)/120.0); diff --git a/src/gromacs/domdec/collect.cpp b/src/gromacs/domdec/collect.cpp index 5b9c6d5c07..1091872a53 100644 --- a/src/gromacs/domdec/collect.cpp +++ b/src/gromacs/domdec/collect.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -119,7 +119,7 @@ static void dd_collect_cg(gmx_domdec_t *dd, fprintf(debug, "Initial charge group distribution: "); for (int rank = 0; rank < dd->nnodes; rank++) { - fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.size()); + fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.ssize()); } fprintf(debug, "\n"); } diff --git a/src/gromacs/domdec/domdec_topology.cpp b/src/gromacs/domdec/domdec_topology.cpp index 1e9b1c4ef8..23b7bce5ef 100644 --- a/src/gromacs/domdec/domdec_topology.cpp +++ b/src/gromacs/domdec/domdec_topology.cpp @@ -1141,7 +1141,7 @@ static void combine_blocka(t_blocka *dest, dest->nalloc_a = over_alloc_large(dest->nra+na); srenew(dest->a, dest->nalloc_a); } - for (gmx::index s = 1; s < src.size(); s++) + for (gmx::index s = 1; s < src.ssize(); s++) { for (int i = dest->nr + 1; i < src[s].excl.nr + 1; i++) { @@ -1168,7 +1168,7 @@ static void combine_idef(t_idef *dest, for (ftype = 0; ftype < F_NRE; ftype++) { int n = 0; - for (gmx::index s = 1; s < src.size(); s++) + for (gmx::index s = 1; s < src.ssize(); s++) { n += src[s].idef.il[ftype].nr; } @@ -1190,7 +1190,7 @@ static void combine_idef(t_idef *dest, const int nral1 = 1 + NRAL(ftype); const int ftv = ftype - c_ftypeVsiteStart; - for (gmx::index s = 1; s < src.size(); s++) + for (gmx::index s = 1; s < src.ssize(); s++) { const t_ilist &ils = src[s].idef.il[ftype]; @@ -1226,12 +1226,12 @@ static void combine_idef(t_idef *dest, } /* Set nposres to the number of original position restraints in dest */ - for (gmx::index s = 1; s < src.size(); s++) + for (gmx::index s = 1; s < src.ssize(); s++) { nposres -= src[s].idef.il[ftype].nr/2; } - for (gmx::index s = 1; s < src.size(); s++) + for (gmx::index s = 1; s < src.ssize(); s++) { const t_iparams *iparams_src = (ftype == F_POSRES ? src[s].idef.iparams_posres : src[s].idef.iparams_fbposres); @@ -1788,7 +1788,7 @@ static void make_exclusions_zone(gmx_domdec_t *dd, gmx_domdec_zones_t *zones, if (isExcludedAtom) { - if (n + intermolecularExclusionGroup.size() > lexcls->nalloc_a) + if (n + intermolecularExclusionGroup.ssize() > lexcls->nalloc_a) { lexcls->nalloc_a = over_alloc_large(n + intermolecularExclusionGroup.size()); diff --git a/src/gromacs/domdec/partition.cpp b/src/gromacs/domdec/partition.cpp index 3a1ea5a7dc..701556db2d 100644 --- a/src/gromacs/domdec/partition.cpp +++ b/src/gromacs/domdec/partition.cpp @@ -456,7 +456,7 @@ static void restoreAtomGroups(gmx_domdec_t *dd, /* Copy back the global charge group indices from state * and rebuild the local charge group to atom index. */ - for (gmx::index i = 0; i < atomGroupsState.size(); i++) + for (gmx::index i = 0; i < atomGroupsState.ssize(); i++) { const int atomGroupGlobal = atomGroupsState[i]; const int groupSize = gcgs_index[atomGroupGlobal + 1] - gcgs_index[atomGroupGlobal]; @@ -2632,7 +2632,7 @@ orderVector(gmx::ArrayRef sort, gmx::ArrayRef vectorToSort, std::vector *workVector) { - if (gmx::index(workVector->size()) < sort.size()) + if (gmx::index(workVector->size()) < sort.ssize()) { workVector->resize(sort.size()); } @@ -2844,7 +2844,7 @@ static void dd_sort_state(gmx_domdec_t *dd, rvec *cgcm, t_forcerec *fr, t_state /* Reorder the state */ gmx::ArrayRef cgsort = sort->sorted; - GMX_RELEASE_ASSERT(cgsort.size() == dd->ncg_home, "We should sort all the home atom groups"); + GMX_RELEASE_ASSERT(cgsort.ssize() == dd->ncg_home, "We should sort all the home atom groups"); if (state->flags & (1 << estX)) { @@ -2899,7 +2899,7 @@ static void dd_sort_state(gmx_domdec_t *dd, rvec *cgcm, t_forcerec *fr, t_state else { /* Copy the sorted ns cell indices back to the ns grid struct */ - for (gmx::index i = 0; i < cgsort.size(); i++) + for (gmx::index i = 0; i < cgsort.ssize(); i++) { fr->ns->grid->cell_index[i] = cgsort[i].nsc; } diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index 5a6d9bbbdf..f8ade235a7 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -90,7 +90,7 @@ copyMovedAtomsToBufferPerAtom(gmx::ArrayRef move, { int pos_vec[DIM*2] = { 0 }; - for (int g = 0; g < move.size(); g++) + for (int g = 0; g < move.ssize(); g++) { const auto atomGroup = atomGroups.block(g); /* Skip moved atoms */ @@ -117,7 +117,7 @@ copyMovedChargeGroupCogs(gmx::ArrayRef move, { int pos_vec[DIM*2] = { 0 }; - for (int g = 0; g < move.size(); g++) + for (int g = 0; g < move.ssize(); g++) { const auto atomGroup = atomGroups.block(g); /* Skip moved atoms */ @@ -138,7 +138,7 @@ copyMovedUpdateGroupCogs(gmx::ArrayRef move, { int pos_vec[DIM*2] = { 0 }; - for (int g = 0; g < move.size(); g++) + for (int g = 0; g < move.ssize(); g++) { /* Skip moved atoms */ const int m = move[g]; @@ -162,7 +162,7 @@ static void clear_and_mark_ind(gmx::ArrayRef move, char *bLocalCG, int *cell_index) { - for (int g = 0; g < move.size(); g++) + for (int g = 0; g < move.ssize(); g++) { if (move[g] >= 0) { diff --git a/src/gromacs/ewald/tests/pmetestcommon.cpp b/src/gromacs/ewald/tests/pmetestcommon.cpp index 625a077afa..c3fe624c5c 100644 --- a/src/gromacs/ewald/tests/pmetestcommon.cpp +++ b/src/gromacs/ewald/tests/pmetestcommon.cpp @@ -178,7 +178,7 @@ PmeSafePointer pmeInitAtoms(const t_inputrec *inputRec, ) { const index atomCount = coordinates.size(); - GMX_RELEASE_ASSERT(atomCount == charges.size(), "Mismatch in atom data"); + GMX_RELEASE_ASSERT(atomCount == charges.ssize(), "Mismatch in atom data"); PmeSafePointer pmeSafe = pmeInitInternal(inputRec, mode, gpuInfo, pmeGpuProgram, atomCount, box); pme_atomcomm_t *atc = nullptr; @@ -381,7 +381,7 @@ void pmePerformGather(gmx_pme_t *pme, CodePath mode, { pme_atomcomm_t *atc = &(pme->atc[0]); const index atomCount = atc->n; - GMX_RELEASE_ASSERT(forces.size() == atomCount, "Invalid force buffer size"); + GMX_RELEASE_ASSERT(forces.ssize() == atomCount, "Invalid force buffer size"); const bool forceReductionWithInput = (inputTreatment == PmeForceOutputHandling::ReduceWithInput); const real scale = 1.0; const size_t threadIndex = 0; @@ -447,7 +447,7 @@ void pmeSetSplineData(const gmx_pme_t *pme, CodePath mode, const index atomCount = atc->n; const index pmeOrder = pme->pme_order; const index dimSize = pmeOrder * atomCount; - GMX_RELEASE_ASSERT(dimSize == splineValues.size(), "Mismatch in spline data"); + GMX_RELEASE_ASSERT(dimSize == splineValues.ssize(), "Mismatch in spline data"); real *splineBuffer = pmeGetSplineDataInternal(pme, type, dimIndex); switch (mode) @@ -472,7 +472,7 @@ void pmeSetGridLineIndices(const gmx_pme_t *pme, CodePath mode, { const pme_atomcomm_t *atc = &(pme->atc[0]); const index atomCount = atc->n; - GMX_RELEASE_ASSERT(atomCount == gridLineIndices.size(), "Mismatch in gridline indices size"); + GMX_RELEASE_ASSERT(atomCount == gridLineIndices.ssize(), "Mismatch in gridline indices size"); IVec paddedGridSizeUnused, gridSize(0, 0, 0); pmeGetRealGridSizesInternal(pme, mode, gridSize, paddedGridSizeUnused); diff --git a/src/gromacs/fileio/readinp.cpp b/src/gromacs/fileio/readinp.cpp index 0e170aea55..0945a2ef48 100644 --- a/src/gromacs/fileio/readinp.cpp +++ b/src/gromacs/fileio/readinp.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -282,7 +282,7 @@ int search_einp(gmx::ArrayRef inp, const char *name) { return -1; } - for (gmx::index i = 0; i < inp.size(); i++) + for (gmx::index i = 0; i < inp.ssize(); i++) { if (gmx_strcasecmp_min(name, inp[i].name_.c_str()) == 0) { diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index ee1b2d2e7a..d3a7b7d12b 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -1297,7 +1297,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t gmx_tng, tng_num_particles_get(tng, &nAtoms); - if (nAtoms == ind.size()) + if (nAtoms == ind.ssize()) { return; } @@ -1307,7 +1307,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t gmx_tng, { tng_molecule_num_atoms_get(tng, mol, &nAtoms); tng_molecule_cnt_get(tng, mol, &cnt); - if (nAtoms == ind.size()) + if (nAtoms == ind.ssize()) { stat = TNG_SUCCESS; } @@ -1323,7 +1323,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t gmx_tng, tng_molecule_name_set(tng, mol, name); tng_molecule_chain_add(tng, mol, "", &chain); - for (int i = 0; i < ind.size(); i++) + for (int i = 0; i < ind.ssize(); i++) { char temp_name[256], temp_type[256]; diff --git a/src/gromacs/gmxana/gmx_densorder.cpp b/src/gromacs/gmxana/gmx_densorder.cpp index 2518095ca8..6180386555 100644 --- a/src/gromacs/gmxana/gmx_densorder.cpp +++ b/src/gromacs/gmxana/gmx_densorder.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -775,7 +775,7 @@ int gmx_densorder(int argc, char *argv[]) gmx::ArrayRef graphFiles = opt2fns("-og", NFILE, fnm); if (graphFiles.size() != 2) { - gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.size()); + gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.ssize()); } writesurftoxpms(surf1, surf2, tblock, xslices, yslices, zslices, binw, binwz, graphFiles, zslices); } @@ -790,7 +790,7 @@ int gmx_densorder(int argc, char *argv[]) gmx::ArrayRef rawFiles = opt2fns("-or", NFILE, fnm); if (rawFiles.size() != 2) { - gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.size()); + gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.ssize()); } writeraw(surf1, surf2, tblock, xslices, yslices, rawFiles, oenv); } @@ -803,7 +803,7 @@ int gmx_densorder(int argc, char *argv[]) if (spectra.size() != 2) { gmx_fatal(FARGS, "No or not correct number (2) of output-file-series: %td", - spectra.size()); + spectra.ssize()); } powerspectavg_intf(surf1, surf2, tblock, xslices, yslices, spectra); } diff --git a/src/gromacs/gmxana/gmx_eneconv.cpp b/src/gromacs/gmxana/gmx_eneconv.cpp index fd439e1003..394c343fb9 100644 --- a/src/gromacs/gmxana/gmx_eneconv.cpp +++ b/src/gromacs/gmxana/gmx_eneconv.cpp @@ -123,10 +123,10 @@ static int *select_it(int nre, gmx_enxnm_t *nm, int *nset) static void sort_files(gmx::ArrayRef files, real *settime) { - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { gmx::index minidx = i; - for (gmx::index j = i + 1; j < files.size(); j++) + for (gmx::index j = i + 1; j < files.ssize(); j++) { if (settime[j] < settime[minidx]) { @@ -244,7 +244,7 @@ static void edit_files(gmx::ArrayRef files, real *readtime, fprintf(stderr, " File Current start New start\n" "---------------------------------------------------------\n"); - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { fprintf(stderr, "%25s %10.3f ", files[i].c_str(), readtime[i]); ok = FALSE; @@ -295,7 +295,7 @@ static void edit_files(gmx::ArrayRef files, real *readtime, } else { - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { settime[i] = readtime[i]; } @@ -315,7 +315,7 @@ static void edit_files(gmx::ArrayRef files, real *readtime, fprintf(stderr, "\nSummary of files and start times used:\n\n" " File Start time\n" "-----------------------------------------\n"); - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { switch (cont_type[i]) { diff --git a/src/gromacs/gmxana/gmx_hydorder.cpp b/src/gromacs/gmxana/gmx_hydorder.cpp index 44e84d3480..2b2ce9572c 100644 --- a/src/gromacs/gmxana/gmx_hydorder.cpp +++ b/src/gromacs/gmxana/gmx_hydorder.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -665,7 +665,7 @@ int gmx_hydorder(int argc, char *argv[]) gmx::ArrayRef intfn = opt2fns("-o", NFILE, fnm); if (intfn.size() != 2) { - gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.size()); + gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.ssize()); } calc_tetra_order_interface(ndxfnm, tpsfnm, trxfnm, binwidth, nsttblock, &frames, &xslices, &yslices, sg1, sg2, &intfpos, oenv); writesurftoxpms(intfpos, frames, xslices, yslices, binwidth, intfn, nlevels); @@ -675,7 +675,7 @@ int gmx_hydorder(int argc, char *argv[]) gmx::ArrayRef spectra = opt2fns("-Spect", NFILE, fnm); if (spectra.size() != 2) { - gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.size()); + gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.ssize()); } powerspectavg(intfpos, frames, xslices, yslices, spectra); } @@ -685,7 +685,7 @@ int gmx_hydorder(int argc, char *argv[]) gmx::ArrayRef raw = opt2fns("-or", NFILE, fnm); if (raw.size() != 2) { - gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.size()); + gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.ssize()); } writeraw(intfpos, frames, xslices, yslices, raw); } diff --git a/src/gromacs/gmxana/gmx_make_ndx.cpp b/src/gromacs/gmxana/gmx_make_ndx.cpp index a1ece34082..12310fb330 100644 --- a/src/gromacs/gmxana/gmx_make_ndx.cpp +++ b/src/gromacs/gmxana/gmx_make_ndx.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -1609,7 +1609,7 @@ int gmx_make_ndx(int argc, char *argv[]) /* read input file(s) */ block = new_blocka(); gnames = nullptr; - printf("Going to read %td old index file(s)\n", ndxInFiles.size()); + printf("Going to read %td old index file(s)\n", ndxInFiles.ssize()); if (!ndxInFiles.empty()) { for (const std::string &ndxInFile : ndxInFiles) diff --git a/src/gromacs/gmxana/gmx_nmeig.cpp b/src/gromacs/gmxana/gmx_nmeig.cpp index 10b44415ed..c153c8afa3 100644 --- a/src/gromacs/gmxana/gmx_nmeig.cpp +++ b/src/gromacs/gmxana/gmx_nmeig.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -140,12 +140,12 @@ nma_full_hessian(real *hess, if (bM) { - for (int i = 0; (i < atom_index.size()); i++) + for (int i = 0; (i < atom_index.ssize()); i++) { size_t ai = atom_index[i]; for (size_t j = 0; (j < DIM); j++) { - for (int k = 0; (k < atom_index.size()); k++) + for (int k = 0; (k < atom_index.ssize()); k++) { size_t ak = atom_index[k]; mass_fac = gmx::invsqrt(top->atoms.atom[ai].m*top->atoms.atom[ak].m); @@ -170,7 +170,7 @@ nma_full_hessian(real *hess, { for (int i = 0; i < (end-begin+1); i++) { - for (int j = 0; j < atom_index.size(); j++) + for (int j = 0; j < atom_index.ssize(); j++) { size_t aj = atom_index[j]; mass_fac = gmx::invsqrt(top->atoms.atom[aj].m); @@ -209,7 +209,7 @@ nma_sparse_hessian(gmx_sparsematrix_t *sparse_hessian, if (bM) { - for (int iatom = 0; (iatom < atom_index.size()); iatom++) + for (int iatom = 0; (iatom < atom_index.ssize()); iatom++) { size_t ai = atom_index[iatom]; for (size_t j = 0; (j < DIM); j++) @@ -236,7 +236,7 @@ nma_sparse_hessian(gmx_sparsematrix_t *sparse_hessian, { for (i = 0; i < neig; i++) { - for (int j = 0; j < atom_index.size(); j++) + for (int j = 0; j < atom_index.ssize(); j++) { size_t aj = atom_index[j]; mass_fac = gmx::invsqrt(top->atoms.atom[aj].m); diff --git a/src/gromacs/gmxana/gmx_trjcat.cpp b/src/gromacs/gmxana/gmx_trjcat.cpp index 5ba16ed1d8..b251dd9af9 100644 --- a/src/gromacs/gmxana/gmx_trjcat.cpp +++ b/src/gromacs/gmxana/gmx_trjcat.cpp @@ -82,7 +82,7 @@ static void scan_trj_files(gmx::ArrayRef files, t_trxframe fr; bool ok; - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { ok = read_first_frame(oenv, &status, files[i].c_str(), &fr, FLAGS); @@ -153,10 +153,10 @@ static void scan_trj_files(gmx::ArrayRef files, static void sort_files(gmx::ArrayRef files, real *settime) { - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { gmx::index minidx = i; - for (gmx::index j = i + 1; j < files.size(); j++) + for (gmx::index j = i + 1; j < files.ssize(); j++) { if (settime[j] < settime[minidx]) { @@ -201,7 +201,7 @@ static void edit_files(gmx::ArrayRef files, "---------------------------------------------------------\n", timeUnit.c_str(), timeUnit.c_str()); - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { fprintf(stderr, "%25s %10.3f %s ", files[i].c_str(), output_env_conv_time(oenv, readtime[i]), timeUnit.c_str()); @@ -256,7 +256,7 @@ static void edit_files(gmx::ArrayRef files, } else { - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { settime[i] = readtime[i]; } @@ -273,7 +273,7 @@ static void edit_files(gmx::ArrayRef files, fprintf(stderr, "\nSummary of files and start times used:\n\n" " File Start time Time step\n" "---------------------------------------------------------\n"); - for (gmx::index i = 0; i < files.size(); i++) + for (gmx::index i = 0; i < files.ssize(); i++) { switch (cont_type[i]) { @@ -321,7 +321,7 @@ static void do_demux(gmx::ArrayRef inFiles, snew(bSet, inFiles.size()); natoms = -1; t = -1; - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { read_first_frame(oenv, &(fp_in[i]), inFiles[i].c_str(), &(trx[i]), TRX_NEED_X); @@ -345,7 +345,7 @@ static void do_demux(gmx::ArrayRef inFiles, } snew(fp_out, inFiles.size()); - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { fp_out[i] = open_trx(outFiles[i].c_str(), "w"); } @@ -364,11 +364,11 @@ static void do_demux(gmx::ArrayRef inFiles, { fprintf(debug, "trx[0].time = %g, time[k] = %g\n", trx[0].time, time[k]); } - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { bSet[i] = FALSE; } - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { int j = gmx::roundToInt(value[i][k]); range_check(j, 0, inFiles.size()); @@ -393,14 +393,14 @@ static void do_demux(gmx::ArrayRef inFiles, } bCont = (k < nval); - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { bCont = bCont && read_next_frame(oenv, fp_in[i], &trx[i]); } } while (bCont); - for (gmx::index i = 0; i < inFiles.size(); i++) + for (gmx::index i = 0; i < inFiles.ssize(); i++) { close_trx(fp_in[i]); close_trx(fp_out[i]); @@ -555,7 +555,7 @@ int gmx_trjcat(int argc, char *argv[]) if (bDeMux && ssize(inFiles) != nset) { - gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.size(), nset); + gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.ssize(), nset); } ftpin = fn2ftp(inFiles[0].c_str()); @@ -584,7 +584,7 @@ int gmx_trjcat(int argc, char *argv[]) } else if (bDeMux && ssize(outFiles) != nset && outFiles.size() != 1) { - gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.size()); + gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.ssize()); } if (bDeMux) { diff --git a/src/gromacs/gmxana/thermochemistry.cpp b/src/gromacs/gmxana/thermochemistry.cpp index f8aa9d5a58..9b7c84fee6 100644 --- a/src/gromacs/gmxana/thermochemistry.cpp +++ b/src/gromacs/gmxana/thermochemistry.cpp @@ -72,7 +72,7 @@ double calcVibrationalInternalEnergy(gmx::ArrayRef eigval, size_t nskip = linear ? 5 : 6; double Evib = 0; double hbar = PLANCK1/(2*M_PI); - for (gmx::index i = nskip; i < eigval.size(); i++) + for (gmx::index i = nskip; i < eigval.ssize(); i++) { if (eigval[i] > 0) { @@ -104,7 +104,7 @@ double calcVibrationalHeatCapacity(gmx::ArrayRef eigval, size_t nskip = linear ? 5 : 6; double cv = 0; double hbar = PLANCK1/(2*M_PI); - for (gmx::index i = nskip; i < eigval.size(); i++) + for (gmx::index i = nskip; i < eigval.ssize(); i++) { if (eigval[i] > 0) { @@ -179,7 +179,7 @@ double calcQuasiHarmonicEntropy(gmx::ArrayRef eigval, size_t nskip = bLinear ? 5 : 6; double S = 0; double hbar = PLANCK1/(2*M_PI); - for (gmx::index i = nskip; (i < eigval.size()); i++) + for (gmx::index i = nskip; (i < eigval.ssize()); i++) { if (eigval[i] > 0) { @@ -218,7 +218,7 @@ double calcSchlitterEntropy(gmx::ArrayRef eigval, ssize(eigval), kteh, evcorr); } double deter = 0; - for (gmx::index i = nskip; i < eigval.size(); i++) + for (gmx::index i = nskip; i < eigval.ssize(); i++) { double dd = 1+kteh*eigval[i]*evcorr; deter += std::log(dd); diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 1960170bb0..2804ab3a1a 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -2646,7 +2646,7 @@ static bool do_numbering(int natoms, gmx_groups_t *groups, } snew(grps->nm_ind, groupsFromMdpFile.size()+1); /* +1 for possible rest group */ - for (int i = 0; i != groupsFromMdpFile.size(); ++i) + for (int i = 0; i != groupsFromMdpFile.ssize(); ++i) { /* Lookup the group name in the block structure */ gid = search_string(groupsFromMdpFile[i].c_str(), block->nr, gnames); diff --git a/src/gromacs/math/tests/testarrayrefs.h b/src/gromacs/math/tests/testarrayrefs.h index 7eb4ff4498..d0b5b0db8c 100644 --- a/src/gromacs/math/tests/testarrayrefs.h +++ b/src/gromacs/math/tests/testarrayrefs.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -98,7 +98,7 @@ void compareViews(ArrayRef input, ArrayRef output) { ASSERT_EQ(input.size(), output.size()); - for (index i = 0; i != input.size(); ++i) + for (index i = 0; i != input.ssize(); ++i) { EXPECT_EQ(input[i], output[i]) << "for index " << i; } @@ -110,7 +110,7 @@ void compareViews(ArrayRef < BasicVector < T>> input, ArrayRef < BasicVector < T>> output) { ASSERT_EQ(input.size(), output.size()); - for (index i = 0; i != input.size(); ++i) + for (index i = 0; i != input.ssize(); ++i) { EXPECT_EQ(input[i][XX], output[i][XX]) << "for index " << i; EXPECT_EQ(input[i][YY], output[i][YY]) << "for index " << i; diff --git a/src/gromacs/mdlib/calc_verletbuf.cpp b/src/gromacs/mdlib/calc_verletbuf.cpp index fd07917451..3de11ebea9 100644 --- a/src/gromacs/mdlib/calc_verletbuf.cpp +++ b/src/gromacs/mdlib/calc_verletbuf.cpp @@ -655,14 +655,14 @@ static real energyDrift(gmx::ArrayRef att, // Here add up the contribution of all atom pairs in the system to // (estimated) energy drift by looping over all atom type pairs. - for (int i = 0; i < att.size(); i++) + for (int i = 0; i < att.ssize(); i++) { // Get the thermal displacement variance for the i-atom type const atom_nonbonded_kinetic_prop_t *prop_i = &att[i].prop; real s2i_2d, s2i_3d; get_atom_sigma2(kT_fac, prop_i, &s2i_2d, &s2i_3d); - for (int j = i; j < att.size(); j++) + for (int j = i; j < att.ssize(); j++) { // Get the thermal displacement variance for the j-atom type const atom_nonbonded_kinetic_prop_t *prop_j = &att[j].prop; @@ -847,7 +847,7 @@ static real maxSigma(real kT_fac, { GMX_ASSERT(!att.empty(), "We should have at least one type"); real smallestMass = att[0].prop.mass; - for (int i = 1; i < att.size(); i++) + for (int i = 1; i < att.ssize(); i++) { smallestMass = std::min(smallestMass, att[i].prop.mass); } @@ -1330,7 +1330,7 @@ chanceOfUpdateGroupCrossingCell(const gmx_mtop_t &mtop, real kT_fac, real cellSize) { - GMX_RELEASE_ASSERT(static_cast(updateGrouping.size()) == mtop.moltype.size(), + GMX_RELEASE_ASSERT(updateGrouping.size() == mtop.moltype.size(), "The update groups should match the topology"); real chance = 0; diff --git a/src/gromacs/mdlib/constr.h b/src/gromacs/mdlib/constr.h index ecb713ce14..a07560bde7 100644 --- a/src/gromacs/mdlib/constr.h +++ b/src/gromacs/mdlib/constr.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -271,7 +271,7 @@ constr_iatomptr(gmx::ArrayRef iatom_constr, gmx::ArrayRef iatom_constrnc, int con) { - if (con*3 < iatom_constr.size()) + if (con*3 < iatom_constr.ssize()) { return iatom_constr.data() + con*3; } diff --git a/src/gromacs/mdlib/force.cpp b/src/gromacs/mdlib/force.cpp index 09f54fc4f8..0ed28de87e 100644 --- a/src/gromacs/mdlib/force.cpp +++ b/src/gromacs/mdlib/force.cpp @@ -767,7 +767,7 @@ void sum_dhdl(gmx_enerdata_t *enerd, gmx::ArrayRef lambda, t_lambda double &enerpart_lambda = enerd->enerpart_lambda[i + 1]; - for (gmx::index j = 0; j < lambda.size(); j++) + for (gmx::index j = 0; j < lambda.ssize(); j++) { /* Note that this loop is over all dhdl components, not just the separated ones */ const double dlam = fepvals->all_lambda[j][i] - lambda[j]; diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index 34f4c663aa..38e4928684 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -1453,7 +1453,7 @@ static bondedtable_t *make_bonded_tables(FILE *fplog, // being recognized and used for table 1. std::string patternToFind = gmx::formatString("_%s%d.%s", tabext, i, ftp2ext(efXVG)); bool madeTable = false; - for (gmx::index j = 0; j < tabbfnm.size() && !madeTable; ++j) + for (gmx::index j = 0; j < tabbfnm.ssize() && !madeTable; ++j) { if (gmx::endsWith(tabbfnm[j], patternToFind)) { diff --git a/src/gromacs/mdlib/qmmm.cpp b/src/gromacs/mdlib/qmmm.cpp index 21221afd2d..643d646558 100644 --- a/src/gromacs/mdlib/qmmm.cpp +++ b/src/gromacs/mdlib/qmmm.cpp @@ -404,7 +404,7 @@ std::vector qmmmAtomIndices(const t_inputrec &ir, const gmx_mtop_t &mtop) void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef qmmmAtoms) { int molb = 0; - for (int i = 0; i < qmmmAtoms.size(); i++) + for (int i = 0; i < qmmmAtoms.ssize(); i++) { int indexInMolecule; mtopGetMolblockIndex(mtop, qmmmAtoms[i], &molb, nullptr, &indexInMolecule); diff --git a/src/gromacs/mdlib/updategroups.cpp b/src/gromacs/mdlib/updategroups.cpp index 353a0a1726..f78c58c00c 100644 --- a/src/gromacs/mdlib/updategroups.cpp +++ b/src/gromacs/mdlib/updategroups.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -754,7 +754,7 @@ computeMaxUpdateGroupRadius(const gmx_mtop_t &mtop, return 0; } - GMX_RELEASE_ASSERT(static_cast(updateGroups.size()) == mtop.moltype.size(), + GMX_RELEASE_ASSERT(updateGroups.size() == mtop.moltype.size(), "We need one update group entry per moleculetype"); real maxRadius = 0; diff --git a/src/gromacs/mdlib/updategroupscog.cpp b/src/gromacs/mdlib/updategroupscog.cpp index 957d373d31..f5c972a862 100644 --- a/src/gromacs/mdlib/updategroupscog.cpp +++ b/src/gromacs/mdlib/updategroupscog.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -88,13 +88,13 @@ void UpdateGroupsCog::addCogs(gmx::ArrayRef globalAtomIndices, const int localAtomBegin = cogIndices_.size(); const size_t cogBegin = cogs_.size(); - GMX_RELEASE_ASSERT(globalAtomIndices.size() >= localAtomBegin, + GMX_RELEASE_ASSERT(globalAtomIndices.ssize() >= localAtomBegin, "addCogs should only be called to add COGs to the list that is already present (which could be empty)"); cogIndices_.reserve(globalAtomIndices.size()); int moleculeBlock = 0; - for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.size(); localAtom++) + for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.ssize(); localAtom++) { const int globalAtom = globalAtomIndices[localAtom]; int moleculeIndex; diff --git a/src/gromacs/mdlib/vsite.cpp b/src/gromacs/mdlib/vsite.cpp index fe98a6ccce..cbbae59a48 100644 --- a/src/gromacs/mdlib/vsite.cpp +++ b/src/gromacs/mdlib/vsite.cpp @@ -758,7 +758,7 @@ static void spread_vsite2(const t_iatom ia[], real a, void constructVsitesGlobal(const gmx_mtop_t &mtop, gmx::ArrayRef x) { - GMX_ASSERT(x.size() >= static_cast(mtop.natoms), "x should contain the whole system"); + GMX_ASSERT(x.ssize() >= mtop.natoms, "x should contain the whole system"); GMX_ASSERT(!mtop.moleculeBlockIndices.empty(), "molblock indices are needed in constructVsitesGlobal"); for (size_t mb = 0; mb < mtop.molblock.size(); mb++) diff --git a/src/gromacs/mdrun/multisim.cpp b/src/gromacs/mdrun/multisim.cpp index b3a73ee7ad..6d0cfd9de2 100644 --- a/src/gromacs/mdrun/multisim.cpp +++ b/src/gromacs/mdrun/multisim.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018, by the GROMACS development team, led by + * Copyright (c) 2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -83,7 +83,7 @@ gmx_multisim_t *init_multisystem(MPI_Comm comm, MPI_Comm_size(comm, &numRanks); if (numRanks % multidirs.size() != 0) { - gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.size()); + gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.ssize()); } int numRanksPerSim = numRanks/multidirs.size(); @@ -92,7 +92,7 @@ gmx_multisim_t *init_multisystem(MPI_Comm comm, if (debug) { - fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.size(), numRanksPerSim, rankWithinComm/numRanksPerSim); + fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.ssize(), numRanksPerSim, rankWithinComm/numRanksPerSim); } ms = new gmx_multisim_t; diff --git a/src/gromacs/mdtypes/state.cpp b/src/gromacs/mdtypes/state.cpp index ef9956a9c8..9305abd47f 100644 --- a/src/gromacs/mdtypes/state.cpp +++ b/src/gromacs/mdtypes/state.cpp @@ -207,7 +207,7 @@ void comp_state(const t_state *st1, const t_state *st2, rvec *makeRvecArray(gmx::ArrayRef v, gmx::index n) { - GMX_ASSERT(v.size() >= n, "We can't copy more elements than the vector size"); + GMX_ASSERT(v.ssize() >= n, "We can't copy more elements than the vector size"); rvec *dest; diff --git a/src/gromacs/pbcutil/pbc.cpp b/src/gromacs/pbcutil/pbc.cpp index f6547f81ad..ca5d7965b3 100644 --- a/src/gromacs/pbcutil/pbc.cpp +++ b/src/gromacs/pbcutil/pbc.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -1430,7 +1430,7 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef x) if (TRICLINIC(box)) { - for (gmx::index i = 0; (i < x.size()); ++i) + for (gmx::index i = 0; (i < x.ssize()); ++i) { for (m = npbcdim-1; m >= 0; m--) { @@ -1453,7 +1453,7 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef x) } else { - for (gmx::index i = 0; (i < x.size()); ++i) + for (gmx::index i = 0; (i < x.ssize()); ++i) { for (d = 0; d < npbcdim; d++) { @@ -1497,7 +1497,7 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box, shift_center[1] = shm12*shift_center[2]; shift_center[2] = 0; - for (gmx::index i = 0; (i < x.size()); ++i) + for (gmx::index i = 0; (i < x.ssize()); ++i) { for (m = DIM-1; m >= 0; m--) { @@ -1542,7 +1542,7 @@ void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box, } calc_box_center(ecenter, box, box_center); - for (gmx::index i = 0; (i < x.size()); ++i) + for (gmx::index i = 0; (i < x.ssize()); ++i) { pbc_dx(&pbc, x[i], box_center, dx); rvec_add(box_center, dx, x[i]); diff --git a/src/gromacs/pulling/pull.cpp b/src/gromacs/pulling/pull.cpp index 2d09c42336..89eac4578e 100644 --- a/src/gromacs/pulling/pull.cpp +++ b/src/gromacs/pulling/pull.cpp @@ -1079,7 +1079,7 @@ static void do_constraint(struct pull_t *pull, t_pbc *pbc, /* update the atom positions */ auto localAtomIndices = pgrp->atomSet.localIndex(); copy_dvec(dr, tmp); - for (gmx::index j = 0; j < localAtomIndices.size(); j++) + for (gmx::index j = 0; j < localAtomIndices.ssize(); j++) { ii = localAtomIndices[j]; if (!pgrp->localWeights.empty()) diff --git a/src/gromacs/pulling/pull_rotation.cpp b/src/gromacs/pulling/pull_rotation.cpp index 2f129777bc..a2c3210fb5 100644 --- a/src/gromacs/pulling/pull_rotation.cpp +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -598,7 +598,7 @@ real add_rot_forces(gmx_enfrot *er, gmx_enfrotgrp *erg = &ergRef; Vrot += erg->V; /* add the local parts from the nodes */ const auto &localRotationGroupIndex = erg->atomSet->localIndex(); - for (gmx::index l = 0; l < localRotationGroupIndex.size(); l++) + for (gmx::index l = 0; l < localRotationGroupIndex.ssize(); l++) { /* Get the right index of the local force */ int ii = localRotationGroupIndex[l]; @@ -1984,7 +1984,7 @@ static real do_flex2_lowlevel( const auto &localRotationGroupIndex = erg->atomSet->localIndex(); const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex(); - for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++) + for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++) { /* Local index of a rotation group atom */ ii = localRotationGroupIndex[j]; @@ -2223,7 +2223,7 @@ static real do_flex_lowlevel( const auto &localRotationGroupIndex = erg->atomSet->localIndex(); const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex(); - for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++) + for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++) { /* Local index of a rotation group atom */ int ii = localRotationGroupIndex[j]; @@ -2907,7 +2907,7 @@ static void do_radial_motion_pf( /* Each process calculates the forces on its local atoms */ const auto &localRotationGroupIndex = erg->atomSet->localIndex(); const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex(); - for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++) + for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++) { /* Local index of a rotation group atom */ int ii = localRotationGroupIndex[j]; @@ -3098,7 +3098,7 @@ static void do_radial_motion2( /* Each process calculates the forces on its local atoms */ const auto &localRotationGroupIndex = erg->atomSet->localIndex(); const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex(); - for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++) + for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++) { if (bPF) { @@ -3758,7 +3758,7 @@ static void choose_pbc_image(rvec x[], matrix box, int npbcdim) { const auto &localRotationGroupIndex = erg->atomSet->localIndex(); - for (gmx::index i = 0; i < localRotationGroupIndex.size(); i++) + for (gmx::index i = 0; i < localRotationGroupIndex.ssize(); i++) { /* Index of a rotation group atom */ int ii = localRotationGroupIndex[i]; @@ -3835,7 +3835,7 @@ void do_rotation(const t_commrec *cr, if (bNS) { const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex(); - for (gmx::index i = 0; i < collectiveRotationGroupIndex.size(); i++) + for (gmx::index i = 0; i < collectiveRotationGroupIndex.ssize(); i++) { /* Index of local atom w.r.t. the collective rotation group */ int ii = collectiveRotationGroupIndex[i]; diff --git a/src/gromacs/pulling/pullutil.cpp b/src/gromacs/pulling/pullutil.cpp index c33a110340..3f39df0cce 100644 --- a/src/gromacs/pulling/pullutil.cpp +++ b/src/gromacs/pulling/pullutil.cpp @@ -251,7 +251,7 @@ static void make_cyl_refgrps(const t_commrec *cr, pdyna.dv.resize(localAtomIndices.size()); /* loop over all atoms in the main ref group */ - for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++) + for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++) { int atomIndex = localAtomIndices[indexInSet]; rvec dx; @@ -867,7 +867,7 @@ static bool pullGroupObeysPbcRestrictions(const pull_group_work_t &group, } auto localAtomIndices = group.atomSet.localIndex(); - for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++) + for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++) { rvec dx; pbc_dx(&pbc, x[localAtomIndices[indexInSet]], x_pbc, dx); diff --git a/src/gromacs/selection/tests/selectioncollection.cpp b/src/gromacs/selection/tests/selectioncollection.cpp index 228f58f218..34f17427ff 100644 --- a/src/gromacs/selection/tests/selectioncollection.cpp +++ b/src/gromacs/selection/tests/selectioncollection.cpp @@ -291,7 +291,7 @@ SelectionCollectionDataTest::runParser( TestReferenceChecker compound(checker_.checkCompound("ParsedSelections", "Parsed")); size_t varcount = 0; count_ = 0; - for (gmx::index i = 0; i < selections.size(); ++i) + for (gmx::index i = 0; i < selections.ssize(); ++i) { SCOPED_TRACE(std::string("Parsing selection \"") + selections[i] + "\""); diff --git a/src/gromacs/selection/tests/toputils.cpp b/src/gromacs/selection/tests/toputils.cpp index ef6b40403d..460276e61d 100644 --- a/src/gromacs/selection/tests/toputils.cpp +++ b/src/gromacs/selection/tests/toputils.cpp @@ -197,7 +197,7 @@ void TopologyManager::initAtomTypes(const ArrayRef &types) index j = 0; for (int i = 0; i < atoms.nr; ++i, ++j) { - if (j == types.size()) + if (j == types.ssize()) { j = 0; } diff --git a/src/gromacs/topology/index.cpp b/src/gromacs/topology/index.cpp index 86088de42b..ea26dce45e 100644 --- a/src/gromacs/topology/index.cpp +++ b/src/gromacs/topology/index.cpp @@ -120,7 +120,7 @@ void add_grp(t_blocka *b, char ***gnames, gmx::ArrayRef a, const std: (*gnames)[b->nr] = gmx_strdup(name.c_str()); srenew(b->a, b->nra+a.size()); - for (int i = 0; (i < a.size()); i++) + for (int i = 0; (i < a.ssize()); i++) { b->a[b->nra++] = a[i]; } @@ -150,11 +150,11 @@ static bool grp_cmp(t_blocka *b, gmx::ArrayRef a, int index) gmx_fatal(FARGS, "no such index group %d in t_blocka (nr=%d)", index, b->nr); } /* compare sizes */ - if (a.size() != b->index[index+1] - b->index[index]) + if (a.ssize() != b->index[index+1] - b->index[index]) { return FALSE; } - for (int i = 0; i < a.size(); i++) + for (int i = 0; i < a.ssize(); i++) { if (a[i] != b->a[b->index[index]+i]) { @@ -178,7 +178,7 @@ static void p_status(gmx::ArrayRef restype, } ); - for (int i = 0; (i < typenames.size()); i++) + for (int i = 0; (i < typenames.ssize()); i++) { if (counter[i] > 0) { diff --git a/src/gromacs/topology/mtop_util.cpp b/src/gromacs/topology/mtop_util.cpp index ad4c3a3403..48ab089c13 100644 --- a/src/gromacs/topology/mtop_util.cpp +++ b/src/gromacs/topology/mtop_util.cpp @@ -1086,7 +1086,7 @@ static void addMimicExclusions(t_blocka *excls, for (int k = 0; k < inter_excl.nr; ++k) { inter_excl.index[k] = prev_index; - for (long i = 0; i < ids.size(); i++) + for (long i = 0; i < ids.ssize(); i++) { if (k != ids[i]) { diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp index aacebf36ed..6e621644fc 100644 --- a/src/gromacs/topology/topology.cpp +++ b/src/gromacs/topology/topology.cpp @@ -567,7 +567,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef mt1, gm { fprintf(fp, "comparing molecule types\n"); cmp_int(fp, "moltype size", -1, mt1.size(), mt2.size()); - for (int i = 0; i < std::min(mt1.size(), mt2.size()); i++) + for (int i = 0; i < std::min(mt1.ssize(), mt2.ssize()); i++) { cmp_str(fp, "Name", i, *mt1[i].name, *mt2[i].name); compareAtoms(fp, &mt1[i].atoms, &mt2[i].atoms, relativeTolerance, absoluteTolerance); @@ -582,7 +582,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef mt1, gm static void compareMoletypeAB(FILE *fp, gmx::ArrayRef mt1, real relativeTolerance, real absoluteTolerance) { fprintf(fp, "comparing free energy molecule types\n"); - for (int i = 0; i < mt1.size(); i++) + for (int i = 0; i < mt1.ssize(); i++) { compareAtoms(fp, &mt1[i].atoms, nullptr, relativeTolerance, absoluteTolerance); } diff --git a/src/gromacs/utility/arrayref.h b/src/gromacs/utility/arrayref.h index 9291870396..fdb754d06b 100644 --- a/src/gromacs/utility/arrayref.h +++ b/src/gromacs/utility/arrayref.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -118,7 +118,7 @@ class ArrayRef //! Type of values stored in the reference. typedef T value_type; //! Type for representing size of the reference. - typedef index size_type; + typedef size_t size_type; //! Type for representing difference between two indices. typedef ptrdiff_t difference_type; //! Const reference to an element. @@ -222,8 +222,14 @@ class ArrayRef //! Returns an iterator to the reverse end of the reference. reverse_iterator rend() const { return reverse_iterator(begin()); } - //! Returns the size of the reference. + /*! \brief Returns the size of the reference. + * + * \note Use ssize for any expression involving arithmetic operations + (including loop indices). + */ size_type size() const { return end_ - begin_; } + //! Returns the signed size of the reference. + index ssize() const { return size(); } //! Identical to size(). size_type capacity() const { return end_ - begin_; } //! Whether the reference refers to no memory.