Use much less PaddedRVecVector and more ArrayRef of RVec
authorMark Abraham <mark.j.abraham@gmail.com>
Thu, 9 Nov 2017 00:23:01 +0000 (17:23 -0700)
committerBerk Hess <hess@kth.se>
Tue, 21 Nov 2017 13:19:17 +0000 (14:19 +0100)
Only code that handles allocations needs to know the concrete type of
the container. In some cases that do need the container type,
templating on the allocator will be needed in future, so that is
arranged here. This prepares for changing the allocator for state->x
so that we can use one that can be configured at run time for
efficient GPU transfers.

Also introduced PaddedArrayRef to use in code that relies on the
padding and/or alignedness attributes of the PaddedRVecVector.  This
keeps partial type safety, although a proper implementation of such a
view should replace the current typedef.

Had to make some associate changes to helper functionality to
use more ArrayRef, rather than rely on the way rvec pointers could
decay to real pointers.

Used some compat::make_unique since that is better style.

Change-Id: I1ed3feb016727665329e919433bece9773b46969

26 files changed:
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec.h
src/gromacs/fileio/checkpoint.cpp
src/gromacs/gmxana/gmx_trjconv.cpp
src/gromacs/math/paddedvector.h
src/gromacs/mdlib/broadcaststructs.cpp
src/gromacs/mdlib/calcmu.cpp
src/gromacs/mdlib/calcmu.h
src/gromacs/mdlib/force.h
src/gromacs/mdlib/mdoutf.cpp
src/gromacs/mdlib/mdoutf.h
src/gromacs/mdlib/minimize.cpp
src/gromacs/mdlib/shellfc.cpp
src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdlib/sim_util.h
src/gromacs/mdlib/tpi.cpp
src/gromacs/mdlib/trajectory_writing.cpp
src/gromacs/mdlib/trajectory_writing.h
src/gromacs/mdlib/update.cpp
src/gromacs/mdlib/update.h
src/gromacs/mdtypes/state.cpp
src/gromacs/mdtypes/state.h
src/gromacs/pbcutil/pbc.cpp
src/gromacs/pbcutil/pbc.h
src/programs/mdrun/md.cpp
src/programs/view/manager.cpp

index adf21588be4b85602180503ff5c02b123a92f265..34ed38d61477cfda81e79383ec6bdae60e7961b7 100644 (file)
@@ -1157,8 +1157,9 @@ static void dd_collect_cg(gmx_domdec_t  *dd,
     dd->comm->master_cg_ddp_count = state_local->ddp_count;
 }
 
