Changeset 1511
- Timestamp:
- 05/30/18 20:08:15 (6 years ago)
- Location:
- XIOS/dev/branch_openmp/extern/ep_dev
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/extern/ep_dev/ep_allgather.cpp
r1504 r1511 37 37 memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count); 38 38 } 39 MPI_Barrier_local(comm); 39 40 } 40 41 -
XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp
r1503 r1511 52 52 BUFFER *my_buffer; 53 53 ep_barrier *ep_barrier; 54 //RANK_MAP *rank_map;55 54 EP_RANK_MAP *ep_rank_map; 56 55 void* mpi_comm; -
XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp
r1504 r1511 101 101 } //MPI_Comm_create_endpoints 102 102 103 103 104 104 105 } //namespace ep_lib -
XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp
r1503 r1511 61 61 if( leader_ranks[1] * leader_ranks[4] == 1) 62 62 { 63 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_unique_leader\n");63 if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n"); 64 64 local_comm->ep_comm_ptr->comm_label = -99; 65 65 … … 167 167 local_comm->ep_comm_ptr->comm_label = tag; 168 168 169 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n");169 if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n"); 170 170 171 171 return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD->mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm); … … 174 174 } 175 175 176 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_kernel\n");176 if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_kernel\n"); 177 177 178 178 return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); -
XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp
r1503 r1511 5 5 typedef std::vector< std::pair<int, int> > RANK_MAP; // at(ep_rank) = <ep_rank_local, mpi_rank> 6 6 typedef std::map<int, std::pair<int, int> > EP_RANK_MAP; // key(ep_rank) = <ep_rank_local, mpi_rank> 7 //typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP;7 typedef std::map<int, std::pair< int, std::pair<int, int> > > INTERCOMM_RANK_MAP; 8 8 9 9 namespace ep_lib … … 18 18 void *mpi_inter_comm; 19 19 20 RANK_MAP *intercomm_rank_map;20 INTERCOMM_RANK_MAP *intercomm_rank_map; 21 21 RANK_MAP *local_rank_map; 22 22 RANK_MAP *remote_rank_map; -
XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp
r1503 r1511 20 20 num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 21 21 mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 22 23 24 // step 1 : local leaders exchange ep_size then bcast to all ep in local_comm 25 26 int remote_ep_size; 27 bool is_local_leader = ep_rank==local_leader? true: false; 28 29 if(is_local_leader) 30 { 31 MPI_Request request[2]; 32 MPI_Status status[2]; 33 MPI_Isend(&ep_size, 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 34 MPI_Irecv(&remote_ep_size, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 35 MPI_Waitall(2, request, status); 36 } 37 38 MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 39 40 #ifdef _showinfo 41 MPI_Barrier(peer_comm); 42 MPI_Barrier(peer_comm); 43 #pragma omp critical(stdoutput) 44 printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size); 45 MPI_Barrier(peer_comm); 46 MPI_Barrier(peer_comm); 47 #endif 48 49 // step 2 : gather ranks in world for both local and remote comm 50 51 int rank_in_world; 52 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world); 53 54 int *ranks_in_world_local = new int[ep_size]; 55 int *ranks_in_world_remote = new int[remote_ep_size]; 56 57 MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm); 58 59 if(is_local_leader) 60 { 61 MPI_Request request[2]; 62 MPI_Status status[2]; 63 MPI_Isend(ranks_in_world_local, ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 64 MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 65 MPI_Waitall(2, request, status); 66 } 67 68 MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm); 69 70 #ifdef _showinfo 71 72 MPI_Barrier(peer_comm); 73 MPI_Barrier(peer_comm); 74 75 if(remote_leader == 4) 76 { 77 for(int i=0; i<ep_size; i++) 78 { 79 if(ep_rank == i) 80 { 81 printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 82 for(int i=0; i<ep_size; i++) 83 { 84 printf("%d\t", ranks_in_world_local[i]); 85 } 86 87 printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 88 for(int i=0; i<remote_ep_size; i++) 89 { 90 printf("%d\t", ranks_in_world_remote[i]); 91 } 92 printf("\n"); 93 94 } 95 96 MPI_Barrier(local_comm); 97 MPI_Barrier(local_comm); 98 MPI_Barrier(local_comm); 99 } 100 } 101 102 MPI_Barrier(peer_comm); 103 MPI_Barrier(peer_comm); 104 MPI_Barrier(peer_comm); 105 106 if(remote_leader == 13) 107 { 108 for(int i=0; i<ep_size; i++) 109 { 110 if(ep_rank == i) 111 { 112 printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 113 for(int i=0; i<ep_size; i++) 114 { 115 printf("%d\t", ranks_in_world_local[i]); 116 } 117 118 printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 119 for(int i=0; i<remote_ep_size; i++) 120 { 121 printf("%d\t", ranks_in_world_remote[i]); 122 } 123 printf("\n"); 124 125 } 126 127 MPI_Barrier(local_comm); 128 MPI_Barrier(local_comm); 129 MPI_Barrier(local_comm); 130 } 131 } 132 133 MPI_Barrier(peer_comm); 134 MPI_Barrier(peer_comm); 135 136 #endif 137 138 139 // step 3 : determine the priority and ownership of each ep 140 141 int local_leader_rank_in_peer; 142 int remote_leader_rank_in_peer; 143 144 if(is_local_leader) MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer); 145 146 if(is_local_leader) 147 { 148 MPI_Request request[2]; 149 MPI_Status status[2]; 150 MPI_Isend(&local_leader_rank_in_peer, 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 151 MPI_Irecv(&remote_leader_rank_in_peer, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 152 MPI_Waitall(2, request, status); 153 } 154 155 MPI_Bcast(&local_leader_rank_in_peer, 1, MPI_INT, local_leader, local_comm); 156 MPI_Bcast(&remote_leader_rank_in_peer, 1, MPI_INT, local_leader, local_comm); 157 158 bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false; 159 160 #ifdef _showinfo 161 MPI_Barrier(peer_comm); 162 MPI_Barrier(peer_comm); 163 printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer); 164 MPI_Barrier(peer_comm); 165 MPI_Barrier(peer_comm); 166 #endif 167 168 int local_leader_rank_in_world = ranks_in_world_local[local_leader]; 169 int remote_leader_rank_in_world; 170 171 if(is_local_leader) 172 { 173 MPI_Request request[2]; 174 MPI_Status status[2]; 175 MPI_Isend(&local_leader_rank_in_world, 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 176 MPI_Irecv(&remote_leader_rank_in_world, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 177 MPI_Waitall(2, request, status); 178 } 179 180 MPI_Bcast(&remote_leader_rank_in_world, 1, MPI_INT, local_leader, local_comm); 181 182 int ownership; 183 184 if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1; 185 else if(rank_in_world == remote_leader_rank_in_world) ownership = 0; 186 else 187 { 188 ownership = 1; 189 for(int i=0; i<remote_ep_size; i++) 190 { 191 if(rank_in_world == ranks_in_world_remote[i]) 192 { 193 ownership = priority? 1 : 0; 194 break; 195 } 196 } 197 } 198 199 #ifdef _showinfo 200 MPI_Barrier(peer_comm); 201 MPI_Barrier(peer_comm); 202 printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership); 203 MPI_Barrier(peer_comm); 204 MPI_Barrier(peer_comm); 205 #endif 206 207 208 // step 4 : extract local_comm and create intercomm 209 210 bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world); 211 212 #ifdef _showinfo 213 214 MPI_Barrier(peer_comm); 215 MPI_Barrier(peer_comm); 216 printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved); 217 MPI_Barrier(peer_comm); 218 MPI_Barrier(peer_comm); 219 220 #endif 221 222 if(is_involved) 223 { 224 ::MPI_Group local_group; 225 ::MPI_Group extracted_group; 226 ::MPI_Comm *extracted_comm = new ::MPI_Comm; 227 228 229 ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group); 230 231 int *ownership_list = new int[mpi_size]; 232 int *mpi_rank_list = new int[mpi_size]; 233 234 ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 235 ::MPI_Allgather(&mpi_rank, 1, to_mpi_type(MPI_INT), mpi_rank_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 236 237 238 int n=0; 239 for(int i=0; i<mpi_size; i++) 240 { 241 n+=ownership_list[i]; 242 } 243 244 int *new_mpi_rank_list = new int[n]; 245 int j=0; 246 for(int i=0; i<mpi_size; i++) 247 { 248 if(ownership_list[i] !=0) 249 { 250 new_mpi_rank_list[j++] = mpi_rank_list[i]; 251 } 252 } 253 254 255 ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group); 256 257 ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, extracted_comm); 258 259 ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm; 260 261 int local_leader_rank_in_extracted_comm; 262 263 if(is_local_leader) 264 { 265 ::MPI_Comm_rank(*extracted_comm, &local_leader_rank_in_extracted_comm); 266 } 267 268 ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 269 270 int local_leader_rank_in_peer_mpi; 271 int remote_leader_rank_in_peer_mpi; 272 273 ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi); 274 275 if(is_local_leader) 276 { 277 MPI_Request request[2]; 278 MPI_Status status[2]; 279 MPI_Isend(&local_leader_rank_in_peer_mpi, 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 280 MPI_Irecv(&remote_leader_rank_in_peer_mpi, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 281 MPI_Waitall(2, request, status); 282 } 283 284 ::MPI_Bcast(&remote_leader_rank_in_peer_mpi, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 285 286 287 if(ownership) 288 ::MPI_Intercomm_create(*extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, mpi_inter_comm); 289 290 291 // step 5 :: determine new num_ep 292 293 int num_ep_count=0; 294 295 for(int i=0; i<ep_size; i++) 296 { 297 if(rank_in_world == ranks_in_world_local[i]) 298 num_ep_count++; 299 } 300 301 for(int i=0; i<remote_ep_size; i++) 302 { 303 if(rank_in_world == ranks_in_world_remote[i]) 304 num_ep_count++; 305 } 306 307 //printf("peer_rank = %d, num_ep_count = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, num_ep_count); 308 309 310 // step 6 : create endpoints from extracted_comm 311 312 if(ownership) 313 { 314 MPI_Comm *ep_comm; 315 MPI_Info info; 316 MPI_Comm_create_endpoints(extracted_comm, num_ep_count, info, ep_comm); 317 318 for(int i=0; i<num_ep_count; i++) 319 { 320 ep_comm[i]->is_intercomm = true; 321 ep_comm[i]->ep_comm_ptr->comm_label = ranks_in_world_local[local_leader]; 322 ep_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 323 ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm; 324 } 325 326 //delete ep_comm[0]->ep_rank_map; 327 328 329 #pragma omp critical (write_to_tag_list) 330 intercomm_list.push_back(make_pair( make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)) , make_pair(ep_comm , make_pair(num_ep_count, 0)))); 331 #pragma omp flush 332 #ifdef _showinfo 333 for(int i=0; i<num_ep_count; i++) 334 printf("peer_rank = %d, ep_comm = %p, ep_comm[%d] -> new_ep_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_comm, i, ep_comm[i]->ep_comm_ptr->size_rank_info[0].first); 335 #endif 336 } 337 338 339 delete ownership_list; 340 delete mpi_rank_list; 341 delete new_mpi_rank_list; 342 343 } 344 345 int repeated=0; 346 for(int i=0; i<remote_ep_size; i++) 347 { 348 if(rank_in_world == ranks_in_world_remote[i]) 349 repeated++; 350 } 351 352 int my_turn = ownership? ep_rank_loc : ep_rank_loc+repeated; 353 354 #ifdef _showinfo 355 356 MPI_Barrier(peer_comm); 357 MPI_Barrier(peer_comm); 358 printf("peer_rank = %d, ep_rank_loc = %d, ownership = %d, repeated = %d, my_turn = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_rank_loc, ownership, repeated, my_turn); 359 MPI_Barrier(peer_comm); 360 MPI_Barrier(peer_comm); 361 362 #endif 363 364 365 #pragma omp flush 366 #pragma omp critical (read_from_intercomm_list) 367 { 368 bool flag=true; 369 while(flag) 370 { 371 for(std::list<std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > >::iterator iter = intercomm_list.begin(); iter!=intercomm_list.end(); iter++) 372 { 373 if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world))) 374 { 375 *newintercomm = iter->second.first[my_turn]; 376 377 iter->second.second.second++; 378 379 if(iter->second.second.first == iter->second.second.second) 380 intercomm_list.erase(iter); 381 382 flag = false; 383 break; 384 } 385 } 386 } 387 } 388 389 #ifdef _showinfo 390 391 MPI_Barrier(peer_comm); 392 MPI_Barrier(peer_comm); 393 printf("peer_rank = %d, test_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].first); 394 MPI_Barrier(peer_comm); 395 MPI_Barrier(peer_comm); 396 397 #endif 398 399 400 // step 7 : create intercomm_rank_map for local leaders 401 402 int my_quadruple[4]; 403 404 my_quadruple[0] = ep_rank; 405 my_quadruple[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 406 my_quadruple[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first; 407 my_quadruple[3] = (*newintercomm)->ep_comm_ptr->comm_label; 408 409 410 #ifdef _showinfo 411 412 MPI_Barrier(peer_comm); 413 MPI_Barrier(peer_comm); 414 printf("peer_rank = %d, my_quadruple = %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, my_quadruple[0], my_quadruple[1], my_quadruple[2], my_quadruple[3]); 415 MPI_Barrier(peer_comm); 416 MPI_Barrier(peer_comm); 417 #endif 418 419 int *local_quadruple_list; 420 int *remote_quadruple_list; 421 if(is_involved) 422 { 423 local_quadruple_list = new int[4*ep_size]; 424 remote_quadruple_list = new int[4*remote_ep_size]; 425 426 } 427 428 MPI_Gather(my_quadruple, 4, MPI_INT, local_quadruple_list, 4, MPI_INT, local_leader, local_comm); 429 430 431 if(is_local_leader) 432 { 433 MPI_Request request[2]; 434 MPI_Status status[2]; 435 MPI_Isend(local_quadruple_list, 4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[0]); 436 MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[1]); 437 MPI_Waitall(2, request, status); 438 } 439 440 if(is_involved) 441 { 442 ::MPI_Bcast(remote_quadruple_list, 4*remote_ep_size, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 443 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP; 444 for(int i=0; i<remote_ep_size; i++) 445 { 446 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->insert(std::pair<int, std::pair< int, std::pair<int, int> > >(remote_quadruple_list[4*i], remote_quadruple_list[4*i+1], remote_quadruple_list[4*i+2], remote_quadruple_list[4*i+3])); 447 } 448 } 449 450 451 // step 8 : associate intercomm_rank_map to endpoints 452 453 int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 454 455 MPI_Allgather_local(&local_leader_rank_in_world, 1, MPI_INT, leader_rank_in_world_local_gathered, *newintercomm); 456 457 458 int new_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 459 int *new_rank_loc_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 460 461 MPI_Allgather_local(&new_rank_loc, 1, MPI_INT, new_rank_loc_local_gathered, *newintercomm); 462 463 //printf("peer_rank = %d, leader_rank_in_world_local_gathered = %d %d %d %d, new_rank_loc_local_gathered = %d %d %d %d\n", 464 // peer_comm->ep_comm_ptr->size_rank_info[0].first, leader_rank_in_world_local_gathered[0], leader_rank_in_world_local_gathered[1], leader_rank_in_world_local_gathered[2], leader_rank_in_world_local_gathered[3], 465 // new_rank_loc_local_gathered[0], new_rank_loc_local_gathered[1], new_rank_loc_local_gathered[2], new_rank_loc_local_gathered[3]); 466 467 if(is_involved) 468 { 469 if((*newintercomm)->ep_comm_ptr->size_rank_info[1].first == 0) 470 { 471 (*newintercomm)->ep_rank_map->clear(); 472 delete (*newintercomm)->ep_rank_map; 473 } 474 (*newintercomm)->ep_rank_map = new EP_RANK_MAP[ep_size]; 475 *((*newintercomm)->ep_rank_map) = *(local_comm->ep_rank_map); 476 } 477 478 MPI_Barrier_local(*newintercomm); 479 480 481 if(!is_involved) 482 { 483 int target; 484 for(int i=0; i<(*newintercomm)->ep_comm_ptr->size_rank_info[1].second; i++) 485 { 486 if(local_leader_rank_in_world == leader_rank_in_world_local_gathered[i]) 487 { 488 target = i; 489 break; 490 } 491 } 492 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map; 493 (*newintercomm)->ep_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_rank_map; 494 } 495 496 497 //printf("peer_rank = %d, intercomm_rank_map add = %p\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map); 498 499 500 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 501 { 502 int receiver = rand()%10; 503 printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 504 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 505 } 506 507 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 9) 508 { 509 int receiver = rand()%6; 510 printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 511 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 512 } 513 514 //printf("peer_rank = %d, rank_map add = %p\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_rank_map); 515 516 517 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 518 { 519 for(int i=0; i<ep_size; i++) 520 { 521 printf("rank_map->at(%d) = %d, %d\n", i, (*newintercomm)->ep_rank_map->at(i).first, (*newintercomm)->ep_rank_map->at(i).second); 522 } 523 } 524 525 526 // clean up 527 528 delete ranks_in_world_local; 529 delete ranks_in_world_remote; 530 531 if(is_involved) 532 { 533 delete local_quadruple_list; 534 delete remote_quadruple_list; 535 } 536 537 delete leader_rank_in_world_local_gathered; 538 delete new_rank_loc_local_gathered; 539 540 541 } 542 543 int MPI_Intercomm_create_kernel_bkp(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm) 544 { 545 int ep_rank, ep_rank_loc, mpi_rank; 546 int ep_size, num_ep, mpi_size; 547 548 ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first; 549 ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 550 mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first; 551 ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second; 552 num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 553 mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 554 22 555 23 556 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm … … 531 1064 532 1065 533 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;534 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);1066 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 1067 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 535 1068 536 1069 … … 558 1091 for(ii=0; ii<vec2map.size(); ii++) 559 1092 { 560 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second);1093 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second); 561 1094 } 562 1095 … … 564 1097 } 565 1098 566 MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, new_bcast_root, *newintercomm);1099 //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, new_bcast_root, *newintercomm); 567 1100 568 1101 (*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]); -
XIOS/dev/branch_openmp/extern/ep_dev/ep_split.cpp
r1506 r1511 222 222 } 223 223 } 224 225 #ifdef _showinfo 226 printf("ep_rank = %d, color = %d, key = %d, new_ep_rank = %d, new_ep_rank_loc = %d\n", ep_rank, color, key, new_ep_rank, new_ep_rank_loc); 227 #endif 228 229 MPI_Barrier(comm); 230 MPI_Barrier(comm); 231 MPI_Barrier(comm); 224 232 225 233 -
XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp
r1503 r1511 42 42 43 43 44 //typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size>45 46 //typedef std::vector< std::pair<int, int> > RANK_MAP; // at(ep_rank) = <ep_rank_local, mpi_rank>47 //typedef std::map<int, std::pair<int, int> > EP_RANK_MAP; // key(ep_rank) = <ep_rank_local, mpi_rank>48 49 //typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP;50 51 44 52 45 namespace ep_lib … … 55 48 class ep_communicator; 56 49 class ep_intercomm; 57 class OMPbarrier;58 typedef ep_communicator* EP_Comm;59 //class MPI_Comm;60 50 61 /*62 class MPI_Status63 {64 public:65 66 void* ep_datatype;67 int ep_src;68 int ep_tag;69 void* mpi_status;70 };71 72 class MPI_Message73 {74 public:75 76 void* mpi_message;77 int ep_src;78 int ep_tag;79 void* mpi_status;80 81 MPI_Message() {}82 MPI_Message(void* message);83 };84 85 typedef std::list<MPI_Message > Message_list;86 */87 88 class OMPbarrier89 {90 private:91 int nbThreads; //<The number of threads for this barrier92 int currentNbThread; //<The current number of threads waiting93 bool sense; //<Direct barrier feedback protection94 omp_lock_t mutex; //<To have an atomic int95 96 OMPbarrier(OMPbarrier&){}97 OMPbarrier& operator=(OMPbarrier&){return *this;}98 99 public:100 /** Constructor with the number of threads */101 explicit OMPbarrier(const int inNbThreads)102 : nbThreads(inNbThreads), currentNbThread(0), sense(false) {103 omp_init_lock( &mutex );104 }105 106 /** Destructor, release the omp lock */107 ~OMPbarrier(){108 omp_destroy_lock( &mutex );109 }110 111 /** Perform a barrier */112 void wait(){113 const bool mySense = sense;114 omp_set_lock( &mutex );115 const int nbThreadsArrived = (++currentNbThread);116 omp_unset_lock( &mutex );117 118 if(nbThreadsArrived == nbThreads) {119 currentNbThread = 0;120 sense = !sense;121 #pragma omp flush122 }123 else {124 volatile const bool* const ptSense = &sense;125 while( (*ptSense) == mySense){126 }127 }128 }129 130 131 /** Change the number of threads */132 void setNbThreads(const int inNbThread){133 omp_set_lock( &mutex );134 nbThreads = inNbThread;135 omp_unset_lock( &mutex );136 }137 };138 139 /*140 class ep_intercomm141 {142 public:143 144 void *mpi_inter_comm;145 146 RANK_MAP *intercomm_rank_map;147 RANK_MAP *local_rank_map;148 RANK_MAP *remote_rank_map;149 150 151 SIZE_RANK_INFO size_rank_info[3];152 153 154 MPI_Comm *local_comm;155 int intercomm_tag;156 157 ep_intercomm();158 //~ep_intercomm(){delete mpi_inter_comm;}159 bool operator == (ep_intercomm right);160 bool operator != (ep_intercomm right);161 162 };163 164 class ep_communicator165 {166 public:167 168 SIZE_RANK_INFO size_rank_info[3]; // 0: ep_rank, ep_size169 // 1: ep_rank_loc, num_ep170 // 2: mpi_rank, mpi_size171 172 173 MPI_Comm *comm_list;174 175 Message_list *message_queue;176 177 178 int comm_label;179 180 ep_intercomm *intercomm;181 182 ep_communicator();183 bool operator == (ep_communicator right);184 bool operator != (ep_communicator right);185 186 };187 188 189 struct BUFFER190 {191 void * void_buffer[12];192 };193 194 195 class MPI_Comm196 {197 public:198 199 bool is_ep;200 bool is_intercomm;201 202 BUFFER *my_buffer;203 OMPbarrier *ep_barrier;204 RANK_MAP *rank_map;205 void* mpi_comm;206 EP_Comm ep_comm_ptr;207 MPI_Comm *mem_bridge;208 void* mpi_bridge;209 210 MPI_Comm();211 MPI_Comm(void* comm);212 //~MPI_Comm(){delete mpi_comm;}213 214 215 bool operator == (MPI_Comm right);216 bool operator != (MPI_Comm right);217 bool is_null();218 219 };220 221 222 class MPI_Info223 {224 public:225 226 void* mpi_info;227 228 MPI_Info();229 MPI_Info(void* info);230 };231 232 233 class MPI_Request234 {235 public:236 237 void* mpi_request;238 239 int type; //! type of the non-blocking communication. 1: Isend; 2:Irecv; 3:Imrecv; 4:Issend240 void* buf;241 242 int ep_src;243 int ep_tag;244 void* ep_datatype;245 246 MPI_Comm comm; //! EP communicator related to the communication247 248 MPI_Request() {}249 MPI_Request(void* request);250 bool operator == (MPI_Request right);251 252 };253 254 */255 51 256 52 class MPI_Aint … … 264 60 MPI_Aint(int aint); 265 61 MPI_Aint operator=(int a); 266 //MPI_Aint(int a): mpi_aint(a) {}267 62 }; 268 63 … … 275 70 MPI_Fint() {} 276 71 MPI_Fint(void* fint); 277 //MPI_Fint(int f): mpi_fint(f) {}278 72 279 73 }; … … 288 82 static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_list; 289 83 84 static std::list< std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > > intercomm_list; 85 290 86 static std::map<std::pair<int, int>, MPI_Comm > fc_comm_map; 291 87 292 // static std::map<std::pair<int, int>, MPI_Comm > *fc_comm_map_ptr;293 // #pragma omp threadprivate(fc_comm_map_ptr)294 // // <MPI_Fint,thread_num> EP_Comm295 88 296 89 } -
XIOS/dev/branch_openmp/extern/ep_dev/main.cpp
r1506 r1511 680 680 681 681 682 MPI_Barrier(comm); 683 { 684 int rank, size; 685 MPI_Comm_rank(comm, &rank); 686 MPI_Comm_size(comm, &size); 687 688 //int tab_color[16]={2,2,2,3,0,1,1,3,2,1,3,0,0,2,0,0}; // OK 689 //int tab_key[16]={3,11,10,5,6,8,15,7,2,1,9,13,4,14,12,0}; // OK 690 691 692 int tab_color[16]={2,2,1,1,1,1,0,1,1,1,0,1,1,1,2,0}; 693 //int tab_key[16]={3,11,12,4,6,15,10,5,2,8,14,7,13,9,1,0}; 694 int tab_key[16]={3,11,7,7,6,15,10,5,2,8,14,7,13,9,1,0}; 695 696 int color = tab_color[rank]; 697 int key = tab_key[rank]; 698 699 MPI_Comm split_comm; 700 MPI_Comm_split(comm, color, key, &split_comm); 701 702 703 704 int split_rank; 705 MPI_Comm_rank(split_comm, &split_rank); 706 707 printf("rank = %d, color = %d, key = %d, split_rank = %d, local_rank=%d\n", rank, color, key, split_rank, split_comm->ep_comm_ptr->size_rank_info[1].first); 708 709 710 MPI_Barrier(comm); 711 if(rank == 0) printf("\tMPI_Comm_split OK\n"); 712 MPI_Barrier(comm); 713 /* 714 MPI_Comm inter_comm; 715 //MPI_Intercomm_create(sub_comm, 0, comm, (color+1)%2, 99, &inter_comm); 716 MPI_Intercomm_create(sub_comm, 0, comm, remote_leader, 99, &inter_comm); 717 718 MPI_Barrier(comm); 719 if(rank == 0) printf("\tMPI_Intercomm_create OK\n"); 720 MPI_Barrier(comm); 721 722 723 724 int high=color; 725 MPI_Comm intra_comm; 726 MPI_Intercomm_merge(inter_comm, high, &intra_comm); 727 728 int intra_rank, intra_size; 729 MPI_Comm_rank(intra_comm, &intra_rank); 730 MPI_Comm_size(intra_comm, &intra_size); 731 732 MPI_Barrier(comm); 733 if(rank == 0) printf("\tMPI_Intercomm_merge OK\n"); 734 MPI_Barrier(comm); 735 736 737 738 //check_test_gatherv(comm); 739 */ 740 MPI_Barrier(comm); 741 MPI_Comm_free(&split_comm); 742 743 744 //MPI_Barrier(comm); 745 //MPI_Comm_free(&inter_comm); 746 747 682 // TEST OF COMM_SPLIT 683 { 684 685 MPI_Barrier(comm); 686 int rank, size; 687 MPI_Comm_rank(comm, &rank); 688 MPI_Comm_size(comm, &size); 689 690 int color = rand()%3; 691 int key = rand()%5; 692 693 int color2 = rand()%3; 694 int key2 = rand()%5; 695 696 MPI_Comm split_comm; 697 MPI_Comm_split(comm, color, key, &split_comm); 698 699 700 MPI_Comm split_comm2; 701 MPI_Comm_split(comm, color2, key2, &split_comm2); 702 703 704 705 int split_rank, split_size; 706 MPI_Comm_rank(split_comm, &split_rank); 707 MPI_Comm_size(split_comm, &split_size); 708 709 #ifdef _Memory_check 710 printf("rank = %d, color = %d, key = %d, split_rank = %d, local_rank=%d\n", rank, color, key, split_rank, split_comm->ep_comm_ptr->size_rank_info[1].first); 711 #endif 712 713 MPI_Barrier(comm); 714 MPI_Barrier(comm); 715 MPI_Barrier(comm); 716 717 if(rank == 0) printf(" \t tMPI_Comm_split \t OK\n"); 718 719 MPI_Barrier(comm); 720 MPI_Barrier(comm); 721 722 int bcast_buf_size=100; 723 724 std::vector<int> bcast_buf(bcast_buf_size, 0); 725 726 if(split_rank==0) bcast_buf.assign(bcast_buf_size, (color+1)*split_size); 727 728 MPI_Bcast(bcast_buf.data(), bcast_buf_size, MPI_INT, 0, split_comm); 729 730 int bcast_test = 0; 731 for(int i=0; i<bcast_buf_size; i++) 732 { 733 if(bcast_buf[i] != (color+1)*split_size) 734 bcast_test = 1; 735 } 736 737 int bcast_result; 738 739 MPI_Reduce(&bcast_test, &bcast_result, 1, MPI_INT, MPI_SUM, 0, comm); 740 741 MPI_Barrier(split_comm); 742 MPI_Comm_free(&split_comm); 743 744 MPI_Barrier(split_comm2); 745 MPI_Comm_free(&split_comm2); 746 747 748 if(bcast_result == 0 && rank == 0) printf(" \t test MPI_Bcast for split comm\t OK\n"); 749 if(bcast_result != 0 && rank == 0) printf(" \t test MPI_Bcast for split comm\t FAILED %d\n", bcast_result); 750 751 } 752 753 MPI_Barrier(comm); 754 MPI_Barrier(comm); 755 MPI_Barrier(comm); 756 757 // TESE OF INTERCOMM_CREATE 758 { 759 MPI_Barrier(comm); 760 761 int rank, size; 762 MPI_Comm_rank(comm, &rank); 763 MPI_Comm_size(comm, &size); 764 765 int tab_color[16] = {2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1}; 766 int tab_key[16] = {2, 1, 4, 1, 0, 4, 3, 3, 4, 3, 4, 4, 4, 0, 0, 2}; 767 768 int color = tab_color[rank]; 769 int key = tab_key[rank]; 770 771 772 MPI_Comm split_comm; 773 MPI_Comm_split(comm, color, key, &split_comm); 774 775 776 int split_rank, split_size; 777 MPI_Comm_rank(split_comm, &split_rank); 778 MPI_Comm_size(split_comm, &split_size); 779 780 781 printf("rank = %d, color = %d, key = %d, split_rank = %d, local_rank=%d\n", rank, color, key, split_rank, split_comm->ep_comm_ptr->size_rank_info[1].first); 782 783 MPI_Barrier(comm); 784 MPI_Barrier(comm); 785 786 if(rank == 0) printf(" \t MPI_Comm_split \t OK\n"); 787 788 MPI_Barrier(comm); 789 MPI_Barrier(comm); 790 791 792 793 794 795 int local_leader = 0; 796 int remote_leader = color==2? 13: 4; 797 798 MPI_Comm peer_comm = comm; 799 800 MPI_Comm inter_comm; 801 MPI_Intercomm_create(split_comm, local_leader, peer_comm, remote_leader, 99, &inter_comm); 802 803 804 805 MPI_Barrier(comm); 806 MPI_Barrier(comm); 807 808 MPI_Barrier(split_comm); 809 MPI_Comm_free(&split_comm); 810 811 812 /* 813 MPI_Barrier(comm); 814 if(rank == 0) printf("\tMPI_Intercomm_create OK\n"); 815 MPI_Barrier(comm); 816 817 818 819 int high=color; 820 MPI_Comm intra_comm; 821 MPI_Intercomm_merge(inter_comm, high, &intra_comm); 822 823 int intra_rank, intra_size; 824 MPI_Comm_rank(intra_comm, &intra_rank); 825 MPI_Comm_size(intra_comm, &intra_size); 826 827 MPI_Barrier(comm); 828 if(rank == 0) printf("\tMPI_Intercomm_merge OK\n"); 829 MPI_Barrier(comm); 830 831 832 833 //check_test_gatherv(comm); 834 835 MPI_Barrier(comm); 836 MPI_Comm_free(&inter_comm); 837 */ 838 } 839 748 840 MPI_Barrier(comm); 749 841 MPI_Comm_free(&comm); 750 }751 842 } 752 843 -
XIOS/dev/branch_openmp/extern/ep_dev/makefile
r1503 r1511 1 1 appname := EP_test 2 2 3 CXX := mpiicc -D_intelmpi -D_noMemory_check -D_nocheck_sum - openmp3 CXX := mpiicc -D_intelmpi -D_noMemory_check -D_nocheck_sum -qopenmp 4 4 CXXFLAGS := -std=c++11 -g 5 #CXXFLAGS := -std=c++11 -g6 5 7 6 srcfiles := $(shell find . -name "*.cpp") … … 16 15 depend: .depend 17 16 18 .depend: $(srcfiles)17 depend: $(srcfiles) 19 18 rm -f ./.depend 20 19 $(CXX) $(CXXFLAGS) -MM $^>>./.depend; … … 26 25 rm -f *~ .depend 27 26 28 include .depend29 27
Note: See TracChangeset
for help on using the changeset viewer.