source: CPL/oasis3-mct_5.0/lib/mct/mpi-serial/collective.c @ 6328

Last change on this file since 6328 was 6328, checked in by aclsce, 17 months ago

First import of oasis3-mct_5.0 (from oasis git server, branch OASIS3-MCT_5.0)

File size: 11.1 KB
Line 
1
2#include "mpiP.h"
3
4
5
6/*
7 * COLLECTIVE
8 */
9
10
11FC_FUNC( mpi_barrier , MPI_BARRIER )(int *comm, int *ierror)
12{
13  *ierror=MPI_Barrier( *comm );
14}
15
16
17int MPI_Barrier(MPI_Comm comm )
18{
19  return(MPI_SUCCESS);
20}
21
22
23/*********/
24
25
26FC_FUNC( mpi_bcast , MPI_BCAST )(void *buffer, int *count, int *datatype,
27                                   int *root, int *comm, int *ierror )
28{
29  *ierror=MPI_Bcast(buffer, *count, *datatype, *root, *comm);
30}
31
32
33
34int MPI_Bcast(void* buffer, int count, MPI_Datatype datatype,
35              int root, MPI_Comm comm )
36{
37  if (root==MPI_ROOT)
38    return(MPI_SUCCESS);
39
40  if (root!=0)
41    {
42      fprintf(stderr,"MPI_Bcast: bad root = %d\n",root);
43      abort();
44    }
45
46
47  return(MPI_SUCCESS);
48}
49
50
51/*********/
52
53
54FC_FUNC( mpi_gather , MPI_GATHER )
55                       (void *sendbuf, int *sendcount, int *sendtype,
56                        void *recvbuf, int *recvcount, int *recvtype,
57                        int *root, int *comm, int *ierror)
58{
59  *ierror=MPI_Gather( mpi_c_in_place(sendbuf), *sendcount, *sendtype,
60                      recvbuf, *recvcount, *recvtype,
61                      *root, *comm);
62}
63
64
65int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype,
66               void* recvbuf, int recvcount, MPI_Datatype recvtype,
67               int root, MPI_Comm comm)
68{
69  if (sendbuf==MPI_IN_PLACE)
70    return(MPI_SUCCESS);
71
72  if (root==MPI_ROOT)
73    return(MPI_SUCCESS);
74
75  if (root!=0)
76    {
77      fprintf(stderr,"MPI_Gather: bad root = %d\n",root);
78      abort();
79    }
80
81  copy_data2(sendbuf, sendcount, sendtype,
82             recvbuf, recvcount, recvtype);
83//  memcpy(recvbuf,sendbuf,sendcount*sendtype);
84
85  return(MPI_SUCCESS);
86}
87
88/*********/
89
90
91
92FC_FUNC( mpi_gatherv , MPI_GATHERV )
93                        ( void *sendbuf, int *sendcount, int *sendtype,
94                          void *recvbuf, int *recvcounts, int *displs,
95                          int *recvtype, int *root, int *comm, int *ierror)
96{
97  *ierror=MPI_Gatherv( mpi_c_in_place(sendbuf), *sendcount, *sendtype,
98                       recvbuf, recvcounts, displs,
99                       *recvtype, *root, *comm);
100}
101
102
103int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype,
104                void* recvbuf, int *recvcounts, int *displs,
105                MPI_Datatype recvtype, int root, MPI_Comm comm)
106{
107  int offset;
108  MPI_Aint rt_extent;
109
110  if (sendbuf==MPI_IN_PLACE)
111    return(MPI_SUCCESS);
112
113  if (root==MPI_ROOT)
114    return(MPI_SUCCESS);
115
116  if (root!=0)
117    {
118      fprintf(stderr,"MPI_Gatherv: bad root = %d\n",root);
119      abort();
120    }
121
122  MPI_Type_extent(recvtype, &rt_extent);
123  offset=displs[0]*rt_extent;
124
125  copy_data2(sendbuf, sendcount, sendtype,
126             (char*)recvbuf+offset, recvcounts[0], recvtype);
127
128//  memcpy( (char *)recvbuf+offset, sendbuf, recvcounts[0] * recvtype);
129
130  return(MPI_SUCCESS);
131}
132
133
134
135/*********/
136
137
138FC_FUNC( mpi_allgather , MPI_ALLGATHER )
139                          ( void *sendbuf, int *sendcount, int *sendtype,
140                            void *recvbuf, int *recvcount, int *recvtype,
141                            int *comm, int *ierror)
142{
143  *ierror=MPI_Allgather( mpi_c_in_place(sendbuf), *sendcount, *sendtype,
144                         recvbuf, *recvcount, *recvtype,
145                         *comm );
146}
147
148
149int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype,
150                  void* recvbuf, int recvcount, MPI_Datatype recvtype,
151                  MPI_Comm comm)
152{
153  if (sendbuf==MPI_IN_PLACE)
154    return(MPI_SUCCESS);
155
156  copy_data2(sendbuf, sendcount, sendtype,
157             recvbuf, recvcount, recvtype);
158//  memcpy(recvbuf,sendbuf,sendcount * sendtype);
159
160  return(MPI_SUCCESS);
161
162}
163
164
165/*********/
166
167
168FC_FUNC( mpi_allgatherv , MPI_ALLGATHERV )
169                          ( void *sendbuf, int *sendcount, int *sendtype,
170                            void *recvbuf, int *recvcounts, int *displs,
171                            int *recvtype, int *comm, int *ierror)
172{
173  *ierror=MPI_Allgatherv( mpi_c_in_place(sendbuf), *sendcount, *sendtype,
174                          recvbuf, recvcounts, displs,
175                          *recvtype, *comm );
176}
177
178
179int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype,
180                   void* recvbuf, int *recvcounts, int *displs,
181                   MPI_Datatype recvtype, MPI_Comm comm)
182{
183  int offset;
184  MPI_Aint rt_extent;
185
186  if (sendbuf==MPI_IN_PLACE)
187    return(MPI_SUCCESS);
188
189  MPI_Type_extent(recvtype, &rt_extent);
190  offset=displs[0]*rt_extent;
191
192  copy_data2(sendbuf, sendcount, sendtype,
193             (char*)recvbuf+offset, recvcounts[0], recvtype);
194
195//  memcpy( (char *)recvbuf+offset, sendbuf, recvcounts[0] * recvtype);
196
197  return(MPI_SUCCESS);
198}
199
200
201/*********/
202
203/* MPI_Scatter
204 * Scattering to one proc involves only one copy operation, so copy
205 * data from source to dest pointer
206 */
207
208FC_FUNC( mpi_scatter, MPI_SCATTER )
209                         ( void *sendbuf, int *sendcount, int *sendtype,
210                         void *recvbuf, int *recvcount, int *recvtype,
211                         int *root, int *comm, int *ierror)
212{
213  *ierror = MPI_Scatter(sendbuf, *sendcount, *sendtype,
214                        mpi_c_in_place(recvbuf), *recvcount, *recvtype,
215                        *root, *comm);
216}
217
218int MPI_Scatter(void * sendbuf, int sendcount, MPI_Datatype sendtype,
219                void * recvbuf, int recvcount, MPI_Datatype recvtype,
220                int root, MPI_Comm comm)
221{
222  if (recvbuf==MPI_IN_PLACE)
223    return(MPI_SUCCESS);
224
225  if (root==MPI_ROOT)
226    return(MPI_SUCCESS);
227
228  if (root!=0)
229    {
230      fprintf(stderr,"MPI_Scatter: bad root = %d\n",root);
231      abort();
232    }
233
234  copy_data2(sendbuf, sendcount, sendtype,
235             recvbuf, recvcount, recvtype);
236
237  return(MPI_SUCCESS);
238}
239
240
241
242/*********/
243
244
245FC_FUNC( mpi_scatterv , MPI_SCATTERV )
246                         ( void *sendbuf, int *sendcounts, int *displs,
247                           int *sendtype, void *recvbuf, int *recvcount,
248                           int *recvtype, int *root, int *comm, int *ierror)
249{
250  *ierror=MPI_Scatterv(sendbuf, sendcounts, displs,
251                       *sendtype, mpi_c_in_place(recvbuf), *recvcount,
252                       *recvtype, *root, *comm);
253}
254
255
256
257int MPI_Scatterv(void* sendbuf, int *sendcounts, int *displs,
258                 MPI_Datatype sendtype, void* recvbuf, int recvcount,
259                 MPI_Datatype recvtype, int root, MPI_Comm comm)
260{
261  int offset;
262  MPI_Aint st_extent;
263
264  if (recvbuf==MPI_IN_PLACE)
265    return(MPI_SUCCESS);
266
267  if (root==MPI_ROOT)
268    return(MPI_SUCCESS);
269
270  if (root!=0)
271    {
272      fprintf(stderr,"MPI_Scatterv: bad root = %d\n",root);
273      abort();
274    }
275  MPI_Type_extent(sendtype, &st_extent);
276  offset=displs[0]*st_extent;
277
278  copy_data2((char*)sendbuf+offset, sendcounts[0], sendtype,
279             recvbuf, recvcount, recvtype);
280//  memcpy(recvbuf,(char *)sendbuf+offset,sendcounts[0] * sendtype);
281
282  return(MPI_SUCCESS);
283}
284
285
286
287/*********/
288
289
290FC_FUNC( mpi_reduce , MPI_REDUCE )
291                       ( void *sendbuf, void *recvbuf, int *count,
292                         int *datatype, int *op, int *root, int *comm,
293                         int *ierror)
294{
295  *ierror=MPI_Reduce(sendbuf, recvbuf, *count,
296                     *datatype, *op, *root, *comm);
297}
298
299
300
301int MPI_Reduce(void* sendbuf, void* recvbuf, int count,
302               MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
303
304{
305  if (root!=0)
306    {
307      fprintf(stderr,"MPI_Reduce: bad root = %d\n",root);
308      abort();
309    }
310
311  copy_data2(sendbuf, count, datatype, recvbuf, count, datatype);
312//  memcpy(recvbuf,sendbuf,count * datatype);
313
314  return(MPI_SUCCESS);
315}
316
317
318/*********/
319
320
321FC_FUNC( mpi_allreduce , MPI_ALLREDUCE )
322                          ( void *sendbuf, void *recvbuf, int *count,
323                            int *datatype, int *op, int *comm, int *ierror)
324{
325  *ierror=MPI_Allreduce(sendbuf, recvbuf, *count,
326                        *datatype, *op, *comm);
327
328}
329
330
331int MPI_Allreduce(void* sendbuf, void* recvbuf, int count,
332                  MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
333{
334  if (sendbuf==MPI_IN_PLACE)
335    return(MPI_SUCCESS);
336
337  copy_data2(sendbuf, count, datatype, recvbuf, count, datatype);
338//  memcpy(recvbuf,sendbuf,count * datatype);
339
340  return(MPI_SUCCESS);
341
342}
343
344
345/*********/
346
347
348/* MPI_Reduce_scatter
349 * Performs reduction of n*sum(recvcounts) and distributes to all members
350 * in a group. We do this to only one proc, so recvcounts[0] is only used.
351 */
352
353FC_FUNC(mpi_reduce_scatter, MPI_REDUCE_SCATTER)
354                (void * sendbuf, void * recvbuf, int *recvcounts,
355                 int *datatype, int *op, int *comm, int *ierr)
356{
357  *ierr = MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, *datatype, *op, *comm);
358}
359
360
361int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int *recvcounts,
362                         MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
363{
364  copy_data2(sendbuf, recvcounts[0], datatype, recvbuf, recvcounts[0], datatype);
365}
366
367
368/*********/
369
370
371FC_FUNC( mpi_scan , MPI_SCAN)
372                       ( void *sendbuf, void *recvbuf, int *count,
373                         int *datatype, int *op, int *comm,
374                         int *ierror)
375{
376  *ierror=MPI_Scan( sendbuf, recvbuf, *count,
377                    *datatype, *op, *comm);
378}
379
380
381
382int MPI_Scan(void* sendbuf, void* recvbuf, int count,
383             MPI_Datatype datatype, MPI_Op op, MPI_Comm comm )
384{
385    copy_data2(sendbuf, count, datatype, recvbuf, count, datatype);
386
387    return(MPI_SUCCESS);
388}
389
390/*********/
391
392
393FC_FUNC( mpi_alltoall , MPI_ALLTOALL )
394                        ( void *sendbuf, int *sendcount, int *sendtype,
395                          void *recvbuf, int *recvcount, int *recvtype,
396                          int *comm, int *ierror )
397{
398  *ierror=MPI_Alltoall(sendbuf, *sendcount, *sendtype,
399                       recvbuf, *recvcount, *recvtype,
400                       *comm);
401}
402
403
404int MPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
405                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
406                 MPI_Comm comm)
407{
408  copy_data2(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
409//  memcpy(recvbuf,sendbuf,sendcount * sendtype);
410
411  return(MPI_SUCCESS);
412}
413
414
415/*********/
416
417
418FC_FUNC( mpi_alltoallv , MPI_ALLTOALLV )
419           ( void *sendbuf, int *sendcounts, int *sdispls, int *sendtype,
420             void *recvbuf, int *recvcounts, int *rdispls, int *recvtype,
421             int *comm, int *ierror )
422{
423
424  *ierror=MPI_Alltoallv(sendbuf, sendcounts, sdispls, *sendtype,
425                        recvbuf, recvcounts, rdispls, *recvtype,
426                        *comm);
427
428}
429
430int MPI_Alltoallv(void *sendbuf, int *sendcounts,
431                  int *sdispls, MPI_Datatype sendtype,
432                  void *recvbuf, int *recvcounts,
433                  int *rdispls, MPI_Datatype recvtype,
434                  MPI_Comm comm)
435
436{
437  int send_offset;
438  int recv_offset;
439  MPI_Aint st_extent;
440  MPI_Aint rt_extent;
441
442  MPI_Type_extent(sendtype, &st_extent);
443  MPI_Type_extent(recvtype, &rt_extent);
444
445  send_offset=sdispls[0]*st_extent;
446  recv_offset=rdispls[0]*rt_extent;
447
448  copy_data2((char*)sendbuf+send_offset, sendcounts[0], sendtype,
449             (char*)recvbuf+recv_offset, recvcounts[0], recvtype);
450
451//  memcpy( (char *)recvbuf+recv_offset, (char *)sendbuf+send_offset,
452//        sendcounts[0] * sendtype);
453
454
455  return(MPI_SUCCESS);
456}
457
458
459/*********/
460
461
462FC_FUNC( mpi_alltoallw , MPI_ALLTOALLW )
463           ( void *sendbuf, int *sendcounts, int *sdispls, int *sendtypes,
464             void *recvbuf, int *recvcounts, int *rdispls, int *recvtypes,
465             int *comm, int *ierror )
466{
467
468  *ierror=MPI_Alltoallw(sendbuf, sendcounts, sdispls, sendtypes,
469                        recvbuf, recvcounts, rdispls, recvtypes,
470                        *comm);
471
472}
473
474
475int MPI_Alltoallw(void *sendbuf, int *sendcounts,
476                  int *sdispls, MPI_Datatype *sendtypes,
477                  void *recvbuf, int *recvcounts,
478                  int *rdispls, MPI_Datatype *recvtypes,
479                  MPI_Comm comm)
480
481{
482
483  copy_data2((char*)sendbuf+sdispls[0], sendcounts[0], sendtypes[0],
484             (char*)recvbuf+rdispls[0], recvcounts[0], recvtypes[0]);
485
486
487  return(MPI_SUCCESS);
488}
489
490
491
492/*********/
493
494MPI_Op MPI_Op_f2c(MPI_Fint op)
495{
496  return(op);
497}
498
499
500/*********/
501
502
503MPI_Fint MPI_Op_c2f(MPI_Op op)
504{
505  return(op);
506}
Note: See TracBrowser for help on using the repository browser.