Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / gmxlib / mvdata.c
index d383740c1f5215b8eaf3634538b7b293fccdf50d..41aeaeaf15e7267d1bbb475c44d016d6e6ddd7f0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 /* This file is completely threadsafe - keep it that way! */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
+
+#include "gromacs/legacyheaders/mvdata.h"
 
-#include <sysstuff.h>
 #include <string.h>
-#include "typedefs.h"
-#include "main.h"
-#include "mvdata.h"
-#include "network.h"
-#include "smalloc.h"
-#include "gmx_fatal.h"
-#include "symtab.h"
-#include "vec.h"
-#include "tgroup.h"
+
+#include "gromacs/legacyheaders/main.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/legacyheaders/tgroup.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 
 #define   block_bc(cr,   d) gmx_bcast(     sizeof(d),     &(d), (cr))
 /* Probably the test for (nr) > 0 in the next macro is only needed
@@ -241,34 +241,43 @@ static void bc_groups(const t_commrec *cr, t_symtab *symtab,
     }
 }
 
-void bcast_state_setup(const t_commrec *cr, t_state *state)
+void bcast_state(const t_commrec *cr, t_state *state)
 {
+    int      i, nnht, nnhtp;
+    gmx_bool bAlloc;
+
+    if (!PAR(cr))
+    {
+        return;
+    }
+
+    /* Broadcasts the state sizes and flags from the master to all nodes
+     * in cr->mpi_comm_mygroup. The arrays are not broadcasted. */
     block_bc(cr, state->natoms);
     block_bc(cr, state->ngtc);
     block_bc(cr, state->nnhpres);
     block_bc(cr, state->nhchainlength);
-    block_bc(cr, state->nrng);
-    block_bc(cr, state->nrngi);
     block_bc(cr, state->flags);
     if (state->lambda == NULL)
     {
         snew_bc(cr, state->lambda, efptNR)
     }
-}
 
-void bcast_state(const t_commrec *cr, t_state *state, gmx_bool bAlloc)
-{
-    int i, nnht, nnhtp;
-
-    bcast_state_setup(cr, state);
+    if (cr->dd)
+    {
+        /* We allocate dynamically in dd_partition_system. */
+        return;
+    }
+    /* The code below is reachable only by TPI and NM, so it is not
+       tested by anything. */
 
     nnht  = (state->ngtc)*(state->nhchainlength);
     nnhtp = (state->nnhpres)*(state->nhchainlength);
 
-    if (MASTER(cr))
-    {
-        bAlloc = FALSE;
-    }
+    /* We still need to allocate the arrays in state for non-master
+     * ranks, which is done (implicitly via bAlloc) in the dirty,
+     * dirty nblock_abc macro. */
+    bAlloc = !MASTER(cr);
     if (bAlloc)
     {
         state->nalloc = state->natoms;
@@ -298,16 +307,6 @@ void bcast_state(const t_commrec *cr, t_state *state, gmx_bool bAlloc)
                 case estV:       nblock_abc(cr, state->natoms, state->v); break;
                 case estSDX:     nblock_abc(cr, state->natoms, state->sd_X); break;
                 case estCGP:     nblock_abc(cr, state->natoms, state->cg_p); break;
-                case estLD_RNG:  if (state->nrngi == 1)
-                    {
-                        nblock_abc(cr, state->nrng, state->ld_rng);
-                    }
-                    break;
-                case estLD_RNGI: if (state->nrngi == 1)
-                    {
-                        nblock_abc(cr, state->nrngi, state->ld_rngi);
-                    }
-                    break;
                 case estDISRE_INITF: block_bc(cr, state->hist.disre_initf); break;
                 case estDISRE_RM3TAV:
                     block_bc(cr, state->hist.ndisrepairs);
@@ -555,6 +554,16 @@ static void bc_adress(const t_commrec *cr, t_adress *adress)
         nblock_bc(cr, adress->n_energy_grps, adress->group_explicit);
     }
 }
+
+static void bc_imd(const t_commrec *cr, t_IMD *imd)
+{
+    int g;
+
+    block_bc(cr, *imd);
+    snew_bc(cr, imd->ind, imd->nat);
+    nblock_bc(cr, imd->nat, imd->ind);
+}
+
 static void bc_fepvals(const t_commrec *cr, t_lambda *fep)
 {
     gmx_bool bAlloc = TRUE;
@@ -564,7 +573,7 @@ static void bc_fepvals(const t_commrec *cr, t_lambda *fep)
     block_bc(cr, fep->init_lambda);
     block_bc(cr, fep->init_fep_state);
     block_bc(cr, fep->delta_lambda);
-    block_bc(cr, fep->bPrintEnergy);
+    block_bc(cr, fep->edHdLPrintEnergy);
     block_bc(cr, fep->n_lambda);
     if (fep->n_lambda > 0)
     {
@@ -644,6 +653,31 @@ static void bc_simtempvals(const t_commrec *cr, t_simtemp *simtemp, int n_lambda
     }
 }
 
+
+static void bc_swapions(const t_commrec *cr, t_swapcoords *swap)
+{
+    int i;
+
+
+    block_bc(cr, *swap);
+
+    /* Broadcast ion group atom indices */
+    snew_bc(cr, swap->ind, swap->nat);
+    nblock_bc(cr, swap->nat, swap->ind);
+
+    /* Broadcast split groups atom indices */
+    for (i = 0; i < 2; i++)
+    {
+        snew_bc(cr, swap->ind_split[i], swap->nat_split[i]);
+        nblock_bc(cr, swap->nat_split[i], swap->ind_split[i]);
+    }
+
+    /* Broadcast solvent group atom indices */
+    snew_bc(cr, swap->ind_sol, swap->nat_sol);
+    nblock_bc(cr, swap->nat_sol, swap->ind_sol);
+}
+
+
 static void bc_inputrec(const t_commrec *cr, t_inputrec *inputrec)
 {
     gmx_bool bAlloc = TRUE;
@@ -682,11 +716,21 @@ static void bc_inputrec(const t_commrec *cr, t_inputrec *inputrec)
         snew_bc(cr, inputrec->rot, 1);
         bc_rot(cr, inputrec->rot);
     }
+    if (inputrec->bIMD)
+    {
+        snew_bc(cr, inputrec->imd, 1);
+        bc_imd(cr, inputrec->imd);
+    }
     for (i = 0; (i < DIM); i++)
     {
         bc_cosines(cr, &(inputrec->ex[i]));
         bc_cosines(cr, &(inputrec->et[i]));
     }
+    if (inputrec->eSwapCoords != eswapNO)
+    {
+        snew_bc(cr, inputrec->swap, 1);
+        bc_swapions(cr, inputrec->swap);
+    }
     if (inputrec->bAdress)
     {
         snew_bc(cr, inputrec->adress, 1);