PME load balancing now checks for PME grid restrictions
[alexxy/gromacs.git] / include / pme.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38
39 #ifndef _pme_h
40 #define _pme_h
41
42 #include <stdio.h>
43 #include "visibility.h"
44 #include "typedefs.h"
45 #include "gmxcomplex.h"
46 #include "gmx_wallcycle.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 typedef real *splinevec[DIM];
53
54 enum {
55     GMX_SUM_QGRID_FORWARD, GMX_SUM_QGRID_BACKWARD
56 };
57
58 GMX_LIBMD_EXPORT
59 int gmx_pme_init(gmx_pme_t *pmedata, t_commrec *cr,
60                  int nnodes_major, int nnodes_minor,
61                  t_inputrec *ir, int homenr,
62                  gmx_bool bFreeEnergy, gmx_bool bReproducible, int nthread);
63 /* Initialize the pme data structures resepectively.
64  * Return value 0 indicates all well, non zero is an error code.
65  */
66
67 GMX_LIBMD_EXPORT
68 int gmx_pme_reinit(gmx_pme_t *         pmedata,
69                    t_commrec *         cr,
70                    gmx_pme_t           pme_src,
71                    const t_inputrec *  ir,
72                    ivec                grid_size);
73 /* As gmx_pme_init, but takes most settings, except the grid, from pme_src */
74
75 int gmx_pme_destroy(FILE *log, gmx_pme_t *pmedata);
76 /* Destroy the pme data structures resepectively.
77  * Return value 0 indicates all well, non zero is an error code.
78  */
79
80 #define GMX_PME_SPREAD_Q      (1<<0)
81 #define GMX_PME_SOLVE         (1<<1)
82 #define GMX_PME_CALC_F        (1<<2)
83 #define GMX_PME_CALC_ENER_VIR (1<<3)
84 /* This forces the grid to be backtransformed even without GMX_PME_CALC_F */
85 #define GMX_PME_CALC_POT      (1<<4)
86 #define GMX_PME_DO_ALL_F  (GMX_PME_SPREAD_Q | GMX_PME_SOLVE | GMX_PME_CALC_F)
87
88 int gmx_pme_do(gmx_pme_t pme,
89                int start,       int homenr,
90                rvec x[],        rvec f[],
91                real chargeA[],  real chargeB[],
92                matrix box,      t_commrec *cr,
93                int  maxshift_x, int maxshift_y,
94                t_nrnb *nrnb,    gmx_wallcycle_t wcycle,
95                matrix lrvir,    real ewaldcoeff,
96                real *energy,    real lambda,
97                real *dvdlambda, int flags);
98 /* Do a PME calculation for the long range electrostatics.
99  * flags, defined above, determine which parts of the calculation are performed.
100  * Return value 0 indicates all well, non zero is an error code.
101  */
102
103 GMX_LIBMD_EXPORT
104 int gmx_pmeonly(gmx_pme_t pme,
105                 t_commrec *cr,     t_nrnb *mynrnb,
106                 gmx_wallcycle_t wcycle,
107                 real ewaldcoeff,   gmx_bool bGatherOnly,
108                 t_inputrec *ir);
109 /* Called on the nodes that do PME exclusively (as slaves)
110  */
111
112 void gmx_pme_calc_energy(gmx_pme_t pme, int n, rvec *x, real *q, real *V);
113 /* Calculate the PME grid energy V for n charges with a potential
114  * in the pme struct determined before with a call to gmx_pme_do
115  * with at least GMX_PME_SPREAD_Q and GMX_PME_SOLVE specified.
116  * Note that the charges are not spread on the grid in the pme struct.
117  * Currently does not work in parallel or with free energy.
118  */
119
120 /* The following three routines are for PME/PP node splitting in pme_pp.c */
121
122 /* Abstract type for PME <-> PP communication */
123 typedef struct gmx_pme_pp *gmx_pme_pp_t;
124
125 GMX_LIBMD_EXPORT
126 void gmx_pme_check_restrictions(int pme_order,
127                                 int nkx, int nky, int nkz,
128                                 int nnodes_major,
129                                 int nnodes_minor,
130                                 gmx_bool bUseThreads,
131                                 gmx_bool bFatal,
132                                 gmx_bool *bValidSettings);
133 /* Check restrictions on pme_order and the PME grid nkx,nky,nkz.
134  * With bFatal=TRUE, a fatal error is generated on violation,
135  * bValidSettings=NULL can be passed.
136  * With bFatal=FALSE, *bValidSettings reports the validity of the settings.
137  * bUseThreads tells if any MPI rank doing PME uses more than 1 threads.
138  * If at calling you bUseThreads is unknown, pass TRUE for conservative
139  * checking.
140  */
141
142 gmx_pme_pp_t gmx_pme_pp_init(t_commrec *cr);
143 /* Initialize the PME-only side of the PME <-> PP communication */
144
145 void gmx_pme_send_q(t_commrec *cr,
146                     gmx_bool bFreeEnergy, real *chargeA, real *chargeB,
147                     int maxshift_x, int maxshift_y);
148 /* Send the charges and maxshift to out PME-only node. */
149
150 void gmx_pme_send_x(t_commrec *cr, matrix box, rvec *x,
151                     gmx_bool bFreeEnergy, real lambda,
152                     gmx_bool bEnerVir,
153                     gmx_large_int_t step);
154 /* Send the coordinates to our PME-only node and request a PME calculation */
155
156 GMX_LIBMD_EXPORT
157 void gmx_pme_send_finish(t_commrec *cr);
158 /* Tell our PME-only node to finish */
159
160 GMX_LIBMD_EXPORT
161 void gmx_pme_send_switchgrid(t_commrec *cr, ivec grid_size, real ewaldcoeff);
162 /* Tell our PME-only node to switch to a new grid size */
163
164 GMX_LIBMD_EXPORT
165 void gmx_pme_send_resetcounters(t_commrec *cr, gmx_large_int_t step);
166 /* Tell our PME-only node to reset all cycle and flop counters */
167
168 void gmx_pme_receive_f(t_commrec *cr,
169                        rvec f[], matrix vir,
170                        real *energy, real *dvdlambda,
171                        float *pme_cycles);
172 /* PP nodes receive the long range forces from the PME nodes */
173
174 /* Return values for gmx_pme_recv_q_x */
175 enum {
176     pmerecvqxX,            /* calculate PME mesh interactions for new x    */
177     pmerecvqxFINISH,       /* the simulation should finish, we should quit */
178     pmerecvqxSWITCHGRID,   /* change the PME grid size                     */
179     pmerecvqxRESETCOUNTERS /* reset the cycle and flop counters            */
180 };
181
182 int gmx_pme_recv_q_x(gmx_pme_pp_t pme_pp,
183                      int *natoms,
184                      real **chargeA, real **chargeB,
185                      matrix box, rvec **x, rvec **f,
186                      int *maxshift_x, int *maxshift_y,
187                      gmx_bool *bFreeEnergy, real *lambda,
188                      gmx_bool *bEnerVir,
189                      gmx_large_int_t *step,
190                      ivec grid_size, real *ewaldcoeff);
191 ;
192 /* With return value:
193  * pmerecvqxX:             all parameters set, chargeA and chargeB can be NULL
194  * pmerecvqxFINISH:        no parameters set
195  * pmerecvqxSWITCHGRID:    only grid_size and *ewaldcoeff are set
196  * pmerecvqxRESETCOUNTERS: *step is set
197  */
198
199 void gmx_pme_send_force_vir_ener(gmx_pme_pp_t pme_pp,
200                                  rvec *f, matrix vir,
201                                  real energy, real dvdlambda,
202                                  float cycles);
203 /* Send the PME mesh force, virial and energy to the PP-only nodes */
204
205 #ifdef __cplusplus
206 }
207 #endif
208
209 #endif