Added conditional inclusion of config.h to source files
[gromacs.git] / src / gmxlib / mvdata.c
blob93b400764b08e8b2baf80ee64e26886f68bc60de
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * GROningen Mixture of Alchemy and Childrens' Stories
36 /* This file is completely threadsafe - keep it that way! */
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
41 #include <sysstuff.h>
42 #include <string.h>
43 #include "typedefs.h"
44 #include "main.h"
45 #include "assert.h"
46 #include "mvdata.h"
47 #include "network.h"
48 #include "smalloc.h"
49 #include "fatal.h"
50 #include "symtab.h"
51 #include "vec.h"
52 #include "tgroup.h"
53 #include "block_tx.h"
55 static void ld_nsb(int src,t_nsborder *nsb)
57 blockrx(src,nsb->nnodes);
58 blockrx(src,nsb->shift);
59 blockrx(src,nsb->bshift);
60 blockrx(src,nsb->nstDlb);
61 blockrx(src,nsb->cgtotal);
62 blockrx(src,nsb->natoms);
63 nblockrx(src,MAXNODES,nsb->homenr);
64 nblockrx(src,MAXNODES,nsb->index);
65 nblockrx(src,MAXNODES,nsb->cgload);
66 nblockrx(src,MAXNODES,nsb->workload);
69 static char **ld_string(int src,t_symtab *symtab)
71 int name;
73 blockrx(src,name);
74 return get_symtab_handle(symtab,name);
77 static int ld_strings(int src,t_symtab *symtab,char ****nm)
79 int i,nr;
80 int *handle;
81 char ***NM;
83 blockrx(src,nr);
84 snew(handle,nr);
85 nblockrx(src,nr,handle);
87 snew(*nm,nr);
88 NM=*nm;
89 for (i=0; (i<nr); i++)
90 NM[i]=get_symtab_handle(symtab,handle[i]);
91 sfree(handle);
93 return nr;
96 static void ld_symtab(int src,t_symtab *symtab)
98 int i,nr,len;
100 blockrx(src,symtab->nr);
101 nr=symtab->nr;
102 snew(symtab->symbuf,1);
103 symtab->symbuf->bufsize=nr;
104 snew(symtab->symbuf->buf,nr);
105 for (i=0; i<nr; i++)
107 blockrx(src,len);
108 snew(symtab->symbuf->buf[i],len);
109 nblockrx(src,len,symtab->symbuf->buf[i]);
113 static void ld_grps(int src,t_grps grps[])
115 int i;
117 for(i=0; (i<egcNR); i++) {
118 blockrx(src,grps[i].nr);
119 snew(grps[i].nm_ind,grps[i].nr);
120 nblockrx(src,grps[i].nr,grps[i].nm_ind);
122 for( ; (i<egcNR); i++) {
123 grps[i].nr=0;
124 grps[i].nm_ind=NULL;
128 static void ld_atoms(int src,t_symtab *symtab,t_atoms *atoms)
130 int atomnr;
132 blockrx(src,atoms->nr);
133 snew(atoms->atom,atoms->nr);
134 nblockrx(src,atoms->nr,atoms->atom);
135 atomnr=ld_strings(src,symtab,&atoms->atomname);
136 assert(atomnr==atoms->nr);
137 atoms->nres=ld_strings(src,symtab,&atoms->resname);
138 atoms->ngrpname=ld_strings(src,symtab,&atoms->grpname);
139 ld_grps(src,atoms->grps);
140 ld_block(src,&atoms->excl);
143 static void ld_state(int src,t_state *state)
145 blockrx(src,state->natoms);
146 blockrx(src,state->ngtc);
147 blockrx(src,state->box);
148 blockrx(src,state->boxv);
149 blockrx(src,state->pcoupl_mu);
150 nblockrx(src,state->ngtc,state->nosehoover_xi);
151 nblockrx(src,state->ngtc,state->tcoupl_lambda);
152 nblockrx(src,state->natoms,state->x);
153 nblockrx(src,state->natoms,state->v);
156 static void ld_ilist(int src,t_ilist *ilist)
158 blockrx(src,ilist->nr);
159 nblockrx(src,MAXNODES,ilist->multinr);
160 snew(ilist->iatoms,ilist->nr);
161 nblockrx(src,ilist->nr,ilist->iatoms);
164 static void ld_idef(int src,t_idef *idef)
166 int i;
168 blockrx(src,idef->ntypes);
169 blockrx(src,idef->atnr);
170 snew(idef->functype,idef->ntypes);
171 snew(idef->iparams,idef->ntypes);
172 nblockrx(src,idef->ntypes,idef->functype);
173 nblockrx(src,idef->ntypes,idef->iparams);
174 for(i=0; (i<F_NRE); i++)
175 ld_ilist(src,&idef->il[i]);
178 static void ld_grpopts(int src,t_grpopts *g)
180 int i,n;
182 blockrx(src,g->ngtc);
183 blockrx(src,g->ngacc);
184 blockrx(src,g->ngfrz);
185 blockrx(src,g->ngener);
186 snew(g->nrdf,g->ngtc);
187 snew(g->tau_t,g->ngtc);
188 snew(g->ref_t,g->ngtc);
189 snew(g->acc,g->ngacc);
190 snew(g->nFreeze,g->ngfrz);
191 snew(g->eg_excl,g->ngener*g->ngener);
192 nblockrx(src,g->ngtc,g->nrdf);
193 nblockrx(src,g->ngtc,g->tau_t);
194 nblockrx(src,g->ngtc,g->ref_t);
195 nblockrx(src,g->ngacc,g->acc);
196 nblockrx(src,g->ngfrz,g->nFreeze);
197 nblockrx(src,g->ngener*g->ngener,g->eg_excl);
198 snew(g->annealing,g->ngtc);
199 snew(g->anneal_npoints,g->ngtc);
200 snew(g->anneal_time,g->ngtc);
201 snew(g->anneal_temp,g->ngtc);
202 nblockrx(src,g->ngtc,g->annealing);
203 nblockrx(src,g->ngtc,g->anneal_npoints);
204 for(i=0;(i<g->ngtc); i++) {
205 n = g->anneal_npoints[i];
206 if (n > 0) {
207 snew(g->anneal_time[i],n);
208 snew(g->anneal_temp[i],n);
209 nblockrx(src,n,g->anneal_time[i]);
210 nblockrx(src,n,g->anneal_temp[i]);
215 static void ld_cosines(int src,t_cosines *cs)
217 blockrx(src,cs->n);
218 snew(cs->a,cs->n);
219 snew(cs->phi,cs->n);
220 if (cs->n > 0) {
221 nblockrx(src,cs->n,cs->a);
222 nblockrx(src,cs->n,cs->phi);
226 static void ld_parm(int src,t_parm *parm)
228 int i;
230 blockrx(src,*parm);
231 ld_grpopts(src,&(parm->ir.opts));
232 for(i=0; (i<DIM); i++) {
233 ld_cosines(src,&(parm->ir.ex[i]));
234 ld_cosines(src,&(parm->ir.et[i]));
238 void ld_data(int left,int right,t_parm *parm,t_nsborder *nsb,
239 t_topology *top,t_state *state)
241 int i;
243 ld_parm(left,parm);
244 if (debug) fprintf(stdlog,"after ld_parm");
245 ld_nsb(left,nsb);
246 if (debug) fprintf(stdlog,"after ld_nsb");
247 ld_symtab(left,&top->symtab);
248 if (debug) fprintf(stdlog,"after ld_symtab");
249 top->name=ld_string(left,&top->symtab);
250 if (debug) fprintf(stdlog,"after ld_name");
251 ld_atoms(left,&top->symtab,&top->atoms);
252 if (debug) fprintf(stdlog,"after ld_atoms");
253 ld_idef(left,&top->idef);
254 if (debug) fprintf(stdlog,"after ld_idef");
255 for (i=0; (i<ebNR); i++)
256 ld_block(left,&top->blocks[i]);
257 if (debug) fprintf(stdlog,"after ld_block");
258 snew(state->nosehoover_xi,parm->ir.opts.ngtc);
259 snew(state->tcoupl_lambda,parm->ir.opts.ngtc);
260 snew(state->x,top->atoms.nr);
261 snew(state->v,top->atoms.nr);
262 ld_state(left,state);
263 if (debug) fprintf(stdlog,"after ld_state");
266 static void mv_grpopts(int dest,t_grpopts *g)
268 int i,n;
270 blocktx(dest,g->ngtc);
271 blocktx(dest,g->ngacc);
272 blocktx(dest,g->ngfrz);
273 blocktx(dest,g->ngener);
274 nblocktx(dest,g->ngtc,g->nrdf);
275 nblocktx(dest,g->ngtc,g->tau_t);
276 nblocktx(dest,g->ngtc,g->ref_t);
277 nblocktx(dest,g->ngacc,g->acc);
278 nblocktx(dest,g->ngfrz,g->nFreeze);
279 nblocktx(dest,g->ngener*g->ngener,g->eg_excl);
280 nblocktx(dest,g->ngtc,g->annealing);
281 nblocktx(dest,g->ngtc,g->anneal_npoints);
282 for(i=0;(i<g->ngtc); i++) {
283 n = g->anneal_npoints[i];
284 if (n > 0) {
285 nblocktx(dest,n,g->anneal_time[i]);
286 nblocktx(dest,n,g->anneal_temp[i]);
291 static void mv_cosines(int dest,t_cosines *cs)
293 blocktx(dest,cs->n);
294 if (cs->n > 0) {
295 nblocktx(dest,cs->n,cs->a);
296 nblocktx(dest,cs->n,cs->phi);
300 static void mv_parm(int dest,t_parm *parm)
302 int i;
304 blocktx(dest,*parm);
305 mv_grpopts(dest,&(parm->ir.opts));
306 for(i=0; (i<DIM); i++) {
307 mv_cosines(dest,&(parm->ir.ex[i]));
308 mv_cosines(dest,&(parm->ir.et[i]));
312 static void mv_nsb(int dest,t_nsborder *nsb)
314 blocktx(dest,nsb->nnodes);
315 blocktx(dest,nsb->shift);
316 blocktx(dest,nsb->bshift);
317 blocktx(dest,nsb->nstDlb);
318 blocktx(dest,nsb->cgtotal);
319 blocktx(dest,nsb->natoms);
320 nblocktx(dest,MAXNODES,nsb->homenr);
321 nblocktx(dest,MAXNODES,nsb->index);
322 nblocktx(dest,MAXNODES,nsb->cgload);
323 nblocktx(dest,MAXNODES,nsb->workload);
326 static void mv_string(int dest,t_symtab *symtab,char **s)
328 int handle;
330 handle=lookup_symtab(symtab,s);
331 blocktx(dest,handle);
334 static void mv_strings(int dest,t_symtab *symtab,int nr,
335 char ***nm)
337 int i;
338 int *handle;
340 snew(handle,nr);
341 for(i=0; (i<nr); i++)
342 handle[i]=lookup_symtab(symtab,nm[i]);
343 blocktx(dest,nr);
344 nblocktx(dest,nr,handle);
345 sfree(handle);
348 static void mv_symtab(int dest,t_symtab *symtab)
350 int i,nr,len;
351 struct symbuf *symbuf;
353 blocktx(dest,symtab->nr);
354 nr=symtab->nr;
355 symbuf=symtab->symbuf;
356 while (symbuf!=NULL)
358 for (i=0; (i<symbuf->bufsize)&&(i<nr); i++)
360 len=strlen(symbuf->buf[i])+1;
361 blocktx(dest,len);
362 nblocktx(dest,len,symbuf->buf[i]);
364 nr-=i;
365 symbuf=symbuf->next;
367 assert(nr==0);
370 static void mv_grps(int dest,t_grps grps[])
372 int i;
374 for(i=0; (i<egcNR); i++) {
375 blocktx(dest,grps[i].nr);
376 nblocktx(dest,grps[i].nr,grps[i].nm_ind);
381 static void mv_atoms(int dest,t_symtab *symtab,t_atoms *atoms)
383 int nr;
385 nr=atoms->nr;
386 blocktx(dest,nr);
387 nblocktx(dest,nr,atoms->atom);
388 mv_strings(dest,symtab,atoms->nr,atoms->atomname);
389 mv_strings(dest,symtab,atoms->nres,atoms->resname);
390 mv_strings(dest,symtab,atoms->ngrpname,atoms->grpname);
391 mv_grps(dest,atoms->grps);
392 mv_block(dest,&atoms->excl);
395 static void mv_state(int dest,t_state *state)
397 blocktx(dest,state->natoms);
398 blocktx(dest,state->ngtc);
399 blocktx(dest,state->box);
400 blocktx(dest,state->boxv);
401 blocktx(dest,state->pcoupl_mu);
402 nblocktx(dest,state->ngtc,state->nosehoover_xi);
403 nblocktx(dest,state->ngtc,state->tcoupl_lambda);
404 nblocktx(dest,state->natoms,state->x);
405 nblocktx(dest,state->natoms,state->v);
408 static void mv_ilist(int dest,t_ilist *ilist)
410 blocktx(dest,ilist->nr);
411 nblocktx(dest,MAXNODES,ilist->multinr);
412 nblocktx(dest,ilist->nr,ilist->iatoms);
415 static void mv_idef(int dest,t_idef *idef)
417 int i;
419 blocktx(dest,idef->ntypes);
420 blocktx(dest,idef->atnr);
421 nblocktx(dest,idef->ntypes,idef->functype);
422 nblocktx(dest,idef->ntypes,idef->iparams);
423 for(i=0; (i<F_NRE); i++)
424 mv_ilist(dest,&idef->il[i]);
427 void mv_data(int left,int right,t_parm *parm,t_nsborder *nsb,
428 t_topology *top,t_state *state)
430 int i;
432 mv_parm(right,parm);
433 mv_nsb(right,nsb);
434 mv_symtab(right,&top->symtab);
435 mv_string(right,&top->symtab,top->name);
436 mv_atoms(right,&top->symtab,&top->atoms);
437 mv_idef(right,&top->idef);
438 for (i=0; (i<ebNR); i++)
439 mv_block(right,&top->blocks[i]);
440 mv_state(right,state);