source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/oasis3-mct/lib/mct/mpi-serial/req.c

Last change on this file was 5725, checked in by aclsce, 3 years ago

Added new oasis3-MCT version to be used to handle ensembles simulations with XIOS.

File size: 6.0 KB
Line 
1#include "mpiP.h"
2
3
4/*
5 * COMPLETION
6 */
7
8
9
10FC_FUNC( mpi_test , MPI_TEST)(int *request, int *flag, int *status,
11                                int *ierror)
12{
13  *ierror=MPI_Test( (void *)request ,flag,mpi_c_status(status));
14}
15
16
17
18int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status)
19{
20  Req *req;
21
22  if (*request==MPI_REQUEST_NULL)
23    {
24      if (status!=MPI_STATUS_IGNORE)
25        {
26          status->MPI_TAG= MPI_ANY_TAG;
27          status->MPI_SOURCE= MPI_ANY_SOURCE;
28        }
29      *flag=1;
30      return(MPI_SUCCESS);
31    }
32
33
34  req=mpi_handle_to_ptr(*request);
35
36  *flag=req->complete;
37
38  if (*flag)
39    {
40      if (status!=MPI_STATUS_IGNORE)
41        {
42          status->MPI_SOURCE= req->source;
43          status->MPI_TAG= req->tag;
44        }
45
46      mpi_free_handle(*request);
47      *request=MPI_REQUEST_NULL;
48    }
49
50  return(MPI_SUCCESS);
51}
52
53
54
55FC_FUNC( mpi_wait , MPI_WAIT )(int *request, int *status, int *ierror)
56{
57  *ierror=MPI_Wait( (void *)request, mpi_c_status(status) );
58}
59
60
61
62int MPI_Wait(MPI_Request *request, MPI_Status *status)
63{
64  int flag;
65
66  MPI_Test(request,&flag,status);
67
68  if (!flag)
69    {
70      fprintf(stderr,"MPI_Wait: request not complete, deadlock\n");
71      abort();
72    }
73
74  return(MPI_SUCCESS);
75}
76
77
78/*********/
79
80
81FC_FUNC( mpi_waitany , MPI_WAITANY )(int *count, int *requests,
82                                       int *index, int *status, int *ierror)
83{
84
85  *ierror=MPI_Waitany(*count, (void *)requests,index,mpi_c_status(status));
86}
87
88
89
90int MPI_Waitany(int count, MPI_Request *array_of_requests,
91                int *index, MPI_Status *status)
92{
93  int flag;
94
95  MPI_Testany(count, array_of_requests, index, &flag, status);
96
97  if (!flag)
98  {
99    /* none are completed */
100
101    fprintf(stderr,"MPI_Waitany: no requests complete, deadlock\n");
102    abort();
103
104  }
105
106  return(MPI_SUCCESS);
107}
108
109/* MPI_Testany:  looks for any message matching an element
110 * in request array and returns its status.
111 * flag=0 means no match was found.
112 */
113
114FC_FUNC(mpi_testany, MPI_TESTANY)
115         (int * count, int * array_of_requests,
116          int * index, int * flag, int *status, int * ierr)
117{
118  *ierr = MPI_Testany(*count, array_of_requests, index,
119                      flag, mpi_c_status(status));
120}
121
122int MPI_Testany(int count,  MPI_Request *array_of_requests,
123                int *index, int *flag, MPI_Status *status)
124{
125  int i;
126
127  for (i=0; i<count; i++)
128    {
129      MPI_Test(&array_of_requests[i],flag,status);
130
131      if (*flag)
132        return(MPI_SUCCESS);
133    }
134
135  /* none are completed */
136
137  *flag=0;
138  return(MPI_SUCCESS);
139}
140
141/************
142 * testall: tests that all requests have completed,
143 * if so return request array, otherwise set flag=0
144 */
145FC_FUNC(mpi_testall, MPI_TESTALL)
146         (int * count, int * array_of_requests, int *flag,
147          int * array_of_statuses, int * ierr)
148{
149  *ierr = MPI_Testall(*count, array_of_requests, flag,
150                      mpi_c_statuses(array_of_statuses));
151}
152
153int MPI_Testall(int count, MPI_Request *array_of_requests,
154                int *flag, MPI_Status *array_of_statuses)
155{
156  int i;
157  int iflag;
158
159  *flag = 1;
160
161  for (i=0; i<count && flag; i++)
162  {
163      MPI_Test(&array_of_requests[i],&iflag,&array_of_statuses[i]);
164
165      if (!iflag)
166        *flag=0;
167  }
168
169  return(MPI_SUCCESS);
170}
171
172/*********/
173/* Waitall:  Does a testall, but if no request has
174 * completed, abort with an error
175 */
176
177FC_FUNC( mpi_waitall , MPI_WAITALL )(int *count, int *array_of_requests,
178                                       int *array_of_statuses, int *ierror)
179{
180  *ierror=MPI_Waitall(*count, (void *)array_of_requests,
181                      mpi_c_statuses(array_of_statuses));
182
183}
184
185
186
187int MPI_Waitall(int count, MPI_Request *array_of_requests,
188                MPI_Status *array_of_statuses)
189{
190  int i;
191  int flag;
192
193  for (i=0; i<count; i++)
194    {
195      MPI_Test(&array_of_requests[i],&flag,&array_of_statuses[i]);
196
197      if (!flag)
198        {
199          fprintf(stderr,"MPI_Waitall: request not complete, deadlock\n");
200          abort();
201        }
202    }
203
204  return(MPI_SUCCESS);
205}
206
207/* Testsome:  tests each of an array of requests, and returns each one's
208 * status in an array (if it is available
209 */
210
211FC_FUNC(mpi_testsome, MPI_TESTSOME)
212         (int * incount, int * array_of_requests, int * outcount,
213          int * array_of_indices, int * array_of_statuses, int * ierr)
214{
215  *ierr = MPI_Testsome(*incount, array_of_requests, outcount,
216                       array_of_indices, mpi_c_statuses(array_of_statuses));
217}
218
219int MPI_Testsome(int incount, MPI_Request *array_of_requests, int *outcount,
220                 int *array_of_indices, MPI_Status *array_of_statuses)
221{
222  int i;
223  int flag;
224
225  *outcount =0;
226    for (i=0; i<incount; i++)
227    {
228      flag=0;
229      MPI_Test(&array_of_requests[i],&flag,&array_of_statuses[i]);
230
231      if (flag)
232        *outcount++;
233    }
234
235  return(MPI_SUCCESS);
236
237}
238
239/* Waitsome: checks for availability of at least one status from array of
240 * requests.  If no statuses are available, abort with error
241 */
242
243FC_FUNC(mpi_waitsome, MPI_WAITSOME)
244         (int * incount, int * array_of_requests, int * outcount,
245          int * array_of_indices, int *array_of_statuses, int * ierr)
246{
247  *ierr = MPI_Waitsome(*incount, array_of_requests, outcount,
248                       array_of_indices, mpi_c_statuses(array_of_statuses));
249}
250
251int MPI_Waitsome(int incount, MPI_Request *array_of_requests, int *outcount,
252                 int *array_of_indices, MPI_Status *array_of_statuses)
253{
254  MPI_Testsome(incount, array_of_requests, outcount,
255               array_of_indices, array_of_statuses);
256
257  if (!outcount)
258  {
259    fprintf(stderr,"Waitsome: No requests complete, deadlock\n");
260    abort();
261  }
262
263  return MPI_SUCCESS;
264}
265
266/***********************/
267/* Request_free:  Frees the handle and request
268 */
269
270FC_FUNC(mpi_request_free, MPI_REQUEST_FREE)
271         (int * request, int * ierr)
272{
273  *ierr = MPI_Request_free(request);
274}
275
276int MPI_Request_free(MPI_Request * req)
277{
278  mpi_free_handle(*req);
279  *req = MPI_REQUEST_NULL;
280  return (MPI_SUCCESS);
281}
282
283
284
285/*********/
286
287
288MPI_Request MPI_Request_f2c(MPI_Fint request)
289{
290  return(request);
291}
292
293
294/*********/
295
296
297
298MPI_Fint MPI_Request_c2f(MPI_Request request)
299{
300  return(request);
301}
Note: See TracBrowser for help on using the repository browser.