forked from ESMCI/mpi-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomm.c
297 lines (201 loc) · 5.07 KB
/
comm.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#include "mpiP.h"
/*
* Communicators
*
*/
MPI_Comm mpi_comm_new(void)
{
MPI_Comm chandle;
Comm *cptr;
static int num=0;
mpi_alloc_handle(&chandle,(void **) &cptr);
cptr->sendlist=AP_list_new();
cptr->recvlist=AP_list_new();
cptr->num=num++;
return(chandle);
}
/*********/
int FC_FUNC( mpi_comm_free , MPI_COMM_FREE )(int *comm, int *ierror)
{
*ierror=MPI_Comm_free(comm);
return MPI_SUCCESS;
}
/*
* MPI_Comm_free()
*
* Note: will NOT free any pending MPI_Request handles
* that are allocated... correct user code should have
* already done a Wait or Test to free them.
*
*/
int MPI_Comm_free(MPI_Comm *comm)
{
pList sendlist, recvlist;
int size;
Comm *mycomm;
mycomm=mpi_handle_to_ptr(*comm); /* (Comm *)(*comm) */
sendlist=mycomm->sendlist;
recvlist=mycomm->recvlist;
size=AP_list_size(sendlist);
if (size!=0)
fprintf(stderr,"MPI_Comm_free: warning: %d pending send reqs\n",
size);
AP_list_free(sendlist);
size=AP_list_size(recvlist);
if (size!=0)
fprintf(stderr,"MPI_Comm_free: warning: %d pending receive reqs\n",
size);
AP_list_free(recvlist);
mpi_free_handle(*comm); /* free(mycomm); */
*comm=MPI_COMM_NULL;
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_size , MPI_COMM_SIZE )(int *comm, int *size, int *ierror)
{
*ierror=MPI_Comm_size(*comm, size);
return MPI_SUCCESS;
}
int MPI_Comm_size(MPI_Comm comm, int *size)
{
*size=1;
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_rank , MPI_COMM_RANK )(int *comm, int *rank, int *ierror)
{
*ierror=MPI_Comm_rank( *comm, rank);
return MPI_SUCCESS;
}
int MPI_Comm_rank(MPI_Comm comm, int *rank)
{
*rank=0;
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_dup , MPI_COMM_DUP )(int *comm, int *newcomm, int *ierror)
{
*ierror=MPI_Comm_dup( *comm, newcomm);
return MPI_SUCCESS;
}
int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
{
*newcomm= mpi_comm_new();
#ifdef INFO
fflush(stdout);
fprintf(stderr,"MPI_Comm_dup: new comm handle=%d\n",*newcomm);
#endif
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_create, MPI_COMM_CREATE)
(int *comm, int *group, int *newcomm, int *ierror)
{
*ierror=MPI_Comm_create(*comm,*group,newcomm);
return MPI_SUCCESS;
}
int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm *newcomm)
{
if (group==MPI_GROUP_NULL || group==MPI_GROUP_EMPTY)
*newcomm= MPI_COMM_NULL;
else
*newcomm=mpi_comm_new();
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_split, MPI_COMM_SPLIT )
(int *comm, int *color, int *key, int *newcomm, int *ierror)
{
*ierror=MPI_Comm_split(*comm,*color,*key,newcomm);
return MPI_SUCCESS;
}
int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm)
{
if (color==MPI_UNDEFINED)
*newcomm=MPI_COMM_NULL;
else
*newcomm= mpi_comm_new();
return(MPI_SUCCESS);
}
/*********/
int FC_FUNC( mpi_comm_group, MPI_COMM_GROUP )
(int *comm, int *group, int *ierror)
{
*ierror= MPI_Comm_group(*comm, group);
return MPI_SUCCESS;
}
int MPI_Comm_group(MPI_Comm comm, MPI_Group *group)
{
if (comm==MPI_COMM_NULL)
*group= MPI_GROUP_NULL;
else
*group= MPI_GROUP_ONE;
return(MPI_SUCCESS);
}
/* Intercomm_create
*
*/
int FC_FUNC(mpi_intercomm_create, MPI_INTERCOMM_CREATE)(
int * local_comm, int * local_leader,
int * peer_comm, int * remote_leader,
int * tag, int * newintercomm, int* ierr)
{
*ierr = MPI_Intercomm_create(*local_comm, *local_leader, *peer_comm,
*remote_leader, *tag, newintercomm);
return MPI_SUCCESS;
}
int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader,
MPI_Comm peer_comm, int remote_leader,
int tag, MPI_Comm *newintercomm)
{
if (local_comm==MPI_COMM_NULL && peer_comm==MPI_COMM_NULL)
*newintercomm = MPI_COMM_NULL;
else
MPI_Comm_dup(MPI_COMM_WORLD, newintercomm);
return MPI_SUCCESS;
}
int MPI_Comm_test_inter(MPI_Comm comm, int *flag)
{
if (comm == MPI_COMM_NULL)
return MPI_ERR_COMM;
*flag = 1;
return MPI_SUCCESS;
}
int MPI_Comm_compare( MPI_Comm comm1, MPI_Comm comm2, int *result)
{
if (comm1 == comm2)
*result = MPI_IDENT;
else if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL)
*result = MPI_UNEQUAL;
else
*result = MPI_CONGRUENT;
return MPI_SUCCESS;
}
int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
{
*flag = 0;
if (comm == MPI_COMM_NULL)
return MPI_ERR_COMM;
return MPI_ERR_KEYVAL;
}
int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
{
return MPI_SUCCESS;
}
int MPI_Topo_test(MPI_Comm comm, int *status)
{
if (comm == MPI_COMM_NULL)
return MPI_ERR_COMM;
*status = MPI_UNDEFINED;
return MPI_SUCCESS;
}
/*********/
MPI_Comm MPI_Comm_f2c(MPI_Fint comm)
{
/* Comm is an integer handle used both by C and Fortran */
return(comm);
}
MPI_Fint MPI_Comm_c2f(MPI_Comm comm)
{
return(comm);
}