[1381] | 1 | /*! |
---|
| 2 | \file ep_bcast.cpp |
---|
| 3 | \since 2 may 2016 |
---|
| 4 | |
---|
| 5 | \brief Definitions of MPI collective function: MPI_Bcast |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ep_lib.hpp" |
---|
| 9 | #include <mpi.h> |
---|
| 10 | #include "ep_declaration.hpp" |
---|
| 11 | #include "ep_mpi.hpp" |
---|
| 12 | |
---|
| 13 | using namespace std; |
---|
| 14 | |
---|
| 15 | namespace ep_lib |
---|
| 16 | { |
---|
| 17 | |
---|
| 18 | int MPI_Bcast_local(void *buffer, int count, MPI_Datatype datatype, int local_root, MPI_Comm comm) |
---|
| 19 | { |
---|
| 20 | assert(valid_type(datatype)); |
---|
| 21 | |
---|
[1500] | 22 | int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
[1381] | 23 | |
---|
| 24 | ::MPI_Aint datasize, lb; |
---|
| 25 | ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | if(ep_rank_loc == local_root) |
---|
| 29 | { |
---|
[1500] | 30 | comm->my_buffer->void_buffer[local_root] = buffer; |
---|
[1381] | 31 | } |
---|
| 32 | |
---|
| 33 | MPI_Barrier_local(comm); |
---|
| 34 | |
---|
| 35 | if(ep_rank_loc != local_root) |
---|
| 36 | { |
---|
| 37 | #pragma omp critical (_bcast) |
---|
[1500] | 38 | memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count); |
---|
[1381] | 39 | } |
---|
| 40 | |
---|
| 41 | MPI_Barrier_local(comm); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) |
---|
| 45 | { |
---|
| 46 | |
---|
[1500] | 47 | if(!comm->is_ep) |
---|
[1381] | 48 | { |
---|
| 49 | #pragma omp single nowait |
---|
[1500] | 50 | ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm)); |
---|
[1381] | 51 | return 0; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
[1500] | 55 | int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; |
---|
| 56 | int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 57 | int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; |
---|
[1381] | 58 | |
---|
[1503] | 59 | int root_mpi_rank = comm->ep_rank_map->at(root).second; |
---|
| 60 | int root_ep_rank_loc = comm->ep_rank_map->at(root).first; |
---|
[1381] | 61 | |
---|
| 62 | |
---|
| 63 | if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root) |
---|
| 64 | { |
---|
[1500] | 65 | ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); |
---|
[1381] | 66 | } |
---|
| 67 | |
---|
| 68 | if(mpi_rank == root_mpi_rank) MPI_Bcast_local(buffer, count, datatype, root_ep_rank_loc, comm); |
---|
| 69 | else MPI_Bcast_local(buffer, count, datatype, 0, comm); |
---|
| 70 | |
---|
| 71 | return 0; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | } |
---|