3/3 of old-style casting
authorRoland Schulz <roland.schulz@intel.com>
Fri, 6 Jul 2018 02:05:20 +0000 (19:05 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Sun, 12 Aug 2018 18:04:15 +0000 (11:04 -0700)
Also remove GMX_CXX11_COMPILATION and gmx_qsort

Change-Id: I3cfec7dfdb47da89d3849ff7e9cc15f0550194a9

44 files changed:
src/gromacs/CMakeLists.txt
src/gromacs/correlationfunctions/gmx_lmcurve.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec_constraints.cpp
src/gromacs/ewald/pme.cpp
src/gromacs/fft/fft5d.cpp
src/gromacs/fileio/gmxfio.cpp
src/gromacs/fileio/matio.cpp
src/gromacs/fileio/md5.cpp
src/gromacs/fileio/readinp.cpp
src/gromacs/fileio/tngio.cpp
src/gromacs/gmxana/gmx_anaeig.cpp
src/gromacs/gmxana/gmx_bar.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/gmxana/gmx_energy.cpp
src/gromacs/gmxana/gmx_hbond.cpp
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/resall.cpp
src/gromacs/gmxpreprocess/toppush.cpp
src/gromacs/math/gmxcomplex.h
src/gromacs/mdlib/constr.cpp
src/gromacs/mdlib/constr.h
src/gromacs/mdlib/lincs.cpp
src/gromacs/mdlib/nbnxn_atomdata.cpp
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_inner.h
src/gromacs/mdlib/ns.cpp
src/gromacs/mdlib/qmmm.cpp
src/gromacs/options/timeunitmanager.cpp
src/gromacs/pulling/pull.cpp
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/selection/compiler.cpp
src/gromacs/selection/indexutil.cpp
src/gromacs/selection/params.cpp
src/gromacs/timing/cyclecounter.h
src/gromacs/utility/allocator.h
src/gromacs/utility/basedefinitions.h
src/gromacs/utility/binaryinformation.cpp
src/gromacs/utility/bitmask.h
src/gromacs/utility/pleasecite.cpp
src/gromacs/utility/qsort_threadsafe.cpp [deleted file]
src/gromacs/utility/qsort_threadsafe.h [deleted file]
src/gromacs/utility/smalloc.h

index b1fba8987bf35620a8248dbc892b4b2d4067bd56..9022e5c4b67ad5646b77f9ddc41d469c0d3b73c3 100644 (file)
@@ -279,7 +279,6 @@ set(IGNORED_CLANG_ALL_WARNINGS
 
     #Following ones are undecided/TODO
     "-Wno-disabled-macro-expansion"
-    "-Wno-cast-align"
     "-Wno-reserved-id-macro"
     "-Wno-global-constructors"
     "-Wno-exit-time-destructors"
@@ -293,7 +292,6 @@ set(IGNORED_CLANG_ALL_WARNINGS
     "-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}")
@@ -346,6 +344,7 @@ if (GMX_CLANG_TIDY)
        "-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"
index c8fe2b6b306144c5c82477ea646f559c46f0a61e..256eb5918c3285e041895c229c8c4586e5829473 100644 (file)
@@ -73,9 +73,8 @@ static void lmcurve_evaluate(
         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)
@@ -96,7 +95,7 @@ static void gmx_lmcurve(
 {
     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);
 }
 
index 8226424f0670edceb95d65c59870777655e6b927..d72ccd4e9dee890ee15aee8dc629241375f232cc 100644 (file)
 #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"
@@ -5803,21 +5802,14 @@ static void set_zones_size(gmx_domdec_t *dd,
     }
 }
 
-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
@@ -5908,7 +5900,7 @@ static void orderedSort(gmx::ArrayRef<const gmx_cgsort_t>  stationary,
                         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());
@@ -6000,7 +5992,7 @@ static void dd_sort_order(const gmx_domdec_t *dd,
             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);
index 08cf72fabcbcf64582d58796a132bfbb262a794b..89d289ecbfa27d324569661401b20c50f9ecfd8e 100644 (file)
@@ -232,7 +232,7 @@ static void walk_out(int con, int con_offset, int a, int offset, int nrec,
 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)
@@ -431,7 +431,7 @@ int dd_make_local_constraints(gmx_domdec_t *dd, int at_start,
     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;
index 3d3f9220d43359e208cd055e87b2aefbef1b7d3b..5ca669b0bbd9e62b36e5fddc49e9ba0e2ac42126 100644 (file)
@@ -1226,7 +1226,7 @@ int gmx_pme_do(struct gmx_pme_t *pme,
         {
             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!");
index 12c1e010f800de5bdcac40c154cf98fb1849079c..fa725120ba3c7a75dc5775a5b45017dc3b2e7a4f 100644 (file)
@@ -944,7 +944,7 @@ static void print_localdata(const t_complex* lin, const char* txt, int s, fft5d_
             {
                 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, ",");
             }
@@ -1399,18 +1399,18 @@ void fft5d_compare_data(const t_complex* lin, const t_complex* in, fft5d_plan pl
                 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)
                     {
index 993fe341ddb82c44f767006f03dd732dd0658239..190a521c2abcdec6c3cb82d565b8cc9ff04e30a8 100644 (file)
@@ -119,7 +119,7 @@ static void gmx_fio_make_dummy(void)
 {
     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;
@@ -301,7 +301,7 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode)
         strcat(newmode, "b");
     }
 
-    snew(fio, 1);
+    fio = new t_fileio {};
     tMPI_Lock_init(&(fio->mtx));
     bRead      = (newmode[0] == 'r' && newmode[1] != '+');
     bReadWrite = (newmode[1] == '+');
@@ -386,7 +386,7 @@ int gmx_fio_close(t_fileio *fio)
     gmx_fio_unlock(fio);
 
     sfree(fio->fn);
-    sfree(fio);
+    delete fio;
 
     return rc;
 }
@@ -434,7 +434,7 @@ int gmx_fio_fclose(FILE *fp)
             gmx_fio_remove(cur);
             gmx_fio_stop_getting_next(cur);
             sfree(cur->fn);
-            sfree(cur);
+            delete cur;
             break;
         }
         cur = gmx_fio_get_next(cur);
index a9190bc3591ab5a68b8a85afe6563a5ac2c94ff9..1e824a4a5dc1311ce6972b2e894c819ccd922a53 100644 (file)
@@ -57,7 +57,7 @@
 #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
 
index ab63444073a2835f7ebb06177152d21fd926bf37..8d985d6f1e4779fe3dd66ed7eb88aa26dbb33ff7 100644 (file)
 #  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
index 9d911c9b78ecc94ea50ed6e06776dc4861da4f06..bc3d674192fc29700e2ec811b12a454e1b701d72 100644 (file)
@@ -51,7 +51,6 @@
 #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"
index 1df209b6398b5e823939360e8cdf067c2f35773c..d9d67fa0a5f23a1f4fa3d6f01254cd9743123224 100644 (file)
@@ -681,7 +681,7 @@ static void add_selection_groups(gmx_tng_trajectory_t  gmx_tng,
                 }
                 else
                 {
-                    res_name = (char *)"";
+                    res_name = const_cast<char*>("");
                     res_id   = 0;
                 }
                 if (tng_chain_residue_find(tng, chain, res_name, res_id, &res)
index ad7e2e104849176041a52e04764e1151728cade1..7f12ca971afc7f42b40d672c052afb656d6868d5 100644 (file)
@@ -465,7 +465,8 @@ static void project(const char *trajfile, const t_topology *top, int ePBC, matri
     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;
 
@@ -607,7 +608,7 @@ static void project(const char *trajfile, const t_topology *top, int ePBC, matri
         }
         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);
     }
@@ -821,9 +822,10 @@ static void components(const char *outfile, int natoms,
                        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);
 
@@ -855,7 +857,7 @@ static void components(const char *outfile, int natoms,
     }
     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");
 }
@@ -866,9 +868,10 @@ static void rmsf(const char *outfile, int natoms, const real *sqrtm,
                  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++)
     {
@@ -903,7 +906,7 @@ static void rmsf(const char *outfile, int natoms, const real *sqrtm,
         }
     }
     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");
 }
