Changeset 1765 for XIOS/dev/dev_ym/XIOS_SERVICES/src/client.cpp
- Timestamp:
- 11/06/19 11:03:38 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_SERVICES/src/client.cpp
r1764 r1765 45 45 * \param [in/out] returnComm (intra)communicator of client group. 46 46 */ 47 48 void CClient::initRessources(void)49 {50 51 /*52 int commRank;53 MPI_Comm_rank(CXios::globalComm,&commRank) ;54 if (commRank==0)55 {56 ressources.createPool("ioserver1",ressources.getRessourcesSize()/2) ;57 }58 else if (commRank==1)59 {60 ressources.createPool("ioserver2",ressources.getRessourcesSize()/2) ;61 }62 */63 }64 47 65 48 void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) … … 204 187 ///////////////////////////////////////// 205 188 206 // create the services207 /*208 int commRank ;209 MPI_Comm_rank(clientComm,&commRank) ;210 auto contextsManager=CXios::getContextsManager() ;211 212 if (commRank==0)213 {214 contextsManager->createServerContext(CXios::defaultPoolId, CXios::defaultGathererId, 0, codeId) ;215 }216 217 MPI_Comm interComm ;218 219 contextsManager->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultGathererId, 0, codeId, clientComm, interComm) ;220 */221 /* while (true)222 {223 224 }225 */226 189 returnComm = clientComm ; 227 190 } … … 360 323 } 361 324 325 // to check on other architecture 362 326 void CClient::xiosGlobalCommByPublishing(MPI_Comm clientComm, const string& codeId) 363 327 { … … 443 407 } 444 408 445 void CClient::initialize_old(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)446 {447 int initialized ;448 MPI_Initialized(&initialized) ;449 if (initialized) is_MPI_Initialized=true ;450 else is_MPI_Initialized=false ;451 int rank ;452 453 CXios::launchRessourcesManager(false) ;454 CXios::launchServicesManager( false) ;455 CXios::launchContextsManager(false) ;456 457 initRessources() ;458 // don't use OASIS459 if (!CXios::usingOasis)460 {461 // localComm isn't given462 if (localComm == MPI_COMM_NULL)463 {464 if (!is_MPI_Initialized)465 {466 MPI_Init(NULL, NULL);467 }468 CTimer::get("XIOS").resume() ;469 CTimer::get("XIOS init/finalize",false).resume() ;470 boost::hash<string> hashString ;471 472 unsigned long hashClient=hashString(codeId) ;473 unsigned long hashServer=hashString(CXios::xiosCodeId) ;474 unsigned long* hashAll ;475 int size ;476 int myColor ;477 int i,c ;478 MPI_Comm newComm ;479 480 MPI_Comm_size(CXios::globalComm,&size) ;481 MPI_Comm_rank(CXios::globalComm,&rank_);482 483 hashAll=new unsigned long[size] ;484 485 MPI_Allgather(&hashClient,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ;486 487 map<unsigned long, int> colors ;488 map<unsigned long, int> leaders ;489 490 for(i=0,c=0;i<size;i++)491 {492 if (colors.find(hashAll[i])==colors.end())493 {494 colors[hashAll[i]] =c ;495 leaders[hashAll[i]]=i ;496 c++ ;497 }498 }499 500 // Verify whether we are on server mode or not501 CXios::setNotUsingServer();502 for (i=0; i < size; ++i)503 {504 if (hashServer == hashAll[i])505 {506 CXios::setUsingServer();507 break;508 }509 }510 511 myColor=colors[hashClient];512 MPI_Comm_split(CXios::globalComm,myColor,rank_,&intraComm) ;513 514 if (CXios::usingServer)515 {516 int clientLeader=leaders[hashClient] ;517 serverLeader=leaders[hashServer] ;518 int intraCommSize, intraCommRank ;519 MPI_Comm_size(intraComm,&intraCommSize) ;520 MPI_Comm_rank(intraComm,&intraCommRank) ;521 info(50)<<"intercommCreate::client "<<rank_<<" intraCommSize : "<<intraCommSize522 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< serverLeader<<endl ;523 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader, 0, &interComm) ;524 //rank_ = intraCommRank;525 }526 else527 {528 MPI_Comm_dup(intraComm,&interComm) ;529 }530 delete [] hashAll ;531 }532 // localComm argument is given533 else534 {535 if (CXios::usingServer)536 {537 //ERROR("void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)", << " giving a local communictor is not compatible with using server mode") ;538 }539 else540 {541 MPI_Comm_dup(localComm,&intraComm) ;542 MPI_Comm_dup(intraComm,&interComm) ;543 }544 }545 }546 // using OASIS547 else548 {549 // localComm isn't given550 if (localComm == MPI_COMM_NULL)551 {552 if (!is_MPI_Initialized) oasis_init(codeId) ;553 oasis_get_localcomm(localComm) ;554 }555 MPI_Comm_dup(localComm,&intraComm) ;556 557 CTimer::get("XIOS").resume() ;558 CTimer::get("XIOS init/finalize",false).resume() ;559 560 if (CXios::usingServer)561 {562 MPI_Status status ;563 MPI_Comm_rank(intraComm,&rank_) ;564 565 oasis_get_intercomm(interComm,CXios::xiosCodeId) ;566 if (rank_==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;567 MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ;568 }569 else MPI_Comm_dup(intraComm,&interComm) ;570 }571 572 MPI_Comm_dup(intraComm,&returnComm) ;573 }574 575 576 577 void CClient::registerContext(const string& id, MPI_Comm contextComm)578 {579 int commRank, commSize ;580 MPI_Comm_rank(contextComm,&commRank) ;581 MPI_Comm_size(contextComm,&commSize) ;582 583 getPoolRessource()->createService(contextComm, id, 0, CServicesManager::CLIENT, 1) ;584 getPoolRessource()->createService(contextComm, CXios::defaultServerId, 0, CServicesManager::IO_SERVER, 1) ;585 586 if (commRank==0) while (!CXios::getServicesManager()->hasService(getPoolRessource()->getId(), id, 0)) { CXios::getDaemonsManager()->eventLoop();}587 588 if (commRank==0) CXios::getContextsManager()->createServerContext(getPoolRessource()->getId(), id, 0, id) ;589 int type=CServicesManager::CLIENT ;590 string name = CXios::getContextsManager()->getServerContextName(getPoolRessource()->getId(), id, 0, type, id) ;591 while (!CXios::getContextsManager()->hasContext(name, contextComm) )592 {593 CXios::getDaemonsManager()->eventLoop() ;594 }595 596 /*597 598 CContext::setCurrent(id) ;599 CContext* context=CContext::create(id);600 601 // register the new client side context to the contexts manager602 if (commRank==0)603 {604 MPI_Comm_rank(CXios::getXiosComm(),&commRank) ;605 SRegisterContextInfo contextInfo ;606 contextInfo.serviceType=CServicesManager::CLIENT ;607 contextInfo.partitionId=0 ;608 contextInfo.leader=commRank ;609 contextInfo.size=commSize ;610 CXios::getContextsManager()->registerContext(id, contextInfo) ;611 }612 context->initClient(contextComm) ;613 */614 }615 616 409 617 410 ///--------------------------------------------------------------- … … 623 416 * Function is only called by client. 624 417 */ 625 void CClient::registerContext_old(const string& id, MPI_Comm contextComm) 626 { 627 CContext::setCurrent(id) ; 628 CContext* context=CContext::create(id); 629 StdString idServer(id); 630 idServer += "_server"; 631 632 if (CXios::isServer && !context->hasServer) 633 // Attached mode 634 { 635 MPI_Comm contextInterComm ; 636 MPI_Comm_dup(contextComm,&contextInterComm) ; 637 CContext* contextServer = CContext::create(idServer); 638 639 // Firstly, initialize context on client side 640 context->initClient(contextComm,contextInterComm, contextServer); 641 642 // Secondly, initialize context on server side 643 contextServer->initServer(contextComm,contextInterComm, context); 644 645 // Finally, we should return current context to context client 646 CContext::setCurrent(id); 647 648 contextInterComms.push_back(contextInterComm); 649 } 650 else 651 { 652 int size,rank,globalRank ; 653 size_t message_size ; 654 int leaderRank ; 655 MPI_Comm contextInterComm ; 656 657 MPI_Comm_size(contextComm,&size) ; 658 MPI_Comm_rank(contextComm,&rank) ; 659 MPI_Comm_rank(CXios::globalComm,&globalRank) ; 660 if (rank!=0) globalRank=0 ; 661 662 CMessage msg ; 663 msg<<idServer<<size<<globalRank ; 664 // msg<<id<<size<<globalRank ; 665 666 int messageSize=msg.size() ; 667 char * buff = new char[messageSize] ; 668 CBufferOut buffer((void*)buff,messageSize) ; 669 buffer<<msg ; 670 671 MPI_Send((void*)buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ; 672 673 MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ; 674 info(10)<<"Register new Context : "<<id<<endl ; 675 MPI_Comm inter ; 676 MPI_Intercomm_merge(contextInterComm,0,&inter) ; 677 MPI_Barrier(inter) ; 678 679 context->initClient(contextComm,contextInterComm) ; 680 681 contextInterComms.push_back(contextInterComm); 682 MPI_Comm_free(&inter); 683 delete [] buff ; 684 685 } 686 } 418 void CClient::registerContext(const string& id, MPI_Comm contextComm) 419 { 420 int commRank, commSize ; 421 MPI_Comm_rank(contextComm,&commRank) ; 422 MPI_Comm_size(contextComm,&commSize) ; 423 424 getPoolRessource()->createService(contextComm, id, 0, CServicesManager::CLIENT, 1) ; 425 getPoolRessource()->createService(contextComm, CXios::defaultServerId, 0, CServicesManager::IO_SERVER, 1) ; 426 427 if (commRank==0) while (!CXios::getServicesManager()->hasService(getPoolRessource()->getId(), id, 0)) { CXios::getDaemonsManager()->eventLoop();} 428 429 if (commRank==0) CXios::getContextsManager()->createServerContext(getPoolRessource()->getId(), id, 0, id) ; 430 int type=CServicesManager::CLIENT ; 431 string name = CXios::getContextsManager()->getServerContextName(getPoolRessource()->getId(), id, 0, type, id) ; 432 while (!CXios::getContextsManager()->hasContext(name, contextComm) ) 433 { 434 CXios::getDaemonsManager()->eventLoop() ; 435 } 436 437 } 438 439 687 440 688 441 /*! … … 759 512 760 513 761 void CClient::finalize_old(void)762 {763 int rank ;764 int msg=0 ;765 766 MPI_Comm_rank(intraComm,&rank) ;767 768 if (!CXios::isServer)769 {770 MPI_Comm_rank(intraComm,&rank) ;771 if (rank==0)772 {773 MPI_Send(&msg,1,MPI_INT,0,0,interComm) ;774 }775 }776 777 for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)778 MPI_Comm_free(&(*it));779 MPI_Comm_free(&interComm);780 MPI_Comm_free(&intraComm);781 782 CTimer::get("XIOS init/finalize",false).suspend() ;783 CTimer::get("XIOS").suspend() ;784 785 if (!is_MPI_Initialized)786 {787 if (CXios::usingOasis) oasis_finalize();788 else MPI_Finalize() ;789 }790 791 info(20) << "Client side context is finalized"<<endl ;792 report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ;793 report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ;794 report(0)<< " Performance report : time spent for waiting free buffer : "<< CTimer::get("Blocking time").getCumulatedTime()<<" s"<<endl ;795 report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS init/finalize").getCumulatedTime()*100.<<" %"<<endl ;796 report(0)<< " Performance report : This ratio must be close to zero. Otherwise it may be usefull to increase buffer size or numbers of server"<<endl ;797 // report(0)<< " Memory report : Current buffer_size : "<<CXios::bufferSize<<endl ;798 report(0)<< " Memory report : Minimum buffer size required : " << CClientBuffer::maxRequestSize << " bytes" << endl ;799 report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;800 report(100)<<CTimer::getAllCumulatedTime()<<endl ;801 }802 803 514 /*! 804 515 * Return global rank without oasis and current rank in model intraComm in case of oasis
Note: See TracChangeset
for help on using the changeset viewer.