Ignore:
Timestamp:
11/05/19 16:02:34 (5 years ago)
Author:
ymipsl
Message:

Some Update on XIOS services
Seems to work on Irène for :

  • first level of servers
  • fisrt + second level of servers
  • attached mode

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.cpp

    r1761 r1764  
    1515 
    1616  CServerContext::CServerContext(CService* parentService, MPI_Comm contextComm, const std::string& poolId, const std::string& serviceId,  
    17                                  const int& partitionId, const std::string& contextId) : finalizeSignal_(false), parentService_(parentService) 
     17                                 const int& partitionId, const std::string& contextId) : finalizeSignal_(false), parentService_(parentService), 
     18                                 hasNotification_(false) 
    1819  { 
    1920   int localRank, globalRank, commSize ; 
     
    4849  } 
    4950 
    50    
     51  CServerContext::~CServerContext() 
     52  { 
     53 
     54  }  
     55 
    5156  bool CServerContext::createIntercomm(const string& poolId, const string& serviceId, const int& partitionId, const string& contextId,  
    5257                                       const MPI_Comm& intraComm, MPI_Comm& interCommClient, MPI_Comm& interCommServer, bool wait) 
     
    7580    } 
    7681     
    77     auto eventScheduler=parentService_->getEventScheduler() ; 
    78     std::hash<string> hashString ; 
    79     size_t hashId = hashString(name_) ; 
    80     size_t currentTimeLine=0 ; 
    81     eventScheduler->registerEvent(currentTimeLine,hashId);  
    82  
    83     while (!eventScheduler->queryEvent(currentTimeLine,hashId)) 
    84     { 
    85        CXios::getDaemonsManager()->eventLoop() ; 
    86     }   
     82    MPI_Request req ; 
     83    MPI_Status status ; 
     84    MPI_Ibarrier(intraComm,&req) ; 
     85     
     86    int flag=false ; 
     87    while(!flag)  
     88    { 
     89      CXios::getDaemonsManager()->servicesEventLoop() ; 
     90      MPI_Test(&req,&flag,&status) ; 
     91    } 
     92//    auto eventScheduler=parentService_->getEventScheduler() ; 
     93//    std::hash<string> hashString ; 
     94//    size_t hashId = hashString(name_) ; 
     95//    size_t currentTimeLine=0 ; 
     96//    eventScheduler->registerEvent(currentTimeLine,hashId);  
     97// 
     98//    while (!eventScheduler->queryEvent(currentTimeLine,hashId)) 
     99//    { 
     100//       CXios::getDaemonsManager()->servicesEventLoop() ; 
     101//       eventScheduler->checkEvent() ; 
     102//    }   
    87103     
    88104    MPI_Bcast(&ok, 1, MPI_INT, 0, intraComm) ; 
     
    90106    if (ok)   
    91107    { 
     108      int globalRank ; 
     109      MPI_Comm_rank(xiosComm_,&globalRank) ; 
     110      MPI_Bcast(&contextLeader, 1, MPI_INT, 0, intraComm) ; 
     111       
     112      int overlap, nOverlap ; 
     113      if (contextLeader==globalRank) overlap=1 ; 
     114      else overlap=0 ; 
     115      MPI_Allreduce(&overlap, &nOverlap, 1, MPI_INT, MPI_SUM, contextComm_) ; 
     116/* 
    92117      int overlap  ; 
    93118      if (get<0>(overlapedComm_[name_])) overlap=1 ; 
     
    98123      int commSize ; 
    99124      MPI_Comm_size(contextComm_,&commSize ) ; 
    100       if (nOverlap==commSize) 
    101       { 
     125*/ 
     126      if (nOverlap> 0 ) 
     127      { 
     128        while (get<0>(overlapedComm_[name_])==false) CXios::getDaemonsManager()->servicesEventLoop() ; 
     129        isAttachedMode_=true ; 
    102130        cout<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ; 
    103131        interCommClient=newInterCommClient ; 
     
    107135      {  
    108136        cout<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ; 
     137        isAttachedMode_=false ; 
    109138        MPI_Intercomm_create(intraComm, 0, xiosComm_, contextLeader, 3141, &interCommClient) ; 
    110139        MPI_Comm_dup(interCommClient, &interCommServer) ; 
     
    128157     for(int rank=0; rank<commSize; rank++) 
    129158     { 
    130        notifyType_=NOTIFY_CREATE_INTERCOMM ; 
    131        notifyCreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ; 
     159       notifyOutType_=NOTIFY_CREATE_INTERCOMM ; 
     160       notifyOutCreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ; 
    132161       sendNotification(rank) ; 
    133162     } 
     
    147176    buffer.realloc(maxBufferSize_) ; 
    148177     
    149     if (notifyType_==NOTIFY_CREATE_INTERCOMM) 
    150     { 
    151       auto& arg=notifyCreateIntercomm_ ; 
    152       buffer << notifyType_ << std::get<0>(arg)<<std::get<1>(arg) ; 
     178    if (notifyOutType_==NOTIFY_CREATE_INTERCOMM) 
     179    { 
     180      auto& arg=notifyOutCreateIntercomm_ ; 
     181      buffer << notifyOutType_ << std::get<0>(arg)<<std::get<1>(arg) ; 
    153182    } 
    154183  } 
     
    156185  void CServerContext::notificationsDumpIn(CBufferIn& buffer) 
    157186  { 
    158     if (buffer.bufferSize() == 0) notifyType_= NOTIFY_NOTHING ; 
     187    if (buffer.bufferSize() == 0) notifyInType_= NOTIFY_NOTHING ; 
    159188    else 
    160189    { 
    161       buffer>>notifyType_; 
    162       if (notifyType_==NOTIFY_CREATE_INTERCOMM) 
    163       { 
    164         auto& arg=notifyCreateIntercomm_ ; 
     190      buffer>>notifyInType_; 
     191      if (notifyInType_==NOTIFY_CREATE_INTERCOMM) 
     192      { 
     193        auto& arg=notifyInCreateIntercomm_ ; 
    165194        buffer >> std::get<0>(arg)>> std::get<1>(arg) ; 
    166195      } 
     
    170199  void CServerContext::checkNotifications(void) 
    171200  { 
    172     int commRank ; 
    173     MPI_Comm_rank(contextComm_, &commRank) ; 
    174     winNotify_->lockWindow(commRank,0) ; 
    175     winNotify_->popFromWindow(commRank, this, &CServerContext::notificationsDumpIn) ; 
    176     winNotify_->unlockWindow(commRank,0) ; 
    177     if (notifyType_==NOTIFY_CREATE_INTERCOMM) createIntercomm() ; 
    178   } 
    179  
    180   bool CServerContext::eventLoop(void) 
     201    if (!hasNotification_) 
     202    { 
     203      int commRank ; 
     204      MPI_Comm_rank(contextComm_, &commRank) ; 
     205      winNotify_->lockWindow(commRank,0) ; 
     206      winNotify_->popFromWindow(commRank, this, &CServerContext::notificationsDumpIn) ; 
     207      winNotify_->unlockWindow(commRank,0) ; 
     208       
     209      if (notifyInType_!= NOTIFY_NOTHING) 
     210      { 
     211        hasNotification_=true ; 
     212        auto eventScheduler=parentService_->getEventScheduler() ; 
     213        std::hash<string> hashString ; 
     214        size_t hashId = hashString(name_) ; 
     215        size_t currentTimeLine=0 ; 
     216        eventScheduler->registerEvent(currentTimeLine,hashId);  
     217      } 
     218    } 
     219     
     220    if (hasNotification_) 
     221    { 
     222      auto eventScheduler=parentService_->getEventScheduler() ; 
     223      std::hash<string> hashString ; 
     224      size_t hashId = hashString(name_) ; 
     225      size_t currentTimeLine=0 ; 
     226      if (eventScheduler->queryEvent(currentTimeLine,hashId)) 
     227      { 
     228        if (notifyInType_==NOTIFY_CREATE_INTERCOMM) createIntercomm() ; 
     229        hasNotification_=false ; 
     230      } 
     231    } 
     232  } 
     233 
     234  bool CServerContext::eventLoop(bool serviceOnly) 
    181235  { 
    182236    bool finished=false ; 
    183     checkNotifications() ; 
    184     if (context_!=nullptr)   
     237    if (winNotify_!=nullptr) checkNotifications() ; 
     238    if (!serviceOnly && context_!=nullptr)   
    185239    { 
    186240      if (context_->eventLoop()) 
     
    198252  { 
    199253     MPI_Comm interCommServer, interCommClient ; 
    200      int remoteLeader=get<0>(notifyCreateIntercomm_) ; 
    201      string sourceContext=get<1>(notifyCreateIntercomm_) ; 
     254     auto& arg=notifyInCreateIntercomm_ ; 
     255     int remoteLeader=get<0>(arg) ; 
     256     string sourceContext=get<1>(arg) ; 
    202257 
    203258     auto it=overlapedComm_.find(sourceContext) ; 
     
    215270    if (nOverlap==commSize) 
    216271    { 
    217       cout<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ; 
     272      info(10)<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ; 
     273      isAttachedMode_=true ; 
    218274      interCommClient=get<2>(it->second) ; 
    219275      interCommServer=get<1>(it->second) ; 
     
    224280    else if (nOverlap==0) 
    225281    {  
    226       cout<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ; 
     282      info(10)<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ; 
     283      isAttachedMode_=false ; 
    227284      MPI_Intercomm_create(contextComm_, 0, xiosComm_, remoteLeader, 3141, &interCommServer) ; 
    228285      MPI_Comm_dup(interCommServer,&interCommClient) ; 
     
    233290    else 
    234291    { 
    235       cout<<"CServerContext::createIntercomm : partial overlap ==> not managed"<<endl ; 
     292      ERROR("void CServerContext::createIntercomm(void)",<<"CServerContext::createIntercomm : partial overlap ==> not managed") ; 
    236293    } 
    237294    
    238295  } 
    239296 
     297  void CServerContext::freeComm(void) 
     298  { 
     299    delete winNotify_ ; 
     300    winNotify_=nullptr ; 
     301    MPI_Comm_free(&contextComm_) ; 
     302    // don't forget intercomm -> later 
     303  } 
     304   
    240305  void CServerContext::finalizeSignal(void) 
    241306  { 
    242307    finalizeSignal_=true ; 
    243308  } 
    244     
    245309 
    246310} 
Note: See TracChangeset for help on using the changeset viewer.