index f7e1db88ea871e7aeee090429c3abfa11b80caf9..08416daea293170b16c84d69e48e234f805908be 100644 (file)
@@ -1041,7 +1041,7 @@ static void sim_data_histogram(sim_data_t *sd, const char *filename,
 
         bl = bl->next;
     }
-    xvgr_legend(fp, nsets, (const char**)setnames, oenv);
+    xvgr_legend(fp, nsets, setnames, oenv);
 
 
     /* now make the histograms */
index 131fb59fa379622753778f4d000f5e13104f651f..93c2a5d235c61128ce469fc5fc6f8a3a7438d054 100644 (file)
@@ -693,7 +693,7 @@ static void histogramming(FILE *log, int nbin, gmx_residuetype_t *rt,
         {
             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++)
         {
@@ -1032,7 +1032,7 @@ static void print_transitions(const char *fn, int maxchi, int nlist,
     /* 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]);
index e12dd7e566db7e065384c68f450db8c05a4f754f..7000f0ad9eab331c3691bf6a7403344957b79d10 100644 (file)
@@ -210,7 +210,7 @@ static void check_viol(FILE *log,
 
         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;
@@ -262,27 +262,6 @@ typedef struct {
     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" };
@@ -418,7 +397,8 @@ static void dump_stats(FILE *log, int nsteps, int ndr, t_ilist *disres,
     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);
@@ -794,7 +774,7 @@ int gmx_disre(int argc, char *argv[])
             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
     {
index ecbfcb78bdfa6352dd8ddbd46a073c795539f153..6dc4c6ea4fe1825c3fc75bc0c0c3c2019f00e326 100644 (file)
@@ -1831,11 +1831,11 @@ int gmx_energy(int argc, char *argv[])
         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);
index 346d6c55a9d6b380abd49a4fea4dc17f0a96d045..41a9f2df777169b8729427883aa3b24f063bbe6a 100644 (file)
@@ -3216,7 +3216,7 @@ int gmx_hbond(int argc, char *argv[])
     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);
@@ -3420,7 +3420,7 @@ int gmx_hbond(int argc, char *argv[])
         {
             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]);
index 6ca704eb3a63426b6e8ced607a7d9cc93969f93f..01606649bcdfb5068b2f934eccb73792ab148a8c 100644 (file)
@@ -1548,26 +1548,6 @@ static void print_histograms(const char *fnhist, t_UmbrellaWindow * window, int
     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)
 {
@@ -1582,7 +1562,7 @@ static void setRandomBsWeights(t_UmbrellaWindow *synthwin, int nAllPull, t_Umbre
     {
         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];
index 49add7cf883ad6be3cd3c44d3a87e06751238a35..036e47f19afc200fc8eb9f8ac85b0d79f7cd9802 100644 (file)
@@ -43,6 +43,8 @@
 #include <string.h>
 #include <time.h>
 
+#include <algorithm>
+
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/gmxfio.h"
@@ -678,29 +680,22 @@ typedef struct {
     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[],
@@ -759,7 +754,7 @@ 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);
index 510525dcfa41a5111553e7455d06d6c429c90100..b2bc373a742781fa5fddfc35c17b160e2940996e 100644 (file)
@@ -276,7 +276,7 @@ static int get_bt(char* header)
 
 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 */
index 8783264b18a509f574bfdf36e5d84b712a72a53a..5f81a3d7e47947f3e91a216936ccf7f843c58420 100644 (file)
@@ -2492,11 +2492,6 @@ void b2_to_b(t_block2 *b2, t_blocka *b)
     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;
@@ -2525,7 +2520,7 @@ void merge_excl(t_blocka *excl, t_block2 *b2, warninp_t wi)
         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++)
             {
index 67c798558e087808845101c88bc43e910f148879..3faa4b960bdd45329b99e36be8e9759deac02c79 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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.
@@ -62,8 +62,8 @@ static inline t_complex rcexp(real r)
 {
     t_complex c;
 
-    c.re = (real)cos(r);
-    c.im = (real)sin(r);
+    c.re = cos(r);
+    c.im = sin(r);
 
     return c;
 }
index fd90a6ce82f4aa1459af9fd25c4313c4d9e50720..34977fd4f1d0c8c7dfc3bc11c4303d8e0f973244 100644 (file)
@@ -1113,9 +1113,9 @@ Constraints::atom2constraints_moltype() const
     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;
 }
 
 
index d7a8b4a7431c91217f1b9027fe0a11653c51e5ad..6579ba96744f22dafba6334dccf7972592749a17 100644 (file)
@@ -178,7 +178,7 @@ class Constraints
         //! 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
index 557b3b972575fb830d105d2a3946bdc3987300b8..681cf142b404d29e6d2f63d224d2c3fd4368d961 100644 (file)
@@ -1481,12 +1481,6 @@ static bool more_than_two_sequential_constraints(const t_ilist  *ilist,
     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)
@@ -1967,8 +1961,7 @@ static void set_matrix_indices(Lincs                *li,
         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]]));
         }
     }
 }
