changed reading hint
[gromacs/adressmacs.git] / include / network.h
blob52d52e7b4cf4a52d491c2eade0fc65a8f50ec3b0
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 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
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
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Good ROcking Metal Altar for Chronical Sinners
30 #ifndef _network_h
31 #define _network_h
33 static char *SRCID_network_h = "$Id$";
35 #ifdef HAVE_IDENT
36 #ident "@(#) network.h 1.9 11/23/92"
37 #endif /* HAVE_IDENT */
40 * This module defines the interface of the actual communication routines.
43 #include <stdio.h>
44 #include "typedefs.h"
45 #include "main.h"
46 #include "fatal.h"
48 #define LEFT 0 /* channel to the left processor */
49 #define RIGHT 1 /* channel to the right processor */
51 #define record(rec) &(rec),sizeof(rec)
52 #define array(arr,nr) (arr),((nr)*sizeof((arr)[0]))
53 #define arrayp(el,nr) &(el),((nr)*sizeof(el))
54 /*
55 * These macro's can be used as shown in the following examples:
57 * int chan=1;
58 * int nr;
59 * struct {float x,y} coordinate;
60 * int arr[10];
62 * gmx_rxs(chan,record(nr)); receive data in nr
63 * gmx_txs(chan,record(coordinate)); sends data from coordinate
64 * gmx_rxs(chan,array(arr,10)); sends an array of 10 elements
65 * gmx_rxs(chan,arrayp(arr[3],4)); receives an array of 4 elements
66 * and stores it starting at element 3
69 /******************************************************
71 * Here are the communication routines to be called from GROMACS
72 * programs!
74 * The following 9 routines MUST be overridden !!!!!!!!
75 * (for parallel processing)
77 * For sequential processing dummies are in Kernel/sys/libnet.c
79 ******************************************************/
80 extern void gmx_tx(int chan,void *buf,int bufsize);
82 * Asynchronously sends bufsize bytes from the buffer pointed to by buf
83 * over the communication channel, identified by chan. The buffer becomes
84 * available after a successful call of gmx_tx_wait(chan).
87 extern void gmx_tx_wait(int chan);
89 * Waits until the asynchronous send operation associated with chan has
90 * succeeded. This makes the buffer of the send operation available to
91 * the sending process.
94 extern void gmx_txs(int chan,void *buf,int bufsize);
96 * Synchronously sends bufsize bytes from the buffer pointed to by buf to
97 * the processor/process identified by chan. This is implemented by a call
98 * to gmx_tx(chan,buf,bufsize), directly followed by a call to
99 * gmx_tx_wait(chan), so the buffer is available after
100 * gmx_txs() returns.
103 extern void gmx_rx(int chan,void *buf,int bufsize);
105 * Asynchronously receives bufsize bytes in the buffer pointed to by buf
106 * from communication channel identified by chan. The buffer becomes
107 * available after a successful call of gmx_rx_wait(chan).
110 extern void gmx_rx_wait(int chan);
112 * Waits until the asynchronous receive operation, associated with chan,
113 * has succeeded. This makes the buffer of the receive operation
114 * available to the receiving process.
117 extern void gmx_rxs(int chan,void *buf,int bufsize);
119 * Synchronously receives bufsize bytes from the buffer pointed to by
120 * buf over the communication channel identified by chan. This is
121 * implemented by a call to gmx_rx(chan,buf,bufsize), directly
122 * followed by a call to gmx_rx_wait(chan), so the buffer is
123 * available after gmx_rxs() returns.
126 extern int gmx_cpu_num(void);
127 /* return the number of cpus in the ring */
129 extern int gmx_cpu_id(void);
130 /* return the identification ID of the cpu */
132 extern void gmx_left_right(int nprocs,int pid,int *left,int *right);
133 /* Get left and right proc id. */
135 /******************************************************
137 * Here are some routines that are platform independent.
138 * In principle they might be overridden by more efficient
139 * routines for particular library packages (pvm, mpi?)
141 ******************************************************/
142 extern void gmx_stat(FILE *fp,char *msg);
143 /* Prints a overview of the status of the network, useful for debugging. */
145 extern void gmx_reset_idle(void);
146 /* Reset the idle count */
148 extern void gmx_tx_rx(int send_pid,void *send_buf,int send_bufsize,
149 int rec_pid,void *rec_buf,int rec_bufsize);
151 extern void gmx_wait(int send,int receive);
153 extern void gmx_sync_ring(int pid,int nprocs,int left,int right);
154 /* Synchronise the ring... */
156 extern void gmx_sumi(int nr,int r[],t_commrec *cr);
157 /* Calculate the global sum of an array of ints */
159 extern void gmx_sumf(int nr,float r[],t_commrec *cr);
160 /* Calculate the global sum of an array of floats */
162 extern void gmx_sumd(int nr,double r[],t_commrec *cr);
163 /* Calculate the global sum of an array of doubles */
165 /******************************************************
167 * These routines are now superseded by a macro...
168 * Each of the communication libraries may override the
169 * macros, hopefully the compiler will tell you!
171 ******************************************************/
173 #ifdef USE_CM5
174 #include "cm5io.h"
175 #endif
177 #ifdef USE_PVM3
178 #include "pvmio.h"
179 #endif
181 #ifdef USE_MPI
182 #include "mpiio.h"
183 #endif
185 /********************************************************
187 * Some routines, do not have an implementation everywhere,
188 * for these there are defaults using our low-level routines.
190 *******************************************************/
191 #ifndef gmx_wait
192 extern void def_wait(int send,int receive);
193 #define gmx_wait def_wait
194 #endif
196 #ifndef gmx_tx_rx
197 extern void def_tx_rx(int send_pid,void *send_buf,int send_bufsize,
198 int rec_pid,void *rec_buf,int rec_bufsize);
199 #define gmx_tx_rx def_tx_rx
200 #endif
202 #ifndef gmx_sync_ring
203 extern void def_sync_ring(int pid,int nprocs,int left,int right);
204 #define gmx_sync_ring def_sync_ring
205 #endif
207 #ifndef gmx_stat
208 extern void def_stat(FILE *fp,char *msg);
209 #define gmx_stat def_stat
210 #endif
212 #ifndef gmx_reset_idle
213 extern void def_reset_idle(void);
214 #define gmx_reset_idle def_reset_idle
215 #endif
217 #ifndef gmx_sumf
218 extern void def_sumf(int nr,float r[],t_commrec *cr);
219 #define gmx_sumf def_sumf
220 #endif
222 #ifndef gmx_sumd
223 extern void def_sumd(int nr,double r[],t_commrec *cr);
224 #define gmx_sumd def_sumd
225 #endif
227 #ifndef gmx_sumi
228 extern void def_sumi(int nr,int r[],t_commrec *cr);
229 #define gmx_sumi def_sumi
230 #endif
232 #ifdef DOUBLE
233 #define gmx_sum gmx_sumd
234 #else
235 #define gmx_sum gmx_sumf
236 #endif
238 #ifdef DEBUG_GMX
239 #define debug_gmx() do { FILE *fp=debug ? debug : (stdlog ? stdlog : stderr);\
240 if (bDebugMode()) fprintf(fp,"PID=%d, %s %d\n",gmx_cpu_id(),__FILE__,__LINE__); fflush(fp); } while (0)
241 #else
242 #define debug_gmx()
243 #endif
245 #endif /* _network_h */