3ba294d17d5cec5742a3f697f3911882e83935f4
[alexxy/gromacs.git] / src / gromacs / ewald / pme_pp_communication.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 /*! \internal \file
38  *
39  * \brief This file contains declarations and constants necessary for
40  * coordinating the communication for the offload of long-ranged PME
41  * work to separate MPI rank, for computing energies and forces
42  * (Coulomb and LJ).
43  *
44  * \author Berk Hess <hess@kth.se>
45  * \author Mark Abraham <mark.j.abraham@gmail.com>
46  * \ingroup module_ewald
47  */
48
49 #include "gromacs/math/vectypes.h"
50 #include "gromacs/mdlib/sighandler.h"
51 #include "gromacs/utility/real.h"
52
53 /*! \brief MPI Tags used to separate communication of different types of quantities */
54 enum
55 {
56     eCommType_ChargeA,
57     eCommType_ChargeB,
58     eCommType_SQRTC6A,
59     eCommType_SQRTC6B,
60     eCommType_SigmaA,
61     eCommType_SigmaB,
62     eCommType_NR,
63     eCommType_COORD,
64     eCommType_CNB
65 };
66
67 //@{
68 /*! \brief Flags used to coordinate PP-PME communication and computation phases
69  *
70  * Some parts of the code(gmx_pme_send_q, gmx_pme_recv_q_x) assume
71  * that the six first flags are exactly in this order.
72  */
73
74 #define PP_PME_CHARGE (1 << 0)
75 #define PP_PME_CHARGEB (1 << 1)
76 #define PP_PME_SQRTC6 (1 << 2)
77 #define PP_PME_SQRTC6B (1 << 3)
78 #define PP_PME_SIGMA (1 << 4)
79 #define PP_PME_SIGMAB (1 << 5)
80 #define PP_PME_COORD (1 << 6)
81 #define PP_PME_ENER_VIR (1 << 9)
82 #define PP_PME_FINISH (1 << 10)
83 #define PP_PME_SWITCHGRID (1 << 11)
84 #define PP_PME_RESETCOUNTERS (1 << 12)
85 #define PP_PME_GPUCOMMS (1 << 13)
86 //@}
87
88 /*! \brief Return values for gmx_pme_recv_q_x */
89 enum
90 {
91     pmerecvqxX,            /* calculate PME mesh interactions for new x    */
92     pmerecvqxFINISH,       /* the simulation should finish, we should quit */
93     pmerecvqxSWITCHGRID,   /* change the PME grid size                     */
94     pmerecvqxRESETCOUNTERS /* reset the cycle and flop counters            */
95 };
96
97 /*! \internal
98  * \brief Helper struct for PP-PME communication of parameters.
99  *
100  * The contents are communicated over MPI in memcpy style, so should
101  * remain suitable for that.
102  */
103 struct gmx_pme_comm_n_box_t
104 {
105     int          natoms;     /**< Number of atoms */
106     matrix       box;        /**< Box */
107     int          maxshift_x; /**< Maximum shift in x direction */
108     int          maxshift_y; /**< Maximum shift in y direction */
109     real         lambda_q;   /**< Free-energy lambda for electrostatics */
110     real         lambda_lj;  /**< Free-energy lambda for Lennard-Jones */
111     unsigned int flags;      /**< Control flags */
112     int64_t      step;       /**< MD integration step number */
113     //@{
114     /*! \brief Used in PME grid tuning */
115     ivec grid_size;
116     real ewaldcoeff_q;
117     real ewaldcoeff_lj;
118     //@}
119 };
120
121 /*! \internal
122  * \brief Helper struct for PP-PME communication of virial and energy.
123  *
124  * The contents are communicated over MPI in memcpy style, so should
125  * remain suitable for that.
126  */
127 struct gmx_pme_comm_vir_ene_t
128 {
129     //@{
130     /*! \brief Virial, energy, and derivative of potential w.r.t. lambda for charge and Lennard-Jones */
131     matrix vir_q;
132     matrix vir_lj;
133     real   energy_q;
134     real   energy_lj;
135     real   dvdlambda_q;
136     real   dvdlambda_lj;
137     //@}
138     float           cycles;    /**< Counter of CPU cycles used */
139     gmx_stop_cond_t stop_cond; /**< Flag used in responding to an external signal to terminate */
140 };