4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
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.
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.
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.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * GRoups of Organic Molecules in ACtion for Science
40 static char *SRCID_network_h = "$Id$";
46 #ident "@(#) network.h 1.9 11/23/92"
47 #endif /* HAVE_IDENT */
50 * This module defines the interface of the actual communication routines.
58 #define LEFT 0 /* channel to the left processor */
59 #define RIGHT 1 /* channel to the right processor */
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))
65 * These macro's can be used as shown in the following examples:
69 * struct {float x,y} coordinate;
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
79 /******************************************************
81 * Here are the communication routines to be called from GROMACS
84 * The following 9 routines MUST be overridden !!!!!!!!
85 * (for parallel processing)
87 * For sequential processing dummies are in Kernel/sys/libnet.c
89 ******************************************************/
90 extern void gmx_tx(int chan,void *buf,int bufsize);
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).
97 extern void gmx_tx_wait(int chan);
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.
104 extern void gmx_txs(int chan,void *buf,int bufsize);
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
113 extern void gmx_rx(int chan,void *buf,int bufsize);
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).
120 extern void gmx_rx_wait(int chan);
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.
127 extern void gmx_rxs(int chan,void *buf,int bufsize);
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.
136 extern int gmx_node_num(void);
137 /* return the number of nodes in the ring */
139 extern int gmx_node_id(void);
140 /* return the identification ID of the node */
142 extern void gmx_left_right(int nnodes,int nodeid,int *left,int *right);
143 /* Get left and right proc id. */
145 /******************************************************
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?)
151 ******************************************************/
152 extern void gmx_stat(FILE *fp,char *msg);
153 /* Prints a overview of the status of the network, useful for debugging. */
155 extern void gmx_reset_idle(void);
156 /* Reset the idle count */
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);
161 extern void gmx_wait(int send,int receive);
163 extern void gmx_sync_ring(int nodeid,int nnodes,int left,int right);
164 /* Synchronise the ring... */
166 extern void gmx_sumi(int nr,int r[],t_commrec *cr);
167 /* Calculate the global sum of an array of ints */
169 extern void gmx_sumf(int nr,float r[],t_commrec *cr);
170 /* Calculate the global sum of an array of floats */
172 extern void gmx_sumd(int nr,double r[],t_commrec *cr);
173 /* Calculate the global sum of an array of doubles */
175 /******************************************************
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!
181 ******************************************************/
187 /********************************************************
189 * Some routines, do not have an implementation everywhere,
190 * for these there are defaults using our low-level routines.
192 *******************************************************/
194 extern void def_wait(int send,int receive);
195 #define gmx_wait def_wait
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
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
210 extern void def_stat(FILE *fp,char *msg);
211 #define gmx_stat def_stat
214 #ifndef gmx_reset_idle
215 extern void def_reset_idle(void);
216 #define gmx_reset_idle def_reset_idle
220 extern void def_sumf(int nr,float r[],t_commrec *cr);
221 #define gmx_sumf def_sumf
225 extern void def_sumd(int nr,double r[],t_commrec *cr);
226 #define gmx_sumd def_sumd
230 extern void def_sumi(int nr,int r[],t_commrec *cr);
231 #define gmx_sumi def_sumi
235 #define gmx_sum gmx_sumd
237 #define gmx_sum gmx_sumf
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)
247 #endif /* _network_h */