#include "gromacs/legacyheaders/gmx_fatal.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/timing/wallcycle.h"
struct gmx_mdoutf {
t_fileio *fp_trn;
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];
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))
{
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,
}
}
+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)
{
gmx_fio_fclose(of->fp_field);
}
+
gmx_tng_close(&of->tng);
gmx_tng_close(&of->tng_low_prec);
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);
/*! \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);
gmx_ekindata_t *ekind,
rvec *f,
rvec *f_global,
- gmx_wallcycle_t wcycle,
int *nchkpt,
gmx_bool bCPT,
gmx_bool bRerunMD,
if (mdof_flags != 0)
{
- wallcycle_start(wcycle, ewcTRAJ);
+ wallcycle_start(mdoutf_get_wcycle(outf), ewcTRAJ);
if (bCPT)
{
if (MASTER(cr))
ir->ePBC, state->box);
debug_gmx();
}
- wallcycle_stop(wcycle, ewcTRAJ);
+ wallcycle_stop(mdoutf_get_wcycle(outf), ewcTRAJ);
}
}
gmx_ekindata_t *ekind,
rvec *f,
rvec *f_global,
- gmx_wallcycle_t wcycle,
int *nchkpt,
gmx_bool bCPT,
gmx_bool bRerunMD,
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
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;
*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,
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);
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.
*/
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);
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);
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;
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));
&(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);
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. */
/* 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);