added README_changes.txt
[wrffire.git] / wrfv2_fire / external / RSL / RSL / rsl_mpl_compat.c
blob5e0168194360039bbde9face06d0033530bb75aa
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>
62 #include "rsl.h"
63 #include "rsl_comm.h"
65 typedef int MPL_Request ;
66 typedef int MPL_Status ;
68 #define RSLHandleInc 32
70 #define FATAL_ERRORS
73 struct tagsToHandles
75 int tag;
76 MPL_Request Handle;
77 int type ; /* send = 1, recv = 2 */
78 int nbytes ;
80 struct rslMPLHandles
82 int nHandles;
83 int nUsed;
84 struct tagsToHandles *tags;
85 } rslMPLHandleLUT;
87 /******************************************************
88 * rslMPLInit ()
89 * do whatever initialization is necessary for the
90 * MPL port
92 * Initial coding: Leslie Hart, 22 Apr 94
93 * Adapted to MPL: J. Michalakes 7/13/94
95 *****************************************************/
97 static int argc_dummy = 0 ;
98 static char * argv_dummy = "" ;
100 int dontcare ;
101 int allmsg ;
102 int nulltask ;
103 int allgrp ;
104 int type_low ;
105 int type_high ;
107 void rslMPLInit()
109 int nbuf[4] ;
111 rslMPLHandleLUT.nHandles = RSLHandleInc;
112 rslMPLHandleLUT.nUsed = 0;
113 rslMPLHandleLUT.tags = (struct tagsToHandles *)
114 malloc (sizeof (struct tagsToHandles) * RSLHandleInc);
116 mpc_task_query( nbuf, 2, 2 ) ;
117 type_low = nbuf[0] ;
118 type_high= nbuf[1] ;
119 mpc_task_query( nbuf, 4, 3 ) ;
120 dontcare = nbuf[0] ;
121 allmsg = nbuf[1] ;
122 nulltask = nbuf[2] ;
123 allgrp = nbuf[3] ;
125 #if 0
126 fprintf(stderr,"rslMPLInit: \n") ;
127 fprintf(stderr,"type_low: %d\n",type_low) ;
128 fprintf(stderr,"type_high: %d\n",type_high) ;
129 fprintf(stderr,"dontcare: %d\n",dontcare) ;
130 fprintf(stderr,"allmsg: %d\n",allmsg) ;
131 fprintf(stderr,"nulltask: %d\n",nulltask) ;
132 fprintf(stderr,"allgrp: %d\n",allgrp) ;
133 #endif
136 #ifdef FATAL_ERRORS
137 if (rslMPLHandleLUT.tags == NULL)
139 fprintf (stderr, "Fatal Error: malloc failure in rslMPLInit\n");
140 exit(1);
142 #endif
146 /******************************************************
147 * rslMPLFindWaitH (tag)
148 * Use the LUT to find an MPL wait handle from a tag
150 * Initial coding: Leslie Hart, 22 Apr 94
152 *****************************************************/
154 long rslMPLFindWaitH (tag, waitHandle, type, nbytes )
155 int tag; /* Tag for which we lookup a wait handle */
156 MPL_Request *waitHandle ;
157 int *type, *nbytes ;
159 int i;
160 long retVal = -1;
162 for (i=0; i < rslMPLHandleLUT.nUsed; i++)
164 if (rslMPLHandleLUT.tags[i].tag == tag)
166 *waitHandle = rslMPLHandleLUT.tags[i].Handle;
167 *type = rslMPLHandleLUT.tags[i].type;
168 *nbytes = rslMPLHandleLUT.tags[i].nbytes;
169 rslMPLHandleLUT.nUsed--; /* Keep them contiguous */
170 rslMPLHandleLUT.tags[i].tag=rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].tag;
171 rslMPLHandleLUT.tags[i].Handle=
172 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].Handle;
173 rslMPLHandleLUT.tags[i].type=
174 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].type;
175 rslMPLHandleLUT.tags[i].nbytes=
176 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].nbytes ;
177 retVal = 0 ;
178 break;
181 return( retVal ) ;
184 /* same as above, but leaves list alone */
185 long rslMPLPeekWaitH (tag, waitHandle, type, nbytes )
186 int tag; /* Tag for which we lookup a wait handle */
187 MPL_Request *waitHandle ;
188 int *type, *nbytes ;
190 int i;
191 long retVal = -1;
193 for (i=0; i < rslMPLHandleLUT.nUsed; i++)
195 if (rslMPLHandleLUT.tags[i].tag == tag)
197 *waitHandle = rslMPLHandleLUT.tags[i].Handle;
198 *type = rslMPLHandleLUT.tags[i].type;
199 *nbytes = rslMPLHandleLUT.tags[i].nbytes;
200 retVal = 0 ;
201 break;
204 return( retVal ) ;
208 /******************************************************
209 * rslMPLSaveWaitH (tag, waitHandle)
210 * Use the LUT to save an MPL wait handle referenced by a tag
212 * Initial coding: Leslie Hart, 22 Apr 94
214 *****************************************************/
216 void rslMPLSaveWaitH (tag, waitHandle,type,nbytes)
217 int tag;
218 MPL_Request * waitHandle;
219 int type, nbytes ;
221 /* Make sure there is enough space, if not, try a realloc */
222 /* If the realloc fails we're in deep trouble */
223 if (rslMPLHandleLUT.nUsed == rslMPLHandleLUT.nHandles)
225 struct tagsToHandles *tags; /* Temp pointer */
226 tags = (struct tagsToHandles *)
227 realloc (rslMPLHandleLUT.tags,
228 sizeof (struct tagsToHandles) * (rslMPLHandleLUT.nHandles + RSLHandleInc));
229 if (tags != NULL)
231 rslMPLHandleLUT.tags = tags;
232 rslMPLHandleLUT.nHandles += RSLHandleInc;
234 else
236 #ifdef FATAL_ERRORS
237 fprintf (stderr, "Fatal Error: realloc failure in rslMPLSaveWaitH\n");
238 exit(1);
239 #endif
240 return;
243 /* Stash the handle */
244 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].tag = tag;
245 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].Handle = *waitHandle;
246 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].type = type ;
247 rslMPLHandleLUT.tags[rslMPLHandleLUT.nUsed].nbytes = nbytes ;
248 rslMPLHandleLUT.nUsed++;
251 /******************************************************
252 * rslMPLISend (buff, mlen, tag, dest)
253 * Post a non blocking send an stash a wait handle
255 * Initial coding: Leslie Hart, 22 Apr 94
257 *****************************************************/
259 void rslMPLISend (buff, mlen, tag, dest)
260 char *buff;
261 int mlen;
262 int tag;
263 int dest;
265 MPL_Request waitHandle;
266 int rc ;
268 if ( tag < type_low || tag > type_high )
270 sprintf(mess,"RSL_SENDBEGIN message type %d out of allowed range: %d..%d\n",
271 tag,type_low,type_high) ;
272 RSL_TEST_ERR( 1, mess ) ;
275 rc = mpc_send (buff,
276 mlen,
277 dest,
278 tag,
279 &waitHandle);
281 #if 0
282 fprintf(stderr,"mpc_send: nlen %10d type %10d dest %10d handle %08x\n",
283 mlen, tag, dest, waitHandle ) ;
284 #endif
286 if ( rc )
288 sprintf(mess,"mpc_send returns %d", rc ) ;
289 RSL_TEST_ERR( 1, mess ) ;
292 rslMPLSaveWaitH (tag, &waitHandle,1,mlen);
295 /******************************************************
296 * rslMPLIRecv (buff, mlen, tag)
297 * Post a non blocking receive an stash a wait handle
299 * Initial coding: Leslie Hart, 22 Apr 94
301 *****************************************************/
303 void rslMPLIRecv (buff, mlen, tag)
304 char *buff;
305 int mlen;
306 int tag;
308 MPL_Request waitHandle;
309 int source ;
310 int tagloc ;
311 int rc ;
313 source = dontcare ;
314 tagloc = tag ;
316 if ( tag < type_low || tag > type_high )
318 sprintf(mess,"RSL_RECVBEGIN message type %d out of allowed range: %d..%d\n",
319 tag,type_low,type_high) ;
320 RSL_TEST_ERR( 1, mess ) ;
324 rc = mpc_recv (buff,
325 mlen,
326 &source,
327 &tagloc,
328 &waitHandle);
330 if ( rc )
332 sprintf(mess,"mpc_recv returns %d", rc ) ;
333 RSL_TEST_ERR( 1, mess ) ;
336 /* fprintf(stderr,"rslMPLIRecv tag = %d, handle = %d\n",tag,waitHandle) ; */
338 rslMPLSaveWaitH (tag, &waitHandle, 2, mlen);
341 /******************************************************
342 * rslMPLWait (tag)
343 * Wait for a pending send/recv
345 * Initial coding: Leslie Hart, 22 Apr 94
347 *****************************************************/
349 extern int mperrno ;
351 void rslMPLWait (tag)
352 int tag;
354 MPL_Request waitHandle;
355 MPL_Status status ;
356 int rc ;
357 int type, nbytes;
359 if ( rslMPLFindWaitH (tag, &waitHandle, &type, &nbytes ) != 0 )
361 fprintf(stderr,"rslMPLWait: tag %d not found by rslMPLFindWaitH\n",tag) ;
362 exit(2) ;
365 #if 0
366 fprintf(stderr,"calling mpc_wait: tag %d, handle %08x, type %d (%s), original nbytes %d\n",
367 tag, waitHandle, type, (type==1)?"send":((type==2)?"recv":"unknown"),
368 nbytes) ;
369 #endif
371 rc = mpc_wait ( &waitHandle, &status );
372 if ( rc )
374 fprintf(stderr,"mpc_wait fails: tag %d, handle %08x, type %d (%s), original nbytes %d, status %d, rc %d, mperrno = %d\n",
375 tag, waitHandle, type, (type==1)?"send":((type==2)?"recv":"unknown"),
376 nbytes, status, rc, mperrno) ;
377 exit(2) ;
380 #if 0
381 fprintf(stderr,"mpc_wait : tag %d, handle %08x, status %d\n",
382 tag, waitHandle, status) ;
383 #endif
388 MPL_Request d1, d2, d3, waitHandle, d4, d5, d6 ;
390 rslMPLProbe( tag, retval )
391 int tag, *retval ;
393 MPL_Status status ;
394 int rc ;
395 int type, nbytes ;
397 if ( rslMPLPeekWaitH (tag, &waitHandle, &type, &nbytes ) != 0 )
399 fprintf(stderr,"rslMPLWait: tag %d not found by rslMPLPeekWaitH\n",tag) ;
400 exit(2) ;
402 rc = mpc_status( waitHandle ) ;
404 if ( rc >= 0 )
406 *retval = 1 ;
408 else if ( rc == -1 )
410 *retval = 0 ;
412 else
414 sprintf(mess,"No outstanding message for tag %d (handle %d) rc=%d\n",tag,waitHandle,rc) ;
415 RSL_TEST_ERR(1,mess) ;
417 return ;
420 #endif /* __MPL_COMPAT__ */
421 #endif /* MPL */