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