Changeset 1517 for XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp
- Timestamp:
- 06/01/18 15:24:53 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp
r1515 r1517 11 11 if(! (*comm)->is_ep) 12 12 { 13 if((*comm)->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm)) 14 { 15 ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm); 16 17 ::MPI_Comm_free(&mpi_comm); 18 Debug("comm is MPI, freed\n"); 19 } 20 return 0; 21 } 22 23 else if((*comm)->is_intercomm) 24 { 25 return MPI_Comm_free_intercomm(comm); 26 } 27 28 else 29 { 30 int ep_rank_loc, num_ep; 31 32 ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; 33 num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; 34 35 MPI_Barrier(*comm); 36 37 if(ep_rank_loc == 0) 38 { 39 Debug("comm is EP, mpi_comm_ptr != NULL\n"); 40 41 delete (*comm)->my_buffer; 42 43 44 if((*comm)->ep_barrier != NULL) 45 { 46 (*comm)->ep_barrier->~ep_barrier(); 47 Debug("ep_barrier freed\n"); 48 } 49 50 51 if( ! (*comm)->ep_rank_map->empty() ) 52 { 53 (*comm)->ep_rank_map->clear(); 54 delete (*comm)->ep_rank_map; 55 Debug("ep_rank_map emptied and freed\n"); 56 } 57 58 for(int i=0; i<num_ep; i++) 59 { 60 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); 61 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; 62 Debug("message queue freed\n"); 63 64 65 if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr != NULL) 66 { 67 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; 68 Debug("ep_comm_ptr freed\n"); 69 } 70 } 71 72 if( to_mpi_comm((*comm)->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm) 73 && to_mpi_comm((*comm)->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_WORLD->mpi_comm)) 74 { 75 ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm); 76 ::MPI_Comm_free(&mpi_comm); 77 Debug("mpi_comm freed\n"); 78 } 79 80 //if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} 81 82 } 83 84 return 0; 85 } 86 87 88 89 } 90 91 int MPI_Comm_free_intercomm(MPI_Comm *comm) 92 { 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 93 39 int ep_rank_loc, num_ep; 94 //MPI_Barrier(*comm);95 96 return 0;97 40 98 41 ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; 99 42 num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; 100 43 101 102 103 //MPI_Barrier(*comm); 44 MPI_Barrier(*comm); 104 45 105 46 if(ep_rank_loc == 0) 106 47 { 107 Debug("comm is EP, mpi_comm_ptr != NULL\n"); 108 109 110 if((*comm)->ep_barrier != NULL) 111 { 112 (*comm)->ep_barrier->~ep_barrier(); 113 Debug("ep_barrier freed\n"); 114 } 115 116 117 if( ! (*comm)->ep_rank_map->empty() ) 118 { 119 (*comm)->ep_rank_map->clear(); 120 delete (*comm)->ep_rank_map; 121 Debug("ep_rank_map emptied and freed\n"); 122 } 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 123 69 124 70 for(int i=0; i<num_ep; i++) 125 71 { 126 72 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); 127 Debug("message queue freed\n"); 128 129 #pragma omp critical (memory_free) 130 if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm != NULL)131 {132 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->clear(); 133 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->clear(); 134 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->clear();135 Debug("intercomm local/remote/intercomm_rank_map emptied\n"); 136 }137 138 if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr != NULL) 139 { 140 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;141 Debug("ep_comm_ptr freed\n"); 142 }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]; 143 89 } 144 90 145 if((*comm)->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm)) 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 106 107 108 109 int MPI_Comm_free_intercomm(MPI_Comm *comm) 110 { 111 int ep_rank; 112 MPI_Comm_rank(*comm, &ep_rank); 113 int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; 114 int num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; 115 116 int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 117 int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first; 118 int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second; 119 120 MPI_Barrier(*comm); 121 122 if(ep_rank_loc == 0) 123 { 124 (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear(); 125 #ifdef _showinfo 126 printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map); 127 #endif 128 delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map; 129 130 (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear(); 131 #ifdef _showinfo 132 printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map); 133 #endif 134 delete (*comm)->ep_comm_ptr->intercomm->local_rank_map; 135 } 136 137 if(newcomm_ep_rank_loc == 0) 138 { 139 140 #ifdef _showinfo 141 printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); 142 #endif 143 delete (*comm)->my_buffer; 144 145 146 147 #ifdef _showinfo 148 printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); 149 #endif 150 delete (*comm)->ep_barrier; 151 152 153 (*comm)->ep_rank_map->clear(); 154 #ifdef _showinfo 155 printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); 156 #endif 157 delete (*comm)->ep_rank_map; 158 159 #ifdef _showinfo 160 printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm); 161 #endif 162 ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm)); 163 164 for(int i=0; i<newcomm_num_ep; i++) 146 165 { 147 ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm); 148 ::MPI_Comm_free(&mpi_comm); 149 Debug("mpi_comm freed\n"); 166 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); 167 #ifdef _showinfo 168 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); 169 #endif 170 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; 171 172 #ifdef _showinfo 173 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); 174 #endif 175 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm; 176 177 178 #ifdef _showinfo 179 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); 180 #endif 181 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; 182 183 184 #ifdef _showinfo 185 printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); 186 #endif 187 delete (*comm)->ep_comm_ptr->comm_list[i]; 188 150 189 } 151 190 152 if((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm)) 153 { 154 ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->ep_comm_ptr->comm_list[0]->ep_comm_ptr->intercomm->mpi_inter_comm); 155 ::MPI_Comm_free(&mpi_comm); 156 Debug("mpi_intercomm freed\n"); 157 } 158 159 if(comm != NULL) {delete[] (*comm)->ep_comm_ptr->comm_list; Debug("comm freed\n");} 160 161 } 162 163 164 165 return 0; 166 } 167 191 #ifdef _showinfo 192 printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); 193 #endif 194 ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); 195 196 #ifdef _showinfo 197 printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); 198 #endif 199 delete[] (*comm)->ep_comm_ptr->comm_list; 200 } 201 } 168 202 169 203
Note: See TracChangeset
for help on using the changeset viewer.