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

Last change on this file since 1381 was 1381, checked in by yushan, 6 years ago

add folder for MPI EP-RMA development. Current: MPI_Win, MPI_win_create, MPI_win_fence, MPI_win_free

File size: 1.5 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
20
21  int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
22  {
23    if(!comm.is_ep && comm.mpi_comm)
24    {
25      return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));
26    }
27
28
29
30    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
31    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
32    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
33    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
34    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
35    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
36
37
38    ::MPI_Aint datasize, lb;
39
40    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
41
42    bool is_master = ep_rank_loc==0;
43
44    void* local_recvbuf;
45
46    if(is_master)
47    {
48      local_recvbuf = new void*[datasize * count];
49    }
50
51    MPI_Reduce_local(sendbuf, local_recvbuf, count, datatype, op, 0, comm);
52   
53
54
55    if(is_master)
56    {
57      ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));
58    }
59
60    MPI_Bcast_local(recvbuf, count, datatype, 0, comm);
61
62
63    if(is_master)
64    {
65      delete[] local_recvbuf;
66    }
67
68    MPI_Barrier_local(comm);
69  }
70
71 
72
73
74}
75
Note: See TracBrowser for help on using the repository browser.