1 | |
---|
2 | #include "mpiP.h" |
---|
3 | |
---|
4 | |
---|
5 | /* |
---|
6 | * SENDING |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | static int mpi_match_recv(void *r, void *tag) |
---|
13 | { |
---|
14 | return( ((Req *)r)->tag == MPI_ANY_TAG || |
---|
15 | ((Req *)r)->tag == *((int *)tag) ); |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | /* |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | FC_FUNC( mpi_isend , MPI_ISEND )(void *buf, int *count, int *datatype, |
---|
26 | int *dest, int *tag, int *comm, int *req, int *ierror) |
---|
27 | { |
---|
28 | |
---|
29 | *ierror=MPI_Isend(buf,*count,*datatype,*dest,*tag, |
---|
30 | *comm, (void *)req); |
---|
31 | |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | int MPI_Isend(void *buf, int count, MPI_Datatype datatype, |
---|
37 | int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
38 | { |
---|
39 | pListitem match; |
---|
40 | Comm *mycomm; |
---|
41 | Req *rreq, *sreq; |
---|
42 | |
---|
43 | mycomm=mpi_handle_to_ptr(comm); /* (Comm *)comm; */ |
---|
44 | |
---|
45 | #ifdef INFO |
---|
46 | fflush(stdout); |
---|
47 | fprintf(stderr,"MPI_Isend: Comm=%d tag=%d count=%d type=%d\n", |
---|
48 | mycomm->num,tag,count,datatype); |
---|
49 | #endif |
---|
50 | |
---|
51 | if (dest!=0 && dest!=MPI_PROC_NULL) |
---|
52 | { |
---|
53 | fprintf(stderr,"MPI_Isend: send to %d\n",dest); |
---|
54 | abort(); |
---|
55 | } |
---|
56 | |
---|
57 | mpi_alloc_handle(request,(void **) &sreq); |
---|
58 | |
---|
59 | |
---|
60 | if (dest==MPI_PROC_NULL) |
---|
61 | { |
---|
62 | sreq->complete=1; |
---|
63 | return(MPI_SUCCESS); |
---|
64 | } |
---|
65 | |
---|
66 | if ( match=AP_list_search_func(mycomm->recvlist,mpi_match_recv,&tag) ) |
---|
67 | { |
---|
68 | rreq=(Req *)AP_listitem_data(match); |
---|
69 | AP_list_delete_item(mycomm->recvlist,match); |
---|
70 | |
---|
71 | memcpy(rreq->buf,buf,count * datatype); |
---|
72 | rreq->complete=1; |
---|
73 | rreq->source=0; |
---|
74 | rreq->tag=tag; /* in case rreq->tag was MPI_ANY_TAG */ |
---|
75 | |
---|
76 | sreq->complete=1; |
---|
77 | |
---|
78 | #ifdef DEBUG |
---|
79 | printf("Completion(send) value=%d tag=%d\n", |
---|
80 | *((int *)buf),rreq->tag); |
---|
81 | #endif |
---|
82 | |
---|
83 | return(MPI_SUCCESS); |
---|
84 | } |
---|
85 | |
---|
86 | sreq->buf=buf; |
---|
87 | sreq->tag=tag; |
---|
88 | sreq->complete=0; |
---|
89 | sreq->listitem=AP_list_append(mycomm->sendlist,sreq); |
---|
90 | |
---|
91 | #ifdef INFO |
---|
92 | print_list(mycomm->sendlist,"sendlist for comm ",mycomm->num); |
---|
93 | #endif |
---|
94 | |
---|
95 | return(MPI_SUCCESS); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | /*********/ |
---|
100 | |
---|
101 | |
---|
102 | FC_FUNC(mpi_send, MPI_SEND) ( void *buf, int *count, int *datatype, |
---|
103 | int *dest, int *tag, int *comm, int *ierror) |
---|
104 | { |
---|
105 | *ierror=MPI_Send(buf, *count, *datatype, *dest, *tag, *comm); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | int MPI_Send(void* buf, int count, MPI_Datatype datatype, |
---|
111 | int dest, int tag, MPI_Comm comm) |
---|
112 | { |
---|
113 | MPI_Request request; |
---|
114 | MPI_Status status; |
---|
115 | |
---|
116 | #ifdef INFO |
---|
117 | fflush(stdout); |
---|
118 | fprintf(stderr,"MPI_Send: "); |
---|
119 | #endif |
---|
120 | |
---|
121 | MPI_Isend(buf,count,datatype,dest,tag,comm,&request); |
---|
122 | MPI_Wait(&request,&status); |
---|
123 | |
---|
124 | |
---|
125 | return(MPI_SUCCESS); |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | /*********/ |
---|
132 | |
---|
133 | |
---|
134 | FC_FUNC(mpi_ssend, MPI_SSEND) ( void *buf, int *count, int *datatype, |
---|
135 | int *dest, int *tag, int *comm, int *ierror) |
---|
136 | { |
---|
137 | *ierror=MPI_Send(buf, *count, *datatype, *dest, *tag, *comm); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | int MPI_Ssend(void* buf, int count, MPI_Datatype datatype, |
---|
143 | int dest, int tag, MPI_Comm comm) |
---|
144 | { |
---|
145 | return(MPI_Send(buf,count,datatype,dest,tag,comm)); |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | /*********/ |
---|
151 | |
---|
152 | |
---|
153 | FC_FUNC(mpi_rsend, MPI_RSEND) ( void *buf, int *count, int *datatype, |
---|
154 | int *dest, int *tag, int *comm, int *ierror) |
---|
155 | { |
---|
156 | *ierror=MPI_Send(buf, *count, *datatype, *dest, *tag, *comm); |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | int MPI_Rsend(void* buf, int count, MPI_Datatype datatype, |
---|
162 | int dest, int tag, MPI_Comm comm) |
---|
163 | { |
---|
164 | return(MPI_Send(buf,count,datatype,dest,tag,comm)); |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | /*********/ |
---|
171 | |
---|
172 | |
---|
173 | |
---|
174 | FC_FUNC( mpi_irsend , MPI_IRSEND )(void *buf, int *count, int *datatype, |
---|
175 | int *dest, int *tag, int *comm, int *req, int *ierror) |
---|
176 | { |
---|
177 | |
---|
178 | *ierror=MPI_Irsend(buf,*count,*datatype,*dest,*tag, |
---|
179 | *comm, (void *)req); |
---|
180 | |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | int MPI_Irsend(void *buf, int count, MPI_Datatype datatype, |
---|
186 | int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
187 | { |
---|
188 | MPI_Status status; |
---|
189 | Req *req; |
---|
190 | |
---|
191 | |
---|
192 | MPI_Isend(buf,count,datatype,dest,tag,comm,request); |
---|
193 | |
---|
194 | /* Ready mode implied a receive must already be posted, |
---|
195 | * so the Isend should have completed already. |
---|
196 | * Can't use MPI_Test here for the error check because |
---|
197 | * it would clear the request prematurely. |
---|
198 | */ |
---|
199 | |
---|
200 | req=mpi_handle_to_ptr(*request); |
---|
201 | if ( !req->complete ) |
---|
202 | { |
---|
203 | fprintf(stderr,"MPI_Irsend: no matching receive found\n"); |
---|
204 | abort(); |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | return(MPI_SUCCESS); |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | /*********/ |
---|
215 | |
---|
216 | |
---|
217 | FC_FUNC(mpi_sendrecv, MPI_SENDRECV) ( |
---|
218 | void *sendbuf, int *sendcount, int *sendtype, int *dest, int *sendtag, |
---|
219 | void *recvbuf, int *recvcount, int *recvtype, int *source, int *recvtag, |
---|
220 | int *comm, int *status, |
---|
221 | int *ierror) |
---|
222 | { |
---|
223 | *ierror=MPI_Sendrecv(sendbuf, *sendcount, *sendtype, *dest, *sendtag, |
---|
224 | recvbuf, *recvcount, *recvtype, *source, *recvtag, |
---|
225 | *comm, (MPI_Status *)status); |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | int MPI_Sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, |
---|
231 | int dest, int sendtag, |
---|
232 | void *recvbuf, int recvcount, MPI_Datatype recvtype, |
---|
233 | int source, int recvtag, |
---|
234 | MPI_Comm comm, MPI_Status *status) |
---|
235 | { |
---|
236 | MPI_Request request; |
---|
237 | |
---|
238 | |
---|
239 | MPI_Irecv(recvbuf, recvcount, recvtype, source, recvtag, comm, &request); |
---|
240 | |
---|
241 | MPI_Send(sendbuf, sendcount, sendtype, dest, sendtag, comm); |
---|
242 | |
---|
243 | MPI_Wait(&request,status); |
---|
244 | |
---|
245 | |
---|
246 | return(MPI_SUCCESS); |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | |
---|