From 7e1a2085c439225fdb3e52b8636bdec211b9db66 Mon Sep 17 00:00:00 2001 From: Prashanth Kanduri Date: Tue, 19 Mar 2019 16:37:46 +0100 Subject: [PATCH] Moving put_atoms_in_box_omp() to pbc.h This is another patch in the cleaning efforts of sim_util. It finally removes sim_util.h The idea is to only have functions relevant to the force schedules there so that it becomes easy to move it into its own module with minimal merging pains. Related: #2574 Change-Id: Ib0c2dbc21bd31ee272888d3fa25a3c0ce65b5478 --- src/gromacs/gmxpreprocess/grompp.cpp | 1 - src/gromacs/mdlib/forcerec.cpp | 1 - src/gromacs/mdlib/shellfc.cpp | 4 +-- src/gromacs/mdlib/sim_util.cpp | 23 +----------- src/gromacs/mdlib/sim_util.h | 54 ---------------------------- src/gromacs/mdrun/md.cpp | 1 - src/gromacs/mdrun/tpi.cpp | 1 - src/gromacs/pbcutil/pbc.cpp | 18 ++++++++++ src/gromacs/pbcutil/pbc.h | 16 +++++++-- src/gromacs/swap/swapcoords.cpp | 1 - 10 files changed, 35 insertions(+), 85 deletions(-) delete mode 100644 src/gromacs/mdlib/sim_util.h diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 8b01bd5f25..189743bdc1 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -80,7 +80,6 @@ #include "gromacs/mdlib/constr.h" #include "gromacs/mdlib/perf_est.h" #include "gromacs/mdlib/qmmm.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdlib/vsite.h" #include "gromacs/mdrunutility/mdmodules.h" #include "gromacs/mdtypes/inputrec.h" diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index e852525ebd..1d42ce69b2 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -73,7 +73,6 @@ #include "gromacs/mdlib/ns.h" #include "gromacs/mdlib/qmmm.h" #include "gromacs/mdlib/rf_util.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdlib/wall.h" #include "gromacs/mdtypes/commrec.h" #include "gromacs/mdtypes/fcdata.h" diff --git a/src/gromacs/mdlib/shellfc.cpp b/src/gromacs/mdlib/shellfc.cpp index 76caff9003..9fa062db9c 100644 --- a/src/gromacs/mdlib/shellfc.cpp +++ b/src/gromacs/mdlib/shellfc.cpp @@ -58,8 +58,8 @@ #include "gromacs/mdlib/constr.h" #include "gromacs/mdlib/force.h" #include "gromacs/mdlib/force_flags.h" +#include "gromacs/mdlib/gmx_omp_nthreads.h" #include "gromacs/mdlib/mdatoms.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdlib/vsite.h" #include "gromacs/mdtypes/commrec.h" #include "gromacs/mdtypes/enerdata.h" @@ -1059,7 +1059,7 @@ void relax_shell_flexcon(FILE *fplog, if (inputrec->cutoff_scheme == ecutsVERLET) { auto xRef = state->x.arrayRefWithPadding().paddedArrayRef(); - put_atoms_in_box_omp(fr->ePBC, state->box, xRef.subArray(0, md->homenr)); + put_atoms_in_box_omp(fr->ePBC, state->box, xRef.subArray(0, md->homenr), gmx_omp_nthreads_get(emntDefault)); } else { diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 1c3fc508d0..843b1db72d 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -36,8 +36,6 @@ */ #include "gmxpre.h" -#include "sim_util.h" - #include "config.h" #include @@ -892,7 +890,7 @@ static void do_force_cutsVERLET(FILE *fplog, if (bCalcCGCM) { - put_atoms_in_box_omp(fr->ePBC, box, x.unpaddedArrayRef().subArray(0, homenr)); + put_atoms_in_box_omp(fr->ePBC, box, x.unpaddedArrayRef().subArray(0, homenr), gmx_omp_nthreads_get(emntDefault)); inc_nrnb(nrnb, eNR_SHIFTX, homenr); } else if (EI_ENERGY_MINIMIZATION(inputrec->eI) && graph) @@ -1869,22 +1867,3 @@ void do_force(FILE *fplog, */ ddBalanceRegionHandler.openBeforeForceComputationCpu(DdAllowBalanceRegionReopen::no); } - -void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef x) -{ - int t, nth; - nth = gmx_omp_nthreads_get(emntDefault); - -#pragma omp parallel for num_threads(nth) schedule(static) - for (t = 0; t < nth; t++) - { - try - { - 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; - } -} diff --git a/src/gromacs/mdlib/sim_util.h b/src/gromacs/mdlib/sim_util.h deleted file mode 100644 index 036aac4188..0000000000 --- a/src/gromacs/mdlib/sim_util.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of the GROMACS molecular simulation package. - * - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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. - * - * GROMACS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * GROMACS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with GROMACS; if not, see - * http://www.gnu.org/licenses, or write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * If you want to redistribute modifications to GROMACS, please - * consider that scientific software is very special. Version - * control is crucial - bugs must be traceable. We will be happy to - * consider code for inclusion in the official distribution, but - * derived work must not be called official GROMACS. Details are found - * in the README & COPYING files - if they are missing, get the - * official version at http://www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the research papers on the package. Check out http://www.gromacs.org. - */ -#ifndef GMX_MDLIB_SIM_UTIL_H -#define GMX_MDLIB_SIM_UTIL_H - -#include "gromacs/math/vectypes.h" -#include "gromacs/utility/arrayref.h" - -/*! \brief Parallellizes put_atoms_in_box() - * - * This wrapper function around put_atoms_in_box() with the ugly manual - * workload splitting is needed to avoid silently introducing multithreading - * in tools. - * \param[in] ePBC The pbc type - * \param[in] box The simulation box - * \param[inout] x The coordinates of the atoms - */ -void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef x); - -#endif diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 338ff42958..5e1db3704f 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -90,7 +90,6 @@ #include "gromacs/mdlib/resethandler.h" #include "gromacs/mdlib/shellfc.h" #include "gromacs/mdlib/sighandler.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdlib/simulationsignal.h" #include "gromacs/mdlib/stat.h" #include "gromacs/mdlib/stophandler.h" diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 227ce96fd7..cb75faf26a 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -72,7 +72,6 @@ #include "gromacs/mdlib/force_flags.h" #include "gromacs/mdlib/mdatoms.h" #include "gromacs/mdlib/ns.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdlib/tgroup.h" #include "gromacs/mdlib/update.h" #include "gromacs/mdlib/vsite.h" diff --git a/src/gromacs/pbcutil/pbc.cpp b/src/gromacs/pbcutil/pbc.cpp index b77448fc5f..0397683415 100644 --- a/src/gromacs/pbcutil/pbc.cpp +++ b/src/gromacs/pbcutil/pbc.cpp @@ -1471,6 +1471,24 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef x) } } +void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef x, gmx_unused int nth) +{ + int t; + +#pragma omp parallel for num_threads(nth) schedule(static) + for (t = 0; t < nth; t++) + { + try + { + 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; + } +} + void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box, gmx::ArrayRef x) { diff --git a/src/gromacs/pbcutil/pbc.h b/src/gromacs/pbcutil/pbc.h index ad8d41ff05..dc70f22994 100644 --- a/src/gromacs/pbcutil/pbc.h +++ b/src/gromacs/pbcutil/pbc.h @@ -306,12 +306,24 @@ int *compact_unitcell_edges(); * These routines puts ONE or ALL atoms in the box, not caring * about charge groups! * Also works for triclinic cells. - * \param[in] ePBC The pbc type - * \param[in] box The simulation box + * \param[in] ePBC The pbc type + * \param[in] box The simulation box * \param[in,out] x The coordinates of the atoms */ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef x); +/*! \brief Parallellizes put_atoms_in_box() + * + * This wrapper function around put_atoms_in_box() with the ugly manual + * workload splitting is needed to avoid silently introducing multithreading + * in tools. + * \param[in] ePBC The pbc type + * \param[in] box The simulation box + * \param[in,out] x The coordinates of the atoms + * \param[in] nth number of threads to be used in the given module + */ +void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef x, gmx_unused int nth); + /*! \brief Put atoms inside triclinic box * * This puts ALL atoms in the triclinic unit cell, centered around the diff --git a/src/gromacs/swap/swapcoords.cpp b/src/gromacs/swap/swapcoords.cpp index 7673365bc8..68302f8b8f 100644 --- a/src/gromacs/swap/swapcoords.cpp +++ b/src/gromacs/swap/swapcoords.cpp @@ -60,7 +60,6 @@ #include "gromacs/gmxlib/network.h" #include "gromacs/math/vec.h" #include "gromacs/mdlib/groupcoord.h" -#include "gromacs/mdlib/sim_util.h" #include "gromacs/mdtypes/commrec.h" #include "gromacs/mdtypes/inputrec.h" #include "gromacs/mdtypes/md_enums.h" -- 2.22.0