Original WRF subgrid support version from John Michalakes without fire
[wrffire.git] / wrfv2_fire / external / RSL / RSL / rsl_comm.h
blob8fc4c80e3f3752f36379fc2de20b1d63d289ad43
1 /***********************************************************************
3 COPYRIGHT
5 The following is a notice of limited availability of the code and
6 Government license and disclaimer which must be included in the
7 prologue of the code and in all source listings of the code.
9 Copyright notice
10 (c) 1977 University of Chicago
12 Permission is hereby granted to use, reproduce, prepare
13 derivative works, and to redistribute to others at no charge. If
14 you distribute a copy or copies of the Software, or you modify a
15 copy or copies of the Software or any portion of it, thus forming
16 a work based on the Software and make and/or distribute copies of
17 such work, you must meet the following conditions:
19 a) If you make a copy of the Software (modified or verbatim)
20 it must include the copyright notice and Government
21 license and disclaimer.
23 b) You must cause the modified Software to carry prominent
24 notices stating that you changed specified portions of
25 the Software.
27 This software was authored by:
29 Argonne National Laboratory
30 J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
31 Mathematics and Computer Science Division
32 Argonne National Laboratory, Argonne, IL 60439
34 ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
35 OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
36 AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
37 CONTRACT WITH THE DEPARTMENT OF ENERGY.
39 GOVERNMENT LICENSE AND DISCLAIMER
41 This computer code material was prepared, in part, as an account
42 of work sponsored by an agency of the United States Government.
43 The Government is granted for itself and others acting on its
44 behalf a paid-up, nonexclusive, irrevocable worldwide license in
45 this data to reproduce, prepare derivative works, distribute
46 copies to the public, perform publicly and display publicly, and
47 to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
48 NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
49 THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
50 ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
51 COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
52 PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
53 NOT INFRINGE PRIVATELY OWNED RIGHTS.
55 ***************************************************************************/
59 #ifndef RSL_COMM_H
60 #define RSL_COMM_H
62 /* #define STUBS */
64 /***********************************************************************
65 Below is a mapping of the message passing macros that are used in RSL,
66 the library package that supports the model (there is no explicit
67 message passing in the model code itself -- all of that is encapsulated
68 within RSL).
70 # define RSL_OPEN0(A,B) open0_( &(A), &(B), &rsl_idum )
71 # define RSL_CLOSE0() close0_()
72 # define RSL_WHO(A,B) who0_( &(A), &(B), &rsl_idum )
73 # define RSL_RECV(A,B,C) recv0_( A, &(B), &(C) )
74 # define RSL_SEND(A,B,C,D) send0_( A, &(B), &(C), &(D) )
75 # define RSL_RECVBEGIN(A,B,C) recvbegin0_( A, &(B), &(C) )
76 # define RSL_SENDBEGIN(A,B,C,D) sendbegin0_( A, &(B), &(C), &(D) )
77 # define RSL_RECVEND(A) recvend0_( &(A) )
78 # define RSL_SENDEND(A) sendend0_( &(A) )
79 # define RSL_PROBE(A,B) rsl_probe_( &(A), B )
81 In this particular fragment, the macros are defined to PICL calls,
82 but that is just incidental.
84 RSL_OPEN0(A,B)
85 RSL_CLOSE0()
87 This will map to whatever routine the underlying mp library requires
88 for startup and initialization/shutdown. It can just be a noop if the
89 mp lib in use does not require initialization. As far as RSL is concerned,
90 arguments A and B are dummys.
92 RSL_WHO(A,B)
94 This will map to the informational routine in the mp library that
95 returns number of nodes in partition (returned as A) and the node
96 number of the local processor (returned as B).
98 RSL_RECV(A,B,C)
100 This is the synchronous recv (like crecv in NX). A is a pointer
101 to the buffer, B is the length in bytes, and C is the integer
102 message tag.
104 RSL_SEND(A,B,C,D)
106 This is the synchronous send (like csend in NX). A is a pointer
107 to the buffer, B is the length in bytes, and C is the integer
108 message tag. D is the node number of the destination processor.
110 RSL_RECVBEGIN(A,B,C)
112 This is the asynchronous version of RSL_RECV. It records the message
113 descriptor returned by the OS, posts the receive and then returns
114 control to the calling program. In NX is it implemented using
115 irecv.
117 RSL_RECVEND(A)
119 This is the call the blocks until completion of the message started
120 with RSL_RECVBEGIN. The argument, A, is the integer tag of the
121 message (the third argument, C, of the original RSL_RECVBEGIN call).
122 Using the tag, the routine looks up the OS descriptor for the original
123 message and then issues the mp library call to block on that message
124 (in the case of NX, the routine called is msgwait).
127 RSL_SENDBEGIN(A,B,C,D)
129 This is the asynchronous version of RSL_SEND. It records the message
130 descriptor returned by the OS, posts the send and then returns
131 control to the calling program. In NX is it implemented using
132 isend.
134 RSL_SENDEND(A)
136 This is the call the blocks until completion of the message started
137 with RSL_SENDBEGIN. The argument, A, is the integer tag of the
138 message (the third argument, C, of the original RSL_SENDBEGIN call).
139 Using the tag, the routine looks up the OS descriptor for the original
140 message and then issues the mp library call to block on that message
141 (in the case of NX, the routine called is msgwait).
143 RSL_PROBE(A,B)
145 This maps to the mp library routine for checking on the status of
146 an asynchronously posted receive. This is *not* currently in use
147 but may be needed at some point in the future.
151 John
152 ***********************************************************************/
154 #ifdef STUBS
156 # define RSL_OPEN0 {RSL_TEST_WRN(1,"COMMUNICATIONS STUBBED!");}
157 # define RSL_CLOSE0()
158 # define RSL_WHO(A,B) { A = 1 ; B = 0 ; }
159 # define RSL_RECV(A,B,C)
160 # define RSL_SEND(A,B,C,D)
161 # define RSL_RECVBEGIN(A,B,C)
162 # define RSL_SENDBEGIN(A,B,C,D)
163 # define RSL_RECVEND(A)
164 # define RSL_SENDEND(A)
165 # define RSL_PROBE(A,B) { *(B) = 1 ; }
167 #else
168 #ifdef PGON
170 # define RSL_OPEN0(A,B) rslNXInit()
171 # define RSL_CLOSE0
172 # define RSL_WHO(A,B) { A = numnodes(); B = mynode(); }
173 # define RSL_RECV(A,B,C) crecv ((long)(C),A,(long)(B))
174 # define RSL_SEND(A,B,C,D) csend ((long)(C),A,(long)(B),(long)(D),(long)0)
175 # define RSL_RECVBEGIN(A,B,C) rslNXIRecv ( A, B, C )
176 # define RSL_SENDBEGIN(A,B,C,D) rslNXISend ( A, B, C, D )
177 # define RSL_RECVEND(A) rslNXWait ( A )
178 # define RSL_SENDEND(A) rslNXWait ( A )
179 # define RSL_PROBE(A,B) rslNXProbe ( A, B )
180 /* # define RSL_PROBE(A,B) (*(B) = (iprobe ( A ) == 1)) */
182 #else
183 #ifdef MPL
184 /* map down to native MPL primitives of SP[12] */
186 # ifdef __MPL_COMPAT__
187 int rsl_mp_source ;
188 int rsl_mp_nbytes ;
189 int rsl_mp_n ;
190 int rsl_mp_type ;
192 int dontcare ;
193 int allmsg ;
194 int nulltask ;
195 int allgrp ;
196 int type_low ;
197 int type_high ;
199 # else
200 extern int rsl_mp_source ;
201 extern int rsl_mp_nbytes ;
202 extern int rsl_mp_type ;
203 extern int rsl_mp_n ;
205 extern int dontcare ;
206 extern int allmsg ;
207 extern int nulltask ;
208 extern int allgrp ;
209 extern int type_low ;
210 extern int type_high ;
212 # endif
214 # define RSL_OPEN0(A,B) rslMPLInit()
215 # define RSL_CLOSE0()
216 # define RSL_WHO(A,B) mpc_environ( &(A), &(B) )
218 # define RSL_RECV(A,B,C) \
219 { int rc ; \
220 rsl_mp_source = dontcare ;\
221 rsl_mp_type = C ;\
222 rsl_mp_n = B ;\
223 if ( rsl_mp_type < type_low || rsl_mp_type > type_high ) \
225 sprintf(mess,"RSL_RECV message type %d out of allowed range: %d..%d\n", \
226 rsl_mp_type,type_low,type_high) ; \
227 RSL_TEST_ERR( 1, mess ) ; \
229 rc = mpc_brecv(A,rsl_mp_n, \
230 &rsl_mp_source, \
231 &rsl_mp_type, \
232 &rsl_mp_nbytes) ; \
233 if ( rc ) {fprintf(stderr,"mpc_brecv returns %d\n",rc);exit(1);} \
234 if ( rsl_mp_nbytes > (B) ) \
236 fprintf(stderr,"Message too large: tag %d, recvd %d, allocated %d\n", \
237 C,rsl_mp_nbytes,(B)); \
241 # define RSL_SEND(A,B,C,D) \
243 int rc ; \
244 rsl_mp_type = C ; \
245 if ( rsl_mp_type < type_low || rsl_mp_type > type_high ) \
247 sprintf(mess,"RSL_SEND message type %d out of allowed range: %d..%d\n", \
248 rsl_mp_type,type_low,type_high) ; \
249 RSL_TEST_ERR( 1, mess ) ; \
251 if (0) fprintf(stderr,"mpc_bsend: nlen %10d type %10d dest %10d\n", \
252 B, rsl_mp_type, D ) ; \
253 rc = mpc_bsend(A,B,D,C) ; \
254 if ( rc ) {fprintf(stderr,"mpc_bsend returns %d\n",rc);exit(1);} \
257 # define RSL_RECVBEGIN(A,B,C) rslMPLIRecv ( A, B, C )
258 # define RSL_SENDBEGIN(A,B,C,D) rslMPLISend ( A, B, C, D )
259 # define RSL_RECVEND(A) rslMPLWait ( A )
260 # define RSL_SENDEND(A) rslMPLWait ( A )
261 # define RSL_PROBE(A,B) rslMPLProbe( A, B )
263 #else
264 #ifdef MPI
266 # include "mpi.h"
267 /* EXTERN is defined in rsl.h */
269 EXTERN MPI_Comm rsl_mpi_communicator ;
271 # ifdef __MPI_COMPAT__
272 MPI_Status mpi_status ;
273 # else
274 extern MPI_Status mpi_status ;
275 # endif
277 # define RSL_OPEN0(A,B) rslMPIInit()
278 # define RSL_CLOSE0() MPI_Finalize()
279 # define RSL_WHO(A,B) rslMPIWho( &(A), &(B) )
281 # define RSL_RECV(A,B,C) \
283 MPI_Recv(A,B,MPI_BYTE,MPI_ANY_SOURCE,C,rsl_mpi_communicator,&mpi_status) ; \
286 # define RSL_SEND(A,B,C,D) MPI_Send(A,B,MPI_BYTE,D,C,rsl_mpi_communicator)
287 # define RSL_RECVBEGIN(A,B,C) rslMPIIRecv ( A, B, C )
288 # define RSL_SENDBEGIN(A,B,C,D) rslMPIISend ( A, B, C, D )
289 # define RSL_RECVEND(A) rslMPIWait ( A )
290 # define RSL_SENDEND(A) rslMPIWait ( A )
291 # define RSL_PROBE(A,B) /* rslMPITest ( A, B ) */
293 #else
294 #ifdef CHAMELEON
296 #include "tools.h"
297 #include "comm/comm.h"
299 # define RSL_OPEN0(A,B) rslCHAMInit()
300 # define RSL_CLOSE0
301 # define RSL_WHO(A,B) who0_( &(A), &(B), &rsl_idum )
302 # define RSL_RECV(A,B,C) PIbrecv( C, A, B, MSG_OTHER )
303 # define RSL_SEND(A,B,C,D) PIbsend( C, A, B, D, MSG_OTHER )
304 # define RSL_RECVBEGIN(A,B,C) rslCHAMRecv( A, B, C )
305 # define RSL_SENDBEGIN(A,B,C,D) rslCHAMSend( A, B, C, D )
306 # define RSL_RECVEND(A) rslCHAMWait( A, 1 )
307 # define RSL_SENDEND(A) rslCHAMWait( A, 0 )
308 # define RSL_PROBE(A,B) ( &(A), B )
311 else
313 # ifndef NOUNDERSCORE
315 # ifdef CHAMELEON_PICL
316 # define RSL_OPEN0(A,B) /* a noop */
317 # else
318 # define RSL_OPEN0(A,B) open0_( &(A), &(B), &rsl_idum )
319 # endif
320 # define RSL_CLOSE0
321 # define RSL_WHO(A,B) who0_( &(A), &(B), &rsl_idum )
322 # define RSL_RECV(A,B,C) recv0_( A, &(B), &(C) )
323 # define RSL_SEND(A,B,C,D) send0_( A, &(B), &(C), &(D) )
324 # define RSL_RECVBEGIN(A,B,C) recvbegin0_( A, &(B), &(C) )
325 # define RSL_SENDBEGIN(A,B,C,D) sendbegin0_( A, &(B), &(C), &(D) )
326 # define RSL_RECVEND(A) recvend0_( &(A) )
327 # define RSL_SENDEND(A) sendend0_( &(A) )
328 # define RSL_PROBE(A,B) rsl_probe_( &(A), B )
331 # else
333 # ifdef CHAMELEON_PICL_ooo
334 # define RSL_OPEN0(A,B) /* a noop */
335 # else
336 # define RSL_OPEN0(A,B) open0( &(A), &(B), &rsl_idum )
337 # endif
338 # define RSL_CLOSE0
339 # define RSL_WHO(A,B) who0( &(A), &(B), &rsl_idum )
340 # define RSL_RECV(A,B,C) recv0( A, &(B), &(C) )
341 # define RSL_SEND(A,B,C,D) send0( A, &(B), &(C), &(D) )
342 # define RSL_RECVBEGIN(A,B,C) recvbegin0( A, &(B), &(C) )
343 # define RSL_SENDBEGIN(A,B,C,D) sendbegin0( A, &(B), &(C), &(D) )
344 # define RSL_RECVEND(A) recvend0( &(A) )
345 # define RSL_SENDEND(A) sendend0( &(A) )
346 # define RSL_PROBE(A,B) rsl_probe( &(A), B )
348 # endif /* NOUNDERSCORE */
350 #endif /* CHAMELEON */
351 #endif /* MPI */
352 #endif /* MPL */
353 #endif /* PGON */
354 #endif /* STUBS */
358 #endif /* nothing after this line */