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.
38 /* This file is completely threadsafe - keep it that way! */
50 #include "gmx_fatal.h"
59 void move_rvecs(const t_commrec *cr,gmx_bool bForward,gmx_bool bSum,
60 int left,int right,rvec vecs[],rvec buf[],
61 int shift,t_nrnb *nrnb)
63 int i,j,j0=137,j1=391;
66 #define next ((cur + 1) % cr->nnodes)
67 #define prev ((cur - 1 + cr->nnodes) % cr->nnodes)
69 #define HOMENRI(ind,i) ((ind)[(i)+1] - (ind)[(i)])
74 cur = (cr->nodeid + pd_shift(cr)) % cr->nnodes;
79 for(i=0; (i<shift); i++) {
89 for(j=j0; (j<j1); j++) {
93 /* Forward pulse around the ring, to increasing NODE number */
97 GMX_RIGHT,vecs[index[cur ]],HOMENRI(index,cur )*DIM,
98 GMX_LEFT, buf [index[prev]],HOMENRI(index,prev)*DIM);
101 GMX_RIGHT,vecs[index[cur ]],HOMENRI(index,cur )*DIM,
102 GMX_LEFT, vecs[index[prev]],HOMENRI(index,prev)*DIM);
103 /* Wait for communication to end */
104 gmx_wait(cr, right,left);
107 /* Backward pulse around the ring, to decreasing NODE number */
111 GMX_LEFT, vecs[index[cur ]],HOMENRI(index,cur )*DIM,
112 GMX_RIGHT,buf [index[next]],HOMENRI(index,next)*DIM);
115 GMX_LEFT, vecs[index[cur ]],HOMENRI(index,cur )*DIM,
116 GMX_RIGHT,vecs[index[next]],HOMENRI(index,next)*DIM);
117 /* Wait for communication to end */
118 gmx_wait(cr, left,right);
121 /* Actual summation */
123 for(j=j0; (j<j1); j++) {
124 rvec_inc(vecs[j],buf[j]);
134 inc_nrnb(nrnb,eNR_FSUM,nsum);
140 void move_reals(const t_commrec *cr,gmx_bool bForward,gmx_bool bSum,
141 int left,int right,real reals[],real buf[],
142 int shift,t_nrnb *nrnb)
144 int i,j,j0=137,j1=391;
147 #define next ((cur + 1) % cr->nnodes)
148 #define prev ((cur - 1 + cr->nnodes) % cr->nnodes)
150 #define HOMENRI(ind,i) ((ind)[(i)+1] - (ind)[(i)])
152 index = pd_index(cr);
156 cur = (cr->nodeid + pd_shift(cr)) % cr->nnodes;
164 for(i=0; (i<shift); i++)
178 for(j=j0; (j<j1); j++)
183 /* Forward pulse around the ring, to increasing NODE number */
188 GMX_RIGHT,reals+index[cur ],HOMENRI(index,cur ),
189 GMX_LEFT, buf+index[prev],HOMENRI(index,prev));
194 GMX_RIGHT,reals+index[cur ],HOMENRI(index,cur ),
195 GMX_LEFT, reals+index[prev],HOMENRI(index,prev));
197 /* Wait for communication to end */
198 gmx_wait(cr, right,left);
202 /* Backward pulse around the ring, to decreasing NODE number */
206 GMX_LEFT, reals+index[cur ],HOMENRI(index,cur ),
207 GMX_RIGHT,buf+index[next],HOMENRI(index,next));
212 GMX_LEFT, reals+index[cur ],HOMENRI(index,cur ),
213 GMX_RIGHT,reals+index[next],HOMENRI(index,next));
214 /* Wait for communication to end */
216 gmx_wait(cr, left,right);
219 /* Actual summation */
222 for(j=j0; (j<j1); j++)
240 inc_nrnb(nrnb,eNR_FSUM,nsum/3);
246 void move_x(FILE *log,const t_commrec *cr,
247 int left,int right,rvec x[],
250 move_rvecs(cr,FALSE,FALSE,left,right,x,NULL,pd_shift(cr),nrnb);
251 move_rvecs(cr,TRUE, FALSE,left,right,x,NULL,pd_bshift(cr),nrnb);
256 void move_rborn(FILE *log,const t_commrec *cr,
257 int left,int right,real rborn[],
260 move_reals(cr,FALSE,FALSE,left,right,rborn,NULL,pd_shift(cr),nrnb);
261 move_reals(cr,TRUE, FALSE,left,right,rborn,NULL,pd_bshift(cr),nrnb);
266 void move_f(FILE *log,const t_commrec *cr,
267 int left,int right,rvec f[],rvec fadd[],
270 move_rvecs(cr,TRUE, TRUE,left,right,f,fadd,pd_shift(cr),nrnb);
271 move_rvecs(cr,FALSE,TRUE,left,right,f,fadd,pd_bshift(cr),nrnb);
276 void move_gpol(FILE *log,const t_commrec *cr,
277 int left,int right,real gpol[],real gpol_add[],
280 move_reals(cr,TRUE, TRUE,left,right,gpol,gpol_add,pd_shift(cr),nrnb);
281 move_reals(cr,FALSE,TRUE,left,right,gpol,gpol_add,pd_bshift(cr),nrnb);
287 void move_cgcm(FILE *log,const t_commrec *cr,rvec cg_cm[])
293 #define next ((cur+1) % cr->nnodes)
295 cgindex = pd_cgindex(cr);
297 for(i=0; (i<cr->nnodes-1); i++) {
298 start = cgindex[cur];
299 nr = cgindex[cur+1] - start;
301 gmx_tx(cr,GMX_LEFT, cg_cm[start], nr*sizeof(cg_cm[0]));
303 fprintf(log,"move_cgcm: TX start=%d, nr=%d\n",start,nr);
305 start = cgindex[next];
306 nr = cgindex[next+1] - start;
308 gmx_rx(cr,GMX_RIGHT,cg_cm[start], nr*sizeof(cg_cm[0]));
310 fprintf(log,"move_cgcm: RX start=%d, nr=%d\n",start,nr);
312 gmx_tx_wait(cr,GMX_LEFT);
313 gmx_rx_wait(cr,GMX_RIGHT);
316 fprintf(debug,"cgcm[0][XX] %f\n",cg_cm[0][XX]);