4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_pvmio_c
= "$Id$";
41 #define DEFAULT_STRIDE 1
49 static int tids
[MAXPROC
];
50 static int mypid
=0,mynprocs
=1;
51 static unsigned long idle_send
=0,idle_rec
=0;
53 void pvmio_tx(int dest
,void *buf
,int bufsize
)
57 fprintf(stderr
,"dest: %d, type: %d \n",dest
,PVM_BYTE
);
59 bufid
= pvm_initsend(PvmDataRaw
);
60 info
= pvm_pkbyte(buf
,bufsize
,DEFAULT_STRIDE
);
61 info
= pvm_send(dest
,PVM_BYTE
);
64 char *pvm_error(int errorno
)
66 static t_pvmerr pvmerrs
[] = {
67 -2, "PvmBadParam (giving an invalid argument value)",
68 -6, "PvmNoHost (specified host is not on the virtual machine)",
69 -7, "PvmNoFile (Can not find executable)",
70 -10, "PvmNoMem (not enough memory)",
71 -14, "PvmSysErr (pvmd not responding)",
72 -27, "PvmOutOfRes (out of resources)"
74 static char *deferr
="Unknown Pvm Error";
77 for(i
=0; (i
<asize(pvmerrs
)); i
++)
78 if (errorno
== pvmerrs
[i
].errnok
)
79 return pvmerrs
[i
].msgk
;
84 void pvmio_tx_wait(int dest
)
91 void pvmio_txs(int dest
,void *buf
,int bufsize
)
93 pvmio_tx(dest
,buf
,bufsize
);
97 void pvmio_rx(int src
,void *buf
,int bufsize
)
101 bufid
= pvm_recv(src
,PVM_BYTE
);
103 pvm_upkbyte(buf
,bufsize
,DEFAULT_STRIDE
);
105 fatal_error(0,"Did not receive %d bytes from src %x",bufsize
,src
);
108 void pvmio_rx_wait(int src
)
115 void pvmio_rxs(int src
,void *buf
,int bufsize
)
117 pvmio_rx(src
,buf
,bufsize
);
122 int pvmio_setup(char *argv
[],int nprocs
)
127 if (pvm_parent() == PvmNoParent
) {
128 /* I am the MASTER! Obey me... */
131 fprintf(stderr
,"PVM_MD: Spawning %d tasks\n",nprocs
-1);
132 numt
=pvm_spawn(argv
[0],&(argv
[1]),PvmTaskDefault
,
134 if (numt
!= nprocs
-1) {
135 fprintf(stderr
,"Could only spawn %d tasks!\n",numt
);
136 for(i
=0; (i
<nprocs
); i
++) {
138 fprintf(stderr
,"PVM_MD: tids[%d] = %d --> %s\n",
139 i
,tids
[i
],pvm_error(tids
[i
]));
141 fprintf(stderr
,"PVM_MD: tids[%d] = %d\n",i
,tids
[i
]);
143 fatal_error(0,"Could not spawn %d processes, numt=%d",nprocs
-1,numt
);
145 for(i
=0; (i
<nprocs
); i
++)
146 fprintf(stderr
,"tids[%d]=%x\n",i
,tids
[i
]);
148 for (i
=1; (i
<nprocs
); i
++) {
149 fprintf(stderr
,"pid %d: sending tids to pid %d = tid %x \n",
151 /* Send target id's to everyone */
152 pvmio_tx(tids
[i
],tids
,nprocs
*sizeof(tids
[0]));
154 /* Send index to other CPUS */
155 pvmio_tx(tids
[i
],&i
,sizeof(i
));
159 /* I am a slave, get some tids */
160 bufid
= pvm_recv(ANY_TID
,PVM_BYTE
);
161 info
= pvm_upkbyte((char *)tids
,nprocs
*sizeof(tids
[0]),DEFAULT_STRIDE
);
162 fprintf(stderr
,"Got tids...\n");
164 /* Get my own number */
165 pvmio_rx(tids
[0],&pid
,sizeof(pid
));
170 fprintf(stderr
,"my pid is: %d\n",pid
);
175 void pvmio_stat(FILE *fp
,char *msg
)
177 fprintf(fp
,"pvmio_stat message: %s\n",msg
);
178 fprintf(fp
,"Idle Send: %d\n",idle_send
);
179 fprintf(fp
,"Idle Receive: %d\n",idle_rec
);
182 int pvmnodenumber(void)
187 int pvmnodecount(void)
192 int pvm_idle_send(void)
197 int pvm_idle_rec(void)
202 void pvm_left_right(int nprocs
,int pid
,int *left
,int *right
)
204 *left
=tids
[(pid
-1+nprocs
) % nprocs
];
205 *right
=tids
[(pid
+1) % nprocs
];
206 fprintf(stderr
,"PVM: left=%d, right=%d\n",*left
,*right
); fflush(stderr
);
209 void pvm_reset_idle()
211 idle_send
=0,idle_rec
=0;
214 void pvmio_tx_rx(int send_pid
,void *send_buf
,int send_bufsize
,
215 int rec_pid
,void *rec_buf
,int rec_bufsize
)
217 fatal_error(0,"pvmio_tx_rx called");
220 void pvmio_wait(int send
,int receive
)
223 pvmio_rx_wait(receive
);
226 void pvmio_sync_ring(int pid
,int nprocs
,int left
,int right
)
228 fatal_error(0,"pvmio_sync_ring called");
231 void pvm_abort(int pid
,int nprocs
,int errno
)
235 for(i
=0; i
<nprocs
; i
++)
237 pvm_sendsig(tids
[i
],SIGKILL
);