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