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$";
40 #ident "@(#) network.h 1.9 11/23/92"
41 #endif /* HAVE_IDENT */
44 * This module defines the interface of the actual communication routines.
52 #define LEFT 0 /* channel to the left processor */
53 #define RIGHT 1 /* channel to the right processor */
55 #define record(rec) &(rec),sizeof(rec)
56 #define array(arr,nr) (arr),((nr)*sizeof((arr)[0]))
57 #define arrayp(el,nr) &(el),((nr)*sizeof(el))
59 * These macro's can be used as shown in the following examples:
63 * struct {float x,y} coordinate;
66 * gmx_rxs(chan,record(nr)); receive data in nr
67 * gmx_txs(chan,record(coordinate)); sends data from coordinate
68 * gmx_rxs(chan,array(arr,10)); sends an array of 10 elements
69 * gmx_rxs(chan,arrayp(arr[3],4)); receives an array of 4 elements
70 * and stores it starting at element 3
73 /******************************************************
75 * Here are the communication routines to be called from GROMACS
78 * The following 9 routines MUST be overridden !!!!!!!!
79 * (for parallel processing)
81 * For sequential processing dummies are in Kernel/sys/libnet.c
83 ******************************************************/
84 extern void gmx_tx(int chan,void *buf,int bufsize);
86 * Asynchronously sends bufsize bytes from the buffer pointed to by buf
87 * over the communication channel, identified by chan. The buffer becomes
88 * available after a successful call of gmx_tx_wait(chan).
91 extern void gmx_tx_wait(int chan);
93 * Waits until the asynchronous send operation associated with chan has
94 * succeeded. This makes the buffer of the send operation available to
95 * the sending process.
98 extern void gmx_txs(int chan,void *buf,int bufsize);
100 * Synchronously sends bufsize bytes from the buffer pointed to by buf to
101 * the processor/process identified by chan. This is implemented by a call
102 * to gmx_tx(chan,buf,bufsize), directly followed by a call to
103 * gmx_tx_wait(chan), so the buffer is available after
107 extern void gmx_rx(int chan,void *buf,int bufsize);
109 * Asynchronously receives bufsize bytes in the buffer pointed to by buf
110 * from communication channel identified by chan. The buffer becomes
111 * available after a successful call of gmx_rx_wait(chan).
114 extern void gmx_rx_wait(int chan);
116 * Waits until the asynchronous receive operation, associated with chan,
117 * has succeeded. This makes the buffer of the receive operation
118 * available to the receiving process.
121 extern void gmx_rxs(int chan,void *buf,int bufsize);
123 * Synchronously receives bufsize bytes from the buffer pointed to by
124 * buf over the communication channel identified by chan. This is
125 * implemented by a call to gmx_rx(chan,buf,bufsize), directly
126 * followed by a call to gmx_rx_wait(chan), so the buffer is
127 * available after gmx_rxs() returns.
130 extern int gmx_node_num(void);
131 /* return the number of nodes in the ring */
133 extern int gmx_node_id(void);
134 /* return the identification ID of the node */
136 extern void gmx_left_right(int nnodes,int nodeid,int *left,int *right);
137 /* Get left and right proc id. */
139 /******************************************************
141 * Here are some routines that are platform independent.
142 * In principle they might be overridden by more efficient
143 * routines for particular library packages (pvm, mpi?)
145 ******************************************************/
146 extern void gmx_stat(FILE *fp,char *msg);
147 /* Prints a overview of the status of the network, useful for debugging. */
149 extern void gmx_reset_idle(void);
150 /* Reset the idle count */
152 extern void gmx_tx_rx(int send_nodeid,void *send_buf,int send_bufsize,
153 int rec_nodeid,void *rec_buf,int rec_bufsize);
155 extern void gmx_wait(int send,int receive);
157 extern void gmx_sync_ring(int nodeid,int nnodes,int left,int right);
158 /* Synchronise the ring... */
160 extern void gmx_sumi(int nr,int r[],t_commrec *cr);
161 /* Calculate the global sum of an array of ints */
163 extern void gmx_sumf(int nr,float r[],t_commrec *cr);
164 /* Calculate the global sum of an array of floats */
166 extern void gmx_sumd(int nr,double r[],t_commrec *cr);
167 /* Calculate the global sum of an array of doubles */
169 /******************************************************
171 * These routines are now superseded by a macro...
172 * Each of the communication libraries may override the
173 * macros, hopefully the compiler will tell you!
175 ******************************************************/
181 /********************************************************
183 * Some routines, do not have an implementation everywhere,
184 * for these there are defaults using our low-level routines.
186 *******************************************************/
188 extern void def_wait(int send,int receive);
189 #define gmx_wait def_wait
193 extern void def_tx_rx(int send_nodeid,void *send_buf,int send_bufsize,
194 int rec_nodeid,void *rec_buf,int rec_bufsize);
195 #define gmx_tx_rx def_tx_rx
198 #ifndef gmx_sync_ring
199 extern void def_sync_ring(int nodeid,int nprocs,int left,int right);
200 #define gmx_sync_ring def_sync_ring
204 extern void def_stat(FILE *fp,char *msg);
205 #define gmx_stat def_stat
208 #ifndef gmx_reset_idle
209 extern void def_reset_idle(void);
210 #define gmx_reset_idle def_reset_idle
214 extern void def_sumf(int nr,float r[],t_commrec *cr);
215 #define gmx_sumf def_sumf
219 extern void def_sumd(int nr,double r[],t_commrec *cr);
220 #define gmx_sumd def_sumd
224 extern void def_sumi(int nr,int r[],t_commrec *cr);
225 #define gmx_sumi def_sumi
229 #define gmx_sum gmx_sumd
231 #define gmx_sum gmx_sumf
235 #define debug_gmx() do { FILE *fp=debug ? debug : (stdlog ? stdlog : stderr);\
236 if (bDebugMode()) fprintf(fp,"NODEID=%d, %s %d\n",gmx_node_id(),__FILE__,__LINE__); fflush(fp); } while (0)
241 #endif /* _network_h */