/*! \file ep_gather.cpp \since 2 may 2016 \brief Definitions of MPI collective function: MPI_Scatterv */ #include "ep_lib.hpp" #include #include "ep_declaration.hpp" #include "ep_mpi.hpp" using namespace std; namespace ep_lib { int MPI_Scatterv_local(const void *sendbuf, const int sendcounts[], const int displs[], MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int local_root, MPI_Comm comm) { assert(valid_type(sendtype) && valid_type(recvtype)); ::MPI_Aint datasize, lb; ::MPI_Type_get_extent(to_mpi_type(sendtype), &lb, &datasize); int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; assert(recvcount == sendcounts[ep_rank_loc]); if(ep_rank_loc == local_root) comm->my_buffer->void_buffer[local_root] = const_cast(sendbuf); MPI_Barrier_local(comm); #pragma omp critical (_scatterv) memcpy(recvbuf, comm->my_buffer->void_buffer[local_root]+datasize*displs[ep_rank_loc], datasize * recvcount); MPI_Barrier_local(comm); } int MPI_Scatterv(const void *sendbuf, const int sendcounts[], const int displs[], MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { if(!comm->is_ep) return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm)); if(comm->is_intercomm) return MPI_Scatterv_intercomm(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm); assert(sendtype == recvtype); int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; int root_mpi_rank = comm->ep_rank_map->at(root).second; int root_ep_loc = comm->ep_rank_map->at(root).first; bool is_master = (ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root; bool is_root = ep_rank == root; MPI_Datatype datatype = sendtype; int count = recvcount; ::MPI_Aint datasize, lb; ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); void *tmp_sendbuf; if(is_root) tmp_sendbuf = new void*[ep_size * count * datasize]; // reorder tmp_sendbuf std::vectorlocal_ranks(num_ep); std::vectorranks(ep_size); if(mpi_rank == root_mpi_rank) MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), root_ep_loc, comm); else MPI_Gather_local(&ep_rank, 1, MPI_INT, local_ranks.data(), 0, comm); std::vector recvcounts(mpi_size, 0); std::vector my_displs(mpi_size, 0); if(is_master) { for(int i=0; iep_rank_map->at(i).second]++; } for(int i=1; impi_comm)); } if(is_root) { int local_displs = 0; for(int i=0; impi_comm)); if(is_root) for(int i=1; impi_comm)); } std::vectorlocal_sendcounts(num_ep, 0); std::vectorlocal_displs(num_ep, 0); MPI_Gather_local(&recvcount, 1, MPI_INT, local_sendcounts.data(), 0, comm); MPI_Bcast_local(local_sendcounts.data(), num_ep, MPI_INT, 0, comm); for(int i=1; i