index 42fa2ba3ddf41256b8e3a7bdcac8eb54e523e964..a79e1cb6d514b63b919e52c8676d6c2aa094199d 100644 (file)
@@ -767,7 +767,7 @@ void nbnxn_atomdata_init(const gmx::MDLogger &mdlog,
     {
         GMX_LOG(mdlog.info).asParagraph().appendText("Using tree force reduction");
 
-        snew(nbat->syncStep, nth);
+        nbat->syncStep = new tMPI_Atomic[nth];
     }
 }
 
@@ -1369,7 +1369,7 @@ static void nbnxn_atomdata_add_nbat_f_to_f_treereduce(const nbnxn_atomdata_t *nb
                     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();
                         }
index 62f5cc96a8f5c4e531c832c961a69754d83d721e..34088450bf430a249539df4bc9edb543067d8478 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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) */
index 46b51fd3570b984482ea62a554fcdd8efe2be289..a1b31a82eda641ef6bdc9df48bfcb4e1f92703e0 100644 (file)
@@ -89,9 +89,9 @@ static gmx_bool NOTEXCL_(t_excl e[], int i, int j)
     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
 
index e6c97ebbec78a6feed8558e582f07abd3c6b75ab..e192cd4ac978a86d3ed7c3f15a8bf92cc2420562 100644 (file)
@@ -121,12 +121,10 @@ typedef struct {
     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[])
