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