Ignore:
Timestamp:
05/28/18 09:54:32 (6 years ago)
Author:
yushan
Message:

save dev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_world.cpp

    r1499 r1500  
    99{ 
    1010 
    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 
     11 
    54012  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) 
    54113  { 
     
    54315    int ep_size, num_ep, mpi_size; 
    54416 
    545     ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 
    546     ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 
    547     mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 
    548     ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 
    549     num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 
    550     mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 
     17    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first; 
     18    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 
     19    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first; 
     20    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second; 
     21    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 
     22    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 
    55123 
    55224    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm 
     
    56032 
    56133    ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr); 
    562     ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 
     34    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm->mpi_comm); 
    56335 
    56436    ::MPI_Comm_rank(peer_comm, &rank_in_world); 
     
    57244 
    57345    if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 
    574     if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 
     46    if(ep_rank_loc == 0 && mpi_rank != local_comm->rank_map->at(local_leader).second) is_proc_master = true; 
    57547 
    57648 
     
    633105      } 
    634106 
    635       ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 
     107      ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm->rank_map->at(local_leader).second, local_mpi_comm); 
    636108 
    637109      size_info[1] = recv_buf[0]; 
     
    663135      } 
    664136 
    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); 
     137      ::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); 
    666138 
    667139      std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 
     
    789261      } 
    790262 
    791       ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 
     263      ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm->rank_map->at(local_leader).second, local_mpi_comm); 
    792264 
    793265      new_rank_info[2].resize(size_info[3]); 
     
    811283      } 
    812284 
    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); 
     285      ::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); 
    814286 
    815287      std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 
     
    843315      } 
    844316 
    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)) 
     317      ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm->rank_map->at(local_leader).second, local_mpi_comm); 
     318 
     319      if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) 
    848320      { 
    849321        ::MPI_Barrier(*new_comm); 
     
    861333        for(int i= 0; i<my_num_ep; i++) 
    862334        { 
    863           ep_intercomm[i].is_intercomm = true; 
    864  
    865           ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
    866           ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 
    867           ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 
     335          ep_intercomm[i]->is_intercomm = true; 
     336 
     337          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
     338          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 
     339          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_info[0]; 
    868340        } 
    869341 
     
    979451    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 
    980452 
    981     intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 
    982     intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 
    983     intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 
    984     intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 
    985     intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 
    986     intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 
     453    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first; 
     454    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 
     455    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first; 
     456    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second; 
     457    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second; 
     458    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second; 
    987459 
    988460 
     
    994466    my_rank_map_elem[0] = intercomm_ep_rank; 
    995467 
    996     my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 
     468    my_rank_map_elem[1] = (*newintercomm)->ep_comm_ptr->comm_label; 
    997469 
    998470    vector<pair<int, int> > local_rank_map_array; 
     
    1000472 
    1001473 
    1002     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 
    1003     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 
    1004  
    1005     MPI_Allgather(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 
     474    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 
     475    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 
     476 
     477    MPI_Allgather(my_rank_map_elem, 2, MPI_INT, (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 
    1006478    
    1007     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 
    1008     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 
     479    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 
     480    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 
    1009481 
    1010482    int local_intercomm_size = intercomm_ep_size; 
     
    1016488      ::MPI_Status status; 
    1017489 
    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); 
     490      ::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); 
     491 
     492      ::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); 
    1021493 
    1022494      ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 
     
    1025497    } 
    1026498 
    1027     MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 
     499    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 
    1028500    MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm); 
    1029501 
    1030502 
    1031     (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 
    1032     (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 
    1033  
    1034     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 
    1035     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 
    1036     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 
     503    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 
     504    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 
     505 
     506    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0]; 
     507    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1]; 
     508    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2]; 
    1037509 
    1038510 
     
    1041513      ::MPI_Status status; 
    1042514 
    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); 
    1049  
    1050     (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 
    1051     (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label; 
     515      ::MPI_Send((*newintercomm)->rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 
     516 
     517      ::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); 
     518    } 
     519 
     520    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm); 
     521 
     522    (*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]); 
     523    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = local_comm->ep_comm_ptr->comm_label; 
    1052524 
    1053525    return MPI_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.