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