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 * Good ROcking Metal Altar for Chronical Sinners
33 static char *SRCID_network_h
= "$Id$";
36 #ident "@(#) network.h 1.9 11/23/92"
37 #endif /* HAVE_IDENT */
40 * This module defines the interface of the actual communication routines.
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))
55 * These macro's can be used as shown in the following examples:
59 * struct {float x,y} coordinate;
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
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
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 ******************************************************/
185 /********************************************************
187 * Some routines, do not have an implementation everywhere,
188 * for these there are defaults using our low-level routines.
190 *******************************************************/
192 extern void def_wait(int send
,int receive
);
193 #define gmx_wait def_wait
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
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
208 extern void def_stat(FILE *fp
,char *msg
);
209 #define gmx_stat def_stat
212 #ifndef gmx_reset_idle
213 extern void def_reset_idle(void);
214 #define gmx_reset_idle def_reset_idle
218 extern void def_sumf(int nr
,float r
[],t_commrec
*cr
);
219 #define gmx_sumf def_sumf
223 extern void def_sumd(int nr
,double r
[],t_commrec
*cr
);
224 #define gmx_sumd def_sumd
228 extern void def_sumi(int nr
,int r
[],t_commrec
*cr
);
229 #define gmx_sumi def_sumi
233 #define gmx_sum gmx_sumd
235 #define gmx_sum gmx_sumf
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)
245 #endif /* _network_h */