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 | { |
---|
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 | |
---|
17 | ::MPI_Comm input = to_mpi_comm(comm->mpi_comm); |
---|
18 | ::MPI_Comm *output = new ::MPI_Comm; |
---|
19 | |
---|
20 | |
---|
21 | ::MPI_Comm_dup(input, output); |
---|
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 |
---|
31 | if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0; |
---|
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; |
---|
42 | ::MPI_Comm *mpi_dup = new ::MPI_Comm; |
---|
43 | |
---|
44 | ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm); |
---|
45 | |
---|
46 | ::MPI_Comm_dup(in_comm, mpi_dup); |
---|
47 | |
---|
48 | MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); |
---|
49 | comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; |
---|
50 | } |
---|
51 | |
---|
52 | MPI_Barrier(comm); |
---|
53 | |
---|
54 | *newcomm = (comm->ep_comm_ptr->comm_list[0]->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 | |
---|
62 | if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0; |
---|
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; |
---|
72 | ::MPI_Comm *mpi_dup = new ::MPI_Comm; |
---|
73 | |
---|
74 | ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm); |
---|
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 | |
---|
82 | ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter); |
---|
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->inter_rank_map = new RANK_MAP; |
---|
93 | out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map = new RANK_MAP; |
---|
94 | out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; |
---|
95 | |
---|
96 | int map_size = 0; |
---|
97 | map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->size(); |
---|
98 | out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map->resize(map_size); |
---|
99 | for(int ii=0; ii<map_size; ii++) |
---|
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); |
---|
101 | |
---|
102 | map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->size(); |
---|
103 | out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map->resize(map_size); |
---|
104 | for(int ii=0; ii<map_size; ii++) |
---|
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); |
---|
106 | |
---|
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); |
---|
109 | for(int ii=0; ii<map_size; ii++) |
---|
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); |
---|
111 | |
---|
112 | |
---|
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; |
---|
116 | |
---|
117 | //out_comm[i]->ep_comm_ptr->intercomm->local_comm = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_comm; |
---|
118 | out_comm[i]->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_tag; |
---|
119 | |
---|
120 | for(int j =0; j<3; j++) |
---|
121 | { |
---|
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]; |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; |
---|
128 | } |
---|
129 | |
---|
130 | MPI_Barrier(comm); |
---|
131 | |
---|
132 | *newcomm = comm->ep_comm_ptr->comm_list[0]->mem_bridge[my_rank]; |
---|
133 | |
---|
134 | |
---|
135 | return MPI_SUCCESS; |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | |
---|