Ignore:
Timestamp:
07/05/17 14:14:09 (7 years ago)
Author:
yushan
Message:

add request_check. test client and complete OK

Location:
XIOS/dev/branch_yushan_merged/extern/src_ep_dev
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_fortran.cpp

    r1134 r1196  
    3131      { 
    3232        fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm)); 
    33         //printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), comm.ep_comm_ptr); 
     33        //printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, fint, omp_get_thread_num(), comm.ep_comm_ptr); 
    3434      } 
    3535    } 
     
    5454      MPI_Comm comm_ptr; 
    5555      comm_ptr = it->second; 
    56       //printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, comm_ptr.ep_comm_ptr); 
     56      //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); 
    5757      return  comm_ptr; 
    5858    } 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_intercomm.cpp

    r1134 r1196  
    4343      MPI_Isend(&leader_ranks[0], 3, MPI_INT_STD, remote_leader, tag, peer_comm, &req_s); 
    4444      MPI_Status status; 
     45      MPI_Wait(&req_s, &status); 
     46       
    4547      MPI_Irecv(&leader_ranks[3], 3, MPI_INT_STD, remote_leader, tag, peer_comm, &req_r); 
    46       MPI_Wait(&req_s, &status); 
    4748      MPI_Wait(&req_r, &status); 
    4849    } 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_lib.cpp

    r1187 r1196  
    77using namespace std; 
    88 
     9std::list< ep_lib::MPI_Request* > ** EP_PendingRequests = 0; 
     10#pragma omp threadprivate(EP_PendingRequests) 
    911 
    1012namespace ep_lib 
     
    429431 
    430432 
     433 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_lib.hpp

    r1134 r1196  
    6262 
    6363  int Message_Check(MPI_Comm comm); 
     64  int Request_Check(); 
    6465 
    6566  int MPI_Recv  (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status); 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_message.cpp

    r1187 r1196  
    1111 
    1212using namespace std; 
     13 
     14extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests; 
     15#pragma omp threadprivate(EP_PendingRequests) 
    1316 
    1417namespace ep_lib 
     
    248251          #pragma omp flush 
    249252          ptr_comm_target->ep_comm_ptr->message_queue->push_back(*msg_block); 
    250           printf("probed one message, ep_src = %d, tag = %d, mpi_status = %p (%p), message = %d\n", msg_block->ep_src, msg_block->ep_tag, msg_block->mpi_status, &status, msg_block->mpi_message); 
     253          //printf("probed one message, ep_src = %d, tag = %d, mpi_status = %p (%p), message = %d\n", msg_block->ep_src, msg_block->ep_tag, msg_block->mpi_status, &status, msg_block->mpi_message); 
    251254          #pragma omp flush 
    252255        } 
     
    261264  } 
    262265 
     266  int Request_Check() 
     267  { 
     268    MPI_Status status; 
     269    MPI_Message message; 
     270    int probed = false; 
     271    int recv_count = 0; 
     272    std::list<MPI_Request* >::iterator it; 
     273     
     274    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) 
     275    {  
     276      Message_Check((*it)->comm); 
     277    } 
     278 
     279 
     280    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 
     281    { 
     282      MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status); 
     283      if(probed) 
     284      { 
     285        MPI_Get_count(&status, (*it)->ep_datatype, &recv_count); 
     286        MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it); 
     287        (*it)->type = 3; 
     288        //printf("request add = %p, mpi_request=%d\n", *it, (*it)->mpi_request); 
     289        EP_PendingRequests->erase(it); 
     290        it = EP_PendingRequests->begin(); 
     291        continue; 
     292      } 
     293      it++; 
     294    } 
     295  } 
     296 
    263297} 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_recv.cpp

    r1187 r1196  
    1313using namespace std; 
    1414 
     15extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests; 
     16#pragma omp threadprivate(EP_PendingRequests) 
    1517 
    1618namespace ep_lib  
     
    5456    int dest_rank; 
    5557    MPI_Comm_rank(comm, &dest_rank); 
     58    int world_rank; 
     59    MPI_Comm_rank(MPI_COMM_WORLD_STD, &world_rank); 
    5660 
    5761    if(!comm.is_ep) 
     
    8387    if(EP_PendingRequests == 0 )  
    8488    { 
    85       EP_PendingRequests = new std::list< MPI_Request* >;  
    86       printf("proc %d : EP_PendingRequests allocated, add = %p\n", dest_rank, EP_PendingRequests);   
     89      EP_PendingRequests = new std::list< MPI_Request* >; 
     90      //printf("proc %d(%d) : EP_PendingRequests allocated, add = %p\n", dest_rank, world_rank, EP_PendingRequests);   
    8791    } 
    8892 
    89     request->pending_ptr = EP_PendingRequests; 
    90     printf("proc %d : &EP_PendingRequests add = %p, ptr = %p\n", dest_rank, EP_PendingRequests, request->pending_ptr);   
     93 
     94    EP_PendingRequests->push_back(request); 
     95 
     96    Request_Check(); 
     97    //printf("proc %d(%d) : EP_PendingRequests insert one request, src = %d(%d), tag = %d(%d), size = %d; request add = %p\n",  
     98    //        dest_rank, world_rank, EP_PendingRequests->back()->ep_src, request->ep_src,  
     99    //        EP_PendingRequests->back()->ep_tag, request->ep_tag,  
     100    //        EP_PendingRequests->size(), request); 
    91101     
    92     EP_PendingRequests->push_back(request); 
    93     //printf("proc %d : EP_PendingRequests insert one request, src = %d, tag = %d, size = %d\n", dest_rank, request->ep_src, request->ep_tag, EP_PendingRequests->size()); 
     102    // check all EP_PendingRequests       
     103    //for(std::list<MPI_Request* >::iterator it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 
     104    //{ 
     105    //if((*it)->type == 3)  
     106    //{ 
     107    //    EP_PendingRequests->erase(it); 
     108   //     it = EP_PendingRequests->begin(); 
     109    //    continue; 
     110     // } 
     111         
     112      //int probed = false; 
     113      //MPI_Message pending_message; 
     114      //MPI_Status pending_status; 
    94115     
    95     // check all EP_PendingRequests 
     116      //MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &pending_message, &pending_status); 
    96117     
    97     //printf("proc %d have %d pending irecv request\n", dest_rank, EP_PendingRequests->size()); 
    98        
    99     for(std::list<MPI_Request* >::iterator it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 
    100     { 
    101       if((*it)->type == 3)  
    102       { 
    103         //printf("proc %d : pending request type = %d, src= %d, tag = %d    skip\n", dest_rank, (*it)->type, (*it)->ep_src, (*it)->ep_tag); 
    104         EP_PendingRequests->erase(it); 
    105         it = EP_PendingRequests->begin(); 
    106         //printf("proc %d : pending request processed, size = %d\n", dest_rank, EP_PendingRequests->size()); 
    107         continue; 
    108       } 
     118      //if(probed)  
     119      //{  
     120        //int count; 
     121        //MPI_Get_count(&pending_status, (*it)->ep_datatype, &count); 
     122        //MPI_Imrecv((*it)->buf, count, (*it)->ep_datatype, &pending_message, *it); 
     123 
     124        //EP_PendingRequests->erase(it); 
     125        //if(EP_PendingRequests->empty()) return 0; 
    109126         
    110       //printf("proc %d : pending irecv request src = %d, tag = %d, type = %d\n", dest_rank, (*it)->ep_src, (*it)->ep_tag, (*it)->type); 
    111       int probed = false; 
    112       MPI_Message pending_message; 
    113       MPI_Status pending_status; 
    114      
    115       MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &pending_message, &pending_status); 
    116       //printf("proc %d : pending irecv request probed to be %d, src = %d, tag = %d\n",dest_rank, probed, (*it)->ep_src, (*it)->ep_tag); 
    117      
    118       if(probed)  
    119       {  
    120         int count; 
    121         MPI_Get_count(&pending_status, (*it)->ep_datatype, &count); 
    122         MPI_Imrecv((*it)->buf, count, (*it)->ep_datatype, &pending_message, *it); 
    123         //printf("proc %d : pending request is imrecving src = %d, tag = %d, count = %d\n", dest_rank, (*it)->ep_src, (*it)->ep_tag, count); 
    124         EP_PendingRequests->erase(it); 
    125         it = EP_PendingRequests->begin(); 
    126         //printf("proc %d : pending request processed, size = %d\n", dest_rank, EP_PendingRequests->size()); 
    127         continue; 
    128       } 
     127        //it = EP_PendingRequests->begin(); 
     128        //continue; 
     129     // } 
    129130 
    130       it++; 
    131     } 
     131      //it++; 
     132   // } 
    132133     
    133134    return 0; 
     
    149150    request->ep_tag = message->ep_tag; 
    150151    request->ep_src = message->ep_src; 
    151     //request->buf = buf; 
    152152 
    153153    return 0; 
     
    177177 
    178178 
     179 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_send.cpp

    r1185 r1196  
    5050    return 0; 
    5151  } 
     52   
     53  int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) 
     54  { 
     55    if(!comm.is_ep) 
     56    { 
     57      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm); 
     58      ::MPI_Bsend(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm); 
     59      return 0; 
     60    } 
     61 
     62    MPI_Request request; 
     63    MPI_Status status; 
     64    //MPI_Ibsend(buf, count, datatype, dest, tag, comm, &request); 
     65    MPI_Wait(&request, &status); 
     66 
     67    //check_sum_send(buf, count, datatype, dest, tag, comm); 
     68 
     69    return 0; 
     70  } 
     71  
    5272 
    5373 
     
    103123    request->buf = const_cast<void*>(buf); 
    104124 
    105     Message_Check(comm); 
     125    //Message_Check(comm); 
    106126 
    107127    return 0; 
     
    166186    return 0; 
    167187  } 
     188   
     189  int MPI_Ibsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     190  { 
     191    Debug("\nMPI_Isend with EP\n"); 
     192    int src_rank; 
     193    MPI_Comm_rank(comm, &src_rank); 
     194 
     195   
     196 
     197    if(!comm.is_ep) 
     198    { 
     199      ::MPI_Request mpi_request; 
     200      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm); 
     201      ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request); 
     202 
     203      request->mpi_request = mpi_request; 
     204 
     205      request->ep_src = src_rank; 
     206      request->ep_tag = tag; 
     207      request->ep_datatype = datatype; 
     208      request->type = 1; 
     209      request->comm = comm; 
     210 
     211      return 0; 
     212    } 
     213 
     214    if(comm.is_intercomm) return 0;//MPI_Ibsend_intercomm(buf, count, datatype, dest, tag, comm, request); 
     215 
     216   // EP intracomm 
     217 
     218    //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
     219 
     220    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first; 
     221    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; 
     222    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     223    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; 
     224 
     225    request->ep_src  = src_rank; 
     226    request->ep_tag  = tag; 
     227    request->ep_datatype = datatype; 
     228 
     229    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm); 
     230    ::MPI_Request mpi_request; 
     231 
     232    ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request); 
     233 
     234    request->mpi_request = mpi_request; 
     235    request->type = 1;          // used in wait 
     236    request->comm = comm; 
     237    request->buf = const_cast<void*>(buf); 
     238 
     239    //Message_Check(comm); 
     240 
     241    return 0;   
     242  } 
    168243 
    169244 
     
    190265    } 
    191266 
    192     Message_Check(comm); 
     267    //Message_Check(comm); 
    193268 
    194269 
     
    263338    } 
    264339 
    265     Message_Check(comm); 
     340    //Message_Check(comm); 
    266341 
    267342 
     
    313388 
    314389  } 
     390   
     391  int MPI_Ibsend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) 
     392  { 
     393    printf("MPI_Ibsend with intercomm not yet implemented\n"); 
     394    MPI_Abort(comm, 0); 
     395    //check_sum_send(buf, count, datatype, dest, tag, comm, 1); 
     396 
     397    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first; 
     398    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second; 
     399 
     400    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; 
     401    int src_comm_label; 
     402 
     403    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++) 
     404    { 
     405      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank) 
     406      { 
     407        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second; 
     408        break; 
     409      } 
     410    } 
     411 
     412    //Message_Check(comm); 
     413 
     414 
     415    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs 
     416    { 
     417      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
     418      int ep_src_loc = comm.rank_map->at(inter_src).first; 
     419      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first; 
     420      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second; 
     421      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     422 
     423      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm); 
     424      ::MPI_Request mpi_request; 
     425   
     426      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request); 
     427 
     428      request->mpi_request = mpi_request; 
     429      request->type = 1;                // used in wait 
     430      request->comm = comm; 
     431 
     432      request->ep_src = src_ep_rank; 
     433      request->ep_tag = tag; 
     434      request->ep_datatype = datatype; 
     435    } 
     436 
     437    else   // dest_remote_comm_label != src_comm_label 
     438    {  
     439      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; 
     440      int ep_src_loc = comm.rank_map->at(inter_src).first; 
     441      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first; 
     442      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second; 
     443      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 
     444 
     445      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm); 
     446      ::MPI_Request mpi_request; 
     447 
     448      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request); 
     449 
     450      request->mpi_request = mpi_request; 
     451      request->type = 1;                // used in wait 
     452      request->comm = comm; 
     453    
     454      request->ep_src = src_ep_rank; 
     455      request->ep_tag = tag; 
     456      request->ep_datatype = datatype; 
     457    } 
     458 
     459    return 0; 
     460 
     461  } 
    315462} 
    316463 
     
    319466 
    320467 
     468 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_type.hpp

    r1187 r1196  
    454454      #endif 
    455455 
    456       std::list< MPI_Request* > * pending_ptr; 
     456 
     457    bool operator == (MPI_Request right) 
     458    { 
     459      //bool a = mpi_request == right.mpi_request; 
     460      bool b = type == right.type; 
     461      bool c = buf == right.buf; 
     462      bool d = ep_src == right.ep_src; 
     463      bool e = ep_tag == right.ep_tag; 
     464      bool f = ep_datatype == right.ep_datatype; 
     465      return b&&c&&d&&e&&f; 
     466    } 
    457467  }; 
    458468 
     
    492502            //    <MPI_Fint,thread_num>   EP_Comm 
    493503 
    494   static std::list< MPI_Request* > * EP_PendingRequests = 0; 
    495   #pragma omp threadprivate(EP_PendingRequests) 
     504  //static std::list<MPI_Request * > *EP_PendingRequests = 0;  
    496505} 
    497506 
     
    499508 
    500509#endif // EP_TYPE_HPP_INCLUDED 
     510 
  • XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp

    r1187 r1196  
    1212using namespace std; 
    1313 
     14extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests; 
     15#pragma omp threadprivate(EP_PendingRequests) 
     16 
    1417 
    1518 
    1619namespace ep_lib  
    1720{        
    18  
     21   
    1922  int MPI_Wait(MPI_Request *request, MPI_Status *status) 
    2023  { 
    21  
    22     if(request->type == 1)  //=>isend 
     24    if(request->type !=1 && request->type !=2 && request->type !=3)  
    2325    { 
    24       ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request); 
    25       ::MPI_Status mpi_status; 
    26       ::MPI_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN); 
    27       int error_code = ::MPI_Wait(&mpi_request, &mpi_status); 
    28       if (error_code != MPI_SUCCESS) { 
    29        
    30          char error_string[BUFSIZ]; 
    31          int length_of_error_string, error_class; 
    32        
    33          ::MPI_Error_class(error_code, &error_class); 
    34          ::MPI_Error_string(error_class, error_string, &length_of_error_string); 
    35          printf("%s\n", error_string); 
    36       } 
    37  
    38       status->mpi_status = &mpi_status; 
    39       status->ep_src = request->ep_src; 
    40       status->ep_tag = request->ep_tag; 
    41       status->ep_datatype = request->ep_datatype; 
    42  
    43       return 0; 
     26      printf("Error in request type\n"); 
     27  
     28      exit(1); 
    4429    } 
    4530 
    46     if(request->type == 3) //=>imrecv 
    47     { 
    48       ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request); 
    49       ::MPI_Status mpi_status; 
    50       ::MPI_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN); 
    51       int error_code = ::MPI_Wait(&mpi_request, &mpi_status); 
    52       if (error_code != MPI_SUCCESS) { 
     31    while(request->type == 2) Request_Check(); 
     32 
     33 
     34    ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request); 
     35    ::MPI_Status mpi_status; 
     36    ::MPI_Wait(&mpi_request, &mpi_status); 
    5337       
    54          char error_string[BUFSIZ]; 
    55          int length_of_error_string, error_class; 
    56        
    57          ::MPI_Error_class(error_code, &error_class); 
    58          ::MPI_Error_string(error_class, error_string, &length_of_error_string); 
    59          printf("%s\n", error_string); 
    60       } 
    61        
     38    request->mpi_request = mpi_request; 
    6239 
    63       status->mpi_status = new ::MPI_Status(mpi_status); 
    64       status->ep_src = request->ep_src; 
    65       status->ep_tag = request->ep_tag; 
    66       status->ep_datatype = request->ep_datatype; 
    67  
    68       //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2); 
    69       return 0; 
    70  
    71     } 
    72  
    73     if(request->type == 2) //=>irecv not probed 
    74     { 
    75        
    76       while(true) 
    77       { 
    78         Message_Check(request->comm); 
    79         // parcours pending list 
    80         for(std::list<MPI_Request* >::iterator it = (request->pending_ptr)->begin(); it!=(request->pending_ptr)->end(); ) 
    81         { 
    82           if(*it == request) 
    83           {  
    84             int probed = false; 
    85             MPI_Message message; 
    86  
    87             MPI_Improbe(request->ep_src, request->ep_tag, request->comm, &probed, &message, status); 
    88                    
    89             if(probed) 
    90             { 
    91               int recv_count; 
    92               MPI_Get_count(status, request->ep_datatype, &recv_count); 
    93               MPI_Mrecv(request->buf, recv_count, request->ep_datatype, &message, status); 
    94               (request->pending_ptr)->erase(it); 
    95               //printf("wait  : pending request processed, size = %d\n", (request->pending_ptr)->size()); 
    96               request->type = 3; 
    97              
    98               return 0; 
    99             } 
    100  
    101             it++; 
    102           } 
    103           else  
    104           { 
    105             int probed = false; 
    106             MPI_Message message; 
    107             MPI_Status status; 
    108  
    109             MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status); 
    110                    
    111             if(probed) 
    112             { 
    113               int recv_count; 
    114               MPI_Get_count(&status, (*it)->ep_datatype, &recv_count); 
    115               MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it); 
    116                    
    117               (request->pending_ptr)->erase(it); 
    118                    
    119               it = (request->pending_ptr)->begin(); 
    120               //printf("wait  : pending request processed, size = %d\n", (request->pending_ptr)->size()); 
    121             } 
    122             else it++; 
    123           } 
    124         } 
    125  
    126       } 
    127        
    128  
    129     } 
     40    status->mpi_status = &mpi_status; 
     41    status->ep_src = request->ep_src; 
     42    status->ep_tag = request->ep_tag; 
     43    status->ep_datatype = request->ep_datatype; 
    13044 
    13145    return MPI_SUCCESS; 
     
    14054  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses) 
    14155  { 
    142     //int dest_rank; 
    143     //MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank); 
    144     //printf("proc %d enters waitall\n", dest_rank); 
     56    std::vector<int> finished(count, 0); 
    14557 
    146     int finished = 0; 
    147     int finished_index[count]; 
     58    ::MPI_Request* mpi_request = new ::MPI_Request[count]; 
     59    ::MPI_Status* mpi_status = new ::MPI_Status[count]; 
    14860 
    149     for(int i=0; i<count; i++) 
    150       printf("pending add = %p\n",  array_of_requests[i].pending_ptr); 
     61    //if(EP_PendingRequests != 0) printf("pending size = %d, add = %p\n", EP_PendingRequests->size(), EP_PendingRequests); 
    15162 
    152     //if(EP_PendingRequests == 0) EP_PendingRequests = new std::list< MPI_Request* >;   
    153     //printf("pending size = %d, add = %p\n", EP_PendingRequests->size(), EP_PendingRequests); 
    154  
    155     for(int i=0; i<count; i++) 
    156     { 
    157       finished_index[i] = false; 
    158     } 
    159  
    160     while(finished < count) 
     63    while(std::accumulate(finished.begin(), finished.end(), 0) < count) 
    16164    { 
    16265       
    16366      for(int i=0; i<count; i++) 
    16467      { 
    165         if(finished_index[i] == false) // this request has not been tested. 
     68        if(array_of_requests[i].type !=1 && array_of_requests[i].type !=2 && array_of_requests[i].type !=3)  
    16669        { 
    167           if(array_of_requests[i].type == 1 || array_of_requests[i].type == 3) // isend or imrecv 
    168           {       
    169             //MPI_Wait(&array_of_requests[i], &array_of_statuses[i]); 
    170             int tested; 
    171             MPI_Test(&array_of_requests[i], &tested, &array_of_statuses[i]); 
    172             if(!tested) MPI_Wait(&array_of_requests[i], &array_of_statuses[i]); 
    173             finished++; 
    174             finished_index[i] = true; 
    175           } 
    176           else // irecv 
    177           { 
    178              
    179             Message_Check(array_of_requests[i].comm); 
    180             // parcours pending list 
    181             for(std::list<MPI_Request* >::iterator it = (array_of_requests[i].pending_ptr)->begin(); it!=(array_of_requests[i].pending_ptr)->end(); ) 
    182             { 
    183               bool matched = false; 
    184               for(int j=0; j<count; j++) 
    185               { 
    186                 if(*it == &array_of_requests[j]) 
    187                 {  
    188                   int probed = false; 
    189                   MPI_Message message; 
    190  
    191                   MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &array_of_statuses[j]); 
    192                    
    193                   if(probed) 
    194                   { 
    195                     int recv_count; 
    196                     MPI_Get_count(&array_of_statuses[j], array_of_requests[j].ep_datatype, &recv_count); 
    197                     MPI_Mrecv(array_of_requests[j].buf, recv_count, array_of_requests[j].ep_datatype, &message, &array_of_statuses[j]); 
    198                     //check_sum_recv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, 2); 
    199                     (array_of_requests[i].pending_ptr)->erase(it); 
    200                     array_of_requests[j].type = 3; 
    201                     finished++; 
    202                     finished_index[j] = true; 
    203                     matched = true; 
    204                     it = (array_of_requests[i].pending_ptr)->begin(); 
    205                     j=count; 
    206                     //printf("waitall  : pending request processed, size = %d\n", (*(array_of_requests[i].pending_ptr))->size()); 
    207                     //printf("matched = %d, j=%d, src = %d, tag = %d, probed = %d\n", matched, j, (*it)->ep_src, (*it)->ep_tag, probed); 
    208                   } 
    209                 } 
    210  
    211               } 
    212  
    213               if(!matched) 
    214               { 
    215                 int probed = false; 
    216                 MPI_Message message; 
    217                 MPI_Status status; 
    218  
    219                 MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status); 
    220                    
    221                 if(probed) 
    222                 { 
    223                   int recv_count; 
    224                   MPI_Get_count(&status, (*it)->ep_datatype, &recv_count); 
    225                   MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it); 
    226                    
    227                   (array_of_requests[i].pending_ptr)->erase(it); 
    228                    
    229                   it = (array_of_requests[i].pending_ptr)->begin(); 
    230                   //printf("waitall  : pending request processed, size = %d\n", (*(array_of_requests[i].pending_ptr))->size()); 
    231                 } 
    232                 else it++; 
    233               } 
    234             } 
    235  
    236           } 
     70          printf("Error in request type\n"); 
     71  
     72          exit(1); 
     73        } 
     74         
     75        if(array_of_requests[i].type == 2) Request_Check();  
     76        if(array_of_requests[i].type != 2 && finished.at(i) == 0)  
     77        { 
     78          finished.at(i) = 1; 
     79          mpi_request[i] = static_cast< ::MPI_Request >(array_of_requests[i].mpi_request); 
    23780        } 
    23881      }     
    23982    } 
    240     //printf("proc %d exits waitall\n", dest_rank); 
     83 
     84    ::MPI_Waitall(count, mpi_request, mpi_status); 
     85 
     86    for(int i=0; i<count; i++) 
     87    { 
     88      array_of_statuses[i].mpi_status = &mpi_status; 
     89      array_of_statuses[i].ep_src = array_of_requests[i].ep_src; 
     90      array_of_statuses[i].ep_tag = array_of_requests[i].ep_tag; 
     91      array_of_statuses[i].ep_datatype = array_of_requests[i].ep_datatype; 
     92    } 
     93 
     94    delete[] mpi_request; 
     95    delete[] mpi_status; 
    24196    return MPI_SUCCESS; 
    24297  }  /* end of mpi_waitall*/ 
     
    24499 
    245100} 
     101 
Note: See TracChangeset for help on using the changeset viewer.