Ignore:
Timestamp:
08/29/23 17:24:04 (10 months ago)
Author:
ymipsl
Message:

Major update :

  • New method to lock and unlock one-sided windows (window_dynamic) to avoid network overhead
  • Introducing multithreading on server sided to manage more efficiently dead-lock occuring (similar to co-routine which will be available and implemented in futur c++ standard), based on c++ threads
  • Suprression of old "attached mode" which is replaced by online writer and reder filters

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/manager/servers_ressource.cpp

    r2523 r2547  
    99#include <vector> 
    1010#include <string> 
     11#include "thread_manager.hpp" 
    1112 
    1213 
     
    4344    eventScheduler_ = make_shared<CEventScheduler>(freeRessourcesComm_) ; 
    4445    freeRessourceEventScheduler_ = eventScheduler_ ; 
     46    if (CThreadManager::isUsingThreads()) CThreadManager::spawnThread(&CServersRessource::threadEventLoop, this) ; 
    4547  } 
    4648 
     
    131133    if (poolRessource_!=nullptr)  
    132134    { 
    133       if (poolRessource_->eventLoop(serviceOnly)) 
     135      poolRessource_->eventLoop(serviceOnly) ; 
     136      if (poolRessource_->isFinished()) 
    134137      { 
    135138        delete poolRessource_ ; 
     
    139142    } 
    140143    CTimer::get("CServersRessource::eventLoop").suspend(); 
    141     if (poolRessource_==nullptr && finalizeSignal_) return true ; 
    142     else return false ; 
    143   } 
     144    if (poolRessource_==nullptr && finalizeSignal_) finished_=true ; 
     145    return finished_ ; 
     146  } 
     147 
     148  void CServersRessource::threadEventLoop(void) 
     149  { 
     150    CTimer::get("CServersRessource::eventLoop").resume(); 
     151    info(100)<<"Launch Thread for  CServersRessource::threadEventLoop"<<endl ; 
     152    CThreadManager::threadInitialize() ;  
     153 
     154    do 
     155    { 
     156      double time=MPI_Wtime() ; 
     157      int flag ; 
     158      MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); 
     159 
     160      if (time-lastEventLoop_ > eventLoopLatency_)  
     161      { 
     162        checkNotifications() ; 
     163        lastEventLoop_=time ; 
     164      } 
     165 
     166      if (poolRessource_!=nullptr)  
     167      { 
     168        if (poolRessource_->isFinished()) 
     169        { 
     170          delete poolRessource_ ; 
     171          poolRessource_=nullptr ; 
     172          // don't forget to free pool ressource later 
     173        }  
     174      } 
     175      CTimer::get("CServersRessource::eventLoop").suspend(); 
     176      if (poolRessource_==nullptr && finalizeSignal_) finished_=true ; 
     177      if (!finished_) CThreadManager::yield() ; 
     178     
     179    } while (!finished_) ; 
     180 
     181    CThreadManager::threadFinalize() ; 
     182    info(100)<<"Close thread for CServersRessource::threadEventLoop"<<endl ; ; 
     183  } 
     184 
    144185 
    145186  void CServersRessource::checkNotifications(void) 
     
    148189    MPI_Comm_rank(serverComm_, &commRank) ; 
    149190    winNotify_->popFromExclusiveWindow(commRank, this, &CServersRessource::notificationsDumpIn) ; 
    150     if (notifyInType_==NOTIFY_CREATE_POOL) createPool() ; 
     191    if (notifyInType_==NOTIFY_CREATE_POOL)  
     192    { 
     193      if (CThreadManager::isUsingThreads()) synchronize() ; 
     194      createPool() ; 
     195    } 
    151196    else if (notifyInType_==NOTIFY_FINALIZE) finalizeSignal() ; 
     197  } 
     198 
     199  void CServersRessource::synchronize(void) 
     200  { 
     201    bool out=false ;  
     202    size_t timeLine=0 ; 
     203    std::hash<string> hashString ; 
     204    int commSize ; 
     205    MPI_Comm_size(freeRessourcesComm_,&commSize) ; 
     206    size_t hashId = hashString("CServersRessource::"+to_string(commSize)) ; 
     207    freeRessourceEventScheduler_->registerEvent(timeLine, hashId) ; 
     208    while (!out) 
     209    { 
     210      CThreadManager::yield() ; 
     211      out = eventScheduler_->queryEvent(timeLine,hashId) ; 
     212      if (out) eventScheduler_->popEvent() ; 
     213    } 
    152214  } 
    153215 
Note: See TracChangeset for help on using the changeset viewer.