[1134] | 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 | |
---|
| 13 | if(! comm->is_ep) |
---|
| 14 | { |
---|
| 15 | if(comm->mpi_comm != MPI_COMM_NULL_STD) |
---|
| 16 | { |
---|
| 17 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm); |
---|
| 18 | |
---|
| 19 | ::MPI_Comm_free(&mpi_comm); |
---|
| 20 | Debug("comm is MPI, freed\n"); |
---|
| 21 | } |
---|
| 22 | return 0; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | else if(comm->is_intercomm) |
---|
| 26 | { |
---|
| 27 | return MPI_Comm_free_intercomm(comm); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | else |
---|
| 31 | { |
---|
| 32 | int ep_rank_loc, num_ep; |
---|
| 33 | |
---|
| 34 | ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 35 | num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 36 | |
---|
| 37 | MPI_Barrier(*comm); |
---|
| 38 | |
---|
| 39 | if(ep_rank_loc == 0) |
---|
| 40 | { |
---|
| 41 | Debug("comm is EP, mpi_comm_ptr != NULL\n"); |
---|
| 42 | |
---|
| 43 | if(comm->my_buffer != NULL) |
---|
| 44 | { |
---|
| 45 | if(comm->my_buffer->buf_int != NULL) delete[] comm->my_buffer->buf_int; Debug("buf_int freed\n"); |
---|
| 46 | if(comm->my_buffer->buf_float != NULL) delete[] comm->my_buffer->buf_float; Debug("buf_float freed\n"); |
---|
| 47 | if(comm->my_buffer->buf_double != NULL) delete[] comm->my_buffer->buf_double; Debug("buf_double freed\n"); |
---|
| 48 | if(comm->my_buffer->buf_long != NULL) delete[] comm->my_buffer->buf_long; Debug("buf_long freed\n"); |
---|
| 49 | if(comm->my_buffer->buf_ulong != NULL) delete[] comm->my_buffer->buf_ulong; Debug("buf_ulong freed\n"); |
---|
| 50 | if(comm->my_buffer->buf_char != NULL) delete[] comm->my_buffer->buf_char; Debug("buf_char freed\n"); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | if(comm->ep_barrier != NULL) |
---|
| 54 | { |
---|
| 55 | comm->ep_barrier->~OMPbarrier(); |
---|
| 56 | Debug("ep_barrier freed\n"); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | if( ! comm->rank_map->empty() ) |
---|
| 61 | { |
---|
| 62 | comm->rank_map->clear(); |
---|
| 63 | Debug("rank_map emptied\n"); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | for(int i=0; i<num_ep; i++) |
---|
| 67 | { |
---|
| 68 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear(); |
---|
| 69 | Debug("message queue freed\n"); |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL) |
---|
| 73 | { |
---|
| 74 | delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr; |
---|
| 75 | Debug("ep_comm_ptr freed\n"); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if(comm->mpi_comm != MPI_COMM_NULL_STD) |
---|
| 80 | { |
---|
| 81 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm); |
---|
| 82 | ::MPI_Comm_free(&mpi_comm); |
---|
| 83 | Debug("mpi_comm freed\n"); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | int MPI_Comm_free_intercomm(MPI_Comm *comm) |
---|
| 97 | { |
---|
| 98 | int ep_rank_loc, num_ep; |
---|
| 99 | |
---|
| 100 | ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 101 | num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 102 | |
---|
| 103 | //MPI_Barrier(*comm); |
---|
| 104 | |
---|
| 105 | if(ep_rank_loc == 0) |
---|
| 106 | { |
---|
| 107 | Debug("comm is EP, mpi_comm_ptr != NULL\n"); |
---|
| 108 | |
---|
| 109 | if(comm->my_buffer != NULL) |
---|
| 110 | { |
---|
| 111 | if(comm->my_buffer->buf_int != NULL) delete[] comm->my_buffer->buf_int; Debug("buf_int freed\n"); |
---|
| 112 | if(comm->my_buffer->buf_float != NULL) delete[] comm->my_buffer->buf_float; Debug("buf_float freed\n"); |
---|
| 113 | if(comm->my_buffer->buf_double != NULL) delete[] comm->my_buffer->buf_double; Debug("buf_double freed\n"); |
---|
| 114 | if(comm->my_buffer->buf_long != NULL) delete[] comm->my_buffer->buf_long; Debug("buf_long freed\n"); |
---|
| 115 | if(comm->my_buffer->buf_ulong != NULL) delete[] comm->my_buffer->buf_ulong; Debug("buf_ulong freed\n"); |
---|
| 116 | if(comm->my_buffer->buf_char != NULL) delete[] comm->my_buffer->buf_char; Debug("buf_char freed\n"); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if(comm->ep_barrier != NULL) |
---|
| 120 | { |
---|
| 121 | comm->ep_barrier->~OMPbarrier(); |
---|
| 122 | Debug("ep_barrier freed\n"); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | if( ! comm->rank_map->empty() ) |
---|
| 127 | { |
---|
| 128 | comm->rank_map->clear(); |
---|
| 129 | Debug("rank_map emptied\n"); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | for(int i=0; i<num_ep; i++) |
---|
| 133 | { |
---|
| 134 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear(); |
---|
| 135 | Debug("message queue freed\n"); |
---|
| 136 | |
---|
| 137 | #pragma omp critical (memory_free) |
---|
| 138 | if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm != NULL) |
---|
| 139 | { |
---|
| 140 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->clear(); |
---|
| 141 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->clear(); |
---|
| 142 | comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->clear(); |
---|
| 143 | Debug("intercomm local/remote/intercomm_rank_map emptied\n"); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL) |
---|
| 147 | { |
---|
| 148 | delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr; |
---|
| 149 | Debug("ep_comm_ptr freed\n"); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | if(comm->mpi_comm != MPI_COMM_NULL_STD) |
---|
| 154 | { |
---|
| 155 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm); |
---|
| 156 | ::MPI_Comm_free(&mpi_comm); |
---|
| 157 | Debug("mpi_comm freed\n"); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | // if(comm->ep_comm_ptr->intercomm->mpi_inter_comm != MPI_COMM_NULL_STD) |
---|
| 161 | // { |
---|
| 162 | // ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->ep_comm_ptr->comm_list->ep_comm_ptr->intercomm->mpi_inter_comm); |
---|
| 163 | // ::MPI_Comm_free(&mpi_comm); |
---|
| 164 | // Debug("mpi_intercomm freed\n"); |
---|
| 165 | // } |
---|
| 166 | |
---|
| 167 | if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} |
---|
| 168 | |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | return 0; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | |
---|