From 033fbf068ba9c57526ec48da8bda54db077146d1 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Tue, 27 May 2014 15:14:53 +0200 Subject: [PATCH] Converted md.c to C++ Removed unused variables, added missing headers, added missing extern "C" specifiers. Removed assignments of unused values. Made the code always call init_nlistheuristics(), in order to suppress a clang-static-analyzer check that thinks (for example) MULTISIM(cr) can change its value over MD loops. Calling that init function is cheap, outside the MD loop, has no effect because those code paths are always protected by a check for nstlist == -1, and probably those code paths will go away shortly. Change-Id: I8abb8ef28c121c7b5432bf38d958c0b2a55ed9da --- src/gromacs/fileio/mdoutf.h | 7 +++++++ src/gromacs/fileio/trajectory_writing.h | 8 ++++++++ src/programs/mdrun/{md.c => md.cpp} | 17 +++++------------ src/programs/mdrun/pme_loadbal.h | 10 +++++++++- src/programs/mdrun/repl_ex.h | 8 ++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) rename src/programs/mdrun/{md.c => md.cpp} (99%) diff --git a/src/gromacs/fileio/mdoutf.h b/src/gromacs/fileio/mdoutf.h index 3372db38d9..645ecab6f0 100644 --- a/src/gromacs/fileio/mdoutf.h +++ b/src/gromacs/fileio/mdoutf.h @@ -47,6 +47,10 @@ #include "filenm.h" #include "enxio.h" +#ifdef __cplusplus +extern "C" { +#endif + struct gmx_mtop_t; typedef struct gmx_mdoutf *gmx_mdoutf_t; @@ -98,5 +102,8 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, #define MDOF_CPT (1<<4) #define MDOF_IMD (1<<5) +#ifdef __cplusplus +} +#endif #endif /* GMX_FILEIO_MDOUTF_H */ diff --git a/src/gromacs/fileio/trajectory_writing.h b/src/gromacs/fileio/trajectory_writing.h index 07cb6f4afe..a5250d2afd 100644 --- a/src/gromacs/fileio/trajectory_writing.h +++ b/src/gromacs/fileio/trajectory_writing.h @@ -47,6 +47,10 @@ #include "filenm.h" #include "mdoutf.h" +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief Wrapper routine for writing trajectories during mdrun * * This routine does communication (e.g. collecting distributed coordinates) @@ -79,4 +83,8 @@ do_md_trajectory_writing(FILE *fplog, ); +#ifdef __cplusplus +} +#endif + #endif /* GMX_FILEIO_TRAJECTORY_WRITING_H */ diff --git a/src/programs/mdrun/md.c b/src/programs/mdrun/md.cpp similarity index 99% rename from src/programs/mdrun/md.c rename to src/programs/mdrun/md.cpp index bad0af3ab3..e320584225 100644 --- a/src/programs/mdrun/md.c +++ b/src/programs/mdrun/md.cpp @@ -82,6 +82,7 @@ #include "nbnxn_cuda_data_mgmt.h" #include "gromacs/fileio/confio.h" +#include "gromacs/fileio/mdoutf.h" #include "gromacs/fileio/trajectory_writing.h" #include "gromacs/fileio/trnio.h" #include "gromacs/fileio/trxio.h" @@ -170,7 +171,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], rvec mu_tot; t_vcm *vcm; t_state *bufstate = NULL; - matrix *scale_tot, pcoupl_mu, M, ebox; + matrix pcoupl_mu, M; gmx_nlheur_t nlh; t_trxframe rerun_fr; gmx_repl_ex_t repl_ex = NULL; @@ -189,10 +190,8 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], gmx_ekindata_t *ekind, *ekind_save; gmx_shellfc_t shellfc; int count, nconverged = 0; - real timestep = 0; - double tcount = 0; - gmx_bool bConverged = TRUE, bOK, bSumEkinhOld, bExchanged, bNeedRepartition; - gmx_bool bAppend; + double tcount = 0; + gmx_bool bConverged = TRUE, bOK, bSumEkinhOld, bExchanged, bNeedRepartition; gmx_bool bResetCountersHalfMaxH = FALSE; gmx_bool bVV, bIterativeCase, bFirstIterate, bTemp, bPres, bTrotter; gmx_bool bUpdateDoLR; @@ -207,7 +206,6 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], double cycles; real saved_conserved_quantity = 0; real last_ekin = 0; - int iter_i; t_extmass MassQ; int **trotter_seq; char sbuf[STEPSTRSIZE], sbuf2[STEPSTRSIZE]; @@ -231,7 +229,6 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], /* Check for special mdrun options */ bRerunMD = (Flags & MD_RERUN); - bAppend = (Flags & MD_APPENDFILES); if (Flags & MD_RESETCOUNTERSHALFWAY) { if (ir->nsteps > 0) @@ -728,7 +725,6 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], bStateFromTPX = !bStateFromCP; bInitStep = bFirstStep && (bStateFromTPX || bVV); bStartingFromCpt = (Flags & MD_STARTFROMCPT) && bInitStep; - bLastStep = FALSE; bSumEkinhOld = FALSE; bExchanged = FALSE; bNeedRepartition = FALSE; @@ -738,10 +734,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], step = ir->init_step; step_rel = 0; - if (ir->nstlist == -1) - { - init_nlistheuristics(&nlh, bGStatEveryStep, step); - } + init_nlistheuristics(&nlh, bGStatEveryStep, step); if (MULTISIM(cr) && (repl_ex_nst <= 0 )) { diff --git a/src/programs/mdrun/pme_loadbal.h b/src/programs/mdrun/pme_loadbal.h index f2b9f0152b..eddb4d67eb 100644 --- a/src/programs/mdrun/pme_loadbal.h +++ b/src/programs/mdrun/pme_loadbal.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014, 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. @@ -36,6 +36,10 @@ #ifndef _pme_loadbal_h #define _pme_loadbal_h +#ifdef __cplusplus +extern "C" { +#endif + typedef struct pme_load_balancing *pme_load_balancing_t; /* Initialze the PP-PME load balacing data and infrastructure */ @@ -76,4 +80,8 @@ void pme_loadbal_done(pme_load_balancing_t pme_lb, t_commrec *cr, FILE *fplog, gmx_bool bNonBondedOnGPU); +#ifdef __cplusplus +} +#endif + #endif /* _pme_loadbal_h */ diff --git a/src/programs/mdrun/repl_ex.h b/src/programs/mdrun/repl_ex.h index ec6c6ee23c..b04f549ccc 100644 --- a/src/programs/mdrun/repl_ex.h +++ b/src/programs/mdrun/repl_ex.h @@ -41,6 +41,10 @@ #include "typedefs.h" #include "types/commrec.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Abstract type for replica exchange */ typedef struct gmx_repl_ex *gmx_repl_ex_t; @@ -68,4 +72,8 @@ extern gmx_bool replica_exchange(FILE *fplog, extern void print_replica_exchange_statistics(FILE *fplog, gmx_repl_ex_t re); /* Should only be called on the master nodes */ +#ifdef __cplusplus +} +#endif + #endif /* _repl_ex_h */ -- 2.22.0