Original WRF subgrid support version from John Michalakes without fire
[wrffire.git] / wrfv2_fire / external / RSL / RSL / picl_mpl_compat.c
blob0ec081b46c82a4775484d1d75bd82bde731319ec
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 ***************************************************************************/
57 #ifdef MPL
58 #ifndef __MPL_COMPAT__
59 #define __MPL_COMPAT__
61 #include <stdio.h>
63 typedef unsigned int MPL_Request ;
64 typedef unsigned int MPL_Status ;
66 #define PICLHandleInc 128
68 struct tagsToHandles
70 int tag;
71 MPL_Request Handle;
72 int type ; /* send = 1, recv = 2 */
73 int nbytes ;
75 struct piclMPLHandles
77 int nHandles;
78 int nUsed;
79 struct tagsToHandles *tags;
80 } piclMPLHandleLUT;
82 /******************************************************
83 * piclMPLInit ()
84 * do whatever initialization is necessary for the
85 * MPL port
87 * Initial coding: Leslie Hart, 22 Apr 94
88 * Adapted to MPL: J. Michalakes 7/13/94
89 * Adapted to PICL from RSL: J. Michalakes 7/13/94
91 *****************************************************/
93 static int argc_dummy = 0 ;
94 static char * argv_dummy = "" ;
96 int dontcare ;
97 int allmsg ;
98 int nulltask ;
99 int allgrp ;
100 int type_low ;
101 int type_high ;
104 * setarc0
107 void setarc0( i1, i2, i3, i4 ) /* noop */
108 int *i1, *i2, *i3, *i4 ;
109 { return ; }
112 * check0
115 void check0( i1 ) /* noop */
116 int *i1 ;
117 { return ; }
120 * open0
123 void open0( nprocs, me, dum )
124 int *nprocs, *me, *dum ;
126 int nbuf[4] ;
128 piclMPLHandleLUT.nHandles = PICLHandleInc;
129 piclMPLHandleLUT.nUsed = 0;
130 piclMPLHandleLUT.tags = (struct tagsToHandles *)
131 malloc (sizeof (struct tagsToHandles) * PICLHandleInc);
133 mpc_task_query( nbuf, 2, 2 ) ;
134 type_low = nbuf[0] ;
135 type_high= nbuf[1] ;
136 mpc_task_query( nbuf, 4, 3 ) ;
137 dontcare = nbuf[0] ;
138 allmsg = nbuf[1] ;
139 nulltask = nbuf[2] ;
140 allgrp = nbuf[3] ;
142 #if 0
143 fprintf(stderr,"piclMPLInit: \n") ;
144 fprintf(stderr,"type_low: %d\n",type_low) ;
145 fprintf(stderr,"type_high: %d\n",type_high) ;
146 fprintf(stderr,"dontcare: %d\n",dontcare) ;
147 fprintf(stderr,"allmsg: %d\n",allmsg) ;
148 fprintf(stderr,"nulltask: %d\n",nulltask) ;
149 fprintf(stderr,"allgrp: %d\n",allgrp) ;
150 #endif
153 if (piclMPLHandleLUT.tags == NULL)
155 fprintf (stderr, "Fatal Error: malloc failure in piclMPLInit\n");
156 exit(1);
159 who0( nprocs, me, dum ) ;
163 * who0
165 who0( nprocs, me, dum )
166 int *nprocs, *me, *dum ;
168 mpc_environ( nprocs, me ) ;
172 * clock0
174 double clock0()
176 fprintf(stderr,"Warning -- clock0 is stubbed in %s\n", __FILE__ ) ;
177 return(0.0) ; /* stub for now */
181 * recv0
184 recv0( buf, len, type )
185 char *buf ;
186 int *len, *type ;
188 int rc ;
189 int rsl_mp_source ;
190 int rsl_mp_type ;
191 int rsl_mp_n ;
193 rsl_mp_type = *type ;
194 rsl_mp_n = *len ;
196 if ( rsl_mp_type < type_low || rsl_mp_type > type_high )
198 sprintf(mess,"RSL_RECV message type %d out of allowed range: %d..%d\n",
199 rsl_mp_type,type_low,type_high) ;
200 RSL_TEST_ERR( 1, mess ) ;
202 rc = mpc_brecv(buf,rsl_mp_n,
203 &rsl_mp_source,
204 &rsl_mp_type,
205 &rsl_mp_nbytes) ;
206 if ( rc ) {fprintf(stderr,"mpc_brecv returns %d\n",rc);exit(1);}
207 if ( rsl_mp_nbytes > (*len) )
209 fprintf(stderr,"Message too large: tag %d, recvd %d, allocated %d\n",
210 *type,rsl_mp_nbytes,(*len));
215 * send0
218 send0( buf, len, type, dest )
219 char *buf ;
220 int *len, *type, *dest ;
222 int rc ;
223 int rsl_mp_type ;
225 rsl_mp_type = *type ;
226 if ( rsl_mp_type < type_low || rsl_mp_type > type_high )
228 sprintf(mess,"RSL_SEND message type %d out of allowed range: %d..%d\n",
229 rsl_mp_type,type_low,type_high) ;
230 RSL_TEST_ERR( 1, mess ) ;
232 if (0) fprintf(stderr,"mpc_bsend: nlen %10d type %10d dest %10d\n", \
233 B, rsl_mp_type, D ) ; \
234 rc = mpc_bsend(A,B,D,C) ; \
235 if ( rc ) {fprintf(stderr,"mpc_bsend returns %d\n",rc);exit(1);} \
241 /******************************************************
242 * piclMPLFindWaitH (tag)
243 * Use the LUT to find an MPL wait handle from a tag
245 * Initial coding: Leslie Hart, 22 Apr 94
247 *****************************************************/
249 long piclMPLFindWaitH (tag, waitHandle, type, nbytes )
250 int tag; /* Tag for which we lookup a wait handle */
251 MPL_Request *waitHandle ;
252 int *type, *nbytes ;
254 int i;
255 long retVal = -1;
257 for (i=0; i < piclMPLHandleLUT.nUsed; i++)
259 if (piclMPLHandleLUT.tags[i].tag == tag)
261 *waitHandle = piclMPLHandleLUT.tags[i].Handle;
262 *type = piclMPLHandleLUT.tags[i].type;
263 *nbytes = piclMPLHandleLUT.tags[i].nbytes;
264 piclMPLHandleLUT.nUsed--; /* Keep them contiguous */
265 piclMPLHandleLUT.tags[i].tag=piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].tag;
266 piclMPLHandleLUT.tags[i].Handle=
267 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].Handle;
268 piclMPLHandleLUT.tags[i].type=
269 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].type;
270 piclMPLHandleLUT.tags[i].nbytes=
271 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].nbytes ;
272 retVal = 0 ;
273 break;
276 return( retVal ) ;
279 /******************************************************
280 * piclMPLSaveWaitH (tag, waitHandle)
281 * Use the LUT to save an MPL wait handle referenced by a tag
283 * Initial coding: Leslie Hart, 22 Apr 94
285 *****************************************************/
287 void piclMPLSaveWaitH (tag, waitHandle,type,nbytes)
288 int tag;
289 MPL_Request * waitHandle;
290 int type, nbytes ;
292 /* Make sure there is enough space, if not, try a realloc */
293 /* If the realloc fails we're in deep trouble */
294 if (piclMPLHandleLUT.nUsed == piclMPLHandleLUT.nHandles)
296 struct tagsToHandles *tags; /* Temp pointer */
297 tags = (struct tagsToHandles *)
298 realloc (piclMPLHandleLUT.tags,
299 sizeof (struct tagsToHandles) * (piclMPLHandleLUT.nHandles + PICLHandleInc));
300 if (tags != NULL)
302 piclMPLHandleLUT.tags = tags;
303 piclMPLHandleLUT.nHandles += PICLHandleInc;
305 else
307 #ifdef FATAL_ERRORS
308 fprintf (stderr, "Fatal Error: realloc failure in piclMPLSaveWaitH\n");
309 exit(1);
310 #endif
311 return;
314 /* Stash the handle */
315 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].tag = tag;
316 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].Handle = *waitHandle;
317 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].type = type ;
318 piclMPLHandleLUT.tags[piclMPLHandleLUT.nUsed].nbytes = nbytes ;
319 piclMPLHandleLUT.nUsed++;
322 /******************************************************
323 * piclMPLISend (buff, mlen, tag, dest)
324 * Post a non blocking send an stash a wait handle
326 * Initial coding: Leslie Hart, 22 Apr 94
328 *****************************************************/
330 void piclMPLISend (buff, mlen, tag, dest)
331 char *buff;
332 int mlen;
333 int tag;
334 int dest;
336 MPL_Request waitHandle;
337 int rc ;
339 if ( tag < type_low || tag > type_high )
341 sprintf(mess,"PICL_SENDBEGIN message type %d out of allowed range: %d..%d\n",
342 tag,type_low,type_high) ;
343 PICL_TEST_ERR( 1, mess ) ;
346 rc = mpc_send (buff,
347 mlen,
348 dest,
349 tag,
350 &waitHandle);
352 #if 0
353 fprintf(stderr,"mpc_send: nlen %10d type %10d dest %10d handle %08x\n",
354 mlen, tag, dest, waitHandle ) ;
355 #endif
357 if ( rc )
359 sprintf(mess,"mpc_send returns %d", rc ) ;
360 PICL_TEST_ERR( 1, mess ) ;
363 piclMPLSaveWaitH (tag, &waitHandle,1,mlen);
366 /******************************************************
367 * piclMPLIRecv (buff, mlen, tag)
368 * Post a non blocking receive an stash a wait handle
370 * Initial coding: Leslie Hart, 22 Apr 94
372 *****************************************************/
374 void piclMPLIRecv (buff, mlen, tag)
375 char *buff;
376 int mlen;
377 int tag;
379 MPL_Request waitHandle;
380 int source ;
381 int tagloc ;
382 int rc ;
384 source = dontcare ;
385 tagloc = tag ;
387 if ( tag < type_low || tag > type_high )
389 sprintf(mess,"PICL_RECVBEGIN message type %d out of allowed range: %d..%d\n",
390 tag,type_low,type_high) ;
391 PICL_TEST_ERR( 1, mess ) ;
395 rc = mpc_recv (buff,
396 mlen,
397 &source,
398 &tagloc,
399 &waitHandle);
401 #if 0
402 fprintf(stderr,"mpc_recv: nlen %10d type %10d source %10d handle %08x\n",
403 mlen, tag, source, waitHandle ) ;
404 #endif
406 if ( rc )
408 sprintf(mess,"mpc_recv returns %d", rc ) ;
409 PICL_TEST_ERR( 1, mess ) ;
412 piclMPLSaveWaitH (tag, &waitHandle, 2, mlen);
415 /******************************************************
416 * piclMPLWait (tag)
417 * Wait for a pending send/recv
419 * Initial coding: Leslie Hart, 22 Apr 94
421 *****************************************************/
423 extern int mperrno ;
425 void piclMPLWait (tag)
426 int tag;
428 MPL_Request waitHandle;
429 MPL_Status status ;
430 int rc ;
431 int type, nbytes;
433 if ( piclMPLFindWaitH (tag, &waitHandle, &type, &nbytes ) != 0 )
435 fprintf(stderr,"piclMPLWait: tag %d not found by piclMPLFindWaitH\n",tag) ;
436 exit(2) ;
439 #if 0
440 fprintf(stderr,"calling mpc_wait: tag %d, handle %08x, type %d (%s), original nbytes %d\n",
441 tag, waitHandle, type, (type==1)?"send":((type==2)?"recv":"unknown"),
442 nbytes) ;
443 #endif
445 rc = mpc_wait ( &waitHandle, &status );
446 if ( rc )
448 fprintf(stderr,"mpc_wait fails: tag %d, handle %08x, type %d (%s), original nbytes %d, status %d, rc %d, mperrno = %d\n",
449 tag, waitHandle, type, (type==1)?"send":((type==2)?"recv":"unknown"),
450 nbytes, status, rc, mperrno) ;
451 exit(2) ;
454 #if 0
455 fprintf(stderr,"mpc_wait : tag %d, handle %08x, status %d\n",
456 tag, waitHandle, status) ;
457 #endif
461 #endif /* __MPL_COMPAT__ */
462 #endif /* MPL */