2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
43 #include "visibility.h"
45 #include "gmxcomplex.h"
46 #include "gmx_wallcycle.h"
52 typedef real *splinevec[DIM];
55 GMX_SUM_QGRID_FORWARD, GMX_SUM_QGRID_BACKWARD
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.
68 int gmx_pme_reinit(gmx_pme_t * pmedata,
71 const t_inputrec * ir,
73 /* As gmx_pme_init, but takes most settings, except the grid, from pme_src */
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.
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)
88 int gmx_pme_do(gmx_pme_t pme,
89 int start, int homenr,
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.
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,
109 /* Called on the nodes that do PME exclusively (as slaves)
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.
120 /* The following three routines are for PME/PP node splitting in pme_pp.c */
122 /* Abstract type for PME <-> PP communication */
123 typedef struct gmx_pme_pp *gmx_pme_pp_t;
126 void gmx_pme_check_restrictions(int pme_order,
127 int nkx, int nky, int nkz,
130 gmx_bool bUseThreads,
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
142 gmx_pme_pp_t gmx_pme_pp_init(t_commrec *cr);
143 /* Initialize the PME-only side of the PME <-> PP communication */
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. */
150 void gmx_pme_send_x(t_commrec *cr, matrix box, rvec *x,
151 gmx_bool bFreeEnergy, real lambda,
153 gmx_large_int_t step);
154 /* Send the coordinates to our PME-only node and request a PME calculation */
157 void gmx_pme_send_finish(t_commrec *cr);
158 /* Tell our PME-only node to finish */
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 */
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 */
168 void gmx_pme_receive_f(t_commrec *cr,
169 rvec f[], matrix vir,
170 real *energy, real *dvdlambda,
172 /* PP nodes receive the long range forces from the PME nodes */
174 /* Return values for gmx_pme_recv_q_x */
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 */
182 int gmx_pme_recv_q_x(gmx_pme_pp_t pme_pp,
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,
189 gmx_large_int_t *step,
190 ivec grid_size, real *ewaldcoeff);
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
199 void gmx_pme_send_force_vir_ener(gmx_pme_pp_t pme_pp,
201 real energy, real dvdlambda,
203 /* Send the PME mesh force, virial and energy to the PP-only nodes */