- Timestamp:
- 11/05/19 16:02:34 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_SERVICES/src/manager/server_context.cpp
r1761 r1764 15 15 16 16 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) 18 19 { 19 20 int localRank, globalRank, commSize ; … … 48 49 } 49 50 50 51 CServerContext::~CServerContext() 52 { 53 54 } 55 51 56 bool CServerContext::createIntercomm(const string& poolId, const string& serviceId, const int& partitionId, const string& contextId, 52 57 const MPI_Comm& intraComm, MPI_Comm& interCommClient, MPI_Comm& interCommServer, bool wait) … … 75 80 } 76 81 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 // } 87 103 88 104 MPI_Bcast(&ok, 1, MPI_INT, 0, intraComm) ; … … 90 106 if (ok) 91 107 { 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 /* 92 117 int overlap ; 93 118 if (get<0>(overlapedComm_[name_])) overlap=1 ; … … 98 123 int commSize ; 99 124 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 ; 102 130 cout<<"CServerContext::createIntercomm : total overlap ==> context in attached mode"<<endl ; 103 131 interCommClient=newInterCommClient ; … … 107 135 { 108 136 cout<<"CServerContext::createIntercomm : No overlap ==> context in server mode"<<endl ; 137 isAttachedMode_=false ; 109 138 MPI_Intercomm_create(intraComm, 0, xiosComm_, contextLeader, 3141, &interCommClient) ; 110 139 MPI_Comm_dup(interCommClient, &interCommServer) ; … … 128 157 for(int rank=0; rank<commSize; rank++) 129 158 { 130 notify Type_=NOTIFY_CREATE_INTERCOMM ;131 notify CreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ;159 notifyOutType_=NOTIFY_CREATE_INTERCOMM ; 160 notifyOutCreateIntercomm_ = make_tuple(remoteLeader, sourceContext) ; 132 161 sendNotification(rank) ; 133 162 } … … 147 176 buffer.realloc(maxBufferSize_) ; 148 177 149 if (notify Type_==NOTIFY_CREATE_INTERCOMM)150 { 151 auto& arg=notify CreateIntercomm_ ;152 buffer << notify Type_ << 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) ; 153 182 } 154 183 } … … 156 185 void CServerContext::notificationsDumpIn(CBufferIn& buffer) 157 186 { 158 if (buffer.bufferSize() == 0) notify Type_= NOTIFY_NOTHING ;187 if (buffer.bufferSize() == 0) notifyInType_= NOTIFY_NOTHING ; 159 188 else 160 189 { 161 buffer>>notify Type_;162 if (notify Type_==NOTIFY_CREATE_INTERCOMM)163 { 164 auto& arg=notify CreateIntercomm_ ;190 buffer>>notifyInType_; 191 if (notifyInType_==NOTIFY_CREATE_INTERCOMM) 192 { 193 auto& arg=notifyInCreateIntercomm_ ; 165 194 buffer >> std::get<0>(arg)>> std::get<1>(arg) ; 166 195 } … … 170 199 void CServerContext::checkNotifications(void) 171 200 { 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) 181 235 { 182 236 bool finished=false ; 183 checkNotifications() ;184 if ( context_!=nullptr)237 if (winNotify_!=nullptr) checkNotifications() ; 238 if (!serviceOnly && context_!=nullptr) 185 239 { 186 240 if (context_->eventLoop()) … … 198 252 { 199 253 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) ; 202 257 203 258 auto it=overlapedComm_.find(sourceContext) ; … … 215 270 if (nOverlap==commSize) 216 271 { 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 ; 218 274 interCommClient=get<2>(it->second) ; 219 275 interCommServer=get<1>(it->second) ; … … 224 280 else if (nOverlap==0) 225 281 { 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 ; 227 284 MPI_Intercomm_create(contextComm_, 0, xiosComm_, remoteLeader, 3141, &interCommServer) ; 228 285 MPI_Comm_dup(interCommServer,&interCommClient) ; … … 233 290 else 234 291 { 235 cout<<"CServerContext::createIntercomm : partial overlap ==> not managed"<<endl;292 ERROR("void CServerContext::createIntercomm(void)",<<"CServerContext::createIntercomm : partial overlap ==> not managed") ; 236 293 } 237 294 238 295 } 239 296 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 240 305 void CServerContext::finalizeSignal(void) 241 306 { 242 307 finalizeSignal_=true ; 243 308 } 244 245 309 246 310 }
Note: See TracChangeset
for help on using the changeset viewer.