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