void do_md_trajectory_writing(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], gmx_int64_t step, gmx_int64_t step_rel, double t, t_inputrec *ir, t_state *state, t_state *state_global, gmx_mtop_t *top_global, t_forcerec *fr, gmx_mdoutf_t outf, t_mdebin *mdebin, gmx_ekindata_t *ekind, rvec *f, rvec *f_global, int *nchkpt, gmx_bool bCPT, gmx_bool bRerunMD, gmx_bool bLastStep, gmx_bool bDoConfOut, gmx_bool bSumEkinhOld ) { int mdof_flags; mdof_flags = 0; if (do_per_step(step, ir->nstxout)) { mdof_flags |= MDOF_X; } if (do_per_step(step, ir->nstvout)) { mdof_flags |= MDOF_V; } if (do_per_step(step, ir->nstfout)) { mdof_flags |= MDOF_F; } if (do_per_step(step, ir->nstxout_compressed)) { mdof_flags |= MDOF_X_COMPRESSED; } if (bCPT) { mdof_flags |= MDOF_CPT; } ; #if defined(GMX_FAHCORE) || defined(GMX_WRITELASTSTEP) if (bLastStep) { /* Enforce writing positions and velocities at end of run */ mdof_flags |= (MDOF_X | MDOF_V); } #endif #ifdef GMX_FAHCORE if (MASTER(cr)) { fcReportProgress( ir->nsteps, step ); } #if defined(__native_client__) fcCheckin(MASTER(cr)); #endif /* sync bCPT and fc record-keeping */ if (bCPT && MASTER(cr)) { fcRequestCheckPoint(); } #endif if (mdof_flags != 0) { wallcycle_start(mdoutf_get_wcycle(outf), ewcTRAJ); if (bCPT) { if (MASTER(cr)) { if (bSumEkinhOld) { state_global->ekinstate.bUpToDate = FALSE; } else { update_ekinstate(&state_global->ekinstate, ekind); state_global->ekinstate.bUpToDate = TRUE; } update_energyhistory(&state_global->enerhist, mdebin); } } mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, top_global, step, t, state, state_global, f, f_global); if (bCPT) { (*nchkpt)++; } debug_gmx(); if (bLastStep && step_rel == ir->nsteps && bDoConfOut && MASTER(cr) && !bRerunMD) { /* x and v have been collected in mdoutf_write_to_trajectory_files, * because a checkpoint file will always be written * at the last step. */ fprintf(stderr, "\nWriting final coordinates.\n"); if (fr->bMolPBC) { /* Make molecules whole only for confout writing */ do_pbc_mtop(fplog, ir->ePBC, state->box, top_global, state_global->x); } write_sto_conf_mtop(ftp2fn(efSTO, nfile, fnm), *top_global->name, top_global, state_global->x, state_global->v, ir->ePBC, state->box); debug_gmx(); } wallcycle_stop(mdoutf_get_wcycle(outf), ewcTRAJ); } }
void do_md_trajectory_writing(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[], gmx_int64_t step, gmx_int64_t step_rel, double t, t_inputrec *ir, t_state *state, t_state *state_global, gmx_mtop_t *top_global, t_forcerec *fr, gmx_mdoutf_t outf, t_mdebin *mdebin, gmx_ekindata_t *ekind, rvec *f, rvec *f_global, int *nchkpt, gmx_bool bCPT, gmx_bool bRerunMD, gmx_bool bLastStep, gmx_bool bDoConfOut, gmx_bool bSumEkinhOld ) { int mdof_flags; rvec *x_for_confout = NULL; mdof_flags = 0; if (do_per_step(step, ir->nstxout)) { mdof_flags |= MDOF_X; } if (do_per_step(step, ir->nstvout)) { mdof_flags |= MDOF_V; } if (do_per_step(step, ir->nstfout)) { mdof_flags |= MDOF_F; } if (do_per_step(step, ir->nstxout_compressed)) { mdof_flags |= MDOF_X_COMPRESSED; } if (bCPT) { mdof_flags |= MDOF_CPT; } ; #if defined(GMX_FAHCORE) if (bLastStep) { /* Enforce writing positions and velocities at end of run */ mdof_flags |= (MDOF_X | MDOF_V); } if (MASTER(cr)) { fcReportProgress( ir->nsteps, step ); } #if defined(__native_client__) fcCheckin(MASTER(cr)); #endif /* sync bCPT and fc record-keeping */ if (bCPT && MASTER(cr)) { fcRequestCheckPoint(); } #endif if (mdof_flags != 0) { wallcycle_start(mdoutf_get_wcycle(outf), ewcTRAJ); if (bCPT) { if (MASTER(cr)) { if (bSumEkinhOld) { state_global->ekinstate.bUpToDate = FALSE; } else { update_ekinstate(&state_global->ekinstate, ekind); state_global->ekinstate.bUpToDate = TRUE; } update_energyhistory(state_global->enerhist, mdebin); } } mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, top_global, step, t, state, state_global, f, f_global); if (bCPT) { (*nchkpt)++; } debug_gmx(); if (bLastStep && step_rel == ir->nsteps && bDoConfOut && MASTER(cr) && !bRerunMD) { if (fr->bMolPBC && state->x == state_global->x) { /* This (single-rank) run needs to allocate a temporary array of size natoms so that any periodicity removal for mdrun -confout does not perturb the update and thus the final .edr output. This makes .cpt restarts look binary identical, and makes .edr restarts binary identical. */ snew(x_for_confout, state_global->natoms); copy_rvecn(state_global->x, x_for_confout, 0, state_global->natoms); } else { /* With DD, or no bMolPBC, it doesn't matter if we change state_global->x */ x_for_confout = state_global->x; } /* x and v have been collected in mdoutf_write_to_trajectory_files, * because a checkpoint file will always be written * at the last step. */ fprintf(stderr, "\nWriting final coordinates.\n"); if (fr->bMolPBC) { /* Make molecules whole only for confout writing */ do_pbc_mtop(fplog, ir->ePBC, state->box, top_global, x_for_confout); } write_sto_conf_mtop(ftp2fn(efSTO, nfile, fnm), *top_global->name, top_global, x_for_confout, state_global->v, ir->ePBC, state->box); if (fr->bMolPBC && state->x == state_global->x) { sfree(x_for_confout); } debug_gmx(); } wallcycle_stop(mdoutf_get_wcycle(outf), ewcTRAJ); } }