source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/lib/mct/mpi-serial/recv.c @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 4 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 2.8 KB
Line 
1
2#include "mpiP.h"
3
4
5
6/*
7 * RECEIVING
8 *
9 */
10
11
12
13static int mpi_match_send(void *r, void *tag)
14{
15  return( *((int *)tag) == MPI_ANY_TAG ||
16          *((int *)tag) == ((Req *)r)->tag );
17}
18
19
20
21/*
22 *
23 */
24
25
26
27FC_FUNC( mpi_irecv , MPI_IRECV )(void *buf, int *count, int *datatype,
28                                   int *source, int *tag, int *comm,
29                                   int *request, int *ierror)
30{
31
32  *ierror=MPI_Irecv(buf,*count,*datatype,*source,*tag,
33                    *comm, (void *)request);
34
35}
36
37
38
39int MPI_Irecv(void *buf, int count, MPI_Datatype datatype,
40              int source, int tag, MPI_Comm comm, MPI_Request *request)
41
42{
43  pListitem match;
44  Comm *mycomm;
45  Req *rreq, *sreq;
46
47  mycomm=mpi_handle_to_ptr(comm);         /* mycomm=(Comm *)comm; */
48
49#ifdef INFO
50  fflush(stdout);
51  fprintf(stderr,"MPI_Irecv: Comm=%d  tag=%d  count=%d type=%d\n",
52         mycomm->num,tag,count,datatype);
53#endif
54
55
56  if (source!=0 && source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL)
57    {
58      fprintf(stderr,"MPI_Irecv: bad source %d\n",source);
59      abort();
60    }
61
62  mpi_alloc_handle(request,(void **)&rreq);
63
64  if (source==MPI_PROC_NULL)
65    {
66      rreq->complete=1;
67      rreq->source=MPI_PROC_NULL;
68      rreq->tag=MPI_ANY_TAG;
69
70      return(MPI_SUCCESS);
71    }
72
73
74  if ( match=AP_list_search_func(mycomm->sendlist,mpi_match_send,&tag) )
75    {
76      sreq=(Req *)AP_listitem_data(match);
77      AP_list_delete_item(mycomm->sendlist,match);
78
79      memcpy(buf,sreq->buf,count * datatype);
80      rreq->complete=1;
81      rreq->source=0;
82      rreq->tag=sreq->tag;                   /* in case tag was MPI_ANY_TAG */
83
84      sreq->complete=1;
85
86#ifdef DEBUG
87      printf("Completion(recv) value=%d tag=%d\n",
88             *((int *)buf),rreq->tag);
89#endif
90
91      return(MPI_SUCCESS);
92    }
93
94  rreq->buf=buf;
95  rreq->tag=tag;
96  rreq->complete=0;
97  rreq->listitem=AP_list_append(mycomm->recvlist,rreq);
98
99#ifdef INFO
100  print_list(mycomm->recvlist,"recvlist for comm ",mycomm->num);
101#endif
102
103  return(MPI_SUCCESS);
104}
105
106
107/*********/
108
109
110FC_FUNC( mpi_recv , MPI_RECV )(void *buf, int *count, int *datatype,
111                                 int *source, int *tag, int *comm,
112                                 int *status, int *ierror)
113{
114  *ierror=MPI_Recv(buf,*count,*datatype,*source,*tag,*comm,
115                   (MPI_Status *)status);
116}
117
118
119
120int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
121             int tag, MPI_Comm comm, MPI_Status *status)
122{
123  MPI_Request request;
124
125#ifdef INFO
126  fflush(stdout);
127  fprintf(stderr,"MPI_Recv: ");
128#endif
129
130
131  MPI_Irecv(buf,count,datatype,source,tag,comm,&request);
132  MPI_Wait(&request,status);
133
134
135  return(MPI_SUCCESS);
136}
137
138
139
140#ifdef INFO
141
142int print_item(void *item, void *data)
143{
144  fprintf(stderr,"%d  ", ((Req *)item)->tag);
145  return(0);
146}
147
148
149int print_list(pList list, char *msg, int num)
150{
151  fflush(stdout);
152  fprintf(stderr,"%s %d: ",msg,num);
153
154  AP_list_apply(list,print_item,NULL);
155
156  fprintf(stderr,"\n");
157  return(0);
158}
159
160
161#endif
Note: See TracBrowser for help on using the repository browser.