-static void dd_collect_vec_sendrecv(gmx_domdec_t *dd,
-                                    const rvec *lv, rvec *v)
+static void dd_collect_vec_sendrecv(gmx_domdec_t                  *dd,
+                                    gmx::ArrayRef<const gmx::RVec> lv,
+                                    gmx::ArrayRef<gmx::RVec>       v)
 {
     gmx_domdec_master_t *ma;
     int                  n, i, c, a, nalloc = 0;
@@ -1170,7 +1171,7 @@ static void dd_collect_vec_sendrecv(gmx_domdec_t *dd,
     if (!DDMASTER(dd))
     {
 #if GMX_MPI
-        MPI_Send(const_cast<void *>(static_cast<const void *>(lv)), dd->nat_home*sizeof(rvec), MPI_BYTE,
+        MPI_Send(const_cast<void *>(static_cast<const void *>(lv.data())), dd->nat_home*sizeof(rvec), MPI_BYTE,
                  DDMASTERRANK(dd), dd->rank, dd->mpi_comm_all);
 #endif
     }
@@ -1234,8 +1235,9 @@ static void get_commbuffer_counts(gmx_domdec_t *dd,
     }
 }
 
-static void dd_collect_vec_gatherv(gmx_domdec_t *dd,
-                                   const rvec *lv, rvec *v)
+static void dd_collect_vec_gatherv(gmx_domdec_t                  *dd,
+                                   gmx::ArrayRef<const gmx::RVec> lv,
+                                   gmx::ArrayRef<gmx::RVec>       v)
 {
     gmx_domdec_master_t *ma;
     int                 *rcounts = nullptr, *disps = nullptr;
@@ -1252,7 +1254,7 @@ static void dd_collect_vec_gatherv(gmx_domdec_t *dd,
         buf = ma->vbuf;
     }
 
-    dd_gatherv(dd, dd->nat_home*sizeof(rvec), lv, rcounts, disps, buf);
+    dd_gatherv(dd, dd->nat_home*sizeof(rvec), lv.data(), rcounts, disps, buf);
 
     if (DDMASTER(dd))
     {
@@ -1272,15 +1274,13 @@ static void dd_collect_vec_gatherv(gmx_domdec_t *dd,
     }
 }
 
-void dd_collect_vec(gmx_domdec_t           *dd,
-                    const t_state          *state_local,
-                    const PaddedRVecVector *localVector,
-                    rvec                   *v)
+void dd_collect_vec(gmx_domdec_t                  *dd,
+                    const t_state                 *state_local,
+                    gmx::ArrayRef<const gmx::RVec> lv,
+                    gmx::ArrayRef<gmx::RVec>       v)
 {
     dd_collect_cg(dd, state_local);
 
-    const rvec *lv = as_rvec_array(localVector->data());
-
     if (dd->nnodes <= GMX_DD_NNODES_SENDRECV)
     {
         dd_collect_vec_sendrecv(dd, lv, v);
@@ -1291,15 +1291,6 @@ void dd_collect_vec(gmx_domdec_t           *dd,
     }
 }
 
-void dd_collect_vec(gmx_domdec_t           *dd,
-                    const t_state          *state_local,
-                    const PaddedRVecVector *localVector,
-                    PaddedRVecVector       *vector)
-{
-    dd_collect_vec(dd, state_local, localVector,
-                   DDMASTER(dd) ? as_rvec_array(vector->data()) : nullptr);
-}
-
 
 void dd_collect_state(gmx_domdec_t *dd,
                       const t_state *state_local, t_state *state)
@@ -1344,15 +1335,18 @@ void dd_collect_state(gmx_domdec_t *dd,
     }
     if (state_local->flags & (1 << estX))
     {
-        dd_collect_vec(dd, state_local, &state_local->x, &state->x);
+        gmx::ArrayRef<gmx::RVec> globalXRef = state ? gmx::makeArrayRef(state->x) : gmx::EmptyArrayRef();
+        dd_collect_vec(dd, state_local, state_local->x, globalXRef);
     }
     if (state_local->flags & (1 << estV))
     {
-        dd_collect_vec(dd, state_local, &state_local->v, &state->v);
+        gmx::ArrayRef<gmx::RVec> globalVRef = state ? gmx::makeArrayRef(state->v) : gmx::EmptyArrayRef();
+        dd_collect_vec(dd, state_local, state_local->v, globalVRef);
     }
     if (state_local->flags & (1 << estCGP))
     {
-        dd_collect_vec(dd, state_local, &state_local->cg_p, &state->cg_p);
+        gmx::ArrayRef<gmx::RVec> globalCgpRef = state ? gmx::makeArrayRef(state->cg_p) : gmx::EmptyArrayRef();
+        dd_collect_vec(dd, state_local, state_local->cg_p, globalCgpRef);
     }
 }
 
index 5ae8947effaee1ab3780dc8dd9dae9e6c9ecd77b..44f61a0372d2495b18d24f8c13b57649b091ba9d 100644 (file)
@@ -71,6 +71,7 @@
 #include "gromacs/topology/block.h"
 #include "gromacs/topology/idef.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
@@ -256,16 +257,10 @@ void dd_setup_dlb_resource_sharing(t_commrec           *cr,
                                    int                  gpu_id);
 
 /*! \brief Collects local rvec arrays \p lv to \p v on the master rank */
-void dd_collect_vec(struct gmx_domdec_t    *dd,
-                    const t_state          *state_local,
-                    const PaddedRVecVector *lv,
-                    rvec                   *v);
-
-/*! \brief Collects local rvec arrays \p lv to \p v on the master rank */
-void dd_collect_vec(struct gmx_domdec_t    *dd,
-                    const t_state          *state_local,
-                    const PaddedRVecVector *lv,
-                    PaddedRVecVector       *v);
+void dd_collect_vec(struct gmx_domdec_t           *dd,
+                    const t_state                 *state_local,
+                    gmx::ArrayRef<const gmx::RVec> lv,
+                    gmx::ArrayRef<gmx::RVec>       v);
 
 /*! \brief Collects the local state \p state_local to \p state on the master rank */
 void dd_collect_state(struct gmx_domdec_t *dd,
index 9cd842b644af9d78097c3e24688ca103a2016e38..c9413b9d8aec83f0143f1795ed03c0c161e3c0b0 100644 (file)
@@ -512,15 +512,20 @@ static void convertArrayRealPrecision(const char gmx_unused *c, int gmx_unused *
  * and std::vector<real>. Using real * is deprecated and this routine
  * will simplify a lot when only std::vector needs to be supported.
  *
+ * The routine is generic to vectors with different allocators,
+ * because as part of reading a checkpoint there are vectors whose
+ * size is not known until reading has progressed far enough, so a
+ * resize method must be called.
+ *
  * When not listing, we use either v or vector, depending on which is !=NULL.
  * If nval >= 0, nval is used; on read this should match the passed value.
  * If nval n<0, *nptr (with v) or vector->size() is used. On read using v,
  * the value is stored in nptr
  */
-template<typename T>
+template<typename T, typename AllocatorType>
 static int doVectorLow(XDR *xd, StatePart part, int ecpt, int sflags,
                        int nval, int *nptr,
-                       T **v, std::vector<T> *vector,
+                       T **v, std::vector<T, AllocatorType> *vector,
                        FILE *list, CptElementType cptElementType)
 {
     GMX_RELEASE_ASSERT(list != nullptr || (v != nullptr && vector == nullptr) || (v == nullptr && vector != nullptr), "Without list, we should have exactly one of v and vector != NULL");
@@ -669,12 +674,13 @@ static int doRealArrayRef(XDR *xd, StatePart part, int ecpt, int sflags,
                           gmx::ArrayRef<real> vector, FILE *list)
 {
     real *v_real = vector.data();
-    return doVectorLow<real>(xd, part, ecpt, sflags, vector.size(), nullptr, &v_real, nullptr, list, CptElementType::real);
+    return doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags, vector.size(), nullptr, &v_real, nullptr, list, CptElementType::real);
 }
 
-//! \brief Read/Write a PaddedRVecVector.
-static int doPaddedRvecVector(XDR *xd, StatePart part, int ecpt, int sflags,
-                              gmx::PaddedRVecVector *v, int numAtoms, FILE *list)
+//! \brief Read/Write a vector whose value_type is RVec and whose allocator is \c AllocatorType.
+template <typename AllocatorType>
+static int doRvecVector(XDR *xd, StatePart part, int ecpt, int sflags,
+                        std::vector<gmx::RVec, AllocatorType> *v, int numAtoms, FILE *list)
 {
     const int numReals = numAtoms*DIM;
 
@@ -693,7 +699,10 @@ static int doPaddedRvecVector(XDR *xd, StatePart part, int ecpt, int sflags,
     }
     else
     {
-        return doVectorLow<real>(xd, part, ecpt, sflags, numReals, nullptr, nullptr, nullptr, list, CptElementType::real);
+        // Use the rebind facility to change the value_type of the
+        // allocator from RVec to real.
+        using realAllocator = typename AllocatorType::template rebind<real>::other;
+        return doVectorLow<real, realAllocator>(xd, part, ecpt, sflags, numReals, nullptr, nullptr, nullptr, list, CptElementType::real);
     }
 }
 
@@ -704,7 +713,7 @@ static int doPaddedRvecVector(XDR *xd, StatePart part, int ecpt, int sflags,
 static int do_cpte_reals(XDR *xd, StatePart part, int ecpt, int sflags,
                          int n, real **v, FILE *list)
 {
-    return doVectorLow<real>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::real);
+    return doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::real);
 }
 
 /* This function does the same as do_cpte_reals,
@@ -714,19 +723,19 @@ static int do_cpte_reals(XDR *xd, StatePart part, int ecpt, int sflags,
 static int do_cpte_n_reals(XDR *xd, StatePart part, int ecpt, int sflags,
                            int *n, real **v, FILE *list)
 {
-    return doVectorLow<real>(xd, part, ecpt, sflags, -1, n, v, nullptr, list, CptElementType::real);
+    return doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags, -1, n, v, nullptr, list, CptElementType::real);
 }
 
 static int do_cpte_real(XDR *xd, StatePart part, int ecpt, int sflags,
                         real *r, FILE *list)
 {
-    return doVectorLow<real>(xd, part, ecpt, sflags, 1, nullptr, &r, nullptr, list, CptElementType::real);
+    return doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags, 1, nullptr, &r, nullptr, list, CptElementType::real);
 }
 
 static int do_cpte_ints(XDR *xd, StatePart part, int ecpt, int sflags,
                         int n, int **v, FILE *list)
 {
-    return doVectorLow<int>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::integer);
+    return doVectorLow < int, std::allocator < int>>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::integer);
 }
 
 static int do_cpte_int(XDR *xd, StatePart part, int ecpt, int sflags,
@@ -738,7 +747,7 @@ static int do_cpte_int(XDR *xd, StatePart part, int ecpt, int sflags,
 static int do_cpte_doubles(XDR *xd, StatePart part, int ecpt, int sflags,
                            int n, double **v, FILE *list)
 {
-    return doVectorLow<double>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::real);
+    return doVectorLow < double, std::allocator < double>>(xd, part, ecpt, sflags, n, nullptr, v, nullptr, list, CptElementType::real);
 }
 
 static int do_cpte_double(XDR *xd, StatePart part, int ecpt, int sflags,
@@ -754,8 +763,8 @@ static int do_cpte_matrix(XDR *xd, StatePart part, int ecpt, int sflags,
     int   ret;
 
     vr  = &(v[0][0]);
-    ret = doVectorLow<real>(xd, part, ecpt, sflags,
-                            DIM*DIM, nullptr, &vr, nullptr, nullptr, CptElementType::matrix3x3);
+    ret = doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags,
+                                                      DIM*DIM, nullptr, &vr, nullptr, nullptr, CptElementType::matrix3x3);
 
     if (list && ret == 0)
     {
@@ -780,7 +789,7 @@ static int do_cpte_nmatrix(XDR *xd, StatePart part, int ecpt, int sflags,
     }
     for (i = 0; i < n; i++)
     {
-        reti = doVectorLow<real>(xd, part, ecpt, sflags, n, nullptr, &(v[i]), nullptr, nullptr, CptElementType::matrix3x3);
+        reti = doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags, n, nullptr, &(v[i]), nullptr, nullptr, CptElementType::matrix3x3);
         if (list && reti == 0)
         {
             sprintf(name, "%s[%d]", entryName(part, ecpt), i);
@@ -837,9 +846,9 @@ static int do_cpte_matrices(XDR *xd, StatePart part, int ecpt, int sflags,
             }
         }
     }
-    ret = doVectorLow<real>(xd, part, ecpt, sflags,
-                            nf*DIM*DIM, nullptr, &vr, nullptr, nullptr,
-                            CptElementType::matrix3x3);
+    ret = doVectorLow < real, std::allocator < real>>(xd, part, ecpt, sflags,
+                                                      nf*DIM*DIM, nullptr, &vr, nullptr, nullptr,
+                                                      CptElementType::matrix3x3);
     for (i = 0; i < nf; i++)
     {
         for (j = 0; j < DIM; j++)
@@ -1094,8 +1103,8 @@ static int do_cpt_state(XDR *xd,
                 case estBAROS_INT:   ret  = do_cpte_double(xd, part, i, sflags, &state->baros_integral, list); break;
                 case estVETA:    ret      = do_cpte_real(xd, part, i, sflags, &state->veta, list); break;
                 case estVOL0:    ret      = do_cpte_real(xd, part, i, sflags, &state->vol0, list); break;
-                case estX:       ret      = doPaddedRvecVector(xd, part, i, sflags, &state->x, state->natoms, list); break;
-                case estV:       ret      = doPaddedRvecVector(xd, part, i, sflags, &state->v, state->natoms, list); break;
+                case estX:       ret      = doRvecVector(xd, part, i, sflags, &state->x, state->natoms, list); break;
+                case estV:       ret      = doRvecVector(xd, part, i, sflags, &state->v, state->natoms, list); break;
                 /* The RNG entries are no longer written,
                  * the next 4 lines are only for reading old files.
                  */
@@ -2787,12 +2796,12 @@ void read_checkpoint_trxframe(t_fileio *fp, t_trxframe *fr)
     fr->bX         = (state.flags & (1<<estX));
     if (fr->bX)
     {
-        fr->x   = getRvecArrayFromPaddedRVecVector(&state.x, state.natoms);
+        fr->x   = makeRvecArray(state.x, state.natoms);
     }
     fr->bV      = (state.flags & (1<<estV));
     if (fr->bV)
     {
-        fr->v   = getRvecArrayFromPaddedRVecVector(&state.v, state.natoms);
+        fr->v   = makeRvecArray(state.v, state.natoms);
     }
     fr->bF      = FALSE;
     fr->bBox    = (state.flags & (1<<estBOX));
index 51d48f2b5f0a68c9ede9e19434e305435f9de322..bbec0cf7351c8b697148e57f460a7d55b4692747 100644 (file)
@@ -65,6 +65,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/trajectory/trajectoryframe.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
@@ -270,7 +271,7 @@ static void put_molecule_com_in_box(int unitcell_enum, int ecenter,
 {
     int     i, j;
     int     d;
-    rvec    com, new_com, shift, box_center;
+    rvec    com, shift, box_center;
     real    m;
     double  mtot;
     t_pbc   pbc;
@@ -299,20 +300,22 @@ static void put_molecule_com_in_box(int unitcell_enum, int ecenter,
         svmul(1.0/mtot, com, com);
 
         /* check if COM is outside box */
-        copy_rvec(com, new_com);
+        gmx::RVec newCom;
+        copy_rvec(com, newCom);
+        auto      newComArrayRef = gmx::arrayRefFromArray(&newCom, 1);
         switch (unitcell_enum)
         {
             case euRect:
-                put_atoms_in_box(ePBC, box, 1, &new_com);
+                put_atoms_in_box(ePBC, box, newComArrayRef);
                 break;
             case euTric:
-                put_atoms_in_triclinic_unitcell(ecenter, box, 1, &new_com);
+                put_atoms_in_triclinic_unitcell(ecenter, box, newComArrayRef);
                 break;
             case euCompact:
-                put_atoms_in_compact_unitcell(ePBC, ecenter, box, 1, &new_com);
+                put_atoms_in_compact_unitcell(ePBC, ecenter, box, newComArrayRef);
                 break;
         }
-        rvec_sub(new_com, com, shift);
+        rvec_sub(newCom, com, shift);
         if (norm2(shift) > 0)
         {
             if (debug)
@@ -337,7 +340,7 @@ static void put_residue_com_in_box(int unitcell_enum, int ecenter,
     int              d, presnr;
     real             m;
     double           mtot;
-    rvec             box_center, com, new_com, shift;
+    rvec             box_center, com, shift;
     static const int NOTSET = -12347;
     calc_box_center(ecenter, box, box_center);
 
@@ -354,20 +357,22 @@ static void put_residue_com_in_box(int unitcell_enum, int ecenter,
             svmul(1.0/mtot, com, com);
 
             /* check if COM is outside box */
-            copy_rvec(com, new_com);
+            gmx::RVec newCom;
+            copy_rvec(com, newCom);
+            auto      newComArrayRef = gmx::arrayRefFromArray(&newCom, 1);
             switch (unitcell_enum)
             {
                 case euRect:
-                    put_atoms_in_box(ePBC, box, 1, &new_com);
+                    put_atoms_in_box(ePBC, box, newComArrayRef);
                     break;
                 case euTric:
-                    put_atoms_in_triclinic_unitcell(ecenter, box, 1, &new_com);
+                    put_atoms_in_triclinic_unitcell(ecenter, box, newComArrayRef);
                     break;
                 case euCompact:
-                    put_atoms_in_compact_unitcell(ePBC, ecenter, box, 1, &new_com);
+                    put_atoms_in_compact_unitcell(ePBC, ecenter, box, newComArrayRef);
                     break;
             }
-            rvec_sub(new_com, com, shift);
+            rvec_sub(newCom, com, shift);
             if (norm2(shift))
             {
                 if (debug)
@@ -1651,19 +1656,20 @@ int gmx_trjconv(int argc, char *argv[])
                             }
                         }
 
+                        auto positionsArrayRef = gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec *>(fr.x), natoms);
                         if (bPBCcomAtom)
                         {
                             switch (unitcell_enum)
                             {
                                 case euRect:
-                                    put_atoms_in_box(ePBC, fr.box, natoms, fr.x);
+                                    put_atoms_in_box(ePBC, fr.box, positionsArrayRef);
                                     break;
                                 case euTric:
-                                    put_atoms_in_triclinic_unitcell(ecenter, fr.box, natoms, fr.x);
+                                    put_atoms_in_triclinic_unitcell(ecenter, fr.box, positionsArrayRef);
                                     break;
                                 case euCompact:
                                     put_atoms_in_compact_unitcell(ePBC, ecenter, fr.box,
-                                                                  natoms, fr.x);
+                                                                  positionsArrayRef);
                                     break;
                             }
                         }
index e3cf9c8ec1cb89e81d12f1486dcb15fdb8345c5c..3433a394323a8a67167fbdd4964d2d294ccdc960 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/alignedallocator.h"
+#include "gromacs/utility/arrayref.h"
 
 namespace gmx
 {
@@ -60,9 +61,9 @@ namespace gmx
  *       by automated padding on resize() of the vector.
  * \todo Undo the move of allocator.h and alignedallocator.h from the internal
  *       to be public API applied in Change-Id: Ifb8dacf, needed to use
- *       AlginedAllocationPolicy here, when replacing std::vector here.
+ *       AlignedAllocationPolicy here, when replacing std::vector here.
  */
-using PaddedRVecVector = std::vector < gmx::RVec, gmx::Allocator < gmx::RVec, AlignedAllocationPolicy > >;
+using PaddedRVecVector = std::vector < RVec, Allocator < RVec, AlignedAllocationPolicy > >;
 
 /*! \brief Returns the padded size for PaddedRVecVector given the number of atoms
  *
@@ -92,9 +93,16 @@ static inline size_t paddedRVecVectorSize(size_t numAtoms)
     return std::max(simdScatterAccessSize, simdFlatAccesSize);
 }
 
+/*! \brief Temporary definition of a type usable for SIMD-style loads of RVec quantities from a view.
+ *
+ * \todo Find a more permanent solution that permits the update code to safely
+ * use a padded, aligned array-ref type. */
+template <typename T>
+using PaddedArrayRef = ArrayRef<T>;
+
 } // namespace gmx
 
-// TODO This is a hack to avoid littering gmx:: all over code that is
+// TODO These are hacks to avoid littering gmx:: all over code that is
 // almost all destined to move into the gmx namespace at some point.
 // An alternative would be about 20 files with using statements.
 using gmx::PaddedRVecVector;
index cf187966936ade490221fb879710b398c0927707..4977cf3acf8593f43fda614368be60712ebf82e6 100644 (file)
@@ -259,7 +259,8 @@ static void bc_groups(const t_commrec *cr, t_symtab *symtab,
     }
 }
 
-static void bcastPaddedRVecVector(const t_commrec *cr, PaddedRVecVector *v, int numAtoms)
+template <typename AllocatorType>
+static void bcastPaddedRVecVector(const t_commrec *cr, std::vector<gmx::RVec, AllocatorType> *v, int numAtoms)
 {
     v->resize(gmx::paddedRVecVectorSize(numAtoms));
     nblock_bc(cr, numAtoms, as_rvec_array(v->data()));
index c29e37005262a5c1ca1b0a8413865e358d9a319c..ef8bb89fafa7b214f502e1b288149f382a6a7949 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) 2012,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015,2017, 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.
@@ -47,7 +47,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
 
-void calc_mu(int start, int homenr, rvec x[], real q[], real qB[],
+void calc_mu(int start, int homenr, gmx::ArrayRef<gmx::RVec> x, real q[], real qB[],
              int nChargePerturbed,
              dvec mu, dvec mu_B)
 {
index 7a74d13797c42999e368b490d9bdefd7989beab8..f33e6af3189dd8fe071c8a313496eb05f5e3390e 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) 2010,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015,2017, 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.
 #include <stdio.h>
 
 #include "gromacs/math/vectypes.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void calc_mu(int start, int homenr, rvec x[], real q[], real qB[],
+void calc_mu(int start, int homenr, gmx::ArrayRef<gmx::RVec> x, real q[], real qB[],
              int nChargePerturbed,
              dvec mu, dvec mu_B);
 
 gmx_bool read_mu(FILE *fp, rvec mu, real *vol);
 /* Return true on succes */
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 6cfe0c14044d3a366121561599ca3e8920e8a5ff..87d4fe94961a048b1ad5bbd594fbac7285cf654b 100644 (file)
@@ -155,8 +155,8 @@ void do_force(FILE *log, t_commrec *cr,
               gmx_int64_t step, struct t_nrnb *nrnb, gmx_wallcycle_t wcycle,
               gmx_localtop_t *top,
               gmx_groups_t *groups,
-              matrix box, PaddedRVecVector *coordinates, history_t *hist,
-              PaddedRVecVector *force,
+              matrix box, gmx::PaddedArrayRef<gmx::RVec> coordinates, history_t *hist,
+              gmx::PaddedArrayRef<gmx::RVec> force,
               tensor vir_force,
               t_mdatoms *mdatoms,
               gmx_enerdata_t *enerd, t_fcdata *fcd,
index 52c2520142505ca91f770e69ae6c84e353f090f8..0dac9e7f2f59f0168c0d8afae98f8abe6f8cca04 100644 (file)
@@ -251,7 +251,7 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
                                       gmx_int64_t step, double t,
                                       t_state *state_local, t_state *state_global,
                                       ObservablesHistory *observablesHistory,
-                                      PaddedRVecVector *f_local)
+                                      gmx::ArrayRef<gmx::RVec> f_local)
 {
     rvec *f_global;
 
@@ -265,19 +265,19 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
         {
             if (mdof_flags & (MDOF_X | MDOF_X_COMPRESSED))
             {
-                dd_collect_vec(cr->dd, state_local, &state_local->x,
-                               MASTER(cr) ? &state_global->x : nullptr);
+                gmx::ArrayRef<gmx::RVec> globalXRef = MASTER(cr) ? gmx::makeArrayRef(state_global->x) : gmx::EmptyArrayRef();
+                dd_collect_vec(cr->dd, state_local, state_local->x, globalXRef);
             }
             if (mdof_flags & MDOF_V)
             {
-                dd_collect_vec(cr->dd, state_local, &state_local->v,
-                               MASTER(cr) ? &state_global->v : nullptr);
+                gmx::ArrayRef<gmx::RVec> globalVRef = MASTER(cr) ? gmx::makeArrayRef(state_global->v) : gmx::EmptyArrayRef();
+                dd_collect_vec(cr->dd, state_local, state_local->v, globalVRef);
             }
         }
         f_global = of->f_global;
         if (mdof_flags & MDOF_F)
         {
-            dd_collect_vec(cr->dd, state_local, f_local, f_global);
+            dd_collect_vec(cr->dd, state_local, f_local, gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec *>(f_global), f_local.size()));
         }
     }
     else
@@ -285,7 +285,7 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
         /* We have the whole state locally: copy the local state pointer */
         state_global = state_local;
 
-        f_global     = as_rvec_array(f_local->data());
+        f_global     = as_rvec_array(f_local.data());
     }
 
     if (MASTER(cr))
index 612982182fceeb91d82539e7952cd49271e0c1b5..ec68f27fd0a4604708108c505fb293f3b8fea9e0 100644 (file)
@@ -41,6 +41,7 @@
 #include "gromacs/math/paddedvector.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 
 class energyhistory_t;
@@ -108,7 +109,7 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr,
                                       gmx_int64_t step, double t,
                                       t_state *state_local, t_state *state_global,
                                       ObservablesHistory *observablesHistory,
-                                      PaddedRVecVector *f_local);
+                                      gmx::ArrayRef<gmx::RVec> f_local);
 
 #define MDOF_X            (1<<0)
 #define MDOF_V            (1<<1)
index dbed5d27e77a44f02822434c915a42e2c96a5cb2..a27575016d14266131847ff9d5e0c6bf55b85ba2 100644 (file)
@@ -531,7 +531,7 @@ static void write_em_traj(FILE *fplog, t_commrec *cr,
     mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags,
                                      top_global, step, (double)step,
                                      &state->s, state_global, observablesHistory,
-                                     &state->f);
+                                     state->f);
 
     if (confout != nullptr && MASTER(cr))
     {
@@ -767,8 +767,8 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
      */
     do_force(fplog, cr, inputrec,
              count, nrnb, wcycle, top, &top_global->groups,
-             ems->s.box, &ems->s.x, &ems->s.hist,
-             &ems->f, force_vir, mdAtoms->mdatoms(), enerd, fcd,
+             ems->s.box, ems->s.x, &ems->s.hist,
+             ems->f, force_vir, mdAtoms->mdatoms(), enerd, fcd,
              ems->s.lambda, graph, fr, vsite, mu_tot, t, nullptr, TRUE,
              GMX_FORCE_STATECHANGED | GMX_FORCE_ALLFORCES |
              GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY |
@@ -1870,7 +1870,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
         }
 
         mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags,
-                                         top_global, step, (real)step, &ems.s, state_global, observablesHistory, &ems.f);
+                                         top_global, step, (real)step, &ems.s, state_global, observablesHistory, ems.f);
 
         /* Do the linesearching in the direction dx[point][0..(n-1)] */
 
