source: XIOS/dev/branch_openmp/extern/ep_dev/ep_allreduce.cpp @ 1527

Last change on this file since 1527 was 1527, checked in by yushan, 3 years ago

save dev

File size: 1.8 KB
Line 
1/*!
2   \file ep_reduce.cpp
3   \since 2 may 2016
4
5   \brief Definitions of MPI collective function: MPI_Reduce, MPI_Allreduce
6 */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11#include "ep_mpi.hpp"
12
13using namespace std;
14
15
16namespace ep_lib
17 {
18
19  int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
20  {
21    if(!comm->is_ep) return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
22    if(comm->is_intercomm) return MPI_Allreduce_intercomm(sendbuf, recvbuf, count, datatype, op, comm);
23
24
25    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
26    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
27    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
28    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
29    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
30    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
31
32
33    ::MPI_Aint datasize, lb;
34
35    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
36
37    bool is_master = ep_rank_loc==0;
38
39    void* local_recvbuf;
40
41    if(is_master)
42    {
43      local_recvbuf = new void*[datasize * count];
44    }
45
46    MPI_Reduce_local(sendbuf, local_recvbuf, count, datatype, op, 0, comm);
47   
48
49
50    if(is_master)
51    {
52      ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
53    }
54
55    MPI_Bcast_local(recvbuf, count, datatype, 0, comm);
56
57
58    if(is_master)
59    {
60      delete[] local_recvbuf;
61    }
62
63  }
64
65
66  int MPI_Allreduce_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
67  {
68    printf("MPI_Allreduce_intercomm not yet implemented\n");
69    MPI_Abort(comm, 0);
70  }
71
72
73}
74
Note: See TracBrowser for help on using the repository browser.