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_free(MPI_Comm *comm) |
---|
10 | { |
---|
11 | if(! (*comm)->is_ep) |
---|
12 | { |
---|
13 | return MPI_Comm_free_mpi(comm); |
---|
14 | } |
---|
15 | |
---|
16 | else |
---|
17 | { |
---|
18 | if((*comm)->is_intercomm) |
---|
19 | return MPI_Comm_free_intercomm(comm); |
---|
20 | else |
---|
21 | return MPI_Comm_free_intracomm(comm); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | int MPI_Comm_free_mpi(MPI_Comm *comm) |
---|
28 | { |
---|
29 | Debug("MPI_Comm_free with MPI\n"); |
---|
30 | |
---|
31 | return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | int MPI_Comm_free_intracomm(MPI_Comm *comm) |
---|
36 | { |
---|
37 | Debug("MPI_Comm_free with EP_intracomm\n"); |
---|
38 | |
---|
39 | int ep_rank_loc, num_ep; |
---|
40 | |
---|
41 | ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; |
---|
42 | num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; |
---|
43 | |
---|
44 | MPI_Barrier(*comm); |
---|
45 | |
---|
46 | if(ep_rank_loc == 0) |
---|
47 | { |
---|
48 | |
---|
49 | #ifdef _showinfo |
---|
50 | printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); |
---|
51 | #endif |
---|
52 | delete (*comm)->my_buffer; |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | #ifdef _showinfo |
---|
57 | printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); |
---|
58 | #endif |
---|
59 | delete (*comm)->ep_barrier; |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | (*comm)->ep_rank_map->clear(); |
---|
64 | #ifdef _showinfo |
---|
65 | printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); |
---|
66 | #endif |
---|
67 | delete (*comm)->ep_rank_map; |
---|
68 | |
---|
69 | |
---|
70 | for(int i=0; i<num_ep; i++) |
---|
71 | { |
---|
72 | (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); |
---|
73 | #ifdef _showinfo |
---|
74 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue); |
---|
75 | #endif |
---|
76 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; |
---|
77 | |
---|
78 | |
---|
79 | #ifdef _showinfo |
---|
80 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr); |
---|
81 | #endif |
---|
82 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; |
---|
83 | |
---|
84 | |
---|
85 | #ifdef _showinfo |
---|
86 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); |
---|
87 | #endif |
---|
88 | delete (*comm)->ep_comm_ptr->comm_list[i]; |
---|
89 | } |
---|
90 | |
---|
91 | #ifdef _showinfo |
---|
92 | printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); |
---|
93 | #endif |
---|
94 | ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); |
---|
95 | |
---|
96 | #ifdef _showinfo |
---|
97 | printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); |
---|
98 | #endif |
---|
99 | delete[] (*comm)->ep_comm_ptr->comm_list; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | int MPI_Comm_free2(MPI_Comm *comm) |
---|
106 | { |
---|
107 | Debug("MPI_Comm_free with EP_intracomm\n"); |
---|
108 | |
---|
109 | int ep_rank_loc, num_ep; |
---|
110 | |
---|
111 | ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; |
---|
112 | num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; |
---|
113 | |
---|
114 | MPI_Barrier2(*comm); |
---|
115 | |
---|
116 | if(ep_rank_loc == 0) |
---|
117 | { |
---|
118 | |
---|
119 | #ifdef _showinfo |
---|
120 | printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); |
---|
121 | #endif |
---|
122 | delete (*comm)->my_buffer; |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | #ifdef _showinfo |
---|
127 | printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); |
---|
128 | #endif |
---|
129 | delete (*comm)->ep_barrier; |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | (*comm)->ep_rank_map->clear(); |
---|
134 | #ifdef _showinfo |
---|
135 | printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); |
---|
136 | #endif |
---|
137 | delete (*comm)->ep_rank_map; |
---|
138 | |
---|
139 | |
---|
140 | for(int i=0; i<num_ep; i++) |
---|
141 | { |
---|
142 | if((*comm)->is_intercomm) |
---|
143 | { |
---|
144 | (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map->clear(); |
---|
145 | #ifdef _showinfo |
---|
146 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->inter_rank_map = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map); |
---|
147 | #endif |
---|
148 | delete (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map; |
---|
149 | } |
---|
150 | |
---|
151 | (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); |
---|
152 | #ifdef _showinfo |
---|
153 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue); |
---|
154 | #endif |
---|
155 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; |
---|
156 | |
---|
157 | |
---|
158 | #ifdef _showinfo |
---|
159 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr); |
---|
160 | #endif |
---|
161 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; |
---|
162 | |
---|
163 | |
---|
164 | #ifdef _showinfo |
---|
165 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); |
---|
166 | #endif |
---|
167 | delete (*comm)->ep_comm_ptr->comm_list[i]; |
---|
168 | } |
---|
169 | |
---|
170 | #ifdef _showinfo |
---|
171 | printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); |
---|
172 | #endif |
---|
173 | ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); |
---|
174 | |
---|
175 | #ifdef _showinfo |
---|
176 | printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); |
---|
177 | #endif |
---|
178 | delete[] (*comm)->ep_comm_ptr->comm_list; |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | int MPI_Comm_free_intercomm(MPI_Comm *comm) |
---|
185 | { |
---|
186 | int ep_rank; |
---|
187 | MPI_Comm_rank(*comm, &ep_rank); |
---|
188 | int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; |
---|
189 | int num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; |
---|
190 | |
---|
191 | int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; |
---|
192 | int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first; |
---|
193 | int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second; |
---|
194 | |
---|
195 | MPI_Barrier(*comm); |
---|
196 | |
---|
197 | if(ep_rank_loc == 0) |
---|
198 | { |
---|
199 | (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear(); |
---|
200 | #ifdef _showinfo |
---|
201 | printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map); |
---|
202 | #endif |
---|
203 | delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map; |
---|
204 | |
---|
205 | (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear(); |
---|
206 | #ifdef _showinfo |
---|
207 | printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map); |
---|
208 | #endif |
---|
209 | delete (*comm)->ep_comm_ptr->intercomm->local_rank_map; |
---|
210 | } |
---|
211 | |
---|
212 | if(newcomm_ep_rank_loc == 0) |
---|
213 | { |
---|
214 | |
---|
215 | #ifdef _showinfo |
---|
216 | printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); |
---|
217 | #endif |
---|
218 | delete (*comm)->my_buffer; |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | #ifdef _showinfo |
---|
223 | printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); |
---|
224 | #endif |
---|
225 | delete (*comm)->ep_barrier; |
---|
226 | |
---|
227 | |
---|
228 | (*comm)->ep_rank_map->clear(); |
---|
229 | #ifdef _showinfo |
---|
230 | printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); |
---|
231 | #endif |
---|
232 | delete (*comm)->ep_rank_map; |
---|
233 | |
---|
234 | #ifdef _showinfo |
---|
235 | printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm); |
---|
236 | #endif |
---|
237 | ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm)); |
---|
238 | |
---|
239 | for(int i=0; i<newcomm_num_ep; i++) |
---|
240 | { |
---|
241 | (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); |
---|
242 | #ifdef _showinfo |
---|
243 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue); |
---|
244 | #endif |
---|
245 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; |
---|
246 | |
---|
247 | #ifdef _showinfo |
---|
248 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->intercomm = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm); |
---|
249 | #endif |
---|
250 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm; |
---|
251 | |
---|
252 | |
---|
253 | #ifdef _showinfo |
---|
254 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr); |
---|
255 | #endif |
---|
256 | delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; |
---|
257 | |
---|
258 | |
---|
259 | #ifdef _showinfo |
---|
260 | printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); |
---|
261 | #endif |
---|
262 | delete (*comm)->ep_comm_ptr->comm_list[i]; |
---|
263 | |
---|
264 | } |
---|
265 | |
---|
266 | #ifdef _showinfo |
---|
267 | printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); |
---|
268 | #endif |
---|
269 | ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); |
---|
270 | |
---|
271 | #ifdef _showinfo |
---|
272 | printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); |
---|
273 | #endif |
---|
274 | delete[] (*comm)->ep_comm_ptr->comm_list; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | } |
---|
280 | |
---|
281 | |
---|