ccde422f1aefe035ee76be0d42162d407b06bace
[alexxy/gromacs.git] / include / network.h
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
11  * 
12  * Copyright (c) 1991-1999
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
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)
20  * 
21  * Also check out our WWW page:
22  * http://md.chem.rug.nl/~gmx
23  * or e-mail to:
24  * gromacs@chem.rug.nl
25  * 
26  * And Hey:
27  * Good ROcking Metal Altar for Chronical Sinners
28  */
29
30 #ifndef _network_h
31 #define _network_h
32
33 static char *SRCID_network_h = "$Id$";
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifdef HAVE_IDENT
40 #ident  "@(#) network.h 1.9 11/23/92"
41 #endif /* HAVE_IDENT */
42
43 /*
44  * This module defines the interface of the actual communication routines.
45  */
46
47 #include <stdio.h>
48 #include "typedefs.h"
49 #include "main.h"
50 #include "fatal.h"
51
52 #define LEFT     0          /* channel to the left processor  */
53 #define RIGHT    1          /* channel to the right processor */
54
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))
58 /* 
59  * These macro's can be used as shown in the following examples:
60  *
61  * int chan=1;
62  * int nr;
63  * struct {float x,y} coordinate;
64  * int arr[10];
65  *
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
71  */
72
73 /****************************************************** 
74  *
75  * Here are the communication routines to be called from GROMACS
76  * programs!
77  *
78  * The following 9 routines MUST be overridden !!!!!!!!
79  * (for parallel processing)
80  *
81  * For sequential processing dummies are in Kernel/sys/libnet.c
82  *
83  ******************************************************/
84 extern void gmx_tx(int chan,void *buf,int bufsize);
85      /*
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).
89       */
90
91 extern void gmx_tx_wait(int chan);
92      /*
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.
96       */
97
98 extern void gmx_txs(int chan,void *buf,int bufsize);
99      /*
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 
104       * gmx_txs() returns.
105       */
106
107 extern void gmx_rx(int chan,void *buf,int bufsize);
108      /*
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).
112       */
113
114 extern void gmx_rx_wait(int chan);
115      /*
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.
119       */
120
121 extern void gmx_rxs(int chan,void *buf,int bufsize);
122      /*
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.
128       */
129
130 extern int gmx_node_num(void);
131 /* return the number of nodes in the ring */
132
133 extern int gmx_node_id(void);
134 /* return the identification ID of the node */
135       
136 extern void gmx_left_right(int nnodes,int nodeid,int *left,int *right);
137 /* Get left and right proc id. */
138
139 /****************************************************** 
140  *
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?)
144  *
145  ******************************************************/
146 extern void gmx_stat(FILE *fp,char *msg);
147 /* Prints a overview of the status of the network, useful for debugging. */
148
149 extern void gmx_reset_idle(void);
150 /* Reset the idle count */
151
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);
154
155 extern void gmx_wait(int send,int receive);
156
157 extern void gmx_sync_ring(int nodeid,int nnodes,int left,int right);
158 /* Synchronise the ring... */
159
160 extern void gmx_sumi(int nr,int r[],t_commrec *cr);
161 /* Calculate the global sum of an array of ints */
162
163 extern void gmx_sumf(int nr,float r[],t_commrec *cr);
164 /* Calculate the global sum of an array of floats */
165
166 extern void gmx_sumd(int nr,double r[],t_commrec *cr);
167 /* Calculate the global sum of an array of doubles */
168
169 /******************************************************
170  *
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!
174  *
175  ******************************************************/
176
177 #ifdef USE_MPI
178 #include "mpiio.h"
179 #endif
180
181 /********************************************************
182  *
183  * Some routines, do not have an implementation everywhere,
184  * for these there are defaults using our low-level routines.
185  *
186  *******************************************************/
187 #ifndef gmx_wait
188 extern  void def_wait(int send,int receive);
189 #define gmx_wait def_wait
190 #endif
191
192 #ifndef gmx_tx_rx
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
196 #endif 
197
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
201 #endif
202
203 #ifndef gmx_stat
204 extern  void def_stat(FILE *fp,char *msg);
205 #define gmx_stat def_stat
206 #endif
207
208 #ifndef gmx_reset_idle
209 extern  void def_reset_idle(void);
210 #define gmx_reset_idle def_reset_idle
211 #endif
212
213 #ifndef gmx_sumf
214 extern  void def_sumf(int nr,float r[],t_commrec *cr);
215 #define gmx_sumf def_sumf
216 #endif
217
218 #ifndef gmx_sumd
219 extern  void def_sumd(int nr,double r[],t_commrec *cr);
220 #define gmx_sumd def_sumd
221 #endif
222
223 #ifndef gmx_sumi
224 extern  void def_sumi(int nr,int r[],t_commrec *cr);
225 #define gmx_sumi def_sumi
226 #endif
227
228 #ifdef DOUBLE
229 #define gmx_sum gmx_sumd
230 #else
231 #define gmx_sum gmx_sumf
232 #endif
233
234 #ifdef DEBUG_GMX
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)
237 #else
238 #define debug_gmx()
239 #endif
240
241 #endif  /* _network_h */