From 867084344e764d2a9959895615f0bfa77b751e72 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Tue, 15 Jul 2014 15:54:49 +0200 Subject: [PATCH] When writing TNG include file closing in wallcycle. If there is an unwritten frame set when closing a TNG file it will be written to disk. This includes compressing the data (when writing compressed output), which can take a significant amount of time if the system is large. This should be included in the wallcycle count to make it more fair. Change-Id: Ida43fe73b8bc1b0c1326e286a4bff647410da45f --- src/gromacs/fileio/mdoutf.c | 22 +++++++++++++++++++++- src/gromacs/fileio/mdoutf.h | 13 ++++++++++++- src/gromacs/fileio/trajectory_writing.c | 5 ++--- src/gromacs/fileio/trajectory_writing.h | 1 - src/gromacs/legacyheaders/sim_util.h | 3 ++- src/gromacs/mdlib/minimize.c | 13 +++++++------ src/gromacs/mdlib/sim_util.c | 5 +++-- src/programs/mdrun/md.c | 8 ++++++-- 8 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/gromacs/fileio/mdoutf.c b/src/gromacs/fileio/mdoutf.c index 2c19cdfe36..1118cc0653 100644 --- a/src/gromacs/fileio/mdoutf.c +++ b/src/gromacs/fileio/mdoutf.c @@ -48,6 +48,7 @@ #include "gromacs/legacyheaders/gmx_fatal.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/timing/wallcycle.h" struct gmx_mdoutf { t_fileio *fp_trn; @@ -67,13 +68,14 @@ struct gmx_mdoutf { int natoms_global; int natoms_x_compressed; gmx_groups_t *groups; /* for compressed position writing */ + gmx_wallcycle_t wcycle; }; gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[], int mdrun_flags, const t_commrec *cr, const t_inputrec *ir, gmx_mtop_t *top_global, - const output_env_t oenv) + const output_env_t oenv, gmx_wallcycle_t wcycle) { gmx_mdoutf_t of; char filemode[3]; @@ -95,6 +97,7 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[], of->elamstats = ir->expandedvals->elamstats; of->simulation_part = ir->simulation_part; of->x_compression_precision = ir->x_compression_precision; + of->wcycle = wcycle; if (MASTER(cr)) { @@ -231,6 +234,11 @@ FILE *mdoutf_get_fp_dhdl(gmx_mdoutf_t of) return of->fp_dhdl; } +gmx_wallcycle_t mdoutf_get_wcycle(gmx_mdoutf_t of) +{ + return of->wcycle; +} + void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, gmx_mdoutf_t of, int mdof_flags, @@ -372,6 +380,17 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, } } +void mdoutf_tng_close(gmx_mdoutf_t of) +{ + if (of->tng || of->tng_low_prec) + { + wallcycle_start(of->wcycle, ewcTRAJ); + gmx_tng_close(&of->tng); + gmx_tng_close(&of->tng_low_prec); + wallcycle_stop(of->wcycle, ewcTRAJ); + } +} + void done_mdoutf(gmx_mdoutf_t of) { if (of->fp_ene != NULL) @@ -394,6 +413,7 @@ void done_mdoutf(gmx_mdoutf_t of) { gmx_fio_fclose(of->fp_field); } + gmx_tng_close(&of->tng); gmx_tng_close(&of->tng_low_prec); diff --git a/src/gromacs/fileio/mdoutf.h b/src/gromacs/fileio/mdoutf.h index 783d3da63a..a063c1fd8f 100644 --- a/src/gromacs/fileio/mdoutf.h +++ b/src/gromacs/fileio/mdoutf.h @@ -59,7 +59,8 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, const t_commrec *cr, const t_inputrec *ir, gmx_mtop_t *mtop, - const output_env_t oenv); + const output_env_t oenv, + gmx_wallcycle_t wcycle); /*! \brief Getter for file pointer */ FILE *mdoutf_get_fp_field(gmx_mdoutf_t of); @@ -70,6 +71,16 @@ ener_file_t mdoutf_get_fp_ene(gmx_mdoutf_t of); /*! \brief Getter for file pointer */ FILE *mdoutf_get_fp_dhdl(gmx_mdoutf_t of); +/*! \brief Getter for wallcycle timer */ +gmx_wallcycle_t mdoutf_get_wcycle(gmx_mdoutf_t of); + +/*! \brief Close TNG files if they are open. + * + * This also measures the time it takes to close the TNG + * files. + */ +void mdoutf_tng_close(gmx_mdoutf_t of); + /*! \brief Close all open output files and free the of pointer */ void done_mdoutf(gmx_mdoutf_t of); diff --git a/src/gromacs/fileio/trajectory_writing.c b/src/gromacs/fileio/trajectory_writing.c index 699b482022..0d90e8ea53 100644 --- a/src/gromacs/fileio/trajectory_writing.c +++ b/src/gromacs/fileio/trajectory_writing.c @@ -66,7 +66,6 @@ do_md_trajectory_writing(FILE *fplog, gmx_ekindata_t *ekind, rvec *f, rvec *f_global, - gmx_wallcycle_t wcycle, int *nchkpt, gmx_bool bCPT, gmx_bool bRerunMD, @@ -126,7 +125,7 @@ do_md_trajectory_writing(FILE *fplog, if (mdof_flags != 0) { - wallcycle_start(wcycle, ewcTRAJ); + wallcycle_start(mdoutf_get_wcycle(outf), ewcTRAJ); if (bCPT) { if (MASTER(cr)) @@ -171,6 +170,6 @@ do_md_trajectory_writing(FILE *fplog, ir->ePBC, state->box); debug_gmx(); } - wallcycle_stop(wcycle, ewcTRAJ); + wallcycle_stop(mdoutf_get_wcycle(outf), ewcTRAJ); } } diff --git a/src/gromacs/fileio/trajectory_writing.h b/src/gromacs/fileio/trajectory_writing.h index 65e8e067ea..6327946777 100644 --- a/src/gromacs/fileio/trajectory_writing.h +++ b/src/gromacs/fileio/trajectory_writing.h @@ -66,7 +66,6 @@ do_md_trajectory_writing(FILE *fplog, gmx_ekindata_t *ekind, rvec *f, rvec *f_global, - gmx_wallcycle_t wcycle, int *nchkpt, gmx_bool bCPT, gmx_bool bRerunMD, diff --git a/src/gromacs/legacyheaders/sim_util.h b/src/gromacs/legacyheaders/sim_util.h index 546038479e..e5eb468588 100644 --- a/src/gromacs/legacyheaders/sim_util.h +++ b/src/gromacs/legacyheaders/sim_util.h @@ -133,7 +133,8 @@ void init_md(FILE *fplog, gmx_mdoutf_t *outf, t_mdebin **mdebin, tensor force_vir, tensor shake_vir, rvec mu_tot, - gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags); + gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags, + gmx_wallcycle_t wcycle); /* Routine in sim_util.c */ #ifdef __cplusplus diff --git a/src/gromacs/mdlib/minimize.c b/src/gromacs/mdlib/minimize.c index ab48e44b42..3cc1bbc8a0 100644 --- a/src/gromacs/mdlib/minimize.c +++ b/src/gromacs/mdlib/minimize.c @@ -310,7 +310,8 @@ void init_em(FILE *fplog, const char *title, gmx_vsite_t *vsite, gmx_constr_t constr, int nfile, const t_filenm fnm[], gmx_mdoutf_t *outf, t_mdebin **mdebin, - int imdport, unsigned long gmx_unused Flags) + int imdport, unsigned long gmx_unused Flags, + gmx_wallcycle_t wcycle) { int i; real dvdl_constr; @@ -427,7 +428,7 @@ void init_em(FILE *fplog, const char *title, *gstat = global_stat_init(ir); } - *outf = init_mdoutf(fplog, nfile, fnm, 0, cr, ir, top_global, NULL); + *outf = init_mdoutf(fplog, nfile, fnm, 0, cr, ir, top_global, NULL, wcycle); snew(*enerd, 1); init_enerdata(top_global->groups.grps[egcENER].nr, ir->fepvals->n_lambda, @@ -1000,7 +1001,7 @@ double do_cg(FILE *fplog, t_commrec *cr, init_em(fplog, CG, cr, inputrec, state_global, top_global, s_min, &top, &f, &f_global, nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr, - nfile, fnm, &outf, &mdebin, imdport, Flags); + nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle); /* Print to log file */ print_em_start(fplog, cr, walltime_accounting, wcycle, CG); @@ -1672,7 +1673,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, init_em(fplog, LBFGS, cr, inputrec, state, top_global, &ems, &top, &f, &f_global, nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr, - nfile, fnm, &outf, &mdebin, imdport, Flags); + nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle); /* Do_lbfgs is not completely updated like do_steep and do_cg, * so we free some memory again. */ @@ -2417,7 +2418,7 @@ double do_steep(FILE *fplog, t_commrec *cr, init_em(fplog, SD, cr, inputrec, state_global, top_global, s_try, &top, &f, &f_global, nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr, - nfile, fnm, &outf, &mdebin, imdport, Flags); + nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle); /* Print to log file */ print_em_start(fplog, cr, walltime_accounting, wcycle, SD); @@ -2669,7 +2670,7 @@ double do_nm(FILE *fplog, t_commrec *cr, state_global, top_global, state_work, &top, &f, &f_global, nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, vsite, constr, - nfile, fnm, &outf, NULL, imdport, Flags); + nfile, fnm, &outf, NULL, imdport, Flags, wcycle); natoms = top_global->natoms; snew(fneg, natoms); diff --git a/src/gromacs/mdlib/sim_util.c b/src/gromacs/mdlib/sim_util.c index a904a2ef52..0c2b89605b 100644 --- a/src/gromacs/mdlib/sim_util.c +++ b/src/gromacs/mdlib/sim_util.c @@ -2830,7 +2830,8 @@ void init_md(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mdoutf_t *outf, t_mdebin **mdebin, tensor force_vir, tensor shake_vir, rvec mu_tot, - gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags) + gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags, + gmx_wallcycle_t wcycle) { int i, j, n; real tmpt, mod; @@ -2886,7 +2887,7 @@ void init_md(FILE *fplog, if (nfile != -1) { - *outf = init_mdoutf(fplog, nfile, fnm, Flags, cr, ir, mtop, oenv); + *outf = init_mdoutf(fplog, nfile, fnm, Flags, cr, ir, mtop, oenv, wcycle); *mdebin = init_mdebin((Flags & MD_APPENDFILES) ? NULL : mdoutf_get_fp_ene(*outf), mtop, ir, mdoutf_get_fp_dhdl(*outf)); diff --git a/src/programs/mdrun/md.c b/src/programs/mdrun/md.c index 2b320246b5..dc01b6de0c 100644 --- a/src/programs/mdrun/md.c +++ b/src/programs/mdrun/md.c @@ -298,7 +298,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], &(state_global->fep_state), lam0, nrnb, top_global, &upd, nfile, fnm, &outf, &mdebin, - force_vir, shake_vir, mu_tot, &bSimAnn, &vcm, Flags); + force_vir, shake_vir, mu_tot, &bSimAnn, &vcm, Flags, wcycle); clear_mat(total_vir); clear_mat(pres); @@ -1327,7 +1327,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], do_md_trajectory_writing(fplog, cr, nfile, fnm, step, step_rel, t, ir, state, state_global, top_global, fr, outf, mdebin, ekind, f, f_global, - wcycle, &nchkpt, + &nchkpt, bCPT, bRerunMD, bLastStep, (Flags & MD_CONFOUT), bSumEkinhOld); /* Check if IMD step and do IMD communication, if bIMD is TRUE. */ @@ -1969,6 +1969,10 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], /* End of main MD loop */ debug_gmx(); + /* Closing TNG files can include compressing data. Therefore it is good to do that + * before stopping the time measurements. */ + mdoutf_tng_close(outf); + /* Stop measuring walltime */ walltime_accounting_end(walltime_accounting); -- 2.22.0