Changeset 1130 for XIOS/dev/dev_olga/src/node
- Timestamp:
- 05/15/17 15:00:24 (7 years ago)
- Location:
- XIOS/dev/dev_olga/src/node
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/node/context.cpp
r1129 r1130 26 26 : CObjectTemplate<CContext>(), CContextAttributes() 27 27 , calendar(), hasClient(false), hasServer(false) 28 , isPostProcessed(false) , finalized(false)28 , isPostProcessed(false)//, finalized(false) 29 29 , idServer_(), client(0), server(0) 30 , allProcessed(false) 30 , allProcessed(false), countChildCtx_(0) 31 31 { /* Ne rien faire de plus */ } 32 32 … … 34 34 : CObjectTemplate<CContext>(id), CContextAttributes() 35 35 , calendar(), hasClient(false), hasServer(false) 36 , isPostProcessed(false) , finalized(false)36 , isPostProcessed(false)//, finalized(false) 37 37 , idServer_(), client(0), server(0) 38 , allProcessed(false) 38 , allProcessed(false), countChildCtx_(0) 39 39 { /* Ne rien faire de plus */ } 40 40 … … 300 300 std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize); 301 301 302 303 302 std::map<int, StdSize>::iterator it, ite = dataBufferSize.end(); 304 303 for (it = dataBufferSize.begin(); it != ite; ++it) … … 351 350 hasServer=true; 352 351 server = new CContextServer(this,intraComm,interComm); 353 // client = new CContextClient(this,intraComm,interComm, cxtClient);354 352 355 353 registryIn=new CRegistry(intraComm); … … 373 371 comms.push_back(interCommClient); 374 372 } 375 client = new CContextClient(this,intraCommClient,interCommClient); 376 373 client = new CContextClient(this,intraCommClient,interCommClient,cxtClient); 377 374 } 378 375 379 376 //! Try to send the buffers and receive possible answers 380 bool CContext::checkBuffersAndListen(void) 381 { 382 if (CServer::serverLevel == 0) 383 { 384 client->checkBuffers(); 385 bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); 386 if (hasTmpBufferedEvent) 387 hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); 388 // Don't process events if there is a temporarily buffered event 389 return server->eventLoop(!hasTmpBufferedEvent); 390 } 391 392 else if (CServer::serverLevel == 1) 393 { 394 client->checkBuffers(); 395 bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); 396 if (hasTmpBufferedEvent) 397 hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); 398 bool serverFinished = server->eventLoop(!hasTmpBufferedEvent); 399 400 bool serverPrimFinished = true; 401 for (int i = 0; i < clientPrimServer.size(); ++i) 402 { 403 clientPrimServer[i]->checkBuffers(); 404 bool hasTmpBufferedEventPrim = clientPrimServer[i]->hasTemporarilyBufferedEvent(); 405 if (hasTmpBufferedEventPrim) 406 hasTmpBufferedEventPrim = !clientPrimServer[i]->sendTemporarilyBufferedEvent(); 407 // serverPrimFinished *= serverPrimServer[i]->eventLoop(!hasTmpBufferedEventPrim); 408 serverPrimFinished *= serverPrimServer[i]->eventLoop(); 409 } 410 return ( serverFinished && serverPrimFinished); 411 } 412 413 else if (CServer::serverLevel == 2) 414 { 415 client->checkBuffers(); 416 bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); 417 // if (hasTmpBufferedEvent) 418 // hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); 419 // return server->eventLoop(!hasTmpBufferedEvent); 420 return server->eventLoop(); 377 bool CContext::checkBuffersAndListen(void) 378 { 379 bool clientReady, serverFinished; 380 381 // Only classical servers are non-blocking 382 if (CServer::serverLevel == 0) 383 { 384 client->checkBuffers(); 385 bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent(); 386 if (hasTmpBufferedEvent) 387 hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent(); 388 // Don't process events if there is a temporarily buffered event 389 return server->eventLoop(!hasTmpBufferedEvent); 390 } 391 else if (CServer::serverLevel == 1) 392 { 393 client->checkBuffers(); 394 bool serverFinished = server->eventLoop(); 395 bool serverPrimFinished = true; 396 for (int i = 0; i < clientPrimServer.size(); ++i) 397 { 398 clientPrimServer[i]->checkBuffers(); 399 serverPrimFinished *= serverPrimServer[i]->eventLoop(); 421 400 } 422 } 401 return ( serverFinished && serverPrimFinished); 402 } 403 404 else if (CServer::serverLevel == 2) 405 { 406 client->checkBuffers(); 407 return server->eventLoop(); 408 } 409 } 423 410 424 411 //! Terminate a context 425 412 void CContext::finalize(void) 426 413 { 427 if (!finalized) 428 { 429 finalized = true; 430 414 // Send registry upon calling the function the first time 415 if (countChildCtx_ == 0) 431 416 if (hasClient) sendRegistry() ; 432 417 433 if ((hasClient) && (hasServer)) 418 // Client: 419 // (1) blocking send context finalize to its server 420 // (2) blocking receive context finalize from its server 421 if (CXios::isClient) 422 { 423 // Make sure that client (model) enters the loop only once 424 if (countChildCtx_ < 1) 434 425 { 426 ++countChildCtx_; 427 428 client->finalize(); 429 while (client->havePendingRequests()) 430 client->checkBuffers(); 431 432 while (!server->hasFinished()) 433 server->eventLoop(); 434 } 435 } 436 // Server: non-blocking send context finalize 437 else if (CXios::isServer) 438 { 439 // First context finalize message received from a model => send context finalize to its child contexts (if any) 440 if (countChildCtx_ == 0) 435 441 for (int i = 0; i < clientPrimServer.size(); ++i) 436 442 clientPrimServer[i]->finalize(); 437 443 438 for (int i = 0; i < serverPrimServer.size(); ++i) 439 { 440 while (!serverPrimServer[i]->hasFinished()) 441 { 442 serverPrimServer[i]->eventLoop(); 443 CServer::eventScheduler->checkEvent() ; 444 } 445 } 446 } 447 client->finalize(); 448 while (!server->hasFinished()) 449 { 450 server->eventLoop(); 451 } 452 453 info(20)<<"Server Side context <"<<getId()<<"> finalized"<<endl; 454 report(0)<< " Memory report : Context <"<<getId()<<"> : server side : total memory used for buffers "<<CContextServer::getTotalBuf()<<" bytes"<<endl; 455 456 // if (hasServer) 457 if (hasServer && !hasClient) 458 { 459 closeAllFile(); 460 registryOut->hierarchicalGatherRegistry() ; 461 if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 462 } 463 } 464 } 465 466 //! Free internally allocated communicators 467 void CContext::freeComms(void) 468 { 444 // (Last) context finalized message received => send context finalize to its parent context 445 if (countChildCtx_ == clientPrimServer.size()) 446 client->finalize(); 447 448 ++countChildCtx_; 449 } 450 451 // If in mode attache call postFinalize 452 if (CXios::isServer && CXios::isClient) 453 postFinalize(); 454 } 455 456 /*! 457 * \fn void CContext::postFinalize(void) 458 * Close files, gather registries, , and make deallocations. 459 * Function is called when a context is finalized (it has nothing to receive and nothing to send). 460 */ 461 void CContext::postFinalize(void) 462 { 463 info(20)<<"Context <"<<getId()<<"> is finalized."<<endl; 464 465 // if (hasServer && !hasClient) 466 { 467 closeAllFile(); 468 registryOut->hierarchicalGatherRegistry() ; 469 if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ; 470 } 471 472 //! Free internally allocated communicators 469 473 for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) 470 474 MPI_Comm_free(&(*it)); 471 475 comms.clear(); 476 477 //! Deallocate client buffers 478 client->releaseBuffers(); 479 for (int i = 0; i < clientPrimServer.size(); ++i) 480 clientPrimServer[i]->releaseBuffers(); 481 } 482 483 //! Free internally allocated communicators 484 void CContext::freeComms(void) 485 { 486 for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it) 487 MPI_Comm_free(&(*it)); 488 comms.clear(); 489 } 490 491 //! Deallocate buffers allocated by clientContexts 492 void CContext::releaseClientBuffers(void) 493 { 494 client->releaseBuffers(); 495 for (int i = 0; i < clientPrimServer.size(); ++i) 496 clientPrimServer[i]->releaseBuffers(); 472 497 } 473 498 … … 509 534 510 535 // After that, send all grid (if any) 511 sendRefGrid(); 536 sendRefGrid(); 512 537 513 538 // We have a xml tree on the server side and now, it should be also processed 514 539 sendPostProcessing(); 515 516 540 sendGridEnabledFields(); 517 541 } 518 519 542 allProcessed = true; 520 543 } … … 555 578 556 579 void CContext::recvPostProcessingGlobalAttributes(CBufferIn& buffer) 557 { 580 { 581 // CCalendarWrapper::get(CCalendarWrapper::GetDefName())->createCalendar(); 558 582 postProcessingGlobalAttributes(); 559 583 } … … 572 596 postProcessingGlobalAttributes(); 573 597 574 if (hasClient) sendPostProcessingGlobalAttributes(); 575 598 if (hasClient) sendPostProcessingGlobalAttributes(); 599 600 // There are some processings that should be done after all of above. For example: check mask or index 576 601 this->buildFilterGraphOfEnabledFields(); 577 602 578 if (hasClient && !hasServer)603 if (hasClient && !hasServer) 579 604 { 580 buildFilterGraphOfFieldsWithReadAccess(); 605 buildFilterGraphOfFieldsWithReadAccess(); 581 606 } 582 607 … … 622 647 { 623 648 this->enabledFiles[i]->solveOnlyRefOfEnabledFields(false); 624 // this->enabledFiles[i]->solveAllReferenceEnabledField(false);625 649 } 626 650 … … 649 673 } 650 674 651 652 653 675 void CContext::solveOnlyRefOfEnabledFields(bool sendToServer) 654 676 { … … 663 685 this->enabledFiles[i]->generateNewTransformationGridDest(); 664 686 } 687 665 688 } 666 689 … … 857 880 } 858 881 859 // // Only send close definition from process having hasClient860 // void CContext::sendCloseDefinitionToServer(void)861 // {862 // CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION);863 // }864 865 882 //! Client side: Send a message to server to make it close 866 883 void CContext::sendCloseDefinition(void) 867 884 { 868 885 // Use correct context client to send message 869 // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1;870 886 int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; 871 887 for (int i = 0; i < nbSrvPools; ++i) … … 902 918 { 903 919 // Use correct context client to send message 904 // CContextClient* contextClientTmp = (0 != clientPrimServer) ? clientPrimServer : client;905 // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1;906 920 int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1; 907 921 for (int i = 0; i < nbSrvPools; ++i) … … 1462 1476 void CContext::updateCalendar(int step) 1463 1477 { 1464 info(50) << "updateCalendar : before : " << calendar->getCurrentDate() << endl;1478 info(50) <<"Context "<< this->getId() <<" updateCalendar : before : " << calendar->getCurrentDate() << endl; 1465 1479 calendar->update(step); 1466 info(50) << "updateCalendar : after : " << calendar->getCurrentDate() << endl;1480 info(50) <<"Context "<< this->getId() << " updateCalendar : after : " << calendar->getCurrentDate() << endl; 1467 1481 1468 1482 if (hasClient) … … 1569 1583 } 1570 1584 1585 /*! 1586 * \fn bool CContext::isFinalized(void) 1587 * Context is finalized if: 1588 * (1) it has received all context finalize events 1589 * (2) it has no pending events to send. 1590 */ 1571 1591 bool CContext::isFinalized(void) 1572 1592 { 1573 return finalized; 1593 if (countChildCtx_==clientPrimServer.size()+1) 1594 { 1595 bool buffersReleased = !client->havePendingRequests(); 1596 for (int i = 0; i < clientPrimServer.size(); ++i) 1597 buffersReleased *= !clientPrimServer[i]->havePendingRequests(); 1598 return buffersReleased; 1599 } 1600 else 1601 return false; 1574 1602 } 1575 1603 -
XIOS/dev/dev_olga/src/node/context.hpp
r1129 r1130 99 99 // Finalize a context 100 100 void finalize(void); 101 void postFinalize(void); 102 bool isFinalized(void); 103 101 104 void closeDefinition(void); 102 bool isFinalized(void);103 105 104 106 // Some functions to process context … … 167 169 void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers 168 170 169 void freeComms(void); //!< Free internally allcoated communicators 171 void freeComms(void); //!< Free internally allcoated communicators 172 void releaseClientBuffers(void); //! Deallocate buffers allocated by clientContexts 170 173 171 174 // dispatch event … … 233 236 bool hasServer; 234 237 235 CContextServer* server; //!< Concrete context server236 CContextClient* client; //!< Concrete contex client238 CContextServer* server; //!< Concrete context server 239 CContextClient* client; //!< Concrete contex client 237 240 std::vector<CContextServer*> serverPrimServer; 238 241 std::vector<CContextClient*> clientPrimServer; 239 242 240 CRegistry* registryIn ; //!< input registry which is read from file241 CRegistry* registryOut ; //!< output registry which will be wrote onfile at the finalize243 CRegistry* registryIn ; //!< input registry which is read from file 244 CRegistry* registryOut ; //!< output registry which will be written into file at the finalize 242 245 243 246 private: 244 247 bool isPostProcessed; 245 248 bool allProcessed; 246 bool finalized; 249 // bool finalized; 250 int countChildCtx_; //!< Counter of child contexts (for now it is the number of secondary server pools) 247 251 StdString idServer_; 248 252 CGarbageCollector garbageCollector; -
XIOS/dev/dev_olga/src/node/domain.cpp
r1129 r1130 3051 3051 if ((0 <= indexI) && (0 <= indexJ)) 3052 3052 { 3053 data_i_index(nbCompressedData) = (1 == data_dim) ? ind : i _index(ind) - i_index(0);3054 data_j_index(nbCompressedData) = (1 == data_dim) ? 0 : j_index(ind) - j_index(0);3053 data_i_index(nbCompressedData) = (1 == data_dim) ? ind : ind % ni; 3054 data_j_index(nbCompressedData) = (1 == data_dim) ? 0 : ind / ni; 3055 3055 ++nbCompressedData; 3056 3056 } -
XIOS/dev/dev_olga/src/node/file.cpp
r1129 r1130 866 866 { 867 867 sendAddItem(id, EVENT_ID_ADD_FIELD); 868 // CContext* context = CContext::getCurrent();869 870 // if (! context->hasServer )871 // {872 // CContextClient* client = context->client;873 874 // CEventClient event(this->getType(),EVENT_ID_ADD_FIELD);875 // if (client->isServerLeader())876 // {877 // CMessage msg;878 // msg << this->getId();879 // msg << id;880 // const std::list<int>& ranks = client->getRanksServerLeader();881 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)882 // event.push(*itRank,1,msg);883 // client->sendEvent(event);884 // }885 // else client->sendEvent(event);886 // }887 888 868 } 889 869 … … 891 871 { 892 872 sendAddItem(id, EVENT_ID_ADD_FIELD, client); 893 // CContext* context = CContext::getCurrent();894 895 // if (! context->hasServer )896 // {897 // CContextClient* client = context->client;898 899 // CEventClient event(this->getType(),EVENT_ID_ADD_FIELD);900 // if (client->isServerLeader())901 // {902 // CMessage msg;903 // msg << this->getId();904 // msg << id;905 // const std::list<int>& ranks = client->getRanksServerLeader();906 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)907 // event.push(*itRank,1,msg);908 // client->sendEvent(event);909 // }910 // else client->sendEvent(event);911 // }912 913 873 } 914 874 … … 920 880 { 921 881 sendAddItem(id, (int)EVENT_ID_ADD_FIELD_GROUP); 922 // CContext* context = CContext::getCurrent();923 // if (! context->hasServer )924 // {925 // CContextClient* client = context->client;926 927 // CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP);928 // if (client->isServerLeader())929 // {930 // CMessage msg;931 // msg << this->getId();932 // msg << id;933 // const std::list<int>& ranks = client->getRanksServerLeader();934 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)935 // event.push(*itRank,1,msg);936 // client->sendEvent(event);937 // }938 // else client->sendEvent(event);939 // }940 941 882 } 942 883 … … 1030 971 { 1031 972 sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE_GROUP); 1032 // CContext* context = CContext::getCurrent();1033 // if (! context->hasServer )1034 // {1035 // CContextClient* client = context->client;1036 1037 // CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP);1038 // if (client->isServerLeader())1039 // {1040 // CMessage msg;1041 // msg << this->getId();1042 // msg << id;1043 // const std::list<int>& ranks = client->getRanksServerLeader();1044 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)1045 // event.push(*itRank,1,msg);1046 // client->sendEvent(event);1047 // }1048 // else client->sendEvent(event);1049 // }1050 1051 973 } 1052 974 … … 1059 981 { 1060 982 sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE); 1061 // CContext* context = CContext::getCurrent();1062 1063 // if (! context->hasServer )1064 // {1065 // CContextClient* client = context->client;1066 1067 // CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE);1068 // if (client->isServerLeader())1069 // {1070 // CMessage msg;1071 // msg << this->getId();1072 // msg << id;1073 // const std::list<int>& ranks = client->getRanksServerLeader();1074 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)1075 // event.push(*itRank,1,msg);1076 // client->sendEvent(event);1077 // }1078 // else client->sendEvent(event);1079 // }1080 1081 983 } 1082 984 1083 985 void CFile::sendAddVariable(const string& id, CContextClient* client) 1084 986 { 1085 sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE); 1086 // CContext* context = CContext::getCurrent(); 1087 1088 // if (! context->hasServer ) 1089 // { 1090 // CContextClient* client = context->client; 1091 1092 // CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); 1093 // if (client->isServerLeader()) 1094 // { 1095 // CMessage msg; 1096 // msg << this->getId(); 1097 // msg << id; 1098 // const std::list<int>& ranks = client->getRanksServerLeader(); 1099 // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1100 // event.push(*itRank,1,msg); 1101 // client->sendEvent(event); 1102 // } 1103 // else client->sendEvent(event); 1104 // } 1105 987 sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE, client); 1106 988 } 1107 989 … … 1153 1035 addVariableGroup(id); 1154 1036 } 1155 1156 /*!1157 \brief Sending all active (enabled) fields from client to server.1158 Each field is identified uniquely by its string identity. Not only should we1159 send the id to server but also we need to send ids of reference domain and reference axis.1160 With these two id, it's easier to make reference to grid where all data should be written.1161 Remark: This function must be called AFTER all active (enabled) files have been created on the server side1162 */1163 // void CFile::sendEnabledFields()1164 // {1165 // size_t size = this->enabledFields.size();1166 // for (size_t i = 0; i < size; ++i)1167 // {1168 // CField* field = this->enabledFields[i];1169 // this->sendAddField(field->getId());1170 // field->sendAllAttributesToServer();1171 // field->sendAddAllVariables();1172 // }1173 // }1174 1037 1175 1038 /*!
Note: See TracChangeset
for help on using the changeset viewer.