[1646] | 1 | #ifdef _usingEP |
---|
[1603] | 2 | /*! |
---|
| 3 | \file ep_bcast.cpp |
---|
| 4 | \since 2 may 2016 |
---|
| 5 | |
---|
| 6 | \brief Definitions of MPI collective function: MPI_Bcast |
---|
| 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 | namespace ep_lib |
---|
| 17 | { |
---|
| 18 | |
---|
| 19 | int MPI_Bcast_local(void *buffer, int count, MPI_Datatype datatype, int local_root, MPI_Comm comm) |
---|
| 20 | { |
---|
| 21 | assert(valid_type(datatype)); |
---|
| 22 | |
---|
| 23 | int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 24 | |
---|
| 25 | ::MPI_Aint datasize, lb; |
---|
| 26 | ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | if(ep_rank_loc == local_root) |
---|
| 30 | { |
---|
| 31 | comm->my_buffer->void_buffer[local_root] = buffer; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | MPI_Barrier_local(comm); |
---|
| 35 | |
---|
| 36 | if(ep_rank_loc != local_root) |
---|
| 37 | { |
---|
| 38 | #pragma omp critical (_bcast) |
---|
| 39 | memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | MPI_Barrier_local(comm); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | if(!comm->is_ep) return ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm)); |
---|
| 49 | if(comm->is_intercomm) return MPI_Bcast_intercomm(buffer, count, datatype, root, comm); |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; |
---|
| 53 | int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 54 | int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; |
---|
| 55 | |
---|
| 56 | int root_mpi_rank = comm->ep_rank_map->at(root).second; |
---|
| 57 | int root_ep_rank_loc = comm->ep_rank_map->at(root).first; |
---|
| 58 | |
---|
| 59 | //printf("ep_rank = %d, root_mpi_rank = %d, root_ep_rank_loc = %d\n", ep_rank, root_mpi_rank, root_ep_rank_loc); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root) |
---|
| 63 | { |
---|
| 64 | ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if(mpi_rank == root_mpi_rank) MPI_Bcast_local(buffer, count, datatype, root_ep_rank_loc, comm); |
---|
| 68 | else MPI_Bcast_local(buffer, count, datatype, 0, comm); |
---|
| 69 | |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | int MPI_Bcast_intercomm(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) |
---|
| 74 | { |
---|
| 75 | printf("MPI_Bcast_intercomm not yet implemented\n"); |
---|
| 76 | MPI_Abort(comm, 0); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | } |
---|
[1646] | 81 | #endif |
---|