[1381] | 1 | /*! |
---|
| 2 | \file ep_create.cpp |
---|
| 3 | \since 2 may 2016 |
---|
| 4 | |
---|
| 5 | \brief Definitions of MPI endpoint function: MPI_Comm_create_endpoints |
---|
| 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 | int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls) |
---|
| 18 | { |
---|
| 19 | |
---|
| 20 | int base_rank; |
---|
| 21 | int base_size; |
---|
| 22 | |
---|
| 23 | ::MPI_Comm mpi_base_comm = to_mpi_comm(base_comm_ptr); |
---|
| 24 | |
---|
| 25 | ::MPI_Comm_size(mpi_base_comm, &base_size); // ep_lib::mpi_comm_size |
---|
| 26 | ::MPI_Comm_rank(mpi_base_comm, &base_rank); // ep_lib::mpi_comm_rank |
---|
| 27 | // parent_comm can also be endpoints communicators |
---|
| 28 | |
---|
| 29 | std::vector<int> recv_num_ep(base_size); |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | out_comm_hdls = new MPI_Comm[num_ep]; |
---|
| 34 | |
---|
| 35 | for (int idx = 0; idx < num_ep; ++idx) |
---|
| 36 | { |
---|
| 37 | out_comm_hdls[idx].is_ep = true; |
---|
| 38 | out_comm_hdls[idx].is_intercomm = false; |
---|
| 39 | out_comm_hdls[idx].ep_comm_ptr = new ep_communicator; |
---|
| 40 | *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx].mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr)); |
---|
| 41 | out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls; |
---|
| 42 | out_comm_hdls[idx].ep_comm_ptr->comm_label = 0; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | ::MPI_Allgather(&num_ep, 1, to_mpi_type(MPI_INT), &recv_num_ep[0], 1, to_mpi_type(MPI_INT), mpi_base_comm); |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | int sum = 0; // representing total ep number of process with smaller rank |
---|
| 49 | for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; } |
---|
| 50 | |
---|
| 51 | int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0); |
---|
| 52 | |
---|
| 53 | out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep); |
---|
| 54 | out_comm_hdls[0].my_buffer = new BUFFER; |
---|
| 55 | |
---|
| 56 | out_comm_hdls[0].rank_map = new RANK_MAP; |
---|
| 57 | out_comm_hdls[0].rank_map->resize(ep_size); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | for (int i = 1; i < num_ep; i++) |
---|
| 61 | { |
---|
| 62 | out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier; |
---|
| 63 | out_comm_hdls[i].my_buffer = out_comm_hdls[0].my_buffer; |
---|
| 64 | out_comm_hdls[i].rank_map = out_comm_hdls[0].rank_map; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | for (int i = 0; i < num_ep; i++) |
---|
| 69 | { |
---|
| 70 | out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size); |
---|
| 71 | out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep); |
---|
| 72 | out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size); |
---|
| 73 | |
---|
| 74 | out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | int ind = 0; |
---|
| 79 | |
---|
| 80 | for(int i=0; i<base_size; i++) |
---|
| 81 | { |
---|
| 82 | for(int j=0; j<recv_num_ep[i]; j++) |
---|
| 83 | { |
---|
| 84 | out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i); |
---|
| 85 | ind++; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | return 0; |
---|
| 90 | |
---|
| 91 | } //MPI_Comm_create_endpoints |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | } //namespace ep_lib |
---|