added README_changes.txt
[wrffire.git] / wrfv2_fire / external / RSL / RSL / rsl_cham_compat.c
blobee6b80adebf4b47455e3a0c365901ea948b044b5
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 /* this is still under construction -- 11/94 */
59 #ifdef CHAMELEON
60 #ifndef __CHAM_COMPAT__
61 #define __CHAM_COMPAT__
63 #include <stdio.h>
64 #include "tools.h"
65 #include "comm/comm.h"
66 #include "rsl.h"
68 #define RSLHandleInc 32
70 typedef long CHAM_request ;
72 struct tagsToHandles
74 int tag;
75 char * buff ;
76 int mlen ;
77 int datatype ;
78 CHAM_Request Handle;
80 struct rslCHAMHandles
82 int nHandles;
83 int nUsed;
84 struct tagsToHandles *tags;
85 } rslCHAMHandleLUT;
87 /******************************************************
88 * rslCHAMInit ()
89 * do whatever initialization is necessary for the
90 * CHAM port
92 * Initial coding: Leslie Hart, 22 Apr 94
93 * Adapted to CHAM: J. Michalakes 11/94
95 *****************************************************/
97 static int dummy = 0 ;
99 void rslCHAMInit()
101 rslCHAMHandleLUT.nHandles = RSLHandleInc;
102 rslCHAMHandleLUT.nUsed = 0;
103 rslCHAMHandleLUT.tags = (struct tagsToHandles *)
104 malloc (sizeof (struct tagsToHandles) * RSLHandleInc);
106 #ifdef FATAL_ERRORS
107 if (rslCHAMHandleLUT.tags == NULL)
109 fprintf (stderr, "Fatal Error: malloc failure in rslCHAMInit\n");
110 exit(1);
112 #endif
116 /******************************************************
117 * rslCHAMWho ( numproc, myproc )
118 * Use the LUT to find an CHAM wait handle from a tag
120 * Initial coding: J. Michalakes 7/13/94
122 *****************************************************/
124 long rslCHAMWho( numproc, myproc )
125 int * numproc, * myproc ;
127 *myproc = PImytid ;
128 *numproc = PInumtids ;
129 return( 0L ) ;
132 /******************************************************
133 * rslCHAMFindWaitH (tag)
134 * Use the LUT to find an CHAM wait handle from a tag
136 * Initial coding: Leslie Hart, 22 Apr 94
138 *****************************************************/
140 long rslCHAMFindWaitH (tag, waitHandle,
141 buff, mlen, datatype )
142 int tag; /* Tag for which we lookup a wait handle */
143 CHAM_Request *waitHandle ;
144 char ** buff ;
145 int *mlen ;
146 int *datatype ;
148 int i;
149 long retVal = -1;
151 for (i=0; i < rslCHAMHandleLUT.nUsed; i++)
153 if (rslCHAMHandleLUT.tags[i].tag == tag)
155 *buff = rslCHAMHandleLUT.tags[i].buff;
156 *mlen = rslCHAMHandleLUT.tags[i].mlen;
157 *datatype = rslCHAMHandleLUT.tags[i].datatype;
158 *waitHandle = rslCHAMHandleLUT.tags[i].Handle;
160 rslCHAMHandleLUT.nUsed--; /* Keep them contiguous */
161 rslCHAMHandleLUT.tags[i].tag=rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].tag;
162 rslCHAMHandleLUT.tags[i].buff=
163 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].buff;
164 rslCHAMHandleLUT.tags[i].mlen=
165 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].mlen;
166 rslCHAMHandleLUT.tags[i].datatype=
167 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].datatype;
168 rslCHAMHandleLUT.tags[i].Handle=
169 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].Handle;
170 break;
175 /******************************************************
176 * rslCHAMSaveWaitH (tag, waitHandle)
177 * Use the LUT to save an CHAM wait handle referenced by a tag
179 * Initial coding: Leslie Hart, 22 Apr 94
181 *****************************************************/
183 void rslCHAMSaveWaitH (tag, waitHandle)
184 int tag;
185 CHAM_Request * waitHandle;
187 /* Make sure there is enough space, if not, try a realloc */
188 /* If the realloc fails we're in deep trouble */
189 if (rslCHAMHandleLUT.nUsed == rslCHAMHandleLUT.nHandles)
191 struct tagsToHandles *tags; /* Temp pointer */
192 tags = (struct tagsToHandles *)
193 realloc (rslCHAMHandleLUT.tags,
194 sizeof (struct tagsToHandles) * (rslCHAMHandleLUT.nHandles + RSLHandleInc));
195 if (tags != NULL)
197 rslCHAMHandleLUT.tags = tags;
198 rslCHAMHandleLUT.nHandles += RSLHandleInc;
200 else
202 #ifdef FATAL_ERRORS
203 fprintf (stderr, "Fatal Error: realloc failure in rslCHAMSaveWaitH\n");
204 exit(1);
205 #endif
206 return;
209 /* Stash the handle */
210 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].tag = tag;
211 rslCHAMHandleLUT.tags[rslCHAMHandleLUT.nUsed].Handle = *waitHandle;
212 rslCHAMHandleLUT.nUsed++;
215 /******************************************************
216 * rslCHAMISend (buff, mlen, tag, dest)
217 * Post a non blocking send an stash a wait handle
219 * Initial coding: Leslie Hart, 22 Apr 94
221 *****************************************************/
223 void rslCHAMISend (buff, mlen, tag, dest)
224 char *buff;
225 int mlen;
226 int tag;
227 int dest;
229 CHAM_Request waitHandle;
231 PInsend( tag,
232 buff,
233 mlen,
234 dest,
235 MSG_OTHER,
236 &waitHandle);
238 rslCHAMSaveWaitH (tag, &waitHandle);
241 /******************************************************
242 * rslCHAMIRecv (buff, mlen, tag)
243 * Post a non blocking receive an stash a wait handle
245 * Initial coding: Leslie Hart, 22 Apr 94
247 *****************************************************/
249 void rslCHAMIRecv (buff, mlen, tag)
250 char *buff;
251 int mlen;
252 int tag;
254 CHAM_Request waitHandle;
256 PInrecv (tag,
257 buff,
258 mlen,
259 MSG_OTHER,
260 tag,
261 &waitHandle);
263 rslCHAMSaveWaitH (tag, waitHandle);
266 /******************************************************
267 * rslCHAMWait (tag)
268 * Wait for a pending send/recv
270 * Initial coding: Leslie Hart, 22 Apr 94
272 *****************************************************/
274 void rslCHAMWait (tag, flag)
275 int tag, flag;
277 CHAM_Request waitHandle;
278 CHAM_Status status ;
280 rslCHAMFindWaitH (tag, &waitHandle );
281 if ( flag == 1 ) /* receive */
282 CHAM_Wait ( &waitHandle, &status );
283 else /* send */
284 CHAM_Wait ( &waitHandle, &status );
287 #endif /* __CHAM_COMPAT__ */
288 #endif /* CHAM */