1 | #include "ep_lib.hpp" |
---|
2 | #include <mpi.h> |
---|
3 | #include "ep_declaration.hpp" |
---|
4 | |
---|
5 | namespace ep_lib |
---|
6 | { |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | int MPI_Comm_free(MPI_Comm *comm) |
---|
11 | { |
---|
12 | //return 0; |
---|
13 | |
---|
14 | if(comm == NULL) return 0; |
---|
15 | |
---|
16 | MPI_Barrier(*comm); |
---|
17 | |
---|
18 | |
---|
19 | if(! comm->is_ep) |
---|
20 | { |
---|
21 | if(comm->mpi_comm) |
---|
22 | { |
---|
23 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm); |
---|
24 | |
---|
25 | ::MPI_Comm_free(&mpi_comm); |
---|
26 | Debug("comm is MPI, freed\n"); |
---|
27 | } |
---|
28 | return 0; |
---|
29 | } |
---|
30 | |
---|
31 | else |
---|
32 | { |
---|
33 | if(! comm->mpi_comm) return 0; |
---|
34 | |
---|
35 | int ep_rank, ep_rank_loc, mpi_rank; |
---|
36 | int ep_size, num_ep, mpi_size; |
---|
37 | |
---|
38 | ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; |
---|
39 | ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
40 | mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; |
---|
41 | ep_size = comm->ep_comm_ptr->size_rank_info[0].second; |
---|
42 | num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
43 | mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; |
---|
44 | |
---|
45 | MPI_Barrier(*comm); |
---|
46 | |
---|
47 | |
---|
48 | #pragma omp critical (memory_free) |
---|
49 | if(comm->is_intercomm && comm->ep_comm_ptr->intercomm) |
---|
50 | { |
---|
51 | if(comm->ep_comm_ptr->intercomm->local_rank_map) comm->ep_comm_ptr->intercomm->local_rank_map->clear(); |
---|
52 | if(comm->ep_comm_ptr->intercomm->remote_rank_map) comm->ep_comm_ptr->intercomm->remote_rank_map->clear(); |
---|
53 | if(comm->ep_comm_ptr->intercomm->intercomm_rank_map) comm->ep_comm_ptr->intercomm->intercomm_rank_map->clear(); |
---|
54 | Debug("intercomm local/remote/intercomm_rank_map emptied\n"); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | if(ep_rank_loc == 0) |
---|
59 | { |
---|
60 | Debug("comm is EP, mpi_comm_ptr != NULL\n"); |
---|
61 | |
---|
62 | |
---|
63 | /* |
---|
64 | if(comm->my_buffer) |
---|
65 | { |
---|
66 | if(comm->my_buffer->buf_int) delete[] comm->my_buffer->buf_int; Debug("buf_int freed\n"); |
---|
67 | if(comm->my_buffer->buf_float) delete[] comm->my_buffer->buf_float; Debug("buf_float freed\n"); |
---|
68 | if(comm->my_buffer->buf_double) delete[] comm->my_buffer->buf_double; Debug("buf_double freed\n"); |
---|
69 | if(comm->my_buffer->buf_long) delete[] comm->my_buffer->buf_long; Debug("buf_long freed\n"); |
---|
70 | if(comm->my_buffer->buf_ulong) delete[] comm->my_buffer->buf_ulong; Debug("buf_ulong freed\n"); |
---|
71 | if(comm->my_buffer->buf_char) delete[] comm->my_buffer->buf_char; Debug("buf_char freed\n"); |
---|
72 | } |
---|
73 | */ |
---|
74 | if(comm->ep_barrier) |
---|
75 | { |
---|
76 | comm->ep_barrier->~OMPbarrier(); |
---|
77 | Debug("ep_barrier freed\n"); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | if(comm->rank_map) |
---|
82 | { |
---|
83 | comm->rank_map->clear(); |
---|
84 | Debug("rank_map emptied\n"); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | if(comm->is_intercomm && comm->ep_comm_ptr->intercomm->mpi_inter_comm) |
---|
89 | { |
---|
90 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->ep_comm_ptr->intercomm->mpi_inter_comm); |
---|
91 | |
---|
92 | ::MPI_Comm_free(&mpi_comm); |
---|
93 | comm->ep_comm_ptr->intercomm->mpi_inter_comm = NULL; |
---|
94 | Debug("mpi_intercomm freed\n"); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | for(int i=0; i<num_ep; i++) |
---|
100 | { |
---|
101 | if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue) |
---|
102 | { |
---|
103 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear(); |
---|
104 | Debug("message queue freed\n"); |
---|
105 | } |
---|
106 | |
---|
107 | if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr) |
---|
108 | { |
---|
109 | delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr; |
---|
110 | Debug("ep_comm_ptr freed\n"); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | if(comm->mpi_comm) |
---|
115 | { |
---|
116 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm); |
---|
117 | #ifdef _serialized |
---|
118 | #pragma omp critical (_mpi_call) |
---|
119 | #endif // _serialized |
---|
120 | ::MPI_Comm_free(&mpi_comm); |
---|
121 | comm->mpi_comm = NULL; |
---|
122 | // printf("label = %d, mpi_comm freed\n", comm->ep_comm_ptr->comm_label); |
---|
123 | } |
---|
124 | |
---|
125 | if(comm) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} |
---|
126 | |
---|
127 | } |
---|
128 | return 0; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
140 | |
---|