@@ -691,15 +689,11 @@ void update_QMMMrec(const t_commrec  *cr,
 
 
 
-            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
index 49b2c7023e993ee3d67ab5e6c110cd816c16c686..e03245e742af9f3e59a5ebce565c87ea00ad385b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -108,7 +108,7 @@ const char *TimeUnitManager::timeUnitAsString() const
 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_];
 }
index 9ab7626302c651c81cca2a6ee65cc7e6b7a96520..ece8811a636ad443b3e7368246da2b8d2994728a 100644 (file)
@@ -411,7 +411,7 @@ static FILE *open_pull_out(const char *fn, struct pull_t *pull,
         }
         if (nsets > 1)
         {
-            xvgr_legend(fp, nsets, (const char**)setname, oenv);
+            xvgr_legend(fp, nsets, setname, oenv);
         }
         for (int c = 0; c < nsets; c++)
         {
index c0d009cc1a2f749b10e69f6315fa9f81dbb27eeb..1e7b3f4838556d62d4e986873806f5e576eee00b 100644 (file)
@@ -75,7 +75,6 @@
 #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:"};
@@ -1704,7 +1703,7 @@ 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)
+#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 */
@@ -2360,26 +2359,6 @@ static real do_flex_lowlevel(
     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 */
@@ -2395,7 +2374,11 @@ static void sort_collective_coordinates(
         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++)
index 25e4bff11fdb381ab186daad1d4cc284cb8948c4..1e9875240c9ee098005c18c143dc15d7f5b48567 100644 (file)
@@ -377,15 +377,15 @@ print_group_info(FILE *fp, const char *name,
     }
     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));
     }
 }
 
