From 2a77c0b979ac2c9f87e03743eaec648a63358eb1 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Sat, 8 Sep 2018 09:57:12 -0700 Subject: [PATCH] Replace rounding using int(x+0.5) with roundToInt Enable clang-tidy misc-incorrect-roundings Change-Id: If448e37ad86c01a38e7a4951f3cb42a3b4cd1f12 --- src/.clang-tidy | 2 +- src/gromacs/analysisdata/modules/histogram.cpp | 5 +++-- src/gromacs/awh/bias.cpp | 3 ++- src/gromacs/awh/grid.cpp | 6 +++--- src/gromacs/domdec/cellsizes.cpp | 4 ++-- src/gromacs/domdec/distribute.cpp | 2 +- src/gromacs/domdec/domdec.cpp | 6 +++--- src/gromacs/domdec/domdec_box.cpp | 2 +- src/gromacs/domdec/domdec_setup.cpp | 6 +++--- src/gromacs/ewald/pme.cpp | 2 +- src/gromacs/fileio/trxio.cpp | 2 +- src/gromacs/gmxana/anadih.cpp | 2 +- src/gromacs/gmxana/cmat.cpp | 4 ++-- src/gromacs/gmxana/gmx_anaeig.cpp | 2 +- src/gromacs/gmxana/gmx_analyze.cpp | 8 ++++---- src/gromacs/gmxana/gmx_angle.cpp | 2 +- src/gromacs/gmxana/gmx_densmap.cpp | 10 +++++----- src/gromacs/gmxana/gmx_dipoles.cpp | 2 +- src/gromacs/gmxana/gmx_editconf.cpp | 6 +++--- src/gromacs/gmxana/gmx_msd.cpp | 4 ++-- src/gromacs/gmxana/gmx_rms.cpp | 6 +++--- src/gromacs/gmxana/gmx_rmsdist.cpp | 2 +- src/gromacs/gmxana/gmx_sorient.cpp | 4 ++-- src/gromacs/gmxana/gmx_tcaf.cpp | 4 ++-- src/gromacs/gmxana/gmx_vanhove.cpp | 8 ++++---- src/gromacs/gmxana/gmx_wham.cpp | 14 +++++++------- src/gromacs/gmxana/sfactor.cpp | 12 ++++++------ src/gromacs/gmxpreprocess/convparm.cpp | 11 +---------- src/gromacs/gmxpreprocess/genconf.cpp | 6 +++--- src/gromacs/gmxpreprocess/grompp.cpp | 6 +++--- src/gromacs/gmxpreprocess/readir.cpp | 2 +- src/gromacs/gmxpreprocess/toppush.cpp | 3 ++- src/gromacs/mdlib/coupling.cpp | 2 +- src/gromacs/mdlib/nbnxn_search.cpp | 2 +- src/gromacs/mdlib/nsgrid.cpp | 4 ++-- src/gromacs/mdlib/shellfc.cpp | 2 +- src/gromacs/mdlib/stat.cpp | 2 +- src/gromacs/mdlib/update.cpp | 2 +- src/gromacs/mdrun/minimize.cpp | 2 +- src/gromacs/mdrun/tpi.cpp | 7 +++---- src/gromacs/pulling/pull_rotation.cpp | 3 +-- src/gromacs/statistics/statistics.cpp | 2 +- src/gromacs/tables/forcetable.cpp | 6 ++++-- src/gromacs/timing/wallcycle.cpp | 13 +++++++------ src/gromacs/tools/convert_tpr.cpp | 4 ++-- src/programs/mdrun/mdrun.cpp | 6 +++--- 46 files changed, 105 insertions(+), 110 deletions(-) diff --git a/src/.clang-tidy b/src/.clang-tidy index 56ffbb29ff..21b88ea026 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -1,5 +1,5 @@ Checks: clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy, - bugprone-*,misc-*,readability-*,performance-*,mpi-*,-misc-incorrect-roundings, + bugprone-*,misc-*,readability-*,performance-*,mpi-*, -readability-inconsistent-declaration-parameter-name, -readability-function-size,-readability-else-after-return, modernize-use-nullptr,modernize-use-emplace, diff --git a/src/gromacs/analysisdata/modules/histogram.cpp b/src/gromacs/analysisdata/modules/histogram.cpp index 092b0009b1..f77f96e9c7 100644 --- a/src/gromacs/analysisdata/modules/histogram.cpp +++ b/src/gromacs/analysisdata/modules/histogram.cpp @@ -51,6 +51,7 @@ #include "gromacs/analysisdata/dataframe.h" #include "gromacs/analysisdata/datastorage.h" #include "gromacs/analysisdata/framelocaldata.h" +#include "gromacs/math/functions.h" #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/gmxassert.h" @@ -140,7 +141,7 @@ AnalysisHistogramSettings::AnalysisHistogramSettings( binWidth_ = settings.binWidth_; firstEdge_ = binWidth_ * std::floor(settings.min_ / binWidth_); lastEdge_ = binWidth_ * std::ceil(settings.max_ / binWidth_); - binCount_ = static_cast((lastEdge_ - firstEdge_) / binWidth_ + 0.5); + binCount_ = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_); } else { @@ -165,7 +166,7 @@ AnalysisHistogramSettings::AnalysisHistogramSettings( else { binWidth_ = settings.binWidth_; - binCount_ = static_cast((lastEdge_ - firstEdge_) / binWidth_ + 0.5); + binCount_ = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_); if (settings.bIntegerBins_) { firstEdge_ -= 0.5 * binWidth_; diff --git a/src/gromacs/awh/bias.cpp b/src/gromacs/awh/bias.cpp index 27167183d7..bde1a68fbe 100644 --- a/src/gromacs/awh/bias.cpp +++ b/src/gromacs/awh/bias.cpp @@ -57,6 +57,7 @@ #include "gromacs/compat/make_unique.h" #include "gromacs/fileio/gmxfio.h" #include "gromacs/gmxlib/network.h" +#include "gromacs/math/functions.h" #include "gromacs/math/utilities.h" #include "gromacs/mdtypes/awh-history.h" #include "gromacs/mdtypes/awh-params.h" @@ -222,7 +223,7 @@ static int64_t countSamples(const std::vector &pointState) numSamples += point.weightSumTot(); } - return static_cast(numSamples + 0.5); + return gmx::roundToInt64(numSamples); } /*! \brief diff --git a/src/gromacs/awh/grid.cpp b/src/gromacs/awh/grid.cpp index 243c1639c8..7b6492791f 100644 --- a/src/gromacs/awh/grid.cpp +++ b/src/gromacs/awh/grid.cpp @@ -52,6 +52,7 @@ #include +#include "gromacs/math/functions.h" #include "gromacs/math/utilities.h" #include "gromacs/mdtypes/awh-params.h" #include "gromacs/utility/cstringutil.h" @@ -497,9 +498,8 @@ static int pointDistanceAlongAxis(const GridAxis &axis, double x, double x0) double period = axis.period(); double dx = getDeviationPeriodic(x, x0, period); - /* Transform the distance into a point distance. - Shift by +0.5 so we can use floor or integer casting below to get the integer index */ - distance = static_cast(floor(dx/axis.spacing() + 0.5)); + /* Transform the distance into a point distance by rounding. */ + distance = gmx::roundToInt(dx/axis.spacing()); /* If periodic, shift the point distance to be in [0, period) */ distance = indexWithinPeriod(distance, axis.numPointsInPeriod()); diff --git a/src/gromacs/domdec/cellsizes.cpp b/src/gromacs/domdec/cellsizes.cpp index 1a776ebf38..1719c7f4e0 100644 --- a/src/gromacs/domdec/cellsizes.cpp +++ b/src/gromacs/domdec/cellsizes.cpp @@ -759,10 +759,10 @@ static void distribute_dd_cell_sizes_dlb(gmx_domdec_t *dd, relative_to_absolute_cell_bounds(dd, ddbox, d1); } /* Convert the communicated shift from float to int */ - comm.ddpme[0].maxshift = static_cast(cellFracRow[pos++] + 0.5); + comm.ddpme[0].maxshift = gmx::roundToInt(cellFracRow[pos++]); if (d >= 1) { - comm.ddpme[1].maxshift = static_cast(cellFracRow[pos++] + 0.5); + comm.ddpme[1].maxshift = gmx::roundToInt(cellFracRow[pos++]); } } diff --git a/src/gromacs/domdec/distribute.cpp b/src/gromacs/domdec/distribute.cpp index 040d75626e..1b4520f425 100644 --- a/src/gromacs/domdec/distribute.cpp +++ b/src/gromacs/domdec/distribute.cpp @@ -422,7 +422,7 @@ getAtomGroupDistribution(FILE *fplog, fprintf(fplog, "Atom distribution over %d domains: av %d stddev %d min %d max %d\n", dd->nnodes, nat_sum, - static_cast(std::sqrt(nat2_sum - gmx::square(static_cast(nat_sum)) + 0.5)), + gmx::roundToInt(std::sqrt(nat2_sum - gmx::square(static_cast(nat_sum)))), nat_min, nat_max); } diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index e8cd6942b3..dbe8dc1edb 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -2223,7 +2223,7 @@ static void get_load_distribution(gmx_domdec_t *dd, gmx_wallcycle_t wcycle) pos++; if (d < dd->ndim-1) { - load->flags = static_cast(load->load[pos++] + 0.5); + load->flags = gmx::roundToInt(load->load[pos++]); } if (d > 0) { @@ -2366,7 +2366,7 @@ static void print_dd_load_av(FILE *fplog, gmx_domdec_t *dd) msg += " " + dlbStateStr + "\n"; msg += gmx::formatString(" Average load imbalance: %.1f%%.\n", imbalance*100); msg += gmx::formatString(" The balanceable part of the MD step is %d%%, load imbalance is computed from this.\n", - static_cast(dd_force_load_fraction(dd)*100 + 0.5)); + gmx::roundToInt(dd_force_load_fraction(dd)*100)); msg += gmx::formatString(" Part of the total run time spent waiting due to load imbalance: %.1f%%.\n", lossFraction*100); fprintf(fplog, "%s", msg.c_str()); @@ -2532,7 +2532,7 @@ static void dd_print_load_verbose(gmx_domdec_t *dd) } if (dd->nnodes > 1) { - fprintf(stderr, "imb F %2d%% ", static_cast(dd_f_imbal(dd)*100+0.5)); + fprintf(stderr, "imb F %2d%% ", gmx::roundToInt(dd_f_imbal(dd)*100)); } if (dd->comm->cycl_n[ddCyclPME]) { diff --git a/src/gromacs/domdec/domdec_box.cpp b/src/gromacs/domdec/domdec_box.cpp index ebd4de8d1b..7f6822fba3 100644 --- a/src/gromacs/domdec/domdec_box.cpp +++ b/src/gromacs/domdec/domdec_box.cpp @@ -103,7 +103,7 @@ static void calc_pos_av_stddev(int n, const rvec *x, s1[d] = receiveBuffer[d]; s2[d] = receiveBuffer[DIM + d]; } - n = static_cast(receiveBuffer[6] + 0.5); + n = gmx::roundToInt(receiveBuffer[6]); } #else // GMX_MPI GMX_UNUSED_VALUE(mpiCommunicator); diff --git a/src/gromacs/domdec/domdec_setup.cpp b/src/gromacs/domdec/domdec_setup.cpp index e6766d9c8a..1ff9e88c37 100644 --- a/src/gromacs/domdec/domdec_setup.cpp +++ b/src/gromacs/domdec/domdec_setup.cpp @@ -143,8 +143,8 @@ static gmx_bool fits_pp_pme_perf(int ntot, int npme, float ratio) std::vector mdiv; factorize(ntot - npme, &div, &mdiv); - int npp_root3 = static_cast(std::cbrt(ntot - npme) + 0.5); - int npme_root2 = static_cast(std::sqrt(static_cast(npme)) + 0.5); + int npp_root3 = gmx::roundToInt(std::cbrt(ntot - npme)); + int npme_root2 = gmx::roundToInt(std::sqrt(static_cast(npme))); /* The check below gives a reasonable division: * factor 5 allowed at 5 or more PP ranks, @@ -237,7 +237,7 @@ static int guess_npme(FILE *fplog, const gmx_mtop_t *mtop, const t_inputrec *ir, { gmx_fatal(FARGS, "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks (%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n" "Use the -npme option of mdrun or change the number of ranks or the PME grid dimensions, see the manual for details.", - ratio, static_cast(0.95*ratio*nrank_tot + 0.5), nrank_tot/2, ir->nkx, ir->nky); + ratio, gmx::roundToInt(0.95*ratio*nrank_tot), nrank_tot/2, ir->nkx, ir->nky); } else { diff --git a/src/gromacs/ewald/pme.cpp b/src/gromacs/ewald/pme.cpp index 2d2f04484a..46411815da 100644 --- a/src/gromacs/ewald/pme.cpp +++ b/src/gromacs/ewald/pme.cpp @@ -803,7 +803,7 @@ gmx_pme_t *gmx_pme_init(const t_commrec *cr, " PME grid_x (%d) and grid_y (%d) should be divisible by #PME_ranks_x (%d)\n" " and PME grid_y (%d) and grid_z (%d) should be divisible by #PME_ranks_y (%d)\n" "\n", - static_cast((imbal-1)*100 + 0.5), + gmx::roundToInt((imbal-1)*100), pme->nkx, pme->nky, pme->nnodes_major, pme->nky, pme->nkz, pme->nnodes_minor); } diff --git a/src/gromacs/fileio/trxio.cpp b/src/gromacs/fileio/trxio.cpp index f69f6dbc2e..73a036433c 100644 --- a/src/gromacs/fileio/trxio.cpp +++ b/src/gromacs/fileio/trxio.cpp @@ -226,7 +226,7 @@ int prec2ndec(real prec) gmx_fatal(FARGS, "DEATH HORROR prec (%g) <= 0 in prec2ndec", prec); } - return static_cast(log(prec)/log(10.0)+0.5); + return gmx::roundToInt(log(prec)/log(10.0)); } real ndec2prec(int ndec) diff --git a/src/gromacs/gmxana/anadih.cpp b/src/gromacs/gmxana/anadih.cpp index bc524a5890..cf7869ced0 100644 --- a/src/gromacs/gmxana/anadih.cpp +++ b/src/gromacs/gmxana/anadih.cpp @@ -961,7 +961,7 @@ void read_ang_dih(const char *trj_fn, } /* Update the distribution histogram */ - angind = static_cast((angle*maxangstat)/pifac + 0.5); + angind = gmx::roundToInt((angle*maxangstat)/pifac); if (angind == maxangstat) { angind = 0; diff --git a/src/gromacs/gmxana/cmat.cpp b/src/gromacs/gmxana/cmat.cpp index d19601cff2..ec67259db6 100644 --- a/src/gromacs/gmxana/cmat.cpp +++ b/src/gromacs/gmxana/cmat.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,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2017,2018, 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. @@ -220,7 +220,7 @@ void low_rmsd_dist(const char *fn, real maxrms, int nn, real **mat, { for (j = i+1; j < nn; j++) { - x = static_cast(fac*mat[i][j]+0.5); + x = gmx::roundToInt(fac*mat[i][j]); if (x <= 100) { histo[x]++; diff --git a/src/gromacs/gmxana/gmx_anaeig.cpp b/src/gromacs/gmxana/gmx_anaeig.cpp index 1d213722f7..b9e1e7d1d0 100644 --- a/src/gromacs/gmxana/gmx_anaeig.cpp +++ b/src/gromacs/gmxana/gmx_anaeig.cpp @@ -273,7 +273,7 @@ compare(int natoms, int n1, rvec **eigvec1, int n2, rvec **eigvec2, if (neig1 != n || neig2 != n) { fprintf(stdout, "this is %d%% and %d%% of the total trace\n", - static_cast(100*sum1/trace1+0.5), static_cast(100*sum2/trace2+0.5)); + gmx::roundToInt(100*sum1/trace1), gmx::roundToInt(100*sum2/trace2)); } fprintf(stdout, "Square root of the traces: %g and %g\n", std::sqrt(sum1), std::sqrt(sum2)); diff --git a/src/gromacs/gmxana/gmx_analyze.cpp b/src/gromacs/gmxana/gmx_analyze.cpp index d76bc83f6c..4e98ff3d98 100644 --- a/src/gromacs/gmxana/gmx_analyze.cpp +++ b/src/gromacs/gmxana/gmx_analyze.cpp @@ -271,7 +271,7 @@ static void histogram(const char *distfile, real binwidth, int n, int nset, real } maxval += binwidth; - nbin = static_cast(((maxval - minval)/binwidth + 0.5) + 1); + nbin = gmx::roundToInt(((maxval - minval)/binwidth) + 1); fprintf(stderr, "Making distributions with %d bins\n", nbin); snew(histo, nbin); fp = xvgropen(distfile, "Distribution", "", "", oenv); @@ -283,7 +283,7 @@ static void histogram(const char *distfile, real binwidth, int n, int nset, real } for (i = 0; i < n; i++) { - histo[static_cast((val[s][i] - minval)/binwidth + 0.5)]++; + histo[gmx::roundToInt((val[s][i] - minval)/binwidth)]++; } for (i = 0; i < nbin; i++) { @@ -334,9 +334,9 @@ static void average(const char *avfile, int avbar_opt, { snew(tmp, nset); fprintf(fp, "@TYPE xydydy\n"); - edge = static_cast(nset*0.05+0.5); + edge = gmx::roundToInt(nset*0.05); fprintf(stdout, "Errorbars: discarding %d points on both sides: %d%%" - " interval\n", edge, static_cast(100.*(nset-2*edge)/nset+0.5)); + " interval\n", edge, gmx::roundToInt(100.*(nset-2*edge)/nset)); } else { diff --git a/src/gromacs/gmxana/gmx_angle.cpp b/src/gromacs/gmxana/gmx_angle.cpp index c1f2370c1b..1b56598e0f 100644 --- a/src/gromacs/gmxana/gmx_angle.cpp +++ b/src/gromacs/gmxana/gmx_angle.cpp @@ -229,7 +229,7 @@ int gmx_g_angle(int argc, char *argv[]) } /* Calculate bin size */ - maxangstat = static_cast(maxang/binwidth+0.5); + maxangstat = gmx::roundToInt(maxang/binwidth); binwidth = maxang/maxangstat; rd_index(ftp2fn(efNDX, NFILE, fnm), 1, &isize, &index, &grpname); diff --git a/src/gromacs/gmxana/gmx_densmap.cpp b/src/gromacs/gmxana/gmx_densmap.cpp index de5e182276..8ba3593944 100644 --- a/src/gromacs/gmxana/gmx_densmap.cpp +++ b/src/gromacs/gmxana/gmx_densmap.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, 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. @@ -241,17 +241,17 @@ int gmx_densmap(int argc, char *argv[]) { if (n1 == 0) { - n1 = static_cast(box[c1][c1]/bin + 0.5); + n1 = gmx::roundToInt(box[c1][c1]/bin); } if (n2 == 0) { - n2 = static_cast(box[c2][c2]/bin + 0.5); + n2 = gmx::roundToInt(box[c2][c2]/bin); } } else { - n1 = static_cast(2*amax/bin + 0.5); - nradial = static_cast(rmax/bin + 0.5); + n1 = gmx::roundToInt(2*amax/bin); + nradial = gmx::roundToInt(rmax/bin); invspa = n1/(2*amax); invspz = nradial/rmax; if (bMirror) diff --git a/src/gromacs/gmxana/gmx_dipoles.cpp b/src/gromacs/gmxana/gmx_dipoles.cpp index 302818b18e..5fe85b58a2 100644 --- a/src/gromacs/gmxana/gmx_dipoles.cpp +++ b/src/gromacs/gmxana/gmx_dipoles.cpp @@ -1120,7 +1120,7 @@ static void do_dip(const t_topology *top, int ePBC, real volume, mu_ave += mu_mol; /* calc. the average mu */ /* Update the dipole distribution */ - ibin = static_cast(ndipbin*mu_mol/mu_max + 0.5); + ibin = gmx::roundToInt(ndipbin*mu_mol/mu_max); if (ibin < ndipbin) { dipole_bin[ibin]++; diff --git a/src/gromacs/gmxana/gmx_editconf.cpp b/src/gromacs/gmxana/gmx_editconf.cpp index 9d012ec3ee..5b249260b0 100644 --- a/src/gromacs/gmxana/gmx_editconf.cpp +++ b/src/gromacs/gmxana/gmx_editconf.cpp @@ -381,9 +381,9 @@ static void visualize_box(FILE *out, int a0, int r0, matrix box, const rvec grid a0++; r0++; - nx = static_cast(gridsize[XX] + 0.5); - ny = static_cast(gridsize[YY] + 0.5); - nz = static_cast(gridsize[ZZ] + 0.5); + nx = gmx::roundToInt(gridsize[XX]); + ny = gmx::roundToInt(gridsize[YY]); + nz = gmx::roundToInt(gridsize[ZZ]); nbox = nx * ny * nz; if (TRICLINIC(box)) { diff --git a/src/gromacs/gmxana/gmx_msd.cpp b/src/gromacs/gmxana/gmx_msd.cpp index 3d4e240a2f..8c54f617e6 100644 --- a/src/gromacs/gmxana/gmx_msd.cpp +++ b/src/gromacs/gmxana/gmx_msd.cpp @@ -957,7 +957,7 @@ static void do_corr(const char *trx_file, const char *ndx_file, const char *msd_ if (beginfit == -1) { - i0 = static_cast(0.1*(msd->nframes - 1) + 0.5); + i0 = gmx::roundToInt(0.1*(msd->nframes - 1)); beginfit = msd->time[i0]; } else @@ -970,7 +970,7 @@ static void do_corr(const char *trx_file, const char *ndx_file, const char *msd_ if (endfit == -1) { - i1 = static_cast(0.9*(msd->nframes - 1) + 0.5) + 1; + i1 = gmx::roundToInt(0.9*(msd->nframes - 1)) + 1; endfit = msd->time[i1-1]; } else diff --git a/src/gromacs/gmxana/gmx_rms.cpp b/src/gromacs/gmxana/gmx_rms.cpp index e981c775e6..1e29cc0fd4 100644 --- a/src/gromacs/gmxana/gmx_rms.cpp +++ b/src/gromacs/gmxana/gmx_rms.cpp @@ -845,7 +845,7 @@ int gmx_rms(int argc, char *argv[]) if (bDeltaLog) { delta_scalex = 8.0/std::log(2.0); - delta_xsize = static_cast(std::log(tel_mat/2.)*delta_scalex+0.5)+1; + delta_xsize = gmx::roundToInt(std::log(tel_mat/2.)*delta_scalex)+1; } else { @@ -1035,9 +1035,9 @@ int gmx_rms(int argc, char *argv[]) { if (bDeltaLog) { - mx = static_cast(std::log(static_cast(mx))*delta_scalex+0.5); + mx = gmx::roundToInt(std::log(static_cast(mx))*delta_scalex); } - my = static_cast(rmsd_mat[i][j]*delta_scaley*del_lev+0.5); + my = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*del_lev); delta_tot[mx] += 1.0; if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy)) { diff --git a/src/gromacs/gmxana/gmx_rmsdist.cpp b/src/gromacs/gmxana/gmx_rmsdist.cpp index 6cf2eae1ed..0e47df8cc6 100644 --- a/src/gromacs/gmxana/gmx_rmsdist.cpp +++ b/src/gromacs/gmxana/gmx_rmsdist.cpp @@ -547,7 +547,7 @@ static void write_noe(FILE *fp, int gnr, t_noe **noe, t_noe_gr *noe_gr, real rma "%4d %4d %4s %4s%3d %4d %4d %4s %4s%3d %5s %5s %8d %2d %2s %s\n", gri.ianr+1, gri.anr+1, gri.aname, gri.rname, gri.rnr+1, grj.ianr+1, grj.anr+1, grj.aname, grj.rname, grj.rnr+1, - b3, b6, static_cast(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf, + b3, b6, gmx::roundToInt(noe[i][j].i_6), grj.rnr-gri.rnr, buf, noe2scale(r3, r6, rmax)); } } diff --git a/src/gromacs/gmxana/gmx_sorient.cpp b/src/gromacs/gmxana/gmx_sorient.cpp index 2a88186f8b..837c234828 100644 --- a/src/gromacs/gmxana/gmx_sorient.cpp +++ b/src/gromacs/gmxana/gmx_sorient.cpp @@ -255,8 +255,8 @@ int gmx_sorient(int argc, char *argv[]) rcut2 = gmx::square(rcut); invbw = 1/binwidth; - nbin1 = 1+static_cast(2*invbw + 0.5); - nbin2 = 1+static_cast(invbw + 0.5); + nbin1 = 1+gmx::roundToInt(2*invbw); + nbin2 = 1+gmx::roundToInt(invbw); invrbw = 1/rbinw; diff --git a/src/gromacs/gmxana/gmx_tcaf.cpp b/src/gromacs/gmxana/gmx_tcaf.cpp index 6cb1ed63fc..7e1553e18e 100644 --- a/src/gromacs/gmxana/gmx_tcaf.cpp +++ b/src/gromacs/gmxana/gmx_tcaf.cpp @@ -107,9 +107,9 @@ static void process_tcaf(int nframes, real dt, int nkc, real **tc, rvec *kfac, } ncorr = (nframes+1)/2; - if (ncorr > static_cast(5*wt/dt+0.5)) + if (ncorr > gmx::roundToInt(5*wt/dt)) { - ncorr = static_cast(5*wt/dt+0.5)+1; + ncorr = gmx::roundToInt(5*wt/dt)+1; } snew(tcaf, nk); for (k = 0; k < nk; k++) diff --git a/src/gromacs/gmxana/gmx_vanhove.cpp b/src/gromacs/gmxana/gmx_vanhove.cpp index 7d2ca2c170..53e57368ef 100644 --- a/src/gromacs/gmxana/gmx_vanhove.cpp +++ b/src/gromacs/gmxana/gmx_vanhove.cpp @@ -240,7 +240,7 @@ int gmx_vanhove(int argc, char *argv[]) fmmax = nfr - 1; } snew(mcount, fmmax); - nbin = static_cast(rmax*invbin + 0.5); + nbin = gmx::roundToInt(rmax*invbin); if (sbin == 0) { mat_nx = fmmax + 1; @@ -334,14 +334,14 @@ int gmx_vanhove(int argc, char *argv[]) } else { - mbin = static_cast(std::sqrt(fbin*dt)*invsbin + 0.5); + mbin = gmx::roundToInt(std::sqrt(fbin*dt)*invsbin); } for (i = 0; i < isize; i++) { d2 = distance2(sx[f][i], sx[ff][i]); if (mbin < mat_nx && d2 < rmax2) { - bin = static_cast(std::sqrt(d2)*invbin + 0.5); + bin = gmx::roundToInt(std::sqrt(d2)*invbin); if (bin < nbin) { mat[mbin][bin] += 1; @@ -372,7 +372,7 @@ int gmx_vanhove(int argc, char *argv[]) for (i = 0; i < isize; i++) { d2 = distance2(sx[f][i], sx[ff][i]); - bin = static_cast(std::sqrt(d2)*invbin + 0.5); + bin = gmx::roundToInt(std::sqrt(d2)*invbin); if (bin >= nalloc) { nallocn = 10*(bin/10) + 11; diff --git a/src/gromacs/gmxana/gmx_wham.cpp b/src/gromacs/gmxana/gmx_wham.cpp index 1b8929506f..395d9e96de 100644 --- a/src/gromacs/gmxana/gmx_wham.cpp +++ b/src/gromacs/gmxana/gmx_wham.cpp @@ -659,7 +659,7 @@ static void read_pdo_data(FILE * file, t_UmbrellaHeader * header, sscanf(ptr, fmtlf, &time); /* printf("Time %f\n",time); */ /* Round time to fs */ - time = 1.0/1000*( static_cast (time*1000+0.5) ); + time = 1.0/1000*( gmx::roundToInt64(time*1000) ); /* get time step of pdo file */ if (count == 0) @@ -671,7 +671,7 @@ static void read_pdo_data(FILE * file, t_UmbrellaHeader * header, dt = time-time0; if (opt->dt > 0.0) { - dstep = static_cast(opt->dt/dt+0.5); + dstep = gmx::roundToInt(opt->dt/dt); if (dstep == 0) { dstep = 1; @@ -799,7 +799,7 @@ static void enforceEqualWeights(t_UmbrellaWindow * window, int nWindows) { window[j].Histo[k][i] *= ratio; } - window[j].N[k] = static_cast(ratio*window[j].N[k] + 0.5); + window[j].N[k] = gmx::roundToInt(ratio*window[j].N[k]); } } } @@ -1114,7 +1114,7 @@ static void symmetrizeProfile(double* profile, t_UmbrellaOptions *opt) z = min+(i+0.5)*dz; zsym = -z; /* bin left of zsym */ - j = static_cast (std::floor((zsym-min)/dz-0.5)); + j = gmx::roundToInt((zsym-min)/dz)-1; if (j >= 0 && (j+1) < bins) { /* interpolate profile linearly between bins j and j+1 */ @@ -2352,7 +2352,7 @@ static void read_pull_xf(const char *fn, t_UmbrellaHeader * header, for (i = 0; i < nt; i++) { /* Do you want that time frame? */ - t = 1.0/1000*( static_cast ((y[0][i]*1000) + 0.5)); /* round time to fs */ + t = 1.0/1000*( gmx::roundToInt64((y[0][i]*1000))); /* round time to fs */ /* get time step of pdo file and get dstep from opt->dt */ if (i == 0) @@ -2364,7 +2364,7 @@ static void read_pull_xf(const char *fn, t_UmbrellaHeader * header, dt = t-time0; if (opt->dt > 0.0) { - dstep = static_cast(opt->dt/dt+0.5); + dstep = gmx::roundToInt(opt->dt/dt); if (dstep == 0) { dstep = 1; @@ -2719,7 +2719,7 @@ static void calcIntegratedAutocorrelationTimes(t_UmbrellaWindow *window, int nwi snew(count, ncorr); dt = window[i].dt; snew(window[i].tau, window[i].nPull); - restart = static_cast(opt->acTrestart/dt+0.5); + restart = gmx::roundToInt(opt->acTrestart/dt); if (restart == 0) { restart = 1; diff --git a/src/gromacs/gmxana/sfactor.cpp b/src/gromacs/gmxana/sfactor.cpp index 4432f90606..603f458602 100644 --- a/src/gromacs/gmxana/sfactor.cpp +++ b/src/gromacs/gmxana/sfactor.cpp @@ -176,9 +176,9 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box, k_factor[YY] = 2 * M_PI / box[YY][YY]; k_factor[ZZ] = 2 * M_PI / box[ZZ][ZZ]; - maxkx = static_cast(end_q / k_factor[XX] + 0.5); - maxky = static_cast(end_q / k_factor[YY] + 0.5); - maxkz = static_cast(end_q / k_factor[ZZ] + 0.5); + maxkx = gmx::roundToInt(end_q / k_factor[XX]); + maxky = gmx::roundToInt(end_q / k_factor[YY]); + maxkz = gmx::roundToInt(end_q / k_factor[ZZ]); snew (counter, sf->n_angles); @@ -205,7 +205,7 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box, krr = std::sqrt (gmx::square(kx) + gmx::square(ky) + gmx::square(kz)); if (krr >= start_q && krr <= end_q) { - kr = static_cast(krr/sf->ref_k + 0.5); + kr = gmx::roundToInt(krr/sf->ref_k); if (kr < sf->n_angles) { counter[kr]++; /* will be used for the copmutation @@ -241,7 +241,7 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box, kz = k * k_factor[ZZ]; krr = std::sqrt (gmx::square(kx) + gmx::square(ky) + gmx::square(kz)); if (krr >= start_q && krr <= end_q) { - kr = static_cast(krr / sf->ref_k + 0.5); + kr = gmx::roundToInt(krr / sf->ref_k); if (kr < sf->n_angles && counter[kr] != 0) { sf->F[group][kr] += @@ -505,7 +505,7 @@ extern int do_scattering_intensity (const char* fnTPS, const char* fnNDX, sf->ref_k = (2.0 * M_PI) / (r_tmp); /* ref_k will be the reference momentum unit */ - sf->n_angles = static_cast(end_q / sf->ref_k + 0.5); + sf->n_angles = gmx::roundToInt(end_q / sf->ref_k); snew (sf->F, ng); for (i = 0; i < ng; i++) diff --git a/src/gromacs/gmxpreprocess/convparm.cpp b/src/gromacs/gmxpreprocess/convparm.cpp index aaea388177..525aa064e6 100644 --- a/src/gromacs/gmxpreprocess/convparm.cpp +++ b/src/gromacs/gmxpreprocess/convparm.cpp @@ -58,16 +58,7 @@ static int round_check(real r, int limit, int ftype, const char *name) { - int i; - - if (r >= 0) - { - i = static_cast(r + 0.5); - } - else - { - i = static_cast(r - 0.5); - } + const int i = gmx::roundToInt(r); if (r-i > 0.01 || r-i < -0.01) { diff --git a/src/gromacs/gmxpreprocess/genconf.cpp b/src/gromacs/gmxpreprocess/genconf.cpp index 70849f1e64..d3665adacf 100644 --- a/src/gromacs/gmxpreprocess/genconf.cpp +++ b/src/gromacs/gmxpreprocess/genconf.cpp @@ -169,9 +169,9 @@ int gmx_genconf(int argc, char *argv[]) gmx::DefaultRandomEngine rng(seed); bTRX = ftp2bSet(efTRX, NFILE, fnm); - nx = static_cast(nrbox[XX]+0.5); - ny = static_cast(nrbox[YY]+0.5); - nz = static_cast(nrbox[ZZ]+0.5); + nx = gmx::roundToInt(nrbox[XX]); + ny = gmx::roundToInt(nrbox[YY]); + nz = gmx::roundToInt(nrbox[ZZ]); if ((nx <= 0) || (ny <= 0) || (nz <= 0)) { diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index cbf86d9e30..338de9a82b 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -2061,7 +2061,7 @@ int gmx_grompp(int argc, char *argv[]) else { sprintf(warn_buf, "NVE simulation with an initial temperature of zero: will use a Verlet buffer of %d%%. Check your energy drift!", - static_cast(verlet_buffer_ratio_NVE_T0*100 + 0.5)); + gmx::roundToInt(verlet_buffer_ratio_NVE_T0*100)); warning_note(wi, warn_buf); } } @@ -2099,8 +2099,8 @@ int gmx_grompp(int argc, char *argv[]) { sprintf(warn_buf, "You are using a Verlet buffer tolerance of %g kJ/mol/ps for an NVE simulation of length %g ps, which can give a final drift of %d%%. For conserving energy to %d%% when using constraints, you might need to set verlet-buffer-tolerance to %.1e.", ir->verletbuf_tol, ir->nsteps*ir->delta_t, - static_cast(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100 + 0.5), - static_cast(100*driftTolerance + 0.5), + gmx::roundToInt(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100), + gmx::roundToInt(100*driftTolerance), driftTolerance*totalEnergyDriftPerAtomPerPicosecond); warning_note(wi, warn_buf); } diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 3425f9884e..62885e2ebd 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -4012,7 +4012,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys, { for (i = 0; i < ir->opts.ngtc; i++) { - int nsteps = static_cast(ir->opts.tau_t[i]/ir->delta_t + 0.5); + int nsteps = gmx::roundToInt(ir->opts.tau_t[i]/ir->delta_t); sprintf(err_buf, "tau_t/delta_t for group %d for temperature control method %s must be a multiple of nstcomm (%d), as velocities of atoms in coupled groups are randomized every time step. The input tau_t (%8.3f) leads to %d steps per randomization", i, etcoupl_names[ir->etc], ir->nstcomm, ir->opts.tau_t[i], nsteps); CHECK(nsteps % ir->nstcomm != 0); } diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index 46cf9f3bbd..8acd507abf 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -52,6 +52,7 @@ #include "gromacs/gmxpreprocess/readir.h" #include "gromacs/gmxpreprocess/topdirs.h" #include "gromacs/gmxpreprocess/toputil.h" +#include "gromacs/math/functions.h" #include "gromacs/mdtypes/md_enums.h" #include "gromacs/topology/ifunc.h" #include "gromacs/topology/symtab.h" @@ -2070,7 +2071,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[], { sprintf(errbuf, "%s table number can not be perturbed %d!=%d", interaction_function[ftype].longname, - static_cast(param.c[0]+0.5), static_cast(param.c[2]+0.5)); + gmx::roundToInt(param.c[0]), gmx::roundToInt(param.c[2])); warning_error_and_exit(wi, errbuf, FARGS); } diff --git a/src/gromacs/mdlib/coupling.cpp b/src/gromacs/mdlib/coupling.cpp index 8d9313a8b3..27304afeed 100644 --- a/src/gromacs/mdlib/coupling.cpp +++ b/src/gromacs/mdlib/coupling.cpp @@ -1448,7 +1448,7 @@ static real vrescale_sumnoises(real nn, int nn_int, i; real gauss; - nn_int = static_cast(nn + 0.5); + nn_int = gmx::roundToInt(nn); if (nn - nn_int < -ndeg_tol || nn - nn_int > ndeg_tol) { diff --git a/src/gromacs/mdlib/nbnxn_search.cpp b/src/gromacs/mdlib/nbnxn_search.cpp index bc2ee37f55..eae0873ae6 100644 --- a/src/gromacs/mdlib/nbnxn_search.cpp +++ b/src/gromacs/mdlib/nbnxn_search.cpp @@ -2773,7 +2773,7 @@ static void get_nsubpair_target(const nbnxn_search *nbs, * (and we can't chop up j-groups) so we use a minimum target size of 36. */ *nsubpair_target = std::max(nsubpair_target_min, - static_cast(nsp_est/min_ci_balanced + 0.5)); + roundToInt(nsp_est/min_ci_balanced)); *nsubpair_tot_est = static_cast(nsp_est); if (debug) diff --git a/src/gromacs/mdlib/nsgrid.cpp b/src/gromacs/mdlib/nsgrid.cpp index 4c8df50a1c..941fe11c37 100644 --- a/src/gromacs/mdlib/nsgrid.cpp +++ b/src/gromacs/mdlib/nsgrid.cpp @@ -320,7 +320,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis * we will use the normal grid ns that checks all cells * that are within cut-off distance of the i-particle. */ - grid->n[i] = static_cast(size*inv_r_ideal + 0.5); + grid->n[i] = gmx::roundToInt(size*inv_r_ideal); if (grid->n[i] < 2) { grid->n[i] = 2; @@ -335,7 +335,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis * We can then beforehand exclude certain ns grid cells * for non-home i-particles. */ - grid->ncpddc[i] = static_cast(izones_size[i]*inv_r_ideal + 0.5); + grid->ncpddc[i] = gmx::roundToInt(izones_size[i]*inv_r_ideal); if (grid->ncpddc[i] < 2) { grid->ncpddc[i] = 2; diff --git a/src/gromacs/mdlib/shellfc.cpp b/src/gromacs/mdlib/shellfc.cpp index e4b54384c5..667c958150 100644 --- a/src/gromacs/mdlib/shellfc.cpp +++ b/src/gromacs/mdlib/shellfc.cpp @@ -848,7 +848,7 @@ static real rms_force(const t_commrec *cr, gmx::ArrayRef force, buf[2] = *sf_dir; buf[3] = *Epot; gmx_sumd(4, buf, cr); - ntot = static_cast(buf[1] + 0.5); + ntot = gmx::roundToInt(buf[1]); *sf_dir = buf[2]; *Epot = buf[3]; } diff --git a/src/gromacs/mdlib/stat.cpp b/src/gromacs/mdlib/stat.cpp index 4a118743c5..c24ef03006 100644 --- a/src/gromacs/mdlib/stat.cpp +++ b/src/gromacs/mdlib/stat.cpp @@ -371,7 +371,7 @@ void global_stat(gmx_global_stat_t gs, if (checkNumberOfBondedInteractions) { extract_bind(rb, inb, 1, &nb); - *totalNumberOfBondedInteractions = static_cast(nb+0.5); + *totalNumberOfBondedInteractions = gmx::roundToInt(nb); } if (nsig > 0) diff --git a/src/gromacs/mdlib/update.cpp b/src/gromacs/mdlib/update.cpp index 67af223fc9..5578853df9 100644 --- a/src/gromacs/mdlib/update.cpp +++ b/src/gromacs/mdlib/update.cpp @@ -1956,7 +1956,7 @@ extern gmx_bool update_randomize_velocities(t_inputrec *ir, int64_t step, const /* proceed with andersen if 1) it's fixed probability per particle andersen or 2) it's massive andersen and it's tau_t/dt */ - if ((ir->etc == etcANDERSEN) || do_per_step(step, static_cast(1.0/rate + 0.5))) + if ((ir->etc == etcANDERSEN) || do_per_step(step, roundToInt(1.0/rate))) { andersen_tcoupl(ir, step, cr, md, state, rate, upd->sd->randomize_group, upd->sd->boltzfac); diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index 8019ffa10b..d1276689c2 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -313,7 +313,7 @@ static void get_f_norm_max(const t_commrec *cr, if (sum[2*i] > fmax2) { fmax2 = sum[2*i]; - a_max = static_cast(sum[2*i+1] + 0.5); + a_max = gmx::roundToInt(sum[2*i+1]); } } sfree(sum); diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 66d8f30ba6..8e6fd483ee 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -734,9 +734,8 @@ Integrator::do_tpi() } else { - i = static_cast((bU_logV_bin_limit - - (beta*epot - logV + refvolshift))*invbinw - + 0.5); + i = gmx::roundToInt((bU_logV_bin_limit + - (beta*epot - logV + refvolshift))*invbinw); if (i < 0) { i = 0; @@ -848,7 +847,7 @@ Integrator::do_tpi() bUlogV = -i/invbinw + bU_logV_bin_limit - refvolshift + log(V_all/frame); fprintf(fp_tpi, "%6.2f %10d %12.5e\n", bUlogV, - static_cast(bin[i]+0.5), + roundToInt(bin[i]), bin[i]*exp(-bUlogV)*V_all/VembU_all); } xvgrclose(fp_tpi); diff --git a/src/gromacs/pulling/pull_rotation.cpp b/src/gromacs/pulling/pull_rotation.cpp index 315433b9ab..76badaeda5 100644 --- a/src/gromacs/pulling/pull_rotation.cpp +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -1703,7 +1703,6 @@ static inline void shift_single_coord(const matrix box, rvec x, const ivec is) /* Determine the 'home' slab of this atom which is the * slab with the highest Gaussian weight of all */ -#define round(a) int((a)+0.5) static inline int get_homeslab( rvec curr_x, /* The position for which the home slab shall be determined */ const rvec rotvec, /* The rotation vector */ @@ -1716,7 +1715,7 @@ static inline int get_homeslab( * slab with index 0) is */ dist = iprod(rotvec, curr_x); - return round(dist / slabdist); + return gmx::roundToInt(dist / slabdist); } diff --git a/src/gromacs/statistics/statistics.cpp b/src/gromacs/statistics/statistics.cpp index 7097595430..ee4cecb124 100644 --- a/src/gromacs/statistics/statistics.cpp +++ b/src/gromacs/statistics/statistics.cpp @@ -48,7 +48,7 @@ static int gmx_dnint(double x) { - return static_cast(x+0.5); + return gmx::roundToInt(x); } typedef struct gmx_stats { diff --git a/src/gromacs/tables/forcetable.cpp b/src/gromacs/tables/forcetable.cpp index 1b0ecc2dfd..f3e462e8b6 100644 --- a/src/gromacs/tables/forcetable.cpp +++ b/src/gromacs/tables/forcetable.cpp @@ -708,7 +708,9 @@ static void read_tables(FILE *fp, const char *fn, if (ns > 0) { ssd /= ns; - sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %lld%% from minus the numerical derivative of the potential\n", ns, k, libfn, static_cast(100*ssd+0.5)); + sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %" PRId64 + "%% from minus the numerical derivative of the potential\n", + ns, k, libfn, gmx::roundToInt64(100*ssd)); if (debug) { fprintf(debug, "%s", buf); @@ -1369,7 +1371,7 @@ t_forcetable *make_tables(FILE *out, gmx_fatal(FARGS, "Tables in file %s not long enough for cut-off:\n" "\tshould be at least %f nm\n", fn, rtab); } - table->n = static_cast(rtab*td[0].tabscale + 0.5); + table->n = gmx::roundToInt(rtab*td[0].tabscale); } table->scale = td[0].tabscale; nx0 = td[0].nx0; diff --git a/src/gromacs/timing/wallcycle.cpp b/src/gromacs/timing/wallcycle.cpp index a7eeb65846..e521c47010 100644 --- a/src/gromacs/timing/wallcycle.cpp +++ b/src/gromacs/timing/wallcycle.cpp @@ -45,6 +45,7 @@ #include #include +#include "gromacs/math/functions.h" #include "gromacs/mdtypes/commrec.h" #include "gromacs/timing/cyclecounter.h" #include "gromacs/timing/gpu_timing.h" @@ -575,14 +576,14 @@ WallcycleCounts wallcycle_sum(const t_commrec *cr, gmx_wallcycle_t wc) cr->mpi_comm_mysim); for (i = 0; i < ewcNR; i++) { - wcc[i].n = static_cast(buf[i] + 0.5); + wcc[i].n = gmx::roundToInt(buf[i]); } wc->haveInvalidCount = (buf[nsum] > 0); if (wc->wcsc) { for (i = 0; i < ewcsNR; i++) { - wc->wcsc[i].n = static_cast(buf[ewcNR+i] + 0.5); + wc->wcsc[i].n = gmx::roundToInt(buf[ewcNR+i]); } } @@ -1054,7 +1055,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted( "NOTE: %d %% of the run time was spent in pair search,\n" " you might want to increase nstlist (this has no effect on accuracy)\n", - static_cast(100*cyc_sum[ewcNS]/tot+0.5)); + gmx::roundToInt(100*cyc_sum[ewcNS]/tot)); } else { @@ -1062,8 +1063,8 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np "NOTE: %d %% of the run time was spent in domain decomposition,\n" " %d %% of the run time was spent in pair search,\n" " you might want to increase nstlist (this has no effect on accuracy)\n", - static_cast(100*cyc_sum[ewcDOMDEC]/tot+0.5), - static_cast(100*cyc_sum[ewcNS]/tot+0.5)); + gmx::roundToInt(100*cyc_sum[ewcDOMDEC]/tot), + gmx::roundToInt(100*cyc_sum[ewcNS]/tot)); } } @@ -1072,7 +1073,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted( "NOTE: %d %% of the run time was spent communicating energies,\n" " you might want to use the -gcom option of mdrun\n", - static_cast(100*cyc_sum[ewcMoveE]/tot+0.5)); + gmx::roundToInt(100*cyc_sum[ewcMoveE]/tot)); } } diff --git a/src/gromacs/tools/convert_tpr.cpp b/src/gromacs/tools/convert_tpr.cpp index d4fca39d74..343fa5525b 100644 --- a/src/gromacs/tools/convert_tpr.cpp +++ b/src/gromacs/tools/convert_tpr.cpp @@ -404,7 +404,7 @@ int gmx_convert_tpr(int argc, char *argv[]) /* Determine total number of steps remaining */ if (bExtend) { - ir->nsteps = ir->nsteps - (run_step - ir->init_step) + static_cast(extend_t/ir->delta_t + 0.5); + ir->nsteps = ir->nsteps - (run_step - ir->init_step) + gmx::roundToInt64(extend_t/ir->delta_t); printf("Extending remaining runtime of by %g ps (now %s steps)\n", extend_t, gmx_step_str(ir->nsteps, buf)); } @@ -414,7 +414,7 @@ int gmx_convert_tpr(int argc, char *argv[]) gmx_step_str(ir->nsteps, buf), gmx_step_str(run_step, buf2), run_t, until_t); - ir->nsteps = static_cast((until_t - run_t)/ir->delta_t + 0.5); + ir->nsteps = gmx::roundToInt64((until_t - run_t)/ir->delta_t); printf("Extending remaining runtime until %g ps (now %s steps)\n", until_t, gmx_step_str(ir->nsteps, buf)); } diff --git a/src/programs/mdrun/mdrun.cpp b/src/programs/mdrun/mdrun.cpp index ae214d59a5..651b97a4c2 100644 --- a/src/programs/mdrun/mdrun.cpp +++ b/src/programs/mdrun/mdrun.cpp @@ -499,9 +499,9 @@ int Mdrunner::mainFunction(int argc, char *argv[]) domdecOptions.rankOrder = static_cast(nenum(ddrank_opt_choices)); domdecOptions.dlbOption = static_cast(nenum(dddlb_opt_choices)); - domdecOptions.numCells[XX] = static_cast(realddxyz[XX] + 0.5); - domdecOptions.numCells[YY] = static_cast(realddxyz[YY] + 0.5); - domdecOptions.numCells[ZZ] = static_cast(realddxyz[ZZ] + 0.5); + domdecOptions.numCells[XX] = roundToInt(realddxyz[XX]); + domdecOptions.numCells[YY] = roundToInt(realddxyz[YY]); + domdecOptions.numCells[ZZ] = roundToInt(realddxyz[ZZ]); nbpu_opt = nbpu_opt_choices[0]; pme_opt = pme_opt_choices[0]; -- 2.22.0