- Timestamp:
- 12/04/17 17:12:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp
r1287 r1354 2 2 #include <mpi.h> 3 3 #include "ep_declaration.hpp" 4 #include "ep_mpi.hpp" 4 5 5 6 using namespace std; … … 8 9 { 9 10 10 #ifdef _openmpi 11 11 // #ifdef _openmpi 12 13 // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm) 14 // { 15 16 // int ep_rank, ep_rank_loc, mpi_rank; 17 // int ep_size, num_ep, mpi_size; 18 19 // ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 20 // ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 21 // mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 22 // ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 23 // num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 24 // mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 25 26 27 // std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 28 // //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 29 30 // int rank_in_world; 31 // int rank_in_local_parent; 32 33 // int local_ep_size = ep_size; 34 // int remote_ep_size; 35 36 // ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr); 37 // ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 38 39 // ::MPI_Comm_rank(peer_comm, &rank_in_world); 40 41 // ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent); 42 43 // bool is_proc_master = false; 44 // bool is_local_leader = false; 45 // bool is_final_master = false; 46 47 48 // if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 49 // if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 50 51 52 // int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm 53 54 // int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader 55 56 57 // std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm 58 59 // std::vector<int> new_rank_info[4]; 60 // std::vector<int> new_ep_info[2]; 61 62 // std::vector<int> offset; 63 64 // if(is_proc_master) 65 // { 66 67 // size_info[0] = mpi_size; 68 69 // rank_info[0].resize(size_info[0]); 70 // rank_info[1].resize(size_info[0]); 71 72 73 74 // ep_info[0].resize(size_info[0]); 75 76 // vector<int> send_buf(6); 77 // vector<int> recv_buf(3*size_info[0]); 78 79 // send_buf[0] = rank_in_world; 80 // send_buf[1] = rank_in_local_parent; 81 // send_buf[2] = num_ep; 82 83 // ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm); 84 85 // for(int i=0; i<size_info[0]; i++) 86 // { 87 // rank_info[0][i] = recv_buf[3*i]; 88 // rank_info[1][i] = recv_buf[3*i+1]; 89 // ep_info[0][i] = recv_buf[3*i+2]; 90 // } 91 92 // if(is_local_leader) 93 // { 94 // leader_info[0] = rank_in_world; 95 // leader_info[1] = mpi_remote_leader; 96 97 // ::MPI_Status mpi_status; 98 99 // send_buf[0] = size_info[0]; 100 // send_buf[1] = local_ep_size; 101 102 // ::MPI_Send(send_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 103 104 // ::MPI_Recv(recv_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 105 106 // recv_buf[2] = rank_in_world; 107 // recv_buf[3] = mpi_remote_leader; 108 109 // } 110 111 // ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 112 113 // size_info[1] = recv_buf[0]; 114 // remote_ep_size = recv_buf[1]; 115 // leader_info[0] = recv_buf[2]; 116 // leader_info[1] = recv_buf[3]; 117 118 // rank_info[2].resize(size_info[1]); 119 // rank_info[3].resize(size_info[1]); 120 121 // ep_info[1].resize(size_info[1]); 122 123 // send_buf.resize(3*size_info[0]); 124 // recv_buf.resize(3*size_info[1]); 125 126 // if(is_local_leader) 127 // { 128 // ::MPI_Status mpi_status; 129 130 131 // std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() ); 132 // std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] ); 133 // std::copy ( ep_info[0].data(), ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[0] ); 134 135 // ::MPI_Send(send_buf.data(), 3*size_info[0], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 136 137 // ::MPI_Recv(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 138 139 // } 140 141 // ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 142 143 // std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 144 // std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin() ); 145 // std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() ); 146 147 // offset.resize(size_info[0]); 148 149 // if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader 150 // { 151 152 // bool found = false; 153 // int ep_tmp; 154 // int ep_local; 155 // int ep_remote; 156 // for(int i=0; i<size_info[0]; i++) 157 // { 158 // int target = rank_info[0][i]; 159 // found = false; 160 // for(int j=0; j<size_info[1]; j++) 161 // { 162 // if(target == rank_info[2][j]) 163 // { 164 // found = true; 165 // ep_tmp = ep_info[1][j]; 166 // ep_local = ep_info[0][j]; 167 // ep_remote = ep_info[1][j]; 168 // break; 169 // } 170 // } 171 // if(found) 172 // { 173 174 // if(target == leader_info[0]) // the leader is doubled in remote 175 // { 176 // new_rank_info[0].push_back(target); 177 // new_rank_info[1].push_back(rank_info[1][i]); 178 179 // new_ep_info[0].push_back(ep_local + ep_remote); 180 // offset[i] = 0; 181 // } 182 // else 183 // { 184 // offset[i] = ep_local; 185 // } 186 // } 187 // else 188 // { 189 // new_rank_info[0].push_back(target); 190 // new_rank_info[1].push_back(rank_info[1][i]); 191 192 // new_ep_info[0].push_back(ep_info[0][i]); 193 194 // offset[i] = 0; 195 // } 196 197 // } 198 // } 199 200 // else // erase rank doubled with remote leader 201 // { 202 203 // bool found = false; 204 // int ep_tmp; 205 // int ep_local; 206 // int ep_remote; 207 // for(int i=0; i<size_info[0]; i++) 208 // { 209 // int target = rank_info[0][i]; 210 // found = false; 211 // for(int j=0; j<size_info[1]; j++) 212 // { 213 214 // if(target == rank_info[2][j]) 215 // { 216 // found = true; 217 // ep_tmp = ep_info[1][j]; 218 // ep_local = ep_info[0][j]; 219 // ep_remote = ep_info[1][j]; 220 // break; 221 // } 222 // } 223 // if(found) 224 // { 225 // if(target != leader_info[1]) 226 // { 227 // new_rank_info[0].push_back(target); 228 // new_rank_info[1].push_back(rank_info[1][i]); 229 230 // new_ep_info[0].push_back(ep_local + ep_remote); 231 // offset[i] = 0; 232 // } 233 // else // found remote leader 234 // { 235 // offset[i] = ep_remote; 236 // } 237 // } 238 // else 239 // { 240 // new_rank_info[0].push_back(target); 241 // new_rank_info[1].push_back(rank_info[1][i]); 242 243 // new_ep_info[0].push_back(ep_info[0][i]); 244 // offset[i] = 0; 245 // } 246 // } 247 // } 248 249 // if(offset[mpi_rank] == 0) 250 // { 251 // is_final_master = true; 252 // } 253 254 255 // // size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote 256 257 // if(is_local_leader) 258 // { 259 // size_info[2] = new_ep_info[0].size(); 260 // ::MPI_Status mpi_status; 261 262 // ::MPI_Send(&size_info[2], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 263 264 // ::MPI_Recv(&size_info[3], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 265 // } 266 267 // ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 268 269 // new_rank_info[2].resize(size_info[3]); 270 // new_rank_info[3].resize(size_info[3]); 271 // new_ep_info[1].resize(size_info[3]); 272 273 // send_buf.resize(size_info[2]); 274 // recv_buf.resize(size_info[3]); 275 276 // if(is_local_leader) 277 // { 278 // ::MPI_Status mpi_status; 279 280 // std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() ); 281 // std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] ); 282 // std::copy ( new_ep_info[0].data(), new_ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[2] ); 283 284 // ::MPI_Send(send_buf.data(), 3*size_info[2], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 285 // ::MPI_Recv(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 286 287 // } 288 289 // ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 290 291 // std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 292 // std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin() ); 293 // std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() ); 294 295 // } 296 297 298 299 // if(is_proc_master) 300 // { 301 // // leader_info[4]: 2-> rank of local leader in new_group generated comm; 302 // // 3-> rank of remote leader in new_group generated comm; 303 // ::MPI_Group local_group; 304 // ::MPI_Group new_group; 305 // ::MPI_Comm *new_comm = new ::MPI_Comm; 306 // ::MPI_Comm *intercomm = new ::MPI_Comm; 307 308 // ::MPI_Comm_group(local_mpi_comm, &local_group); 309 310 // ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 311 312 // ::MPI_Comm_create(local_mpi_comm, new_group, new_comm); 313 314 315 316 // if(is_local_leader) 317 // { 318 // ::MPI_Comm_rank(*new_comm, &leader_info[2]); 319 // } 320 321 // ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 322 323 // if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 324 // { 325 // ::MPI_Barrier(*new_comm); 326 327 // ::MPI_Intercomm_create(*new_comm, leader_info[2], peer_comm, leader_info[1], tag, intercomm); 328 329 // int id; 330 // ::MPI_Comm_rank(*new_comm, &id); 331 // int my_num_ep = new_ep_info[0][id]; 332 333 // MPI_Comm *ep_intercomm; 334 // MPI_Info info; 335 // MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 336 337 338 339 // for(int i= 0; i<my_num_ep; i++) 340 // { 341 // ep_intercomm[i].is_intercomm = true; 342 343 // ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 344 // ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 345 // ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 346 // } 347 348 // #pragma omp critical (write_to_tag_list) 349 // tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 350 // } 351 352 353 // } 354 355 356 // MPI_Barrier_local(local_comm); 357 358 // vector<int> bcast_buf(8); 359 // if(is_local_leader) 360 // { 361 // std::copy(size_info, size_info+4, bcast_buf.begin()); 362 // std::copy(leader_info, leader_info+4, bcast_buf.begin()+4); 363 // } 364 365 // MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm); 366 367 // if(!is_local_leader) 368 // { 369 // std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info); 370 // std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 371 // } 372 373 // if(!is_local_leader) 374 // { 375 // new_rank_info[1].resize(size_info[2]); 376 // ep_info[1].resize(size_info[1]); 377 // offset.resize(size_info[0]); 378 // } 379 380 // bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1); 381 382 // if(is_local_leader) 383 // { 384 // bcast_buf[0] = remote_ep_size; 385 // std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1); 386 // std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1); 387 // std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1); 388 // } 389 390 // MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm); 391 392 // if(!is_local_leader) 393 // { 394 // remote_ep_size = bcast_buf[0]; 395 // std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin()); 396 // std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin()); 397 // std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin()); 398 // } 399 400 401 // int my_position = offset[rank_in_local_parent]+ep_rank_loc; 402 403 404 // MPI_Barrier_local(local_comm); 405 // #pragma omp flush 406 407 408 // #pragma omp critical (read_from_tag_list) 409 // { 410 // bool found = false; 411 // while(!found) 412 // { 413 // for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 414 // { 415 // if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 416 // { 417 // *newintercomm = iter->second[my_position]; 418 419 // found = true; 420 // //tag_list.erase(iter); 421 // break; 422 // } 423 // } 424 // } 425 // } 426 427 // MPI_Barrier(local_comm); 428 429 // if(is_local_leader) 430 // { 431 // int local_flag = true; 432 // int remote_flag = false; 433 // ::MPI_Status mpi_status; 434 435 // ::MPI_Send(&local_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 436 437 // ::MPI_Recv(&remote_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 438 // } 439 440 // MPI_Barrier(local_comm); 441 442 // if(is_proc_master) 443 // { 444 // for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 445 // { 446 // if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 447 // { 448 // tag_list.erase(iter); 449 // break; 450 // } 451 // } 452 // } 453 454 455 456 // int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 457 // int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 458 459 // intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 460 // intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 461 // intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 462 // intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 463 // intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 464 // intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 465 466 // MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 467 468 // int my_rank_map_elem[2]; 469 470 471 // my_rank_map_elem[0] = intercomm_ep_rank; 472 473 // my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 474 475 // vector<pair<int, int> > local_rank_map_array; 476 // vector<pair<int, int> > remote_rank_map_array; 477 478 479 // (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 480 // (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 481 482 // MPI_Allgather2(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 483 484 // (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 485 // (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 486 487 // int local_intercomm_size = intercomm_ep_size; 488 // int remote_intercomm_size; 489 490 491 492 493 // if(is_local_leader) 494 // { 495 // ::MPI_Status status; 496 497 // ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 498 499 // ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 500 501 // ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 502 503 // ::MPI_Recv(&remote_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 504 // } 505 506 // MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 507 // MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm); 508 509 510 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 511 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 512 513 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 514 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 515 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 516 517 518 // if(is_local_leader) 519 // { 520 // ::MPI_Status status; 521 522 // ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 523 524 // ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 525 // } 526 527 // MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), 0, *newintercomm); 528 529 // (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 530 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label; 531 532 533 // return MPI_SUCCESS; 534 535 // } 536 537 538 539 // #elif _intelmpi 12 540 int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm) 13 541 { 14 15 542 int ep_rank, ep_rank_loc, mpi_rank; 16 543 int ep_size, num_ep, mpi_size; … … 23 550 mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 24 551 25 26 552 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 27 553 //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm … … 33 559 int remote_ep_size; 34 560 35 ::MPI_Comm peer_comm = static_cast< ::MPI_Comm>(peer_comm_ptr);36 ::MPI_Comm local_mpi_comm = static_cast< ::MPI_Comm>(local_comm.mpi_comm);561 ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr); 562 ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 37 563 38 564 ::MPI_Comm_rank(peer_comm, &rank_in_world); 39 565 40 ::MPI_Comm_rank( static_cast< ::MPI_Comm>(local_comm.mpi_comm), &rank_in_local_parent);566 ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent); 41 567 42 568 bool is_proc_master = false; … … 69 595 rank_info[1].resize(size_info[0]); 70 596 71 72 73 597 ep_info[0].resize(size_info[0]); 74 598 … … 80 604 send_buf[2] = num_ep; 81 605 82 ::MPI_Allgather(send_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), recv_buf.data(), 3, static_cast< ::MPI_Datatype>(MPI_INT), local_mpi_comm);606 ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm); 83 607 84 608 for(int i=0; i<size_info[0]; i++) … … 89 613 } 90 614 615 91 616 if(is_local_leader) 92 617 { … … 99 624 send_buf[1] = local_ep_size; 100 625 101 ::MPI_Send(send_buf.data(), 2, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);102 103 ::MPI_Recv(recv_buf.data(), 2, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);626 ::MPI_Send(send_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 627 628 ::MPI_Recv(recv_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 104 629 105 630 recv_buf[2] = rank_in_world; … … 108 633 } 109 634 110 ::MPI_Bcast(recv_buf.data(), 4, static_cast< ::MPI_Datatype>(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);635 ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 111 636 112 637 size_info[1] = recv_buf[0]; … … 132 657 std::copy ( ep_info[0].data(), ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[0] ); 133 658 134 ::MPI_Send(send_buf.data(), 3*size_info[0], static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);135 136 ::MPI_Recv(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);137 138 } 139 140 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype>(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);659 ::MPI_Send(send_buf.data(), 3*size_info[0], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 660 661 ::MPI_Recv(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 662 663 } 664 665 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 141 666 142 667 std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); … … 259 784 ::MPI_Status mpi_status; 260 785 261 ::MPI_Send(&size_info[2], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);262 263 ::MPI_Recv(&size_info[3], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);264 } 265 266 ::MPI_Bcast(&size_info[2], 2, static_cast< ::MPI_Datatype>(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);786 ::MPI_Send(&size_info[2], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 787 788 ::MPI_Recv(&size_info[3], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 789 } 790 791 ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 267 792 268 793 new_rank_info[2].resize(size_info[3]); … … 281 806 std::copy ( new_ep_info[0].data(), new_ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[2] ); 282 807 283 ::MPI_Send(send_buf.data(), 3*size_info[2], static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);284 ::MPI_Recv(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 285 286 } 287 288 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype>(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);808 ::MPI_Send(send_buf.data(), 3*size_info[2], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 809 810 ::MPI_Recv(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 811 } 812 813 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 289 814 290 815 std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); … … 302 827 ::MPI_Group local_group; 303 828 ::MPI_Group new_group; 304 ::MPI_Comm new_comm;305 ::MPI_Comm intercomm;829 ::MPI_Comm *new_comm = new ::MPI_Comm; 830 ::MPI_Comm *intercomm = new ::MPI_Comm; 306 831 307 832 ::MPI_Comm_group(local_mpi_comm, &local_group); … … 309 834 ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 310 835 311 ::MPI_Comm_create(local_mpi_comm, new_group, &new_comm);836 ::MPI_Comm_create(local_mpi_comm, new_group, new_comm); 312 837 313 838 … … 315 840 if(is_local_leader) 316 841 { 317 ::MPI_Comm_rank( new_comm, &leader_info[2]);318 } 319 320 ::MPI_Bcast(&leader_info[2], 1, static_cast< ::MPI_Datatype>(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);321 322 if(new_comm != static_cast< ::MPI_Comm >(MPI_COMM_NULL.mpi_comm))323 { 324 ::MPI_Barrier( new_comm);325 326 ::MPI_Intercomm_create( new_comm, leader_info[2], peer_comm, leader_info[1], tag, &intercomm);842 ::MPI_Comm_rank(*new_comm, &leader_info[2]); 843 } 844 845 ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 846 847 if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) 848 { 849 ::MPI_Barrier(*new_comm); 850 851 ::MPI_Intercomm_create(*new_comm, leader_info[2], peer_comm, leader_info[1], tag, intercomm); 327 852 328 853 int id; 329 MPI_Comm_rank(new_comm, &id);854 ::MPI_Comm_rank(*new_comm, &id); 330 855 int my_num_ep = new_ep_info[0][id]; 331 856 … … 333 858 MPI_Info info; 334 859 MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 335 336 337 860 338 861 for(int i= 0; i<my_num_ep; i++) … … 345 868 } 346 869 870 347 871 #pragma omp critical (write_to_tag_list) 348 872 tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 349 }350 351 352 } 353 354 355 MPI_Barrier_local(local_comm); 873 874 875 } 876 877 878 } 879 356 880 357 881 vector<int> bcast_buf(8); … … 362 886 } 363 887 364 MPI_Bcast(bcast_buf.data(), 8, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 888 889 890 MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm); 891 365 892 366 893 if(!is_local_leader) … … 369 896 std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 370 897 } 898 899 371 900 372 901 if(!is_local_leader) … … 387 916 } 388 917 389 MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 918 MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm); 919 390 920 391 921 if(!is_local_leader) … … 399 929 400 930 int my_position = offset[rank_in_local_parent]+ep_rank_loc; 401 402 403 MPI_Barrier_local(local_comm);404 #pragma omp flush405 931 406 932 … … 417 943 418 944 found = true; 419 //tag_list.erase(iter);420 945 break; 421 946 } … … 432 957 ::MPI_Status mpi_status; 433 958 434 ::MPI_Send(&local_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);435 436 ::MPI_Recv(&remote_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);959 ::MPI_Send(&local_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 960 961 ::MPI_Recv(&remote_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 437 962 } 438 963 … … 450 975 } 451 976 } 452 453 454 977 455 978 int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; … … 463 986 intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 464 987 465 MPI_Bcast(&remote_ep_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 466 467 int my_rank_map_elem[2]; 468 469 470 my_rank_map_elem[0] = intercomm_ep_rank; 471 472 my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 473 474 vector<pair<int, int> > local_rank_map_array; 475 vector<pair<int, int> > remote_rank_map_array; 476 477 478 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 479 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 480 481 MPI_Allgather2(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 482 483 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 484 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 485 486 int local_intercomm_size = intercomm_ep_size; 487 int remote_intercomm_size; 488 489 490 491 492 if(is_local_leader) 493 { 494 ::MPI_Status status; 495 496 ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 497 498 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 499 500 ::MPI_Send(&local_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 501 502 ::MPI_Recv(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 503 } 504 505 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 506 MPI_Bcast(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm); 507 508 509 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 510 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 511 512 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 513 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 514 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 515 516 517 if(is_local_leader) 518 { 519 ::MPI_Status status; 520 521 ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 522 523 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 524 } 525 526 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm); 527 528 (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 529 (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label; 530 531 532 return MPI_SUCCESS; 533 534 } 535 536 537 538 #elif _intelmpi 539 int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, int peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm) 540 { 541 int ep_rank, ep_rank_loc, mpi_rank; 542 int ep_size, num_ep, mpi_size; 543 544 ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 545 ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 546 mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 547 ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 548 num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 549 mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 550 551 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 552 //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 553 554 int rank_in_world; 555 int rank_in_local_parent; 556 557 int local_ep_size = ep_size; 558 int remote_ep_size; 559 560 ::MPI_Comm peer_comm = static_cast< ::MPI_Comm>(peer_comm_ptr); 561 ::MPI_Comm local_mpi_comm = static_cast< ::MPI_Comm>(local_comm.mpi_comm); 562 563 ::MPI_Comm_rank(peer_comm, &rank_in_world); 564 565 ::MPI_Comm_rank(static_cast< ::MPI_Comm>(local_comm.mpi_comm), &rank_in_local_parent); 566 567 bool is_proc_master = false; 568 bool is_local_leader = false; 569 bool is_final_master = false; 570 571 572 if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 573 if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 574 575 576 int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm 577 578 int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader 579 580 581 std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm 582 583 std::vector<int> new_rank_info[4]; 584 std::vector<int> new_ep_info[2]; 585 586 std::vector<int> offset; 587 588 if(is_proc_master) 589 { 590 591 size_info[0] = mpi_size; 592 593 rank_info[0].resize(size_info[0]); 594 rank_info[1].resize(size_info[0]); 595 596 ep_info[0].resize(size_info[0]); 597 598 vector<int> send_buf(6); 599 vector<int> recv_buf(3*size_info[0]); 600 601 send_buf[0] = rank_in_world; 602 send_buf[1] = rank_in_local_parent; 603 send_buf[2] = num_ep; 604 605 ::MPI_Allgather(send_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), recv_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), local_mpi_comm); 606 607 for(int i=0; i<size_info[0]; i++) 608 { 609 rank_info[0][i] = recv_buf[3*i]; 610 rank_info[1][i] = recv_buf[3*i+1]; 611 ep_info[0][i] = recv_buf[3*i+2]; 612 } 613 614 615 if(is_local_leader) 616 { 617 leader_info[0] = rank_in_world; 618 leader_info[1] = mpi_remote_leader; 619 620 ::MPI_Status mpi_status; 621 622 send_buf[0] = size_info[0]; 623 send_buf[1] = local_ep_size; 624 625 ::MPI_Send(send_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 626 627 ::MPI_Recv(recv_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 628 629 recv_buf[2] = rank_in_world; 630 recv_buf[3] = mpi_remote_leader; 631 632 } 633 634 ::MPI_Bcast(recv_buf.data(), 4, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 635 636 size_info[1] = recv_buf[0]; 637 remote_ep_size = recv_buf[1]; 638 leader_info[0] = recv_buf[2]; 639 leader_info[1] = recv_buf[3]; 640 641 rank_info[2].resize(size_info[1]); 642 rank_info[3].resize(size_info[1]); 643 644 ep_info[1].resize(size_info[1]); 645 646 send_buf.resize(3*size_info[0]); 647 recv_buf.resize(3*size_info[1]); 648 649 if(is_local_leader) 650 { 651 ::MPI_Status mpi_status; 652 653 654 std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() ); 655 std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] ); 656 std::copy ( ep_info[0].data(), ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[0] ); 657 658 ::MPI_Send(send_buf.data(), 3*size_info[0], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 659 660 ::MPI_Recv(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 661 662 } 663 664 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 665 666 std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 667 std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin() ); 668 std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() ); 669 670 offset.resize(size_info[0]); 671 672 if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader 673 { 674 675 bool found = false; 676 int ep_tmp; 677 int ep_local; 678 int ep_remote; 679 for(int i=0; i<size_info[0]; i++) 680 { 681 int target = rank_info[0][i]; 682 found = false; 683 for(int j=0; j<size_info[1]; j++) 684 { 685 if(target == rank_info[2][j]) 686 { 687 found = true; 688 ep_tmp = ep_info[1][j]; 689 ep_local = ep_info[0][j]; 690 ep_remote = ep_info[1][j]; 691 break; 692 } 693 } 694 if(found) 695 { 696 697 if(target == leader_info[0]) // the leader is doubled in remote 698 { 699 new_rank_info[0].push_back(target); 700 new_rank_info[1].push_back(rank_info[1][i]); 701 702 new_ep_info[0].push_back(ep_local + ep_remote); 703 offset[i] = 0; 704 } 705 else 706 { 707 offset[i] = ep_local; 708 } 709 } 710 else 711 { 712 new_rank_info[0].push_back(target); 713 new_rank_info[1].push_back(rank_info[1][i]); 714 715 new_ep_info[0].push_back(ep_info[0][i]); 716 717 offset[i] = 0; 718 } 719 720 } 721 } 722 723 else // erase rank doubled with remote leader 724 { 725 726 bool found = false; 727 int ep_tmp; 728 int ep_local; 729 int ep_remote; 730 for(int i=0; i<size_info[0]; i++) 731 { 732 int target = rank_info[0][i]; 733 found = false; 734 for(int j=0; j<size_info[1]; j++) 735 { 736 737 if(target == rank_info[2][j]) 738 { 739 found = true; 740 ep_tmp = ep_info[1][j]; 741 ep_local = ep_info[0][j]; 742 ep_remote = ep_info[1][j]; 743 break; 744 } 745 } 746 if(found) 747 { 748 if(target != leader_info[1]) 749 { 750 new_rank_info[0].push_back(target); 751 new_rank_info[1].push_back(rank_info[1][i]); 752 753 new_ep_info[0].push_back(ep_local + ep_remote); 754 offset[i] = 0; 755 } 756 else // found remote leader 757 { 758 offset[i] = ep_remote; 759 } 760 } 761 else 762 { 763 new_rank_info[0].push_back(target); 764 new_rank_info[1].push_back(rank_info[1][i]); 765 766 new_ep_info[0].push_back(ep_info[0][i]); 767 offset[i] = 0; 768 } 769 } 770 } 771 772 if(offset[mpi_rank] == 0) 773 { 774 is_final_master = true; 775 } 776 777 778 // size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote 779 780 if(is_local_leader) 781 { 782 size_info[2] = new_ep_info[0].size(); 783 ::MPI_Status mpi_status; 784 785 ::MPI_Send(&size_info[2], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 786 787 ::MPI_Recv(&size_info[3], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 788 } 789 790 ::MPI_Bcast(&size_info[2], 2, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 791 792 new_rank_info[2].resize(size_info[3]); 793 new_rank_info[3].resize(size_info[3]); 794 new_ep_info[1].resize(size_info[3]); 795 796 send_buf.resize(size_info[2]); 797 recv_buf.resize(size_info[3]); 798 799 if(is_local_leader) 800 { 801 ::MPI_Status mpi_status; 802 803 std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() ); 804 std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] ); 805 std::copy ( new_ep_info[0].data(), new_ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[2] ); 806 807 ::MPI_Send(send_buf.data(), 3*size_info[2], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm); 808 809 ::MPI_Recv(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 810 } 811 812 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 813 814 std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 815 std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin() ); 816 std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() ); 817 818 } 819 820 821 822 if(is_proc_master) 823 { 824 // leader_info[4]: 2-> rank of local leader in new_group generated comm; 825 // 3-> rank of remote leader in new_group generated comm; 826 ::MPI_Group local_group; 827 ::MPI_Group new_group; 828 ::MPI_Comm new_comm; 829 ::MPI_Comm intercomm; 830 831 ::MPI_Comm_group(local_mpi_comm, &local_group); 832 833 ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 834 835 ::MPI_Comm_create(local_mpi_comm, new_group, &new_comm); 836 837 838 839 if(is_local_leader) 840 { 841 ::MPI_Comm_rank(new_comm, &leader_info[2]); 842 } 843 844 ::MPI_Bcast(&leader_info[2], 1, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 845 846 if(new_comm != static_cast< ::MPI_Comm >(MPI_COMM_NULL.mpi_comm)) 847 { 848 ::MPI_Barrier(new_comm); 849 850 ::MPI_Intercomm_create(new_comm, leader_info[2], peer_comm, leader_info[1], tag, &intercomm); 851 852 int id; 853 ::MPI_Comm_rank(new_comm, &id); 854 int my_num_ep = new_ep_info[0][id]; 855 856 MPI_Comm *ep_intercomm; 857 MPI_Info info; 858 MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 859 860 for(int i= 0; i<my_num_ep; i++) 861 { 862 ep_intercomm[i].is_intercomm = true; 863 864 ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 865 ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 866 ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 867 } 868 869 870 #pragma omp critical (write_to_tag_list) 871 tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 872 873 874 } 875 876 877 } 878 879 880 vector<int> bcast_buf(8); 881 if(is_local_leader) 882 { 883 std::copy(size_info, size_info+4, bcast_buf.begin()); 884 std::copy(leader_info, leader_info+4, bcast_buf.begin()+4); 885 } 886 887 888 889 MPI_Bcast(bcast_buf.data(), 8, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 890 891 892 if(!is_local_leader) 893 { 894 std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info); 895 std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 896 } 897 898 899 900 if(!is_local_leader) 901 { 902 new_rank_info[1].resize(size_info[2]); 903 ep_info[1].resize(size_info[1]); 904 offset.resize(size_info[0]); 905 } 906 907 bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1); 908 909 if(is_local_leader) 910 { 911 bcast_buf[0] = remote_ep_size; 912 std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1); 913 std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1); 914 std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1); 915 } 916 917 MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 918 919 920 if(!is_local_leader) 921 { 922 remote_ep_size = bcast_buf[0]; 923 std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin()); 924 std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin()); 925 std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin()); 926 } 927 928 929 int my_position = offset[rank_in_local_parent]+ep_rank_loc; 930 931 932 #pragma omp critical (read_from_tag_list) 933 { 934 bool found = false; 935 while(!found) 936 { 937 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 938 { 939 if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 940 { 941 *newintercomm = iter->second[my_position]; 942 943 found = true; 944 break; 945 } 946 } 947 } 948 } 949 950 MPI_Barrier(local_comm); 951 952 if(is_local_leader) 953 { 954 int local_flag = true; 955 int remote_flag = false; 956 ::MPI_Status mpi_status; 957 958 ::MPI_Send(&local_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm); 959 960 ::MPI_Recv(&remote_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 961 } 962 963 MPI_Barrier(local_comm); 964 965 if(is_proc_master) 966 { 967 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 968 { 969 if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 970 { 971 tag_list.erase(iter); 972 break; 973 } 974 } 975 } 976 977 int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 978 int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 979 980 intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 981 intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 982 intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 983 intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 984 intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 985 intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 986 987 988 MPI_Bcast(&remote_ep_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm); 988 989 MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 989 990 990 991 int my_rank_map_elem[2]; … … 1015 1016 ::MPI_Status status; 1016 1017 1017 ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);1018 1019 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);1020 1021 ::MPI_Send(&local_intercomm_size, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);1022 1023 ::MPI_Recv(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);1024 } 1025 1026 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);1027 MPI_Bcast(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm);1018 ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 1019 1020 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 1021 1022 ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 1023 1024 ::MPI_Recv(&remote_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 1025 } 1026 1027 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 1028 MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm); 1028 1029 1029 1030 … … 1040 1041 ::MPI_Status status; 1041 1042 1042 ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);1043 1044 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);1045 } 1046 1047 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm);1043 ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 1044 1045 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 1046 } 1047 1048 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm); 1048 1049 1049 1050 (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); … … 1054 1055 } 1055 1056 1056 #endif1057 // #endif 1057 1058 1058 1059 }
Note: See TracChangeset
for help on using the changeset viewer.