Partial commit of the project to remove all static variables.
[gromacs.git] / include / network.h
blob4311464bf0d07e608827571b6e98ee592a3b2585
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.1
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
29 * And Hey:
30 * Getting the Right Output Means no Artefacts in Calculating Stuff
32 #ifndef _network_h
33 #define _network_h
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
42 * This module defines the interface of the actual communication routines.
45 #include <stdio.h>
46 #include "typedefs.h"
47 #include "main.h"
48 #include "fatal.h"
50 #define LEFT 0 /* channel to the left processor */
51 #define RIGHT 1 /* channel to the right processor */
53 #define record(rec) &((rec)),sizeof(rec)
54 #define array(arr,nr) (arr),((nr)*sizeof((arr)[0]))
55 #define arrayp(el,nr) &((el)),((nr)*sizeof(el))
56 /*
57 * These macro's can be used as shown in the following examples:
59 * int chan=1;
60 * int nr;
61 * struct {float x,y} coordinate;
62 * int arr[10];
64 * gmx_rxs(chan,record(nr)); receive data in nr
65 * gmx_txs(chan,record(coordinate)); sends data from coordinate
66 * gmx_rxs(chan,array(arr,10)); sends an array of 10 elements
67 * gmx_rxs(chan,arrayp(arr[3],4)); receives an array of 4 elements
68 * and stores it starting at element 3
71 /******************************************************
73 * Here are the communication routines to be called from GROMACS
74 * programs!
76 * The following 9 routines MUST be overridden !!!!!!!!
77 * (for parallel processing)
79 * For sequential processing dummies are in src/gmxlib/libnet.c
81 ******************************************************/
82 extern void gmx_tx(int chan,void *buf,int bufsize);
84 * Asynchronously sends bufsize bytes from the buffer pointed to by buf
85 * over the communication channel, identified by chan. The buffer becomes
86 * available after a successful call of gmx_tx_wait(chan).
89 extern void gmx_tx_wait(int chan);
91 * Waits until the asynchronous send operation associated with chan has
92 * succeeded. This makes the buffer of the send operation available to
93 * the sending process.
96 extern void gmx_txs(int chan,void *buf,int bufsize);
98 * Synchronously sends bufsize bytes from the buffer pointed to by buf to
99 * the processor/process identified by chan. This is implemented by a call
100 * to gmx_tx(chan,buf,bufsize), directly followed by a call to
101 * gmx_tx_wait(chan), so the buffer is available after
102 * gmx_txs() returns.
105 extern void gmx_rx(int chan,void *buf,int bufsize);
107 * Asynchronously receives bufsize bytes in the buffer pointed to by buf
108 * from communication channel identified by chan. The buffer becomes
109 * available after a successful call of gmx_rx_wait(chan).
112 extern void gmx_rx_wait(int chan);
114 * Waits until the asynchronous receive operation, associated with chan,
115 * has succeeded. This makes the buffer of the receive operation
116 * available to the receiving process.
119 extern void gmx_rxs(int chan,void *buf,int bufsize);
121 * Synchronously receives bufsize bytes from the buffer pointed to by
122 * buf over the communication channel identified by chan. This is
123 * implemented by a call to gmx_rx(chan,buf,bufsize), directly
124 * followed by a call to gmx_rx_wait(chan), so the buffer is
125 * available after gmx_rxs() returns.
128 extern int gmx_setup(int *argc,char **argv,int *nnodes);
129 /* Initializes the parallel communication, return the ID of the node */
131 extern int gmx_node_num(void);
132 /* return the number of nodes in the ring */
134 extern int gmx_node_id(void);
135 /* return the identification ID of the node */
137 extern void gmx_left_right(int nnodes,int nodeid,int *left,int *right);
138 /* Get left and right proc id. */
140 extern void gmx_stat(FILE *fp,char *msg);
141 /* Prints a overview of the status of the network, useful for debugging. */
143 extern void gmx_reset_idle(void);
144 /* Reset the idle count */
146 extern void gmx_tx_rx(int send_nodeid,void *send_buf,int send_bufsize,
147 int rec_nodeid,void *rec_buf,int rec_bufsize);
148 /* Communicate simultaneously left and right */
150 extern void gmx_tx_rx_real(int send_nodeid,real *send_buf,int send_bufsize,
151 int rec_nodeid,real *rec_buf,int rec_bufsize);
152 /* Communicate simultaneously left and right, reals only */
154 extern void gmx_wait(int send,int receive);
155 /* Wait for communication to finish */
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 extern void gmx_abort(int nodeid,int nnodes,int errorno);
170 /* Abort the parallel run */
172 extern void gmx_finalize(void);
173 /* Finish the parallel run in an ordered manner */
175 #ifdef DOUBLE
176 #define gmx_sum gmx_sumd
177 #else
178 #define gmx_sum gmx_sumf
179 #endif
181 #ifdef DEBUG_GMX
182 #define debug_gmx() do { FILE *fp=debug ? debug : (stdlog ? stdlog : stderr);\
183 if (bDebugMode()) fprintf(fp,"NODEID=%d, %s %d\n",gmx_node_id(),__FILE__,__LINE__); fflush(fp); } while (0)
184 #else
185 #define debug_gmx()
186 #endif
188 #endif /* _network_h */