Changeset 2547 for XIOS3/trunk/src/manager/servers_ressource.cpp
- Timestamp:
- 08/29/23 17:24:04 (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS3/trunk/src/manager/servers_ressource.cpp
r2523 r2547 9 9 #include <vector> 10 10 #include <string> 11 #include "thread_manager.hpp" 11 12 12 13 … … 43 44 eventScheduler_ = make_shared<CEventScheduler>(freeRessourcesComm_) ; 44 45 freeRessourceEventScheduler_ = eventScheduler_ ; 46 if (CThreadManager::isUsingThreads()) CThreadManager::spawnThread(&CServersRessource::threadEventLoop, this) ; 45 47 } 46 48 … … 131 133 if (poolRessource_!=nullptr) 132 134 { 133 if (poolRessource_->eventLoop(serviceOnly)) 135 poolRessource_->eventLoop(serviceOnly) ; 136 if (poolRessource_->isFinished()) 134 137 { 135 138 delete poolRessource_ ; … … 139 142 } 140 143 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 144 185 145 186 void CServersRessource::checkNotifications(void) … … 148 189 MPI_Comm_rank(serverComm_, &commRank) ; 149 190 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 } 151 196 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 } 152 214 } 153 215
Note: See TracChangeset
for help on using the changeset viewer.