When writing TNG include file closing in wallcycle.
authorMagnus Lundborg <lundborg.magnus@gmail.com>
Tue, 15 Jul 2014 13:54:49 +0000 (15:54 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 1 Sep 2014 19:07:39 +0000 (21:07 +0200)
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
src/gromacs/fileio/mdoutf.h
src/gromacs/fileio/trajectory_writing.c
src/gromacs/fileio/trajectory_writing.h
src/gromacs/legacyheaders/sim_util.h
src/gromacs/mdlib/minimize.c
src/gromacs/mdlib/sim_util.c
src/programs/mdrun/md.c

index 2c19cdfe36deb1be69b26f71a6c6871c8679c682..1118cc06531bdd388470fd99a25449cb92f9614e 100644 (file)
@@ -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);
 
index 783d3da63ab2fd4018ada8abe3e809b173113939..a063c1fd8f0d5a4c87a901d97e89876d58b753f4 100644 (file)
@@ -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);
 
index 699b482022db3bec73c038e07ff2bb36f5948d6b..0d90e8ea5325ffbe41231c2baa538e13425bb9a2 100644 (file)
@@ -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);
     }
 }
index 65e8e067ea158162379079872ea76d24852bd7bc..632794677773f3044a9bde371c68fa5b9977be9d 100644 (file)
@@ -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,
index 546038479ee7ceabeca77faf17104f156641d0b7..e5eb4685886dbf111cabe9e77311d85fdb7c9ad0 100644 (file)
@@ -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
index ab48e44b42c6ad7274b2108f77e1a2b36dfcc733..3cc1bbc8a08c6a9d65f6d324369dc49cc6addcd3 100644 (file)
@@ -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);
index a904a2ef52dce09ee00aa647a482c56cb1ebbd51..0c2b89605bfe99f022e755efd260b86b2437e0ae 100644 (file)
@@ -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));
index 2b320246b588bfd34c87f02885847096fa53499f..dc01b6de0cbd0a69b693000144bf3ada388142f2 100644 (file)
@@ -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);