Ignore:
Timestamp:
06/04/18 19:25:08 (6 years ago)
Author:
yushan
Message:

save dev. TO DO : test with xios

Location:
XIOS/dev/branch_openmp/extern
Files:
45 edited

Legend:

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

    r1517 r1520  
    2727  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) 
    2828  { 
     29    if(comm->is_intercomm) 
     30    { 
     31      for(std::map<int, std::pair< int, std::pair<int, int> > >::iterator it = comm->ep_comm_ptr->intercomm->intercomm_rank_map->begin(); it != comm->ep_comm_ptr->intercomm->intercomm_rank_map->end(); it++) 
     32      { 
     33        if(   ( it->second.first  == ep_rank_loc ) 
     34           && ( it->second.second.first == mpi_rank ) ) 
     35        { 
     36          return it->first; 
     37        } 
     38      } 
     39      printf("rank not find for EP_intercomm\n"); 
     40      int err; 
     41      return MPI_Abort(comm, err); 
     42    } 
     43     
    2944    for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) 
    3045    { 
     
    3550      } 
    3651    } 
    37     printf("rank not find\n"); 
     52    printf("rank not find for EP_intracomm\n"); 
     53    int err; 
     54    return MPI_Abort(comm, err); 
    3855  } 
    3956   
  • XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp

    r1500 r1520  
    3333        status->ep_tag = (*request)->ep_tag; 
    3434        status->ep_datatype = (*request)->ep_datatype; 
    35         //delete request->mpi_request; 
     35        delete (*request)->mpi_request; 
     36        delete request; 
    3637      } 
    3738 
     
    6061        status->ep_tag = (*request)->ep_tag; 
    6162        status->ep_datatype = (*request)->ep_datatype; 
    62         //delete request->mpi_request; 
     63        delete (*request)->mpi_request; 
     64        delete request; 
    6365        //int count; 
    6466        //MPI_Get_count(status, request->ep_datatype, &count); 
     
    7577  { 
    7678    Debug("MPI_Testall with EP"); 
    77     *flag = true; 
    78     int i=0; 
    79     while(*flag && i<count ) 
     79 
     80    ::MPI_Request* mpi_request = new ::MPI_Request[count]; 
     81    ::MPI_Status* mpi_status = new ::MPI_Status[count]; 
     82 
     83 
     84    for(int i=0; i<count; i++) 
    8085    { 
    81       MPI_Test(&array_of_requests[i], flag, &array_of_statuses[i]); 
    82       i++; 
     86      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); 
     87    } 
     88 
     89    ::MPI_Testall(count, mpi_request, flag, mpi_status); 
     90 
     91    if(flag) 
     92    { 
     93      for(int i=0; i<count; i++) 
     94      { 
     95        array_of_statuses[i].mpi_status = &mpi_status[i]; 
     96        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; 
     97        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; 
     98        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; 
     99       
     100        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request"); 
     101        delete array_of_requests[i]->mpi_request; 
     102        delete array_of_requests[i];  
     103      } 
     104       
    83105    } 
    84106 
     
    87109 
    88110} 
     111 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp

    r1354 r1520  
    1717{ 
    1818 
     19  int MPI_Allgather_local(const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm) 
     20  { 
     21    assert(valid_type(datatype)); 
     22 
     23    ::MPI_Aint datasize, lb; 
     24    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 
     25 
     26    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     27    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     28 
     29    #pragma omp critical (write_buffer) 
     30    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
     31 
     32    MPI_Barrier_local(comm); 
     33 
     34    #pragma omp critical (read_buffer) 
     35    { 
     36      for(int i=0; i<num_ep; i++) 
     37        memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count); 
     38    } 
     39    MPI_Barrier_local(comm); 
     40  } 
     41 
    1942  int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) 
    2043  { 
    2144 
    22     if(!comm.is_ep && comm.mpi_comm) 
     45    if(!comm->is_ep && comm->mpi_comm) 
    2346    { 
    24       return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm)); 
     47      return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 
    2548    } 
    2649 
     
    3760 
    3861 
    39     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    40     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    41     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    42     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    43     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    44     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     62    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     63    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     64    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     65    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     66    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     67    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    4568 
    4669    bool is_master = ep_rank_loc==0; 
     
    7093      int local_sendcount = num_ep * count; 
    7194 
    72       ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm.mpi_comm)); 
     95      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 
    7396 
    7497      mpi_displs[0] = 0; 
     
    79102 
    80103     
    81       ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm.mpi_comm)); 
     104      ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm)); 
    82105 
    83106 
     
    86109      for(int i=0; i<ep_size; i++) 
    87110      { 
    88         offset = mpi_displs[comm.rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount;  
     111        offset = mpi_displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount;  
    89112        memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize); 
    90113      } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp

    r1354 r1520  
    2020  { 
    2121 
    22     if(!comm.is_ep && comm.mpi_comm) 
     22    if(!comm->is_ep && comm->mpi_comm) 
    2323    { 
    24       return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm)); 
     24      return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 
    2525    } 
    2626 
    27     if(!comm.mpi_comm) return 0; 
     27    if(!comm->mpi_comm) return 0; 
    2828 
    2929 
     
    3838 
    3939 
    40     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    41     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    42     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    43     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    44     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    45     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     40    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     41    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     42    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     43    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     44    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     45    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    4646 
    4747    assert(sendcount == recvcounts[ep_rank]); 
     
    7979 
    8080      int local_sendcount = std::accumulate(local_recvcounts.begin(), local_recvcounts.end(), 0); 
    81       ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm.mpi_comm)); 
     81      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 
    8282 
    8383      for(int i=1; i<mpi_size; i++) 
     
    8585 
    8686 
    87       ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm.mpi_comm)); 
     87      ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm)); 
    8888 
    8989      // reorder  
     
    9292      { 
    9393        int extra = 0; 
    94         for(int j=0, k=0; j<ep_size, k<comm.rank_map->at(i).first; j++) 
    95           if(comm.rank_map->at(i).second == comm.rank_map->at(j).second) 
     94        for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++) 
     95          if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second) 
    9696          { 
    9797            extra += recvcounts[j]; 
     
    9999          }   
    100100 
    101         offset = mpi_displs[comm.rank_map->at(i).second] +  extra; 
     101        offset = mpi_displs[comm->ep_rank_map->at(i).second] +  extra; 
    102102 
    103103        memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp

    r1354 r1520  
    2121  int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 
    2222  { 
    23     if(!comm.is_ep && comm.mpi_comm) 
     23    if(!comm->is_ep && comm->mpi_comm) 
    2424    { 
    25       return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     25      return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    2626    } 
    2727 
    2828 
    2929 
    30     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    31     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    32     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    33     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    34     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    35     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     30    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     31    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     32    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     33    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     34    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     35    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    3636 
    3737 
     
    5555    if(is_master) 
    5656    { 
    57       ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     57      ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    5858    } 
    5959 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp

    r1354 r1520  
    99  int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) 
    1010  { 
    11     if(!comm.is_ep) 
     11    if(!comm->is_ep) 
    1212    { 
    13       return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm)); 
     13      return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 
    1414    } 
    1515 
     
    2323    int count = sendcount; 
    2424     
    25     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    26     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    27     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    28     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    29     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    30     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     25    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     26    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     27    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     28    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     29    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     30    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    3131 
    3232    void* tmp_recvbuf; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp

    r1354 r1520  
    99  int MPI_Barrier(MPI_Comm comm) 
    1010  { 
    11     if(comm.is_intercomm) return MPI_Barrier_intercomm(comm); 
     11    if(comm->is_intercomm) return MPI_Barrier_intercomm(comm); 
    1212 
    13     if(comm.is_ep) 
     13    if(comm->is_ep)  
    1414    { 
    15       int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    16  
    17       MPI_Barrier_local(comm); 
    18  
    19       if(ep_rank_loc == 0) 
    20       { 
    21         ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
    22  
    23         ::MPI_Barrier(mpi_comm); 
    24       } 
    25  
    26       MPI_Barrier_local(comm); 
    27  
    28       return 0; 
    29     } 
    30     else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 
    31     { 
    32       ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
    33       ::MPI_Barrier(mpi_comm); 
    34       return 0; 
     15      return MPI_Barrier_intracomm(comm); 
    3516    } 
    3617 
    37     else return 0; 
     18     
     19    return MPI_Barrier_mpi(comm); 
     20 
    3821  } 
    3922 
    40  
    41   int MPI_Barrier_intercomm(MPI_Comm comm) 
     23  int MPI_Barrier_intracomm(MPI_Comm comm) 
    4224  { 
    43  
    44     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
     25    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
    4526 
    4627    MPI_Barrier_local(comm); 
     
    4829    if(ep_rank_loc == 0) 
    4930    { 
    50       ::MPI_Comm mpi_comm = to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm); 
     31      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 
     32 
    5133      ::MPI_Barrier(mpi_comm); 
    5234    } 
     
    5537 
    5638    return 0; 
     39  } 
    5740 
     41  int MPI_Barrier_intercomm(MPI_Comm comm) 
     42  { 
     43    MPI_Barrier_local(comm); 
     44 
     45    if(comm->ep_comm_ptr->intercomm->size_rank_info[1].first == 0) 
     46      ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm)); 
     47 
     48    MPI_Barrier_local(comm); 
     49  } 
     50 
     51  int MPI_Barrier_mpi(MPI_Comm comm) 
     52  { 
     53    return ::MPI_Barrier(to_mpi_comm(comm->mpi_comm)); 
    5854  } 
    5955 
     
    6157  int MPI_Barrier_local(MPI_Comm comm) 
    6258  { 
    63     //Message_Check(comm); 
    64     comm.ep_barrier->wait(); 
     59    comm->ep_barrier->wait(); 
    6560  } 
    6661 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp

    r1354 r1520  
    2020    assert(valid_type(datatype)); 
    2121 
    22     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
     22    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
    2323 
    2424    ::MPI_Aint datasize, lb; 
     
    2828    if(ep_rank_loc == local_root) 
    2929    { 
    30       comm.my_buffer->void_buffer[local_root] = buffer; 
     30      comm->my_buffer->void_buffer[local_root] = buffer; 
    3131    } 
    3232 
     
    3636    { 
    3737      #pragma omp critical (_bcast)       
    38       memcpy(buffer, comm.my_buffer->void_buffer[local_root], datasize * count); 
     38      memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count); 
    3939    } 
    4040 
     
    4545  { 
    4646 
    47     if(!comm.is_ep) 
     47    if(!comm->is_ep) 
    4848    { 
    4949      #pragma omp single nowait 
    50       ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm.mpi_comm)); 
     50      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm)); 
    5151      return 0; 
    5252    } 
    5353 
    5454 
    55     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    56     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    57     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
     55    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     56    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     57    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
    5858 
    59     int root_mpi_rank = comm.rank_map->at(root).second; 
    60     int root_ep_rank_loc = comm.rank_map->at(root).first; 
     59    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     60    int root_ep_rank_loc = comm->ep_rank_map->at(root).first; 
    6161 
    6262 
    6363    if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root) 
    6464    { 
    65       ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     65      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    6666    } 
    6767 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp

    r1356 r1520  
    2525    \param [out] out_comm_hdls Handles of EP communicators. 
    2626  */ 
    27   // #ifdef _intelmpi 
    28   // int MPI_Comm_create_endpoints(int base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls) 
    29   // { 
    30   //   int base_rank; 
    31   //   int base_size; 
    32  
    33   //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr); 
    34  
    35   //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size 
    36   //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank 
    37                 //                                                        // parent_comm can also be endpoints communicators 
    38  
    39   //   std::vector<int> recv_num_ep(base_size); 
    40  
    41   //   out_comm_hdls = new MPI_Comm[num_ep]; 
    42  
    43   //   for (int idx = 0; idx < num_ep; ++idx) 
    44   //   { 
    45   //     out_comm_hdls[idx].is_ep = true; 
    46   //     out_comm_hdls[idx].is_intercomm = false; 
    47   //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator; 
    48   //     out_comm_hdls[idx].mpi_comm = base_comm_ptr; 
    49   //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls; 
    50   //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0; 
    51   //   } 
    52  
    53   //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype>(MPI_INT), &recv_num_ep[0], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_base_comm); 
    54  
    55  
    56   //   int sum = 0;  // representing total ep number of process with smaller rank 
    57   //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; } 
    58  
    59   //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0); 
    60  
    61   //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep); 
    62  
    63   //   out_comm_hdls[0].my_buffer = new BUFFER; 
    64  
    65   //   out_comm_hdls[0].rank_map = new RANK_MAP; 
    66   //   out_comm_hdls[0].rank_map->resize(ep_size); 
    67  
    68  
    69   //   for (int i = 1; i < num_ep; i++) 
    70   //   { 
    71   //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier; 
    72   //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer; 
    73   //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map; 
    74   //   } 
    75  
    76  
    77   //   for (int i = 0; i < num_ep; i++) 
    78   //   { 
    79   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size); 
    80   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep); 
    81   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size); 
    82  
    83   //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list; 
    84   //   } 
    85  
    86  
    87   //   int ind = 0; 
    88  
    89   //   for(int i=0; i<base_size; i++) 
    90   //   { 
    91   //     for(int j=0; j<recv_num_ep[i]; j++) 
    92   //     { 
    93   //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i); 
    94   //       ind++; 
    95   //     } 
    96   //   } 
    97  
    98  
    99  
    100   //   return 0; 
    101  
    102   // } //MPI_Comm_create_endpoints 
    103  
    104   // #elif _openmpi 
    105   // int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls) 
    106   // { 
    107  
    108   //   int base_rank; 
    109   //   int base_size; 
    110  
    111   //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr); 
    112  
    113   //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size 
    114   //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank 
    115   //                                                // parent_comm can also be endpoints communicators ? 
    116   //   std::vector<int> recv_num_ep(base_size); 
    117  
    118   //   out_comm_hdls = new MPI_Comm[num_ep]; 
    119  
    120   //   for (int idx = 0; idx < num_ep; ++idx) 
    121   //   { 
    122   //     out_comm_hdls[idx].is_ep = true; 
    123   //     out_comm_hdls[idx].is_intercomm = false; 
    124   //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator; 
    125   //     out_comm_hdls[idx].mpi_comm = base_comm_ptr; 
    126   //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls; 
    127   //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0; 
    128   //   } 
    129  
    130   //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype> (MPI_INT),  
    131   //                  &recv_num_ep[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_base_comm); 
    132  
    133   //   int sum = 0;  // representing total ep number of process with smaller rank 
    134   //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; } 
    135  
    136   //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0); 
    137  
    138   //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep); 
    139   //   out_comm_hdls[0].my_buffer = new BUFFER; 
    140  
    141   //   out_comm_hdls[0].rank_map = new RANK_MAP; 
    142   //   out_comm_hdls[0].rank_map->resize(ep_size); 
    143  
    144  
    145   //   for (int i = 1; i < num_ep; i++) 
    146   //   { 
    147   //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier; 
    148   //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer; 
    149   //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map; 
    150   //   } 
    151  
    152  
    153   //   for (int i = 0; i < num_ep; i++) 
    154   //   { 
    155   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size); 
    156   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep); 
    157   //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size); 
    158  
    159   //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list; 
    160   //   } 
    161  
    162  
    163   //   int ind = 0; 
    164  
    165   //   for(int i=0; i<base_size; i++) 
    166   //   { 
    167   //     for(int j=0; j<recv_num_ep[i]; j++) 
    168   //     { 
    169   //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i); 
    170   //       ind++; 
    171   //     } 
    172   //   } 
    173  
    174   //   return 0; 
    175  
    176   // } //MPI_Comm_create_endpoints 
    177  
    178   // #endif 
    179    
    18027   
    18128  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls) 
     
    19441 
    19542    out_comm_hdls = new MPI_Comm[num_ep]; 
     43#ifdef _showinfo 
     44    printf("new out_comm_hdls = %p\n", out_comm_hdls); 
     45#endif 
    19646 
     47    ::MPI_Comm *parent_comm = new ::MPI_Comm; 
     48    ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm); 
     49 
     50#ifdef _showinfo 
     51    printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm); 
     52#endif 
     53     
    19754    for (int idx = 0; idx < num_ep; ++idx) 
    19855    { 
    199       out_comm_hdls[idx].is_ep = true; 
    200       out_comm_hdls[idx].is_intercomm = false; 
    201       out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;      
    202       *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx].mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr)); 
    203       out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls; 
    204       out_comm_hdls[idx].ep_comm_ptr->comm_label = 0; 
     56 
     57      out_comm_hdls[idx] = new ep_comm; 
     58#ifdef _showinfo 
     59      printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]); 
     60#endif 
     61 
     62      out_comm_hdls[idx]->is_ep = true; 
     63      out_comm_hdls[idx]->is_intercomm = false; 
     64       
     65      out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator;      
     66#ifdef _showinfo 
     67      printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr); 
     68#endif 
     69 
     70 
     71      out_comm_hdls[idx]->mpi_comm = parent_comm; 
     72      out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls; 
     73      out_comm_hdls[idx]->ep_comm_ptr->comm_label = 0; 
    20574    } 
    20675 
     
    21382    int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0); 
    21483 
    215     out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep); 
    216     out_comm_hdls[0].my_buffer = new BUFFER; 
     84    out_comm_hdls[0]->ep_barrier = new ep_barrier(num_ep); 
     85#ifdef _showinfo 
     86    printf("new out_comm_hdls[0]->ep_barrier = %p\n", out_comm_hdls[0]->ep_barrier); 
     87#endif 
    21788 
    218     out_comm_hdls[0].rank_map = new RANK_MAP; 
    219     out_comm_hdls[0].rank_map->resize(ep_size); 
     89    out_comm_hdls[0]->my_buffer = new BUFFER; 
     90#ifdef _showinfo 
     91    printf("new out_comm_hdls[0]->my_buffer = %p\n", out_comm_hdls[0]->my_buffer); 
     92#endif 
    22093 
     94    out_comm_hdls[0]->ep_rank_map = new EP_RANK_MAP; 
     95#ifdef _showinfo 
     96    printf("new out_comm_hdls[0]->ep_rank_map = %p\n", out_comm_hdls[0]->ep_rank_map); 
     97#endif 
    22198 
    22299    for (int i = 1; i < num_ep; i++) 
    223100    { 
    224       out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier; 
    225       out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer; 
    226       out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map; 
     101      out_comm_hdls[i]->ep_barrier = out_comm_hdls[0]->ep_barrier; 
     102      out_comm_hdls[i]->my_buffer  = out_comm_hdls[0]->my_buffer; 
     103      out_comm_hdls[i]->ep_rank_map= out_comm_hdls[0]->ep_rank_map; 
    227104    } 
    228105 
     
    230107    for (int i = 0; i < num_ep; i++) 
    231108    { 
    232       out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size); 
    233       out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep); 
    234       out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size); 
     109      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size); 
     110      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep); 
     111      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size); 
    235112 
    236       out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list; 
     113      out_comm_hdls[i]->ep_comm_ptr->message_queue = new Message_list; 
     114#ifdef _showinfo 
     115      printf("new out_comm_hdls[%d]->ep_comm_ptr->message_queue = %p\n", i, out_comm_hdls[i]->ep_comm_ptr->message_queue); 
     116#endif 
     117 
    237118    } 
    238119 
     
    244125      for(int j=0; j<recv_num_ep[i]; j++) 
    245126      { 
    246         out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i); 
     127        out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i)); 
    247128        ind++; 
    248129      } 
     
    253134  } //MPI_Comm_create_endpoints 
    254135 
     136   
    255137 
    256138} //namespace ep_lib 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp

    r1482 r1520  
    4242::MPI_Op MPI_MIN_STD = MPI_MIN; 
    4343::MPI_Op MPI_LOR_STD = MPI_LOR; 
     44::MPI_Op MPI_REPLACE_STD = MPI_REPLACE; 
    4445 
    4546#undef MPI_SUM 
     
    4748#undef MPI_MIN 
    4849#undef MPI_LOR 
     50#undef MPI_REPLACE 
    4951 
    5052 
     
    6668extern ::MPI_Op MPI_MIN_STD; 
    6769extern ::MPI_Op MPI_LOR_STD; 
     70extern ::MPI_Op MPI_REPLACE_STD; 
    6871 
    6972extern ::MPI_Comm MPI_COMM_WORLD_STD; 
     
    8992ep_lib::MPI_Op MPI_MIN = &MPI_MIN_STD; 
    9093ep_lib::MPI_Op MPI_LOR = &MPI_LOR_STD; 
     94ep_lib::MPI_Op MPI_REPLACE = &MPI_REPLACE_STD; 
    9195 
    92 ep_lib::MPI_Comm MPI_COMM_WORLD(&MPI_COMM_WORLD_STD); 
    93 ep_lib::MPI_Comm MPI_COMM_NULL(&MPI_COMM_NULL_STD); 
     96ep_lib::ep_comm EP_COMM_WORLD(&MPI_COMM_WORLD_STD); 
     97ep_lib::ep_comm EP_COMM_NULL(&MPI_COMM_NULL_STD); 
    9498 
    95 ep_lib::MPI_Request MPI_REQUEST_NULL(&MPI_REQUEST_NULL_STD); 
    96 ep_lib::MPI_Info MPI_INFO_NULL(&MPI_INFO_NULL_STD); 
     99ep_lib::MPI_Comm MPI_COMM_WORLD = &EP_COMM_WORLD; 
     100ep_lib::MPI_Comm MPI_COMM_NULL = &EP_COMM_NULL; 
     101 
     102//ep_lib::ep_status EP_STATUS_IGNORE(&MPI_STATUS_IGNORE_STD); 
     103ep_lib::ep_request EP_REQUEST_NULL(&MPI_REQUEST_NULL_STD); 
     104ep_lib::ep_info EP_INFO_NULL(&MPI_INFO_NULL_STD); 
     105 
     106//ep_lib::MPI_Status MPI_STATUS_IGNORE = &EP_STATUS_IGNORE; 
     107ep_lib::MPI_Request MPI_REQUEST_NULL = &EP_REQUEST_NULL; 
     108ep_lib::MPI_Info MPI_INFO_NULL = &EP_INFO_NULL; 
    97109 
    98110 
    99111 
    100  
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp

    r1482 r1520  
    1616#undef MPI_MIN 
    1717#undef MPI_LOR 
     18#undef MPI_REPLACE 
    1819 
    1920#undef MPI_COMM_WORLD 
     
    3839extern ep_lib::MPI_Op MPI_MIN; 
    3940extern ep_lib::MPI_Op MPI_LOR; 
     41extern ep_lib::MPI_Op MPI_REPLACE; 
    4042 
    4143extern ep_lib::MPI_Comm MPI_COMM_WORLD; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp

    r1468 r1520  
    77{ 
    88 
    9   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) 
     9  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm) 
    1010  { 
    11     if(!comm.is_ep) 
    12     { 
    13       Debug("Comm_dup MPI\n"); 
    14       newcomm = new MPI_Comm; 
    15       newcomm->is_ep = comm.is_ep; 
     11    newcomm = new MPI_Comm; 
     12    (*newcomm)->is_ep = false; 
    1613 
    17       ::MPI_Comm input = to_mpi_comm(comm.mpi_comm); 
    18       ::MPI_Comm *output = new ::MPI_Comm; 
     14    ::MPI_Comm *output = new ::MPI_Comm; 
     15       
     16    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output); 
    1917 
    20        
    21       ::MPI_Comm_dup(input, output); 
     18    (*newcomm)->mpi_comm = output; 
     19  } 
    2220 
    23       newcomm->mpi_comm = output; 
    24  
    25       return 0; 
    26     } 
    27  
    28     if(comm.is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm); 
    29  
    30     // for intracomm 
    31     if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0; 
     21  int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm) 
     22  { 
     23    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     24    int num_ep      = comm->ep_comm_ptr->size_rank_info[1].second; 
    3225 
    3326 
    34     int my_rank = comm.ep_comm_ptr->size_rank_info[1].first; 
    35     int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second; 
    36  
    37  
    38     if(0 == my_rank) 
     27    if(0 == ep_rank_loc) 
    3928    { 
    4029      MPI_Info info; 
    4130      MPI_Comm *out_comm; 
    42       ::MPI_Comm *mpi_dup = new ::MPI_Comm; 
    4331 
    44       ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm); 
    45  
    46       ::MPI_Comm_dup(in_comm, mpi_dup); 
    47  
    48       MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); 
    49       comm.ep_comm_ptr->comm_list->mem_bridge = out_comm; 
     32      MPI_Comm_create_endpoints(comm->mpi_comm, num_ep, info, out_comm); 
     33      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; 
    5034    } 
    5135 
    52     MPI_Barrier(comm); 
     36    MPI_Barrier_local(comm); 
    5337 
    54     *newcomm = (comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]); 
     38    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]); 
     39     
     40  } 
    5541 
    56     return MPI_SUCCESS; 
     42  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) 
     43  { 
     44     
     45    if(!comm->is_ep) 
     46    { 
     47      Debug("MPI_Comm_dup with MPI\n"); 
     48      return MPI_Comm_dup_mpi(comm, newcomm);  
     49    } 
     50 
     51    if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm); 
     52 
     53     
     54    return MPI_Comm_dup_intracomm(comm, newcomm);  
     55 
     56    
    5757  } 
    5858 
     
    6060  { 
    6161     
    62     if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0; 
    63  
    64     int my_rank = comm.ep_comm_ptr->size_rank_info[1].first; 
    65     int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second; 
     62    int newcomm_ep_rank =comm->ep_comm_ptr->intercomm->size_rank_info[0].first;  
     63    int newcomm_ep_rank_loc = comm->ep_comm_ptr->intercomm->size_rank_info[1].first; 
     64    int newcomm_num_ep = comm->ep_comm_ptr->intercomm->size_rank_info[1].second; 
    6665 
    6766 
    68     if(0 == my_rank) 
     67    if(0 == newcomm_ep_rank_loc) 
    6968    { 
     69      //printf("in dup , newcomm_ep_rank_loc = 0 :  ep %d\n", comm->ep_comm_ptr->intercomm->size_rank_info[0].first); 
     70 
    7071      MPI_Info info; 
    7172      MPI_Comm *out_comm; 
    72       ::MPI_Comm *mpi_dup = new ::MPI_Comm; 
    7373 
    74       ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm); 
     74      MPI_Comm_create_endpoints(comm->mpi_comm, newcomm_num_ep, info, out_comm); 
    7575 
    76       ::MPI_Comm_dup(in_comm, mpi_dup); 
     76      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm; 
     77      ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter_comm); 
    7778 
    78       MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); 
    79  
    80       ::MPI_Comm *mpi_inter = new ::MPI_Comm; 
    81  
    82       ::MPI_Comm_dup(to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter); 
    83        
    84       for(int i=0; i<num_ep; i++) 
     79      for(int i=0; i<newcomm_num_ep; i++) 
    8580      { 
    86         out_comm[i].ep_comm_ptr->comm_label = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->comm_label; 
    87         out_comm[i].ep_comm_ptr->intercomm = new ep_intercomm; 
    88  
    89         out_comm[i].ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter; 
    90         out_comm[i].is_intercomm = true; 
    91  
    92         out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 
    93         out_comm[i].ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 
    94         out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 
    95  
    96         int map_size = 0; 
    97         map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->size(); 
    98         out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->resize(map_size); 
    99         for(int ii=0; ii<map_size; ii++) 
    100           out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii); 
    101  
    102         map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->size(); 
    103         out_comm[i].ep_comm_ptr->intercomm->local_rank_map->resize(map_size); 
    104         for(int ii=0; ii<map_size; ii++) 
    105           out_comm[i].ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->at(ii); 
    106  
    107         map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->size(); 
    108         out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->resize(map_size); 
    109         for(int ii=0; ii<map_size; ii++) 
    110           out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii); 
     81        out_comm[i]->is_intercomm = true; 
     82        out_comm[i]->ep_comm_ptr->comm_label = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->comm_label; 
     83        out_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
     84#ifdef _showinfo 
     85        printf("new out_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, out_comm[i]->ep_comm_ptr->intercomm); 
     86#endif 
     87        out_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm; 
     88      } 
    11189 
    11290 
    113         //out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map; 
    114         //out_comm[i].ep_comm_ptr->intercomm->local_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map; 
    115         //out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map; 
    116  
    117         out_comm[i].ep_comm_ptr->intercomm->local_comm = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_comm;         
    118         out_comm[i].ep_comm_ptr->intercomm->intercomm_tag = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_tag; 
    119  
    120         for(int j =0; j<3; j++) 
    121         { 
    122           out_comm[i].ep_comm_ptr->intercomm->size_rank_info[j] = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->size_rank_info[j]; 
    123         } 
    124  
    125       } 
    126  
    127       comm.ep_comm_ptr->comm_list->mem_bridge = out_comm; 
     91      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; 
    12892    } 
    12993 
    130     MPI_Barrier(comm); 
     94    MPI_Barrier_local(comm); 
    13195 
    132     *newcomm = comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]; 
     96    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[newcomm_ep_rank_loc]); 
     97 
     98    (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0]; 
     99    (*newcomm)->ep_comm_ptr->size_rank_info[1] = comm->ep_comm_ptr->size_rank_info[1]; 
     100    (*newcomm)->ep_comm_ptr->size_rank_info[2] = comm->ep_comm_ptr->size_rank_info[2]; 
     101 
     102    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[0] = comm->ep_comm_ptr->intercomm->size_rank_info[0]; 
     103    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[1] = comm->ep_comm_ptr->intercomm->size_rank_info[1]; 
     104    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[2] = comm->ep_comm_ptr->intercomm->size_rank_info[2]; 
     105 
     106    (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->intercomm->intercomm_tag; 
     107 
     108 
     109    int ep_rank_loc = (*newcomm)->ep_comm_ptr->size_rank_info[1].first; 
     110     
     111    if(ep_rank_loc == 0) 
     112    { 
     113      int world_rank; 
     114      MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 
     115 
     116      (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP; 
     117      (*newcomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP; 
     118 
     119      *(*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = *comm->ep_comm_ptr->intercomm->intercomm_rank_map; 
     120      *(*newcomm)->ep_comm_ptr->intercomm->local_rank_map     = *comm->ep_comm_ptr->intercomm->local_rank_map; 
     121    } 
     122 
     123    MPI_Barrier_local(comm); 
     124 
     125    if(ep_rank_loc !=0 ) 
     126    { 
     127      int target = (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag; 
     128      (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map;  
     129      (*newcomm)->ep_comm_ptr->intercomm->local_rank_map     = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map; 
     130    } 
     131 
    133132     
    134133 
    135     return MPI_SUCCESS; 
     134 
     135 
     136     
    136137  } 
    137138 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp

    r1295 r1520  
    5050    valid_op(op); 
    5151 
    52     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    53     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    54     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
     52    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     53    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     54    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
    5555     
    5656 
     
    6060    if(ep_rank_loc == 0 && mpi_rank != 0) 
    6161    { 
    62       comm.my_buffer->void_buffer[0] = recvbuf; 
     62      comm->my_buffer->void_buffer[0] = recvbuf; 
    6363    } 
    6464    if(ep_rank_loc == 0 && mpi_rank == 0) 
    6565    { 
    66       comm.my_buffer->void_buffer[0] = const_cast<void*>(sendbuf);   
     66      comm->my_buffer->void_buffer[0] = const_cast<void*>(sendbuf);   
    6767    }  
    6868       
     
    7070    MPI_Barrier_local(comm); 
    7171 
    72     memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize*count); 
     72    memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize*count); 
    7373 
    7474    MPI_Barrier_local(comm); 
    7575 
    76     comm.my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);   
     76    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);   
    7777     
    7878    MPI_Barrier_local(comm); 
     
    8484        assert(datasize == sizeof(int)); 
    8585        for(int i=0; i<ep_rank_loc; i++) 
    86           reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     86          reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    8787      } 
    8888      
     
    9191        assert(datasize == sizeof(float)); 
    9292        for(int i=0; i<ep_rank_loc; i++) 
    93           reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     93          reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    9494      } 
    9595       
     
    9999        assert(datasize == sizeof(double)); 
    100100        for(int i=0; i<ep_rank_loc; i++) 
    101           reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     101          reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    102102      } 
    103103 
     
    106106        assert(datasize == sizeof(char)); 
    107107        for(int i=0; i<ep_rank_loc; i++) 
    108           reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     108          reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    109109      } 
    110110 
     
    113113        assert(datasize == sizeof(long)); 
    114114        for(int i=0; i<ep_rank_loc; i++) 
    115           reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     115          reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    116116      } 
    117117 
     
    120120        assert(datasize == sizeof(unsigned long)); 
    121121        for(int i=0; i<ep_rank_loc; i++) 
    122           reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     122          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    123123      } 
    124124 
     
    134134        assert(datasize == sizeof(int)); 
    135135        for(int i=0; i<ep_rank_loc; i++) 
    136           reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     136          reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    137137      } 
    138138 
     
    141141        assert(datasize == sizeof(float)); 
    142142        for(int i=0; i<ep_rank_loc; i++) 
    143           reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     143          reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    144144      } 
    145145 
     
    148148        assert(datasize == sizeof(double)); 
    149149        for(int i=0; i<ep_rank_loc; i++) 
    150           reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     150          reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    151151      } 
    152152 
     
    155155        assert(datasize == sizeof(char)); 
    156156        for(int i=0; i<ep_rank_loc; i++) 
    157           reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     157          reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    158158      } 
    159159 
     
    162162        assert(datasize == sizeof(long)); 
    163163        for(int i=0; i<ep_rank_loc; i++) 
    164           reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     164          reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    165165      } 
    166166 
     
    169169        assert(datasize == sizeof(unsigned long)); 
    170170        for(int i=0; i<ep_rank_loc; i++) 
    171           reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     171          reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    172172      } 
    173173      
     
    181181        assert(datasize == sizeof(int)); 
    182182        for(int i=0; i<ep_rank_loc; i++) 
    183           reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     183          reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    184184      } 
    185185 
     
    188188        assert(datasize == sizeof(float)); 
    189189        for(int i=0; i<ep_rank_loc; i++) 
    190           reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     190          reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    191191      } 
    192192 
     
    195195        assert(datasize == sizeof(double)); 
    196196        for(int i=0; i<ep_rank_loc; i++) 
    197           reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     197          reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    198198      } 
    199199 
     
    202202        assert(datasize == sizeof(char)); 
    203203        for(int i=0; i<ep_rank_loc; i++) 
    204           reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     204          reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    205205      } 
    206206 
     
    209209        assert(datasize == sizeof(long)); 
    210210        for(int i=0; i<ep_rank_loc; i++) 
    211           reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     211          reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    212212      } 
    213213 
     
    216216        assert(datasize == sizeof(unsigned long)); 
    217217        for(int i=0; i<ep_rank_loc; i++) 
    218           reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     218          reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    219219      } 
    220220 
     
    228228  int MPI_Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 
    229229  { 
    230     if(!comm.is_ep) 
    231     { 
    232       return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     230    if(!comm->is_ep) 
     231    { 
     232      return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    233233    } 
    234234     
    235235    valid_type(datatype); 
    236236 
    237     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    238     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    239     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    240     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    241     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    242     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     237    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     238    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     239    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     240    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     241    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     242    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    243243 
    244244    ::MPI_Aint datasize, lb; 
     
    253253    std::vector<int> my_map(mpi_size, 0); 
    254254 
    255     for(int i=0; i<comm.rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++; 
     255    for(int i=0; i<comm->ep_rank_map->size(); i++) my_map[comm->ep_rank_map->at(i).second]++; 
    256256 
    257257    for(int i=0; i<mpi_rank; i++) my_src += my_map[i]; 
     
    291291 
    292292    if(ep_rank_loc == 0) 
    293       ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     293      ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    294294 
    295295    // printf(" ID=%d : %d  %d \n", ep_rank, static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp

    r1354 r1520  
    2222  int MPI_Abort(MPI_Comm comm, int errorcode) 
    2323  { 
    24     int id = omp_get_thread_num(); 
     24    if(!comm->is_ep) 
     25      return MPI_Abort_mpi(comm, errorcode); 
    2526 
    26     if(id == 0) 
     27    else 
    2728    { 
    28       ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
    29       ::MPI_Abort(mpi_comm, errorcode); 
     29      if(comm->ep_comm_ptr->size_rank_info[1].first == 0) 
     30      { 
     31        ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode); 
     32      } 
    3033    } 
    31     return 0; 
     34  } 
     35 
     36  int MPI_Abort_mpi(MPI_Comm comm, int errorcode) 
     37  { 
     38    return ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode); 
    3239  } 
    3340 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp

    r1369 r1520  
    1616    void* fint = new ::MPI_Fint; 
    1717    #ifdef _intelmpi 
    18     *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm.mpi_comm)); 
     18    *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm)); 
    1919    #elif _openmpi 
    20     *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm.mpi_comm)); 
     20    *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); 
    2121    #endif 
    2222     
     
    2929      { 
    3030        fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm)); 
    31         printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm.ep_comm_ptr); 
     31        printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr); 
    3232      } 
    3333    } 
     
    5252      MPI_Comm comm_ptr; 
    5353      comm_ptr = it->second; 
    54       printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr.ep_comm_ptr); 
     54      printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr->ep_comm_ptr); 
    5555      return  comm_ptr; 
    5656    } 
     
    6565    #endif 
    6666 
    67     if(*base_comm != to_mpi_comm(MPI_COMM_NULL.mpi_comm)) 
     67    if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm)) 
    6868    { 
    6969      if(omp_get_thread_num() == 0) 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp

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

    r1365 r1520  
    2323    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 
    2424 
    25     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    26     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
     25    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     26    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
    2727 
    2828    #pragma omp critical (_gather) 
    29     comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
     29    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
    3030 
    3131    MPI_Barrier_local(comm); 
     
    3434    { 
    3535      for(int i=0; i<num_ep; i++) 
    36         memcpy(recvbuf + datasize * i * count, comm.my_buffer->void_buffer[i], datasize * count); 
     36        memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count); 
    3737 
    3838      //printf("local_recvbuf = %d %d \n", static_cast<int*>(recvbuf)[0], static_cast<int*>(recvbuf)[1] ); 
     
    4444  int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) 
    4545  { 
    46     if(!comm.is_ep) 
     46    if(!comm->is_ep) 
    4747    { 
    4848      return ::MPI_Gather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), 
    49                    root, to_mpi_comm(comm.mpi_comm)); 
     49                   root, to_mpi_comm(comm->mpi_comm)); 
    5050    } 
    5151 
    5252    assert(sendcount == recvcount && sendtype == recvtype); 
    5353 
    54     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    55     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    56     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    57     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    58     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    59     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     54    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     55    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     56    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     57    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     58    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     59    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    6060 
    61     int root_mpi_rank = comm.rank_map->at(root).second; 
    62     int root_ep_loc = comm.rank_map->at(root).first; 
     61    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     62    int root_ep_loc = comm->ep_rank_map->at(root).first; 
    6363 
    6464    ::MPI_Aint datasize, lb; 
     
    9090      for(int i=0; i<ep_size; i++) 
    9191      { 
    92         recvcounts[comm.rank_map->at(i).second]+=sendcount; 
     92        recvcounts[comm->ep_rank_map->at(i).second]+=sendcount; 
    9393      } 
    9494 
     
    9696        displs[i] = displs[i-1] + recvcounts[i-1]; 
    9797 
    98       ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     98      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    9999    }    
    100100 
     
    111111      for(int i=0; i<ep_size; i++) 
    112112      { 
    113         offset = displs[comm.rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount;  
     113        offset = displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount;  
    114114        memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize); 
    115115 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp

    r1365 r1520  
    2323    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 
    2424 
    25     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    26     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
     25    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     26    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
    2727 
    2828 
    2929    #pragma omp critical (_gatherv) 
    30     comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
     30    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
    3131 
    3232    MPI_Barrier_local(comm); 
     
    3535    { 
    3636      for(int i=0; i<num_ep; i++) 
    37         memcpy(recvbuf + datasize*displs[i], comm.my_buffer->void_buffer[i], datasize*recvcounts[i]); 
     37        memcpy(recvbuf + datasize*displs[i], comm->my_buffer->void_buffer[i], datasize*recvcounts[i]); 
    3838 
    3939    } 
     
    4646  { 
    4747   
    48     if(!comm.is_ep) 
     48    if(!comm->is_ep) 
    4949    { 
    5050      return ::MPI_Gatherv(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, const_cast<int*>(input_recvcounts), const_cast<int*>(input_displs), 
    51                     to_mpi_type(recvtype), root, to_mpi_comm(comm.mpi_comm)); 
     51                    to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm)); 
    5252    } 
    5353 
     
    5656 
    5757     
    58     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    59     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    60     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    61     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    62     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    63     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     58    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     59    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     60    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     61    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     62    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     63    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    6464 
    65     int root_mpi_rank = comm.rank_map->at(root).second; 
    66     int root_ep_loc = comm.rank_map->at(root).first; 
     65    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     66    int root_ep_loc = comm->ep_rank_map->at(root).first; 
    6767 
    6868    ::MPI_Aint datasize, lb; 
     
    126126      for(int i=0; i<ep_size; i++) 
    127127      { 
    128         mpi_recvcounts[comm.rank_map->at(i).second]+=recvcounts[i]; 
     128        mpi_recvcounts[comm->ep_rank_map->at(i).second]+=recvcounts[i]; 
    129129      } 
    130130 
     
    133133 
    134134 
    135       ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     135      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    136136    }    
    137137 
     
    144144      { 
    145145        int extra = 0; 
    146         for(int j=0, k=0; j<ep_size, k<comm.rank_map->at(i).first; j++) 
    147           if(comm.rank_map->at(i).second == comm.rank_map->at(j).second) 
     146        for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++) 
     147          if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second) 
    148148          { 
    149149            extra += recvcounts[j]; 
     
    151151          }   
    152152 
    153         offset = mpi_displs[comm.rank_map->at(i).second] +  extra; 
     153        offset = mpi_displs[comm->ep_rank_map->at(i).second] +  extra; 
    154154 
    155155        memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp

    r1134 r1520  
    1111  int MPI_Init_thread(int *argc, char*** argv, int required, int*provided) 
    1212  { 
    13     //printf("MPI_Init_thread\n"); 
     13    Debug("MPI_Init_thread with EP/MPI\n"); 
    1414 
    15     int id = omp_get_thread_num(); 
    16  
    17     if(id == 0) 
     15    if(omp_get_thread_num() == 0) 
    1816    { 
    1917      ::MPI_Init_thread(argc, argv, required, provided); 
    2018    } 
    21     return 0; 
    2219  } 
    2320 
    2421  int MPI_Init(int *argc, char ***argv) 
    2522  { 
    26     //printf("MPI_init called\n"); 
    27     int id = omp_get_thread_num(); 
     23    Debug("MPI_Init with EP/MPI\n"); 
    2824 
    29     if(id == 0) 
     25    if(omp_get_thread_num() == 0) 
    3026    { 
    3127      ::MPI_Init(argc, argv); 
    3228    } 
    33         return 0; 
    3429  } 
    3530 
    3631  int MPI_Initialized(int *flag) 
    3732  { 
    38     //printf("MPI_initialized called\n"); 
     33    Debug("MPI_Initialized with EP/MPI\n"); 
    3934 
    40     ::MPI_Initialized(flag); 
    41      
    42     return 0; 
     35    return ::MPI_Initialized(flag); 
    4336  } 
    4437 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp

    r1354 r1520  
    1010  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm) 
    1111  { 
    12     assert(local_comm.is_ep); 
     12    assert(local_comm->is_ep); 
    1313 
    1414    int ep_rank, ep_rank_loc, mpi_rank; 
    1515    int ep_size, num_ep, mpi_size; 
    1616 
    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; 
     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; 
    2323 
    2424 
    2525    MPI_Barrier(local_comm); 
     26 
     27    int leader_ranks_in_peer[3];  // local_leader_rank_in_peer 
     28                                  // remote_leader_rank_in_peer 
     29                                  // size of peer 
     30 
     31    if(ep_rank == local_leader) 
     32    { 
     33      MPI_Comm_rank(peer_comm, &leader_ranks_in_peer[0]); 
     34      leader_ranks_in_peer[1] = remote_leader; 
     35      MPI_Comm_size(peer_comm, &leader_ranks_in_peer[2]); 
     36    } 
     37 
     38    MPI_Bcast(leader_ranks_in_peer, 3, MPI_INT, local_leader, local_comm); 
     39 
     40    if(leader_ranks_in_peer[0] != leader_ranks_in_peer[2]) 
     41    { 
     42      Debug("calling MPI_Intercomm_create_kernel\n"); 
     43      return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 
     44    } 
     45 
     46    else 
     47    { 
     48      if(leader_ranks_in_peer[2] == 1) 
     49      { 
     50        Debug("calling MPI_Intercomm_create_unique\n"); 
     51        return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);  
     52         
     53      } 
     54      else 
     55      { 
     56        Debug("calling MPI_Intercomm_create_world\n"); 
     57        return MPI_Intercomm_create_from_world(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);    
     58      } 
     59       
     60    } 
     61 
     62 
    2663 
    2764 
     
    6198      if( leader_ranks[1] * leader_ranks[4] == 1) 
    6299      { 
    63         if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_unique_leader\n"); 
    64         local_comm.ep_comm_ptr->comm_label = -99; 
     100        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n"); 
     101        local_comm->ep_comm_ptr->comm_label = -99; 
    65102 
    66103        return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 
     
    77114            // change leader 
    78115            is_decider = true; 
    79             int target = local_comm.rank_map->at(local_leader).second; 
     116            int target = local_comm->ep_rank_map->at(local_leader).second; 
    80117            { 
    81118              for(int i=0; i<ep_size; i++) 
    82119              { 
    83                 if(local_comm.rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0) 
     120                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0) 
    84121                { 
    85122                  new_local_leader = i; 
     
    100137            // change leader 
    101138            is_decider = true; 
    102             int target = local_comm.rank_map->at(local_leader).second; 
     139            int target = local_comm->ep_rank_map->at(local_leader).second; 
    103140            { 
    104141              for(int i=0; i<ep_size; i++) 
    105142              { 
    106                 if(local_comm.rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0) 
     143                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0) 
    107144                { 
    108145                  new_local_leader = i; 
     
    146183        if(ep_rank == new_local_leader) 
    147184        { 
    148           ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &leader_in_world[0]); 
     185          ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &leader_in_world[0]); 
    149186        } 
    150187 
     
    165202        MPI_Bcast(&leader_in_world[1], 1, MPI_INT, local_leader, local_comm); 
    166203 
    167         local_comm.ep_comm_ptr->comm_label = tag; 
    168  
    169         if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n"); 
    170  
    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); 
     204        local_comm->ep_comm_ptr->comm_label = tag; 
     205 
     206        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n"); 
     207 
     208        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); 
    172209         
    173210      } 
    174211    } 
    175212 
    176     if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_kernel\n"); 
    177  
    178     return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 
     213     
    179214 
    180215  } 
     
    183218  { 
    184219    *flag = false; 
    185     if(comm.is_ep) 
    186     { 
    187       *flag = comm.is_intercomm; 
     220    if(comm->is_ep) 
     221    { 
     222      *flag = comm->is_intercomm; 
    188223      return 0; 
    189224    }  
    190     else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 
    191     { 
    192       ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
     225    else if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm)) 
     226    { 
     227      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 
    193228       
    194229      ::MPI_Comm_test_inter(mpi_comm, flag); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp

    r1368 r1520  
    1414    int ep_size, num_ep, mpi_size; 
    1515 
    16     ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 
    17     ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 
    18     mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 
    19     ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 
    20     num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 
    21     mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 
    22  
    23     std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm 
    24                                     //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 
     16    ep_rank     = local_comm->ep_comm_ptr->size_rank_info[0].first; 
     17    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 
     18    mpi_rank    = local_comm->ep_comm_ptr->size_rank_info[2].first; 
     19    ep_size     = local_comm->ep_comm_ptr->size_rank_info[0].second; 
     20    num_ep      = local_comm->ep_comm_ptr->size_rank_info[1].second; 
     21    mpi_size    = local_comm->ep_comm_ptr->size_rank_info[2].second; 
     22 
     23    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
     24    // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. // 
     25    //          local leaders bcast results to all ep in local_comm                                                 // 
     26    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
     27 
     28    bool is_local_leader = ep_rank==local_leader? true: false; 
     29 
     30 
     31     
     32    int local_leader_rank_in_peer; 
     33    int local_leader_rank_in_peer_mpi; 
     34    int local_leader_rank_in_world; 
     35 
     36    int remote_ep_size; 
     37    int remote_leader_rank_in_peer; 
     38    int remote_leader_rank_in_peer_mpi; 
     39    int remote_leader_rank_in_world; 
     40 
     41    int send_quadruple[4]; 
     42    int recv_quadruple[4]; 
     43 
     44 
     45    if(is_local_leader) 
     46    { 
     47      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer); 
     48      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi); 
     49      ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world); 
     50 
     51      send_quadruple[0] = ep_size; 
     52      send_quadruple[1] = local_leader_rank_in_peer; 
     53      send_quadruple[2] = local_leader_rank_in_peer_mpi; 
     54      send_quadruple[3] = local_leader_rank_in_world; 
     55 
     56      MPI_Request request; 
     57      MPI_Status status; 
     58 
     59 
     60      if(remote_leader > local_leader_rank_in_peer) 
     61      { 
     62        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     63        MPI_Wait(&request, &status); 
     64        
     65        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     66        MPI_Wait(&request, &status); 
     67      } 
     68      else 
     69      { 
     70        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     71        MPI_Wait(&request, &status); 
     72           
     73        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 
     74        MPI_Wait(&request, &status); 
     75      } 
     76 
     77      remote_ep_size                 = recv_quadruple[0]; 
     78      remote_leader_rank_in_peer     = recv_quadruple[1]; 
     79      remote_leader_rank_in_peer_mpi = recv_quadruple[2]; 
     80      remote_leader_rank_in_world    = recv_quadruple[3]; 
     81#ifdef _showinfo 
     82      printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer); 
     83#endif 
     84    } 
     85 
     86    MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm); 
     87    MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm); 
     88 
     89    if(!is_local_leader) 
     90    { 
     91      local_leader_rank_in_peer     = send_quadruple[1]; 
     92      local_leader_rank_in_peer_mpi = send_quadruple[2]; 
     93      local_leader_rank_in_world    = send_quadruple[3]; 
     94 
     95      remote_ep_size                 = recv_quadruple[0]; 
     96      remote_leader_rank_in_peer     = recv_quadruple[1]; 
     97      remote_leader_rank_in_peer_mpi = recv_quadruple[2]; 
     98      remote_leader_rank_in_world    = recv_quadruple[3]; 
     99    } 
     100 
     101 
     102#ifdef _showinfo 
     103    MPI_Barrier(peer_comm); 
     104    MPI_Barrier(peer_comm); 
     105    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); 
     106    MPI_Barrier(peer_comm); 
     107    MPI_Barrier(peer_comm);  
     108#endif 
     109 
     110    /////////////////////////////////////////////////////////////////// 
     111    // step 2 : gather ranks in world for both local and remote comm // 
     112    /////////////////////////////////////////////////////////////////// 
    25113 
    26114    int rank_in_world; 
    27     int rank_in_local_parent; 
    28  
    29     int rank_in_peer_mpi[2]; 
    30  
    31     int local_ep_size = ep_size; 
    32     int remote_ep_size; 
    33  
    34  
    35     ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 
    36  
    37      
    38     ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world); 
    39     ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent); 
    40      
    41  
    42     bool is_proc_master = false; 
    43     bool is_local_leader = false; 
    44     bool is_final_master = false; 
    45  
    46  
    47     if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 
    48     if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 
    49  
    50  
    51     int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm 
    52  
    53     int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader 
    54  
    55  
    56     std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm 
    57  
    58     std::vector<int> new_rank_info[4]; 
    59     std::vector<int> new_ep_info[2]; 
    60  
    61     std::vector<int> offset; 
    62  
    63     if(is_proc_master) 
    64     { 
    65  
    66       size_info[0] = mpi_size; 
    67  
    68       rank_info[0].resize(size_info[0]); 
    69       rank_info[1].resize(size_info[0]); 
    70  
    71  
    72  
    73       ep_info[0].resize(size_info[0]); 
    74  
    75       vector<int> send_buf(6); 
    76       vector<int> recv_buf(3*size_info[0]); 
    77  
    78       send_buf[0] = rank_in_world; 
    79       send_buf[1] = rank_in_local_parent; 
    80       send_buf[2] = num_ep; 
    81  
    82       ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm); 
    83  
    84       for(int i=0; i<size_info[0]; i++) 
    85       { 
    86         rank_info[0][i] = recv_buf[3*i]; 
    87         rank_info[1][i] = recv_buf[3*i+1]; 
    88         ep_info[0][i]   = recv_buf[3*i+2]; 
    89       } 
     115    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world); 
     116 
     117    int *ranks_in_world_local  = new int[ep_size]; 
     118    int *ranks_in_world_remote = new int[remote_ep_size]; 
     119 
     120    MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm); 
     121 
     122    if(is_local_leader) 
     123    { 
     124      MPI_Request request; 
     125      MPI_Status status; 
     126 
     127      if(remote_leader > local_leader_rank_in_peer) 
     128      { 
     129        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     130        MPI_Wait(&request, &status); 
     131        
     132        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     133        MPI_Wait(&request, &status); 
     134      } 
     135      else 
     136      { 
     137        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     138        MPI_Wait(&request, &status); 
     139           
     140        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     141        MPI_Wait(&request, &status); 
     142      } 
     143#ifdef _showinfo 
     144      printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer); 
     145#endif 
     146    } 
     147 
     148    MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm); 
     149 
     150#ifdef _showinfo 
     151 
     152    MPI_Barrier(peer_comm); 
     153    MPI_Barrier(peer_comm); 
     154 
     155    if(remote_leader == 4) 
     156    { 
     157      for(int i=0; i<ep_size; i++) 
     158      { 
     159        if(ep_rank == i) 
     160        { 
     161          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 
     162          for(int i=0; i<ep_size; i++) 
     163          { 
     164            printf("%d\t", ranks_in_world_local[i]); 
     165          } 
     166     
     167          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 
     168          for(int i=0; i<remote_ep_size; i++) 
     169          { 
     170            printf("%d\t", ranks_in_world_remote[i]); 
     171          } 
     172          printf("\n"); 
     173          
     174        } 
     175         
     176        MPI_Barrier(local_comm); 
     177        MPI_Barrier(local_comm); 
     178        MPI_Barrier(local_comm); 
     179      } 
     180    } 
     181 
     182    MPI_Barrier(peer_comm); 
     183    MPI_Barrier(peer_comm); 
     184    MPI_Barrier(peer_comm); 
     185     
     186    if(remote_leader == 13) 
     187    { 
     188      for(int i=0; i<ep_size; i++) 
     189      { 
     190        if(ep_rank == i) 
     191        { 
     192          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 
     193          for(int i=0; i<ep_size; i++) 
     194          { 
     195            printf("%d\t", ranks_in_world_local[i]); 
     196          } 
     197     
     198          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 
     199          for(int i=0; i<remote_ep_size; i++) 
     200          { 
     201            printf("%d\t", ranks_in_world_remote[i]); 
     202          } 
     203          printf("\n"); 
     204          
     205        } 
     206         
     207        MPI_Barrier(local_comm); 
     208        MPI_Barrier(local_comm); 
     209        MPI_Barrier(local_comm); 
     210      } 
     211    } 
     212 
     213    MPI_Barrier(peer_comm); 
     214    MPI_Barrier(peer_comm); 
     215 
     216#endif 
     217 
     218    ////////////////////////////////////////////////////////////// 
     219    // step 3 : determine the priority and ownership of each ep // 
     220    ////////////////////////////////////////////////////////////// 
     221 
     222    bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false; 
     223 
     224 
     225    int ownership; 
     226 
     227    if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1; 
     228    else if(rank_in_world == remote_leader_rank_in_world)   ownership = 0; 
     229    else 
     230    { 
     231      ownership = 1; 
     232      for(int i=0; i<remote_ep_size; i++) 
     233      { 
     234        if(rank_in_world == ranks_in_world_remote[i]) 
     235        { 
     236          ownership = priority? 1 : 0; 
     237          break; 
     238        }   
     239      } 
     240    } 
     241 
     242#ifdef _showinfo 
     243    MPI_Barrier(peer_comm); 
     244    MPI_Barrier(peer_comm); 
     245    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); 
     246    MPI_Barrier(peer_comm); 
     247    MPI_Barrier(peer_comm); 
     248#endif 
     249 
     250     
     251#ifdef _showinfo 
     252    MPI_Barrier(peer_comm); 
     253    MPI_Barrier(peer_comm); 
     254    printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership); 
     255    MPI_Barrier(peer_comm); 
     256    MPI_Barrier(peer_comm); 
     257#endif 
     258 
     259    ////////////////////////////////////////////////////// 
     260    // step 4 : extract local_comm and create intercomm // 
     261    ////////////////////////////////////////////////////// 
     262 
     263    bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world); 
     264 
     265#ifdef _showinfo 
     266 
     267    MPI_Barrier(peer_comm); 
     268    MPI_Barrier(peer_comm); 
     269    printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved); 
     270    MPI_Barrier(peer_comm); 
     271    MPI_Barrier(peer_comm); 
     272 
     273#endif 
     274 
     275    if(is_involved) 
     276    { 
     277      ::MPI_Group local_group; 
     278      ::MPI_Group extracted_group; 
     279      ::MPI_Comm *extracted_comm = new ::MPI_Comm; 
     280 
     281 
     282      ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group); 
     283 
     284      int *ownership_list = new int[mpi_size]; 
     285      int *mpi_rank_list = new int[mpi_size]; 
     286 
     287      ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 
     288      ::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)); 
     289 
     290       
     291      int n=0; 
     292      for(int i=0; i<mpi_size; i++) 
     293      {  
     294        n+=ownership_list[i]; 
     295      } 
     296 
     297      int *new_mpi_rank_list = new int[n]; 
     298      int j=0; 
     299      for(int i=0; i<mpi_size; i++) 
     300      {  
     301        if(ownership_list[i] !=0) 
     302        { 
     303          new_mpi_rank_list[j++] = mpi_rank_list[i]; 
     304        } 
     305      } 
     306 
     307 
     308      ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group); 
     309 
     310      ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, extracted_comm); 
     311 
     312      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm; 
     313 
     314      int local_leader_rank_in_extracted_comm; 
    90315 
    91316      if(is_local_leader) 
    92317      { 
    93         leader_info[0] = rank_in_world; 
    94         leader_info[1] = remote_leader; 
    95  
    96         ::MPI_Comm_rank(to_mpi_comm(peer_comm.mpi_comm), &rank_in_peer_mpi[0]); 
    97  
    98         send_buf[0] = size_info[0]; 
    99         send_buf[1] = local_ep_size; 
    100         send_buf[2] = rank_in_peer_mpi[0]; 
    101  
    102          
    103          
    104         MPI_Request requests[2]; 
    105         MPI_Status statuses[2]; 
    106          
    107         MPI_Isend(send_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[0]); 
    108         MPI_Irecv(recv_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[1]); 
    109  
    110  
    111         MPI_Waitall(2, requests, statuses); 
    112          
    113         size_info[1] = recv_buf[0]; 
    114         remote_ep_size = recv_buf[1]; 
    115         rank_in_peer_mpi[1] = recv_buf[2]; 
    116  
    117       } 
    118  
    119  
    120  
    121       send_buf[0] = size_info[1]; 
    122       send_buf[1] = leader_info[0]; 
    123       send_buf[2] = leader_info[1]; 
    124       send_buf[3] = rank_in_peer_mpi[0]; 
    125       send_buf[4] = rank_in_peer_mpi[1]; 
    126  
    127       ::MPI_Bcast(send_buf.data(), 5, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 
    128  
    129       size_info[1] = send_buf[0]; 
    130       leader_info[0] = send_buf[1]; 
    131       leader_info[1] = send_buf[2]; 
    132       rank_in_peer_mpi[0] = send_buf[3]; 
    133       rank_in_peer_mpi[1] = send_buf[4]; 
    134  
    135  
    136       rank_info[2].resize(size_info[1]); 
    137       rank_info[3].resize(size_info[1]); 
    138  
    139       ep_info[1].resize(size_info[1]); 
    140  
    141       send_buf.resize(3*size_info[0]); 
    142       recv_buf.resize(3*size_info[1]); 
    143  
    144       if(is_local_leader) 
    145       { 
    146         MPI_Request requests[2]; 
    147         MPI_Status statuses[2]; 
    148  
    149         std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() ); 
    150         std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] ); 
    151         std::copy ( ep_info[0].data(),   ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[0] ); 
    152  
    153         MPI_Isend(send_buf.data(), 3*size_info[0], MPI_INT, remote_leader, tag+1, peer_comm, &requests[0]); 
    154         MPI_Irecv(recv_buf.data(), 3*size_info[1], MPI_INT, remote_leader, tag+1, peer_comm, &requests[1]); 
    155          
    156         MPI_Waitall(2, requests, statuses); 
    157       } 
    158  
    159       ::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); 
    160  
    161       std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 
    162       std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin()  ); 
    163       std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() ); 
    164  
    165  
    166       offset.resize(size_info[0]); 
    167  
    168       if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader 
    169       { 
    170  
    171         bool found = false; 
    172         int ep_local; 
    173         int ep_remote; 
    174         for(int i=0; i<size_info[0]; i++) 
     318        ::MPI_Comm_rank(*extracted_comm, &local_leader_rank_in_extracted_comm); 
     319      } 
     320 
     321      ::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)); 
     322 
     323 
     324      if(ownership) 
     325        ::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); 
     326 
     327      //////////////////////////////////// 
     328      // step 5 :: determine new num_ep // 
     329      //////////////////////////////////// 
     330 
     331      int num_ep_count=0; 
     332 
     333      for(int i=0; i<ep_size; i++) 
     334      { 
     335        if(rank_in_world == ranks_in_world_local[i]) 
     336          num_ep_count++; 
     337      } 
     338       
     339      for(int i=0; i<remote_ep_size; i++) 
     340      { 
     341        if(rank_in_world == ranks_in_world_remote[i]) 
     342          num_ep_count++; 
     343      } 
     344 
     345 
     346      /////////////////////////////////////////////////// 
     347      // step 6 : create endpoints from extracted_comm // 
     348      /////////////////////////////////////////////////// 
     349 
     350      if(ownership) 
     351      { 
     352        MPI_Comm *ep_comm; 
     353        MPI_Info info; 
     354        MPI_Comm_create_endpoints(extracted_comm, num_ep_count, info, ep_comm); 
     355       
     356#ifdef _showinfo 
     357        printf("new ep_comm->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", mpi_inter_comm); 
     358#endif 
     359 
     360        for(int i=0; i<num_ep_count; i++) 
    175361        { 
    176           int target = rank_info[0][i]; 
    177           found = false; 
    178           for(int j=0; j<size_info[1]; j++) 
     362          ep_comm[i]->is_intercomm = true; 
     363          ep_comm[i]->ep_comm_ptr->comm_label = ranks_in_world_local[local_leader]; 
     364          ep_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
     365#ifdef _showinfo 
     366          printf("new ep_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, ep_comm[i]->ep_comm_ptr->intercomm); 
     367#endif 
     368          ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm; 
     369           
     370        } 
     371 
     372 
     373        #pragma omp critical (write_to_tag_list)       
     374        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)))); 
     375        #pragma omp flush 
     376#ifdef _showinfo 
     377        for(int i=0; i<num_ep_count; i++) 
     378          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); 
     379#endif 
     380      } 
     381 
     382 
     383      delete ownership_list; 
     384      delete mpi_rank_list; 
     385      delete new_mpi_rank_list; 
     386 
     387    } 
     388 
     389    int repeated=0; 
     390    for(int i=0; i<remote_ep_size; i++) 
     391    { 
     392      if(rank_in_world == ranks_in_world_remote[i]) 
     393        repeated++; 
     394    } 
     395 
     396    int my_turn = ownership? ep_rank_loc : ep_rank_loc+repeated; 
     397 
     398#ifdef _showinfo 
     399 
     400    MPI_Barrier(peer_comm); 
     401    MPI_Barrier(peer_comm); 
     402    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); 
     403    MPI_Barrier(peer_comm); 
     404    MPI_Barrier(peer_comm); 
     405 
     406#endif 
     407 
     408 
     409    #pragma omp flush 
     410    #pragma omp critical (read_from_intercomm_list) 
     411    { 
     412      bool flag=true; 
     413      while(flag) 
     414      { 
     415        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++) 
     416        { 
     417          if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world))) 
    179418          { 
    180             if(target == rank_info[2][j]) 
    181             { 
    182               found = true; 
    183               ep_local = ep_info[0][j]; 
    184               ep_remote = ep_info[1][j]; 
    185               break; 
    186             } 
    187           } 
    188           if(found) 
    189           { 
    190  
    191             if(target == leader_info[0]) // the leader is doubled in remote 
    192             { 
    193               new_rank_info[0].push_back(target); 
    194               new_rank_info[1].push_back(rank_info[1][i]); 
    195  
    196               new_ep_info[0].push_back(ep_local + ep_remote); 
    197               offset[i] = 0; 
    198             } 
    199             else 
    200             { 
    201               offset[i] = ep_local; 
    202             } 
    203           } 
    204           else 
    205           { 
    206             new_rank_info[0].push_back(target); 
    207             new_rank_info[1].push_back(rank_info[1][i]); 
    208  
    209             new_ep_info[0].push_back(ep_info[0][i]); 
    210  
    211             offset[i] = 0; 
    212           } 
    213  
    214         } 
    215       } 
    216  
    217       else // erase rank doubled with remote leader 
    218       { 
    219  
    220         bool found = false; 
    221         int ep_local; 
    222         int ep_remote; 
    223         for(int i=0; i<size_info[0]; i++) 
    224         { 
    225           int target = rank_info[0][i]; 
    226           found = false; 
    227           for(int j=0; j<size_info[1]; j++) 
    228           { 
    229  
    230             if(target == rank_info[2][j]) 
    231             { 
    232               found = true; 
    233               ep_local = ep_info[0][j]; 
    234               ep_remote = ep_info[1][j]; 
    235               break; 
    236             } 
    237           } 
    238           if(found) 
    239           { 
    240             if(target != leader_info[1]) 
    241             { 
    242               new_rank_info[0].push_back(target); 
    243               new_rank_info[1].push_back(rank_info[1][i]); 
    244  
    245               new_ep_info[0].push_back(ep_local + ep_remote); 
    246               offset[i] = 0; 
    247             } 
    248             else // found remote leader 
    249             { 
    250               offset[i] = ep_remote; 
    251             } 
    252           } 
    253           else 
    254           { 
    255             new_rank_info[0].push_back(target); 
    256             new_rank_info[1].push_back(rank_info[1][i]); 
    257  
    258             new_ep_info[0].push_back(ep_info[0][i]); 
    259             offset[i] = 0; 
     419            *newintercomm = iter->second.first[my_turn]; 
     420             
     421            iter->second.second.second++; 
     422             
     423            if(iter->second.second.first == iter->second.second.second) 
     424              intercomm_list.erase(iter); 
     425 
     426            flag = false; 
     427            break;  
    260428          } 
    261429        } 
    262430      } 
    263  
    264       if(offset[mpi_rank] == 0) 
    265       { 
    266         is_final_master = true; 
    267       } 
    268  
    269  
    270       //! size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote 
    271  
    272       if(is_local_leader) 
    273       { 
    274         size_info[2] = new_ep_info[0].size(); 
    275         MPI_Request requests[2]; 
    276         MPI_Status statuses[2]; 
    277         MPI_Isend(&size_info[2], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[0]); 
    278         MPI_Irecv(&size_info[3], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[1]); 
    279           
    280         MPI_Waitall(2, requests, statuses); 
    281       } 
    282  
    283       ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 
    284  
    285       new_rank_info[2].resize(size_info[3]); 
    286       new_rank_info[3].resize(size_info[3]); 
    287       new_ep_info[1].resize(size_info[3]); 
    288  
    289       send_buf.resize(size_info[2]); 
    290       recv_buf.resize(size_info[3]); 
    291  
    292       if(is_local_leader) 
    293       { 
    294         MPI_Request requests[2]; 
    295         MPI_Status statuses[2]; 
    296  
    297         std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() ); 
    298         std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] ); 
    299         std::copy ( new_ep_info[0].data(),   new_ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[2] ); 
    300  
    301         MPI_Isend(send_buf.data(), 3*size_info[2], MPI_INT, remote_leader, tag+3, peer_comm, &requests[0]); 
    302         MPI_Irecv(recv_buf.data(), 3*size_info[3], MPI_INT, remote_leader, tag+3, peer_comm, &requests[1]); 
    303          
    304         MPI_Waitall(2, requests, statuses); 
    305       } 
    306  
    307       ::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); 
    308  
    309       std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 
    310       std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin()  ); 
    311       std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() ); 
    312  
    313     } 
    314  
    315      
    316  
    317     if(is_proc_master) 
    318     { 
    319       //! leader_info[4]: 2-> rank of local leader in new_group generated comm; 
    320                       // 3-> rank of remote leader in new_group generated comm; 
    321       ::MPI_Group local_group; 
    322       ::MPI_Group new_group; 
    323       ::MPI_Comm *new_comm = new ::MPI_Comm; 
    324       ::MPI_Comm *intercomm = new ::MPI_Comm; 
    325  
    326       ::MPI_Comm_group(local_mpi_comm, &local_group); 
    327  
    328       ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 
    329  
    330       ::MPI_Comm_create(local_mpi_comm, new_group, new_comm); 
    331  
    332  
    333  
    334       if(is_local_leader) 
    335       { 
    336         ::MPI_Comm_rank(*new_comm, &leader_info[2]); 
    337       } 
    338  
    339       ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 
    340  
    341       if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 
    342       { 
    343  
    344         ::MPI_Barrier(*new_comm); 
    345  
    346         ::MPI_Intercomm_create(*new_comm, leader_info[2], to_mpi_comm(peer_comm.mpi_comm), rank_in_peer_mpi[1], tag, intercomm); 
    347  
    348         int id; 
    349  
    350         ::MPI_Comm_rank(*new_comm, &id); 
    351         int my_num_ep = new_ep_info[0][id]; 
    352  
    353         MPI_Comm *ep_intercomm; 
    354         MPI_Info info; 
    355         MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 
    356  
    357  
    358         for(int i= 0; i<my_num_ep; i++) 
     431    } 
     432 
     433#ifdef _showinfo 
     434 
     435    MPI_Barrier(peer_comm); 
     436    MPI_Barrier(peer_comm); 
     437    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); 
     438    MPI_Barrier(peer_comm); 
     439    MPI_Barrier(peer_comm); 
     440 
     441#endif 
     442 
     443    ////////////////////////////////////////////////////////// 
     444    // step 7 : create intercomm_rank_map for local leaders // 
     445    ////////////////////////////////////////////////////////// 
     446     
     447    int my_quadruple[4]; 
     448 
     449    my_quadruple[0] = ep_rank; 
     450    my_quadruple[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 
     451    my_quadruple[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first; 
     452    my_quadruple[3] = (*newintercomm)->ep_comm_ptr->comm_label; 
     453 
     454 
     455#ifdef _showinfo 
     456 
     457    MPI_Barrier(peer_comm); 
     458    MPI_Barrier(peer_comm); 
     459    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]); 
     460    MPI_Barrier(peer_comm); 
     461    MPI_Barrier(peer_comm); 
     462#endif 
     463 
     464    int *local_quadruple_list; 
     465    int *remote_quadruple_list; 
     466    if(is_involved) 
     467    { 
     468      local_quadruple_list = new int[4*ep_size]; 
     469      remote_quadruple_list = new int[4*remote_ep_size]; 
     470 
     471    } 
     472 
     473    MPI_Gather(my_quadruple, 4, MPI_INT, local_quadruple_list, 4, MPI_INT, local_leader, local_comm); 
     474 
     475 
     476    if(is_local_leader) 
     477    { 
     478      MPI_Request request; 
     479      MPI_Status status; 
     480 
     481      if(remote_leader > local_leader_rank_in_peer) 
     482      { 
     483        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     484        MPI_Wait(&request, &status);         
     485 
     486        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     487        MPI_Wait(&request, &status); 
     488      } 
     489      else 
     490      { 
     491        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     492        MPI_Wait(&request, &status); 
     493           
     494        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 
     495        MPI_Wait(&request, &status);        
     496      } 
     497#ifdef _showinfo 
     498      printf("peer_rank = %d, quadruple_list exchange OK\n", local_leader_rank_in_peer); 
     499#endif 
     500    } 
     501 
     502    if(is_involved) 
     503    { 
     504      ::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)); 
     505      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP; 
     506#ifdef _showinfo 
     507      printf("new intercomm_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map); 
     508#endif 
     509      for(int i=0; i<remote_ep_size; i++) 
     510      { 
     511        (*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])); 
     512      } 
     513    } 
     514 
     515    //////////////////////////////////////////////////////// 
     516    // step 8 : associate intercomm_rank_map to endpoints // 
     517    //////////////////////////////////////////////////////// 
     518 
     519    int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 
     520 
     521    MPI_Allgather_local(&local_leader_rank_in_world, 1, MPI_INT, leader_rank_in_world_local_gathered, *newintercomm); 
     522 
     523 
     524    int new_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 
     525    int *new_rank_loc_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 
     526 
     527    MPI_Allgather_local(&new_rank_loc, 1, MPI_INT, new_rank_loc_local_gathered, *newintercomm); 
     528 
     529    //printf("peer_rank = %d, leader_rank_in_world_local_gathered = %d %d %d %d, new_rank_loc_local_gathered = %d %d %d %d\n",  
     530    //  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], 
     531    //  new_rank_loc_local_gathered[0], new_rank_loc_local_gathered[1], new_rank_loc_local_gathered[2], new_rank_loc_local_gathered[3]); 
     532 
     533    if(is_involved) 
     534    { 
     535 
     536      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP; 
     537#ifdef _showinfo 
     538      printf("new local_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map); 
     539#endif 
     540 
     541      for(std::map<int, std::pair<int, int> >::iterator it = local_comm->ep_rank_map->begin(); it != local_comm->ep_rank_map->end(); it++) 
     542      { 
     543        (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->insert(std::pair<int, std::pair< int, int > >(it->first, it->second.first, it->second.second)); 
     544      } 
     545    } 
     546 
     547    MPI_Barrier_local(*newintercomm); 
     548 
     549     
     550    if(!is_involved) 
     551    { 
     552      int target; 
     553      for(int i=0; i<(*newintercomm)->ep_comm_ptr->size_rank_info[1].second; i++) 
     554      { 
     555        if(local_leader_rank_in_world == leader_rank_in_world_local_gathered[i]) 
    359556        { 
    360           ep_intercomm[i].is_intercomm = true; 
    361  
    362           ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
    363           ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 
    364           ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 
    365         } 
    366  
    367  
    368         #pragma omp critical (write_to_tag_list) 
    369         tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 
    370         //printf("tag_list size = %lu\n", tag_list.size()); 
    371       } 
    372     } 
    373  
    374     vector<int> bcast_buf(8); 
    375     if(is_local_leader) 
    376     { 
    377       std::copy(size_info, size_info+4, bcast_buf.begin()); 
    378       std::copy(leader_info, leader_info+4, bcast_buf.begin()+4); 
    379     } 
    380  
    381     MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm); 
    382  
    383     if(!is_local_leader) 
    384     { 
    385       std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info); 
    386       std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 
    387     } 
    388  
    389     if(!is_local_leader) 
    390     { 
    391       new_rank_info[1].resize(size_info[2]); 
    392       ep_info[1].resize(size_info[1]); 
    393       offset.resize(size_info[0]); 
    394     } 
    395  
    396     bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1); 
    397  
    398     if(is_local_leader) 
    399     { 
    400       bcast_buf[0] = remote_ep_size; 
    401       std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1); 
    402       std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1); 
    403       std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1); 
    404     } 
    405  
    406     MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm); 
    407  
    408     if(!is_local_leader) 
    409     { 
    410       remote_ep_size = bcast_buf[0]; 
    411       std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin()); 
    412       std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin()); 
    413       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()); 
    414     } 
    415  
    416     int my_position = offset[rank_in_local_parent]+ep_rank_loc; 
    417      
    418     MPI_Barrier_local(local_comm); 
    419     #pragma omp flush 
    420  
    421  
    422     #pragma omp critical (read_from_tag_list) 
    423     { 
    424       bool found = false; 
    425       while(!found) 
    426       { 
    427         for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 
    428         { 
    429           if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 
    430           { 
    431             *newintercomm = iter->second[my_position]; 
    432             found = true; 
    433             break; 
    434           } 
    435         } 
    436       } 
    437     } 
    438  
    439     MPI_Barrier(local_comm); 
    440  
    441     if(is_local_leader) 
    442     { 
    443       int local_flag = true; 
    444       int remote_flag = false; 
    445       MPI_Request mpi_requests[2]; 
    446       MPI_Status mpi_statuses[2]; 
    447        
    448       MPI_Isend(&local_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[0]); 
    449       MPI_Irecv(&remote_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[1]); 
    450        
    451       MPI_Waitall(2, mpi_requests, mpi_statuses); 
    452     } 
    453  
    454  
    455     MPI_Barrier(local_comm); 
    456  
    457     if(is_proc_master) 
    458     { 
    459       for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 
    460       { 
    461         if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 
    462         { 
    463           tag_list.erase(iter); 
     557          target = i; 
     558          (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = target; 
    464559          break; 
    465560        } 
    466561      } 
    467     } 
    468  
    469     int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 
    470     int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 
    471  
    472     intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 
    473     intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 
    474     intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 
    475     intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 
    476     intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 
    477     intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 
    478  
    479     MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 
    480  
    481     int my_rank_map_elem[2]; 
    482  
    483     my_rank_map_elem[0] = intercomm_ep_rank; 
    484     my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 
    485  
    486     vector<pair<int, int> > local_rank_map_array; 
    487     vector<pair<int, int> > remote_rank_map_array; 
    488  
    489  
    490     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 
    491     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 
    492  
    493     MPI_Allgather(my_rank_map_elem, 2, MPI_INT,  
    494       (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 
    495  
    496     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 
    497     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 
    498  
    499     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 
    500     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 
    501     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 
    502  
    503     int local_intercomm_size = intercomm_ep_size; 
    504     int remote_intercomm_size; 
    505  
    506     int new_bcast_root_0 = 0; 
    507     int new_bcast_root = 0; 
    508  
    509  
    510     if(is_local_leader) 
    511     { 
    512       MPI_Request requests[4]; 
    513       MPI_Status statuses[4]; 
    514        
    515       MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[0]); 
    516       MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[1]); 
    517  
    518       MPI_Isend(&local_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[2]); 
    519       MPI_Irecv(&remote_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[3]); 
    520        
    521       MPI_Waitall(4, requests, statuses); 
    522  
    523       new_bcast_root_0 = intercomm_ep_rank; 
    524     } 
    525  
    526     MPI_Allreduce(&new_bcast_root_0, &new_bcast_root, 1, MPI_INT, MPI_SUM, *newintercomm); 
    527  
    528  
    529     MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 
    530     MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, new_bcast_root, *newintercomm); 
    531  
    532  
    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); 
    535  
    536  
    537  
    538  
    539     if(is_local_leader) 
    540     { 
    541       MPI_Request requests[2]; 
    542       MPI_Status statuses[2]; 
    543        
    544       MPI_Isend((*newintercomm).rank_map->data(), 2*local_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[0]); 
    545       MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[1]); 
    546        
    547       MPI_Waitall(2, requests, statuses); 
    548     } 
    549  
    550     MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, new_bcast_root, *newintercomm); 
    551  
    552     (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 
    553     (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = tag; 
     562      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map; 
     563      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map     = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map; 
     564    } 
     565    else 
     566    { 
     567      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = -1; 
     568    } 
     569 
     570    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = (*newintercomm)->ep_comm_ptr->size_rank_info[0]; 
     571    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1]; 
     572    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2]; 
     573 
     574 
     575    (*newintercomm)->ep_comm_ptr->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0]; 
     576    (*newintercomm)->ep_comm_ptr->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1]; 
     577    (*newintercomm)->ep_comm_ptr->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2]; 
     578 
     579 
     580#ifdef _showinfo 
     581    MPI_Barrier(peer_comm); 
     582    MPI_Barrier(peer_comm); 
     583 
     584    printf("peer_rank = %d, size_rank_info = %d %d %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first,  
     585      (*newintercomm)->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].second, 
     586      (*newintercomm)->ep_comm_ptr->size_rank_info[1].first, (*newintercomm)->ep_comm_ptr->size_rank_info[1].second, 
     587      (*newintercomm)->ep_comm_ptr->size_rank_info[2].first, (*newintercomm)->ep_comm_ptr->size_rank_info[2].second); 
     588     
     589    MPI_Barrier(peer_comm); 
     590    MPI_Barrier(peer_comm); 
     591 
     592#endif 
    554593 
    555594/* 
    556     for(int i=0; i<local_ep_size; i++) 
    557     if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, local_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 
    558           (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->at(i).second); 
    559  
    560     for(int i=0; i<remote_ep_size; i++) 
    561     if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, remote_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 
    562           (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->at(i).second); 
    563  
    564     for(int i=0; i<remote_intercomm_size; i++) 
    565     if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, intercomm_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 
    566           (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->at(i).second); 
     595    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 
     596    { 
     597      int receiver = rand()%10; 
     598      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,  
     599        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 
     600    } 
     601 
     602    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 9) 
     603    { 
     604      int receiver = rand()%6; 
     605      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,  
     606        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 
     607    } 
     608 
     609 
     610    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 
     611    { 
     612      for(int i=0; i<ep_size; i++) 
     613      { 
     614        printf("rank_map->at(%d) = %d, %d\n", i, (*newintercomm)->ep_rank_map->at(i).first, (*newintercomm)->ep_rank_map->at(i).second); 
     615      } 
     616    } 
    567617*/ 
    568  
    569 //    for(int i=0; i<(*newintercomm).rank_map->size(); i++) 
    570 //    if(local_comm.ep_comm_ptr->comm_label != 99) printf("ep_rank = %d, rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 
    571 //          (*newintercomm).rank_map->at(i).first, (*newintercomm).rank_map->at(i).second); 
    572  
    573 //    MPI_Comm *test_comm = newintercomm->ep_comm_ptr->intercomm->local_comm; 
    574 //    int test_rank; 
    575 //    MPI_Comm_rank(*test_comm, &test_rank); 
    576 //    printf("=================test_rank = %d\n", test_rank); 
    577      
    578      
    579  
    580     return MPI_SUCCESS; 
     618    ////////////// 
     619    // clean up // 
     620    ////////////// 
     621 
     622    delete ranks_in_world_local; 
     623    delete ranks_in_world_remote; 
     624 
     625    if(is_involved) 
     626    { 
     627      delete local_quadruple_list; 
     628      delete remote_quadruple_list; 
     629    } 
     630 
     631    delete leader_rank_in_world_local_gathered; 
     632    delete new_rank_loc_local_gathered; 
     633 
    581634 
    582635  } 
     
    584637 
    585638 
    586  
    587   int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm) 
    588   { 
    589     //! mpi_size of local comm = 1 
    590     //! same world rank of leaders 
    591  
    592     int ep_rank, ep_rank_loc, mpi_rank; 
    593     int ep_size, num_ep, mpi_size; 
    594  
    595     ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 
    596     ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 
    597     mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 
    598     ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 
    599     num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 
    600     mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 
    601  
    602  
    603  
    604     std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm 
    605                                     //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 
    606  
    607     int rank_in_world; 
    608  
    609     int rank_in_peer_mpi[2]; 
    610  
    611     ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world); 
    612  
    613  
    614     int local_num_ep = num_ep; 
    615     int remote_num_ep; 
    616     int total_num_ep; 
    617  
    618     int leader_rank_in_peer[2]; 
    619  
    620     int my_position; 
    621     int tag_label[2]; 
    622  
    623     vector<int> send_buf(4); 
    624     vector<int> recv_buf(4); 
    625  
    626  
    627     if(ep_rank == local_leader) 
    628     { 
    629       MPI_Status status; 
    630  
    631  
    632  
    633       MPI_Comm_rank(peer_comm, &leader_rank_in_peer[0]); 
    634  
    635       send_buf[0] = local_num_ep; 
    636       send_buf[1] = leader_rank_in_peer[0]; 
    637  
    638       MPI_Request req_s, req_r; 
    639  
    640       MPI_Isend(send_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_s); 
    641       MPI_Irecv(recv_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_r); 
    642  
    643  
    644       MPI_Wait(&req_s, &status); 
    645       MPI_Wait(&req_r, &status); 
    646  
    647       recv_buf[2] = leader_rank_in_peer[0]; 
    648  
    649     } 
    650  
    651     MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm); 
    652  
    653     remote_num_ep = recv_buf[0]; 
    654     leader_rank_in_peer[1] = recv_buf[1]; 
    655     leader_rank_in_peer[0] = recv_buf[2]; 
    656  
    657     total_num_ep = local_num_ep + remote_num_ep; 
    658  
    659  
    660     if(leader_rank_in_peer[0] < leader_rank_in_peer[1]) 
    661     { 
    662       my_position = ep_rank_loc; 
    663       //! LEADER create EP 
    664       if(ep_rank == local_leader) 
    665       { 
    666         ::MPI_Comm *mpi_dup = new ::MPI_Comm; 
    667          
    668         ::MPI_Comm_dup(to_mpi_comm(local_comm.mpi_comm), mpi_dup); 
    669  
    670         MPI_Comm *ep_intercomm; 
    671         MPI_Info info; 
    672         MPI_Comm_create_endpoints(mpi_dup, total_num_ep, info, ep_intercomm); 
    673  
    674  
    675         for(int i=0; i<total_num_ep; i++) 
    676         { 
    677           ep_intercomm[i].is_intercomm = true; 
    678           ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 
    679           ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = 0; 
    680  
    681           ep_intercomm[i].ep_comm_ptr->comm_label = leader_rank_in_peer[0]; 
    682         } 
    683  
    684         tag_label[0] = TAG++; 
    685         tag_label[1] = rank_in_world; 
    686  
    687         #pragma omp critical (write_to_tag_list) 
    688         tag_list.push_back(make_pair( make_pair(tag_label[0], tag_label[1]) , ep_intercomm)); 
    689  
    690         MPI_Request req_s; 
    691         MPI_Status sta_s; 
    692         MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s); 
    693  
    694         MPI_Wait(&req_s, &sta_s); 
    695  
    696       } 
    697     } 
    698     else 
    699     { 
    700       //! Wait for EP creation 
    701       my_position = remote_num_ep + ep_rank_loc; 
    702       if(ep_rank == local_leader) 
    703       { 
    704         MPI_Status status; 
    705         MPI_Request req_r; 
    706         MPI_Irecv(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_r); 
    707         MPI_Wait(&req_r, &status); 
    708       } 
    709     } 
    710  
    711     MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm); 
    712  
    713  
    714  
    715  
    716     #pragma omp critical (read_from_tag_list) 
    717     { 
    718       bool found = false; 
    719       while(!found) 
    720       { 
    721         for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 
    722         { 
    723           if((*iter).first == make_pair(tag_label[0], tag_label[1])) 
    724           { 
    725             *newintercomm =  iter->second[my_position]; 
    726             found = true; 
    727             // tag_list.erase(iter); 
    728             break; 
    729           } 
    730         } 
    731       } 
    732     } 
    733  
    734     MPI_Barrier_local(local_comm); 
    735  
    736     if(leader_rank_in_peer[0] < leader_rank_in_peer[1]) 
    737     { 
    738       for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 
    739         { 
    740           if((*iter).first == make_pair(tag_label[0], tag_label[1])) 
    741           { 
    742             tag_list.erase(iter); 
    743             break; 
    744           } 
    745         } 
    746     } 
    747  
    748  
    749  
    750     int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 
    751     int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 
    752  
    753     intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 
    754     intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 
    755     intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 
    756     intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 
    757     intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 
    758     intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 
    759  
    760  
    761  
    762     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map  = new RANK_MAP; 
    763     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 
    764     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_num_ep); 
    765     (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_num_ep); 
    766  
    767     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 
    768     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 
    769     (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 
    770  
    771  
    772  
    773     int local_rank_map_ele[2]; 
    774     local_rank_map_ele[0] = intercomm_ep_rank; 
    775     local_rank_map_ele[1] = (*newintercomm).ep_comm_ptr->comm_label; 
    776  
    777     MPI_Allgather(local_rank_map_ele, 2, MPI_INT,  
    778       (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 
    779  
    780     if(ep_rank == local_leader) 
    781     { 
    782       MPI_Status status; 
    783       MPI_Request req_s, req_r; 
    784  
    785       MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_s); 
    786       MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_r); 
    787  
    788  
    789       MPI_Wait(&req_s, &status); 
    790       MPI_Wait(&req_r, &status); 
    791  
    792     } 
    793  
    794     MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, local_leader, local_comm); 
    795     (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 
    796     (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = tag; 
    797  
    798  
    799     return MPI_SUCCESS; 
    800   } 
    801  
    802  
     639   
    803640} 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp

    r1356 r1520  
    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->ep_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->ep_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->ep_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->ep_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->ep_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->ep_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 
     
    1040512    { 
    1041513      ::MPI_Status status; 
    1042  
    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; 
     514       
     515      std::vector<std::pair<int, std::pair<int, int> > > map2vec((*newintercomm)->ep_rank_map->size()); 
     516      std::vector<std::pair<int, std::pair<int, int> > > vec2map((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->size()); 
     517       
     518      int ii=0; 
     519      for(std::map<int, std::pair<int, int> >::iterator it = (*newintercomm)->ep_rank_map->begin(); it != (*newintercomm)->ep_rank_map->end(); it++) 
     520      { 
     521        map2vec[ii++] = make_pair(it->first, make_pair(it->second.first, it->second.second)); 
     522      } 
     523       
     524       
     525      ::MPI_Send(map2vec.data(), 3*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 
     526      ::MPI_Recv(vec2map.data(), 3*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 
     527       
     528      
     529      for(ii=0; ii<vec2map.size(); ii++) 
     530      { 
     531        //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second); 
     532      } 
     533    } 
     534 
     535    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm); 
     536 
     537    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]); 
     538    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = local_comm->ep_comm_ptr->comm_label; 
    1052539 
    1053540    return MPI_SUCCESS; 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp

    r1495 r1520  
    44#include <iostream> 
    55#include <fstream> 
     6#include "ep_mpi.hpp" 
    67 
    78using namespace std; 
     
    1415namespace ep_lib 
    1516{  
    16   bool MPI_Comm::is_null() 
    17   { 
    18     if(!this->is_intercomm) 
    19       return this->mpi_comm == MPI_COMM_NULL.mpi_comm; 
    20     else 
    21       return this->ep_comm_ptr->intercomm->mpi_inter_comm == MPI_COMM_NULL.mpi_comm; 
    22   } 
    2317 
    2418  int tag_combine(int real_tag, int src, int dest) 
     
    3327  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) 
    3428  { 
    35     for(int i=0; i<comm.rank_map->size(); i++) 
    36     { 
    37       if(   ( comm.rank_map->at(i).first  == ep_rank_loc ) 
    38          && ( comm.rank_map->at(i).second == mpi_rank ) ) 
    39       { 
    40         return i; 
    41       } 
    42     } 
    43     printf("rank not find\n"); 
     29    if(comm->is_intercomm) 
     30    { 
     31      for(std::map<int, std::pair< int, std::pair<int, int> > >::iterator it = comm->ep_comm_ptr->intercomm->intercomm_rank_map->begin(); it != comm->ep_comm_ptr->intercomm->intercomm_rank_map->end(); it++) 
     32      { 
     33        if(   ( it->second.first  == ep_rank_loc ) 
     34           && ( it->second.second.first == mpi_rank ) ) 
     35        { 
     36          return it->first; 
     37        } 
     38      } 
     39      printf("rank not find for EP_intercomm\n"); 
     40      int err; 
     41      return MPI_Abort(comm, err); 
     42    } 
     43     
     44    for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) 
     45    { 
     46      if(   ( it->second.first  == ep_rank_loc ) 
     47         && ( it->second.second == mpi_rank ) ) 
     48      { 
     49        return it->first; 
     50      } 
     51    } 
     52    printf("rank not find for EP_intracomm\n"); 
     53    int err; 
     54    return MPI_Abort(comm, err); 
    4455  } 
    4556   
    46   int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank) 
    47   { 
    48     // intercomm 
    49     int inter_rank; 
    50     for(int i=0; i<comm.ep_comm_ptr->intercomm->intercomm_rank_map->size(); i++) 
    51     { 
    52       if(   ( comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(i).first  == ep_rank_loc ) 
    53          && ( comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(i).second == mpi_rank ) ) 
    54       { 
    55         inter_rank =  i; 
    56         break; 
    57       } 
    58     } 
    59  
    60     for(int i=0; i<comm.ep_comm_ptr->intercomm->remote_rank_map->size(); i++) 
    61     { 
    62       if(  comm.ep_comm_ptr->intercomm->remote_rank_map->at(i).first  == inter_rank  ) 
    63       { 
    64         //printf("get_ep_rank for intercomm, ep_rank_loc = %d, mpi_rank = %d => ep_src = %d\n", ep_rank_loc, mpi_rank, i); 
    65         return i; 
    66       } 
    67     } 
    68  
    69     printf("rank not find\n"); 
    70      
    71   } 
    72  
    7357 
    7458  int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count) 
    7559  { 
    76  
    77     ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status); 
    78     ::MPI_Datatype *mpi_datatype = static_cast< ::MPI_Datatype*>(datatype); 
    79  
    80     ::MPI_Get_count(mpi_status, *mpi_datatype, count); 
     60    return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count); 
    8161  } 
    8262 
     
    8969  void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type) 
    9070  { 
     71 
    9172    int src_rank; 
    9273    int int_count; 
     
    121102  void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type) 
    122103  { 
     104 
    123105    int dest_rank; 
    124106    int int_count; 
     
    147129    } 
    148130    else printf("Unable to open file\n"); 
     131 
    149132 
    150133  } 
     
    251234{ 
    252235  return *(static_cast< MPI_Comm* >(comm)); 
     236}  
     237 
     238MPI_Comm* to_mpi_comm_ptr(void* comm) 
     239{ 
     240  return static_cast< MPI_Comm* >(comm); 
    253241 
    254242 
     
    258246} 
    259247 
    260 MPI_Info to_mpi_info(void* info) 
    261 { 
    262   return *(static_cast< MPI_Info* >(info)); 
    263 } 
    264  
    265  
    266  
    267  
    268  
     248MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message) 
     249{ 
     250  return static_cast< MPI_Message* >(message->mpi_message); 
     251} 
     252 
     253MPI_Info to_mpi_info(ep_lib::MPI_Info info) 
     254{ 
     255  return *(static_cast< MPI_Info* >(info->mpi_info)); 
     256} 
     257 
     258MPI_Win to_mpi_win(void* win) 
     259{ 
     260  return *(static_cast< MPI_Win* >(win)); 
     261} 
     262 
     263MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint) 
     264{ 
     265  return *(static_cast< MPI_Aint* >(aint.mpi_aint)); 
     266} 
     267 
     268MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status) 
     269{ 
     270  return static_cast< MPI_Status* >(status.mpi_status); 
     271} 
     272 
     273MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request) 
     274{ 
     275  return static_cast< MPI_Request* >(request->mpi_request); 
     276} 
     277 
     278 
     279 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp

    r1368 r1520  
    44#include "ep_type.hpp" 
    55#include "ep_lib_intercomm.hpp" 
     6#include "ep_lib_intracomm.hpp" 
    67#include "ep_lib_local.hpp" 
    78#include "ep_lib_collective.hpp" 
    89#include "ep_tag.hpp" 
    910#include "ep_lib_fortran.hpp" 
     11#include "ep_lib_win.hpp" 
     12#include "ep_lib_mpi.hpp" 
     13//#include "ep_mpi.hpp" 
     14 
    1015 
    1116namespace ep_lib 
     
    3338 
    3439  int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count); 
    35  
    36   // #ifdef _openmpi 
    37   // int MPI_Comm_create_endpoints(void* mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints 
    38   // #elif _intelmpi 
    39   // int MPI_Comm_create_endpoints(int mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints 
    40   // #endif 
    4140   
    42   int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints 
     41  int MPI_Comm_remote_size(MPI_Comm comm, int *size); 
    4342 
    4443  int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); 
     
    4746  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 
    4847 
    49   int tag_combine(int real_tag, int src, int dest); 
    50   int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank); 
    51   int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank); 
    52  
    53   int Message_Check(MPI_Comm comm); 
    54   int Request_Check(); 
    5548 
    5649  int MPI_Recv  (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status); 
     
    7467  int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr); 
    7568 
     69  int MPI_Comm_test_inter(MPI_Comm comm, int *flag); 
     70 
    7671 
    7772  void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type); 
     
    8176  bool valid_op(MPI_Op op); 
    8277 
     78  int tag_combine(int real_tag, int src, int dest); 
     79  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank); 
     80 
     81  int Message_Check(MPI_Comm comm); 
     82 
     83  int Request_Check(); 
     84 
     85  int test_sendrecv(MPI_Comm comm); 
     86 
     87 
    8388} 
    8489 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp

    r1368 r1520  
    1010 
    1111  int MPI_Barrier(MPI_Comm comm); 
     12   
    1213 
    1314  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm); 
     
    2627 
    2728  int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); 
     29   
    2830  int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); 
    2931 
     
    4143  int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); 
    4244 
     45  int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm); 
     46 
     47  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
     48 
     49  int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
     50   
     51   
     52  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); 
     53   
     54  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
     55 
     56  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints 
     57 
     58 
     59 
     60  int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 
     61 
     62  int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 
     63 
    4364} 
    4465 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp

    r1368 r1520  
    88  typedef void* MPI_Op; 
    99 
    10    
     10  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); 
     11  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); 
     12  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 
     13 
     14  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 
     15 
     16 
    1117  int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm); 
    1218 
     
    2228 
    2329  int MPI_Iprobe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status); 
    24   int MPI_Iprobe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Status *status); 
    2530  int MPI_Improbe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status); 
    26   int MPI_Improbe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status); 
    2731 
    28   int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm); 
    2932 
    30   int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
    3133 
    32   int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
    33    
    34   // #ifdef _intelmpi 
    35   // 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); 
    36   // #elif _openmpi 
    37   // 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); 
    38   // #endif 
    39  
    40   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); 
    41    
    42   int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 
    43  
    44   int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 
    45  
    46   int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 
    47  
    48   int MPI_Comm_remote_size(MPI_Comm comm, int *size); 
    49  
    50   int MPI_Comm_test_inter(MPI_Comm comm, int *flag); 
    51  
    52   int test_sendrecv(MPI_Comm comm); 
    5334 
    5435} 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_local.hpp

    r1368 r1520  
    1818   
    1919  int MPI_Gather_local      (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, int local_root, MPI_Comm comm); 
     20   
     21  int MPI_Allgather_local      (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm); 
    2022 
    2123  int MPI_Gatherv_local       (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp

    r1354 r1520  
    77 
    88 
    9 namespace ep_lib { 
     9namespace ep_lib  
     10{ 
    1011 
    1112  int MPI_Intercomm_merge_unique_leader(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm) 
     
    1819    int ep_size, num_ep, mpi_size; 
    1920 
    20     ep_rank = inter_comm.ep_comm_ptr->size_rank_info[0].first; 
    21     ep_rank_loc = inter_comm.ep_comm_ptr->size_rank_info[1].first; 
    22     mpi_rank = inter_comm.ep_comm_ptr->size_rank_info[2].first; 
    23     ep_size = inter_comm.ep_comm_ptr->size_rank_info[0].second; 
    24     num_ep = inter_comm.ep_comm_ptr->size_rank_info[1].second; 
    25     mpi_size = inter_comm.ep_comm_ptr->size_rank_info[2].second; 
     21    ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first; 
     22    ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first; 
     23    mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first; 
     24    ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second; 
     25    num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second; 
     26    mpi_size = inter_comm->ep_comm_ptr->size_rank_info[2].second; 
    2627 
    2728    int local_high = high; 
    2829    int remote_high; 
    2930 
    30     int remote_ep_size = inter_comm.ep_comm_ptr->intercomm->remote_rank_map->size(); 
     31    int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->remote_rank_map->size(); 
    3132 
    3233    int local_ep_rank, local_ep_rank_loc, local_mpi_rank; 
    3334    int local_ep_size, local_num_ep, local_mpi_size; 
    3435 
    35     local_ep_rank = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].first; 
    36     local_ep_rank_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first; 
    37     local_mpi_rank = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].first; 
    38     local_ep_size = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].second; 
    39     local_num_ep = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second; 
    40     local_mpi_size = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].second; 
     36    //local_ep_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].first; 
     37    //local_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first; 
     38    //local_mpi_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].first; 
     39    //local_ep_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].second; 
     40    //local_num_ep = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second; 
     41    //local_mpi_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].second; 
    4142 
    4243 
     
    4546      MPI_Status status[2]; 
    4647      MPI_Request request[2]; 
    47       MPI_Isend(&local_high, 1, MPI_INT, 0, inter_comm.ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[0]); 
    48       MPI_Irecv(&remote_high, 1, MPI_INT, 0, inter_comm.ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[1]); 
     48      MPI_Isend(&local_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[0]); 
     49      MPI_Irecv(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[1]); 
    4950 
    5051      MPI_Waitall(2, request, status); 
     
    5253 
    5354 
    54     MPI_Bcast(&remote_high, 1, MPI_INT, 0, *(inter_comm.ep_comm_ptr->intercomm->local_comm)); 
     55    //MPI_Bcast(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->local_comm); 
    5556 
    5657 
     
    6465    int intra_ep_size, intra_num_ep, intra_mpi_size; 
    6566 
    66     intra_ep_rank = newintracomm->ep_comm_ptr->size_rank_info[0].first; 
    67     intra_ep_rank_loc = newintracomm->ep_comm_ptr->size_rank_info[1].first; 
    68     intra_mpi_rank = newintracomm->ep_comm_ptr->size_rank_info[2].first; 
    69     intra_ep_size = newintracomm->ep_comm_ptr->size_rank_info[0].second; 
    70     intra_num_ep = newintracomm->ep_comm_ptr->size_rank_info[1].second; 
    71     intra_mpi_size = newintracomm->ep_comm_ptr->size_rank_info[2].second; 
     67    intra_ep_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first; 
     68    intra_ep_rank_loc = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first; 
     69    intra_mpi_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first; 
     70    intra_ep_size = (*newintracomm)->ep_comm_ptr->size_rank_info[0].second; 
     71    intra_num_ep = (*newintracomm)->ep_comm_ptr->size_rank_info[1].second; 
     72    intra_mpi_size = (*newintracomm)->ep_comm_ptr->size_rank_info[2].second; 
    7273 
    7374 
     
    8586    if(intra_ep_rank_loc == 0) 
    8687    { 
    87       ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm(newintracomm->mpi_comm)); 
     88      ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm((*newintracomm)->mpi_comm)); 
    8889 
    8990      vector< pair<int, int> > tmp_rank_map(intra_ep_size); 
     
    9293      for(int i=0; i<intra_ep_size; i++) 
    9394      { 
    94         tmp_rank_map[reorder[i]] = newintracomm->rank_map->at(i) ; 
    95       } 
    96  
    97       newintracomm->rank_map->swap(tmp_rank_map); 
     95        tmp_rank_map[reorder[i]] = (*newintracomm)->ep_rank_map->at(i) ; 
     96      } 
     97 
     98      //(*newintracomm)->rank_map->swap(tmp_rank_map); 
     99      (*newintracomm)->ep_rank_map->clear(); 
     100      for(int i=0; i<tmp_rank_map.size(); i++) 
     101      { 
     102        (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(i, tmp_rank_map[i].first, tmp_rank_map[i].second)); 
     103      } 
     104       
    98105 
    99106      tmp_rank_map.clear(); 
     
    102109    MPI_Barrier_local(*newintracomm); 
    103110 
    104     (*newintracomm).ep_comm_ptr->size_rank_info[0].first = my_ep_rank; 
     111    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = my_ep_rank; 
    105112 
    106113    if(intra_ep_rank_loc == 0) 
     
    118125  int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm) 
    119126  { 
    120  
    121     assert(inter_comm.is_intercomm); 
    122  
    123     if(inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->comm_label == -99) 
    124     { 
    125         return MPI_Intercomm_merge_unique_leader(inter_comm, high, newintracomm); 
    126     } 
    127  
    128  
    129     Debug("intercomm_merge kernel\n"); 
    130  
    131     int ep_rank_loc; 
    132     int num_ep; 
    133  
    134     ep_rank_loc = inter_comm.ep_comm_ptr->size_rank_info[1].first; 
    135     num_ep = inter_comm.ep_comm_ptr->size_rank_info[1].second; 
    136  
    137  
    138  
    139     int remote_ep_size = inter_comm.ep_comm_ptr->intercomm->remote_rank_map->size(); 
    140  
    141  
    142     MPI_Barrier(inter_comm); 
    143  
    144  
    145     ::MPI_Comm *mpi_intracomm = new ::MPI_Comm; 
    146     MPI_Comm *ep_intracomm; 
    147  
    148     if(ep_rank_loc == 0) 
    149     { 
    150  
    151       ::MPI_Comm mpi_comm = to_mpi_comm(inter_comm.ep_comm_ptr->intercomm->mpi_inter_comm); 
    152  
    153       ::MPI_Intercomm_merge(mpi_comm, high, mpi_intracomm); 
     127     
     128 
     129    assert(inter_comm->is_intercomm); 
     130 
     131    // determine if only one MPI proc 
     132 
     133        // to be completed ...... 
     134 
     135    // multiple MPI proc and high differs 
     136 
     137    int newcomm_ep_rank = inter_comm->ep_comm_ptr->intercomm->size_rank_info[0].first; 
     138    int newcomm_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].first; 
     139    int newcomm_num_ep = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].second; 
     140 
     141    int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first; 
     142    int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first; 
     143    int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second; 
     144 
     145    if(newcomm_ep_rank_loc == 0) 
     146    { 
     147      ::MPI_Comm *mpi_intracomm = new ::MPI_Comm; 
     148      ::MPI_Intercomm_merge(to_mpi_comm(inter_comm->ep_comm_ptr->intercomm->mpi_inter_comm), high, mpi_intracomm); 
     149       
    154150      MPI_Info info; 
    155       MPI_Comm_create_endpoints(mpi_intracomm, num_ep, info, ep_intracomm); 
    156  
    157       inter_comm.ep_comm_ptr->comm_list->mem_bridge = ep_intracomm; 
    158  
     151      MPI_Comm *ep_comm; 
     152      MPI_Comm_create_endpoints(mpi_intracomm, newcomm_num_ep, info, ep_comm); 
     153 
     154      inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge = ep_comm; 
    159155    } 
    160156 
    161157    MPI_Barrier_local(inter_comm); 
    162158 
    163     int inter_rank; 
    164     MPI_Comm_rank(inter_comm, &inter_rank); 
     159    int remote_num_ep = newcomm_num_ep - num_ep; 
     160 
     161    *newintracomm = inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge[high? remote_num_ep+ep_rank_loc : ep_rank_loc]; 
     162 
     163    int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second; 
     164    int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->intercomm_rank_map->size(); 
     165 
     166    //printf("ep_size = %d, remote_ep_size = %d\n", ep_size, remote_ep_size); 
     167 
     168    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = high? remote_ep_size+ep_rank : ep_rank; 
     169 
     170    int my_triple[3]; 
     171    my_triple[0] = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first; 
     172    my_triple[1] = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first; 
     173    my_triple[2] = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first; 
     174 
     175    int *my_triple_list = new int[3 * (*newintracomm)->ep_comm_ptr->size_rank_info[0].second]; 
     176 
     177 
     178    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 
     179 
     180    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first == 0) 
     181    { 
     182      (*newintracomm)->ep_rank_map->clear(); 
     183      for(int i=0; i<(*newintracomm)->ep_comm_ptr->size_rank_info[0].second; i++) 
     184      { 
     185        (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_list[3*i], my_triple_list[3*i+1], my_triple_list[3*i+2])); 
     186      } 
     187    } 
     188 
     189#ifdef _showinfo 
     190    MPI_Barrier_local(inter_comm); 
     191    if((*newintracomm)->ep_comm_ptr->size_rank_info[0].first == 15) 
     192    { 
     193      for(std::map<int, std::pair<int, int> >::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++) 
     194      { 
     195        printf("(%d  %d  %d)\n", it->first, it->second.first, it->second.second); 
     196      } 
     197    } 
     198#endif 
    165199     
    166     int my_ep_rank = high? inter_rank+remote_ep_size : inter_rank; 
    167     int my_ep_rank_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first; 
    168     int my_num_ep_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second; 
    169     int my_num_ep_total = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[1].second; 
    170     int my_ep_size = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[0].second; 
    171  
    172     int tmp_intra_ep_rank_loc = high?my_ep_rank_loc+my_num_ep_total-my_num_ep_loc: my_ep_rank_loc; 
    173  
    174  
    175     *newintracomm = inter_comm.ep_comm_ptr->comm_list->mem_bridge[tmp_intra_ep_rank_loc]; 
    176  
    177     int newintracomm_ep_rank = (*newintracomm).ep_comm_ptr->size_rank_info[0].first; 
    178     int newintracomm_ep_rank_loc = (*newintracomm).ep_comm_ptr->size_rank_info[1].first; 
    179     int newintracomm_mpi_rank = (*newintracomm).ep_comm_ptr->size_rank_info[2].first; 
    180     int newintracomm_ep_size = (*newintracomm).ep_comm_ptr->size_rank_info[0].second; 
    181     int newintracomm_num_ep = (*newintracomm).ep_comm_ptr->size_rank_info[1].second; 
    182     int newintracomm_mpi_size = (*newintracomm).ep_comm_ptr->size_rank_info[2].second; 
    183  
    184  
    185     int buf[3]; 
    186     buf[0] = my_ep_rank; 
    187     buf[1] = tmp_intra_ep_rank_loc; 
    188     buf[2] = newintracomm->ep_comm_ptr->size_rank_info[2].first; 
    189  
    190     // printf("my_ep_rank = %d, tmp_intra_ep_rank_loc = %d, mpi_rank = %d\n", my_ep_rank, tmp_intra_ep_rank_loc, newintracomm->ep_comm_ptr->size_rank_info[2].first); 
    191  
    192     int *rankmap_buf; 
    193     rankmap_buf = new int [3*my_ep_size]; 
    194  
    195     MPI_Allgather(buf, 3, MPI_INT, rankmap_buf, 3, MPI_INT, *newintracomm); 
    196  
    197      
    198     // printf(" ID = %d : rankmap_buf = (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d)\n", newintracomm_ep_rank, 
    199     //                     rankmap_buf[0], rankmap_buf[1], rankmap_buf[2], rankmap_buf[3], rankmap_buf[4], rankmap_buf[5], rankmap_buf[6], rankmap_buf[7], rankmap_buf[8], rankmap_buf[9], 
    200     //                     rankmap_buf[10], rankmap_buf[11], rankmap_buf[12], rankmap_buf[13], rankmap_buf[14], rankmap_buf[15], rankmap_buf[16], rankmap_buf[17], rankmap_buf[18], rankmap_buf[19],  
    201     //                     rankmap_buf[20], rankmap_buf[21], rankmap_buf[22], rankmap_buf[23], rankmap_buf[24], rankmap_buf[25], rankmap_buf[26], rankmap_buf[27], rankmap_buf[28], rankmap_buf[29], 
    202     //                     rankmap_buf[30], rankmap_buf[31], rankmap_buf[32], rankmap_buf[33], rankmap_buf[34], rankmap_buf[35], rankmap_buf[36], rankmap_buf[37], rankmap_buf[38], rankmap_buf[39], 
    203     //                     rankmap_buf[40], rankmap_buf[41], rankmap_buf[42], rankmap_buf[43], rankmap_buf[44], rankmap_buf[45], rankmap_buf[46], rankmap_buf[47]); 
    204  
    205  
    206     for(int i=0; i<newintracomm_ep_size; i++) 
    207     { 
    208       (*newintracomm).rank_map->at(rankmap_buf[3*i]).first  = rankmap_buf[3*i+1]; 
    209       (*newintracomm).rank_map->at(rankmap_buf[3*i]).second = rankmap_buf[3*i+2]; 
    210     } 
    211  
    212  
    213     (*newintracomm).ep_comm_ptr->size_rank_info[0].first = my_ep_rank; 
    214     (*newintracomm).ep_comm_ptr->size_rank_info[1].first = tmp_intra_ep_rank_loc; 
    215      
    216  
    217     delete[] rankmap_buf; 
    218  
    219      
    220     return MPI_SUCCESS; 
    221  
     200    delete my_triple_list; 
    222201  } 
    223  
    224  
     202   
    225203} 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp

    r1374 r1520  
    1818namespace ep_lib 
    1919{ 
    20  
     20  int Request_Check() 
     21  { 
     22    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >; 
     23     
     24    if(EP_PendingRequests->size() == 0) return 0; 
     25     
     26    MPI_Status status; 
     27    MPI_Message *message; 
     28    int probed = false; 
     29    int recv_count = 0; 
     30    std::list<MPI_Request* >::iterator it; 
     31     
     32     
     33    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) 
     34    {  
     35      Message_Check(((*(*it))->comm)); 
     36    } 
     37 
     38 
     39    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 
     40    { 
     41      if((*(*it))->state == 0) 
     42      { 
     43        #pragma omp critical (_query0) 
     44        { 
     45          MPI_Iprobe((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status); 
     46          if(probed) 
     47          { 
     48            message = new MPI_Message; 
     49            *message = new ep_message; 
     50         
     51            memcheck("new "<< message <<" : in ep_lib::Request_Check, message = new MPI_Message"); 
     52            memcheck("new "<< *message <<" : in ep_lib::Request_Check, *message = new ep_message"); 
     53           
     54           
     55            MPI_Improbe((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status); 
     56         
     57          } 
     58        } 
     59       
     60         
     61        if(probed) 
     62        { 
     63          MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count); 
     64           
     65          MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it); 
     66          (*(*it))->type = 3; 
     67          (*(*it))->state = 1; 
     68 
     69          memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status"); 
     70          delete status.mpi_status;           
     71 
     72          memcheck("delete "<< *message <<" : in ep_lib::Request_Check, delete *message"); 
     73          memcheck("delete "<< message <<" : in ep_lib::Request_Check, delete message"); 
     74 
     75          delete *message; 
     76          delete message; 
     77         
     78          it++; 
     79          continue;       
     80        }               
     81      } 
     82       
     83      if((*(*it))->state == 2) 
     84      { 
     85        int ep_rank = ((*(*it))->comm)->ep_comm_ptr->size_rank_info[0].first; 
     86        memcheck("delete "<< (*(*it)) <<" : in ep_lib::Request_Check, delete (*(*it))"); 
     87         
     88         
     89        int world_rank; 
     90        MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 
     91        if(world_rank==2)  
     92        { 
     93          printf("ep %d erased one pending request %p\n", world_rank,*(*it)); 
     94        } 
     95         
     96        EP_PendingRequests->erase(it); 
     97         
     98        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); 
     99        it = EP_PendingRequests->begin(); 
     100        continue; 
     101      } 
     102      else it++; 
     103    } 
     104  } 
     105   
     106   
     107   
    21108  int Message_Check(MPI_Comm comm) 
    22109  { 
    23     if(!comm.is_ep) return 0; 
    24  
    25     if(comm.is_intercomm) 
    26     { 
    27       return  Message_Check_intercomm(comm); 
    28     } 
     110    if(!comm->is_ep) return MPI_SUCCESS; 
     111 
     112    if(comm->is_intercomm) 
     113    { 
     114      Message_Check_intercomm(comm); 
     115    } 
     116     
     117    return Message_Check_intracomm(comm); 
     118 
     119  } 
     120   
     121   
     122  int Message_Check_intracomm(MPI_Comm comm) 
     123  { 
     124     
     125    int flag = true; 
     126    ::MPI_Status status; 
     127    ::MPI_Message message; 
     128 
     129    while(flag) // loop until the end of global queue 
     130    { 
     131      Debug("Message probing for intracomm\n"); 
     132      
     133      #pragma omp critical (_mpi_call) 
     134      { 
     135        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &status); 
     136        if(flag) 
     137        { 
     138          Debug("find message in mpi comm \n"); 
     139          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->mpi_comm), &message, &status); 
     140        } 
     141      } 
     142 
     143       
     144      if(flag) 
     145      { 
     146        MPI_Message msg = new ep_message;  
     147        msg->mpi_message = new ::MPI_Message(message); 
     148 
     149        memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message"); 
     150        memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message"); 
     151               
     152 
     153        msg->ep_tag  = bitset<15>(status.MPI_TAG >> 16).to_ulong();  
     154        int src_loc  = bitset<8> (status.MPI_TAG >> 8) .to_ulong();  
     155        int dest_loc = bitset<8> (status.MPI_TAG)           .to_ulong(); 
     156        int src_mpi  = status.MPI_SOURCE; 
     157              
     158        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);   
     159 
     160#ifdef _showinfo 
     161        printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag); 
     162#endif 
     163 
     164        msg->mpi_status = new ::MPI_Status(status);   
     165        memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status"); 
     166 
     167        #pragma omp critical (_query) 
     168        { 
     169          #pragma omp flush 
     170          comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg);   
     171          int dest_mpi = comm->ep_comm_ptr->size_rank_info[2].first; 
     172          memcheck("message_queue["<<dest_mpi<<","<<dest_loc<<"]->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size()); 
     173          #pragma omp flush 
     174        } 
     175      } 
     176    } 
     177 
     178    return MPI_SUCCESS; 
     179  } 
     180 
     181 
     182   
     183   
     184   
     185 
     186 
     187  int Message_Check_intercomm(MPI_Comm comm) 
     188  { 
     189    if(!comm->ep_comm_ptr->intercomm->mpi_inter_comm) return 0; 
     190 
     191    Debug("Message probing for intercomm\n"); 
    29192 
    30193    int flag = true; 
    31194    ::MPI_Message message; 
    32195    ::MPI_Status status; 
    33     int mpi_source; 
    34  
    35     while(flag) // loop until the end of global queue 
    36     { 
    37       Debug("Message probing for intracomm\n"); 
    38        
    39       #pragma omp critical (_mpi_call) 
    40       { 
    41         ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status); 
    42         if(flag) 
    43         { 
    44           Debug("find message in mpi comm \n"); 
    45           mpi_source = status.MPI_SOURCE; 
    46           int tag = status.MPI_TAG; 
    47           ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status); 
    48  
    49         } 
    50       } 
    51  
    52        
    53       if(flag) 
    54       { 
    55  
    56         MPI_Message *msg_block = new MPI_Message;  
    57         msg_block->mpi_message = new ::MPI_Message; 
    58         *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message;   
    59         msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong();  
    60         int src_loc       = bitset<8> (status.MPI_TAG >> 8) .to_ulong();  
    61         int dest_loc      = bitset<8> (status.MPI_TAG)      .to_ulong(); 
    62         int src_mpi       = status.MPI_SOURCE; 
    63               
    64         msg_block->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);        
    65         msg_block->mpi_status = new ::MPI_Status(status); 
    66  
    67         MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; 
    68         MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; 
    69  
    70  
    71         #pragma omp critical (_query) 
    72         { 
    73           #pragma omp flush 
    74           comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block);       
    75           #pragma omp flush 
    76         } 
    77          
    78         delete msg_block; 
    79       } 
    80  
    81     } 
    82  
    83     return MPI_SUCCESS; 
    84   } 
    85  
    86  
    87  
    88   int Message_Check_intercomm(MPI_Comm comm) 
    89   { 
    90     if(!comm.ep_comm_ptr->intercomm->mpi_inter_comm) return 0; 
    91  
    92     Debug("Message probing for intercomm\n"); 
    93  
    94     int flag = true; 
    95     ::MPI_Message message; 
    96     ::MPI_Status status; 
    97     int mpi_source; 
    98196    int current_ep_rank; 
    99197    MPI_Comm_rank(comm, &current_ep_rank); 
    100198 
    101     while(flag) // loop until the end of global queue "comm.ep_comm_ptr->intercomm->mpi_inter_comm" 
     199    while(flag) // loop until the end of global queue "comm->ep_comm_ptr->intercomm->mpi_inter_comm" 
    102200    { 
    103201      Debug("Message probing for intracomm\n"); 
     
    105203      #pragma omp critical (_mpi_call) 
    106204      { 
    107         ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &flag, &status); 
     205        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &flag, &status); 
    108206        if(flag) 
    109207        { 
    110208          Debug("find message in mpi comm \n"); 
    111           mpi_source = status.MPI_SOURCE; 
    112           int tag = status.MPI_TAG; 
    113           ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status); 
    114  
     209          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status); 
    115210        } 
    116211      } 
     
    120215      { 
    121216 
    122         MPI_Message *msg_block = new MPI_Message; 
    123         msg_block->mpi_message = new ::MPI_Message; 
    124         *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message; 
    125         msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 
    126         int src_loc       = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 
    127         int dest_loc      = bitset<8> (status.MPI_TAG)      .to_ulong(); 
    128         int src_mpi       = status.MPI_SOURCE; 
    129         int current_inter = comm.ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first; 
     217        MPI_Message msg = new ep_message;  
     218        msg->mpi_message = new ::MPI_Message(message); 
     219 
     220        memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message"); 
     221        memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message"); 
     222               
     223 
     224        msg->ep_tag  = bitset<15>(status.MPI_TAG >> 16).to_ulong();  
     225        int src_loc  = bitset<8> (status.MPI_TAG >> 8) .to_ulong();  
     226        int dest_loc = bitset<8> (status.MPI_TAG)           .to_ulong(); 
     227        int src_mpi  = status.MPI_SOURCE; 
    130228              
    131         msg_block->ep_src  = get_ep_rank_intercomm(comm, src_loc,  src_mpi); 
    132         msg_block->mpi_status = new ::MPI_Status(status); 
    133  
    134  
    135         MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; 
    136         MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; 
    137  
     229        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);    
     230#ifdef _showinfo 
     231        printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag); 
     232#endif 
     233 
     234        msg->mpi_status = new ::MPI_Status(status);  
     235        memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status"); 
    138236 
    139237        #pragma omp critical (_query) 
    140238        { 
    141239          #pragma omp flush 
    142           comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block); 
    143           #pragma omp flush 
    144         } 
    145          
    146         delete msg_block; 
    147          
    148       } 
    149  
    150     } 
    151  
    152     flag = true; 
    153     while(flag) // loop until the end of global queue "comm.mpi_comm" 
    154     { 
    155       Debug("Message probing for intracomm\n"); 
    156       
    157       #pragma omp critical (_mpi_call) 
    158       { 
    159         ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status); 
    160         if(flag) 
    161         { 
    162           Debug("find message in mpi comm \n"); 
    163           mpi_source = status.MPI_SOURCE; 
    164           int tag = status.MPI_TAG; 
    165           ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status); 
    166  
    167         } 
    168       } 
    169        
    170  
    171       if(flag) 
    172       { 
    173  
    174         MPI_Message *msg_block = new MPI_Message; 
    175         msg_block->mpi_message = new ::MPI_Message; 
    176         *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message; 
    177         msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 
    178         int src_loc       = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 
    179         int dest_loc      = bitset<8> (status.MPI_TAG)      .to_ulong(); 
    180         int src_mpi       = status.MPI_SOURCE; 
    181          
    182         msg_block->ep_src  = get_ep_rank_intercomm(comm, src_loc, src_mpi); 
    183         msg_block->mpi_status = new ::MPI_Status(status); 
    184          
    185  
    186         MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; 
    187         MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; 
    188  
    189  
    190         #pragma omp critical (_query) 
    191         { 
    192           #pragma omp flush 
    193           comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block); 
    194           #pragma omp flush 
    195         } 
    196          
    197         delete msg_block; 
    198          
    199       } 
    200  
    201     } 
     240          comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg); 
     241          memcheck("comm->ep_comm_ptr->comm_list["<<dest_loc<<"]->ep_comm_ptr->message_queue->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size()); 
     242          #pragma omp flush 
     243        } 
     244      } 
     245    } 
     246 
     247    Message_Check_intracomm(comm); 
    202248 
    203249    return MPI_SUCCESS; 
    204250  } 
    205251 
    206   int Request_Check() 
    207   { 
    208     MPI_Status status; 
    209     MPI_Message message; 
    210     int probed = false; 
    211     int recv_count = 0; 
    212     std::list<MPI_Request* >::iterator it; 
    213      
    214     for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) 
    215     {  
    216       Message_Check((*it)->comm); 
    217     } 
    218  
    219  
    220     for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 
    221     { 
    222       MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status); 
    223       if(probed) 
    224       { 
    225         MPI_Get_count(&status, (*it)->ep_datatype, &recv_count); 
    226         MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it); 
    227         (*it)->type = 3; 
    228         EP_PendingRequests->erase(it); 
    229         it = EP_PendingRequests->begin(); 
    230         continue; 
    231       } 
    232       it++; 
    233     } 
    234   } 
     252   
    235253 
    236254} 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp

    r1362 r1520  
    77MPI_Op       to_mpi_op(ep_lib::MPI_Op op); 
    88MPI_Comm     to_mpi_comm(void* comm); 
     9MPI_Comm*    to_mpi_comm_ptr(void* comm); 
    910MPI_Message  to_mpi_message(void* message); 
    10 MPI_Info     to_mpi_info(void* info); 
     11MPI_Info     to_mpi_info(ep_lib::MPI_Info info); 
     12MPI_Win      to_mpi_win(void* win); 
     13MPI_Aint     to_mpi_aint(ep_lib::MPI_Aint aint); 
     14MPI_Status*  to_mpi_status_ptr (ep_lib::MPI_Status status); 
     15MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request); 
     16MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message); 
    1117 
    1218#endif // EP_MPI_HPP_INCLUDED 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp

    r1362 r1520  
    66namespace ep_lib 
    77{ 
     8  int MPI_Iprobe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status) 
     9  { 
     10    status->ep_src = src; 
     11    status->ep_tag = tag; 
     12    return ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, to_mpi_status_ptr(*status)); 
     13  } 
    814 
    915  int MPI_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status) 
    1016  { 
    11     *flag = false; 
     17    if(!comm->is_ep) 
     18    { 
     19      Debug("MPI_Iprobe with MPI\n"); 
     20      return MPI_Iprobe_mpi(src, tag, comm, flag, status); 
     21    } 
     22     
     23    else 
     24    { 
     25      Debug("MPI_Iprobe with EP\n"); 
     26       
     27      *flag = false; 
     28     
     29      Message_Check(comm); 
    1230 
    13     if(!comm.is_ep) 
    14     { 
    15       ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status); 
    16       ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, mpi_status); 
     31      #pragma omp flush 
    1732 
    18       status->mpi_status = mpi_status; 
    19       status->ep_src = src; 
    20       status->ep_tag = tag; 
    21       return 0; 
    22     } 
    23  
    24     Debug("calling MPI_Iprobe EP\n"); 
    25  
    26     Message_Check(comm); 
    27  
    28     #pragma omp flush 
    29  
    30     #pragma omp critical (_query) 
    31     if(!comm.ep_comm_ptr->message_queue->empty()) 
    32     { 
    33       for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it) 
     33      #pragma omp critical (_query) 
     34      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 
    3435      { 
    35         bool src_matched = src<0? true: it->ep_src == src; 
    36         bool tag_matched = tag<0? true: it->ep_tag == tag; 
     36        bool src_matched = src<0? true: (*it)->ep_src == src; 
     37        bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 
    3738         
    3839        if(src_matched && tag_matched)         
    3940        { 
    4041          Debug("find message\n"); 
     42           
     43 
     44          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 
     45          status->ep_src = (*it)->ep_src; 
     46          status->ep_tag = (*it)->ep_tag; 
     47 
    4148          *flag = true; 
    42  
    43           ::MPI_Status mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status)); 
    44  
    45           status->mpi_status = new ::MPI_Status(mpi_status); 
    46           status->ep_src = it->ep_src; 
    47           status->ep_tag = it->ep_tag; 
    48  
    4949          break; 
    5050        } 
    51  
    5251      } 
    5352    } 
    54  
    55     return 0; 
    5653  } 
    5754 
     
    6057  int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status) 
    6158  { 
     59    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     60    int mpi_rank    = comm->ep_comm_ptr->size_rank_info[2].first; 
    6261    *flag = false; 
    63     if(!comm.is_ep) 
     62    if(!comm->is_ep) 
    6463    { 
    6564      Debug("calling MPI_Improbe MPI\n"); 
     
    7170      #pragma omp critical (_mpi_call) 
    7271      { 
    73         ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, &mpi_status); 
     72        ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_status); 
    7473        if(*flag) 
    7574        { 
    76           ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_message, &mpi_status); 
     75          ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_message, &mpi_status); 
    7776        } 
    7877      } 
    7978      #elif _intelmpi 
    80         ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, &mpi_message, &mpi_status); 
     79        ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_message, &mpi_status); 
    8180      #endif 
    8281         
    83       status->mpi_status = new ::MPI_Status(mpi_status); 
     82      status->mpi_status = &mpi_status; 
    8483      status->ep_src = src; 
    8584      status->ep_tag = tag; 
    8685 
    87       message->mpi_message = new ::MPI_Message; 
    88       *(static_cast< ::MPI_Message*>(message->mpi_message)) = mpi_message; 
    89       message->ep_src = src; 
    90       message->ep_tag = tag; 
     86      (*message)->mpi_message = &message; 
     87      (*message)->ep_src = src; 
     88      (*message)->ep_tag = tag; 
     89       
     90       
    9191      return 0; 
    9292    } 
    9393 
    94      
    95     //Message_Check(comm); 
     94    
    9695 
    9796    #pragma omp flush 
    9897 
    9998    #pragma omp critical (_query) 
    100     if(! comm.ep_comm_ptr->message_queue->empty()) 
     99    if(! comm->ep_comm_ptr->message_queue->empty()) 
    101100    { 
    102       for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it) 
     101      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 
    103102      { 
    104         bool src_matched = src<0? true: it->ep_src == src; 
    105         bool tag_matched = tag<0? true: it->ep_tag == tag; 
     103                                           
     104        bool src_matched = src<0? true: (*it)->ep_src == src; 
     105        bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 
    106106         
    107107        if(src_matched && tag_matched) 
     
    109109          *flag = true; 
    110110 
    111           ::MPI_Status mpi_status; 
    112           mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status)); 
     111          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 
     112          memcheck("new "<< status->mpi_status << " : in ep_lib::MPI_Improbe, status->mpi_status = new ::MPI_Status"); 
     113          status->ep_src = (*it)->ep_src; 
     114          status->ep_tag = (*it)->ep_tag; 
    113115 
    114           status->mpi_status = new ::MPI_Status(mpi_status); 
    115           status->ep_src = it->ep_src; 
    116           status->ep_tag = it->ep_tag; 
    117  
    118           message->mpi_message = it->mpi_message; 
    119           message->ep_tag = it->ep_tag; 
    120           message->ep_src = it->ep_src; 
     116          (*message)->mpi_message = new ::MPI_Message(*static_cast< ::MPI_Message*>((*it)->mpi_message)); 
     117          memcheck("new "<< (*message)->mpi_message <<" : in ep_lib::MPI_Improbe, (*message)->mpi_message = new ::MPI_Message"); 
     118          (*message)->ep_src = (*it)->ep_src; 
     119          (*message)->ep_tag = (*it)->ep_tag; 
     120                                       
    121121 
    122122          #pragma omp critical (_query2) 
    123123          {               
    124             delete it->mpi_status; 
    125             comm.ep_comm_ptr->message_queue->erase(it); 
     124            memcheck("delete "<< (*it)->mpi_message <<" : in ep_lib::Message_Check, delete (*it)->mpi_message"); 
     125            memcheck("delete "<< (*it)->mpi_status <<" : in ep_lib::Message_Check, delete (*it)->mpi_status"); 
     126            memcheck("delete "<< (*it) <<" : in ep_lib::Message_Check, delete (*it)"); 
     127             
     128             
     129            delete (*it)->mpi_message;      
     130            delete (*it)->mpi_status;  
     131            delete *it; 
     132             
     133                        
     134            comm->ep_comm_ptr->message_queue->erase(it); 
     135            memcheck("message_queue["<<mpi_rank<<","<<ep_rank_loc<<"]->size = "<<comm->ep_comm_ptr->message_queue->size()); 
    126136            #pragma omp flush 
    127137          } 
    128  
     138           
    129139          break; 
    130140        } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp

    r1354 r1520  
    77{ 
    88 
     9  int MPI_Comm_rank(MPI_Comm comm, int* rank) 
     10  { 
     11    if(comm->is_ep) 
     12    { 
     13      Debug("MPI_Comm_rank with EP"); 
     14      return *rank = comm->ep_comm_ptr->size_rank_info[0].first;       
     15    } 
     16 
     17    return MPI_Comm_rank_mpi(comm, rank); 
     18  } 
    919 
    1020 
    11   int MPI_Comm_rank(MPI_Comm comm, int* rank) 
     21  int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank) 
    1222  { 
    13  
    14     if(comm.is_ep) 
    15     { 
    16       Debug("Calling EP_Comm_rank\n"); 
    17  
    18       if(comm.is_intercomm) 
    19       { 
    20         *rank = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; 
    21         return 0; 
    22       } 
    23       else 
    24       { 
    25         *rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    26         return 0; 
    27       } 
    28     } 
    29  
    30  
    31     if(comm != MPI_COMM_NULL) 
    32     { 
    33       ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
    34       ::MPI_Comm_rank(mpi_comm, rank); 
    35       return 0; 
    36     } 
    37     else 
    38     { 
    39       printf("rank is undefined\n"); 
    40  
    41       *rank = MPI_UNDEFINED; 
    42       return 0; 
    43     } 
    44  
     23    Debug("MPI_Comm_rank with MPI"); 
     24    return ::MPI_Comm_rank(to_mpi_comm(comm->mpi_comm), rank); 
    4525  } 
    46  
    4726 
    4827 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp

    r1374 r1520  
    1919namespace ep_lib  
    2020{ 
    21    
    2221 
    2322  int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status) 
    2423  { 
    2524 
    26     if(!comm.is_ep) 
    27     { 
    28       ::MPI_Status mpi_status; 
    29       ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_status); 
    30  
    31       status->ep_src = src; 
    32       status->ep_tag = tag; 
    33       status->ep_datatype = datatype; 
    34  
    35       return 0;   
    36     } 
    37  
    38     Message_Check(comm); 
     25    if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status); 
     26     
     27    Debug("MPI_Recv with EP"); 
    3928 
    4029    MPI_Request request; 
     
    4534  } 
    4635 
    47  
     36   
    4837 
    4938 
    5039  int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request) 
    5140  { 
    52  
     41    if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request); 
     42     
    5343    Debug("MPI_Irecv with EP"); 
    5444    int dest_rank; 
    5545    MPI_Comm_rank(comm, &dest_rank); 
    5646     
     47    *request = new ep_request;    
     48    memcheck("new " << *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request"); 
    5749 
    58     if(!comm.is_ep) 
     50    (*request)->mpi_request = new ::MPI_Request; 
     51    memcheck("new " << (*request)->mpi_request << " : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request"); 
     52     
     53    (*request)->buf = buf; 
     54    (*request)->comm = comm; 
     55    (*request)->type = 2; 
     56    (*request)->state = 0; 
     57     
     58 
     59    (*request)->ep_src = src; 
     60    (*request)->ep_tag = tag; 
     61    (*request)->ep_datatype = datatype; 
     62   
     63    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >; 
     64 
     65    EP_PendingRequests->push_back(request);   
     66     
     67    int world_rank; 
     68    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 
     69    if(world_rank==2)  
    5970    { 
    60       ::MPI_Request mpi_request; 
    61       ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
     71      printf("ep %d inserted one pending request %p\n", world_rank, *request); 
     72    } 
     73     
     74    memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());     
    6275 
    63       request->mpi_request = new ::MPI_Request(mpi_request); 
    64       request->ep_src = src; 
    65       request->ep_datatype = datatype; 
    66       request->ep_tag = tag; 
    67     } 
     76#ifdef _showinfo 
     77    if(comm->is_intercomm) 
     78    { 
     79      int ep_dest_loc  = comm->ep_rank_map->at(dest_rank).first; 
     80      int ep_src_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).first; 
     81      int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     82      int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).second.first; 
    6883 
    69     request->buf = buf; 
    70     request->comm = comm; 
    71     request->type = 2; 
     84      printf("Irecv : ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag); 
     85    }                                                           
     86#endif                                       
    7287 
    73     request->ep_src = src; 
    74     request->ep_tag = tag; 
    75     request->ep_datatype = datatype; 
     88    return Request_Check(); 
     89  } 
     90   
     91  int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status) 
     92  { 
     93    Debug("MPI_Mrecv with MPI/EP"); 
    7694 
     95    status->mpi_status = new ::MPI_Status; 
     96    memcheck("new " << status->mpi_status << " : in ep_lib::MPI_Mrecv, status->mpi_status = new ::MPI_Status"); 
     97     
     98    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), to_mpi_status_ptr(*status)); 
    7799 
     100     
     101    status->ep_src = (*message)->ep_src; 
     102    status->ep_datatype = datatype; 
     103    status->ep_tag = (*message)->ep_tag; 
    78104 
    79     /* With Improbe*/ 
    80     Message_Check(comm); 
     105    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message"); 
     106    delete (*message)->mpi_message; 
    81107 
    82     if(EP_PendingRequests == 0 )  
    83     { 
    84       EP_PendingRequests = new std::list< MPI_Request* >; 
    85     } 
     108#ifdef _check_sum 
     109    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag); 
     110#endif 
    86111 
     112    return Request_Check(); 
     113  } 
    87114 
    88     EP_PendingRequests->push_back(request); 
    89  
    90  
    91     Request_Check(); 
    92  
    93     return 0; 
    94   } 
    95115 
    96116  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request) 
    97117  { 
    98     Debug("MPI_Imrecv"); 
     118    Debug("MPI_Imrecv with MPI/EP"); 
    99119 
    100     request->type = 3; 
     120    (*request)->type = 3; 
     121    (*request)->ep_datatype = datatype; 
     122    (*request)->ep_tag = (*message)->ep_tag; 
     123    (*request)->ep_src = (*message)->ep_src; 
     124     
     125    (*request)->state = 1; 
     126         
     127    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));                 
     128     
     129    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Imrecv, delete (*message)->mpi_message"); 
     130    delete (*message)->mpi_message; 
    101131 
    102     ::MPI_Request mpi_request; 
    103     ::MPI_Imrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >(message->mpi_message), &mpi_request);          
     132#ifdef _check_sum 
     133    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag); 
     134#endif 
    104135 
    105     request->mpi_request = new ::MPI_Request(mpi_request); 
    106     request->ep_datatype = datatype; 
    107     request->ep_tag = message->ep_tag; 
    108     request->ep_src = message->ep_src; 
    109136     
    110     delete message->mpi_message; 
    111  
    112     return 0; 
     137    return Request_Check(); 
    113138  } 
    114139 
    115140 
    116   int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status) 
     141   int MPI_Recv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status) 
    117142  { 
    118     Debug("EP Mrecv called\n"); 
     143    Debug("MPI_Recv with MPI"); 
     144    status->ep_src = src; 
     145    status->ep_tag = tag; 
     146    status->ep_datatype = datatype; 
     147     
     148    return ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_status_ptr(*status));  
     149  } 
     150   
     151  int MPI_Irecv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request) 
     152  { 
     153    Debug("MPI_Irecv with MPI"); 
     154    int dest_rank; 
     155    MPI_Comm_rank(comm, &dest_rank); 
     156     
     157    *request = new ep_request; 
     158    memcheck("new "<< *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request"); 
    119159 
    120     ::MPI_Status mpi_status; 
    121     ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >(message->mpi_message), &mpi_status); 
    122  
    123     status->mpi_status = new ::MPI_Status(mpi_status); 
    124     status->ep_src = message->ep_src; 
    125     status->ep_datatype = datatype; 
    126     status->ep_tag = message->ep_tag; 
    127  
    128     delete message->mpi_message; 
    129  
    130     //check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag); 
    131  
    132     return 0; 
     160    (*request)->mpi_request = new ::MPI_Request; 
     161    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request"); 
     162       
     163    (*request)->ep_src = src; 
     164    (*request)->ep_datatype = datatype; 
     165    (*request)->type = 2; 
     166    (*request)->ep_tag = tag; 
     167     
     168    return ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
    133169  } 
    134  
    135170} 
    136171 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp

    r1482 r1520  
    6666    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 
    6767 
    68     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    69     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    70     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
     68    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     69    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     70    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
    7171 
    7272    #pragma omp critical (_reduce) 
    73     comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
     73    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 
    7474 
    7575    MPI_Barrier_local(comm); 
     
    7878    { 
    7979 
    80       memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize * count); 
     80      memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize * count); 
    8181 
    8282      if(op == MPI_MAX) 
     
    8686          assert(datasize == sizeof(int)); 
    8787          for(int i=1; i<num_ep; i++) 
    88             reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
     88            reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
    8989        } 
    9090 
     
    9393          assert(datasize == sizeof(float)); 
    9494          for(int i=1; i<num_ep; i++) 
    95             reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
     95            reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
    9696        } 
    9797 
     
    100100          assert(datasize == sizeof(double)); 
    101101          for(int i=1; i<num_ep; i++) 
    102             reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     102            reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    103103        } 
    104104 
     
    107107          assert(datasize == sizeof(char)); 
    108108          for(int i=1; i<num_ep; i++) 
    109             reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     109            reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    110110        } 
    111111 
     
    114114          assert(datasize == sizeof(long)); 
    115115          for(int i=1; i<num_ep; i++) 
    116             reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     116            reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    117117        } 
    118118 
     
    121121          assert(datasize == sizeof(unsigned long)); 
    122122          for(int i=1; i<num_ep; i++) 
    123             reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
     123            reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
    124124        } 
    125125 
     
    128128          assert(datasize == sizeof(uint64_t)); 
    129129          for(int i=1; i<num_ep; i++) 
    130             reduce_max<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
     130            reduce_max<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
    131131        } 
    132132         
     
    135135          assert(datasize == sizeof(long long)); 
    136136          for(int i=1; i<num_ep; i++) 
    137             reduce_max<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
     137            reduce_max<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
    138138        } 
    139139 
     
    148148          assert(datasize == sizeof(int)); 
    149149          for(int i=1; i<num_ep; i++) 
    150             reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
     150            reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
    151151        } 
    152152 
     
    155155          assert(datasize == sizeof(float)); 
    156156          for(int i=1; i<num_ep; i++) 
    157             reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
     157            reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
    158158        } 
    159159 
     
    162162          assert(datasize == sizeof(double)); 
    163163          for(int i=1; i<num_ep; i++) 
    164             reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     164            reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    165165        } 
    166166 
     
    169169          assert(datasize == sizeof(char)); 
    170170          for(int i=1; i<num_ep; i++) 
    171             reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     171            reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    172172        } 
    173173 
     
    176176          assert(datasize == sizeof(long)); 
    177177          for(int i=1; i<num_ep; i++) 
    178             reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     178            reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    179179        } 
    180180 
     
    183183          assert(datasize == sizeof(unsigned long)); 
    184184          for(int i=1; i<num_ep; i++) 
    185             reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
     185            reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
    186186        } 
    187187 
     
    190190          assert(datasize == sizeof(uint64_t)); 
    191191          for(int i=1; i<num_ep; i++) 
    192             reduce_min<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
     192            reduce_min<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
    193193        } 
    194194         
     
    197197          assert(datasize == sizeof(long long)); 
    198198          for(int i=1; i<num_ep; i++) 
    199             reduce_min<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
     199            reduce_min<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
    200200        } 
    201201 
     
    211211          assert(datasize == sizeof(int)); 
    212212          for(int i=1; i<num_ep; i++) 
    213             reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
     213            reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
    214214        } 
    215215 
     
    218218          assert(datasize == sizeof(float)); 
    219219          for(int i=1; i<num_ep; i++) 
    220             reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
     220            reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 
    221221        } 
    222222 
     
    225225          assert(datasize == sizeof(double)); 
    226226          for(int i=1; i<num_ep; i++) 
    227             reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     227            reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    228228        } 
    229229 
     
    232232          assert(datasize == sizeof(char)); 
    233233          for(int i=1; i<num_ep; i++) 
    234             reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     234            reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    235235        } 
    236236 
     
    239239          assert(datasize == sizeof(long)); 
    240240          for(int i=1; i<num_ep; i++) 
    241             reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     241            reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    242242        } 
    243243 
     
    246246          assert(datasize == sizeof(unsigned long)); 
    247247          for(int i=1; i<num_ep; i++) 
    248             reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
     248            reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 
    249249        } 
    250250 
     
    253253          assert(datasize == sizeof(uint64_t)); 
    254254          for(int i=1; i<num_ep; i++) 
    255             reduce_sum<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
     255            reduce_sum<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count); 
    256256        } 
    257257         
     
    260260          assert(datasize == sizeof(long long)); 
    261261          for(int i=1; i<num_ep; i++) 
    262             reduce_sum<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
     262            reduce_sum<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count); 
    263263        } 
    264264 
     
    275275          assert(datasize == sizeof(int)); 
    276276          for(int i=1; i<num_ep; i++) 
    277             reduce_lor<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
     277            reduce_lor<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 
    278278        } 
    279279      } 
     
    288288  { 
    289289 
    290     if(!comm.is_ep && comm.mpi_comm) 
    291     { 
    292       return ::MPI_Reduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root, to_mpi_comm(comm.mpi_comm)); 
    293     } 
    294  
    295  
    296  
    297     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    298     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    299     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    300     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    301     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    302     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
    303  
    304     int root_mpi_rank = comm.rank_map->at(root).second; 
    305     int root_ep_loc = comm.rank_map->at(root).first; 
     290    if(!comm->is_ep && comm->mpi_comm) 
     291    { 
     292      return ::MPI_Reduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root, to_mpi_comm(comm->mpi_comm)); 
     293    } 
     294 
     295 
     296 
     297    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     298    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     299    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     300    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     301    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     302    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
     303 
     304    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     305    int root_ep_loc = comm->ep_rank_map->at(root).first; 
    306306 
    307307    ::MPI_Aint datasize, lb; 
     
    326326    if(is_master) 
    327327    { 
    328       ::MPI_Reduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     328      ::MPI_Reduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    329329       
    330330    } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp

    r1365 r1520  
    1919  int MPI_Reduce_scatter(const void *sendbuf, void *recvbuf, const int recvcounts[], MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 
    2020  { 
    21     if(!comm.is_ep) 
     21    if(!comm->is_ep) 
    2222    { 
    23       return ::MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     23      return ::MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    2424    } 
    2525 
    2626 
    27     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    28     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    29     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    30     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    31     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    32     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     27    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     28    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     29    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     30    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     31    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     32    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    3333 
    3434 
     
    5252    if(is_master) 
    5353    {   
    54       ::MPI_Allreduce(MPI_IN_PLACE, local_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     54      ::MPI_Allreduce(MPI_IN_PLACE, local_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    5555    } 
    5656 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp

    r1295 r1520  
    5050    valid_op(op); 
    5151 
    52     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    53     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    54     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
     52    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     53    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     54    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
    5555     
    5656 
     
    184184      } 
    185185 
    186       comm.my_buffer->void_buffer[0] = recvbuf; 
     186      comm->my_buffer->void_buffer[0] = recvbuf; 
    187187    } 
    188188    else 
    189189    { 
    190       comm.my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);   
     190      comm->my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);   
    191191      memcpy(recvbuf, sendbuf, datasize*count); 
    192192    }  
     
    196196    MPI_Barrier_local(comm); 
    197197 
    198     memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize*count); 
     198    memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize*count); 
    199199 
    200200 
     
    205205        assert (datasize == sizeof(int)); 
    206206        for(int i=1; i<ep_rank_loc+1; i++) 
    207           reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     207          reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    208208      } 
    209209      
     
    212212        assert(datasize == sizeof(float)); 
    213213        for(int i=1; i<ep_rank_loc+1; i++) 
    214           reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     214          reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    215215      } 
    216216       
     
    220220        assert(datasize == sizeof(double)); 
    221221        for(int i=1; i<ep_rank_loc+1; i++) 
    222           reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     222          reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    223223      } 
    224224 
     
    227227        assert(datasize == sizeof(char)); 
    228228        for(int i=1; i<ep_rank_loc+1; i++) 
    229           reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     229          reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    230230      } 
    231231 
     
    234234        assert(datasize == sizeof(long)); 
    235235        for(int i=1; i<ep_rank_loc+1; i++) 
    236           reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     236          reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    237237      } 
    238238 
     
    241241        assert(datasize == sizeof(unsigned long)); 
    242242        for(int i=1; i<ep_rank_loc+1; i++) 
    243           reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     243          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    244244      } 
    245245 
     
    255255        assert(datasize == sizeof(int)); 
    256256        for(int i=1; i<ep_rank_loc+1; i++) 
    257           reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     257          reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    258258      } 
    259259 
     
    262262        assert(datasize == sizeof(float)); 
    263263        for(int i=1; i<ep_rank_loc+1; i++) 
    264           reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     264          reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    265265      } 
    266266 
     
    269269        assert(datasize == sizeof(double)); 
    270270        for(int i=1; i<ep_rank_loc+1; i++) 
    271           reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     271          reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    272272      } 
    273273 
     
    276276        assert(datasize == sizeof(char)); 
    277277        for(int i=1; i<ep_rank_loc+1; i++) 
    278           reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     278          reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    279279      } 
    280280 
     
    283283        assert(datasize == sizeof(long)); 
    284284        for(int i=1; i<ep_rank_loc+1; i++) 
    285           reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     285          reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    286286      } 
    287287 
     
    290290        assert(datasize == sizeof(unsigned long)); 
    291291        for(int i=1; i<ep_rank_loc+1; i++) 
    292           reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     292          reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    293293      } 
    294294      
     
    302302        assert(datasize == sizeof(int)); 
    303303        for(int i=1; i<ep_rank_loc+1; i++) 
    304           reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
     304          reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);     
    305305      } 
    306306 
     
    309309        assert(datasize == sizeof(float)); 
    310310        for(int i=1; i<ep_rank_loc+1; i++) 
    311           reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
     311          reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);     
    312312      } 
    313313 
     
    316316        assert(datasize == sizeof(double)); 
    317317        for(int i=1; i<ep_rank_loc+1; i++) 
    318           reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
     318          reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 
    319319      } 
    320320 
     
    323323        assert(datasize == sizeof(char)); 
    324324        for(int i=1; i<ep_rank_loc+1; i++) 
    325           reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
     325          reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 
    326326      } 
    327327 
     
    330330        assert(datasize == sizeof(long)); 
    331331        for(int i=1; i<ep_rank_loc+1; i++) 
    332           reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
     332          reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 
    333333      } 
    334334 
     
    337337        assert(datasize == sizeof(unsigned long)); 
    338338        for(int i=1; i<ep_rank_loc+1; i++) 
    339           reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
     339          reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);     
    340340      } 
    341341 
     
    350350  int MPI_Scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 
    351351  { 
    352     if(!comm.is_ep) 
    353     { 
    354       return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     352    if(!comm->is_ep) 
     353    { 
     354      return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    355355    } 
    356356     
    357357    valid_type(datatype); 
    358358 
    359     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    360     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    361     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    362     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    363     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    364     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     359    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     360    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     361    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     362    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     363    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     364    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    365365 
    366366    ::MPI_Aint datasize, lb; 
     
    375375    std::vector<int> my_map(mpi_size, 0); 
    376376 
    377     for(int i=0; i<comm.rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++; 
     377    for(int i=0; i<comm->ep_rank_map->size(); i++) my_map[comm->ep_rank_map->at(i).second]++; 
    378378 
    379379    for(int i=0; i<mpi_rank; i++) my_src += my_map[i]; 
     
    416416 
    417417    if(ep_rank_loc == 0) 
    418       ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm)); 
     418      ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 
    419419 
    420420    //printf(" ID=%d : %d  %d \n", ep_rank, static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp

    r1365 r1520  
    2424    ::MPI_Type_get_extent(to_mpi_type(sendtype), &lb, &datasize); 
    2525 
    26     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    27     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
     26    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     27    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
    2828 
    2929 
    3030    if(ep_rank_loc == local_root) 
    31       comm.my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf); 
     31      comm->my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf); 
    3232 
    3333    MPI_Barrier_local(comm); 
    3434 
    3535    #pragma omp critical (_scatter)       
    36     memcpy(recvbuf, comm.my_buffer->void_buffer[local_root]+datasize*ep_rank_loc*sendcount, datasize * recvcount); 
     36    memcpy(recvbuf, comm->my_buffer->void_buffer[local_root]+datasize*ep_rank_loc*sendcount, datasize * recvcount); 
    3737     
    3838 
     
    4242  int MPI_Scatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) 
    4343  { 
    44     if(!comm.is_ep) 
     44    if(!comm->is_ep) 
    4545    { 
    46       return ::MPI_Scatter(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm.mpi_comm)); 
     46      return ::MPI_Scatter(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm)); 
    4747    } 
    4848    
    4949    assert(sendcount == recvcount); 
    5050 
    51     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    52     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    53     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    54     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    55     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    56     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     51    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     52    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     53    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     54    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     55    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     56    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    5757 
    58     int root_mpi_rank = comm.rank_map->at(root).second; 
    59     int root_ep_loc = comm.rank_map->at(root).first; 
     58    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     59    int root_ep_loc = comm->ep_rank_map->at(root).first; 
    6060 
    6161    bool is_master = (ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root; 
     
    8787      for(int i=0; i<ep_size; i++) 
    8888      { 
    89         recvcounts[comm.rank_map->at(i).second]++; 
     89        recvcounts[comm->ep_rank_map->at(i).second]++; 
    9090      } 
    9191 
     
    9393        displs[i] = displs[i-1] + recvcounts[i-1]; 
    9494 
    95       ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     95      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    9696    } 
    9797 
     
    121121    { 
    122122      int local_sendcount = num_ep * count; 
    123       ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     123      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    124124       
    125125      if(is_root) for(int i=1; i<mpi_size; i++) displs[i] = displs[i-1] + recvcounts[i-1]; 
    126126 
    127       ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), displs.data(), to_mpi_type(sendtype), local_recvbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     127      ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), displs.data(), to_mpi_type(sendtype), local_recvbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    128128 
    129129      // printf("local_recvbuf = %d %d %d %d\n", static_cast<int*>(local_recvbuf)[0], static_cast<int*>(local_recvbuf)[1], static_cast<int*>(local_recvbuf)[2], static_cast<int*>(local_recvbuf)[3]); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp

    r1365 r1520  
    2525    ::MPI_Type_get_extent(to_mpi_type(sendtype), &lb, &datasize); 
    2626 
    27     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    28     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
     27    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     28    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
    2929 
    3030    assert(recvcount == sendcounts[ep_rank_loc]); 
    3131 
    3232    if(ep_rank_loc == local_root) 
    33       comm.my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf); 
     33      comm->my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf); 
    3434 
    3535    MPI_Barrier_local(comm); 
    3636 
    3737    #pragma omp critical (_scatterv)       
    38     memcpy(recvbuf, comm.my_buffer->void_buffer[local_root]+datasize*displs[ep_rank_loc], datasize * recvcount); 
     38    memcpy(recvbuf, comm->my_buffer->void_buffer[local_root]+datasize*displs[ep_rank_loc], datasize * recvcount); 
    3939     
    4040 
     
    4545                   MPI_Datatype recvtype, int root, MPI_Comm comm) 
    4646  { 
    47     if(!comm.is_ep) 
     47    if(!comm->is_ep) 
    4848    { 
    49       return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm.mpi_comm)); 
     49      return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm)); 
    5050    } 
    5151    
    5252    assert(sendtype == recvtype); 
    5353 
    54     int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    55     int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    56     int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    57     int ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    58     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    59     int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     54    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     55    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     56    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     57    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     58    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     59    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    6060 
    61     int root_mpi_rank = comm.rank_map->at(root).second; 
    62     int root_ep_loc = comm.rank_map->at(root).first; 
     61    int root_mpi_rank = comm->ep_rank_map->at(root).second; 
     62    int root_ep_loc = comm->ep_rank_map->at(root).first; 
    6363 
    6464    bool is_master = (ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root; 
     
    9090      for(int i=0; i<ep_size; i++) 
    9191      { 
    92         recvcounts[comm.rank_map->at(i).second]++; 
     92        recvcounts[comm->ep_rank_map->at(i).second]++; 
    9393      } 
    9494 
     
    9696        my_displs[i] = my_displs[i-1] + recvcounts[i-1]; 
    9797 
    98       ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     98      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    9999    } 
    100100 
     
    124124      local_sendbuf = new void*[datasize * local_sendcount]; 
    125125  
    126       ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     126      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    127127 
    128128      if(is_root) for(int i=1; i<mpi_size; i++) my_displs[i] = my_displs[i-1] + recvcounts[i-1]; 
    129129 
    130       ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), my_displs.data(), to_mpi_type(sendtype), local_sendbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm)); 
     130      ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), my_displs.data(), to_mpi_type(sendtype), local_sendbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 
    131131 
    132132      // printf("my_displs = %d %d %d %d\n", my_displs[0], my_displs[1], my_displs[2], my_displs[3] ); 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp

    r1373 r1520  
    1212 
    1313 
    14 namespace ep_lib { 
    15  
    16  
     14namespace ep_lib  
     15{ 
     16   
    1717  int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
    1818  { 
    19     if(!comm.is_ep) 
    20       return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm)); 
    21     if(comm.is_intercomm) 
    22     { 
    23       MPI_Request request; 
    24       MPI_Status status; 
    25       MPI_Isend(buf, count, datatype, dest, tag, comm, &request); 
    26       MPI_Wait(&request, &status); 
    27     } 
    28     else 
    29     { 
    30       int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first; 
    31       int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; 
    32       int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    33       int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; 
    34  
    35       ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm)); 
    36       //printf("call mpi_send for intracomm, dest = %d, tag = %d\n", dest, tag); 
    37     } 
    38     //check_sum_send(buf, count, datatype, dest, tag, comm); 
    39  
    40     return 0; 
     19    if(!comm->is_ep)       return MPI_Send_mpi(buf, count, datatype, dest, tag, comm); 
     20    if(comm->is_intercomm) return MPI_Send_intercomm(buf, count, datatype, dest, tag, comm); 
     21     
     22    Debug("\nMPI_Send with EP\n"); 
     23     
     24    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first; 
     25    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; 
     26    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     27    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; 
     28 
     29#ifdef _check_sum     
     30    check_sum_send(buf, count, datatype, dest, tag, comm); 
     31#endif 
     32 
     33    return ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm)); 
    4134  } 
    4235 
     
    4437  int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
    4538  { 
    46     if(!comm.is_ep) 
    47     { 
    48       return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm)); 
    49     } 
    50  
     39    if(!comm->is_ep)       return MPI_Ssend_mpi(buf, count, datatype, dest, tag, comm); 
     40    if(comm->is_intercomm) return MPI_Ssend_intercomm(buf, count, datatype, dest, tag, comm); 
     41     
     42    Debug("\nMPI_Ssend with EP\n"); 
     43 
     44    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first; 
     45    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; 
     46    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     47    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; 
     48     
     49#ifdef _check_sum     
     50    check_sum_send(buf, count, datatype, dest, tag, comm); 
     51#endif 
     52     
     53    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm)); 
     54  } 
     55   
     56 
     57 
     58 
     59 
     60  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     61  { 
     62    if(!comm->is_ep)       return MPI_Isend_mpi(buf, count, datatype, dest, tag, comm, request); 
     63    if(comm->is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request); 
     64 
     65    Debug("\nMPI_Isend with EP\n"); 
     66    
     67    int src_rank; 
     68    MPI_Comm_rank(comm, &src_rank); 
     69 
     70 
     71#ifdef _check_sum     
     72    check_sum_send(buf, count, datatype, dest, tag, comm); 
     73#endif 
     74     
     75    *request = new ep_request; 
     76    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend, *request = new ep_request"); 
     77 
     78    (*request)->mpi_request = new ::MPI_Request; 
     79    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend, (*request)->mpi_request = new ::MPI_Request"); 
     80     
     81 
     82    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first; 
     83    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; 
     84    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     85    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; 
     86 
     87    (*request)->ep_src  = src_rank; 
     88    (*request)->ep_tag  = tag; 
     89    (*request)->ep_datatype = datatype; 
     90 
     91    (*request)->type = 1;    // used in wait 
     92    (*request)->comm = comm; 
     93    (*request)->buf = const_cast<void*>(buf); 
     94 
     95 
     96    return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
     97  } 
     98 
     99 
     100 
     101 
     102  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     103  { 
     104  
     105    if(!comm->is_ep) return MPI_Issend_mpi(buf, count, datatype, dest, tag, comm, request); 
     106    if(comm->is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request); 
     107 
     108    Debug("\nMPI_Issend with EP\n"); 
     109    
     110    int src_rank; 
     111    MPI_Comm_rank(comm, &src_rank); 
     112 
     113 
     114#ifdef _check_sum     
     115    check_sum_send(buf, count, datatype, dest, tag, comm); 
     116#endif 
     117     
     118    *request = new ep_request; 
     119    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend, *request = new ep_request"); 
     120 
     121    (*request)->mpi_request = new ::MPI_Request; 
     122    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend, (*request)->mpi_request = new ::MPI_Request"); 
     123     
     124 
     125    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first; 
     126    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first; 
     127    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     128    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second; 
     129 
     130    (*request)->ep_src  = src_rank; 
     131    (*request)->ep_tag  = tag; 
     132    (*request)->ep_datatype = datatype; 
     133 
     134    (*request)->type = 1;    // used in wait 
     135    (*request)->comm = comm; 
     136    (*request)->buf = const_cast<void*>(buf); 
     137     
     138    return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));     
     139  } 
     140   
     141  int MPI_Send_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
     142  { 
     143    Debug("\nMPI_Send with MPI\n"); 
     144    return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm)); 
     145  } 
     146   
     147  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
     148  { 
     149    Debug("\nMPI_Send_intercomm with EP\n"); 
     150    MPI_Request request; 
     151    MPI_Status status; 
     152    MPI_Isend(buf, count, datatype, dest, tag, comm, &request); 
     153    MPI_Wait(&request, &status); 
     154    return MPI_SUCCESS; 
     155  } 
     156   
     157   
     158  int MPI_Ssend_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
     159  { 
     160    Debug("\nMPI_Ssend with MPI\n"); 
     161    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm)); 
     162  } 
     163   
     164 
     165  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
     166  { 
     167    Debug("\nMPI_Ssend_intercomm with EP\n"); 
    51168    MPI_Request request; 
    52169    MPI_Status status; 
    53170    MPI_Issend(buf, count, datatype, dest, tag, comm, &request); 
    54171    MPI_Wait(&request, &status); 
    55     //check_sum_send(buf, count, datatype, dest, tag, comm); 
    56     return 0; 
    57   } 
    58    
    59  
    60  
    61  
    62  
    63   int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
    64   { 
    65     Debug("\nMPI_Isend with EP\n"); 
    66     int src_rank; 
    67     MPI_Comm_rank(comm, &src_rank); 
    68  
    69      
    70  
    71     if(!comm.is_ep) 
     172    return MPI_SUCCESS; 
     173  } 
     174   
     175  int MPI_Isend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     176  { 
     177    Debug("\nMPI_Isend with MPI\n"); 
     178     
     179    int src_rank; 
     180    MPI_Comm_rank(comm, &src_rank); 
     181     
     182    *request = new ep_request; 
     183    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_mpi, *request = new ep_request"); 
     184 
     185    (*request)->mpi_request = new ::MPI_Request; 
     186    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_mpi, (*request)->mpi_request = new ::MPI_Request"); 
     187       
     188    (*request)->ep_src = src_rank; 
     189    (*request)->ep_tag = tag; 
     190    (*request)->ep_datatype = datatype; 
     191    (*request)->type = 1; 
     192    (*request)->comm = comm; 
     193     
     194    return ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
     195  } 
     196   
     197  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     198  { 
     199    Debug("\nMPI_Isend_intercomm with EP\n"); 
     200 
     201#ifdef _check_sum     
     202    check_sum_send(buf, count, datatype, dest, tag, comm); 
     203#endif 
     204 
     205    int src_comm_label  = comm->ep_comm_ptr->comm_label; 
     206    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second; 
     207     
     208    int src_rank; 
     209    MPI_Comm_rank(comm, &src_rank); 
     210 
     211     
     212    *request = new ep_request; 
     213    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request"); 
     214 
     215    (*request)->mpi_request = new ::MPI_Request; 
     216    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request"); 
     217     
     218 
     219    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first; 
     220    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first; 
     221    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     222    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first; 
     223 
     224#ifdef _showinfo 
     225    printf("Send : ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag); 
     226#endif 
     227     
     228 
     229    (*request)->ep_src  = src_rank; 
     230    (*request)->ep_tag  = tag; 
     231    (*request)->ep_datatype = datatype; 
     232 
     233    (*request)->type = 1;    // used in wait 
     234    (*request)->comm = comm; 
     235    (*request)->buf = const_cast<void*>(buf); 
     236 
     237 
     238    if(src_comm_label == dest_comm_label) 
    72239    { 
    73       ::MPI_Request mpi_request; 
    74       ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    75  
    76       request->mpi_request = new ::MPI_Request(mpi_request); 
    77  
    78       request->ep_src = src_rank; 
    79       request->ep_tag = tag; 
    80       request->ep_datatype = datatype; 
    81       request->type = 1; 
    82       request->comm = comm; 
    83  
    84       return 0; 
     240      Debug("\nMPI_Isend_intercomm with EP_intracomm\n"); 
     241      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
    85242    } 
    86243 
    87     if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request); 
    88  
    89     // EP intracomm 
    90  
    91     //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
    92  
    93     int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first; 
    94     int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; 
    95     int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    96     int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; 
    97  
    98     request->ep_src  = src_rank; 
    99     request->ep_tag  = tag; 
    100     request->ep_datatype = datatype; 
    101  
    102     ::MPI_Request mpi_request; 
    103  
    104     ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    105  
    106     request->mpi_request = new ::MPI_Request(mpi_request); 
    107     request->type = 1;    // used in wait 
    108     request->comm = comm; 
    109     request->buf = const_cast<void*>(buf); 
    110  
    111     //Message_Check(comm); 
    112  
    113     return 0; 
    114   } 
    115  
    116  
    117  
    118  
    119   int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
    120   { 
    121     Debug("\nMPI_Issend with EP\n"); 
    122  
    123     int src_rank; 
    124     MPI_Comm_rank(comm, &src_rank); 
    125  
    126      
    127  
    128     if(!comm.is_ep) 
     244    else 
    129245    { 
    130       ::MPI_Request mpi_request; 
    131       ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    132  
    133       request->mpi_request = new ::MPI_Request(mpi_request); 
    134       request->ep_src = src_rank; 
    135       request->ep_tag = tag; 
    136       request->ep_datatype = datatype; 
    137       request->type = 1; 
    138       request->comm = comm; 
    139  
    140       return 0; 
     246      Debug("\nMPI_Isend_intercomm with EP_intercomm\n"); 
     247      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request)); 
    141248    } 
    142  
    143     if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request); 
    144  
    145     // EP intracomm 
    146  
    147     //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
    148  
    149     int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first; 
    150     int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; 
    151     int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    152     int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; 
    153      
    154     request->ep_src = src_rank; 
    155     request->ep_tag = tag; 
    156     request->ep_datatype = datatype; 
    157  
    158     ::MPI_Request mpi_request; 
    159  
    160     ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    161  
    162     request->mpi_request = new ::MPI_Request(mpi_request); 
    163     request->type = 1;    // used in wait 
    164     request->comm = comm; 
    165     request->buf = NULL; 
    166      
    167  
    168     //Message_Check(comm); 
    169  
    170     return 0; 
    171   } 
    172    
    173  
    174  
    175  
    176   int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
    177   { 
    178     Debug("MPI_Isend with intercomm\n"); 
    179  
    180     //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
    181  
    182     int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first; 
    183     int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second; 
    184  
    185     int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; 
    186     int src_comm_label; 
    187  
    188     src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second; 
    189  
    190  
    191      
    192  
    193     //Message_Check(comm); 
    194  
    195  
    196     if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs 
     249  } 
     250 
     251 
     252 
     253 
     254  int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     255  { 
     256    Debug("\nMPI_Issend with MPI\n"); 
     257     
     258    int src_rank; 
     259    MPI_Comm_rank(comm, &src_rank); 
     260     
     261    *request = new ep_request; 
     262    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_mpi, *request = new ep_request"); 
     263 
     264    (*request)->mpi_request = new ::MPI_Request; 
     265    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_mpi, (*request)->mpi_request = new ::MPI_Request"); 
     266       
     267    (*request)->ep_src = src_rank; 
     268    (*request)->ep_tag = tag; 
     269    (*request)->ep_datatype = datatype; 
     270    (*request)->type = 1; 
     271    (*request)->comm = comm; 
     272     
     273    return ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
     274  } 
     275 
     276 
     277  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     278  { 
     279    Debug("\nMPI_Issend_intercomm with EP\n"); 
     280 
     281#ifdef _check_sum     
     282    check_sum_send(buf, count, datatype, dest, tag, comm); 
     283#endif 
     284 
     285    int src_comm_label  = comm->ep_comm_ptr->comm_label; 
     286    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second; 
     287     
     288    int src_rank; 
     289    MPI_Comm_rank(comm, &src_rank); 
     290 
     291     
     292    *request = new ep_request; 
     293    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request"); 
     294 
     295    (*request)->mpi_request = new ::MPI_Request; 
     296    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request"); 
     297     
     298 
     299    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first; 
     300    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first; 
     301    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     302    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first; 
     303 
     304#ifdef _showinfo 
     305    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag); 
     306#endif 
     307     
     308    (*request)->ep_src  = src_rank; 
     309    (*request)->ep_tag  = tag; 
     310    (*request)->ep_datatype = datatype; 
     311 
     312    (*request)->type = 1;    // used in wait 
     313    (*request)->comm = comm; 
     314    (*request)->buf = const_cast<void*>(buf); 
     315 
     316 
     317    if(src_comm_label == dest_comm_label) 
    197318    { 
    198       int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
    199       int ep_src_loc = comm.rank_map->at(inter_src).first; 
    200       int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first; 
    201       int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second; 
    202       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    203  
    204       ::MPI_Request mpi_request; 
    205    
    206       ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    207  
    208       request->mpi_request = new ::MPI_Request(mpi_request); 
    209       request->type = 1;    // used in wait 
    210       request->comm = comm; 
    211  
    212       request->ep_src = src_ep_rank; 
    213       request->ep_tag = tag; 
    214       request->ep_datatype = datatype; 
     319      Debug("\nMPI_Issend_intercomm with EP_intracomm\n"); 
     320      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request)); 
    215321    } 
    216322 
    217     else   // dest_remote_comm_label != src_comm_label 
    218     {  
    219       int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
    220       int ep_src_loc = comm.rank_map->at(inter_src).first; 
    221       int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first; 
    222       int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second; 
    223       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    224  
    225       ::MPI_Request mpi_request; 
    226  
    227       ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request); 
    228  
    229       request->mpi_request = new ::MPI_Request(mpi_request); 
    230       request->type = 1;    // used in wait 
    231       request->comm = comm; 
    232     
    233       request->ep_src = src_ep_rank; 
    234       request->ep_tag = tag; 
    235       request->ep_datatype = datatype; 
     323    else 
     324    { 
     325      Debug("\nMPI_Issend_intercomm with EP_intercomm\n"); 
     326      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request)); 
    236327    } 
    237  
    238     return 0; 
    239  
    240   } 
    241  
    242  
    243   int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
    244   { 
    245     Debug("MPI_Issend with intercomm\n"); 
    246  
    247     //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
    248  
    249     int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first; 
    250     int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second; 
    251  
    252     int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; 
    253     int src_comm_label; 
    254  
    255     for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++) 
    256     { 
    257       if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank) 
    258       { 
    259         src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second; 
    260         break; 
    261       } 
    262     } 
    263  
    264     //Message_Check(comm); 
    265  
    266  
    267     if(dest_remote_comm_label == src_comm_label)       // dest rank (loc, mpi) differs 
    268     { 
    269       int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
    270       int ep_src_loc = comm.rank_map->at(inter_src).first; 
    271       int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first; 
    272       int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second; 
    273       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    274  
    275       ::MPI_Request mpi_request; 
    276    
    277       ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 
    278  
    279       request->mpi_request = new ::MPI_Request(mpi_request); 
    280       request->type = 1;    // used in wait 
    281       request->comm = comm; 
    282  
    283       request->ep_src = src_ep_rank; 
    284       request->ep_tag = tag; 
    285       request->ep_datatype = datatype; 
    286     } 
    287  
    288     else   // dest_remote_comm_label != src_comm_label 
    289     {  
    290       int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
    291       int ep_src_loc = comm.rank_map->at(inter_src).first; 
    292       int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first; 
    293       int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second; 
    294       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
    295  
    296       ::MPI_Request mpi_request; 
    297  
    298       ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request); 
    299  
    300       request->mpi_request = new ::MPI_Request(mpi_request); 
    301       request->type = 1;    // used in wait 
    302       request->comm = comm; 
    303     
    304       request->ep_src = src_ep_rank; 
    305       request->ep_tag = tag; 
    306       request->ep_datatype = datatype; 
    307     } 
    308  
    309     return 0; 
    310  
    311328  } 
    312329   
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp

    r1354 r1520  
    77{ 
    88 
    9  
    10  
    11  
    129  int MPI_Comm_size(MPI_Comm comm, int* size) 
    1310  { 
    14      
    15     if(comm.is_ep) 
     11    if(comm->is_ep) 
    1612    { 
    17       if(!comm.is_intercomm) 
    18       { 
    19         *size = comm.ep_comm_ptr->size_rank_info[0].second; 
    20  
    21         return 0; 
    22       } 
    23       else 
    24       { 
    25         *size = comm.ep_comm_ptr->intercomm->size_rank_info[0].second; 
    26  
    27         return 0; 
    28       } 
    29  
     13      Debug("MPI_Comm_size with EP"); 
     14      return *size = comm->ep_comm_ptr->size_rank_info[0].second; 
    3015    } 
    3116 
    32     Debug("Calling EP_Comm_size\n"); 
    33  
    34     if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 
    35     { 
    36       ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);  
    37       int mpi_size; 
    38  
    39       ::MPI_Comm_size(mpi_comm, &mpi_size); 
    40       printf("============ ep comm size called for non ep comm, %d\n", mpi_size); 
    41       *size = mpi_size; 
    42       return 0; 
    43     } 
    44  
    45     else 
    46     { 
    47       *size = MPI_UNDEFINED; 
    48       printf("============ ep comm size called for non ep comm not defined\n"); 
    49       return 0; 
    50     } 
     17    return MPI_Comm_size_mpi(comm, size); 
    5118  } 
    5219 
    5320  int MPI_Comm_remote_size(MPI_Comm comm, int *size) 
    5421  { 
    55     if(!comm.is_ep) 
     22    if(comm->is_ep) 
    5623    { 
    57       if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 
     24      if(comm->is_intercomm) 
    5825      { 
    59         ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);  
    60         ::MPI_Comm_remote_size(mpi_comm, size); 
    61         return 0; 
     26        Debug("MPI_Comm_remote_size with EP_intercomm"); 
     27        return *size = comm->ep_comm_ptr->intercomm->intercomm_rank_map->size(); 
    6228      } 
    63  
    6429      else 
    6530      { 
    66         *size = MPI_UNDEFINED; 
    67         return 0; 
     31        Debug("MPI_Comm_remote_size with EP_intracomm"); 
     32        return *size=0; 
    6833      } 
    6934    } 
    70      
    71     if(comm.is_intercomm) 
    72     { 
    73       *size = comm.ep_comm_ptr->intercomm->remote_rank_map->size(); 
    74       return 0; 
    75     } 
    76     *size = MPI_UNDEFINED; 
    77     return 0;  
     35    return MPI_Comm_remote_size_mpi(comm, size); 
    7836  } 
     37 
     38 
     39  int MPI_Comm_size_mpi(MPI_Comm comm, int* size) 
     40  { 
     41    Debug("MPI_Comm_size with MPI"); 
     42    return ::MPI_Comm_size(to_mpi_comm(comm->mpi_comm), size); 
     43  } 
     44 
     45  int MPI_Comm_remote_size_mpi(MPI_Comm comm, int *size) 
     46  { 
     47    Debug("MPI_Comm_remote_size with MPI"); 
     48    return ::MPI_Comm_remote_size(to_mpi_comm(comm->mpi_comm), size); 
     49  } 
     50 
     51 
    7952} 
    8053 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp

    r1354 r1520  
    3131    inout_vector->swap(out_vec); 
    3232  } 
     33   
     34  void vec_simplify(std::vector<int> *in_vector, std::vector<int> *out_vector) 
     35  { 
     36    int found=false; 
     37    for(std::vector<int>::iterator it_in = in_vector->begin() ; it_in != in_vector->end(); ++it_in) 
     38    { 
     39      for(std::vector<int>::iterator it = out_vector->begin() ; it != out_vector->end(); ++it) 
     40      { 
     41        if(*it_in == *it) 
     42        { 
     43          found=true; 
     44          break; 
     45        } 
     46        else found=false; 
     47      } 
     48      if(found == false) 
     49      { 
     50        out_vector->push_back(*it_in); 
     51      } 
     52    } 
     53  } 
    3354 
    3455 
     
    3960    int ep_size, num_ep, mpi_size; 
    4061 
    41     ep_rank = comm.ep_comm_ptr->size_rank_info[0].first; 
    42     ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
    43     mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first; 
    44     ep_size = comm.ep_comm_ptr->size_rank_info[0].second; 
    45     num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 
    46     mpi_size = comm.ep_comm_ptr->size_rank_info[2].second; 
     62    ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 
     63    ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 
     64    mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 
     65    ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 
     66    num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 
     67    mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 
    4768 
    4869    int num_color = 0; 
     
    5273    vector<int> matched_number; 
    5374    vector<int> matched_number_loc; 
    54  
    55  
     75     
    5676    vector<int> all_color(ep_size); 
    5777    vector<int> all_color_loc(num_ep); 
    5878 
    59     MPI_Gather_local(&color, 1, MPI_INT, all_color_loc.data(), 0, comm); 
    60     MPI_Bcast_local(all_color_loc.data(), num_ep, MPI_INT, 0, comm); 
    61  
    62  
    6379    MPI_Allgather(&color, 1, MPI_INT, all_color.data(), 1, MPI_INT, comm); 
     80    MPI_Allgather_local(&color, 1, MPI_INT, all_color_loc.data(), comm); 
    6481 
    6582    list<int> color_list(all_color.begin(), all_color.end()); 
    6683    list<int> color_list_loc(all_color_loc.begin(), all_color_loc.end()); 
    6784 
    68     vec_simplify(&all_color); 
    69  
    70     matched_number.resize(all_color.size(), 0); 
    71     matched_number_loc.resize(all_color.size(), 0); 
     85    vector<int> all_color_simplified; 
     86    vec_simplify(&all_color, &all_color_simplified); 
     87    int number_of_color; 
     88    for(int i=0; i<all_color_simplified.size(); i++) 
     89    { 
     90      if(color == all_color_simplified[i]) 
     91      { 
     92        number_of_color = i; 
     93        break; 
     94      } 
     95    } 
     96 
     97    matched_number.resize(all_color_simplified.size(), 0); 
     98    matched_number_loc.resize(all_color_simplified.size(), 0); 
    7299 
    73100 
     
    93120      num_color++; 
    94121    } 
    95  
    96  
     122         
     123 
     124    vector<int> all_key(ep_size); 
     125    vector<int> all_key_loc(num_ep); 
     126     
     127    vector<int> colored_key[num_color]; 
    97128    vector<int> colored_key_loc[num_color]; 
    98     vector<int> key_loc(num_ep); 
    99  
    100     MPI_Gather_local(&key, 1, MPI_INT, key_loc.data(), 0, comm); 
    101     MPI_Bcast_local(key_loc.data(), num_ep, MPI_INT, 0, comm); 
    102      
    103     std::sort(key_loc.begin(), key_loc.end()); 
     129     
     130 
     131    MPI_Allgather(&key, 1, MPI_INT, all_key.data(),1, MPI_INT, comm); 
     132    MPI_Allgather_local(&key, 1, MPI_INT, all_key_loc.data(), comm); 
     133     
     134    vector<int> all_ep_rank(ep_size); 
     135    vector<int> all_ep_rank_loc(num_ep); 
     136     
     137    vector<int> colored_ep_rank[num_color]; 
     138    vector<int> colored_ep_rank_loc[num_color]; 
     139     
     140    MPI_Allgather(&ep_rank, 1, MPI_INT, all_ep_rank.data(),1, MPI_INT, comm); 
     141    MPI_Allgather_local(&ep_rank, 1, MPI_INT, all_ep_rank_loc.data(), comm); 
    104142 
    105143    for(int i=0; i<num_ep; i++) 
     
    107145      for(int j = 0; j<num_color; j++) 
    108146      { 
    109         if(all_color_loc[i] == all_color[j]) 
    110         { 
    111           colored_key_loc[j].push_back(key_loc[i]); 
    112         } 
    113       } 
    114     } 
    115  
     147        if(all_color_loc[i] == all_color_simplified[j]) 
     148        { 
     149          colored_key_loc[j].push_back(all_key_loc[i]); 
     150          colored_ep_rank_loc[j].push_back(all_ep_rank_loc[i]); 
     151        } 
     152      } 
     153    } 
     154     
     155    for(int i=0; i<ep_size; i++) 
     156    { 
     157      for(int j = 0; j<num_color; j++) 
     158      { 
     159        if(all_color[i] == all_color_simplified[j]) 
     160        { 
     161          colored_key[j].push_back(all_key[i]); 
     162          colored_ep_rank[j].push_back(all_ep_rank[i]); 
     163        } 
     164      } 
     165    } 
     166     
     167    int my_offset=0; 
     168    for(int i=0; i<colored_key[number_of_color].size(); i++) 
     169    { 
     170      if(key == colored_key[number_of_color][i]) 
     171      { 
     172        if(ep_rank != colored_ep_rank[number_of_color][i]) 
     173        { 
     174          my_offset++; 
     175        } 
     176        else 
     177          break; 
     178      } 
     179    } 
     180     
     181    int my_offset_loc=0; 
     182    for(int i=0; i<colored_key_loc[number_of_color].size(); i++) 
     183    { 
     184      if(key == colored_key_loc[number_of_color][i]) 
     185      { 
     186        if(ep_rank != colored_ep_rank_loc[number_of_color][i]) 
     187        { 
     188          my_offset_loc++; 
     189        } 
     190        else 
     191          break; 
     192      } 
     193    } 
     194     
     195     
     196     
     197    for(int i=0; i<num_color; i++) 
     198    { 
     199      std::sort(colored_key[i].begin(), colored_key[i].end()); 
     200      std::sort(colored_key_loc[i].begin(), colored_key_loc[i].end()); 
     201    } 
     202 
     203    int new_ep_rank; 
     204     
     205    for(int i=0; i<colored_key[number_of_color].size(); i++) 
     206    { 
     207      if(key == colored_key[number_of_color][i]) 
     208      { 
     209        new_ep_rank = i+my_offset; 
     210        break; 
     211      } 
     212    } 
     213     
    116214    int new_ep_rank_loc; 
    117  
    118     for(int i=0; i<num_color; i++) 
    119     { 
    120       if(colored_key_loc[i].size()>1) 
    121       { 
    122         std::sort(colored_key_loc[i].begin(), colored_key_loc[i].end()); 
    123       } 
    124       if(color == all_color[i]) 
    125       { 
    126         for(int j=0; j<colored_key_loc[i].size(); j++) 
    127         { 
    128           if(key == colored_key_loc[i][j]) 
    129           { 
    130             new_ep_rank_loc = j; 
    131             break; 
    132           } 
    133         } 
    134       } 
    135     } 
     215     
     216    for(int i=0; i<colored_key_loc[number_of_color].size(); i++) 
     217    { 
     218      if(key == colored_key_loc[number_of_color][i]) 
     219      { 
     220        new_ep_rank_loc = i+my_offset_loc; 
     221        break; 
     222      } 
     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); 
     232     
    136233 
    137234    ::MPI_Comm **split_mpi_comm; 
     
    147244        if(matched_number_loc[j] == 0) master_color = MPI_UNDEFINED; 
    148245 
    149         ::MPI_Comm_split(to_mpi_comm(comm.mpi_comm), master_color, mpi_rank, split_mpi_comm[j]); 
    150          
    151         comm.ep_comm_ptr->comm_list->mpi_bridge = split_mpi_comm[j]; 
    152       } 
     246        ::MPI_Comm_split(to_mpi_comm(comm->mpi_comm), master_color, mpi_rank, split_mpi_comm[j]); 
     247         
     248        comm->ep_comm_ptr->comm_list[0]->mpi_bridge = split_mpi_comm[j]; 
     249      } 
     250       
    153251      MPI_Barrier_local(comm); 
     252       
    154253      int num_new_ep = 0; 
    155254 
    156       if(new_ep_rank_loc == 0 && color == all_color[j]) 
     255      if(new_ep_rank_loc == 0 && color == all_color_simplified[j]) 
    157256      { 
    158257        num_new_ep = matched_number_loc[j]; 
     
    160259        MPI_Comm *ep_comm; 
    161260 
    162         MPI_Comm_create_endpoints(comm.ep_comm_ptr->comm_list->mpi_bridge, num_new_ep, info, ep_comm); 
    163  
    164  
    165         comm.ep_comm_ptr->comm_list->mem_bridge = ep_comm; 
    166       } 
     261        MPI_Comm_create_endpoints(comm->ep_comm_ptr->comm_list[0]->mpi_bridge, num_new_ep, info, ep_comm); 
     262 
     263        comm->ep_comm_ptr->comm_list[0]->mem_bridge = ep_comm; 
     264         
     265        (*ep_comm)->ep_rank_map->clear(); 
     266         
     267        memcheck("in MPI_Split ep_rank="<< ep_rank <<" : *ep_comm = "<< *ep_comm); 
     268      } 
     269       
    167270      MPI_Barrier_local(comm); 
    168       if(color == all_color[j]) 
    169       { 
    170         *newcomm = comm.ep_comm_ptr->comm_list->mem_bridge[new_ep_rank_loc]; 
    171  
    172         (*newcomm).ep_comm_ptr->comm_label = color; 
    173       } 
    174     } 
    175  
    176  
    177  
    178  
     271       
     272      if(color == all_color_simplified[j]) 
     273      { 
     274        *newcomm = comm->ep_comm_ptr->comm_list[0]->mem_bridge[new_ep_rank_loc]; 
     275        memcheck("in MPI_Split ep_rank="<< ep_rank <<" : *newcomm = "<< *newcomm); 
     276 
     277        (*newcomm)->ep_comm_ptr->comm_label = color; 
     278         
     279        (*newcomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank; 
     280        (*newcomm)->ep_comm_ptr->size_rank_info[1].first = new_ep_rank_loc; 
     281         
     282        int my_triple[3]; 
     283        vector<int> my_triple_vector; 
     284        vector<int> my_triple_vector_recv; 
     285        my_triple[0] = new_ep_rank; 
     286        my_triple[1] = new_ep_rank_loc; 
     287        my_triple[2] = (*newcomm)->ep_comm_ptr->size_rank_info[2].first; // new_mpi_rank 
     288         
     289        int new_ep_size = (*newcomm)->ep_comm_ptr->size_rank_info[0].second; 
     290        int new_num_ep  = (*newcomm)->ep_comm_ptr->size_rank_info[1].second; 
     291         
     292        int new_mpi_size = (*newcomm)->ep_comm_ptr->size_rank_info[2].second; 
     293         
     294        if(new_ep_rank_loc == 0) my_triple_vector.resize(3*new_ep_size); 
     295        if(new_ep_rank_loc == 0) my_triple_vector_recv.resize(3*new_ep_size); 
     296         
     297        MPI_Gather_local(my_triple, 3, MPI_INT, my_triple_vector.data(), 0, *newcomm); 
     298         
     299        if(new_ep_rank_loc == 0) 
     300        { 
     301          int *recvcounts = new int[new_mpi_size]; 
     302          int *displs = new int[new_mpi_size]; 
     303          int new_num_epx3 = new_num_ep * 3; 
     304          ::MPI_Allgather(&new_num_epx3, 1, to_mpi_type(MPI_INT), recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
     305          displs[0]=0; 
     306          for(int i=1; i<new_mpi_size; i++) 
     307            displs[i] = displs[i-1] + recvcounts[i-1]; 
     308              
     309          ::MPI_Allgatherv(my_triple_vector.data(), 3*new_num_ep, to_mpi_type(MPI_INT), my_triple_vector_recv.data(), recvcounts, displs, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm)); 
     310           
     311          for(int i=0; i<new_ep_size; i++) 
     312          { 
     313            (*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_vector_recv[3*i], my_triple_vector_recv[3*i+1], my_triple_vector_recv[3*i+2])); 
     314          } 
     315           
     316          (*newcomm)->ep_rank_map = (*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map; 
     317           
     318          delete recvcounts; 
     319          delete displs; 
     320        }  
     321      } 
     322    } 
     323 
     324#ifdef _Memory_check    
     325    for(int i=0; i<ep_size; i++) 
     326    { 
     327      MPI_Barrier(comm); 
     328      MPI_Barrier(comm); 
     329      if(ep_rank==i)  
     330      { 
     331        printf("ep_rank_map for endpoint %d = \n", ep_rank); 
     332        for(std::map<int, std::pair<int, int> > :: iterator it = (*newcomm)->ep_rank_map->begin(); it != (*newcomm)->ep_rank_map->end(); it++) 
     333        { 
     334          printf("\t\t\t %d %d %d\n", it->first, it->second.first, it->second.second); 
     335        } 
     336        printf("\n"); 
     337      } 
     338      MPI_Barrier(comm); 
     339      MPI_Barrier(comm); 
     340    }    
     341#endif 
     342     
    179343    return 0; 
    180344  } 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp

    r1374 r1520  
    2222     
    2323 
    24     if(request->type == 1)      // isend 
     24    if((*request)->type == 1)      // isend 
    2525    { 
    2626      ::MPI_Status mpi_status; 
    27       ::MPI_Test(static_cast< ::MPI_Request*>(request->mpi_request), flag, &mpi_status); 
     27      ::MPI_Test(static_cast< ::MPI_Request*>((*request)->mpi_request), flag, &mpi_status); 
    2828       
    2929      if(*flag)  
    3030      { 
    3131        status->mpi_status = new ::MPI_Status(mpi_status); 
    32         status->ep_src = request->ep_src; 
    33         status->ep_tag = request->ep_tag; 
    34         status->ep_datatype = request->ep_datatype; 
     32        status->ep_src = (*request)->ep_src; 
     33        status->ep_tag = (*request)->ep_tag; 
     34        status->ep_datatype = (*request)->ep_datatype; 
     35        (*request)->state = 2; 
     36        delete (*request)->mpi_request; 
     37        delete *request; 
    3538      } 
    3639 
     
    3841    } 
    3942 
    40     if(request->type == 2)   // irecv message not probed 
     43    if((*request)->type == 2)   // irecv message not probed 
    4144    { 
    4245      Request_Check(); 
     
    4649    } 
    4750 
    48     if(request->type == 3)  // imrecv 
     51    if((*request)->type == 3)  // imrecv 
    4952    { 
     53      if((*request)->state == 2) 
     54      { 
     55        return *flag = true; 
     56      } 
    5057      ::MPI_Status mpi_status; 
    5158       
    52       ::MPI_Test(static_cast< ::MPI_Request*>(request->mpi_request), flag, &mpi_status); 
     59      ::MPI_Test(static_cast< ::MPI_Request*>((*request)->mpi_request), flag, &mpi_status); 
    5360       
    5461       
     
    5663      { 
    5764        status->mpi_status = new ::MPI_Status(mpi_status); 
    58         status->ep_src = request->ep_src; 
    59         status->ep_tag = request->ep_tag; 
    60         status->ep_datatype = request->ep_datatype; 
     65        status->ep_src = (*request)->ep_src; 
     66        status->ep_tag = (*request)->ep_tag; 
     67        status->ep_datatype = (*request)->ep_datatype; 
     68         
     69        (*request)->state = 2; 
     70         
     71        delete (*request)->mpi_request; 
     72        delete *request; 
    6173        //int count; 
    6274        //MPI_Get_count(status, request->ep_datatype, &count); 
     
    6476      }   
    6577 
    66       return 0; 
     78      return Request_Check(); 
    6779    } 
    6880 
     
    7385  { 
    7486    Debug("MPI_Testall with EP"); 
    75     *flag = true; 
    76     int i=0; 
    77     while(*flag && i<count ) 
     87 
     88    ::MPI_Request* mpi_request = new ::MPI_Request[count]; 
     89    ::MPI_Status* mpi_status = new ::MPI_Status[count]; 
     90 
     91 
     92    for(int i=0; i<count; i++) 
    7893    { 
    79       MPI_Test(&array_of_requests[i], flag, &array_of_statuses[i]); 
    80       i++; 
     94      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); 
    8195    } 
     96 
     97    ::MPI_Testall(count, mpi_request, flag, mpi_status); 
     98 
     99    if(*flag) 
     100    { 
     101      for(int i=0; i<count; i++) 
     102      { 
     103        array_of_statuses[i].mpi_status = &mpi_status[i]; 
     104        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; 
     105        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; 
     106        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; 
     107         
     108        array_of_requests[i]->state = 2; 
     109       
     110        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request"); 
     111        delete array_of_requests[i]->mpi_request; 
     112        delete array_of_requests[i];  
     113      } 
     114       
     115    } 
     116 
     117    return Request_Check(); 
    82118  } 
    83119 
    84120 
    85121} 
     122 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp

    r1374 r1520  
    1111namespace ep_lib 
    1212{  
    13    
    14   ep_intercomm::ep_intercomm() 
     13  ep_comm::ep_comm(void* comm) 
    1514  { 
    16     intercomm_rank_map = NULL; 
    17     local_rank_map = NULL; 
    18     remote_rank_map = NULL; 
    19     mpi_inter_comm = new ::MPI_Comm; 
     15    is_ep = false; 
     16    is_intercomm = false; 
     17    mpi_comm = static_cast< ::MPI_Comm*>(comm); 
    2018  } 
    2119 
    22   bool ep_intercomm::operator == (ep_intercomm right) 
     20  ep_info::ep_info(void* info) 
    2321  { 
    24     bool a = intercomm_rank_map == right.intercomm_rank_map; 
    25     bool b = local_rank_map == right.local_rank_map; 
    26     bool c = remote_rank_map == right.remote_rank_map; 
    27     bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm)); 
    28     bool e = size_rank_info == right.size_rank_info; 
    29     bool f = intercomm_tag == right.intercomm_tag; 
    30     return a&&b&&c&&d&&e&&f; 
     22    mpi_info = static_cast< ::MPI_Info*>(info); 
    3123  } 
    3224 
    33   bool ep_intercomm::operator != (ep_intercomm right) 
     25  ep_request::ep_request(void* request) 
    3426  { 
    35     bool a = intercomm_rank_map != right.intercomm_rank_map; 
    36     bool b = local_rank_map != right.local_rank_map; 
    37     bool c = remote_rank_map != right.remote_rank_map; 
    38     bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm)); 
    39     bool e = size_rank_info != right.size_rank_info; 
    40     bool f = intercomm_tag != right.intercomm_tag; 
    41     return a||b||c||d||e||f; 
     27    mpi_request = static_cast< ::MPI_Request*>(request); 
     28  } 
     29   
     30  ep_status::ep_status(void* status) 
     31  { 
     32    mpi_status = static_cast< ::MPI_Status*>(status); 
    4233  } 
    4334 
    44   ep_communicator::ep_communicator() 
    45   { 
    46     comm_list = NULL; 
    47     message_queue = NULL; 
    48     intercomm = NULL; 
    49   } 
    50  
    51   MPI_Message::MPI_Message(void* message) 
    52   { 
    53     mpi_message = new ::MPI_Message; 
    54     *(static_cast< ::MPI_Message*>(mpi_message)) = *(static_cast< ::MPI_Message*>(message)); 
    55   } 
    56  
    57   MPI_Info::MPI_Info(void* info) 
    58   { 
    59     mpi_info = new ::MPI_Info; 
    60     *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(info)); 
    61   } 
    62    
    63   MPI_Info::MPI_Info() 
    64   { 
    65     mpi_info = new ::MPI_Info; 
    66     *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(MPI_INFO_NULL.mpi_info)); 
    67   } 
    68    
    69   MPI_Request::MPI_Request(void* request) 
    70   { 
    71     mpi_request = new ::MPI_Request; 
    72     *(static_cast< ::MPI_Request*>(mpi_request)) = *static_cast< ::MPI_Request*>(request); 
    73   } 
     35  /* 
    7436   
    7537  MPI_Aint::MPI_Aint(void* aint) 
     
    7739    mpi_aint = new ::MPI_Aint; 
    7840    *(static_cast< ::MPI_Aint*>(mpi_aint)) = *(static_cast< ::MPI_Aint*>(aint)); 
     41  } 
     42 
     43  MPI_Aint::MPI_Aint(int aint) 
     44  { 
     45    mpi_aint = new ::MPI_Aint; 
     46    *(static_cast< ::MPI_Aint*>(mpi_aint)) = aint; 
     47  } 
     48 
     49  MPI_Aint MPI_Aint::operator=(int a) 
     50  { 
     51    mpi_aint = new ::MPI_Aint; 
     52    *(static_cast< int*>(mpi_aint)) = a;  
    7953  } 
    8054   
     
    8559  } 
    8660 
    87   bool ep_communicator::operator == (ep_communicator right) 
    88   { 
    89     bool a = size_rank_info == right.size_rank_info; 
    90     bool b = comm_label == right.comm_label; 
    91     bool c = intercomm == right.intercomm; 
    92     return a&&b&&c; 
    93   } 
    94  
    95   bool ep_communicator::operator != (ep_communicator right) 
    96   { 
    97     bool a = size_rank_info != right.size_rank_info; 
    98     bool b = comm_label != right.comm_label; 
    99     bool c = intercomm != right.intercomm; 
    100     return a||b||c; 
    101   } 
    102  
    103   MPI_Comm::MPI_Comm() 
    104   { 
    105     is_ep = true; 
    106     is_intercomm = false; 
    107     my_buffer = NULL; 
    108     ep_barrier = NULL; 
    109     rank_map = NULL; 
    110     ep_comm_ptr = NULL; 
    111     mem_bridge = NULL; 
    112     mpi_bridge = NULL; 
    113     mpi_comm = new ::MPI_Comm; 
    114   } 
    115  
    11661   
    117  
    118   MPI_Comm::MPI_Comm(void* comm) 
    119   { 
    120     is_ep = false; 
    121     is_intercomm = false; 
    122     my_buffer = NULL; 
    123     ep_barrier = NULL; 
    124     rank_map = NULL; 
    125     ep_comm_ptr = NULL; 
    126     mem_bridge = NULL; 
    127     mpi_bridge = NULL; 
    128     mpi_comm = new ::MPI_Comm; 
    129     *(static_cast< ::MPI_Comm*>(mpi_comm)) = *(static_cast< ::MPI_Comm*>(comm)); 
    130   } 
    131  
     62*/ 
    13263   
    133  
    134   bool MPI_Comm::operator == (MPI_Comm right) 
    135   { 
    136     bool a = is_ep == right.is_ep; 
    137     bool b = is_intercomm == right.is_intercomm; 
    138     bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_comm)); 
    139     bool d = is_ep ? ep_comm_ptr == right.ep_comm_ptr : true; 
    140     return a&&b&&c&&d; 
    141   } 
    142  
    143   bool MPI_Comm::operator != (MPI_Comm right) 
    144   { 
    145     bool a = is_ep != right.is_ep; 
    146     bool b = is_intercomm != right.is_intercomm; 
    147     bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_comm)); 
    148     bool d = is_ep ? ep_comm_ptr != right.ep_comm_ptr : true; 
    149     return a||b||c||d; 
    150   } 
    151  
    152   bool MPI_Request::operator == (MPI_Request right) 
    153   { 
    154     bool b = type == right.type; 
    155     bool c = buf == right.buf; 
    156     bool d = ep_src == right.ep_src; 
    157     bool e = ep_tag == right.ep_tag; 
    158     bool f = ep_datatype == right.ep_datatype; 
    159     return b&&c&&d&&e&&f; 
    160   } 
    16164 
    16265 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp

    r1374 r1520  
    1212#include <numeric> 
    1313#include <bitset> 
    14 //#include <memory.h> 
    1514#include <algorithm> 
    1615#include <assert.h> 
     
    2423#endif 
    2524 
     25#ifdef _Memory_check 
     26#define memcheck(x) std::cout << x << std::endl 
     27#else 
     28#define memcheck(x) 
     29#endif 
     30 
     31 
    2632#define BUFFER_SIZE 10000 
    2733 
    28 //#define NUM_THREADS 12 
    29  
    30 typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size> 
    31  
    32 typedef std::vector< std::pair<int, int> > RANK_MAP;  // at(ep_rank) = <ep_rank_local, mpi_rank> 
    33  
    34 typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP; 
     34#include "ep_status.hpp" 
     35#include "ep_request.hpp" 
     36#include "ep_info.hpp" 
     37#include "ep_message.hpp" 
     38#include "ep_barrier.hpp" 
     39#include "ep_comm.hpp" 
     40#include "ep_intercomm.hpp" 
     41#include "ep_window.hpp" 
    3542 
    3643 
    37 typedef struct 
    38 { 
    39   int first; 
    40   int second; 
    41   int third; 
    42 } Triple_int; 
    4344 
    4445namespace ep_lib 
    4546{ 
    46   //#define EP_UNDEFINED -32766 
    4747 
    4848  class ep_communicator; 
    4949  class ep_intercomm; 
    50   class OMPbarrier; 
    51   typedef ep_communicator* EP_Comm; 
    52   class MPI_Comm; 
    5350 
    5451 
    55   class MPI_Status 
    56   { 
    57     public: 
    58  
    59       void* ep_datatype; 
    60       int ep_src; 
    61       int ep_tag; 
    62       void* mpi_status; 
    63   }; 
    64  
    65   class MPI_Message 
    66   { 
    67     public: 
    68  
    69       void* mpi_message; 
    70       int ep_src; 
    71       int ep_tag; 
    72       void* mpi_status; 
    73  
    74       MPI_Message() {} 
    75       MPI_Message(void* message); 
    76   }; 
    77  
    78   typedef std::list<MPI_Message > Message_list; 
    79  
    80  
    81   class OMPbarrier 
    82   { 
    83     private: 
    84       int nbThreads;          //<The number of threads for this barrier 
    85       int currentNbThread;    //<The current number of threads waiting 
    86       bool sense;             //<Direct barrier feedback protection 
    87       omp_lock_t mutex;       //<To have an atomic int 
    88  
    89       OMPbarrier(OMPbarrier&){} 
    90       OMPbarrier& operator=(OMPbarrier&){return *this;} 
    91  
    92     public: 
    93       /** Constructor with the number of threads */ 
    94       explicit OMPbarrier(const int inNbThreads) 
    95           : nbThreads(inNbThreads), currentNbThread(0), sense(false) { 
    96           omp_init_lock( &mutex ); 
    97       } 
    98  
    99       /** Destructor, release the omp lock */ 
    100       ~OMPbarrier(){ 
    101           omp_destroy_lock( &mutex ); 
    102       } 
    103  
    104       /** Perform a barrier */ 
    105       void wait(){ 
    106           const bool mySense = sense; 
    107           omp_set_lock( &mutex ); 
    108           const int nbThreadsArrived = (++currentNbThread); 
    109           omp_unset_lock( &mutex ); 
    110  
    111           if(nbThreadsArrived == nbThreads) { 
    112               currentNbThread = 0; 
    113               sense = !sense; 
    114               #pragma omp flush 
    115           } 
    116           else { 
    117               volatile const bool* const ptSense = &sense; 
    118               while( (*ptSense) == mySense){ 
    119               } 
    120           } 
    121       } 
    122  
    123  
    124       /** Change the number of threads */ 
    125       void setNbThreads(const int inNbThread){ 
    126           omp_set_lock( &mutex ); 
    127           nbThreads = inNbThread; 
    128           omp_unset_lock( &mutex ); 
    129       } 
    130   }; 
    131  
    132   class ep_intercomm 
    133   { 
    134     public: 
    135  
    136     void *mpi_inter_comm; 
    137  
    138     RANK_MAP *intercomm_rank_map; 
    139     RANK_MAP *local_rank_map; 
    140     RANK_MAP *remote_rank_map; 
    141  
    142  
    143     SIZE_RANK_INFO size_rank_info[3]; 
    144  
    145  
    146     MPI_Comm *local_comm; 
    147     int intercomm_tag; 
    148  
    149     ep_intercomm(); 
    150     //~ep_intercomm(){delete mpi_inter_comm;} 
    151     bool operator == (ep_intercomm right); 
    152     bool operator != (ep_intercomm right); 
    153      
    154  
    155  
    156   }; 
    157  
    158  
    159   class ep_communicator 
    160   { 
    161     public: 
    162  
    163     SIZE_RANK_INFO size_rank_info[3]; // 0: ep_rank,     ep_size 
    164                                       // 1: ep_rank_loc, num_ep 
    165                                       // 2: mpi_rank,    mpi_size 
    166  
    167  
    168     MPI_Comm *comm_list; 
    169  
    170     Message_list *message_queue; 
    171  
    172  
    173     int comm_label; 
    174  
    175     ep_intercomm *intercomm; 
    176  
    177     ep_communicator(); 
    178     bool operator == (ep_communicator right); 
    179     bool operator != (ep_communicator right); 
    180      
    181   }; 
    182  
    183  
    184   struct BUFFER 
    185   { 
    186     void * void_buffer[12]; 
    187   }; 
    188  
    189  
    190   class MPI_Comm 
    191   { 
    192     public: 
    193  
    194     bool is_ep; 
    195     bool is_intercomm; 
    196  
    197     BUFFER     *my_buffer; 
    198     OMPbarrier *ep_barrier; 
    199     RANK_MAP   *rank_map; 
    200     void* mpi_comm; 
    201     EP_Comm ep_comm_ptr; 
    202     MPI_Comm *mem_bridge; 
    203     void* mpi_bridge; 
    204  
    205     MPI_Comm();   
    206     MPI_Comm(void* comm); 
    207     //~MPI_Comm(){delete mpi_comm;} 
    208  
    209  
    210     bool operator == (MPI_Comm right); 
    211     bool operator != (MPI_Comm right); 
    212     bool is_null(); 
    213  
    214   }; 
    215  
    216  
    217   class MPI_Info 
    218   { 
    219     public: 
    220  
    221       void* mpi_info; 
    222  
    223       MPI_Info(); 
    224       MPI_Info(void* info); 
    225   }; 
    226  
    227  
    228   class MPI_Request 
    229   { 
    230     public: 
    231  
    232       void* mpi_request; 
    233  
    234       int type; //! type of the non-blocking communication. 1: Isend; 2:Irecv; 3:Imrecv; 4:Issend 
    235       void* buf; 
    236  
    237       int ep_src; 
    238       int ep_tag; 
    239       void* ep_datatype; 
    240  
    241       MPI_Comm comm;    //! EP communicator related to the communication 
    242  
    243       MPI_Request() {} 
    244       MPI_Request(void* request); 
    245       bool operator == (MPI_Request right); 
    246  
    247   }; 
    248  
    249    
    25052  class MPI_Aint 
    25153  { 
     
    25658    MPI_Aint() {} 
    25759    MPI_Aint(void* aint); 
    258     //MPI_Aint(int a): mpi_aint(a) {} 
     60    MPI_Aint(int aint); 
     61    MPI_Aint operator=(int a); 
    25962  }; 
    26063 
     
    26265  { 
    26366    public: 
    264  
     67   
    26568    void* mpi_fint; 
    266  
     69     
    26770    MPI_Fint() {} 
    26871    MPI_Fint(void* fint); 
    269     //MPI_Fint(int f): mpi_fint(f) {} 
    270      
     72                                  
    27173  }; 
     74  
     75   
    27276 
    27377 
     
    27882  static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_list; 
    27983 
     84  static std::list< std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > > intercomm_list; 
     85 
    28086  static std::map<std::pair<int, int>, MPI_Comm >  fc_comm_map; 
    28187 
    282 //  static std::map<std::pair<int, int>, MPI_Comm >  *fc_comm_map_ptr; 
    283 //  #pragma omp threadprivate(fc_comm_map_ptr) 
    284 //            //    <MPI_Fint,thread_num>   EP_Comm 
    28588 
    28689} 
  • XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp

    r1374 r1520  
    99#include <mpi.h> 
    1010#include "ep_declaration.hpp" 
     11#include "ep_mpi.hpp" 
    1112 
    1213using namespace std; 
     
    2223  int MPI_Wait(MPI_Request *request, MPI_Status *status) 
    2324  { 
    24     if(request->type !=1 && request->type !=2 && request->type !=3)  
     25    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3)  
    2526    { 
    2627      printf("Error in request type\n"); 
     
    2930    } 
    3031 
    31     while(request->type == 2) Request_Check(); 
     32    while((*request)->type == 2) Request_Check(); 
     33     
     34    ::MPI_Wait(to_mpi_request_ptr(*request), to_mpi_status_ptr(status)); 
    3235 
     36     
     37    status->ep_src = (*request)->ep_src; 
     38    status->ep_tag = (*request)->ep_tag; 
     39    status->ep_datatype = (*request)->ep_datatype; 
     40     
     41    (*request)->state = 2; 
    3342 
    34     //::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request); 
    35     ::MPI_Status mpi_status; 
    36     ::MPI_Wait(static_cast< ::MPI_Request*>(request->mpi_request), &mpi_status); 
    37  
    38     
    39             
    40   
    41     // request->mpi_request = mpi_request; 
    42  
    43     status->mpi_status = &mpi_status; 
    44     status->ep_src = request->ep_src; 
    45     status->ep_tag = request->ep_tag; 
    46     status->ep_datatype = request->ep_datatype; 
     43    memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Wait, delete (*request)->mpi_request"); 
     44    delete (*request)->mpi_request; 
     45    delete *request; 
    4746     
    4847 
    49  
    50     return MPI_SUCCESS; 
     48    return Request_Check(); 
    5149 
    5250  }   /*end of mpi_wait*/ 
     
    6967      for(int i=0; i<count; i++) 
    7068      { 
    71         if(array_of_requests[i].type !=1 && array_of_requests[i].type !=2 && array_of_requests[i].type !=3)  
     69        if(array_of_requests[i]->type !=1 && array_of_requests[i]->type !=2 && array_of_requests[i]->type !=3)  
    7270        { 
    7371          printf("Error in request type\n"); 
     
    7674        } 
    7775         
    78         if(array_of_requests[i].type == 2) Request_Check();  
    79         if(array_of_requests[i].type != 2 && finished.at(i) == 0)  
     76        if(array_of_requests[i]->type == 2) Request_Check();  
     77        if(array_of_requests[i]->type != 2 && finished.at(i) == 0)  
    8078        { 
    8179          finished.at(i) = 1; 
    82           //mpi_request[i] = static_cast< ::MPI_Request >(array_of_requests[i].mpi_request); 
    83           mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i].mpi_request); 
     80          mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); 
    8481        } 
    8582      }     
     
    9188    { 
    9289      array_of_statuses[i].mpi_status = &mpi_status[i]; 
    93       array_of_statuses[i].ep_src = array_of_requests[i].ep_src; 
    94       array_of_statuses[i].ep_tag = array_of_requests[i].ep_tag; 
    95       array_of_statuses[i].ep_datatype = array_of_requests[i].ep_datatype; 
     90      array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; 
     91      array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; 
     92      array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; 
     93       
     94      array_of_requests[i]->state = 2; 
     95       
     96      memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request"); 
     97      delete array_of_requests[i]->mpi_request; 
     98      delete array_of_requests[i]; 
    9699    } 
    97100 
     
    99102    delete[] mpi_status; 
    100103     
    101      
    102     return MPI_SUCCESS; 
     104    return Request_Check(); 
    103105  }  /* end of mpi_waitall*/ 
    104106 
Note: See TracChangeset for help on using the changeset viewer.