#Following ones are undecided/TODO
"-Wno-disabled-macro-expansion"
- "-Wno-cast-align"
"-Wno-reserved-id-macro"
"-Wno-global-constructors"
"-Wno-exit-time-destructors"
"-Wno-used-but-marked-unused"
"-Wno-padded"
"-Wno-float-equal"
- "-Wno-old-style-cast"
"-Wno-conversion"
"-Wno-double-promotion")
string(REPLACE " " ";" IGNORED_CLANG_ALL_WARNINGS "${IGNORED_CLANG_ALL_WARNINGS}")
"-readability-implicit-bool-conversion" #TODO: Remove gmx_bool
"modernize-use-nullptr" "modernize-use-emplace"
"modernize-make-unique" "modernize-make-shared"
+ "google-readability-casting"
"cppcoreguidelines-*" "-cppcoreguidelines-pro-*"
"-cppcoreguidelines-owning-memory"
"-cppcoreguidelines-no-malloc"
const double* par, const int m_dat, const void* data, double* fvec,
int* info)
{
- lmcurve_data_struct* D = (lmcurve_data_struct*)data;
- int i;
- for (i = 0; i < m_dat; i++)
+ const lmcurve_data_struct* D = reinterpret_cast<const lmcurve_data_struct*>(data);
+ for (int i = 0; i < m_dat; i++)
{
double dy = D->dy[i];
if (dy == 0)
{
lmcurve_data_struct data = { t, y, dy, f };
- lmmin(n_par, par, m_dat, nullptr, (const void*)&data, lmcurve_evaluate,
+ lmmin(n_par, par, m_dat, nullptr, &data, lmcurve_evaluate,
control, status);
}
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxmpi.h"
-#include "gromacs/utility/qsort_threadsafe.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/strconvert.h"
}
}
-static int comp_cgsort(const void *a, const void *b)
+static bool comp_cgsort(const gmx_cgsort_t &a, const gmx_cgsort_t &b)
{
- int comp;
- gmx_cgsort_t *cga, *cgb;
- cga = (gmx_cgsort_t *)a;
- cgb = (gmx_cgsort_t *)b;
-
- comp = cga->nsc - cgb->nsc;
- if (comp == 0)
+ if (a.nsc == b.nsc)
{
- comp = cga->ind_gl - cgb->ind_gl;
+ return a.ind_gl < b.ind_gl;
}
-
- return comp;
+ return a.nsc < b.nsc;
}
/* Order data in \p dataToSort according to \p sort
std::vector<gmx_cgsort_t> *sort1)
{
/* The new indices are not very ordered, so we qsort them */
- gmx_qsort_threadsafe(moved.data(), moved.size(), sizeof(moved[0]), comp_cgsort);
+ std::sort(moved.begin(), moved.end(), comp_cgsort);
/* stationary is already ordered, so now we can merge the two arrays */
sort1->resize(stationary.size() + moved.size());
fprintf(debug, "qsort cgs: %d new home %d\n", dd->ncg_home, numCGNew);
}
/* Determine the order of the charge groups using qsort */
- gmx_qsort_threadsafe(cgsort.data(), dd->ncg_home, sizeof(cgsort[0]), comp_cgsort);
+ std::sort(cgsort.begin(), cgsort.end(), comp_cgsort);
/* Remove the charge groups which are no longer at home here */
cgsort.resize(numCGNew);
static void atoms_to_settles(gmx_domdec_t *dd,
const gmx_mtop_t *mtop,
const int *cginfo,
- const int **at2settle_mt,
+ const int *const*at2settle_mt,
int cg_start, int cg_end,
t_ilist *ils_local,
std::vector<int> *ireq)
t_ilist *ilc_local, *ils_local;
std::vector<int> *ireq;
gmx::ArrayRef<const t_blocka> at2con_mt;
- const int **at2settle_mt;
+ const int *const*at2settle_mt;
gmx_hash_t *ga2la_specat;
int at_end, i, j;
t_iatom *iap;
{
fprintf(debug, "PME: number of ranks = %d, rank = %d\n",
cr->nnodes, cr->nodeid);
- fprintf(debug, "Grid = %p\n", (void*)grid);
+ fprintf(debug, "Grid = %p\n", static_cast<void*>(grid));
if (grid == nullptr)
{
gmx_fatal(FARGS, "No grid!");
{
for (l = 0; l < ll; l++)
{
- fprintf(debug, "%f ", ((real*)lin)[(z*xs[2]+y*xs[1])*2+(x*xs[0])*ll+l]);
+ fprintf(debug, "%f ", reinterpret_cast<const real*>(lin)[(z*xs[2]+y*xs[1])*2+(x*xs[0])*ll+l]);
}
fprintf(debug, ",");
}
for (l = 0; l < ll; l++) /*loop over real/complex parts*/
{
real a, b;
- a = ((real*)lin)[(z*xs[2]+y*xs[1])*2+x*xs[0]*ll+l];
+ a = reinterpret_cast<const real*>(lin)[(z*xs[2]+y*xs[1])*2+x*xs[0]*ll+l];
if (normalize)
{
a /= plan->rC[0]*plan->rC[1]*plan->rC[2];
}
if (!bothLocal)
{
- b = ((real*)in)[((z+xc[2])*NG[0]*NG[1]+(y+xc[1])*NG[0])*2+(x+xc[0])*ll+l];
+ b = reinterpret_cast<const real*>(in)[((z+xc[2])*NG[0]*NG[1]+(y+xc[1])*NG[0])*2+(x+xc[0])*ll+l];
}
else
{
- b = ((real*)in)[(z*xs[2]+y*xs[1])*2+x*xs[0]*ll+l];
+ b = reinterpret_cast<const real*>(in)[(z*xs[2]+y*xs[1])*2+x*xs[0]*ll+l];
}
if (plan->flags&FFT5D_DEBUG)
{
{
if (!open_files)
{
- snew(open_files, 1);
+ open_files = new t_fileio {};
open_files->fp = nullptr;
open_files->fn = nullptr;
open_files->next = open_files;
strcat(newmode, "b");
}
- snew(fio, 1);
+ fio = new t_fileio {};
tMPI_Lock_init(&(fio->mtx));
bRead = (newmode[0] == 'r' && newmode[1] != '+');
bReadWrite = (newmode[1] == '+');
gmx_fio_unlock(fio);
sfree(fio->fn);
- sfree(fio);
+ delete fio;
return rc;
}
gmx_fio_remove(cur);
gmx_fio_stop_getting_next(cur);
sfree(cur->fn);
- sfree(cur);
+ delete cur;
break;
}
cur = gmx_fio_get_next(cur);
#include "gromacs/utility/smalloc.h"
static const char mapper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+{}|;:',<.>/?";
-#define NMAP (long int)strlen(mapper)
+#define NMAP static_cast<long int>(strlen(mapper))
#define MAX_XPM_LINELENGTH 4096
# define BYTE_ORDER 0
#endif
-#define T_MASK ((md5_word_t) ~0)
+#define T_MASK (static_cast<md5_word_t>(~0))
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
#define T3 0x242070db
#include "gromacs/utility/keyvaluetreebuilder.h"
#include "gromacs/utility/niceheader.h"
#include "gromacs/utility/programcontext.h"
-#include "gromacs/utility/qsort_threadsafe.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
#include "gromacs/utility/textreader.h"
}
else
{
- res_name = (char *)"";
+ res_name = const_cast<char*>("");
res_id = 0;
}
if (tng_chain_residue_find(tng, chain, res_name, res_id, &res)
matrix box;
rvec *xread, *x;
real t, inp, **inprod = nullptr;
- char str[STRLEN], str2[STRLEN], **ylabel, *c;
+ char str[STRLEN], str2[STRLEN], *c;
+ const char **ylabel;
real fact;
gmx_rmpbc_t gpbc = nullptr;
}
sprintf(str, "projection on eigenvectors (%s)", proj_unit);
write_xvgr_graphs(projfile, noutvec, 1, str, nullptr, output_env_get_xvgr_tlabel(oenv),
- (const char **)ylabel,
+ ylabel,
nframes, inprod[noutvec], inprod, nullptr,
output_env_get_time_factor(oenv), FALSE, bSplit, oenv);
}
int noutvec, const int *outvec,
const gmx_output_env_t *oenv)
{
- int g, s, v, i;
- real *x, ***y;
- char str[STRLEN], **ylabel;
+ int g, s, v, i;
+ real *x, ***y;
+ char str[STRLEN];
+ const char**ylabel;
fprintf(stderr, "Writing eigenvector components to %s\n", outfile);
}
write_xvgr_graphs(outfile, noutvec, 4, "Eigenvector components",
"black: total, red: x, green: y, blue: z",
- "Atom number", (const char **)ylabel,
+ "Atom number", ylabel,
natoms, x, nullptr, y, 1, FALSE, FALSE, oenv);
fprintf(stderr, "\n");
}
real *eigval, int neig,
const gmx_output_env_t *oenv)
{
- int g, v, i;
- real *x, **y;
- char str[STRLEN], **ylabel;
+ int g, v, i;
+ real *x, **y;
+ char str[STRLEN];
+ const char **ylabel;
for (i = 0; i < neig; i++)
{
}
}
write_xvgr_graphs(outfile, noutvec, 1, "RMS fluctuation (nm) ", nullptr,
- "Atom number", (const char **)ylabel,
+ "Atom number", ylabel,
natoms, x, y, nullptr, 1, TRUE, FALSE, oenv);
fprintf(stderr, "\n");
}
bl = bl->next;
}
- xvgr_legend(fp, nsets, (const char**)setnames, oenv);
+ xvgr_legend(fp, nsets, setnames, oenv);
/* now make the histograms */
{
leg[i+NKKKPHI+NKKKPSI] = gmx_strdup(kkkchi1[i].name);
}
- xvgr_legend(fp, NJC, (const char**)leg, oenv);
+ xvgr_legend(fp, NJC, leg, oenv);
fprintf(fp, "%5s ", "#Res.");
for (i = 0; (i < NJC); i++)
{
/* Print order parameters */
fp = xvgropen(fn, "Dihedral Rotamer Transitions", "Residue", "Transitions/ns",
oenv);
- xvgr_legend(fp, NONCHI+maxchi, (const char**)leg, oenv);
+ xvgr_legend(fp, NONCHI+maxchi, leg, oenv);
fprintf(fp, "%5s ", "#Res.");
fprintf(fp, "%10s %10s %10s ", leg[edPhi], leg[edPsi], leg[edOmega]);
snew(fshift, SHIFTS);
interaction_function[F_DISRES].ifunc(n, &forceatoms[i], forceparams,
- (const rvec*)x, f, fshift,
+ x, f, fshift,
pbc, g, lam, &dvdl, nullptr, fcd, nullptr);
sfree(fshift);
viol = fcd->disres.sumviol;
real up1, r, rT3, rT6, viol, violT3, violT6;
} t_dr_stats;
-static int drs_comp(const void *a, const void *b)
-{
- t_dr_stats *da, *db;
-
- da = (t_dr_stats *)a;
- db = (t_dr_stats *)b;
-
- if (da->viol > db->viol)
- {
- return -1;
- }
- else if (da->viol < db->viol)
- {
- return 1;
- }
- else
- {
- return 0;
- }
-}
-
static void dump_dump(FILE *log, int ndr, t_dr_stats drs[])
{
static const char *core[] = { "All restraints", "Core restraints" };
dump_viol(log, ndr, drs, FALSE);
fprintf(log, "+++ Sorted by linear averaged violations: +++\n");
- qsort(drs, ndr, sizeof(drs[0]), drs_comp);
+ std::sort(drs, drs+ndr, [](const t_dr_stats &a, const t_dr_stats &b)
+ {return a.viol > b.viol; }); //Reverse sort
dump_viol(log, ndr, drs, TRUE);
dump_dump(log, ndr, drs);
snew(leg[i], 12);
sprintf(leg[i], "index %d", index[i]);
}
- xvgr_legend(xvg, isize, (const char**)leg, oenv);
+ xvgr_legend(xvg, isize, leg, oenv);
}
else
{
if (bSum)
{
leg[nset] = gmx_strdup("Sum");
- xvgr_legend(out, nset+1, (const char**)leg, oenv);
+ xvgr_legend(out, nset+1, leg, oenv);
}
else
{
- xvgr_legend(out, nset, (const char**)leg, oenv);
+ xvgr_legend(out, nset, leg, oenv);
}
snew(bIsEner, nset);
snew(leg[1], STRLEN);
sprintf(leg[0], "%s", bContact ? "Contacts" : "Hydrogen bonds");
sprintf(leg[1], "Pairs within %g nm", (r2cut > 0) ? r2cut : rcut);
- xvgr_legend(fp, 2, (const char**)leg, oenv);
+ xvgr_legend(fp, 2, leg, oenv);
sfree(leg[1]);
sfree(leg[0]);
sfree(leg);
{
gmx_incons("number of legend entries");
}
- xvgr_legend(fp, nleg, (const char**)legnames, oenv);
+ xvgr_legend(fp, nleg, legnames, oenv);
for (i = 0; i < nframes; i++)
{
fprintf(fp, "%10g", hb->time[i]);
sfree(fn);
}
-//! Used for qsort to sort random numbers
-static int func_wham_is_larger(const void *a, const void *b)
-{
- double *aa, *bb;
- aa = (double*)a;
- bb = (double*)b;
- if (*aa < *bb)
- {
- return -1;
- }
- else if (*aa > *bb)
- {
- return 1;
- }
- else
- {
- return 0;
- }
-}
-
//! Make random weights for histograms for the Bayesian bootstrap of complete histograms)
static void setRandomBsWeights(t_UmbrellaWindow *synthwin, int nAllPull, t_UmbrellaOptions *opt)
{
{
r[i] = dist(opt->rng);
}
- qsort((void *)r, nAllPull-1, sizeof(double), &func_wham_is_larger);
+ std::sort(r, r+nAllPull-1);
r[nAllPull-1] = 1.0*nAllPull;
synthwin[0].bsWeight[0] = r[0];
#include <string.h>
#include <time.h>
+#include <algorithm>
+
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/gmxfio.h"
char altloc; /* alternate location indicator */
} t_pdbindex;
-static int pdbicomp(const void *a, const void *b)
+static bool pdbicomp(const t_pdbindex &a, const t_pdbindex &b)
{
- t_pdbindex *pa, *pb;
- int d;
-
- pa = (t_pdbindex *)a;
- pb = (t_pdbindex *)b;
-
- d = (pa->resnr - pb->resnr);
+ int d = (a.resnr - b.resnr);
if (d == 0)
{
- d = (pa->j - pb->j);
+ d = (a.j - b.j);
if (d == 0)
{
- d = (pa->anm1 - pb->anm1);
+ d = (a.anm1 - b.anm1);
if (d == 0)
{
- d = (pa->altloc - pb->altloc);
+ d = (a.altloc - b.altloc);
}
}
}
-
- return d;
+ return d < 0;
}
static void sort_pdbatoms(t_restp restp[],
pdbi[i].anm1 = atomnm[1];
pdbi[i].altloc = pdba->pdbinfo[i].altloc;
}
- qsort(pdbi, natoms, static_cast<size_t>(sizeof(pdbi[0])), pdbicomp);
+ std::sort(pdbi, pdbi+natoms, pdbicomp);
/* pdba is sorted in pdbnew using the pdbi index */
snew(a, natoms);
static void clear_t_restp(t_restp *rrtp)
{
- memset((void *)rrtp, 0, sizeof(t_restp));
+ memset(rrtp, 0, sizeof(t_restp));
}
/* print all the ebtsNR type numbers */
b->index[i] = nra;
}
-static int icomp(const void *v1, const void *v2)
-{
- return (*((int *) v1))-(*((int *) v2));
-}
-
void merge_excl(t_blocka *excl, t_block2 *b2, warninp_t wi)
{
int i, k;
if (b2->nra[i] > 0)
{
/* remove double entries */
- qsort(b2->a[i], static_cast<size_t>(b2->nra[i]), static_cast<size_t>(sizeof(b2->a[i][0])), icomp);
+ std::sort(b2->a[i], b2->a[i]+b2->nra[i]);
k = 1;
for (j = 1; (j < b2->nra[i]); j++)
{
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,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.
{
t_complex c;
- c.re = (real)cos(r);
- c.im = (real)sin(r);
+ c.re = cos(r);
+ c.im = sin(r);
return c;
}
return impl_->at2con_mt;
}
-const int **Constraints::atom2settle_moltype() const
+int *const* Constraints::atom2settle_moltype() const
{
- return (const int **)impl_->at2settle_mt;
+ return impl_->at2settle_mt;
}
//! Getter for use by domain decomposition.
const ArrayRef<const t_blocka> atom2constraints_moltype() const;
//! Getter for use by domain decomposition.
- const int **atom2settle_moltype() const;
+ int *const* atom2settle_moltype() const;
/*! \brief Return the data for reduction for determining
* constraint RMS relative deviations, or an empty ArrayRef
return bMoreThanTwoSequentialConstraints;
}
-//! Sorting helper function to compare two integers.
-static int int_comp(const void *a, const void *b)
-{
- return (*(int *)a) - (*(int *)b);
-}
-
Lincs *init_lincs(FILE *fplog, const gmx_mtop_t &mtop,
int nflexcon_global, ArrayRef<const t_blocka> at2con,
bool bPLINCS, int nIter, int nProjOrder)
if (bSortMatrix)
{
/* Order the blbnb matrix to optimize memory access */
- qsort(&(li->blbnb[li->blnr[b]]), li->blnr[b + 1] - li->blnr[b],
- sizeof(li->blbnb[0]), int_comp);
+ std::sort(&(li->blbnb[li->blnr[b]]), &(li->blbnb[li->blnr[b+1]]));
}
}
}
{
GMX_LOG(mdlog.info).asParagraph().appendText("Using tree force reduction");
- snew(nbat->syncStep, nth);
+ nbat->syncStep = new tMPI_Atomic[nth];
}
}
if (sync_th < nth) /* otherwise nothing to sync index[1] will be >=nout */
{
/* wait on the thread which computed input data in previous step */
- while (tMPI_Atomic_get((volatile tMPI_Atomic_t*)&(nbat->syncStep[sync_th])) < group_size/2)
+ while (tMPI_Atomic_get(static_cast<volatile tMPI_Atomic_t*>(&(nbat->syncStep[sync_th]))) < group_size/2)
{
gmx_pause();
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,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.
#ifdef CALC_COUL_TAB
rs = rsq*rinv*ic->tabq_scale;
- ri = (int)rs;
+ ri = int(rs);
frac = rs - ri;
#if !GMX_DOUBLE
/* fexcl = F_i + frac * (F_(i+1)-F_i) */
return !(ISEXCL(e, i, j));
}
#else
-#define SETEXCL(e, i, j) (e)[((int) (j))] |= (1<<((int) (i)))
-#define RMEXCL(e, i, j) (e)[((int) (j))] &= (~(1<<((int) (i))))
-#define ISEXCL(e, i, j) (gmx_bool) ((e)[((int) (j))] & (1<<((int) (i))))
+#define SETEXCL(e, i, j) (e)[int(j)] |= (1<<(int(i)))
+#define RMEXCL(e, i, j) (e)[int(j)] &= (~(1<<(int(i))))
+#define ISEXCL(e, i, j) static_cast<gmx_bool>((e)[(int(j))] & (1<<(int(i))))
#define NOTEXCL(e, i, j) !(ISEXCL(e, i, j))
#endif
int shift;
} t_j_particle;
-static int struct_comp(const void *a, const void *b)
+static bool struct_comp(const t_j_particle &a, const t_j_particle &b)
{
-
- return (((t_j_particle *)a)->j)-(((t_j_particle *)b)->j);
-
-} /* struct_comp */
+ return a.j < b.j;
+}
static real call_QMroutine(const t_commrec gmx_unused *cr, const t_forcerec gmx_unused *fr, t_QMrec gmx_unused *qm,
t_MMrec gmx_unused *mm, rvec gmx_unused f[], rvec gmx_unused fshift[])
- qsort(qm_i_particles, QMMMlist->nri,
- static_cast<size_t>(sizeof(qm_i_particles[0])),
- struct_comp);
+ std::sort(qm_i_particles, qm_i_particles+QMMMlist->nri, struct_comp);
/* The mm_j_particles argument to qsort is not allowed to be NULL */
if (mm_nr > 0)
{
- qsort(mm_j_particles, mm_nr,
- static_cast<size_t>(sizeof(mm_j_particles[0])),
- struct_comp);
+ std::sort(mm_j_particles, mm_j_particles+mm_nr, struct_comp);
}
/* remove multiples in the QM shift array, since in init_QMMM() we
* went through the atom numbers from 0 to md.nr, the order sorted
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
double TimeUnitManager::timeScaleFactor() const
{
GMX_RELEASE_ASSERT(timeUnit_ >= 0
- && (size_t)timeUnit_ < sizeof(g_timeScaleFactors)/sizeof(g_timeScaleFactors[0]),
+ && static_cast<size_t>(timeUnit_) < sizeof(g_timeScaleFactors)/sizeof(g_timeScaleFactors[0]),
"Time unit index has become out-of-range");
return g_timeScaleFactors[timeUnit_];
}
}
if (nsets > 1)
{
- xvgr_legend(fp, nsets, (const char**)setname, oenv);
+ xvgr_legend(fp, nsets, setname, oenv);
}
for (int c = 0; c < nsets; c++)
{
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/pleasecite.h"
-#include "gromacs/utility/qsort_threadsafe.h"
#include "gromacs/utility/smalloc.h"
static char const *RotStr = {"Enforced rotation:"};
/* 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)
+#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 */
return V;
}
-static int projection_compare(const void *a, const void *b)
-{
- auto xca = reinterpret_cast<const sort_along_vec_t *>(a);
- auto xcb = reinterpret_cast<const sort_along_vec_t *>(b);
-
- if (xca->xcproj < xcb->xcproj)
- {
- return -1;
- }
- else if (xca->xcproj > xcb->xcproj)
- {
- return 1;
- }
- else
- {
- return 0;
- }
-}
-
-
static void sort_collective_coordinates(
gmx_enfrotgrp *erg,
sort_along_vec_t *data) /* Buffer for sorting the positions */
copy_rvec(erg->rotg->x_ref[i], data[i].x_ref);
}
/* Sort the 'data' structure */
- gmx_qsort(data, erg->rotg->nat, sizeof(sort_along_vec_t), projection_compare);
+ std::sort(data, data+erg->rotg->nat,
+ [](const sort_along_vec_t &a, const sort_along_vec_t &b)
+ {
+ return a.xcproj < b.xcproj;
+ });
/* Copy back the sorted values */
for (int i = 0; i < erg->rotg->nat; i++)
}
else if (sel.cdata->flags & SEL_CDATA_MINMAXALLOC)
{
- fprintf(fp, "(%d atoms, %p)", g->isize, (void*)g);
+ fprintf(fp, "(%d atoms, %p)", g->isize, static_cast<void*>(g));
}
else if (sel.v.type == GROUP_VALUE && g == sel.v.u.g)
{
- fprintf(fp, "(static, %p)", (void*)g);
+ fprintf(fp, "(static, %p)", static_cast<void*>(g));
}
else
{
- fprintf(fp, "%p", (void*)g);
+ fprintf(fp, "%p", static_cast<void*>(g));
}
}
* Set operations
********************************************************************/
-/** Helper function for gmx_ana_index_sort(). */
-static int
-cmp_atomid(const void *a, const void *b)
-{
- if (*(int *)a < *(int *)b)
- {
- return -1;
- }
- if (*(int *)a > *(int *)b)
- {
- return 1;
- }
- return 0;
-}
-
/*!
* \param[in,out] g Index group to be sorted.
*/
void
gmx_ana_index_sort(gmx_ana_index_t *g)
{
- std::qsort(g->index, g->isize, sizeof(*g->index), cmp_atomid);
+ std::sort(g->index, g->index+g->isize);
}
void
#include "gmxpre.h"
#include <algorithm>
+#include <array>
#include <string>
#include "gromacs/math/units.h"
}
/*! \brief
- * Comparison function for sorting integer ranges.
+ * Comparison function for sorting ranges.
*
- * \param[in] a Pointer to the first range.
- * \param[in] b Pointer to the second range.
- * \returns -1, 0, or 1 depending on the relative order of \p a and \p b.
+ * \param[in] a First range.
+ * \param[in] b Second range.
+ * \returns return true if a < b
*
* The ranges are primarily sorted based on their starting point, and
* secondarily based on length (longer ranges come first).
*/
-static int
-cmp_int_range(const void *a, const void *b)
+template<typename T>
+static bool cmp_range(const std::array<T, 2> &a, const std::array<T, 2> &b)
{
- if (((int *)a)[0] < ((int *)b)[0])
- {
- return -1;
- }
- if (((int *)a)[0] > ((int *)b)[0])
- {
- return 1;
- }
- if (((int *)a)[1] > ((int *)b)[1])
- {
- return -1;
- }
- return 0;
-}
-
-/*! \brief
- * Comparison function for sorting real ranges.
- *
- * \param[in] a Pointer to the first range.
- * \param[in] b Pointer to the second range.
- * \returns -1, 0, or 1 depending on the relative order of \p a and \p b.
- *
- * The ranges are primarily sorted based on their starting point, and
- * secondarily based on length (longer ranges come first).
- */
-static int
-cmp_real_range(const void *a, const void *b)
-{
- if (((real *)a)[0] < ((real *)b)[0])
- {
- return -1;
- }
- if (((real *)a)[0] > ((real *)b)[0])
- {
- return 1;
- }
- if (((real *)a)[1] > ((real *)b)[1])
- {
- return -1;
- }
- return 0;
+ return a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]);
}
/*! \brief
/* Sort the ranges and merge consequent ones */
if (param->val.type == INT_VALUE)
{
- qsort(idata, n, 2*sizeof(int), &cmp_int_range);
+ const auto range_data = reinterpret_cast<std::array<int, 2>*>(idata);
+ sort(range_data, range_data+n, cmp_range<int>);
for (i = j = 2; i < 2*n; i += 2)
{
if (idata[j-1]+1 >= idata[i])
}
else
{
- qsort(rdata, n, 2*sizeof(real), &cmp_real_range);
+ const auto range_data = reinterpret_cast<std::array<real, 2>*>(rdata);
+ sort(range_data, range_data+n, cmp_range<real>);
for (i = j = 2; i < 2*n; i += 2)
{
if (rdata[j-1] >= rdata[i])
#include <intrin.h>
#endif
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#if 0
-} /* fixes auto-indentation problems */
-#endif
-
#if ((defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__PATHSCALE__) || defined(__PGIC__)) && \
(defined(__i386__) || defined(__x86_64__)))
/* x86 or x86-64 with GCC inline assembly */
static __inline__ gmx_cycles_t gmx_cycles_read(void)
{
/* x86 with GCC inline assembly - pentium TSC register */
- gmx_cycles_t cycle;
unsigned low, high;
#if HAVE_RDTSCP
#else
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
#endif
-
- cycle = ((unsigned long long)low) | (((unsigned long long)high)<<32);
-
- return cycle;
+ const gmx_cycles_t c_low = low;
+ const gmx_cycles_t c_high = high;
+ return c_low | c_high <<32;
}
#elif ((defined __aarch64__) && (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__PATHSCALE__) || defined(__PGIC__)))
static __inline__ gmx_cycles_t gmx_cycles_read(void)
double
gmx_cycles_calibrate(double sampletime);
-#ifdef __cplusplus
-}
-#endif
-
#endif
*/
template<class ... Args>
void
- construct(pointer p, Args && ... args) { ::new((void *)p)T(std::forward<Args>(args) ...); }
+ construct(pointer p, Args && ... args) { ::new(p)T(std::forward<Args>(args) ...); }
/*! \brief Call the destructor of object without releasing memory
*
*/
#define gmx_restrict __restrict
-/*! \def GMX_CXX11_COMPILATION
- * \brief
- * Defined to 1 when compiling as C++11.
- *
- * While \Gromacs only supports C++11 compilation, there are some parts of the
- * code that are compiled with other tools than the actual C++ compiler, and
- * these may not support C++11. Most notable such case is all of CUDA code
- * (with CUDA versions older than 6.5), but other types of kernels might also
- * have similar limitations in the future.
- *
- * The define is intended for conditional compilation in low-level headers that
- * need to support inclusion from such non-C++11 files, but get significant
- * benefit (e.g., for correctness checking or more convenient use) from C++11.
- * It should only be used for features that do not influence the ABI of the
- * header; e.g., static_asserts or additional helper methods.
- */
-#if defined __cplusplus && __cplusplus >= 201103L
-# define GMX_CXX11_COMPILATION 1
-#else
-# define GMX_CXX11_COMPILATION 0
-#endif
-
/*! \def gmx_unused
* \brief
* Attribute to suppress compiler warnings about unused function parameters.
"of the License, or (at your option) any later version."
};
-#define NCONTRIBUTORS (int)asize(Contributors)
-#define NCR (int)asize(CopyrightText)
+#define NCONTRIBUTORS static_cast<int>(asize(Contributors))
+#define NCR static_cast<int>(asize(CopyrightText))
// FAH has an exception permission from LGPL to allow digital signatures in Gromacs.
#ifdef GMX_FAHCORE
#define NLICENSE 0
#else
-#define NLICENSE (int)asize(LicenseText)
+#define NLICENSE static_cast<int>(asize(LicenseText))
#endif
// TODO a centering behaviour of TextWriter could be useful here
/*! \brief Set bit at position b to 1. */
inline static void bitmask_set_bit(gmx_bitmask_t* m, int b)
{
- *m |= ((gmx_bitmask_t)1 << b);
+ *m |= gmx_bitmask_t(1) << b;
}
/*! \brief Initialize all bits: bit b to 1, others to 0 */
inline static void bitmask_init_bit(gmx_bitmask_t* m, int b)
{
- *m = ((gmx_bitmask_t)1 << b);
+ *m = gmx_bitmask_t(1) << b;
}
/*! \brief Initialize all bits: all bits below b to 1, others to 0 */
inline static void bitmask_init_low_bits(gmx_bitmask_t* m, int b)
{
- *m = ((gmx_bitmask_t)1 << b) - 1;
+ *m = (gmx_bitmask_t(1) << b) - 1;
}
/*! \brief Test if bit b is set */
inline static bool bitmask_is_set(gmx_bitmask_t m, int b)
{
- return (m & ((gmx_bitmask_t)1 << b)) != 0;
+ return (m & (gmx_bitmask_t(1) << b)) != 0;
}
/*! \brief Test if both bitmasks have no common bits enabled */
*
* 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.
"J. Chem. Phys.",
141, 2014, "044110" },
};
-#define NSTR (int)asize(citedb)
+#define NSTR static_cast<int>(asize(citedb))
int index;
char *author;
return;
}
- for (index = 0; (index < NSTR) && (strcmp(citedb[index].key, key) != 0); index++)
+ for (index = 0; index < NSTR && (strcmp(citedb[index].key, key) != 0); index++)
{
;
}
+++ /dev/null
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2010,2012,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.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-#include "gmxpre.h"
-
-#include "qsort_threadsafe.h"
-
-#include <stdlib.h>
-
-static void
-qsort_swapfunc(void * a,
- void * b,
- size_t n,
- int swaptype)
-{
- int * ia;
- int * ib;
- int itmp;
-
- char * ca;
- char * cb;
- char ctmp;
-
- if (swaptype <= 1)
- {
- ia = static_cast<int *>(a);
- ib = static_cast<int *>(b);
- for (; n > 0; ia += 1, ib += 1, n -= sizeof(int))
- {
- itmp = *ia;
- *ia = *ib;
- *ib = itmp;
- }
- }
- else
- {
- ca = static_cast<char *>(a);
- cb = static_cast<char *>(b);
- for (; n > 0; ca += 1, cb += 1, n -= 1)
- {
- ctmp = *ca;
- *ca = *cb;
- *cb = ctmp;
- }
- }
-}
-
-
-static void *
-qsort_med3(void * a,
- void * b,
- void * c,
- int (*compar) (const void *a, const void *b))
-{
- if (compar(a, b) < 0)
- {
- if (compar(b, c) < 0)
- {
- return b;
- }
- else if (compar(a, c) < 0)
- {
- return c;
- }
- else
- {
- return a;
- }
- }
- else
- {
- if (compar(b, c) > 0)
- {
- return b;
- }
- else if (compar(a, c) > 0)
- {
- return c;
- }
- else
- {
- return a;
- }
- }
-}
-
-
-void
-gmx_qsort(void * base,
- size_t nmemb,
- size_t size,
- int (*compar)(const void *, const void *))
-{
-#define QSORT_EXCH(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
-#define QSORT_SWAP(a, b) swaptype != 0 ? qsort_swapfunc(a, b, size, swaptype) : \
- (void)QSORT_EXCH(*(int *)(a), *(int *)(b), t)
-
- char *pa, *pb, *pc, *pd, *pl, *pm, *pn, *pv, *cbase;
- int r, swaptype;
- int t, v;
- size_t s, st;
-
- if (size == 0)
- {
- return;
- }
-
- cbase = static_cast<char *>(base);
-
- swaptype = static_cast<size_t>(cbase - (char *)nullptr) % sizeof(int) || size % sizeof(int) ? 2 : size == sizeof(int) ? 0 : 1;
-
- if (nmemb < 7)
- {
- /* Insertion sort on smallest arrays */
- for (pm = cbase + size; pm < cbase + nmemb*size; pm += size)
- {
- for (pl = pm; (pl > cbase) && compar((void *)(pl-size), (void *) pl) > 0; pl -= size)
- {
- QSORT_SWAP(pl, pl-size);
- }
- }
- return;
- }
-
- /* Small arrays, middle element */
- pm = cbase + (nmemb/2)*size;
-
- if (nmemb > 7)
- {
- pl = cbase;
- pn = cbase + (nmemb-1)*size;
- if (nmemb > 40)
- {
- /* Big arrays, pseudomedian of 9 */
- s = (nmemb/8)*size;
- pl = static_cast<char *>(qsort_med3((void *)pl, (void *)((size_t)pl+s), (void *)((size_t)pl+2*s), compar));
- pm = static_cast<char *>(qsort_med3((void *)((size_t)pm-s), (void *)pm, (void *)((size_t)pm+s), compar));
- pn = static_cast<char *>(qsort_med3((void *)((size_t)pn-2*s), (void *)((size_t)pn-s), (void *)pn, compar));
- }
- /* Mid-size, med of 3 */
- pm = static_cast<char *>(qsort_med3((void *)pl, (void *)pm, (void *)pn, compar));
- }
-
- /* pv points to partition value */
- if (swaptype != 0)
- {
- pv = cbase;
- QSORT_SWAP(pv, pm);
- }
- else
- {
- v = *reinterpret_cast<int *>(pm);
- pv = static_cast<char*>((void*)&v);
- }
-
- pa = pb = cbase;
- pc = pd = cbase + (nmemb-1)*size;
-
- for (;; )
- {
- while (pb <= pc && (r = compar((void *)pb, (void *) pv)) <= 0)
- {
- if (r == 0)
- {
- QSORT_SWAP(pa, pb);
- pa += size;
- }
- pb += size;
- }
- while (pc >= pb && (r = compar((void *)pc, (void *) pv)) >= 0)
- {
- if (r == 0)
- {
- QSORT_SWAP(pc, pd);
- pd -= size;
- }
- pc -= size;
- }
- if (pb > pc)
- {
- break;
- }
- QSORT_SWAP(pb, pc);
- pb += size;
- pc -= size;
- }
- pn = cbase + nmemb*size;
-
- s = pa-cbase;
- st = pb-pa;
- if (st < s)
- {
- s = st;
- }
-
- if (s > 0)
- {
- qsort_swapfunc(cbase, pb-s, s, swaptype);
- }
-
- s = pd-pc;
- st = pn-pd-size;
- if (st < s)
- {
- s = st;
- }
-
- if (s > 0)
- {
- qsort_swapfunc(pb, pn-s, s, swaptype);
- }
-
- if ((s = pb-pa) > size)
- {
- gmx_qsort(cbase, s/size, size, compar);
- }
-
- if ((s = pd-pc) > size)
- {
- gmx_qsort(pn-s, s/size, size, compar);
- }
-
-#undef QSORT_EXCH
-#undef QSORT_SWAP
-
-}
+++ /dev/null
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2010,2012,2014,2016, 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.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \libinternal \file
- * \brief
- * Portable implementation of threadsafe quicksort.
- *
- * This module provides a \Gromacs version of the qsort() routine defined.
- * It is not highly optimized, but it is threadsafe, i.e. multiple threads
- * can simultaneously call gmx_qsort() with different data.
- *
- * The rational is that some implementations of qsort() are not threadsafe.
- * For instance qsort() in glibc contains a bug which makes it not threadsafe:
- * http://sources.redhat.com/bugzilla/show_bug.cgi?id=11655
- * On the other hand, system qsort() might be faster than our own.
- *
- * \inlibraryapi
- * \ingroup module_utility
- */
-#ifndef GMX_UTILITY_QSORT_THREADSAFE_H
-#define GMX_UTILITY_QSORT_THREADSAFE_H
-
-#include <stdlib.h>
-
-/* For GMX_THREAD_MPI */
-#include "config.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#if 0
-} /* fixes auto-indentation problems */
-#endif
-
-/*! \addtogroup module_utility
- * \{
- */
-
-/*! \brief
- * Portable threadsafe sort routine.
- *
- * \param base Pointer to first element in list to sort
- * \param nmemb Number of elements in list
- * \param size Size in bytes of each element
- * \param compar Comparison function that takes two pointers to elements
- * being compared as arguments. The function should return an
- * integer less than, equal to, or greater than zero if the
- * first argument is considered to be respectively less than,
- * equal to, or greater than the second.
- */
-void
-gmx_qsort(void *base,
- size_t nmemb,
- size_t size,
- int (*compar)(const void *, const void *));
-
-
-/*! \def gmx_qsort_threadsafe
- * \brief
- * Threadsafe qsort().
- *
- * Expands to gmx_qsort() if Gromacs is built with threading, or system qsort()
- * otherwise.
- */
-#if GMX_THREAD_MPI
-#define gmx_qsort_threadsafe gmx_qsort
-#else
-#define gmx_qsort_threadsafe qsort
-#endif
-
-/*! \} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
*/
void save_free_aligned(const char *name, const char *file, int line, void *ptr);
-#if GMX_CXX11_COMPILATION
#include <type_traits>
-#endif
/*! \cond internal */
/*! \name Implementation templates for C++ memory allocation macros
void gmx_snew_impl(const char *name, const char *file, int line,
T * &ptr, size_t nelem)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value, "snew() called on C++ type");
-#endif
- ptr = (T *)save_calloc(name, file, line, nelem, sizeof(T));
+ ptr = static_cast<T*>(save_calloc(name, file, line, nelem, sizeof(T)));
}
/** C++ helper for srenew(). */
template <typename T> static inline
void gmx_srenew_impl(const char *name, const char *file, int line,
T * &ptr, size_t nelem)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value, "srenew() called on C++ type");
-#endif
- ptr = (T *)save_realloc(name, file, line, ptr, nelem, sizeof(T));
+ ptr = static_cast<T*>(save_realloc(name, file, line, ptr, nelem, sizeof(T)));
}
/** C++ helper for smalloc(). */
template <typename T> static inline
void gmx_smalloc_impl(const char *name, const char *file, int line,
T * &ptr, size_t size)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value, "smalloc() called on C++ type");
-#endif
- ptr = (T *)save_malloc(name, file, line, size);
+ ptr = static_cast<T*>(save_malloc(name, file, line, size));
}
/** C++ helper for snew_aligned(). */
template <typename T> static inline
void gmx_snew_aligned_impl(const char *name, const char *file, int line,
T * &ptr, size_t nelem, size_t alignment)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value, "snew_aligned() called on C++ type");
-#endif
- ptr = (T *)save_calloc_aligned(name, file, line, nelem, sizeof(T), alignment);
+ ptr = static_cast<T*>(save_calloc_aligned(name, file, line, nelem, sizeof(T), alignment));
}
/** C++ helper for sfree(). */
template <typename T> static inline
void gmx_sfree_impl(const char *name, const char *file, int line, T *ptr)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value || std::is_void<T>::value,
"sfree() called on C++ type");
-#endif
save_free(name, file, line, ptr);
}
/** C++ helper for sfree_aligned(). */
template <typename T> static inline
void gmx_sfree_aligned_impl(const char *name, const char *file, int line, T *ptr)
{
-#if GMX_CXX11_COMPILATION
static_assert(std::is_pod<T>::value || std::is_void<T>::value,
"sfree_aligned() called on C++ type");
-#endif
save_free_aligned(name, file, line, ptr);
}
/*! \} */