Merge remote-tracking branch 'gerrit/release-4-6'
[alexxy/gromacs.git] / src / gromacs / gmxlib / mvdata.c
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
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.
14
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.
19  * 
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.
26  * 
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.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * GROningen Mixture of Alchemy and Childrens' Stories
34  */
35 /* This file is completely threadsafe - keep it that way! */
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include <sysstuff.h>
41 #include <string.h>
42 #include "typedefs.h"
43 #include "main.h"
44 #include "mvdata.h"
45 #include "network.h"
46 #include "smalloc.h"
47 #include "gmx_fatal.h"
48 #include "symtab.h"
49 #include "vec.h"
50 #include "tgroup.h"
51
52 #define   block_bc(cr,   d) gmx_bcast(     sizeof(d),     &(d),(cr))
53 /* Probably the test for (nr) > 0 in the next macro is only needed
54  * on BlueGene(/L), where IBM's MPI_Bcast will segfault after
55  * dereferencing a null pointer, even when no data is to be transferred. */
56 #define  nblock_bc(cr,nr,d) { if ((nr) > 0) gmx_bcast((nr)*sizeof((d)[0]), (d),(cr)); }
57 #define    snew_bc(cr,d,nr) { if (!MASTER(cr)) snew((d),(nr)); }
58 /* Dirty macro with bAlloc not as an argument */
59 #define nblock_abc(cr,nr,d) { if (bAlloc) snew((d),(nr)); nblock_bc(cr,(nr),(d)); }
60
61 static void bc_string(const t_commrec *cr,t_symtab *symtab,char ***s)
62 {
63   int handle;
64   
65   if (MASTER(cr)) {
66     handle = lookup_symtab(symtab,*s);
67   }
68   block_bc(cr,handle);
69   if (!MASTER(cr)) {
70     *s = get_symtab_handle(symtab,handle);
71   }
72 }
73
74 static void bc_strings(const t_commrec *cr,t_symtab *symtab,int nr,char ****nm)
75 {
76   int  i;
77   int  *handle;
78   char ***NM;
79
80   snew(handle,nr);
81   if (MASTER(cr)) {
82     NM = *nm;
83     for(i=0; (i<nr); i++)
84       handle[i] = lookup_symtab(symtab,NM[i]);
85   }
86   nblock_bc(cr,nr,handle);
87
88   if (!MASTER(cr)) {
89     snew_bc(cr,*nm,nr);
90     NM = *nm;
91     for (i=0; (i<nr); i++) 
92       (*nm)[i] = get_symtab_handle(symtab,handle[i]);
93   }
94   sfree(handle);
95 }
96
97 static void bc_strings_resinfo(const t_commrec *cr,t_symtab *symtab,
98                                int nr,t_resinfo *resinfo)
99 {
100   int  i;
101   int  *handle;
102
103   snew(handle,nr);
104   if (MASTER(cr)) {
105     for(i=0; (i<nr); i++)
106       handle[i] = lookup_symtab(symtab,resinfo[i].name);
107   }
108   nblock_bc(cr,nr,handle);
109
110   if (!MASTER(cr)) {
111     for (i=0; (i<nr); i++) 
112       resinfo[i].name = get_symtab_handle(symtab,handle[i]);
113   }
114   sfree(handle);
115 }
116
117 static void bc_symtab(const t_commrec *cr,t_symtab *symtab)
118 {
119   int i,nr,len;
120   t_symbuf *symbuf;
121
122   block_bc(cr,symtab->nr);
123   nr = symtab->nr;
124   snew_bc(cr,symtab->symbuf,1);
125   symbuf = symtab->symbuf;
126   symbuf->bufsize = nr;
127   snew_bc(cr,symbuf->buf,nr);
128   for (i=0; i<nr; i++) {
129     if (MASTER(cr))
130       len = strlen(symbuf->buf[i]) + 1;
131     block_bc(cr,len);
132     snew_bc(cr,symbuf->buf[i],len);
133     nblock_bc(cr,len,symbuf->buf[i]);
134   }
135 }
136
137 static void bc_block(const t_commrec *cr,t_block *block)
138 {
139   block_bc(cr,block->nr);
140   snew_bc(cr,block->index,block->nr+1);
141   nblock_bc(cr,block->nr+1,block->index);
142 }
143
144 static void bc_blocka(const t_commrec *cr,t_blocka *block)
145 {
146   block_bc(cr,block->nr);
147   snew_bc(cr,block->index,block->nr+1);
148   nblock_bc(cr,block->nr+1,block->index);
149   block_bc(cr,block->nra);
150   if (block->nra) {
151     snew_bc(cr,block->a,block->nra);
152     nblock_bc(cr,block->nra,block->a);
153   }
154 }
155
156 static void bc_grps(const t_commrec *cr,t_grps grps[])
157 {
158   int i;
159   
160   for(i=0; (i<egcNR); i++) {
161     block_bc(cr,grps[i].nr);
162     snew_bc(cr,grps[i].nm_ind,grps[i].nr);
163     nblock_bc(cr,grps[i].nr,grps[i].nm_ind);
164   }
165 }
166
167 static void bc_atoms(const t_commrec *cr,t_symtab *symtab,t_atoms *atoms)
168 {
169   int dummy;
170
171   block_bc(cr,atoms->nr);
172   snew_bc(cr,atoms->atom,atoms->nr);
173   nblock_bc(cr,atoms->nr,atoms->atom);
174   bc_strings(cr,symtab,atoms->nr,&atoms->atomname);
175   block_bc(cr,atoms->nres);
176   snew_bc(cr,atoms->resinfo,atoms->nres);
177   nblock_bc(cr,atoms->nres,atoms->resinfo);
178   bc_strings_resinfo(cr,symtab,atoms->nres,atoms->resinfo);
179   /* QMMM requires atomtypes to be known on all nodes as well */
180   bc_strings(cr,symtab,atoms->nr,&atoms->atomtype);
181   bc_strings(cr,symtab,atoms->nr,&atoms->atomtypeB);
182 }
183
184 static void bc_groups(const t_commrec *cr,t_symtab *symtab,
185                       int natoms,gmx_groups_t *groups)
186 {
187   int dummy;
188   int g,n;
189
190   bc_grps(cr,groups->grps);
191   block_bc(cr,groups->ngrpname);
192   bc_strings(cr,symtab,groups->ngrpname,&groups->grpname);
193   for(g=0; g<egcNR; g++) {
194     if (MASTER(cr)) {
195       if (groups->grpnr[g]) {
196         n = natoms;
197       } else {
198         n = 0;
199       }
200     }
201     block_bc(cr,n);
202     if (n == 0) {
203       groups->grpnr[g] = NULL;
204     } else {
205       snew_bc(cr,groups->grpnr[g],n);
206       nblock_bc(cr,n,groups->grpnr[g]);
207     }
208   }
209   if (debug) fprintf(debug,"after bc_groups\n");
210 }
211
212 void bcast_state_setup(const t_commrec *cr,t_state *state)
213 {
214   block_bc(cr,state->natoms);
215   block_bc(cr,state->ngtc);
216   block_bc(cr,state->nnhpres);
217   block_bc(cr,state->nhchainlength);
218   block_bc(cr,state->nrng);
219   block_bc(cr,state->nrngi);
220   block_bc(cr,state->flags);
221   if (state->lambda==NULL)
222   {
223       snew_bc(cr,state->lambda,efptNR)
224   }
225 }
226
227 void bcast_state(const t_commrec *cr,t_state *state,gmx_bool bAlloc)
228 {
229   int i,nnht,nnhtp;
230
231   bcast_state_setup(cr,state);
232
233   nnht = (state->ngtc)*(state->nhchainlength); 
234   nnhtp = (state->nnhpres)*(state->nhchainlength); 
235
236   if (MASTER(cr)) {
237     bAlloc = FALSE;
238   }
239   if (bAlloc) {
240     state->nalloc = state->natoms;
241   }
242   for(i=0; i<estNR; i++) {
243     if (state->flags & (1<<i)) {
244       switch (i) {
245       case estLAMBDA:  nblock_bc(cr,efptNR,state->lambda); break;
246       case estFEPSTATE: block_bc(cr,state->fep_state); break;
247       case estBOX:     block_bc(cr,state->box); break;
248       case estBOX_REL: block_bc(cr,state->box_rel); break;
249       case estBOXV:    block_bc(cr,state->boxv); break;
250       case estPRES_PREV: block_bc(cr,state->pres_prev); break;
251       case estSVIR_PREV: block_bc(cr,state->svir_prev); break;
252       case estFVIR_PREV: block_bc(cr,state->fvir_prev); break;
253       case estNH_XI:   nblock_abc(cr,nnht,state->nosehoover_xi); break;
254       case estNH_VXI:  nblock_abc(cr,nnht,state->nosehoover_vxi); break;
255       case estNHPRES_XI:   nblock_abc(cr,nnhtp,state->nhpres_xi); break;
256       case estNHPRES_VXI:  nblock_abc(cr,nnhtp,state->nhpres_vxi); break;
257       case estTC_INT:  nblock_abc(cr,state->ngtc,state->therm_integral); break;
258       case estVETA:    block_bc(cr,state->veta); break;
259       case estVOL0:    block_bc(cr,state->vol0); break;
260       case estX:       nblock_abc(cr,state->natoms,state->x); break;
261       case estV:       nblock_abc(cr,state->natoms,state->v); break;
262       case estSDX:     nblock_abc(cr,state->natoms,state->sd_X); break;
263       case estCGP:     nblock_abc(cr,state->natoms,state->cg_p); break;
264           case estLD_RNG:  if(state->nrngi == 1) nblock_abc(cr,state->nrng,state->ld_rng); break;
265           case estLD_RNGI: if(state->nrngi == 1) nblock_abc(cr,state->nrngi,state->ld_rngi); break;
266       case estDISRE_INITF: block_bc(cr,state->hist.disre_initf); break;
267       case estDISRE_RM3TAV:
268           block_bc(cr,state->hist.ndisrepairs);
269           nblock_abc(cr,state->hist.ndisrepairs,state->hist.disre_rm3tav);
270           break;
271       case estORIRE_INITF: block_bc(cr,state->hist.orire_initf); break;
272       case estORIRE_DTAV:
273           block_bc(cr,state->hist.norire_Dtav);
274           nblock_abc(cr,state->hist.norire_Dtav,state->hist.orire_Dtav);
275           break;
276       default:
277           gmx_fatal(FARGS,
278                     "Communication is not implemented for %s in bcast_state",
279                     est_names[i]);
280       }
281     }
282   }
283 }
284
285 static void bc_ilists(const t_commrec *cr,t_ilist *ilist)
286 {
287   int ftype;
288
289   /* Here we only communicate the non-zero length ilists */
290   if (MASTER(cr)) {
291     for(ftype=0; ftype<F_NRE; ftype++) {
292       if (ilist[ftype].nr > 0) {
293         block_bc(cr,ftype);
294         block_bc(cr,ilist[ftype].nr);
295         nblock_bc(cr,ilist[ftype].nr,ilist[ftype].iatoms);
296       }
297     }
298     ftype = -1;
299     block_bc(cr,ftype);
300   } else {
301     for(ftype=0; ftype<F_NRE; ftype++) {
302       ilist[ftype].nr = 0;
303     }
304     do {
305       block_bc(cr,ftype);
306       if (ftype >= 0) {
307         block_bc(cr,ilist[ftype].nr);
308         snew_bc(cr,ilist[ftype].iatoms,ilist[ftype].nr);
309         nblock_bc(cr,ilist[ftype].nr,ilist[ftype].iatoms);
310       }
311     } while (ftype >= 0);
312   }
313
314   if (debug) fprintf(debug,"after bc_ilists\n");
315 }
316
317 static void bc_cmap(const t_commrec *cr, gmx_cmap_t *cmap_grid)
318 {
319         int i,j,nelem,ngrid;
320         
321         block_bc(cr,cmap_grid->ngrid);
322         block_bc(cr,cmap_grid->grid_spacing);
323         
324         ngrid = cmap_grid->ngrid;
325         nelem = cmap_grid->grid_spacing * cmap_grid->grid_spacing;
326         
327         if(ngrid>0)
328         {
329                 snew_bc(cr,cmap_grid->cmapdata,ngrid);
330                 
331                 for(i=0;i<ngrid;i++)
332                 {
333                         snew_bc(cr,cmap_grid->cmapdata[i].cmap,4*nelem);
334                         nblock_bc(cr,4*nelem,cmap_grid->cmapdata[i].cmap);
335                 }
336         }
337 }
338
339 static void bc_ffparams(const t_commrec *cr,gmx_ffparams_t *ffp)
340 {
341   int i;
342   
343   block_bc(cr,ffp->ntypes);
344   block_bc(cr,ffp->atnr);
345   snew_bc(cr,ffp->functype,ffp->ntypes);
346   snew_bc(cr,ffp->iparams,ffp->ntypes);
347   nblock_bc(cr,ffp->ntypes,ffp->functype);
348   nblock_bc(cr,ffp->ntypes,ffp->iparams);
349   block_bc(cr,ffp->reppow);
350   block_bc(cr,ffp->fudgeQQ);
351   bc_cmap(cr,&ffp->cmap_grid);
352 }
353
354 static void bc_grpopts(const t_commrec *cr,t_grpopts *g)
355 {
356     int i,n;
357     
358     block_bc(cr,g->ngtc);
359     block_bc(cr,g->ngacc);
360     block_bc(cr,g->ngfrz);
361     block_bc(cr,g->ngener);
362     snew_bc(cr,g->nrdf,g->ngtc);
363     snew_bc(cr,g->tau_t,g->ngtc);
364     snew_bc(cr,g->ref_t,g->ngtc);
365     snew_bc(cr,g->acc,g->ngacc);
366     snew_bc(cr,g->nFreeze,g->ngfrz);
367     snew_bc(cr,g->egp_flags,g->ngener*g->ngener);
368     
369     nblock_bc(cr,g->ngtc,g->nrdf);
370     nblock_bc(cr,g->ngtc,g->tau_t);
371     nblock_bc(cr,g->ngtc,g->ref_t);
372     nblock_bc(cr,g->ngacc,g->acc);
373     nblock_bc(cr,g->ngfrz,g->nFreeze);
374     nblock_bc(cr,g->ngener*g->ngener,g->egp_flags);
375     snew_bc(cr,g->annealing,g->ngtc);
376     snew_bc(cr,g->anneal_npoints,g->ngtc);
377     snew_bc(cr,g->anneal_time,g->ngtc);
378     snew_bc(cr,g->anneal_temp,g->ngtc);
379     nblock_bc(cr,g->ngtc,g->annealing);
380     nblock_bc(cr,g->ngtc,g->anneal_npoints);
381     for(i=0;(i<g->ngtc); i++) {
382         n = g->anneal_npoints[i];
383         if (n > 0) {
384           snew_bc(cr,g->anneal_time[i],n);
385           snew_bc(cr,g->anneal_temp[i],n);
386           nblock_bc(cr,n,g->anneal_time[i]);
387           nblock_bc(cr,n,g->anneal_temp[i]);
388         }
389     }
390     
391     /* QMMM stuff, see inputrec */
392     block_bc(cr,g->ngQM);
393     snew_bc(cr,g->QMmethod,g->ngQM);
394     snew_bc(cr,g->QMbasis,g->ngQM);
395     snew_bc(cr,g->QMcharge,g->ngQM);
396     snew_bc(cr,g->QMmult,g->ngQM);
397     snew_bc(cr,g->bSH,g->ngQM);
398     snew_bc(cr,g->CASorbitals,g->ngQM);
399     snew_bc(cr,g->CASelectrons,g->ngQM);
400     snew_bc(cr,g->SAon,g->ngQM);
401     snew_bc(cr,g->SAoff,g->ngQM);
402     snew_bc(cr,g->SAsteps,g->ngQM);
403     
404     if (g->ngQM)
405     {
406         nblock_bc(cr,g->ngQM,g->QMmethod);
407         nblock_bc(cr,g->ngQM,g->QMbasis);
408         nblock_bc(cr,g->ngQM,g->QMcharge);
409         nblock_bc(cr,g->ngQM,g->QMmult);
410         nblock_bc(cr,g->ngQM,g->bSH);
411         nblock_bc(cr,g->ngQM,g->CASorbitals);
412         nblock_bc(cr,g->ngQM,g->CASelectrons);
413         nblock_bc(cr,g->ngQM,g->SAon);
414         nblock_bc(cr,g->ngQM,g->SAoff);
415         nblock_bc(cr,g->ngQM,g->SAsteps);
416         /* end of QMMM stuff */
417     }
418 }
419
420 static void bc_cosines(const t_commrec *cr,t_cosines *cs)
421 {
422   block_bc(cr,cs->n);
423   snew_bc(cr,cs->a,cs->n);
424   snew_bc(cr,cs->phi,cs->n);
425   if (cs->n > 0) {
426     nblock_bc(cr,cs->n,cs->a);
427     nblock_bc(cr,cs->n,cs->phi);
428   }
429 }
430
431 static void bc_pullgrp(const t_commrec *cr,t_pullgrp *pgrp)
432 {
433   block_bc(cr,*pgrp);
434   if (pgrp->nat > 0) {
435     snew_bc(cr,pgrp->ind,pgrp->nat);
436     nblock_bc(cr,pgrp->nat,pgrp->ind);
437   }
438   if (pgrp->nweight > 0) {
439     snew_bc(cr,pgrp->weight,pgrp->nweight);
440     nblock_bc(cr,pgrp->nweight,pgrp->weight);
441   }
442 }
443
444 static void bc_pull(const t_commrec *cr,t_pull *pull)
445 {
446   int g;
447
448   block_bc(cr,*pull);
449   snew_bc(cr,pull->grp,pull->ngrp+1);
450   for(g=0; g<pull->ngrp+1; g++)
451   {
452       bc_pullgrp(cr,&pull->grp[g]);
453   }
454 }
455
456 static void bc_rotgrp(const t_commrec *cr,t_rotgrp *rotg)
457 {
458   block_bc(cr,*rotg);
459   if (rotg->nat > 0) {
460     snew_bc(cr,rotg->ind,rotg->nat);
461     nblock_bc(cr,rotg->nat,rotg->ind);
462     snew_bc(cr,rotg->x_ref,rotg->nat);
463     nblock_bc(cr,rotg->nat,rotg->x_ref);
464   }
465 }
466
467 static void bc_rot(const t_commrec *cr,t_rot *rot)
468 {
469   int g;
470
471   block_bc(cr,*rot);
472   snew_bc(cr,rot->grp,rot->ngrp);
473   for(g=0; g<rot->ngrp; g++)
474     bc_rotgrp(cr,&rot->grp[g]);
475 }
476
477 static void bc_adress(const t_commrec *cr,t_adress *adress)
478 {
479   block_bc(cr,*adress);
480   if (adress->n_tf_grps > 0) {
481       snew_bc(cr, adress->tf_table_index, adress->n_tf_grps);
482       nblock_bc(cr, adress->n_tf_grps, adress->tf_table_index);
483   }
484   if (adress->n_energy_grps > 0) {
485       snew_bc(cr, adress->group_explicit, adress->n_energy_grps);
486       nblock_bc(cr, adress->n_energy_grps, adress->group_explicit);
487   }
488 }
489 static void bc_fepvals(const t_commrec *cr,t_lambda *fep)
490 {
491     gmx_bool bAlloc=TRUE;
492     int i;
493
494     block_bc(cr,fep->nstdhdl);
495     block_bc(cr,fep->init_lambda);
496     block_bc(cr,fep->init_fep_state);
497     block_bc(cr,fep->delta_lambda);
498     block_bc(cr,fep->bPrintEnergy);
499     block_bc(cr,fep->n_lambda);
500     snew_bc(cr,fep->all_lambda,efptNR);
501     nblock_bc(cr,efptNR,fep->all_lambda);
502     for (i=0;i<efptNR;i++) {
503         snew_bc(cr,fep->all_lambda[i],fep->n_lambda);
504         nblock_bc(cr,fep->n_lambda,fep->all_lambda[i]);
505     }
506     block_bc(cr,fep->sc_alpha);
507     block_bc(cr,fep->sc_power);
508     block_bc(cr,fep->sc_r_power);
509     block_bc(cr,fep->sc_sigma);
510     block_bc(cr,fep->sc_sigma_min);
511     block_bc(cr,fep->bScCoul);
512     nblock_bc(cr,efptNR,&(fep->separate_dvdl[0]));
513     block_bc(cr,fep->dhdl_derivatives);
514     block_bc(cr,fep->dh_hist_size);
515     block_bc(cr,fep->dh_hist_spacing);
516     if (debug)
517     {
518         fprintf(debug,"after bc_fepvals\n");
519     }
520 }
521
522 static void bc_expandedvals(const t_commrec *cr,t_expanded *expand, int n_lambda)
523 {
524     gmx_bool bAlloc=TRUE;
525     int i;
526
527     block_bc(cr,expand->nstexpanded);
528     block_bc(cr,expand->elamstats);
529     block_bc(cr,expand->elmcmove);
530     block_bc(cr,expand->elmceq);
531     block_bc(cr,expand->equil_n_at_lam);
532     block_bc(cr,expand->equil_wl_delta);
533     block_bc(cr,expand->equil_ratio);
534     block_bc(cr,expand->equil_steps);
535     block_bc(cr,expand->equil_samples);
536     block_bc(cr,expand->lmc_seed);
537     block_bc(cr,expand->minvar);
538     block_bc(cr,expand->minvar_const);
539     block_bc(cr,expand->c_range);
540     block_bc(cr,expand->bSymmetrizedTMatrix);
541     block_bc(cr,expand->nstTij);
542     block_bc(cr,expand->lmc_repeats);
543     block_bc(cr,expand->lmc_forced_nstart);
544     block_bc(cr,expand->gibbsdeltalam);
545     block_bc(cr,expand->wl_scale);
546     block_bc(cr,expand->wl_ratio);
547     block_bc(cr,expand->init_wl_delta);
548     block_bc(cr,expand->bInit_weights);
549     snew_bc(cr,expand->init_lambda_weights,n_lambda);
550     nblock_bc(cr,n_lambda,expand->init_lambda_weights);
551     block_bc(cr,expand->mc_temp);
552     if (debug)
553     {
554         fprintf(debug,"after bc_expandedvals\n");
555     }
556 }
557
558 static void bc_simtempvals(const t_commrec *cr,t_simtemp *simtemp, int n_lambda)
559 {
560     gmx_bool bAlloc=TRUE;
561     int i;
562
563     block_bc(cr,simtemp->simtemp_low);
564     block_bc(cr,simtemp->simtemp_high);
565     block_bc(cr,simtemp->eSimTempScale);
566     snew_bc(cr,simtemp->temperatures,n_lambda);
567     nblock_bc(cr,n_lambda,simtemp->temperatures);
568     if (debug)
569     {
570         fprintf(debug,"after bc_simtempvals\n");
571     }
572 }
573
574 static void bc_inputrec(const t_commrec *cr,t_inputrec *inputrec)
575 {
576   gmx_bool bAlloc=TRUE;
577   int i;
578
579   block_bc(cr,*inputrec);
580
581   bc_grpopts(cr,&(inputrec->opts));
582
583   /* even if efep is efepNO, we need to initialize to make sure that
584    * n_lambda is set to zero */
585
586   snew_bc(cr,inputrec->fepvals,1);
587   if (inputrec->efep != efepNO || inputrec->bSimTemp) 
588   {
589       bc_fepvals(cr,inputrec->fepvals);
590   }
591   /* need to initialize this as well because of data checked for in the logic */
592   snew_bc(cr,inputrec->expandedvals,1);
593   if (inputrec->bExpanded)
594   {
595       bc_expandedvals(cr,inputrec->expandedvals,inputrec->fepvals->n_lambda);
596   }
597   snew_bc(cr,inputrec->simtempvals,1);
598   if (inputrec->bSimTemp)
599   {
600       bc_simtempvals(cr,inputrec->simtempvals,inputrec->fepvals->n_lambda);
601   }
602   if (inputrec->ePull != epullNO) {
603     snew_bc(cr,inputrec->pull,1);
604     bc_pull(cr,inputrec->pull);
605   }
606   if (inputrec->bRot) {
607     snew_bc(cr,inputrec->rot,1);
608     bc_rot(cr,inputrec->rot);
609   }
610   for(i=0; (i<DIM); i++) {
611     bc_cosines(cr,&(inputrec->ex[i]));
612     bc_cosines(cr,&(inputrec->et[i]));
613   }
614   if (inputrec->bAdress) {
615       snew_bc(cr,inputrec->adress,1);
616       bc_adress(cr,inputrec->adress);
617   }
618 }
619
620 static void bc_moltype(const t_commrec *cr,t_symtab *symtab,
621                        gmx_moltype_t *moltype)
622 {
623   bc_string(cr,symtab,&moltype->name);
624   bc_atoms(cr,symtab,&moltype->atoms);
625   if (debug) fprintf(debug,"after bc_atoms\n");
626
627   bc_ilists(cr,moltype->ilist);
628   bc_block(cr,&moltype->cgs);
629   bc_blocka(cr,&moltype->excls);
630 }
631
632 static void bc_molblock(const t_commrec *cr,gmx_molblock_t *molb)
633 {
634   gmx_bool bAlloc=TRUE;
635   
636   block_bc(cr,molb->type);
637   block_bc(cr,molb->nmol);
638   block_bc(cr,molb->natoms_mol);
639   block_bc(cr,molb->nposres_xA);
640   if (molb->nposres_xA > 0) {
641     snew_bc(cr,molb->posres_xA,molb->nposres_xA);
642     nblock_bc(cr,molb->nposres_xA*DIM,molb->posres_xA[0]);
643   }
644   block_bc(cr,molb->nposres_xB);
645   if (molb->nposres_xB > 0) {
646     snew_bc(cr,molb->posres_xB,molb->nposres_xB);
647     nblock_bc(cr,molb->nposres_xB*DIM,molb->posres_xB[0]);
648   }
649   if (debug) fprintf(debug,"after bc_molblock\n");
650 }
651
652 static void bc_atomtypes(const t_commrec *cr, t_atomtypes *atomtypes)
653 {
654   int nr;
655
656   block_bc(cr,atomtypes->nr);
657
658   nr = atomtypes->nr;
659
660   snew_bc(cr,atomtypes->radius,nr);
661   snew_bc(cr,atomtypes->vol,nr);
662   snew_bc(cr,atomtypes->surftens,nr);
663   snew_bc(cr,atomtypes->gb_radius,nr);
664   snew_bc(cr,atomtypes->S_hct,nr);
665
666   nblock_bc(cr,nr,atomtypes->radius);
667   nblock_bc(cr,nr,atomtypes->vol);
668   nblock_bc(cr,nr,atomtypes->surftens);
669   nblock_bc(cr,nr,atomtypes->gb_radius);
670   nblock_bc(cr,nr,atomtypes->S_hct);
671 }
672
673
674 void bcast_ir_mtop(const t_commrec *cr,t_inputrec *inputrec,gmx_mtop_t *mtop)
675 {
676   int i; 
677   if (debug) fprintf(debug,"in bc_data\n");
678   bc_inputrec(cr,inputrec);
679   if (debug) fprintf(debug,"after bc_inputrec\n");
680   bc_symtab(cr,&mtop->symtab);
681   if (debug) fprintf(debug,"after bc_symtab\n");
682   bc_string(cr,&mtop->symtab,&mtop->name);
683   if (debug) fprintf(debug,"after bc_name\n");
684
685   bc_ffparams(cr,&mtop->ffparams);
686
687   block_bc(cr,mtop->nmoltype);
688   snew_bc(cr,mtop->moltype,mtop->nmoltype);
689   for(i=0; i<mtop->nmoltype; i++) {
690     bc_moltype(cr,&mtop->symtab,&mtop->moltype[i]);
691   }
692
693   block_bc(cr,mtop->nmolblock);
694   snew_bc(cr,mtop->molblock,mtop->nmolblock);
695   for(i=0; i<mtop->nmolblock; i++) {
696     bc_molblock(cr,&mtop->molblock[i]);
697   }
698
699   block_bc(cr,mtop->natoms);
700
701   bc_atomtypes(cr,&mtop->atomtypes);
702
703   bc_block(cr,&mtop->mols);
704   bc_groups(cr,&mtop->symtab,mtop->natoms,&mtop->groups);
705 }