index d0e9962fd59ebf6d4cb1589ead31517ed7fa18f1..f953a5a6aab0e16263432c5367cb1c53164c5ff4 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/mtop_lookup.h"
 #include "gromacs/topology/mtop_util.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
@@ -695,11 +696,12 @@ static void do_1pos3(rvec xnew, const rvec xold, const rvec f, const rvec step)
     xnew[ZZ] = zo+dz;
 }
 
-static void directional_sd(const PaddedRVecVector *xold, PaddedRVecVector *xnew, const rvec acc_dir[],
-                           int homenr, real step)
+static void directional_sd(gmx::ArrayRef<const gmx::RVec> xold,
+                           gmx::ArrayRef<gmx::RVec> xnew,
+                           const rvec acc_dir[], int homenr, real step)
 {
-    const rvec *xo = as_rvec_array(xold->data());
-    rvec       *xn = as_rvec_array(xnew->data());
+    const rvec *xo = as_rvec_array(xold.data());
+    rvec       *xn = as_rvec_array(xnew.data());
 
     for (int i = 0; i < homenr; i++)
     {
@@ -707,9 +709,9 @@ static void directional_sd(const PaddedRVecVector *xold, PaddedRVecVector *xnew,
     }
 }
 
-static void shell_pos_sd(const PaddedRVecVector * gmx_restrict xcur,
-                         PaddedRVecVector * gmx_restrict xnew,
-                         const PaddedRVecVector *f,
+static void shell_pos_sd(gmx::ArrayRef<const gmx::RVec> xcur,
+                         gmx::ArrayRef<gmx::RVec> xnew,
+                         gmx::ArrayRef<const gmx::RVec> f,
                          int ns, t_shell s[], int count)
 {
     const real step_scale_min       = 0.8,
@@ -743,8 +745,8 @@ static void shell_pos_sd(const PaddedRVecVector * gmx_restrict xcur,
         {
             for (d = 0; d < DIM; d++)
             {
-                dx = (*xcur)[shell][d] - s[i].xold[d];
-                df =    (*f)[shell][d] - s[i].fold[d];
+                dx = xcur[shell][d] - s[i].xold[d];
+                df =    f[shell][d] - s[i].fold[d];
                 /* -dx/df gets used to generate an interpolated value, but would
                  * cause a NaN if df were binary-equal to zero. Values close to
                  * zero won't cause problems (because of the min() and max()), so
@@ -778,18 +780,18 @@ static void shell_pos_sd(const PaddedRVecVector * gmx_restrict xcur,
 #endif
             }
         }
-        copy_rvec((*xcur)[shell], s[i].xold);
-        copy_rvec((*f)[shell],   s[i].fold);
+        copy_rvec(xcur [shell], s[i].xold);
+        copy_rvec(f[shell],   s[i].fold);
 
-        do_1pos3((*xnew)[shell], (*xcur)[shell], (*f)[shell], s[i].step);
+        do_1pos3(xnew[shell], xcur[shell], f[shell], s[i].step);
 
         if (gmx_debug_at)
         {
             fprintf(debug, "shell[%d] = %d\n", i, shell);
-            pr_rvec(debug, 0, "fshell", (*f)[shell], DIM, TRUE);
-            pr_rvec(debug, 0, "xold", (*xcur)[shell], DIM, TRUE);
+            pr_rvec(debug, 0, "fshell", f[shell], DIM, TRUE);
+            pr_rvec(debug, 0, "xold", xcur[shell], DIM, TRUE);
             pr_rvec(debug, 0, "step", s[i].step, DIM, TRUE);
-            pr_rvec(debug, 0, "xnew", (*xnew)[shell], DIM, TRUE);
+            pr_rvec(debug, 0, "xnew", xnew[shell], DIM, TRUE);
         }
     }
 #ifdef PRINT_STEP
@@ -825,11 +827,11 @@ static void print_epot(FILE *fp, gmx_int64_t mdstep, int count, real epot, real
 }
 
 
-static real rms_force(t_commrec *cr, const PaddedRVecVector *force, int ns, t_shell s[],
+static real rms_force(t_commrec *cr, gmx::ArrayRef<const gmx::RVec> force, int ns, t_shell s[],
                       int ndir, real *sf_dir, real *Epot)
 {
     double      buf[4];
-    const rvec *f = as_rvec_array(force->data());
+    const rvec *f = as_rvec_array(force.data());
 
     buf[0] = *sf_dir;
     for (int i = 0; i < ns; i++)
@@ -854,7 +856,7 @@ static real rms_force(t_commrec *cr, const PaddedRVecVector *force, int ns, t_sh
     return (ntot ? std::sqrt(buf[0]/ntot) : 0);
 }
 
-static void check_pbc(FILE *fp, PaddedRVecVector x, int shell)
+static void check_pbc(FILE *fp, gmx::ArrayRef<gmx::RVec> x, int shell)
 {
     int m, now;
 
@@ -869,7 +871,7 @@ static void check_pbc(FILE *fp, PaddedRVecVector x, int shell)
     }
 }
 
-static void dump_shells(FILE *fp, PaddedRVecVector x, PaddedRVecVector f, real ftol, int ns, t_shell s[])
+static void dump_shells(FILE *fp, gmx::ArrayRef<gmx::RVec> x, gmx::ArrayRef<gmx::RVec> f, real ftol, int ns, t_shell s[])
 {
     int  i, shell;
     real ft2, ff2;
@@ -1035,13 +1037,13 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         shfc->f[i].resize(gmx::paddedRVecVectorSize(nat));
     }
 
-    /* Create pointer that we can swap */
-    PaddedRVecVector *pos[2];
-    PaddedRVecVector *force[2];
+    /* Create views that we can swap */
+    gmx::PaddedArrayRef<gmx::RVec> pos[2];
+    gmx::PaddedArrayRef<gmx::RVec> force[2];
     for (i = 0; (i < 2); i++)
     {
-        pos[i]   = &shfc->x[i];
-        force[i] = &shfc->f[i];
+        pos[i]   = shfc->x[i];
+        force[i] = shfc->f[i];
     }
 
     if (bDoNS && inputrec->ePBC != epbcNONE && !DOMAINDECOMP(cr))
@@ -1052,7 +1054,8 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
          */
         if (inputrec->cutoff_scheme == ecutsVERLET)
         {
-            put_atoms_in_box_omp(fr->ePBC, state->box, md->homenr, as_rvec_array(state->x.data()));
+            auto xRef = makeArrayRef(state->x);
+            put_atoms_in_box_omp(fr->ePBC, state->box, xRef.subArray(0, md->homenr));
         }
         else
         {
@@ -1115,7 +1118,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         pr_rvecs(debug, 0, "x b4 do_force", as_rvec_array(state->x.data()), homenr);
     }
     do_force(fplog, cr, inputrec, mdstep, nrnb, wcycle, top, groups,
-             state->box, &state->x, &state->hist,
+             state->box, state->x, &state->hist,
              force[Min], force_vir, md, enerd, fcd,
              state->lambda, graph,
              fr, vsite, mu_tot, t, nullptr, bBornRadii,
@@ -1127,7 +1130,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     {
         init_adir(fplog, shfc,
                   constr, idef, inputrec, cr, dd_ac1, mdstep, md, end,
-                  shfc->x_old, as_rvec_array(state->x.data()), as_rvec_array(state->x.data()), as_rvec_array(force[Min]->data()),
+                  shfc->x_old, as_rvec_array(state->x.data()), as_rvec_array(state->x.data()), as_rvec_array(force[Min].data()),
                   shfc->acc_dir,
                   fr->bMolPBC, state->box, state->lambda, &dum, nrnb);
 
@@ -1139,7 +1142,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
 
     Epot[Min] = enerd->term[F_EPOT];
 
-    df[Min] = rms_force(cr, &shfc->f[Min], nshell, shell, nflexcon, &sf_dir, &Epot[Min]);
+    df[Min] = rms_force(cr, shfc->f[Min], nshell, shell, nflexcon, &sf_dir, &Epot[Min]);
     df[Try] = 0;
     if (debug)
     {
@@ -1148,7 +1151,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
 
     if (gmx_debug_at)
     {
-        pr_rvecs(debug, 0, "force0", as_rvec_array(force[Min]->data()), md->nr);
+        pr_rvecs(debug, 0, "force0", as_rvec_array(force[Min].data()), md->nr);
     }
 
     if (nshell+nflexcon > 0)
@@ -1157,8 +1160,8 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
          * shell positions are updated, therefore the other particles must
          * be set here.
          */
-        *pos[Min] = state->x;
-        *pos[Try] = state->x;
+        pos[Min] = state->x;
+        pos[Try] = state->x;
     }
 
     if (bVerbose && MASTER(cr))
@@ -1186,7 +1189,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     {
         if (vsite)
         {
-            construct_vsites(vsite, as_rvec_array(pos[Min]->data()),
+            construct_vsites(vsite, as_rvec_array(pos[Min].data()),
                              inputrec->delta_t, as_rvec_array(state->v.data()),
                              idef->iparams, idef->il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
@@ -1196,7 +1199,7 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         {
             init_adir(fplog, shfc,
                       constr, idef, inputrec, cr, dd_ac1, mdstep, md, end,
-                      x_old, as_rvec_array(state->x.data()), as_rvec_array(pos[Min]->data()), as_rvec_array(force[Min]->data()), acc_dir,
+                      x_old, as_rvec_array(state->x.data()), as_rvec_array(pos[Min].data()), as_rvec_array(force[Min].data()), acc_dir,
                       fr->bMolPBC, state->box, state->lambda, &dum, nrnb);
 
             directional_sd(pos[Min], pos[Try], acc_dir, end, fr->fc_stepsize);
@@ -1208,13 +1211,13 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         /* do_force expected the charge groups to be in the box */
         if (graph)
         {
-            unshift_self(graph, state->box, as_rvec_array(pos[Try]->data()));
+            unshift_self(graph, state->box, as_rvec_array(pos[Try].data()));
         }
 
         if (gmx_debug_at)
         {
-            pr_rvecs(debug, 0, "RELAX: pos[Min]  ", as_rvec_array(pos[Min]->data()), homenr);
-            pr_rvecs(debug, 0, "RELAX: pos[Try]  ", as_rvec_array(pos[Try]->data()), homenr);
+            pr_rvecs(debug, 0, "RELAX: pos[Min]  ", as_rvec_array(pos[Min].data()), homenr);
+            pr_rvecs(debug, 0, "RELAX: pos[Try]  ", as_rvec_array(pos[Try].data()), homenr);
         }
         /* Try the new positions */
         do_force(fplog, cr, inputrec, 1, nrnb, wcycle,
@@ -1227,15 +1230,15 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
 
         if (gmx_debug_at)
         {
-            pr_rvecs(debug, 0, "RELAX: force[Min]", as_rvec_array(force[Min]->data()), homenr);
-            pr_rvecs(debug, 0, "RELAX: force[Try]", as_rvec_array(force[Try]->data()), homenr);
+            pr_rvecs(debug, 0, "RELAX: force[Min]", as_rvec_array(force[Min].data()), homenr);
+            pr_rvecs(debug, 0, "RELAX: force[Try]", as_rvec_array(force[Try].data()), homenr);
         }
         sf_dir = 0;
         if (nflexcon)
         {
             init_adir(fplog, shfc,
                       constr, idef, inputrec, cr, dd_ac1, mdstep, md, end,
-                      x_old, as_rvec_array(state->x.data()), as_rvec_array(pos[Try]->data()), as_rvec_array(force[Try]->data()), acc_dir,
+                      x_old, as_rvec_array(state->x.data()), as_rvec_array(pos[Try].data()), as_rvec_array(force[Try].data()), acc_dir,
                       fr->bMolPBC, state->box, state->lambda, &dum, nrnb);
 
             for (i = 0; i < end; i++)
@@ -1257,12 +1260,12 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
         {
             if (gmx_debug_at)
             {
-                pr_rvecs(debug, 0, "F na do_force", as_rvec_array(force[Try]->data()), homenr);
+                pr_rvecs(debug, 0, "F na do_force", as_rvec_array(force[Try].data()), homenr);
             }
             if (gmx_debug_at)
             {
                 fprintf(debug, "SHELL ITER %d\n", count);
-                dump_shells(debug, *pos[Try], *force[Try], ftol, nshell, shell);
+                dump_shells(debug, pos[Try], force[Try], ftol, nshell, shell);
             }
         }
 
@@ -1318,8 +1321,8 @@ void relax_shell_flexcon(FILE *fplog, t_commrec *cr, gmx_bool bVerbose,
     }
 
     /* Copy back the coordinates and the forces */
-    state->x = *pos[Min];
-    *f       = *force[Min];
+    std::copy(pos[Min].begin(), pos[Min].end(), state->x.begin());
+    std::copy(force[Min].begin(), force[Min].end(), f->begin());
 }
 
 void done_shellfc(FILE *fplog, gmx_shellfc_t *shfc, gmx_int64_t numSteps)
index 5f240212dfe5b1cc3b4b619b514bbb03245c8394..0663126424e7e7d2fa5ce997e26348a32078e523 100644 (file)
@@ -855,8 +855,8 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
                                 gmx_int64_t step, t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                                 gmx_localtop_t *top,
                                 gmx_groups_t gmx_unused *groups,
-                                matrix box, rvec x[], history_t *hist,
-                                PaddedRVecVector *force,
+                                matrix box, gmx::PaddedArrayRef<gmx::RVec> x, history_t *hist,
+                                gmx::PaddedArrayRef<gmx::RVec> force,
                                 tensor vir_force,
                                 t_mdatoms *mdatoms,
                                 gmx_enerdata_t *enerd, t_fcdata *fcd,
@@ -947,12 +947,12 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
 
         if (bCalcCGCM)
         {
-            put_atoms_in_box_omp(fr->ePBC, box, homenr, x);
+            put_atoms_in_box_omp(fr->ePBC, box, x.subArray(0, homenr));
             inc_nrnb(nrnb, eNR_SHIFTX, homenr);
         }
         else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph)
         {
-            unshift_self(graph, box, x);
+            unshift_self(graph, box, as_rvec_array(x.data()));
         }
     }
 
@@ -968,7 +968,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
          * we do not need to worry about shifting.
          */
         wallcycle_start(wcycle, ewcPP_PMESENDX);
-        gmx_pme_send_coordinates(cr, box, x,
+        gmx_pme_send_coordinates(cr, box, as_rvec_array(x.data()),
                                  lambda[efptCOUL], lambda[efptVDW],
                                  (flags & (GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY)),
                                  step);
@@ -978,7 +978,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
 
     if (useGpuPme)
     {
-        launchPmeGpuSpread(fr->pmedata, box, x, flags, wcycle);
+        launchPmeGpuSpread(fr->pmedata, box, as_rvec_array(x.data()), flags, wcycle);
     }
 
     /* do gridding for pair search */
@@ -987,7 +987,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         if (graph && bStateChanged)
         {
             /* Calculate intramolecular shift vectors to make molecules whole */
-            mk_mshift(fplog, graph, fr->ePBC, box, x);
+            mk_mshift(fplog, graph, fr->ePBC, box, as_rvec_array(x.data()));
         }
 
         clear_rvec(vzero);
@@ -1001,7 +1001,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
             wallcycle_sub_start(wcycle, ewcsNBS_GRID_LOCAL);
             nbnxn_put_on_grid(nbv->nbs, fr->ePBC, box,
                               0, vzero, box_diag,
-                              0, mdatoms->homenr, -1, fr->cginfo, x,
+                              0, mdatoms->homenr, -1, fr->cginfo, as_rvec_array(x.data()),
                               0, nullptr,
                               nbv->grp[eintLocal].kernel_type,
                               nbv->nbat);
@@ -1011,7 +1011,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         {
             wallcycle_sub_start(wcycle, ewcsNBS_GRID_NONLOCAL);
             nbnxn_put_on_grid_nonlocal(nbv->nbs, domdec_zones(cr->dd),
-                                       fr->cginfo, x,
+                                       fr->cginfo, as_rvec_array(x.data()),
                                        nbv->grp[eintNonlocal].kernel_type,
                                        nbv->nbat);
             wallcycle_sub_stop(wcycle, ewcsNBS_GRID_NONLOCAL);
@@ -1071,7 +1071,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     {
         wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
         wallcycle_sub_start(wcycle, ewcsNB_X_BUF_OPS);
-        nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs, eatLocal, FALSE, x,
+        nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs, eatLocal, FALSE, as_rvec_array(x.data()),
                                         nbv->nbat);
         wallcycle_sub_stop(wcycle, ewcsNB_X_BUF_OPS);
         wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
@@ -1147,12 +1147,12 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         else
         {
             wallcycle_start(wcycle, ewcMOVEX);
-            dd_move_x(cr->dd, box, x);
+            dd_move_x(cr->dd, box, as_rvec_array(x.data()));
             wallcycle_stop(wcycle, ewcMOVEX);
 
             wallcycle_start(wcycle, ewcNB_XF_BUF_OPS);
             wallcycle_sub_start(wcycle, ewcsNB_X_BUF_OPS);
-            nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs, eatNonlocal, FALSE, x,
+            nbnxn_atomdata_copy_x_to_nbat_x(nbv->nbs, eatNonlocal, FALSE, as_rvec_array(x.data()),
                                             nbv->nbat);
             wallcycle_sub_stop(wcycle, ewcsNB_X_BUF_OPS);
             wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS);
@@ -1229,19 +1229,19 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     if (inputrec->bRot)
     {
         wallcycle_start(wcycle, ewcROT);
-        do_rotation(cr, inputrec, box, x, t, step, bNS);
+        do_rotation(cr, inputrec, box, as_rvec_array(x.data()), t, step, bNS);
         wallcycle_stop(wcycle, ewcROT);
     }
 
     /* Temporary solution until all routines take PaddedRVecVector */
-    rvec *f = as_rvec_array(force->data());
+    rvec *f = as_rvec_array(force.data());
 
     /* Start the force cycle counter.
      * Note that a different counter is used for dynamic load balancing.
      */
     wallcycle_start(wcycle, ewcFORCE);
 
-    gmx::ArrayRef<gmx::RVec> forceRef = *force;
+    gmx::ArrayRef<gmx::RVec> forceRef = force;
     if (bDoForces)
     {
         /* If we need to compute the virial, we might need a separate
@@ -1292,7 +1292,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         if (fr->nbv->grp[eintLocal].nbl_lists.nbl_fep[0]->nrj > 0)
         {
             do_nb_verlet_fep(&fr->nbv->grp[eintLocal].nbl_lists,
-                             fr, x, f, mdatoms,
+                             fr, as_rvec_array(x.data()), f, mdatoms,
                              inputrec->fepvals, lambda,
                              enerd, flags, nrnb, wcycle);
         }
@@ -1301,7 +1301,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
             fr->nbv->grp[eintNonlocal].nbl_lists.nbl_fep[0]->nrj > 0)
         {
             do_nb_verlet_fep(&fr->nbv->grp[eintNonlocal].nbl_lists,
-                             fr, x, f, mdatoms,
+                             fr, as_rvec_array(x.data()), f, mdatoms,
                              inputrec->fepvals, lambda,
                              enerd, flags, nrnb, wcycle);
         }
@@ -1352,13 +1352,13 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     /* update QMMMrec, if necessary */
     if (fr->bQMMM)
     {
-        update_QMMMrec(cr, fr, x, mdatoms, box);
+        update_QMMMrec(cr, fr, as_rvec_array(x.data()), mdatoms, box);
     }
 
     /* Compute the bonded and non-bonded energies and optionally forces */
     do_force_lowlevel(fr, inputrec, &(top->idef),
                       cr, nrnb, wcycle, mdatoms,
-                      x, hist, f, &forceWithVirial, enerd, fcd, top, fr->born,
+                      as_rvec_array(x.data()), hist, f, &forceWithVirial, enerd, fcd, top, fr->born,
                       bBornRadii, box,
                       inputrec->fepvals, lambda, graph, &(top->excls), fr->mu_tot,
                       flags, &cycles_pme);
@@ -1366,7 +1366,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     wallcycle_stop(wcycle, ewcFORCE);
 
     computeSpecialForces(fplog, cr, inputrec, step, t, wcycle,
-                         fr->forceProviders, box, x, mdatoms, lambda,
+                         fr->forceProviders, box, as_rvec_array(x.data()), mdatoms, lambda,
                          flags, &forceWithVirial, enerd,
                          ed, bNS);
 
@@ -1526,7 +1526,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         if (vsite && !(fr->haveDirectVirialContributions && !(flags & GMX_FORCE_VIRIAL)))
         {
             wallcycle_start(wcycle, ewcVSITESPREAD);
-            spread_vsite_f(vsite, x, f, fr->fshift, FALSE, nullptr, nrnb,
+            spread_vsite_f(vsite, as_rvec_array(x.data()), f, fr->fshift, FALSE, nullptr, nrnb,
                            &top->idef, fr->ePBC, fr->bMolPBC, graph, box, cr);
             wallcycle_stop(wcycle, ewcVSITESPREAD);
         }
@@ -1534,7 +1534,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
         if (flags & GMX_FORCE_VIRIAL)
         {
             /* Calculation of the virial must be done after vsites! */
-            calc_virial(0, mdatoms->homenr, x, f,
+            calc_virial(0, mdatoms->homenr, as_rvec_array(x.data()), f,
                         vir_force, graph, box, nrnb, fr, inputrec->ePBC);
         }
     }
@@ -1550,7 +1550,7 @@ static void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     if (bDoForces)
     {
         post_process_forces(cr, step, nrnb, wcycle,
-                            top, box, x, f, &forceWithVirial,
+                            top, box, as_rvec_array(x.data()), f, &forceWithVirial,
                             vir_force, mdatoms, graph, fr, vsite,
                             flags);
     }
@@ -1572,8 +1572,8 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
                                gmx_int64_t step, t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                                gmx_localtop_t *top,
                                gmx_groups_t *groups,
-                               matrix box, rvec x[], history_t *hist,
-                               PaddedRVecVector *force,
+                               matrix box, gmx::PaddedArrayRef<gmx::RVec> x, history_t *hist,
+                               gmx::PaddedArrayRef<gmx::RVec> force,
                                tensor vir_force,
                                t_mdatoms *mdatoms,
                                gmx_enerdata_t *enerd, t_fcdata *fcd,
@@ -1645,18 +1645,18 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
         if (bCalcCGCM)
         {
             put_charge_groups_in_box(fplog, cg0, cg1, fr->ePBC, box,
-                                     &(top->cgs), x, fr->cg_cm);
+                                     &(top->cgs), as_rvec_array(x.data()), fr->cg_cm);
             inc_nrnb(nrnb, eNR_CGCM, homenr);
             inc_nrnb(nrnb, eNR_RESETX, cg1-cg0);
         }
         else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph)
         {
-            unshift_self(graph, box, x);
+            unshift_self(graph, box, as_rvec_array(x.data()));
         }
     }
     else if (bCalcCGCM)
     {
-        calc_cgcm(fplog, cg0, cg1, &(top->cgs), x, fr->cg_cm);
+        calc_cgcm(fplog, cg0, cg1, &(top->cgs), as_rvec_array(x.data()), fr->cg_cm);
         inc_nrnb(nrnb, eNR_CGCM, homenr);
     }
 
@@ -1674,7 +1674,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
          * we do not need to worry about shifting.
          */
         wallcycle_start(wcycle, ewcPP_PMESENDX);
-        gmx_pme_send_coordinates(cr, box, x,
+        gmx_pme_send_coordinates(cr, box, as_rvec_array(x.data()),
                                  lambda[efptCOUL], lambda[efptVDW],
                                  (flags & (GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY)),
                                  step);
@@ -1686,7 +1686,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     if (DOMAINDECOMP(cr))
     {
         wallcycle_start(wcycle, ewcMOVEX);
-        dd_move_x(cr->dd, box, x);
+        dd_move_x(cr->dd, box, as_rvec_array(x.data()));
         wallcycle_stop(wcycle, ewcMOVEX);
         /* No GPU support, no move_x overlap, so reopen the balance region here */
         if (ddOpenBalanceRegion == DdOpenBalanceRegionBeforeForceComputation::yes)
@@ -1737,7 +1737,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
         if (graph && bStateChanged)
         {
             /* Calculate intramolecular shift vectors to make molecules whole */
-            mk_mshift(fplog, graph, fr->ePBC, box, x);
+            mk_mshift(fplog, graph, fr->ePBC, box, as_rvec_array(x.data()));
         }
 
         /* Do the actual neighbour searching */
@@ -1751,7 +1751,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     if (inputrec->implicit_solvent && bNS)
     {
         make_gb_nblist(cr, inputrec->gb_algorithm,
-                       x, box, fr, &top->idef, graph, fr->born);
+                       as_rvec_array(x.data()), box, fr, &top->idef, graph, fr->born);
     }
 
     if (DOMAINDECOMP(cr) && !thisRankHasDuty(cr, DUTY_PME))
@@ -1763,19 +1763,19 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     if (inputrec->bRot)
     {
         wallcycle_start(wcycle, ewcROT);
-        do_rotation(cr, inputrec, box, x, t, step, bNS);
+        do_rotation(cr, inputrec, box, as_rvec_array(x.data()), t, step, bNS);
         wallcycle_stop(wcycle, ewcROT);
     }
 
     /* Temporary solution until all routines take PaddedRVecVector */
-    rvec *f = as_rvec_array(force->data());
+    rvec *f = as_rvec_array(force.data());
 
     /* Start the force cycle counter.
      * Note that a different counter is used for dynamic load balancing.
      */
     wallcycle_start(wcycle, ewcFORCE);
 
-    gmx::ArrayRef<gmx::RVec> forceRef = *force;
+    gmx::ArrayRef<gmx::RVec> forceRef = force;
     if (bDoForces)
     {
         /* If we need to compute the virial, we might need a separate
@@ -1804,13 +1804,13 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     /* update QMMMrec, if necessary */
     if (fr->bQMMM)
     {
-        update_QMMMrec(cr, fr, x, mdatoms, box);
+        update_QMMMrec(cr, fr, as_rvec_array(x.data()), mdatoms, box);
     }
 
     /* Compute the bonded and non-bonded energies and optionally forces */
     do_force_lowlevel(fr, inputrec, &(top->idef),
                       cr, nrnb, wcycle, mdatoms,
-                      x, hist, f, &forceWithVirial, enerd, fcd, top, fr->born,
+                      as_rvec_array(x.data()), hist, f, &forceWithVirial, enerd, fcd, top, fr->born,
                       bBornRadii, box,
                       inputrec->fepvals, lambda,
                       graph, &(top->excls), fr->mu_tot,
@@ -1830,7 +1830,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     }
 
     computeSpecialForces(fplog, cr, inputrec, step, t, wcycle,
-                         fr->forceProviders, box, x, mdatoms, lambda,
+                         fr->forceProviders, box, as_rvec_array(x.data()), mdatoms, lambda,
                          flags, &forceWithVirial, enerd,
                          ed, bNS);
 
@@ -1862,7 +1862,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
         if (vsite && !(fr->haveDirectVirialContributions && !(flags & GMX_FORCE_VIRIAL)))
         {
             wallcycle_start(wcycle, ewcVSITESPREAD);
-            spread_vsite_f(vsite, x, f, fr->fshift, FALSE, nullptr, nrnb,
+            spread_vsite_f(vsite, as_rvec_array(x.data()), f, fr->fshift, FALSE, nullptr, nrnb,
                            &top->idef, fr->ePBC, fr->bMolPBC, graph, box, cr);
             wallcycle_stop(wcycle, ewcVSITESPREAD);
         }
@@ -1870,7 +1870,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
         if (flags & GMX_FORCE_VIRIAL)
         {
             /* Calculation of the virial must be done after vsites! */
-            calc_virial(0, mdatoms->homenr, x, f,
+            calc_virial(0, mdatoms->homenr, as_rvec_array(x.data()), f,
                         vir_force, graph, box, nrnb, fr, inputrec->ePBC);
         }
     }
@@ -1886,7 +1886,7 @@ static void do_force_cutsGROUP(FILE *fplog, t_commrec *cr,
     if (bDoForces)
     {
         post_process_forces(cr, step, nrnb, wcycle,
-                            top, box, x, f, &forceWithVirial,
+                            top, box, as_rvec_array(x.data()), f, &forceWithVirial,
                             vir_force, mdatoms, graph, fr, vsite,
                             flags);
     }
@@ -1909,8 +1909,8 @@ void do_force(FILE *fplog, t_commrec *cr,
               gmx_int64_t step, t_nrnb *nrnb, gmx_wallcycle_t wcycle,
               gmx_localtop_t *top,
               gmx_groups_t *groups,
-              matrix box, PaddedRVecVector *coordinates, history_t *hist,
-              PaddedRVecVector *force,
+              matrix box, gmx::PaddedArrayRef<gmx::RVec> x, history_t *hist,
+              gmx::PaddedArrayRef<gmx::RVec> force,
               tensor vir_force,
               t_mdatoms *mdatoms,
               gmx_enerdata_t *enerd, t_fcdata *fcd,
@@ -1929,10 +1929,8 @@ void do_force(FILE *fplog, t_commrec *cr,
         flags &= ~GMX_FORCE_NONBONDED;
     }
 
-    GMX_ASSERT(coordinates->size() >= gmx::paddedRVecVectorSize(fr->natoms_force), "coordinates should be padded");
-    GMX_ASSERT(force->size()       >= gmx::paddedRVecVectorSize(fr->natoms_force), "force should be padded");
-
-    rvec *x = as_rvec_array(coordinates->data());
+    GMX_ASSERT(x.size()     >= gmx::paddedRVecVectorSize(fr->natoms_force), "coordinates should be padded");
+    GMX_ASSERT(force.size() >= gmx::paddedRVecVectorSize(fr->natoms_force), "force should be padded");
 
     switch (inputrec->cutoff_scheme)
     {
@@ -2501,7 +2499,7 @@ void do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
     low_do_pbc_mtop(fplog, ePBC, box, mtop, x, FALSE);
 }
 
-void put_atoms_in_box_omp(int ePBC, const matrix box, int natoms, rvec x[])
+void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x)
 {
     int t, nth;
     nth = gmx_omp_nthreads_get(emntDefault);
@@ -2511,11 +2509,10 @@ void put_atoms_in_box_omp(int ePBC, const matrix box, int natoms, rvec x[])
     {
         try
         {
-            int offset, len;
-
-            offset = (natoms*t    )/nth;
-            len    = (natoms*(t + 1))/nth - offset;
-            put_atoms_in_box(ePBC, box, len, x + offset);
+            size_t natoms = x.size();
+            size_t offset = (natoms*t    )/nth;
+            size_t len    = (natoms*(t + 1))/nth - offset;
+            put_atoms_in_box(ePBC, box, x.subArray(offset, len));
         }
         GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
     }
index 310e9859b5ab714e5893d3c59534a9f7a8f77528..92ba77015f6f156276b814d98dc99b4c38895c8d 100644 (file)
@@ -75,10 +75,9 @@ void do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
  * in tools.
  * \param[in]    ePBC   The pbc type
  * \param[in]    box    The simulation box
- * \param[in]    natoms The number of atoms
  * \param[inout] x      The coordinates of the atoms
  */
-void put_atoms_in_box_omp(int ePBC, const matrix box, int natoms, rvec x[]);
+void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x);
 
 
 
index 5ea806f6613cd9fffec6405f66d6ef70795ddc72..6588f1522d5ab6694e85b5a7680982b0663feb44 100644 (file)
@@ -661,8 +661,8 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
             cr->nnodes = 1;
             do_force(fplog, cr, inputrec,
                      step, nrnb, wcycle, top, &top_global->groups,
-                     state_global->box, &state_global->x, &state_global->hist,
-                     &f, force_vir, mdatoms, enerd, fcd,
+                     state_global->box, state_global->x, &state_global->hist,
+                     f, force_vir, mdatoms, enerd, fcd,
                      state_global->lambda,
                      nullptr, fr, nullptr, mu_tot, t, nullptr, FALSE,
                      GMX_FORCE_NONBONDED | GMX_FORCE_ENERGY |
index af0bc7785de4bd5acc973bec604e5da04ed14497..9937ef24ad9f7be709eaffae9691745aca712aa0 100644 (file)
 #include "gromacs/utility/smalloc.h"
 
 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,
-                         ObservablesHistory *observablesHistory,
-                         gmx_mtop_t         *top_global,
-                         t_forcerec         *fr,
-                         gmx_mdoutf_t        outf,
-                         t_mdebin           *mdebin,
-                         gmx_ekindata_t     *ekind,
-                         PaddedRVecVector   *f,
-                         int                *nchkpt,
-                         gmx_bool            bCPT,
-                         gmx_bool            bRerunMD,
-                         gmx_bool            bLastStep,
-                         gmx_bool            bDoConfOut,
-                         gmx_bool            bSumEkinhOld
+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,
+                         ObservablesHistory      *observablesHistory,
+                         gmx_mtop_t              *top_global,
+                         t_forcerec              *fr,
+                         gmx_mdoutf_t             outf,
+                         t_mdebin                *mdebin,
+                         gmx_ekindata_t          *ekind,
+                         gmx::ArrayRef<gmx::RVec> f,
+                         int                     *nchkpt,
+                         gmx_bool                 bCPT,
+                         gmx_bool                 bRerunMD,
+                         gmx_bool                 bLastStep,
+                         gmx_bool                 bDoConfOut,
+                         gmx_bool                 bSumEkinhOld
                          )
 {
     int   mdof_flags;
index b2063334b4afed05c7e13031b0b803f58b845066..d925ffa79f5a9916ba2e50bb2262c5b19be27b8d 100644 (file)
@@ -74,7 +74,7 @@ do_md_trajectory_writing(FILE                     *fplog,
                          gmx_mdoutf_t              outf,
                          t_mdebin                 *mdebin,
                          struct gmx_ekindata_t    *ekind,
-                         PaddedRVecVector         *f,
+                         gmx::ArrayRef<gmx::RVec>  f,
                          int                      *nchkpt,
                          gmx_bool                  bCPT,
                          gmx_bool                  bRerunMD,
index 1428bea312e6e35b552fbeb095897c5f0245d573..41a24e62f841969873b3d423b2974de0a5968162 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/listed-forces/orires.h"
 #include "gromacs/math/functions.h"
 #include "gromacs/math/invertmatrix.h"
+#include "gromacs/math/paddedvector.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/vecdump.h"
@@ -1048,10 +1049,10 @@ static void do_update_bd(int start, int nrend, real dt,
 
 static void dump_it_all(FILE gmx_unused *fp, const char gmx_unused *title,
                         int gmx_unused natoms,
-                        const gmx_unused PaddedRVecVector *x,
-                        const gmx_unused PaddedRVecVector *xp,
-                        const gmx_unused PaddedRVecVector *v,
-                        const gmx_unused PaddedRVecVector *f)
+                        gmx::PaddedArrayRef<gmx::RVec> gmx_unused x,
+                        gmx::PaddedArrayRef<gmx::RVec> gmx_unused xp,
+                        gmx::PaddedArrayRef<gmx::RVec> gmx_unused v,
+                        gmx::PaddedArrayRef<gmx::RVec> gmx_unused f)
 {
 #ifdef DEBUG
     if (fp)
@@ -1512,24 +1513,24 @@ void update_pcouple_before_coordinates(FILE             *fplog,
     }
 }
 
-void update_constraints(FILE             *fplog,
-                        gmx_int64_t       step,
-                        real             *dvdlambda, /* the contribution to be added to the bonded interactions */
-                        t_inputrec       *inputrec,  /* input record and box stuff     */
-                        t_mdatoms        *md,
-                        t_state          *state,
-                        gmx_bool          bMolPBC,
-                        t_graph          *graph,
-                        PaddedRVecVector *force,     /* forces on home particles */
-                        t_idef           *idef,
-                        tensor            vir_part,
-                        t_commrec        *cr,
-                        t_nrnb           *nrnb,
-                        gmx_wallcycle_t   wcycle,
-                        gmx_update_t     *upd,
-                        gmx_constr_t      constr,
-                        gmx_bool          bFirstHalf,
-                        gmx_bool          bCalcVir)
+void update_constraints(FILE                          *fplog,
+                        gmx_int64_t                    step,
+                        real                          *dvdlambda, /* the contribution to be added to the bonded interactions */
+                        t_inputrec                    *inputrec,  /* input record and box stuff        */
+                        t_mdatoms                     *md,
+                        t_state                       *state,
+                        gmx_bool                       bMolPBC,
+                        t_graph                       *graph,
+                        gmx::PaddedArrayRef<gmx::RVec> force,     /* forces on home particles */
+                        t_idef                        *idef,
+                        tensor                         vir_part,
+                        t_commrec                     *cr,
+                        t_nrnb                        *nrnb,
+                        gmx_wallcycle_t                wcycle,
+                        gmx_update_t                  *upd,
+                        gmx_constr_t                   constr,
+                        gmx_bool                       bFirstHalf,
+                        gmx_bool                       bCalcVir)
 {
     gmx_bool             bLastStep, bLog = FALSE, bEner = FALSE, bDoConstr = FALSE;
     tensor               vir_con;
@@ -1602,7 +1603,7 @@ void update_constraints(FILE             *fplog,
         where();
 
         dump_it_all(fplog, "After Shake",
-                    state->natoms, &state->x, &upd->xp, &state->v, force);
+                    state->natoms, state->x, upd->xp, state->v, force);
 
         if (bCalcVir)
         {
@@ -1636,7 +1637,7 @@ void update_constraints(FILE             *fplog,
                               inputrec->opts.acc, inputrec->opts.nFreeze,
                               md->invmass, md->ptype,
                               md->cFREEZE, md->cACC, md->cTC,
-                              as_rvec_array(state->x.data()), as_rvec_array(upd->xp.data()), as_rvec_array(state->v.data()), as_rvec_array(force->data()),
+                              as_rvec_array(state->x.data()), as_rvec_array(upd->xp.data()), as_rvec_array(state->v.data()), as_rvec_array(force.data()),
                               bDoConstr, FALSE,
                               step, inputrec->ld_seed,
                               DOMAINDECOMP(cr) ? cr->dd->gatindex : nullptr);
@@ -1740,7 +1741,7 @@ void update_constraints(FILE             *fplog,
         wallcycle_stop(wcycle, ewcUPDATE);
 
         dump_it_all(fplog, "After unshift",
-                    state->natoms, &state->x, &upd->xp, &state->v, force);
+                    state->natoms, state->x, upd->xp, state->v, force);
     }
 /* ############# END the update of velocities and positions ######### */
 }
@@ -1843,22 +1844,22 @@ void update_pcouple_after_coordinates(FILE             *fplog,
     }
     where();
     dump_it_all(fplog, "After update",
-                state->natoms, &state->x, &upd->xp, &state->v, nullptr);
+                state->natoms, state->x, upd->xp, state->v, gmx::EmptyArrayRef());
 }
 
-void update_coords(FILE             *fplog,
-                   gmx_int64_t       step,
-                   t_inputrec       *inputrec,  /* input record and box stuff  */
-                   t_mdatoms        *md,
-                   t_state          *state,
-                   PaddedRVecVector *f,    /* forces on home particles */
-                   t_fcdata         *fcd,
-                   gmx_ekindata_t   *ekind,
-                   matrix            M,
-                   gmx_update_t     *upd,
-                   int               UpdatePart,
-                   t_commrec        *cr, /* these shouldn't be here -- need to think about it */
-                   gmx_constr_t      constr)
+void update_coords(FILE                          *fplog,
+                   gmx_int64_t                    step,
+                   t_inputrec                    *inputrec, /* input record and box stuff      */
+                   t_mdatoms                     *md,
+                   t_state                       *state,
+                   gmx::PaddedArrayRef<gmx::RVec> f,        /* forces on home particles */
+                   t_fcdata                      *fcd,
+                   gmx_ekindata_t                *ekind,
+                   matrix                         M,
+                   gmx_update_t                  *upd,
+                   int                            UpdatePart,
+                   t_commrec                     *cr, /* these shouldn't be here -- need to think about it */
+                   gmx_constr_t                   constr)
 {
     gmx_bool bDoConstr = (nullptr != constr);
 
@@ -1887,7 +1888,7 @@ void update_coords(FILE             *fplog,
     /* ############# START The update of velocities and positions ######### */
     where();
     dump_it_all(fplog, "Before update",
-                state->natoms, &state->x, &upd->xp, &state->v, f);
+                state->natoms, state->x, upd->xp, state->v, f);
 
     int nth = gmx_omp_nthreads_get(emntUpdate);
 
@@ -1908,13 +1909,13 @@ void update_coords(FILE             *fplog,
             GMX_ASSERT(state->x.size() >= homenrSimdPadded, "state->x needs to be padded for SIMD access");
             GMX_ASSERT(upd->xp.size()  >= homenrSimdPadded, "upd->xp needs to be padded for SIMD access");
             GMX_ASSERT(state->v.size() >= homenrSimdPadded, "state->v needs to be padded for SIMD access");
-            GMX_ASSERT(f->size()       >= homenrSimdPadded, "f needs to be padded for SIMD access");
+            GMX_ASSERT(f.size()        >= homenrSimdPadded, "f needs to be padded for SIMD access");
 #endif
 
             const rvec *x_rvec  = as_rvec_array(state->x.data());
             rvec       *xp_rvec = as_rvec_array(upd->xp.data());
             rvec       *v_rvec  = as_rvec_array(state->v.data());
-            const rvec *f_rvec  = as_rvec_array(f->data());
+            const rvec *f_rvec  = as_rvec_array(f.data());
 
             switch (inputrec->eI)
             {
index 670502b437a4ee1508866e4268882f4c0187d069..742ec58e823e735f078e7ab2e877fbaf7a0d92ab 100644 (file)
@@ -40,6 +40,7 @@
 #include "gromacs/math/paddedvector.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
@@ -113,42 +114,42 @@ void update_pcouple_after_coordinates(FILE             *fplog,
                                       t_nrnb           *nrnb,
                                       gmx_update_t     *upd);
 
-void update_coords(FILE              *fplog,
-                   gmx_int64_t        step,
-                   t_inputrec        *inputrec, /* input record and box stuff  */
-                   t_mdatoms         *md,
-                   t_state           *state,
-                   PaddedRVecVector  *f, /* forces on home particles */
-                   t_fcdata          *fcd,
-                   gmx_ekindata_t    *ekind,
-                   matrix             M,
-                   gmx_update_t      *upd,
-                   int                bUpdatePart,
-                   t_commrec         *cr, /* these shouldn't be here -- need to think about it */
-                   gmx_constr        *constr);
+void update_coords(FILE                          *fplog,
+                   gmx_int64_t                    step,
+                   t_inputrec                    *inputrec, /* input record and box stuff      */
+                   t_mdatoms                     *md,
+                   t_state                       *state,
+                   gmx::PaddedArrayRef<gmx::RVec> f, /* forces on home particles */
+                   t_fcdata                      *fcd,
+                   gmx_ekindata_t                *ekind,
+                   matrix                         M,
+                   gmx_update_t                  *upd,
+                   int                            bUpdatePart,
+                   t_commrec                     *cr, /* these shouldn't be here -- need to think about it */
+                   gmx_constr                    *constr);
 
 /* Return TRUE if OK, FALSE in case of Shake Error */
 
 extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_int64_t step, const t_commrec *cr, t_mdatoms *md, t_state *state, gmx_update_t *upd, gmx_constr *constr);
 
-void update_constraints(FILE              *fplog,
-                        gmx_int64_t        step,
-                        real              *dvdlambda, /* FEP stuff */
-                        t_inputrec        *inputrec,  /* input record and box stuff    */
-                        t_mdatoms         *md,
-                        t_state           *state,
-                        gmx_bool           bMolPBC,
-                        t_graph           *graph,
-                        PaddedRVecVector  *force, /* forces on home particles */
-                        t_idef            *idef,
-                        tensor             vir_part,
-                        t_commrec         *cr,
-                        t_nrnb            *nrnb,
-                        gmx_wallcycle_t    wcycle,
-                        gmx_update_t      *upd,
-                        gmx_constr        *constr,
-                        gmx_bool           bFirstHalf,
-                        gmx_bool           bCalcVir);
+void update_constraints(FILE                    *fplog,
+                        gmx_int64_t              step,
+                        real                    *dvdlambda, /* FEP stuff */
+                        t_inputrec              *inputrec,  /* input record and box stuff      */
+                        t_mdatoms               *md,
+                        t_state                 *state,
+                        gmx_bool                 bMolPBC,
+                        t_graph                 *graph,
+                        gmx::ArrayRef<gmx::RVec> force, /* forces on home particles */
+                        t_idef                  *idef,
+                        tensor                   vir_part,
+                        t_commrec               *cr,
+                        t_nrnb                  *nrnb,
+                        gmx_wallcycle_t          wcycle,
+                        gmx_update_t            *upd,
+                        gmx_constr              *constr,
+                        gmx_bool                 bFirstHalf,
+                        gmx_bool                 bCalcVir);
 
 /* Return TRUE if OK, FALSE in case of Shake Error */
 
index 11056acbc2065ed7c8afe5e6b9700af09304668b..9ce223671898098cb343d43e80117146063af19b 100644 (file)
@@ -206,16 +206,16 @@ void comp_state(const t_state *st1, const t_state *st2,
     }
 }
 
-rvec *getRvecArrayFromPaddedRVecVector(const PaddedRVecVector *v,
-                                       unsigned int            n)
+rvec *makeRvecArray(gmx::ArrayRef<const gmx::RVec> v,
+                    unsigned int                   n)
 {
-    GMX_ASSERT(v->size() >= n, "We can't copy more elements than the vector size");
+    GMX_ASSERT(v.size() >= n, "We can't copy more elements than the vector size");
 
     rvec *dest;
 
     snew(dest, n);
 
-    const rvec *vPtr = as_rvec_array(v->data());
+    const rvec *vPtr = as_rvec_array(v.data());
     for (unsigned int i = 0; i < n; i++)
     {
         copy_rvec(vPtr[i], dest[i]);
index b13e9d216a46f7f9e33f22759ece8f5c07427b9c..32d4d69191a37694682df910c071f491fbc92f32 100644 (file)
@@ -61,6 +61,7 @@
 #include "gromacs/math/paddedvector.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/mdtypes/md_enums.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
@@ -265,8 +266,8 @@ void init_dfhist_state(t_state *state, int dfhistNumLambda);
 void comp_state(const t_state *st1, const t_state *st2, gmx_bool bRMSD, real ftol, real abstol);
 
 /*! \brief Allocates an rvec pointer and copy the contents of v to it */
-rvec *getRvecArrayFromPaddedRVecVector(const PaddedRVecVector *v,
-                                       unsigned int            n);
+rvec *makeRvecArray(gmx::ArrayRef<const gmx::RVec> v,
+                    unsigned int                   n);
 
 /*! \brief Determine the relative box components
  *
index 46cdc76b76d52077bd875134f40ec1994528c92b..cecbc2432d6a1cfb5e772b3c55221bd7b2f11f46 100644 (file)
@@ -1413,9 +1413,9 @@ int *compact_unitcell_edges()
     return edge;
 }
 
-void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[])
+void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x)
 {
-    int npbcdim, i, m, d;
+    int npbcdim, m, d;
 
     if (ePBC == epbcSCREW)
     {
@@ -1433,7 +1433,7 @@ void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[])
 
     if (TRICLINIC(box))
     {
-        for (i = 0; (i < natoms); i++)
+        for (size_t i = 0; (i < x.size()); ++i)
         {
             for (m = npbcdim-1; m >= 0; m--)
             {
@@ -1456,7 +1456,7 @@ void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[])
     }
     else
     {
-        for (i = 0; i < natoms; i++)
+        for (size_t i = 0; (i < x.size()); ++i)
         {
             for (d = 0; d < npbcdim; d++)
             {
@@ -1474,11 +1474,11 @@ void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[])
 }
 
 void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
-                                     int natoms, rvec x[])
+                                     gmx::ArrayRef<gmx::RVec> x)
 {
     rvec   box_center, shift_center;
     real   shm01, shm02, shm12, shift;
-    int    i, m, d;
+    int    m, d;
 
     calc_box_center(ecenter, box, box_center);
 
@@ -1500,7 +1500,7 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
     shift_center[1] = shm12*shift_center[2];
     shift_center[2] = 0;
 
-    for (i = 0; (i < natoms); i++)
+    for (size_t i = 0; (i < x.size()); ++i)
     {
         for (m = DIM-1; m >= 0; m--)
         {
@@ -1532,11 +1532,10 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
 }
 
 void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box,
-                                   int natoms, rvec x[])
+                                   gmx::ArrayRef<gmx::RVec> x)
 {
     t_pbc pbc;
     rvec  box_center, dx;
-    int   i;
 
     set_pbc(&pbc, ePBC, box);
 
@@ -1546,7 +1545,7 @@ void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box,
     }
 
     calc_box_center(ecenter, box, box_center);
-    for (i = 0; i < natoms; i++)
+    for (size_t i = 0; (i < x.size()); ++i)
     {
         pbc_dx(&pbc, x[i], box_center, dx);
         rvec_add(box_center, dx, x[i]);
index 23dab9ac1f49b60f7fa5fe729727d8f3e731be2d..bf5fd555293d3e40ae1275d83c910b35a88f3a18 100644 (file)
 #include <stdio.h>
 
 #include "gromacs/math/vectypes.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
 struct gmx_domdec_t;
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 enum {
     epbcXYZ, epbcNONE, epbcXY, epbcSCREW, epbcNR
 };
@@ -305,10 +302,9 @@ int *compact_unitcell_edges(void);
  * Also works for triclinic cells.
  * \param[in]    ePBC   The pbc type
  * \param[in]    box    The simulation box
- * \param[in]    natoms The number of atoms
  * \param[inout] x      The coordinates of the atoms
  */
-void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[]);
+void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x);
 
 /*! \brief Put atoms inside triclinic box
  *
@@ -316,11 +312,10 @@ void put_atoms_in_box(int ePBC, const matrix box, int natoms, rvec x[]);
  * box center as calculated by calc_box_center.
  * \param[in]    ecenter The pbc center type
  * \param[in]    box     The simulation box
- * \param[in]    natoms  The number of atoms
  * \param[inout] x       The coordinates of the atoms
  */
 void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
-                                     int natoms, rvec x[]);
+                                     gmx::ArrayRef<gmx::RVec> x);
 
 /*! \brief Put atoms inside the unitcell
  *
@@ -330,15 +325,10 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
  * \param[in]    ePBC    The pbc type
  * \param[in]    ecenter The pbc center type
  * \param[in]    box     The simulation box
- * \param[in]    natoms  The number of atoms
  * \param[inout] x       The coordinates of the atoms
  */
 void put_atoms_in_compact_unitcell(int ePBC, int ecenter,
                                    const matrix box,
-                                   int natoms, rvec x[]);
-
-#ifdef __cplusplus
-}
-#endif
+                                   gmx::ArrayRef<gmx::RVec> x);
 
 #endif
index c14284008ec2fcf10c57fdc07acb05bcaf2fdfd1..49755d692f1160bbefba4a5e51336864632307f1 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "gromacs/awh/awh.h"
 #include "gromacs/commandline/filenm.h"
+#include "gromacs/compat/make_unique.h"
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/domdec/domdec_network.h"
 #include "gromacs/domdec/domdec_struct.h"
@@ -515,7 +516,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     {
         top = dd_init_local_top(top_global);
 
-        stateInstance = std::unique_ptr<t_state>(new t_state);
+        stateInstance = gmx::compat::make_unique<t_state>();
         state         = stateInstance.get();
         dd_init_local_state(cr->dd, state_global, state);
     }
@@ -1219,8 +1220,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
              * Check comments in sim_util.c
              */
             do_force(fplog, cr, ir, step, nrnb, wcycle, top, groups,
-                     state->box, &state->x, &state->hist,
-                     &f, force_vir, mdatoms, enerd, fcd,
+                     state->box, state->x, &state->hist,
+                     f, force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
                      fr, vsite, mu_tot, t, ed, bBornRadii,
                      (bNS ? GMX_FORCE_NS : 0) | force_flags,
@@ -1250,7 +1251,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 trotter_update(ir, step, ekind, enerd, state, total_vir, mdatoms, &MassQ, trotter_seq, ettTSEQ1);
             }
 
-            update_coords(fplog, step, ir, mdatoms, state, &f, fcd,
+            update_coords(fplog, step, ir, mdatoms, state, f, fcd,
                           ekind, M, upd, etrtVELOCITY1,
                           cr, constr);
 
@@ -1258,7 +1259,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             {
                 wallcycle_stop(wcycle, ewcUPDATE);
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
-                                   state, fr->bMolPBC, graph, &f,
+                                   state, fr->bMolPBC, graph, f,
                                    &top->idef, shake_vir,
                                    cr, nrnb, wcycle, upd, constr,
                                    TRUE, bCalcVir);
@@ -1405,7 +1406,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         do_md_trajectory_writing(fplog, cr, nfile, fnm, step, step_rel, t,
                                  ir, state, state_global, observablesHistory,
                                  top_global, fr,
-                                 outf, mdebin, ekind, &f,
+                                 outf, mdebin, ekind, f,
                                  &nchkpt,
                                  bCPT, bRerunMD, bLastStep,
                                  mdrunOptions.writeConfout,
@@ -1504,7 +1505,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             if (constr && bIfRandomize)
             {
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
-                                   state, fr->bMolPBC, graph, &f,
+                                   state, fr->bMolPBC, graph, f,
                                    &top->idef, tmp_vir,
                                    cr, nrnb, wcycle, upd, constr,
                                    TRUE, bCalcVir);
@@ -1543,7 +1544,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             if (EI_VV(ir->eI))
             {
                 /* velocity half-step update */
-                update_coords(fplog, step, ir, mdatoms, state, &f, fcd,
+                update_coords(fplog, step, ir, mdatoms, state, f, fcd,
                               ekind, M, upd, etrtVELOCITY2,
                               cr, constr);
             }
@@ -1564,12 +1565,12 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 copy_rvecn(as_rvec_array(state->x.data()), cbuf, 0, state->natoms);
             }
 
-            update_coords(fplog, step, ir, mdatoms, state, &f, fcd,
+            update_coords(fplog, step, ir, mdatoms, state, f, fcd,
                           ekind, M, upd, etrtPOSITION, cr, constr);
             wallcycle_stop(wcycle, ewcUPDATE);
 
             update_constraints(fplog, step, &dvdl_constr, ir, mdatoms, state,
-                               fr->bMolPBC, graph, &f,
+                               fr->bMolPBC, graph, f,
                                &top->idef, shake_vir,
                                cr, nrnb, wcycle, upd, constr,
                                FALSE, bCalcVir);
@@ -1589,7 +1590,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 /* now we know the scaling, we can compute the positions again again */
                 copy_rvecn(cbuf, as_rvec_array(state->x.data()), 0, state->natoms);
 
-                update_coords(fplog, step, ir, mdatoms, state, &f, fcd,
+                update_coords(fplog, step, ir, mdatoms, state, f, fcd,
                               ekind, M, upd, etrtPOSITION, cr, constr);
                 wallcycle_stop(wcycle, ewcUPDATE);
 
@@ -1599,7 +1600,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                  * physically? I'm thinking they are just errors, but not completely sure.
                  * For now, will call without actually constraining, constr=NULL*/
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
-                                   state, fr->bMolPBC, graph, &f,
+                                   state, fr->bMolPBC, graph, f,
                                    &top->idef, tmp_vir,
                                    cr, nrnb, wcycle, upd, nullptr,
                                    FALSE, bCalcVir);
index f30af45af66f16644da60993de997a88a15e2926..8695978f12271963df28b263c7ca3ac8f67407d6 100644 (file)
@@ -361,14 +361,15 @@ static bool step_man(t_manager *man, int *nat)
     *nat = man->natom;
     if (ncount == man->nSkip)
     {
+        auto atomsArrayRef = gmx::arrayRefFromArray(reinterpret_cast<gmx::RVec *>(man->x), man->natom);
         switch (man->molw->boxtype)
         {
             case esbTri:
-                put_atoms_in_triclinic_unitcell(ecenterDEF, man->box, man->natom, man->x);
+                put_atoms_in_triclinic_unitcell(ecenterDEF, man->box, atomsArrayRef);
                 break;
             case esbTrunc:
                 put_atoms_in_compact_unitcell(man->molw->ePBC, ecenterDEF, man->box,
-                                              man->natom, man->x);
+                                              atomsArrayRef);
                 break;
             case esbRect:
             case esbNone: