Tagged files with gromacs 3.0 header and added some license info
[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 3.0
11  * 
12  * Copyright (c) 1991-2001
13  * BIOSON Research Institute, Dept. of Biophysical Chemistry
14  * University of Groningen, The Netherlands
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
32  * 
33  * And Hey:
34  * GRoups of Organic Molecules in ACtion for Science
35  */
36
37 #ifndef _network_h
38 #define _network_h
39
40 static char *SRCID_network_h = "$Id$";
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifdef HAVE_IDENT
46 #ident  "@(#) network.h 1.9 11/23/92"
47 #endif /* HAVE_IDENT */
48
49 /*
50  * This module defines the interface of the actual communication routines.
51  */
52
53 #include <stdio.h>
54 #include "typedefs.h"
55 #include "main.h"
56 #include "fatal.h"
57
58 #define LEFT     0          /* channel to the left processor  */
59 #define RIGHT    1          /* channel to the right processor */
60
61 #define record(rec)     &(rec),sizeof(rec)
62 #define array(arr,nr)   (arr),((nr)*sizeof((arr)[0]))
63 #define arrayp(el,nr)   &(el),((nr)*sizeof(el))
64 /* 
65  * These macro's can be used as shown in the following examples:
66  *
67  * int chan=1;
68  * int nr;
69  * struct {float x,y} coordinate;
70  * int arr[10];
71  *
72  * gmx_rxs(chan,record(nr));            receive data in nr
73  * gmx_txs(chan,record(coordinate));    sends data from coordinate
74  * gmx_rxs(chan,array(arr,10)); sends an array of 10 elements
75  * gmx_rxs(chan,arrayp(arr[3],4));      receives an array of 4 elements
76  *                                      and stores it starting at element 3
77  */
78
79 /****************************************************** 
80  *
81  * Here are the communication routines to be called from GROMACS
82  * programs!
83  *
84  * The following 9 routines MUST be overridden !!!!!!!!
85  * (for parallel processing)
86  *
87  * For sequential processing dummies are in Kernel/sys/libnet.c
88  *
89  ******************************************************/
90 extern void gmx_tx(int chan,void *buf,int bufsize);
91      /*
92       * Asynchronously sends bufsize bytes from the buffer pointed to by buf 
93       * over the communication channel, identified by chan. The buffer becomes 
94       * available after a successful call of gmx_tx_wait(chan).
95       */
96
97 extern void gmx_tx_wait(int chan);
98      /*
99       * Waits until the asynchronous send operation associated with chan has 
100       * succeeded. This makes the buffer of the send operation available to 
101       * the sending process.
102       */
103
104 extern void gmx_txs(int chan,void *buf,int bufsize);
105      /*
106       * Synchronously sends bufsize bytes from the buffer pointed to by buf to
107       * the processor/process identified by chan. This is implemented by a call
108       * to gmx_tx(chan,buf,bufsize), directly followed by a call to 
109       * gmx_tx_wait(chan), so the buffer is available after 
110       * gmx_txs() returns.
111       */
112
113 extern void gmx_rx(int chan,void *buf,int bufsize);
114      /*
115       * Asynchronously receives bufsize bytes in the buffer pointed to by buf 
116       * from communication channel identified by chan. The buffer becomes 
117       * available after a successful call of gmx_rx_wait(chan).
118       */
119
120 extern void gmx_rx_wait(int chan);
121      /*
122       * Waits until the asynchronous receive operation, associated with chan, 
123       * has succeeded. This makes the buffer of the receive operation 
124       * available to the receiving process.
125       */
126
127 extern void gmx_rxs(int chan,void *buf,int bufsize);
128      /*
129       * Synchronously receives bufsize bytes from the buffer pointed to by 
130       * buf over the communication channel identified by chan. This is 
131       * implemented by a call to gmx_rx(chan,buf,bufsize), directly 
132       * followed by a call to gmx_rx_wait(chan), so the buffer is 
133       * available after gmx_rxs() returns.
134       */
135
136 extern int gmx_node_num(void);
137 /* return the number of nodes in the ring */
138
139 extern int gmx_node_id(void);
140 /* return the identification ID of the node */
141       
142 extern void gmx_left_right(int nnodes,int nodeid,int *left,int *right);
143 /* Get left and right proc id. */
144
145 /****************************************************** 
146  *
147  * Here are some routines that are platform independent.
148  * In principle they might be overridden by more efficient
149  * routines for particular library packages (pvm, mpi?)
150  *
151  ******************************************************/
152 extern void gmx_stat(FILE *fp,char *msg);
153 /* Prints a overview of the status of the network, useful for debugging. */
154
155 extern void gmx_reset_idle(void);
156 /* Reset the idle count */
157
158 extern void gmx_tx_rx(int send_nodeid,void *send_buf,int send_bufsize,
159                       int rec_nodeid,void *rec_buf,int rec_bufsize);
160
161 extern void gmx_wait(int send,int receive);
162
163 extern void gmx_sync_ring(int nodeid,int nnodes,int left,int right);
164 /* Synchronise the ring... */
165
166 extern void gmx_sumi(int nr,int r[],t_commrec *cr);
167 /* Calculate the global sum of an array of ints */
168
169 extern void gmx_sumf(int nr,float r[],t_commrec *cr);
170 /* Calculate the global sum of an array of floats */
171
172 extern void gmx_sumd(int nr,double r[],t_commrec *cr);
173 /* Calculate the global sum of an array of doubles */
174
175 /******************************************************
176  *
177  * These routines are now superseded by a macro...
178  * Each of the communication libraries may override the
179  * macros, hopefully the compiler will tell you!
180  *
181  ******************************************************/
182
183 #ifdef USE_MPI
184 #include "mpiio.h"
185 #endif
186
187 /********************************************************
188  *
189  * Some routines, do not have an implementation everywhere,
190  * for these there are defaults using our low-level routines.
191  *
192  *******************************************************/
193 #ifndef gmx_wait
194 extern  void def_wait(int send,int receive);
195 #define gmx_wait def_wait
196 #endif
197
198 #ifndef gmx_tx_rx
199 extern  void def_tx_rx(int send_nodeid,void *send_buf,int send_bufsize,
200                        int rec_nodeid,void *rec_buf,int rec_bufsize);
201 #define gmx_tx_rx def_tx_rx
202 #endif 
203
204 #ifndef gmx_sync_ring
205 extern  void def_sync_ring(int nodeid,int nprocs,int left,int right);
206 #define gmx_sync_ring def_sync_ring
207 #endif
208
209 #ifndef gmx_stat
210 extern  void def_stat(FILE *fp,char *msg);
211 #define gmx_stat def_stat
212 #endif
213
214 #ifndef gmx_reset_idle
215 extern  void def_reset_idle(void);
216 #define gmx_reset_idle def_reset_idle
217 #endif
218
219 #ifndef gmx_sumf
220 extern  void def_sumf(int nr,float r[],t_commrec *cr);
221 #define gmx_sumf def_sumf
222 #endif
223
224 #ifndef gmx_sumd
225 extern  void def_sumd(int nr,double r[],t_commrec *cr);
226 #define gmx_sumd def_sumd
227 #endif
228
229 #ifndef gmx_sumi
230 extern  void def_sumi(int nr,int r[],t_commrec *cr);
231 #define gmx_sumi def_sumi
232 #endif
233
234 #ifdef DOUBLE
235 #define gmx_sum gmx_sumd
236 #else
237 #define gmx_sum gmx_sumf
238 #endif
239
240 #ifdef DEBUG_GMX
241 #define debug_gmx() do { FILE *fp=debug ? debug : (stdlog ? stdlog : stderr);\
242 if (bDebugMode()) fprintf(fp,"NODEID=%d, %s  %d\n",gmx_node_id(),__FILE__,__LINE__); fflush(fp); } while (0)
243 #else
244 #define debug_gmx()
245 #endif
246
247 #endif  /* _network_h */