Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / fileio / mdoutf.c
index eb08027c559977db439d9b355e0d58bbd33bc698..844c84602e5eec689f081782194c2f331d6e5701 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+#include "gmxpre.h"
+
 #include "mdoutf.h"
 
-#include "gromacs/legacyheaders/xvgr.h"
+#include "gromacs/fileio/tngio.h"
+#include "gromacs/fileio/trajectory_writing.h"
+#include "gromacs/fileio/trnio.h"
+#include "gromacs/fileio/xtcio.h"
+#include "gromacs/fileio/xvgr.h"
+#include "gromacs/legacyheaders/checkpoint.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/legacyheaders/domdec.h"
 #include "gromacs/legacyheaders/mdrun.h"
-#include "gromacs/legacyheaders/smalloc.h"
 #include "gromacs/legacyheaders/mvdata.h"
-#include "gromacs/legacyheaders/domdec.h"
-#include "trnio.h"
-#include "xtcio.h"
-#include "tngio.h"
-#include "trajectory_writing.h"
-#include "checkpoint.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 struct gmx_mdoutf {
     t_fileio         *fp_trn;
@@ -63,17 +70,18 @@ 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(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)
+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, gmx_wallcycle_t wcycle)
 {
     gmx_mdoutf_t  of;
     char          filemode[3];
-    gmx_bool      bAppendFiles;
+    gmx_bool      bAppendFiles, bCiteTng = FALSE;
     int           i;
 
     snew(of, 1);
@@ -86,11 +94,12 @@ gmx_mdoutf_t init_mdoutf(int nfile, const t_filenm fnm[], int mdrun_flags,
     of->fp_dhdl      = NULL;
     of->fp_field     = NULL;
 
-    of->eIntegrator     = ir->eI;
-    of->bExpanded       = ir->bExpanded;
-    of->elamstats       = ir->expandedvals->elamstats;
-    of->simulation_part = ir->simulation_part;
+    of->eIntegrator             = ir->eI;
+    of->bExpanded               = ir->bExpanded;
+    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))
     {
@@ -124,6 +133,7 @@ gmx_mdoutf_t init_mdoutf(int nfile, const t_filenm fnm[], int mdrun_flags,
                     {
                         gmx_tng_prepare_md_writing(of->tng, top_global, ir);
                     }
+                    bCiteTng = TRUE;
                     break;
                 default:
                     gmx_incons("Invalid full precision file format");
@@ -145,6 +155,7 @@ gmx_mdoutf_t init_mdoutf(int nfile, const t_filenm fnm[], int mdrun_flags,
                     {
                         gmx_tng_prepare_low_prec_writing(of->tng_low_prec, top_global, ir);
                     }
+                    bCiteTng = TRUE;
                     break;
                 default:
                     gmx_incons("Invalid reduced precision file format");
@@ -190,8 +201,8 @@ gmx_mdoutf_t init_mdoutf(int nfile, const t_filenm fnm[], int mdrun_flags,
            trajectory-writing routines later. Also, XTC writing needs
            to know what (and how many) atoms might be in the XTC
            groups, and how to look up later which ones they are. */
-        of->natoms_global = top_global->natoms;
-        of->groups        = &top_global->groups;
+        of->natoms_global       = top_global->natoms;
+        of->groups              = &top_global->groups;
         of->natoms_x_compressed = 0;
         for (i = 0; (i < top_global->natoms); i++)
         {
@@ -202,6 +213,11 @@ gmx_mdoutf_t init_mdoutf(int nfile, const t_filenm fnm[], int mdrun_flags,
         }
     }
 
+    if (bCiteTng)
+    {
+        please_cite(fplog, "Lundborg2014");
+    }
+
     return of;
 }
 
@@ -220,14 +236,9 @@ FILE *mdoutf_get_fp_dhdl(gmx_mdoutf_t of)
     return of->fp_dhdl;
 }
 
-static void moveit(t_commrec *cr, rvec xx[])
+gmx_wallcycle_t mdoutf_get_wcycle(gmx_mdoutf_t of)
 {
-    if (!xx)
-    {
-        return;
-    }
-
-    move_rvecs(cr, FALSE, FALSE, xx, NULL, (cr->nnodes-cr->npmenodes)-1, NULL);
+    return of->wcycle;
 }
 
 void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
@@ -241,8 +252,6 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
     rvec *local_v;
     rvec *global_v;
 
-#define MX(xvf) moveit(cr, xvf)
-
     /* MRS -- defining these variables is to manage the difference
      * between half step and full step velocities, but there must be a better way . . . */
 
@@ -289,63 +298,6 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
             copy_mat(state_local->fvir_prev, state_global->fvir_prev);
             copy_mat(state_local->pres_prev, state_global->pres_prev);
         }
-        if (cr->nnodes > 1)
-        {
-            /* Particle decomposition, collect the data on the master node */
-            if (mdof_flags & MDOF_CPT)
-            {
-                if (state_local->flags & (1<<estX))
-                {
-                    MX(state_global->x);
-                }
-                if (state_local->flags & (1<<estV))
-                {
-                    MX(state_global->v);
-                }
-                if (state_local->flags & (1<<estSDX))
-                {
-                    MX(state_global->sd_X);
-                }
-                if (state_global->nrngi > 1)
-                {
-                    if (state_local->flags & (1<<estLD_RNG))
-                    {
-#ifdef GMX_MPI
-                        MPI_Gather(state_local->ld_rng,
-                                   state_local->nrng*sizeof(state_local->ld_rng[0]), MPI_BYTE,
-                                   state_global->ld_rng,
-                                   state_local->nrng*sizeof(state_local->ld_rng[0]), MPI_BYTE,
-                                   MASTERRANK(cr), cr->mpi_comm_mygroup);
-#endif
-                    }
-                    if (state_local->flags & (1<<estLD_RNGI))
-                    {
-#ifdef GMX_MPI
-                        MPI_Gather(state_local->ld_rngi,
-                                   sizeof(state_local->ld_rngi[0]), MPI_BYTE,
-                                   state_global->ld_rngi,
-                                   sizeof(state_local->ld_rngi[0]), MPI_BYTE,
-                                   MASTERRANK(cr), cr->mpi_comm_mygroup);
-#endif
-                    }
-                }
-            }
-            else
-            {
-                if (mdof_flags & (MDOF_X | MDOF_X_COMPRESSED))
-                {
-                    MX(state_global->x);
-                }
-                if (mdof_flags & MDOF_V)
-                {
-                    MX(global_v);
-                }
-            }
-            if (mdof_flags & MDOF_F)
-            {
-                MX(f_global);
-            }
-        }
     }
 
     if (MASTER(cr))
@@ -399,7 +351,7 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
                 int i, j;
 
                 snew(xxtc, of->natoms_x_compressed);
-                for (i = 0, j = 0; (i < of->natoms_x_compressed); i++)
+                for (i = 0, j = 0; (i < of->natoms_global); i++)
                 {
                     if (ggrpnr(of->groups, egcCompressedX, i) == 0)
                     {
@@ -430,6 +382,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)
@@ -452,6 +415,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);