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,
#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"
binWidth_ = settings.binWidth_;
firstEdge_ = binWidth_ * std::floor(settings.min_ / binWidth_);
lastEdge_ = binWidth_ * std::ceil(settings.max_ / binWidth_);
- binCount_ = static_cast<int>((lastEdge_ - firstEdge_) / binWidth_ + 0.5);
+ binCount_ = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_);
}
else
{
else
{
binWidth_ = settings.binWidth_;
- binCount_ = static_cast<int>((lastEdge_ - firstEdge_) / binWidth_ + 0.5);
+ binCount_ = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_);
if (settings.bIntegerBins_)
{
firstEdge_ -= 0.5 * binWidth_;
#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"
numSamples += point.weightSumTot();
}
- return static_cast<int64_t>(numSamples + 0.5);
+ return gmx::roundToInt64(numSamples);
}
/*! \brief
#include <algorithm>
+#include "gromacs/math/functions.h"
#include "gromacs/math/utilities.h"
#include "gromacs/mdtypes/awh-params.h"
#include "gromacs/utility/cstringutil.h"
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<int>(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());
relative_to_absolute_cell_bounds(dd, ddbox, d1);
}
/* Convert the communicated shift from float to int */
- comm.ddpme[0].maxshift = static_cast<int>(cellFracRow[pos++] + 0.5);
+ comm.ddpme[0].maxshift = gmx::roundToInt(cellFracRow[pos++]);
if (d >= 1)
{
- comm.ddpme[1].maxshift = static_cast<int>(cellFracRow[pos++] + 0.5);
+ comm.ddpme[1].maxshift = gmx::roundToInt(cellFracRow[pos++]);
}
}
fprintf(fplog, "Atom distribution over %d domains: av %d stddev %d min %d max %d\n",
dd->nnodes,
nat_sum,
- static_cast<int>(std::sqrt(nat2_sum - gmx::square(static_cast<double>(nat_sum)) + 0.5)),
+ gmx::roundToInt(std::sqrt(nat2_sum - gmx::square(static_cast<double>(nat_sum)))),
nat_min, nat_max);
}
pos++;
if (d < dd->ndim-1)
{
- load->flags = static_cast<int>(load->load[pos++] + 0.5);
+ load->flags = gmx::roundToInt(load->load[pos++]);
}
if (d > 0)
{
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<int>(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());
}
if (dd->nnodes > 1)
{
- fprintf(stderr, "imb F %2d%% ", static_cast<int>(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])
{
s1[d] = receiveBuffer[d];
s2[d] = receiveBuffer[DIM + d];
}
- n = static_cast<int>(receiveBuffer[6] + 0.5);
+ n = gmx::roundToInt(receiveBuffer[6]);
}
#else // GMX_MPI
GMX_UNUSED_VALUE(mpiCommunicator);
std::vector<int> mdiv;
factorize(ntot - npme, &div, &mdiv);
- int npp_root3 = static_cast<int>(std::cbrt(ntot - npme) + 0.5);
- int npme_root2 = static_cast<int>(std::sqrt(static_cast<double>(npme)) + 0.5);
+ int npp_root3 = gmx::roundToInt(std::cbrt(ntot - npme));
+ int npme_root2 = gmx::roundToInt(std::sqrt(static_cast<double>(npme)));
/* The check below gives a reasonable division:
* factor 5 allowed at 5 or more PP ranks,
{
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<int>(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
{
" 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<int>((imbal-1)*100 + 0.5),
+ gmx::roundToInt((imbal-1)*100),
pme->nkx, pme->nky, pme->nnodes_major,
pme->nky, pme->nkz, pme->nnodes_minor);
}
gmx_fatal(FARGS, "DEATH HORROR prec (%g) <= 0 in prec2ndec", prec);
}
- return static_cast<int>(log(prec)/log(10.0)+0.5);
+ return gmx::roundToInt(log(prec)/log(10.0));
}
real ndec2prec(int ndec)
}
/* Update the distribution histogram */
- angind = static_cast<int>((angle*maxangstat)/pifac + 0.5);
+ angind = gmx::roundToInt((angle*maxangstat)/pifac);
if (angind == maxangstat)
{
angind = 0;
*
* 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.
{
for (j = i+1; j < nn; j++)
{
- x = static_cast<int>(fac*mat[i][j]+0.5);
+ x = gmx::roundToInt(fac*mat[i][j]);
if (x <= 100)
{
histo[x]++;
if (neig1 != n || neig2 != n)
{
fprintf(stdout, "this is %d%% and %d%% of the total trace\n",
- static_cast<int>(100*sum1/trace1+0.5), static_cast<int>(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));
}
maxval += binwidth;
- nbin = static_cast<int>(((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);
}
for (i = 0; i < n; i++)
{
- histo[static_cast<int>((val[s][i] - minval)/binwidth + 0.5)]++;
+ histo[gmx::roundToInt((val[s][i] - minval)/binwidth)]++;
}
for (i = 0; i < nbin; i++)
{
{
snew(tmp, nset);
fprintf(fp, "@TYPE xydydy\n");
- edge = static_cast<int>(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<int>(100.*(nset-2*edge)/nset+0.5));
+ " interval\n", edge, gmx::roundToInt(100.*(nset-2*edge)/nset));
}
else
{
}
/* Calculate bin size */
- maxangstat = static_cast<int>(maxang/binwidth+0.5);
+ maxangstat = gmx::roundToInt(maxang/binwidth);
binwidth = maxang/maxangstat;
rd_index(ftp2fn(efNDX, NFILE, fnm), 1, &isize, &index, &grpname);
*
* 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.
{
if (n1 == 0)
{
- n1 = static_cast<int>(box[c1][c1]/bin + 0.5);
+ n1 = gmx::roundToInt(box[c1][c1]/bin);
}
if (n2 == 0)
{
- n2 = static_cast<int>(box[c2][c2]/bin + 0.5);
+ n2 = gmx::roundToInt(box[c2][c2]/bin);
}
}
else
{
- n1 = static_cast<int>(2*amax/bin + 0.5);
- nradial = static_cast<int>(rmax/bin + 0.5);
+ n1 = gmx::roundToInt(2*amax/bin);
+ nradial = gmx::roundToInt(rmax/bin);
invspa = n1/(2*amax);
invspz = nradial/rmax;
if (bMirror)
mu_ave += mu_mol; /* calc. the average mu */
/* Update the dipole distribution */
- ibin = static_cast<int>(ndipbin*mu_mol/mu_max + 0.5);
+ ibin = gmx::roundToInt(ndipbin*mu_mol/mu_max);
if (ibin < ndipbin)
{
dipole_bin[ibin]++;
a0++;
r0++;
- nx = static_cast<int>(gridsize[XX] + 0.5);
- ny = static_cast<int>(gridsize[YY] + 0.5);
- nz = static_cast<int>(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))
{
if (beginfit == -1)
{
- i0 = static_cast<int>(0.1*(msd->nframes - 1) + 0.5);
+ i0 = gmx::roundToInt(0.1*(msd->nframes - 1));
beginfit = msd->time[i0];
}
else
if (endfit == -1)
{
- i1 = static_cast<int>(0.9*(msd->nframes - 1) + 0.5) + 1;
+ i1 = gmx::roundToInt(0.9*(msd->nframes - 1)) + 1;
endfit = msd->time[i1-1];
}
else
if (bDeltaLog)
{
delta_scalex = 8.0/std::log(2.0);
- delta_xsize = static_cast<int>(std::log(tel_mat/2.)*delta_scalex+0.5)+1;
+ delta_xsize = gmx::roundToInt(std::log(tel_mat/2.)*delta_scalex)+1;
}
else
{
{
if (bDeltaLog)
{
- mx = static_cast<int>(std::log(static_cast<real>(mx))*delta_scalex+0.5);
+ mx = gmx::roundToInt(std::log(static_cast<real>(mx))*delta_scalex);
}
- my = static_cast<int>(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))
{
"%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<int>(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));
}
}
rcut2 = gmx::square(rcut);
invbw = 1/binwidth;
- nbin1 = 1+static_cast<int>(2*invbw + 0.5);
- nbin2 = 1+static_cast<int>(invbw + 0.5);
+ nbin1 = 1+gmx::roundToInt(2*invbw);
+ nbin2 = 1+gmx::roundToInt(invbw);
invrbw = 1/rbinw;
}
ncorr = (nframes+1)/2;
- if (ncorr > static_cast<int>(5*wt/dt+0.5))
+ if (ncorr > gmx::roundToInt(5*wt/dt))
{
- ncorr = static_cast<int>(5*wt/dt+0.5)+1;
+ ncorr = gmx::roundToInt(5*wt/dt)+1;
}
snew(tcaf, nk);
for (k = 0; k < nk; k++)
fmmax = nfr - 1;
}
snew(mcount, fmmax);
- nbin = static_cast<int>(rmax*invbin + 0.5);
+ nbin = gmx::roundToInt(rmax*invbin);
if (sbin == 0)
{
mat_nx = fmmax + 1;
}
else
{
- mbin = static_cast<int>(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<int>(std::sqrt(d2)*invbin + 0.5);
+ bin = gmx::roundToInt(std::sqrt(d2)*invbin);
if (bin < nbin)
{
mat[mbin][bin] += 1;
for (i = 0; i < isize; i++)
{
d2 = distance2(sx[f][i], sx[ff][i]);
- bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
+ bin = gmx::roundToInt(std::sqrt(d2)*invbin);
if (bin >= nalloc)
{
nallocn = 10*(bin/10) + 11;
sscanf(ptr, fmtlf, &time); /* printf("Time %f\n",time); */
/* Round time to fs */
- time = 1.0/1000*( static_cast<int64_t> (time*1000+0.5) );
+ time = 1.0/1000*( gmx::roundToInt64(time*1000) );
/* get time step of pdo file */
if (count == 0)
dt = time-time0;
if (opt->dt > 0.0)
{
- dstep = static_cast<int>(opt->dt/dt+0.5);
+ dstep = gmx::roundToInt(opt->dt/dt);
if (dstep == 0)
{
dstep = 1;
{
window[j].Histo[k][i] *= ratio;
}
- window[j].N[k] = static_cast<int>(ratio*window[j].N[k] + 0.5);
+ window[j].N[k] = gmx::roundToInt(ratio*window[j].N[k]);
}
}
}
z = min+(i+0.5)*dz;
zsym = -z;
/* bin left of zsym */
- j = static_cast<int> (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 */
for (i = 0; i < nt; i++)
{
/* Do you want that time frame? */
- t = 1.0/1000*( static_cast<int64_t> ((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)
dt = t-time0;
if (opt->dt > 0.0)
{
- dstep = static_cast<int>(opt->dt/dt+0.5);
+ dstep = gmx::roundToInt(opt->dt/dt);
if (dstep == 0)
{
dstep = 1;
snew(count, ncorr);
dt = window[i].dt;
snew(window[i].tau, window[i].nPull);
- restart = static_cast<int>(opt->acTrestart/dt+0.5);
+ restart = gmx::roundToInt(opt->acTrestart/dt);
if (restart == 0)
{
restart = 1;
k_factor[YY] = 2 * M_PI / box[YY][YY];
k_factor[ZZ] = 2 * M_PI / box[ZZ][ZZ];
- maxkx = static_cast<int>(end_q / k_factor[XX] + 0.5);
- maxky = static_cast<int>(end_q / k_factor[YY] + 0.5);
- maxkz = static_cast<int>(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);
krr = std::sqrt (gmx::square(kx) + gmx::square(ky) + gmx::square(kz));
if (krr >= start_q && krr <= end_q)
{
- kr = static_cast<int>(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
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<int>(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] +=
sf->ref_k = (2.0 * M_PI) / (r_tmp);
/* ref_k will be the reference momentum unit */
- sf->n_angles = static_cast<int>(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++)
static int round_check(real r, int limit, int ftype, const char *name)
{
- int i;
-
- if (r >= 0)
- {
- i = static_cast<int>(r + 0.5);
- }
- else
- {
- i = static_cast<int>(r - 0.5);
- }
+ const int i = gmx::roundToInt(r);
if (r-i > 0.01 || r-i < -0.01)
{
gmx::DefaultRandomEngine rng(seed);
bTRX = ftp2bSet(efTRX, NFILE, fnm);
- nx = static_cast<int>(nrbox[XX]+0.5);
- ny = static_cast<int>(nrbox[YY]+0.5);
- nz = static_cast<int>(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))
{
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<int>(verlet_buffer_ratio_NVE_T0*100 + 0.5));
+ gmx::roundToInt(verlet_buffer_ratio_NVE_T0*100));
warning_note(wi, warn_buf);
}
}
{
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<int>(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100 + 0.5),
- static_cast<int>(100*driftTolerance + 0.5),
+ gmx::roundToInt(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100),
+ gmx::roundToInt(100*driftTolerance),
driftTolerance*totalEnergyDriftPerAtomPerPicosecond);
warning_note(wi, warn_buf);
}
{
for (i = 0; i < ir->opts.ngtc; i++)
{
- int nsteps = static_cast<int>(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);
}
#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"
{
sprintf(errbuf, "%s table number can not be perturbed %d!=%d",
interaction_function[ftype].longname,
- static_cast<int>(param.c[0]+0.5), static_cast<int>(param.c[2]+0.5));
+ gmx::roundToInt(param.c[0]), gmx::roundToInt(param.c[2]));
warning_error_and_exit(wi, errbuf, FARGS);
}
int nn_int, i;
real gauss;
- nn_int = static_cast<int>(nn + 0.5);
+ nn_int = gmx::roundToInt(nn);
if (nn - nn_int < -ndeg_tol || nn - nn_int > ndeg_tol)
{
* (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<int>(nsp_est/min_ci_balanced + 0.5));
+ roundToInt(nsp_est/min_ci_balanced));
*nsubpair_tot_est = static_cast<int>(nsp_est);
if (debug)
* 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<int>(size*inv_r_ideal + 0.5);
+ grid->n[i] = gmx::roundToInt(size*inv_r_ideal);
if (grid->n[i] < 2)
{
grid->n[i] = 2;
* We can then beforehand exclude certain ns grid cells
* for non-home i-particles.
*/
- grid->ncpddc[i] = static_cast<int>(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;
buf[2] = *sf_dir;
buf[3] = *Epot;
gmx_sumd(4, buf, cr);
- ntot = static_cast<int>(buf[1] + 0.5);
+ ntot = gmx::roundToInt(buf[1]);
*sf_dir = buf[2];
*Epot = buf[3];
}
if (checkNumberOfBondedInteractions)
{
extract_bind(rb, inb, 1, &nb);
- *totalNumberOfBondedInteractions = static_cast<int>(nb+0.5);
+ *totalNumberOfBondedInteractions = gmx::roundToInt(nb);
}
if (nsig > 0)
/* 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<int>(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);
if (sum[2*i] > fmax2)
{
fmax2 = sum[2*i];
- a_max = static_cast<int>(sum[2*i+1] + 0.5);
+ a_max = gmx::roundToInt(sum[2*i+1]);
}
}
sfree(sum);
}
else
{
- i = static_cast<int>((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;
bUlogV = -i/invbinw + bU_logV_bin_limit - refvolshift + log(V_all/frame);
fprintf(fp_tpi, "%6.2f %10d %12.5e\n",
bUlogV,
- static_cast<int>(bin[i]+0.5),
+ roundToInt(bin[i]),
bin[i]*exp(-bUlogV)*V_all/VembU_all);
}
xvgrclose(fp_tpi);
/* 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 */
* slab with index 0) is */
dist = iprod(rotvec, curr_x);
- return round(dist / slabdist);
+ return gmx::roundToInt(dist / slabdist);
}
static int gmx_dnint(double x)
{
- return static_cast<int>(x+0.5);
+ return gmx::roundToInt(x);
}
typedef struct gmx_stats {
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<long long int>(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);
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<int>(rtab*td[0].tabscale + 0.5);
+ table->n = gmx::roundToInt(rtab*td[0].tabscale);
}
table->scale = td[0].tabscale;
nx0 = td[0].nx0;
#include <array>
#include <vector>
+#include "gromacs/math/functions.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/timing/cyclecounter.h"
#include "gromacs/timing/gpu_timing.h"
cr->mpi_comm_mysim);
for (i = 0; i < ewcNR; i++)
{
- wcc[i].n = static_cast<int>(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<int>(buf[ewcNR+i] + 0.5);
+ wc->wcsc[i].n = gmx::roundToInt(buf[ewcNR+i]);
}
}
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<int>(100*cyc_sum[ewcNS]/tot+0.5));
+ gmx::roundToInt(100*cyc_sum[ewcNS]/tot));
}
else
{
"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<int>(100*cyc_sum[ewcDOMDEC]/tot+0.5),
- static_cast<int>(100*cyc_sum[ewcNS]/tot+0.5));
+ gmx::roundToInt(100*cyc_sum[ewcDOMDEC]/tot),
+ gmx::roundToInt(100*cyc_sum[ewcNS]/tot));
}
}
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<int>(100*cyc_sum[ewcMoveE]/tot+0.5));
+ gmx::roundToInt(100*cyc_sum[ewcMoveE]/tot));
}
}
/* Determine total number of steps remaining */
if (bExtend)
{
- ir->nsteps = ir->nsteps - (run_step - ir->init_step) + static_cast<int64_t>(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));
}
gmx_step_str(ir->nsteps, buf),
gmx_step_str(run_step, buf2),
run_t, until_t);
- ir->nsteps = static_cast<int64_t>((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));
}
domdecOptions.rankOrder = static_cast<DdRankOrder>(nenum(ddrank_opt_choices));
domdecOptions.dlbOption = static_cast<DlbOption>(nenum(dddlb_opt_choices));
- domdecOptions.numCells[XX] = static_cast<int>(realddxyz[XX] + 0.5);
- domdecOptions.numCells[YY] = static_cast<int>(realddxyz[YY] + 0.5);
- domdecOptions.numCells[ZZ] = static_cast<int>(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];