1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROningen Mixture of Alchemy and Childrens' Stories
35 /* This file is completely threadsafe - keep it that way! */
47 #include "gmx_fatal.h"
52 #define block_bc(cr, d) gmx_bcast( sizeof(d), &(d),(cr))
53 #define nblock_bc(cr,nr,d) { if ((nr) > 0) gmx_bcast((nr)*sizeof((d)[0]), (d),(cr)); }
54 #define snew_bc(cr,d,nr) { if (!MASTER(cr)) snew((d),(nr)); }
55 /* Dirty macro with bAlloc not as an argument */
56 #define nblock_abc(cr,nr,d) { if (bAlloc) snew((d),(nr)); nblock_bc(cr,(nr),(d)); }
58 static void bc_string(const t_commrec
*cr
,t_symtab
*symtab
,char ***s
)
63 handle
= lookup_symtab(symtab
,*s
);
67 *s
= get_symtab_handle(symtab
,handle
);
71 static void bc_strings(const t_commrec
*cr
,t_symtab
*symtab
,int nr
,char ****nm
)
81 handle
[i
] = lookup_symtab(symtab
,NM
[i
]);
83 nblock_bc(cr
,nr
,handle
);
88 for (i
=0; (i
<nr
); i
++)
89 (*nm
)[i
] = get_symtab_handle(symtab
,handle
[i
]);
94 static void bc_strings_resinfo(const t_commrec
*cr
,t_symtab
*symtab
,
95 int nr
,t_resinfo
*resinfo
)
102 for(i
=0; (i
<nr
); i
++)
103 handle
[i
] = lookup_symtab(symtab
,resinfo
[i
].name
);
105 nblock_bc(cr
,nr
,handle
);
108 for (i
=0; (i
<nr
); i
++)
109 resinfo
[i
].name
= get_symtab_handle(symtab
,handle
[i
]);
114 static void bc_symtab(const t_commrec
*cr
,t_symtab
*symtab
)
119 block_bc(cr
,symtab
->nr
);
121 snew_bc(cr
,symtab
->symbuf
,1);
122 symbuf
= symtab
->symbuf
;
123 symbuf
->bufsize
= nr
;
124 snew_bc(cr
,symbuf
->buf
,nr
);
125 for (i
=0; i
<nr
; i
++) {
127 len
= strlen(symbuf
->buf
[i
]) + 1;
129 snew_bc(cr
,symbuf
->buf
[i
],len
);
130 nblock_bc(cr
,len
,symbuf
->buf
[i
]);
134 static void bc_block(const t_commrec
*cr
,t_block
*block
)
136 block_bc(cr
,block
->nr
);
137 snew_bc(cr
,block
->index
,block
->nr
+1);
138 nblock_bc(cr
,block
->nr
+1,block
->index
);
141 static void bc_blocka(const t_commrec
*cr
,t_blocka
*block
)
143 block_bc(cr
,block
->nr
);
144 snew_bc(cr
,block
->index
,block
->nr
+1);
145 nblock_bc(cr
,block
->nr
+1,block
->index
);
146 block_bc(cr
,block
->nra
);
148 snew_bc(cr
,block
->a
,block
->nra
);
149 nblock_bc(cr
,block
->nra
,block
->a
);
153 static void bc_grps(const t_commrec
*cr
,t_grps grps
[])
157 for(i
=0; (i
<egcNR
); i
++) {
158 block_bc(cr
,grps
[i
].nr
);
159 snew_bc(cr
,grps
[i
].nm_ind
,grps
[i
].nr
);
160 nblock_bc(cr
,grps
[i
].nr
,grps
[i
].nm_ind
);
164 static void bc_atoms(const t_commrec
*cr
,t_symtab
*symtab
,t_atoms
*atoms
)
168 block_bc(cr
,atoms
->nr
);
169 snew_bc(cr
,atoms
->atom
,atoms
->nr
);
170 nblock_bc(cr
,atoms
->nr
,atoms
->atom
);
171 bc_strings(cr
,symtab
,atoms
->nr
,&atoms
->atomname
);
172 block_bc(cr
,atoms
->nres
);
173 snew_bc(cr
,atoms
->resinfo
,atoms
->nres
);
174 nblock_bc(cr
,atoms
->nres
,atoms
->resinfo
);
175 bc_strings_resinfo(cr
,symtab
,atoms
->nres
,atoms
->resinfo
);
176 /* QMMM requires atomtypes to be known on all nodes as well */
177 bc_strings(cr
,symtab
,atoms
->nr
,&atoms
->atomtype
);
178 bc_strings(cr
,symtab
,atoms
->nr
,&atoms
->atomtypeB
);
181 static void bc_groups(const t_commrec
*cr
,t_symtab
*symtab
,
182 int natoms
,gmx_groups_t
*groups
)
187 bc_grps(cr
,groups
->grps
);
188 block_bc(cr
,groups
->ngrpname
);
189 bc_strings(cr
,symtab
,groups
->ngrpname
,&groups
->grpname
);
190 for(g
=0; g
<egcNR
; g
++) {
192 if (groups
->grpnr
[g
]) {
200 groups
->grpnr
[g
] = NULL
;
202 snew_bc(cr
,groups
->grpnr
[g
],n
);
203 nblock_bc(cr
,n
,groups
->grpnr
[g
]);
206 if (debug
) fprintf(debug
,"after bc_groups\n");
209 void bcast_state_setup(const t_commrec
*cr
,t_state
*state
)
211 block_bc(cr
,state
->natoms
);
212 block_bc(cr
,state
->ngtc
);
213 block_bc(cr
,state
->nnhpres
);
214 block_bc(cr
,state
->nhchainlength
);
215 block_bc(cr
,state
->nrng
);
216 block_bc(cr
,state
->nrngi
);
217 block_bc(cr
,state
->flags
);
220 void bcast_state(const t_commrec
*cr
,t_state
*state
,bool bAlloc
)
224 bcast_state_setup(cr
,state
);
226 nnht
= (state
->ngtc
)*(state
->nhchainlength
);
227 nnhtp
= (state
->nnhpres
)*(state
->nhchainlength
);
233 state
->nalloc
= state
->natoms
;
235 for(i
=0; i
<estNR
; i
++) {
236 if (state
->flags
& (1<<i
)) {
238 case estLAMBDA
: block_bc(cr
,state
->lambda
); break;
239 case estBOX
: block_bc(cr
,state
->box
); break;
240 case estBOX_REL
: block_bc(cr
,state
->box_rel
); break;
241 case estBOXV
: block_bc(cr
,state
->boxv
); break;
242 case estPRES_PREV
: block_bc(cr
,state
->pres_prev
); break;
243 case estSVIR_PREV
: block_bc(cr
,state
->svir_prev
); break;
244 case estFVIR_PREV
: block_bc(cr
,state
->fvir_prev
); break;
245 case estNH_XI
: nblock_abc(cr
,nnht
,state
->nosehoover_xi
); break;
246 case estNH_VXI
: nblock_abc(cr
,nnht
,state
->nosehoover_vxi
); break;
247 case estNHPRES_XI
: nblock_abc(cr
,nnhtp
,state
->nhpres_xi
); break;
248 case estNHPRES_VXI
: nblock_abc(cr
,nnhtp
,state
->nhpres_vxi
); break;
249 case estTC_INT
: nblock_abc(cr
,state
->ngtc
,state
->therm_integral
); break;
250 case estVETA
: block_bc(cr
,state
->veta
); break;
251 case estVOL0
: block_bc(cr
,state
->vol0
); break;
252 case estX
: nblock_abc(cr
,state
->natoms
,state
->x
); break;
253 case estV
: nblock_abc(cr
,state
->natoms
,state
->v
); break;
254 case estSDX
: nblock_abc(cr
,state
->natoms
,state
->sd_X
); break;
255 case estCGP
: nblock_abc(cr
,state
->natoms
,state
->cg_p
); break;
256 case estLD_RNG
: if(state
->nrngi
== 1) nblock_abc(cr
,state
->nrng
,state
->ld_rng
); break;
257 case estLD_RNGI
: if(state
->nrngi
== 1) nblock_abc(cr
,state
->nrngi
,state
->ld_rngi
); break;
258 case estDISRE_INITF
: block_bc(cr
,state
->hist
.disre_initf
); break;
259 case estDISRE_RM3TAV
:
260 block_bc(cr
,state
->hist
.ndisrepairs
);
261 nblock_abc(cr
,state
->hist
.ndisrepairs
,state
->hist
.disre_rm3tav
);
263 case estORIRE_INITF
: block_bc(cr
,state
->hist
.orire_initf
); break;
265 block_bc(cr
,state
->hist
.norire_Dtav
);
266 nblock_abc(cr
,state
->hist
.norire_Dtav
,state
->hist
.orire_Dtav
);
270 "Communication is not implemented for %s in bcast_state",
277 static void bc_ilists(const t_commrec
*cr
,t_ilist
*ilist
)
281 /* Here we only communicate the non-zero length ilists */
283 for(ftype
=0; ftype
<F_NRE
; ftype
++) {
284 if (ilist
[ftype
].nr
> 0) {
286 block_bc(cr
,ilist
[ftype
].nr
);
287 nblock_bc(cr
,ilist
[ftype
].nr
,ilist
[ftype
].iatoms
);
293 for(ftype
=0; ftype
<F_NRE
; ftype
++) {
299 block_bc(cr
,ilist
[ftype
].nr
);
300 snew_bc(cr
,ilist
[ftype
].iatoms
,ilist
[ftype
].nr
);
301 nblock_bc(cr
,ilist
[ftype
].nr
,ilist
[ftype
].iatoms
);
303 } while (ftype
>= 0);
306 if (debug
) fprintf(debug
,"after bc_ilists\n");
309 static void bc_idef(const t_commrec
*cr
,t_idef
*idef
)
311 block_bc(cr
,idef
->ntypes
);
312 block_bc(cr
,idef
->atnr
);
313 snew_bc(cr
,idef
->functype
,idef
->ntypes
);
314 snew_bc(cr
,idef
->iparams
,idef
->ntypes
);
315 nblock_bc(cr
,idef
->ntypes
,idef
->functype
);
316 nblock_bc(cr
,idef
->ntypes
,idef
->iparams
);
317 block_bc(cr
,idef
->fudgeQQ
);
318 bc_ilists(cr
,idef
->il
);
319 block_bc(cr
,idef
->ilsort
);
322 static void bc_cmap(const t_commrec
*cr
, gmx_cmap_t
*cmap_grid
)
326 block_bc(cr
,cmap_grid
->ngrid
);
327 block_bc(cr
,cmap_grid
->grid_spacing
);
329 ngrid
= cmap_grid
->ngrid
;
330 nelem
= cmap_grid
->grid_spacing
* cmap_grid
->grid_spacing
;
334 snew_bc(cr
,cmap_grid
->cmapdata
,ngrid
);
338 snew_bc(cr
,cmap_grid
->cmapdata
[i
].cmap
,4*nelem
);
339 nblock_bc(cr
,4*nelem
,cmap_grid
->cmapdata
[i
].cmap
);
344 static void bc_ffparams(const t_commrec
*cr
,gmx_ffparams_t
*ffp
)
348 block_bc(cr
,ffp
->ntypes
);
349 block_bc(cr
,ffp
->atnr
);
350 snew_bc(cr
,ffp
->functype
,ffp
->ntypes
);
351 snew_bc(cr
,ffp
->iparams
,ffp
->ntypes
);
352 nblock_bc(cr
,ffp
->ntypes
,ffp
->functype
);
353 nblock_bc(cr
,ffp
->ntypes
,ffp
->iparams
);
354 block_bc(cr
,ffp
->reppow
);
355 block_bc(cr
,ffp
->fudgeQQ
);
356 bc_cmap(cr
,&ffp
->cmap_grid
);
359 static void bc_grpopts(const t_commrec
*cr
,t_grpopts
*g
)
363 block_bc(cr
,g
->ngtc
);
364 block_bc(cr
,g
->ngacc
);
365 block_bc(cr
,g
->ngfrz
);
366 block_bc(cr
,g
->ngener
);
367 snew_bc(cr
,g
->nrdf
,g
->ngtc
);
368 snew_bc(cr
,g
->tau_t
,g
->ngtc
);
369 snew_bc(cr
,g
->ref_t
,g
->ngtc
);
370 snew_bc(cr
,g
->acc
,g
->ngacc
);
371 snew_bc(cr
,g
->nFreeze
,g
->ngfrz
);
372 snew_bc(cr
,g
->egp_flags
,g
->ngener
*g
->ngener
);
374 nblock_bc(cr
,g
->ngtc
,g
->nrdf
);
375 nblock_bc(cr
,g
->ngtc
,g
->tau_t
);
376 nblock_bc(cr
,g
->ngtc
,g
->ref_t
);
377 nblock_bc(cr
,g
->ngacc
,g
->acc
);
378 nblock_bc(cr
,g
->ngfrz
,g
->nFreeze
);
379 nblock_bc(cr
,g
->ngener
*g
->ngener
,g
->egp_flags
);
380 snew_bc(cr
,g
->annealing
,g
->ngtc
);
381 snew_bc(cr
,g
->anneal_npoints
,g
->ngtc
);
382 snew_bc(cr
,g
->anneal_time
,g
->ngtc
);
383 snew_bc(cr
,g
->anneal_temp
,g
->ngtc
);
384 nblock_bc(cr
,g
->ngtc
,g
->annealing
);
385 nblock_bc(cr
,g
->ngtc
,g
->anneal_npoints
);
386 for(i
=0;(i
<g
->ngtc
); i
++) {
387 n
= g
->anneal_npoints
[i
];
389 snew_bc(cr
,g
->anneal_time
[i
],n
);
390 snew_bc(cr
,g
->anneal_temp
[i
],n
);
391 nblock_bc(cr
,n
,g
->anneal_time
[i
]);
392 nblock_bc(cr
,n
,g
->anneal_temp
[i
]);
396 /* QMMM stuff, see inputrec */
397 block_bc(cr
,g
->ngQM
);
398 snew_bc(cr
,g
->QMmethod
,g
->ngQM
);
399 snew_bc(cr
,g
->QMbasis
,g
->ngQM
);
400 snew_bc(cr
,g
->QMcharge
,g
->ngQM
);
401 snew_bc(cr
,g
->QMmult
,g
->ngQM
);
402 snew_bc(cr
,g
->bSH
,g
->ngQM
);
403 snew_bc(cr
,g
->CASorbitals
,g
->ngQM
);
404 snew_bc(cr
,g
->CASelectrons
,g
->ngQM
);
405 snew_bc(cr
,g
->SAon
,g
->ngQM
);
406 snew_bc(cr
,g
->SAoff
,g
->ngQM
);
407 snew_bc(cr
,g
->SAsteps
,g
->ngQM
);
411 nblock_bc(cr
,g
->ngQM
,g
->QMmethod
);
412 nblock_bc(cr
,g
->ngQM
,g
->QMbasis
);
413 nblock_bc(cr
,g
->ngQM
,g
->QMcharge
);
414 nblock_bc(cr
,g
->ngQM
,g
->QMmult
);
415 nblock_bc(cr
,g
->ngQM
,g
->bSH
);
416 nblock_bc(cr
,g
->ngQM
,g
->CASorbitals
);
417 nblock_bc(cr
,g
->ngQM
,g
->CASelectrons
);
418 nblock_bc(cr
,g
->ngQM
,g
->SAon
);
419 nblock_bc(cr
,g
->ngQM
,g
->SAoff
);
420 nblock_bc(cr
,g
->ngQM
,g
->SAsteps
);
421 /* end of QMMM stuff */
425 static void bc_cosines(const t_commrec
*cr
,t_cosines
*cs
)
428 snew_bc(cr
,cs
->a
,cs
->n
);
429 snew_bc(cr
,cs
->phi
,cs
->n
);
431 nblock_bc(cr
,cs
->n
,cs
->a
);
432 nblock_bc(cr
,cs
->n
,cs
->phi
);
436 static void bc_pullgrp(const t_commrec
*cr
,t_pullgrp
*pgrp
)
440 snew_bc(cr
,pgrp
->ind
,pgrp
->nat
);
441 nblock_bc(cr
,pgrp
->nat
,pgrp
->ind
);
443 if (pgrp
->nweight
> 0) {
444 snew_bc(cr
,pgrp
->weight
,pgrp
->nweight
);
445 nblock_bc(cr
,pgrp
->nweight
,pgrp
->weight
);
449 static void bc_pull(const t_commrec
*cr
,t_pull
*pull
)
454 snew_bc(cr
,pull
->grp
,pull
->ngrp
+1);
455 for(g
=0; g
<pull
->ngrp
+1; g
++)
457 bc_pullgrp(cr
,&pull
->grp
[g
]);
461 static void bc_inputrec(const t_commrec
*cr
,t_inputrec
*inputrec
)
466 block_bc(cr
,*inputrec
);
467 snew_bc(cr
,inputrec
->flambda
,inputrec
->n_flambda
);
468 nblock_bc(cr
,inputrec
->n_flambda
,inputrec
->flambda
);
469 bc_grpopts(cr
,&(inputrec
->opts
));
470 if (inputrec
->ePull
!= epullNO
) {
471 snew_bc(cr
,inputrec
->pull
,1);
472 bc_pull(cr
,inputrec
->pull
);
474 for(i
=0; (i
<DIM
); i
++) {
475 bc_cosines(cr
,&(inputrec
->ex
[i
]));
476 bc_cosines(cr
,&(inputrec
->et
[i
]));
480 static void bc_moltype(const t_commrec
*cr
,t_symtab
*symtab
,
481 gmx_moltype_t
*moltype
)
483 bc_string(cr
,symtab
,&moltype
->name
);
484 bc_atoms(cr
,symtab
,&moltype
->atoms
);
485 if (debug
) fprintf(debug
,"after bc_atoms\n");
487 bc_ilists(cr
,moltype
->ilist
);
488 bc_block(cr
,&moltype
->cgs
);
489 bc_blocka(cr
,&moltype
->excls
);
492 static void bc_molblock(const t_commrec
*cr
,gmx_molblock_t
*molb
)
496 block_bc(cr
,molb
->type
);
497 block_bc(cr
,molb
->nmol
);
498 block_bc(cr
,molb
->natoms_mol
);
499 block_bc(cr
,molb
->nposres_xA
);
500 if (molb
->nposres_xA
> 0) {
501 snew_bc(cr
,molb
->posres_xA
,molb
->nposres_xA
);
502 nblock_bc(cr
,molb
->nposres_xA
*DIM
,molb
->posres_xA
[0]);
504 block_bc(cr
,molb
->nposres_xB
);
505 if (molb
->nposres_xB
> 0) {
506 snew_bc(cr
,molb
->posres_xB
,molb
->nposres_xB
);
507 nblock_bc(cr
,molb
->nposres_xB
*DIM
,molb
->posres_xB
[0]);
509 if (debug
) fprintf(debug
,"after bc_molblock\n");
512 static void bc_atomtypes(const t_commrec
*cr
, t_atomtypes
*atomtypes
)
516 block_bc(cr
,atomtypes
->nr
);
520 snew_bc(cr
,atomtypes
->radius
,nr
);
521 snew_bc(cr
,atomtypes
->vol
,nr
);
522 snew_bc(cr
,atomtypes
->surftens
,nr
);
523 snew_bc(cr
,atomtypes
->gb_radius
,nr
);
524 snew_bc(cr
,atomtypes
->S_hct
,nr
);
526 nblock_bc(cr
,nr
,atomtypes
->radius
);
527 nblock_bc(cr
,nr
,atomtypes
->vol
);
528 nblock_bc(cr
,nr
,atomtypes
->surftens
);
529 nblock_bc(cr
,nr
,atomtypes
->gb_radius
);
530 nblock_bc(cr
,nr
,atomtypes
->S_hct
);
534 void bcast_ir_mtop(const t_commrec
*cr
,t_inputrec
*inputrec
,gmx_mtop_t
*mtop
)
537 if (debug
) fprintf(debug
,"in bc_data\n");
538 bc_inputrec(cr
,inputrec
);
539 if (debug
) fprintf(debug
,"after bc_inputrec\n");
540 bc_symtab(cr
,&mtop
->symtab
);
541 if (debug
) fprintf(debug
,"after bc_symtab\n");
542 bc_string(cr
,&mtop
->symtab
,&mtop
->name
);
543 if (debug
) fprintf(debug
,"after bc_name\n");
545 bc_ffparams(cr
,&mtop
->ffparams
);
547 block_bc(cr
,mtop
->nmoltype
);
548 snew_bc(cr
,mtop
->moltype
,mtop
->nmoltype
);
549 for(i
=0; i
<mtop
->nmoltype
; i
++) {
550 bc_moltype(cr
,&mtop
->symtab
,&mtop
->moltype
[i
]);
553 block_bc(cr
,mtop
->nmolblock
);
554 snew_bc(cr
,mtop
->molblock
,mtop
->nmolblock
);
555 for(i
=0; i
<mtop
->nmolblock
; i
++) {
556 bc_molblock(cr
,&mtop
->molblock
[i
]);
559 block_bc(cr
,mtop
->natoms
);
561 bc_atomtypes(cr
,&mtop
->atomtypes
);
563 bc_block(cr
,&mtop
->mols
);
564 bc_groups(cr
,&mtop
->symtab
,mtop
->natoms
,&mtop
->groups
);