index c3f6600d665eaf140214e1bd79cec3fc8bf5d48a..726408045b0715ffaeb5376fe2ffb88d9ea03373 100644 (file)
@@ -478,28 +478,13 @@ gmx_ana_index_check_range(gmx_ana_index_t *g, int natoms)
  * 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
index d33485f90e01579ff78979e48711c9fd4a28c82b..6e68ac8421b6f2e44a9d5bb8ca0552378fece5e0 100644 (file)
@@ -42,6 +42,7 @@
 #include "gmxpre.h"
 
 #include <algorithm>
+#include <array>
 #include <string>
 
 #include "gromacs/math/units.h"
@@ -238,59 +239,19 @@ place_child(const SelectionTreeElementPointer &root,
 }
 
 /*! \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
@@ -374,7 +335,8 @@ parse_values_range(const SelectionParserValueList &values,
     /* 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])
@@ -394,7 +356,8 @@ parse_values_range(const SelectionParserValueList &values,
     }
     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])
index 53652df835fc0a8990ed03e05c81de319229bede..2c78e68e10f0040192cb58b9e265e54b7efbf66e 100644 (file)
 #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 */
@@ -210,7 +202,6 @@ static __inline__ gmx_cycles_t gmx_cycles_read(void)
 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
@@ -218,10 +209,9 @@ static __inline__ gmx_cycles_t gmx_cycles_read(void)
 #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)
@@ -592,8 +582,4 @@ static bool gmx_cycles_have_counter(void)
 double
 gmx_cycles_calibrate(double sampletime);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index c8905068dfd6e204bbfde3442f33239f2372e720..5afb4bbf92edac78bca5949e43aa13e051403327 100644 (file)
@@ -215,7 +215,7 @@ class Allocator : public AllocationPolicy
          */
         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
          *
index f02b2d1ed59a4fa55498bd9645fec54b1f8e7350..51faac8e9fa3fffd5d820c2b51bf1448b85c31d5 100644 (file)
@@ -89,28 +89,6 @@ using index = std::ptrdiff_t;
  */
 #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.
index 27be14f4b8340e0ad7afca4243e706ee9ae73ad2..6609567cd93f867d6efd5b9bbfba49b34be0ae6f 100644 (file)
@@ -154,14 +154,14 @@ void printCopyright(gmx::TextWriter *writer)
         "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
index d5eb82894fcf1f538acb6db53209a510d1529414..40b897bff3521adf2a502cc47aa0d361e0d47ad5 100644 (file)
@@ -75,25 +75,25 @@ inline static void bitmask_clear(gmx_bitmask_t* m)
 /*! \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 */
index 2aad0cf457c4edc062b56d9db9d8a1755ba5ede8..f3664822f9a00f698efccbb13369d7d3955c5b7f 100644 (file)
@@ -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.
@@ -382,7 +382,7 @@ void please_cite(FILE *fp, const char *key)
           "J. Chem. Phys.",
           141, 2014, "044110" },
     };
-#define NSTR (int)asize(citedb)
+#define NSTR static_cast<int>(asize(citedb))
 
     int   index;
     char *author;
@@ -394,7 +394,7 @@ void please_cite(FILE *fp, const char *key)
         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++)
     {
         ;
     }
diff --git a/src/gromacs/utility/qsort_threadsafe.cpp b/src/gromacs/utility/qsort_threadsafe.cpp
deleted file mode 100644 (file)
index 5339b1b..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * 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
-
-}
diff --git a/src/gromacs/utility/qsort_threadsafe.h b/src/gromacs/utility/qsort_threadsafe.h
deleted file mode 100644 (file)
index b2bd1f7..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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
index 8ef0e02ca2cad53c12ff34a79c8d969a6c196794..906da1c66c9220f818a12629b15a6687f73cf0ac 100644 (file)
@@ -178,9 +178,7 @@ void *save_calloc_aligned(const char *name, const char *file, int line,
  */
 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
@@ -209,59 +207,47 @@ template <typename T> static inline
 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);
 }
 /*! \} */