Changeset 1054 for XIOS/dev/dev_olga/src/server.cpp
- Timestamp:
- 02/17/17 19:51:36 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/server.cpp
r1021 r1054 20 20 list<MPI_Comm> CServer::interCommLeft ; 21 21 list<MPI_Comm> CServer::interCommRight ; 22 list<MPI_Comm> CServer::interComm ;22 // list<MPI_Comm> CServer::interComm ; 23 23 std::list<MPI_Comm> CServer::contextInterComms; 24 24 int CServer::serverLevel = 0 ; 25 int CServer::serverLeader = 0; 26 int CServer::serverSize = 0; 25 27 int CServer::nbPools = 0; 26 28 int CServer::poolId = 0; 27 int CServer::serverSize = 0;28 29 bool CServer::isRoot = false ; 29 30 int CServer::rank = INVALID_RANK; … … 38 39 /*! 39 40 * \fn void CServer::initialize(void) 40 * Creates intraComm and interComm for a server pool (primary or secondary). 41 * Creates intraComm for each possible type of servers (classical, primary or secondary). 42 * In case of secondary servers intraComm is created for each secondary server pool. 43 * (For now the assumption is that there is one proc per pool.) 44 * Creates the following lists of interComms: 45 * classical server -- interCommLeft 46 * primary server -- interCommLeft and interCommRight 47 * secondary server -- interComm for each pool. 41 48 */ 42 49 void CServer::initialize(void) … … 64 71 65 72 unsigned long* hashAll ; 66 // unsigned long* hashAllServers ;67 73 68 74 // int rank ; … … 129 135 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 130 136 interCommLeft.push_back(newComm) ; 131 interComm.push_back(newComm) ;132 137 } 133 138 } … … 135 140 else if (serverLevel == 1) 136 141 { 137 int clientLeader, srvPrmLeader, srvSndLeader; 142 int clientLeader, srvSndLeader; 143 int srvPrmLeader ; 138 144 for (it=leaders.begin();it!=leaders.end();it++) 139 145 { … … 148 154 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 149 155 interCommLeft.push_back(newComm) ; 150 interComm.push_back(newComm) ;151 156 } 152 157 else 153 s rvPrmLeader = it->second;158 serverLeader = it->second; 154 159 } 155 160 156 161 for (int i = 0; i < nbPools; ++i) 157 162 { 158 srvSndLeader = srvPrmLeader + serverSize - nbPools + i; 159 // CClient::initializeClientOnServer(rank, serversComm, srvSndLeader); 160 CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 161 interCommRight.push_back(CClient::getInterComm()); 162 interComm.push_back(CClient::getInterComm()); 163 srvSndLeader = serverLeader + serverSize - nbPools + i; 164 int intraCommSize, intraCommRank ; 165 MPI_Comm_size(intraComm, &intraCommSize) ; 166 MPI_Comm_rank(intraComm, &intraCommRank) ; 167 info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize 168 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< srvSndLeader<<endl ; 169 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvSndLeader, 0, &newComm) ; 170 interCommRight.push_back(newComm) ; 163 171 } 164 172 } // primary server … … 175 183 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 176 184 interCommLeft.push_back(newComm) ; 177 interComm.push_back(newComm) ;178 185 } // secondary server 179 186 … … 210 217 if (rank==0) MPI_Send(&globalRank,1,MPI_INT,0,0,newComm) ; 211 218 MPI_Comm_remote_size(newComm,&size); 212 interComm.push_back(newComm) ; 219 // interComm.push_back(newComm) ; 220 interCommLeft.push_back(newComm) ; 213 221 } 214 222 oasis_enddef() ; 215 223 } 216 224 217 MPI_Comm_rank(intraComm, &rank) ; 218 if (rank==0) isRoot=true; 225 int rankServer; 226 MPI_Comm_rank(intraComm, &rankServer) ; 227 if (rankServer==0) isRoot=true; 219 228 else isRoot=false; 220 229 … … 235 244 // MPI_Comm_free(&(*it)); 236 245 237 for (std::list<MPI_Comm>::iterator it = interCommLeft.begin(); it != interCommLeft.end(); it++)238 MPI_Comm_free(&(*it));239 240 for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++)241 MPI_Comm_free(&(*it));246 for (std::list<MPI_Comm>::iterator it = interCommLeft.begin(); it != interCommLeft.end(); it++) 247 MPI_Comm_free(&(*it)); 248 249 for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++) 250 MPI_Comm_free(&(*it)); 242 251 243 252 MPI_Comm_free(&intraComm); … … 273 282 274 283 contextEventLoop() ; 284 // if (finished && contextList.empty()) stop=true ; 275 285 if (finished && contextList.empty()) stop=true ; 276 286 eventScheduler->checkEvent() ; … … 294 304 if (flag==true) 295 305 { 296 MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; 297 info(20)<<" CServer : Receive client finalize"<<endl ; 298 299 // If primary server, send finalize to secondary server pool(s) 300 for(itr=interCommRight.begin(); itr!=interCommRight.end(); itr++) 301 { 302 MPI_Send(&msg,1,MPI_INT,0,0,*itr) ; 303 // MPI_Comm_free(&(*itr)); 304 // interCommRight.erase(itr) ; 305 } 306 306 MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; 307 info(20)<<" CServer : Receive client finalize"<<endl ; 308 // Sending server finalize message to secondary servers (if any) 309 for(itr=interCommRight.begin();itr!=interCommRight.end();itr++) 310 { 311 MPI_Send(&msg,1,MPI_INT,0,0,*itr) ; 312 // itr = interCommRight.erase(itr) ; 313 } 307 314 MPI_Comm_free(&(*it)); 308 // interComm.erase(it) ;309 315 interCommLeft.erase(it) ; 310 316 break ; … … 312 318 } 313 319 314 if (interCommLeft.empty()) 315 // if (interComm.empty()) 320 if (interCommLeft.empty()) 316 321 { 317 322 int i,size ; … … 381 386 MPI_Get_count(&status,MPI_CHAR,&count) ; 382 387 recvContextMessage(buffer,count) ; 383 delete [] buffer 388 delete [] buffer; 384 389 recept=false ; 385 390 } … … 390 395 { 391 396 static map<string,contextMessage> recvContextId; 392 393 397 map<string,contextMessage>::iterator it ; 394 395 398 CBufferIn buffer(buff,count) ; 396 399 string id ; … … 434 437 void CServer::listenRootContext(void) 435 438 { 436 437 439 MPI_Status status ; 438 440 int flag ; … … 464 466 MPI_Get_count(&status,MPI_CHAR,&count) ; 465 467 registerContext(buffer,count) ; 466 467 468 delete [] buffer ; 468 469 recept=false ; … … 484 485 << "Context '" << contextId << "' has already been registred"); 485 486 486 MPI_Comm contextInterComm;487 MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextInterComm);488 489 MPI_Comm inter;490 MPI_Intercomm_merge(contextInterComm,1,&inter);491 MPI_Barrier(inter);492 493 487 context=CContext::create(contextId); 494 488 contextList[contextId]=context; 495 context->initServer(intraComm,contextInterComm); 496 contextInterComms.push_back(contextInterComm); 497 489 490 // All type of servers initialize its own server (CContextServer) 491 if (serverLevel < 2) 492 { 493 MPI_Comm contextInterComm; 494 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, leaderRank, 10+leaderRank, &contextInterComm); 495 MPI_Comm inter; 496 MPI_Intercomm_merge(contextInterComm,1,&inter); 497 MPI_Barrier(inter); 498 MPI_Comm_free(&inter); 499 context->initServer(intraComm,contextInterComm); 500 contextInterComms.push_back(contextInterComm); 501 } 502 else if (serverLevel == 2) 503 { 504 context->initServer(intraComm, interCommLeft.front()); 505 } 506 507 // Primary server: send create context message to secondary servers and initialize its own client (CContextClient) 498 508 if (serverLevel == 1) 499 509 { 500 // CClient::registerContext(contextId, intraComm); 501 CClient::registerContextByClienOfServer(contextId, intraComm); 502 } 503 504 MPI_Comm_free(&inter); 505 510 int i = 0, size; 511 CMessage msg; 512 int messageSize; 513 MPI_Comm_size(intraComm, &size) ; 514 for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++, ++i) 515 { 516 StdString str = contextId +"_server_" + boost::lexical_cast<string>(i); 517 msg<<str<<size<<rank ; 518 messageSize = msg.size() ; 519 buff = new char[messageSize] ; 520 CBufferOut buffer(buff,messageSize) ; 521 buffer<<msg ; 522 int sndServerGloRanks = serverSize-nbPools+serverLeader +i; // the assumption is that there is only one proc per secondary server pool 523 MPI_Send(buff, buffer.count(), MPI_CHAR, sndServerGloRanks, 1, CXios::globalComm) ; 524 context->initClient(intraComm, *it) ; 525 delete [] buff ; 526 } 527 } 506 528 } 507 529 … … 509 531 { 510 532 bool finished ; 533 511 534 map<string,CContext*>::iterator it ; 512 535 513 536 for(it=contextList.begin();it!=contextList.end();it++) 514 537 { 515 finished=it->second-> checkBuffersAndListen();538 finished=it->second->isFinalized(); 516 539 if (finished) 517 540 { … … 519 542 break ; 520 543 } 544 else 545 finished=it->second->checkBuffersAndListen(); 521 546 } 522 547 } … … 554 579 { 555 580 if (serverLevel == 1) 556 id = getRank();581 id = rank-serverLeader; 557 582 else 558 583 id = poolId;
Note: See TracChangeset
for help on using the changeset viewer.