1 /***********************************************************************
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.
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
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 ***************************************************************************/
58 #ifndef __MPI_COMPAT__
59 #define __MPI_COMPAT__
66 #define RSLHandleInc 32
78 struct tagsToHandles
*tags
;
81 /******************************************************
83 * do whatever initialization is necessary for the
86 * Initial coding: Leslie Hart, 22 Apr 94
87 * Adapted to MPI: J. Michalakes 7/13/94
89 *****************************************************/
91 static int dummy
= 0 ;
100 rslMPIHandleLUT
.nHandles
= RSLHandleInc
;
101 rslMPIHandleLUT
.nUsed
= 0;
102 rslMPIHandleLUT
.tags
= (struct tagsToHandles
*)
103 malloc (sizeof (struct tagsToHandles
) * RSLHandleInc
);
105 MPI_Initialized( &flag
) ;
110 MPI_INIT_F ( &dummy
) ; /* call to fortran wrapper */
114 mpi_init__( &dummy
) ;
116 mpi_init_( &dummy
) ;
123 if (rslMPIHandleLUT
.tags
== NULL
)
125 fprintf (stderr
, "Fatal Error: malloc failure in rslMPIInit\n");
132 /******************************************************
133 * rslMPIWho ( numproc, myproc )
134 * Use the LUT to find an MPI wait handle from a tag
136 * Initial coding: J. Michalakes 7/13/94
138 *****************************************************/
140 long rslMPIWho( numproc
, myproc
)
141 int * numproc
, * myproc
;
143 MPI_Comm_rank( rsl_mpi_communicator
, myproc
) ;
144 MPI_Comm_size( rsl_mpi_communicator
, numproc
) ;
148 /******************************************************
149 * rslMPIFindWaitH (tag)
150 * Use the LUT to find an MPI wait handle from a tag
152 * Initial coding: Leslie Hart, 22 Apr 94
154 *****************************************************/
156 long rslMPIFindWaitH (tag
, waitHandle
)
157 int tag
; /* Tag for which we lookup a wait handle */
158 MPI_Request
*waitHandle
;
163 for (i
=0; i
< rslMPIHandleLUT
.nUsed
; i
++)
165 if (rslMPIHandleLUT
.tags
[i
].tag
== tag
)
167 *waitHandle
= rslMPIHandleLUT
.tags
[i
].Handle
;
168 rslMPIHandleLUT
.nUsed
--; /* Keep them contiguous */
169 rslMPIHandleLUT
.tags
[i
].tag
=rslMPIHandleLUT
.tags
[rslMPIHandleLUT
.nUsed
].tag
;
170 rslMPIHandleLUT
.tags
[i
].Handle
=
171 rslMPIHandleLUT
.tags
[rslMPIHandleLUT
.nUsed
].Handle
;
178 /******************************************************
179 * rslMPISaveWaitH (tag, waitHandle)
180 * Use the LUT to save an MPI wait handle referenced by a tag
182 * Initial coding: Leslie Hart, 22 Apr 94
184 *****************************************************/
186 void rslMPISaveWaitH (tag
, waitHandle
)
188 MPI_Request
* waitHandle
;
190 /* Make sure there is enough space, if not, try a realloc */
191 /* If the realloc fails we're in deep trouble */
192 if (rslMPIHandleLUT
.nUsed
== rslMPIHandleLUT
.nHandles
)
194 struct tagsToHandles
*tags
; /* Temp pointer */
195 tags
= (struct tagsToHandles
*)
196 realloc (rslMPIHandleLUT
.tags
,
197 sizeof (struct tagsToHandles
) * (rslMPIHandleLUT
.nHandles
+ RSLHandleInc
));
200 rslMPIHandleLUT
.tags
= tags
;
201 rslMPIHandleLUT
.nHandles
+= RSLHandleInc
;
206 fprintf (stderr
, "Fatal Error: realloc failure in rslMPISaveWaitH\n");
212 /* Stash the handle */
213 rslMPIHandleLUT
.tags
[rslMPIHandleLUT
.nUsed
].tag
= tag
;
214 rslMPIHandleLUT
.tags
[rslMPIHandleLUT
.nUsed
].Handle
= *waitHandle
;
215 rslMPIHandleLUT
.nUsed
++;
218 /******************************************************
219 * rslMPIISend (buff, mlen, tag, dest)
220 * Post a non blocking send an stash a wait handle
222 * Initial coding: Leslie Hart, 22 Apr 94
224 *****************************************************/
226 void rslMPIISend (buff
, mlen
, tag
, dest
)
232 MPI_Request waitHandle
;
239 rsl_mpi_communicator
,
242 rslMPISaveWaitH (tag
, &waitHandle
);
245 /******************************************************
246 * rslMPIIRecv (buff, mlen, tag)
247 * Post a non blocking receive an stash a wait handle
249 * Initial coding: Leslie Hart, 22 Apr 94
251 *****************************************************/
253 void rslMPIIRecv (buff
, mlen
, tag
)
258 MPI_Request waitHandle
;
265 rsl_mpi_communicator
,
268 rslMPISaveWaitH (tag
, &waitHandle
);
271 /******************************************************
273 * Wait for a pending send/recv
275 * Initial coding: Leslie Hart, 22 Apr 94
277 *****************************************************/
279 void rslMPIWait (tag
)
282 MPI_Request waitHandle
;
285 rslMPIFindWaitH (tag
, &waitHandle
);
286 (void) MPI_Wait ( &waitHandle
, &status
);
289 #endif /* __MPI_COMPAT__ */