Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / fileio / mdoutf.c
index da67416fb8cff3fb84018827b35db4612fac55ec..4532b7d65b1ee1b9a9290fc8efece4a83328c680 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/timing/wallcycle.h"
 
 struct gmx_mdoutf {
     t_fileio         *fp_trn;
@@ -70,13 +71,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];
@@ -98,6 +100,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))
     {
@@ -234,6 +237,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,
@@ -375,6 +383,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)
@@ -397,6 +416,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);