From 1f61b284053fa52ce8d076fcefb2bffeafd50042 Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Thu, 16 Jul 2015 19:06:15 +0200 Subject: [PATCH] Moved timing source to C++ Change-Id: I175cf79b68330767b90e0780829f67aa9ca50af5 --- src/gromacs/timing/CMakeLists.txt | 4 +- .../{cyclecounter.c => cyclecounter.cpp} | 14 +++-- .../timing/{wallcycle.c => wallcycle.cpp} | 52 +++++++++++-------- ...e_accounting.c => walltime_accounting.cpp} | 10 ++-- 4 files changed, 44 insertions(+), 36 deletions(-) rename src/gromacs/timing/{cyclecounter.c => cyclecounter.cpp} (93%) rename src/gromacs/timing/{wallcycle.c => wallcycle.cpp} (94%) rename src/gromacs/timing/{walltime_accounting.c => walltime_accounting.cpp} (96%) diff --git a/src/gromacs/timing/CMakeLists.txt b/src/gromacs/timing/CMakeLists.txt index f0a5af0a1b..627e7e0b6c 100644 --- a/src/gromacs/timing/CMakeLists.txt +++ b/src/gromacs/timing/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2013,2014, by the GROMACS development team, led by +# Copyright (c) 2013,2014,2015, 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. @@ -32,7 +32,7 @@ # To help us fund GROMACS development, we humbly ask that you cite # the research papers on the package. Check out http://www.gromacs.org. -file(GLOB TIMING_SOURCES *.cpp *.c) +file(GLOB TIMING_SOURCES *.cpp) set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${TIMING_SOURCES} PARENT_SCOPE) gmx_install_headers( diff --git a/src/gromacs/timing/cyclecounter.c b/src/gromacs/timing/cyclecounter.cpp similarity index 93% rename from src/gromacs/timing/cyclecounter.c rename to src/gromacs/timing/cyclecounter.cpp index 780587e114..09204ae145 100644 --- a/src/gromacs/timing/cyclecounter.c +++ b/src/gromacs/timing/cyclecounter.cpp @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 1991-2006 David van der Spoel, Erik Lindahl, Berk Hess, University of Groningen. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -39,7 +39,7 @@ #include "config.h" -#include +#include #ifdef HAVE_SYS_TIME_H #include @@ -72,7 +72,7 @@ gmx_cycles_calibrate(double sampletime) QueryPerformanceFrequency(&i); - return 1.0/((double) i.QuadPart); + return 1.0/static_cast(i.QuadPart); /* end of MS Windows implementation */ #elif (defined HAVE_GETTIMEOFDAY) @@ -82,7 +82,6 @@ gmx_cycles_calibrate(double sampletime) gmx_cycles_t c1, c2; double timediff, cyclediff; double d = 0.1; /* Dummy variable so we don't optimize away delay loop */ - int i; if (!gmx_cycles_have_counter()) { @@ -116,15 +115,14 @@ gmx_cycles_calibrate(double sampletime) * that will underflow to zero in most cases. By conditionally adding it * to a result at the end it cannot be removed. n=10000 is arbitrary... */ - for (i = 0; i < 10000; i++) + for (int i = 0; i < 10000; i++) { - d = d/(1.0+(double)i); + d = d/(1.0+static_cast(i)); } /* Read the time again */ gettimeofday(&t2, NULL); c2 = gmx_cycles_read(); - timediff = (double)(t2.tv_sec-t1.tv_sec)+ - (double)(t2.tv_usec-t1.tv_usec)*1e-6; + timediff = static_cast(t2.tv_sec-t1.tv_sec)+(t2.tv_usec-t1.tv_usec)*1e-6; } while (timediff < sampletime); diff --git a/src/gromacs/timing/wallcycle.c b/src/gromacs/timing/wallcycle.cpp similarity index 94% rename from src/gromacs/timing/wallcycle.c rename to src/gromacs/timing/wallcycle.cpp index 4961ce58a3..050d6eee88 100644 --- a/src/gromacs/timing/wallcycle.c +++ b/src/gromacs/timing/wallcycle.cpp @@ -40,14 +40,14 @@ #include "config.h" -#include -#include +#include #include "gromacs/legacyheaders/md_logging.h" #include "gromacs/legacyheaders/types/commrec.h" #include "gromacs/timing/cyclecounter.h" #include "gromacs/timing/gpu_timing.h" #include "gromacs/utility/cstringutil.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/gmxmpi.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/snprintf.h" @@ -110,6 +110,7 @@ static const char *wcn[ewcNR] = "Enforced rotation", "Add rot. forces", "Coordinate swapping", "IMD", "Test" }; +#ifdef GMX_CYCLE_SUBCOUNTERS static const char *wcsn[ewcsNR] = { "DD redist.", "DD NS grid + sort", "DD setup comm.", @@ -124,6 +125,7 @@ static const char *wcsn[ewcsNR] = "NB X buffer ops.", "NB F buffer ops.", }; +#endif gmx_bool wallcycle_have_counter(void) { @@ -344,7 +346,7 @@ double wallcycle_stop(gmx_wallcycle_t wc, int ewc) void wallcycle_get(gmx_wallcycle_t wc, int ewc, int *n, double *c) { *n = wc->wcc[ewc].n; - *c = (double)wc->wcc[ewc].c; + *c = static_cast(wc->wcc[ewc].c); } void wallcycle_reset_all(gmx_wallcycle_t wc) @@ -393,7 +395,7 @@ static void subtract_cycles(wallcc_t *wcc, int ewc_main, int ewc_sub) { if (wcc[ewc_sub].n > 0) { - assert(wcc[ewc_main].c >= wcc[ewc_sub].c); + GMX_ASSERT(wcc[ewc_main].c >= wcc[ewc_sub].c, "Subcounter cannot have more ticks than parent"); wcc[ewc_main].c -= wcc[ewc_sub].c; } @@ -403,7 +405,11 @@ void wallcycle_sum(t_commrec *cr, gmx_wallcycle_t wc) { wallcc_t *wcc; double cycles[ewcNR+ewcsNR]; - double cycles_n[ewcNR+ewcsNR], buf[ewcNR+ewcsNR], *cyc_all, *buf_all; +#ifdef GMX_MPI + double cycles_n[ewcNR+ewcsNR]; + double buf[ewcNR+ewcsNR]; + double *buf_all, *cyc_all; +#endif int i, j; int nsum; @@ -466,7 +472,7 @@ void wallcycle_sum(t_commrec *cr, gmx_wallcycle_t wc) if (wcc[ewcPMEMESH].n > 0) { /* This must be a PME only node, calculate the Wait + Comm. time */ - assert(wcc[ewcRUN].c >= wcc[ewcPMEMESH].c); + GMX_ASSERT(wcc[ewcRUN].c >= wcc[ewcPMEMESH].c, "Total run ticks must be greater than PME-only ticks"); wcc[ewcPMEWAITCOMM].c = wcc[ewcRUN].c - wcc[ewcPMEMESH].c; } } @@ -474,16 +480,20 @@ void wallcycle_sum(t_commrec *cr, gmx_wallcycle_t wc) /* Store the cycles in a double buffer for summing */ for (i = 0; i < ewcNR; i++) { - cycles_n[i] = (double)wcc[i].n; - cycles[i] = (double)wcc[i].c; +#ifdef GMX_MPI + cycles_n[i] = static_cast(wcc[i].n); +#endif + cycles[i] = static_cast(wcc[i].c); } nsum = ewcNR; #ifdef GMX_CYCLE_SUBCOUNTERS for (i = 0; i < ewcsNR; i++) { wc->wcsc[i].c *= wc->nthreads_pp; - cycles_n[ewcNR+i] = (double)wc->wcsc[i].n; - cycles[ewcNR+i] = (double)wc->wcsc[i].c; +#ifdef GMX_MPI + cycles_n[ewcNR+i] = static_cast(wc->wcsc[i].n); +#endif + cycles[ewcNR+i] = static_cast(wc->wcsc[i].c); } nsum += ewcsNR; #endif @@ -495,12 +505,12 @@ void wallcycle_sum(t_commrec *cr, gmx_wallcycle_t wc) cr->mpi_comm_mysim); for (i = 0; i < ewcNR; i++) { - wcc[i].n = (int)(buf[i] + 0.5); + wcc[i].n = static_cast(buf[i] + 0.5); } #ifdef GMX_CYCLE_SUBCOUNTERS for (i = 0; i < ewcsNR; i++) { - wc->wcsc[i].n = (int)(buf[ewcNR+i] + 0.5); + wc->wcsc[i].n = static_cast(buf[ewcNR+i] + 0.5); } #endif @@ -519,7 +529,7 @@ void wallcycle_sum(t_commrec *cr, gmx_wallcycle_t wc) cr->mpi_comm_mysim); for (i = 0; i < ewcNR*ewcNR; i++) { - wc->wcc_all[i].c = buf_all[i]; + wc->wcc_all[i].c = static_cast(buf_all[i]); } sfree(buf_all); sfree(cyc_all); @@ -658,18 +668,18 @@ void wallcycle_print(FILE *fplog, int nnodes, int npme, double realtime, } nth_pp = wc->nthreads_pp; - assert(nth_pp > 0); + GMX_ASSERT(nth_pp > 0, "Number of particle-particle threads must be >0"); nth_pme = wc->nthreads_pme; - assert(nth_pme > 0); + GMX_ASSERT(nth_pme > 0, "Number of PME threads must be >0"); cyc_sum = wc->cycles_sum; - assert(nnodes > 0); - assert(npme >= 0); + GMX_ASSERT(nnodes > 0, "Number of nodes must be >0"); + GMX_ASSERT(npme >= 0, "Number of PME nodes cannot be negative"); npp = nnodes - npme; /* npme is the number of PME-only ranks used, and we always do PP work */ - assert(npp > 0); + GMX_ASSERT(npp > 0, "Number of particle-particle nodes must be >0"); nth_tot = npp*nth_pp + npme*nth_pme; @@ -694,10 +704,10 @@ void wallcycle_print(FILE *fplog, int nnodes, int npme, double realtime, /* Conversion factor from cycles to seconds */ c2t = realtime/tot; - c2t_pp = c2t * nth_tot / (double) (npp*nth_pp); + c2t_pp = c2t * nth_tot / static_cast(npp*nth_pp); if (npme > 0) { - c2t_pme = c2t * nth_tot / (double) (npme*nth_pme); + c2t_pme = c2t * nth_tot / static_cast(npme*nth_pme); } else { @@ -752,7 +762,7 @@ void wallcycle_print(FILE *fplog, int nnodes, int npme, double realtime, } } } - tot_for_rest = tot * (npp * nth_pp) / (double) nth_tot; + tot_for_rest = tot * npp * nth_pp / static_cast(nth_tot); print_cycles(fplog, c2t_pp, "Rest", npp, nth_pp, -1, tot_for_rest - tot_for_pp, tot); diff --git a/src/gromacs/timing/walltime_accounting.c b/src/gromacs/timing/walltime_accounting.cpp similarity index 96% rename from src/gromacs/timing/walltime_accounting.c rename to src/gromacs/timing/walltime_accounting.cpp index ec0cba0b1e..5eeed23c80 100644 --- a/src/gromacs/timing/walltime_accounting.c +++ b/src/gromacs/timing/walltime_accounting.cpp @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 2013, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -39,7 +39,7 @@ #include "config.h" -#include +#include #ifdef HAVE_UNISTD_H #include @@ -201,7 +201,7 @@ gmx_gettime() double seconds; clock_gettime(CLOCK_REALTIME, &t); - seconds = (double) t.tv_sec + 1e-9*(double)t.tv_nsec; + seconds = static_cast(t.tv_sec) + 1e-9*t.tv_nsec; return seconds; #elif defined HAVE_GETTIMEOFDAY @@ -211,7 +211,7 @@ gmx_gettime() double seconds; gettimeofday(&t, NULL); - seconds = (double) t.tv_sec + 1e-6*(double)t.tv_usec; + seconds = static_cast(t.tv_sec) + 1e-6*t.tv_usec; return seconds; #else @@ -231,7 +231,7 @@ gmx_gettime_per_thread() double seconds; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); - seconds = (double) t.tv_sec + 1e-9*(double)t.tv_nsec; + seconds = static_cast(t.tv_sec) + 1e-9*t.tv_nsec; return seconds; #else -- 2.22.0