[1381] | 1 | #include "ep_lib.hpp" |
---|
| 2 | #include <mpi.h> |
---|
| 3 | #include "ep_declaration.hpp" |
---|
| 4 | #include "ep_mpi.hpp" |
---|
| 5 | |
---|
| 6 | namespace ep_lib |
---|
| 7 | { |
---|
| 8 | |
---|
| 9 | int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) |
---|
| 10 | { |
---|
[1500] | 11 | if(!comm->is_ep) |
---|
[1381] | 12 | { |
---|
| 13 | Debug("Comm_dup MPI\n"); |
---|
| 14 | newcomm = new MPI_Comm; |
---|
[1500] | 15 | (*newcomm)->is_ep = comm->is_ep; |
---|
[1381] | 16 | |
---|
[1500] | 17 | ::MPI_Comm input = to_mpi_comm(comm->mpi_comm); |
---|
[1381] | 18 | ::MPI_Comm *output = new ::MPI_Comm; |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | ::MPI_Comm_dup(input, output); |
---|
| 22 | |
---|
[1500] | 23 | (*newcomm)->mpi_comm = output; |
---|
[1381] | 24 | |
---|
| 25 | return 0; |
---|
| 26 | } |
---|
| 27 | |
---|
[1500] | 28 | if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm); |
---|
[1381] | 29 | |
---|
| 30 | // for intracomm |
---|
[1500] | 31 | if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0; |
---|
[1381] | 32 | |
---|
| 33 | |
---|
[1500] | 34 | int my_rank = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 35 | int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
[1381] | 36 | |
---|
| 37 | |
---|
| 38 | if(0 == my_rank) |
---|
| 39 | { |
---|
| 40 | MPI_Info info; |
---|
| 41 | MPI_Comm *out_comm; |
---|
| 42 | ::MPI_Comm *mpi_dup = new ::MPI_Comm; |
---|
| 43 | |
---|
[1500] | 44 | ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm); |
---|
[1381] | 45 | |
---|
| 46 | ::MPI_Comm_dup(in_comm, mpi_dup); |
---|
| 47 | |
---|
| 48 | MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); |
---|
[1500] | 49 | comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; |
---|
[1381] | 50 | } |
---|
| 51 | |
---|
| 52 | MPI_Barrier(comm); |
---|
| 53 | |
---|
[1500] | 54 | *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[my_rank]); |
---|
[1381] | 55 | |
---|
| 56 | return MPI_SUCCESS; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm) |
---|
| 60 | { |
---|
| 61 | |
---|
[1500] | 62 | if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0; |
---|
[1381] | 63 | |
---|
[1500] | 64 | int my_rank = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 65 | int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
[1381] | 66 | |
---|
| 67 | |
---|
| 68 | if(0 == my_rank) |
---|
| 69 | { |
---|
| 70 | MPI_Info info; |
---|
| 71 | MPI_Comm *out_comm; |
---|
| 72 | ::MPI_Comm *mpi_dup = new ::MPI_Comm; |
---|
| 73 | |
---|
[1500] | 74 | ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm); |
---|
[1381] | 75 | |
---|
| 76 | ::MPI_Comm_dup(in_comm, mpi_dup); |
---|
| 77 | |
---|
| 78 | MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); |
---|
| 79 | |
---|
| 80 | ::MPI_Comm *mpi_inter = new ::MPI_Comm; |
---|
| 81 | |
---|
[1500] | 82 | ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter); |
---|
[1381] | 83 | |
---|
| 84 | for(int i=0; i<num_ep; i++) |
---|
| 85 | { |
---|
[1500] | 86 | out_comm[i]->ep_comm_ptr->comm_label = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->comm_label; |
---|
| 87 | out_comm[i]->ep_comm_ptr->intercomm = new ep_intercomm; |
---|
[1381] | 88 | |
---|
[1500] | 89 | out_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter; |
---|
| 90 | out_comm[i]->is_intercomm = true; |
---|
[1381] | 91 | |
---|
[1512] | 92 | out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map = new RANK_MAP; |
---|
[1515] | 93 | out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map = new RANK_MAP; |
---|
[1500] | 94 | out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; |
---|
[1381] | 95 | |
---|
[1499] | 96 | int map_size = 0; |
---|
[1500] | 97 | map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->size(); |
---|
[1512] | 98 | out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map->resize(map_size); |
---|
[1499] | 99 | for(int ii=0; ii<map_size; ii++) |
---|
[1500] | 100 | out_comm[i]->ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->at(ii); |
---|
[1381] | 101 | |
---|
[1500] | 102 | map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->size(); |
---|
[1515] | 103 | out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map->resize(map_size); |
---|
[1499] | 104 | for(int ii=0; ii<map_size; ii++) |
---|
[1500] | 105 | out_comm[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii); |
---|
[1499] | 106 | |
---|
[1500] | 107 | map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->size(); |
---|
| 108 | out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map->resize(map_size); |
---|
[1499] | 109 | for(int ii=0; ii<map_size; ii++) |
---|
[1500] | 110 | out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->at(ii); |
---|
[1499] | 111 | |
---|
| 112 | |
---|
[1500] | 113 | //out_comm[i]->ep_comm_ptr->intercomm->intercomm_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map; |
---|
| 114 | //out_comm[i]->ep_comm_ptr->intercomm->local_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map; |
---|
| 115 | //out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map; |
---|
[1499] | 116 | |
---|
[1512] | 117 | //out_comm[i]->ep_comm_ptr->intercomm->local_comm = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_comm; |
---|
[1500] | 118 | out_comm[i]->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_tag; |
---|
[1381] | 119 | |
---|
| 120 | for(int j =0; j<3; j++) |
---|
| 121 | { |
---|
[1500] | 122 | out_comm[i]->ep_comm_ptr->intercomm->size_rank_info[j] = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->size_rank_info[j]; |
---|
[1381] | 123 | } |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | |
---|
[1500] | 127 | comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; |
---|
[1381] | 128 | } |
---|
| 129 | |
---|
| 130 | MPI_Barrier(comm); |
---|
| 131 | |
---|
[1500] | 132 | *newcomm = comm->ep_comm_ptr->comm_list[0]->mem_bridge[my_rank]; |
---|
[1381] | 133 | |
---|
| 134 | |
---|
| 135 | return MPI_SUCCESS; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|