Changeset 1784 for XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp
- Timestamp:
- 12/12/19 18:15:14 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp
r1766 r1784 24 24 #include "cxios.hpp" 25 25 #include "client.hpp" 26 #include "coupler_in.hpp" 27 #include "coupler_out.hpp" 26 28 27 29 namespace xios { … … 353 355 { 354 356 intraComm_=intraComm ; 357 MPI_Comm_rank(intraComm_, &intraCommRank_) ; 358 MPI_Comm_size(intraComm_, &intraCommSize_) ; 359 355 360 serviceType_ = CServicesManager::CLIENT ; 356 361 if (serviceType_==CServicesManager::CLIENT) … … 385 390 hasServer=true; 386 391 intraComm_=intraComm ; 392 MPI_Comm_rank(intraComm_, &intraCommRank_) ; 393 MPI_Comm_size(intraComm_, &intraCommSize_) ; 394 387 395 serviceType_=serviceType ; 388 396 … … 544 552 } 545 553 554 for (auto it=couplerClient_.begin(); it!=couplerClient_.end(); ++it) 555 { 556 if (!finalized) it->second->checkBuffers(); 557 } 558 559 for (auto it=couplerServer_.begin(); it!=couplerServer_.end(); ++it) 560 { 561 if (!finalized) it->second->eventLoop(enableEventsProcessing); 562 } 563 546 564 if (server!=nullptr) if (!finalized) finished &= server->eventLoop(enableEventsProcessing); 547 565 … … 549 567 } 550 568 551 569 void CContext::addCouplingChanel(const std::string& context, bool out) 570 { 571 vector<string> vectStr=splitRegex(context,"::") ; 572 string poolId=vectStr[0] ; 573 string serviceId=poolId ; 574 string contextId=vectStr[1] ; 575 576 int contextLeader ; 577 int type = CServicesManager::CLIENT ; 578 string contextName=CXios::getContextsManager()->getServerContextName(poolId, serviceId, 0, type, contextId) ; 579 580 if (couplerClient_.find(contextName)==couplerClient_.end()) 581 { 582 bool ok=CXios::getContextsManager()->getContextLeader(contextName, contextLeader, getIntraComm()) ; 583 584 MPI_Comm interComm, interCommClient, interCommServer ; 585 MPI_Comm intraCommClient, intraCommServer ; 586 587 if (ok) MPI_Intercomm_create(getIntraComm(), 0, CXios::getXiosComm(), contextLeader, 0, &interComm) ; 588 589 MPI_Comm_dup(intraComm_, &intraCommClient) ; 590 MPI_Comm_dup(intraComm_, &intraCommServer) ; 591 if (out) 592 { 593 MPI_Comm_dup(interComm, &interCommClient) ; 594 MPI_Comm_dup(interComm, &interCommServer) ; 595 CContextClient* client = new CContextClient(this, intraCommClient, interCommClient); 596 CContextServer* server = new CContextServer(this, intraCommServer, interCommServer); 597 } 598 else 599 { 600 MPI_Comm_dup(interComm, &interCommServer) ; 601 MPI_Comm_dup(interComm, &interCommClient) ; 602 CContextServer* server = new CContextServer(this, intraCommServer, interCommServer); 603 CContextClient* client = new CContextClient(this, intraCommClient, interCommClient); 604 } 605 MPI_Comm_free(&interComm) ; 606 607 608 // for now, we don't now which beffer size must be used for client coupler 609 // It will be evaluated later. Fix a constant size for now... 610 // set to 10Mb for development 611 map<int,size_t> bufferSize, maxEventSize ; 612 for(int i=0;i<client->getRemoteSize();i++) 613 { 614 bufferSize[i]=10000000 ; 615 maxEventSize[i]=10000000 ; 616 } 617 618 client->setBufferSize(bufferSize, maxEventSize); 619 620 couplerClient_[contextName] = client ; 621 couplerServer_[contextName] = server ; 622 } 623 } 552 624 553 625 void CContext::globalEventLoop(void) … … 649 721 postProcessing(); 650 722 723 // Distribute files between secondary servers according to the data size 724 distributeFiles(); 725 651 726 // Check grid and calculate its distribution 652 727 checkGridEnabledFields(); 653 654 // Distribute files between secondary servers according to the data size655 distributeFiles();656 728 657 729 setClientServerBuffer(client, (hasClient && !hasServer)); … … 659 731 setClientServerBuffer(clientPrimServer[i], true); 660 732 733 661 734 if (hasClient) 662 { 663 // Send all attributes of current context to server 664 this->sendAllAttributesToServer(); 665 666 // Send all attributes of current calendar 667 CCalendarWrapper::get(CCalendarWrapper::GetDefName())->sendAllAttributesToServer(); 735 { 736 if (hasServer) 737 { 738 for (auto it=clientPrimServer.begin(); it!=clientPrimServer.end();++it) 739 { 740 this->sendAllAttributesToServer(*it); // Send all attributes of current context to server 741 CCalendarWrapper::get(CCalendarWrapper::GetDefName())->sendAllAttributesToServer(*it); // Send all attributes of current calendar 742 } 743 } 744 else 745 { 746 this->sendAllAttributesToServer(client); // Send all attributes of current context to server 747 CCalendarWrapper::get(CCalendarWrapper::GetDefName())->sendAllAttributesToServer(client); // Send all attributes of current calendar 748 } 749 668 750 669 751 // We have enough information to send to server … … 779 861 { 780 862 buildFilterGraphOfFieldsWithReadAccess(); 781 postProcessFilterGraph(); 863 postProcessFilterGraph(); // For coupling in, modify this later 782 864 } 783 865 … … 849 931 enabledFiles[i]->checkGridOfEnabledFields(); 850 932 } 933 934 size = enabledCouplerOut.size(); 935 for (int i = 0; i < size; ++i) 936 { 937 enabledCouplerOut[i]->checkGridOfEnabledFields(); 938 } 851 939 } 852 940 CATCH_DUMP_ATTR … … 872 960 \param [in] sendToServer Flag to indicate whether calculated information will be sent 873 961 */ 874 void CContext::solveOnlyRefOfEnabledFields( bool sendToServer)962 void CContext::solveOnlyRefOfEnabledFields(void) 875 963 TRY 876 964 { … … 878 966 for (int i = 0; i < size; ++i) 879 967 { 880 this->enabledFiles[i]->solveOnlyRefOfEnabledFields( sendToServer);968 this->enabledFiles[i]->solveOnlyRefOfEnabledFields(); 881 969 } 882 970 … … 884 972 { 885 973 this->enabledFiles[i]->generateNewTransformationGridDest(); 974 } 975 976 size = this->enabledCouplerOut.size(); 977 for (int i = 0; i < size; ++i) 978 { 979 this->enabledCouplerOut[i]->solveOnlyRefOfEnabledFields(); 980 } 981 982 for (int i = 0; i < size; ++i) 983 { 984 this->enabledCouplerOut[i]->generateNewTransformationGridDest(); 886 985 } 887 986 } … … 894 993 \param [in] sendToServer Flag to indicate whether calculated information will be sent 895 994 */ 896 void CContext::solveAllRefOfEnabledFieldsAndTransform( bool sendToServer)995 void CContext::solveAllRefOfEnabledFieldsAndTransform(void) 897 996 TRY 898 997 { … … 900 999 for (int i = 0; i < size; ++i) 901 1000 { 902 this->enabledFiles[i]->solveAllRefOfEnabledFieldsAndTransform(sendToServer); 903 } 1001 this->enabledFiles[i]->solveAllRefOfEnabledFieldsAndTransform(); 1002 } 1003 1004 size = this->enabledCouplerOut.size(); 1005 for (int i = 0; i < size; ++i) 1006 { 1007 this->enabledCouplerOut[i]->solveAllRefOfEnabledFieldsAndTransform(); 1008 } 1009 904 1010 } 905 1011 CATCH_DUMP_ATTR … … 912 1018 { 913 1019 this->enabledFiles[i]->buildFilterGraphOfEnabledFields(garbageCollector); 1020 } 1021 1022 size = this->enabledCouplerOut.size(); 1023 for (int i = 0; i < size; ++i) 1024 { 1025 this->enabledCouplerOut[i]->buildFilterGraphOfEnabledFields(garbageCollector); 914 1026 } 915 1027 } … … 1002 1114 // Résolution des héritages par référence au niveau des fichiers. 1003 1115 const vector<CFile*> allFiles=CFile::getAll(); 1116 const vector<CCouplerIn*> allCouplerIn=CCouplerIn::getAll(); 1117 const vector<CCouplerOut*> allCouplerOut=CCouplerOut::getAll(); 1004 1118 const vector<CGrid*> allGrids= CGrid::getAll(); 1005 1119 … … 1009 1123 for (unsigned int i = 0; i < allFiles.size(); i++) 1010 1124 allFiles[i]->solveFieldRefInheritance(apply); 1125 1126 for (unsigned int i = 0; i < allCouplerIn.size(); i++) 1127 allCouplerIn[i]->solveFieldRefInheritance(apply); 1128 1129 for (unsigned int i = 0; i < allCouplerOut.size(); i++) 1130 allCouplerOut[i]->solveFieldRefInheritance(apply); 1011 1131 } 1012 1132 … … 1071 1191 CATCH_DUMP_ATTR 1072 1192 1193 void CContext::findEnabledCouplerIn(void) 1194 TRY 1195 { 1196 const std::vector<CCouplerIn*> allCouplerIn = CCouplerIn::getAll(); 1197 bool enabled ; 1198 for (size_t i = 0; i < allCouplerIn.size(); i++) 1199 { 1200 if (allCouplerIn[i]->enabled.isEmpty()) enabled=true ; 1201 else enabled=allCouplerIn[i]->enabled ; 1202 if (enabled) enabledCouplerIn.push_back(allCouplerIn[i]) ; 1203 } 1204 } 1205 CATCH_DUMP_ATTR 1206 1207 void CContext::findEnabledCouplerOut(void) 1208 TRY 1209 { 1210 const std::vector<CCouplerOut*> allCouplerOut = CCouplerOut::getAll(); 1211 bool enabled ; 1212 for (size_t i = 0; i < allCouplerOut.size(); i++) 1213 { 1214 if (allCouplerOut[i]->enabled.isEmpty()) enabled=true ; 1215 else enabled=allCouplerOut[i]->enabled ; 1216 if (enabled) enabledCouplerOut.push_back(allCouplerOut[i]) ; 1217 } 1218 } 1219 CATCH_DUMP_ATTR 1220 1221 1222 1223 1073 1224 void CContext::distributeFiles(void) 1074 1225 TRY … … 1669 1820 findEnabledWriteModeFiles(); 1670 1821 findEnabledReadModeFiles(); 1822 findEnabledCouplerIn(); 1823 findEnabledCouplerOut(); 1824 1825 createCouplerInterCommunicator() ; 1671 1826 1672 1827 // For now, only read files with client and only one level server … … 1689 1844 1690 1845 // Only search and rebuild all reference objects of enable fields, don't transform 1691 this->solveOnlyRefOfEnabledFields( false);1846 this->solveOnlyRefOfEnabledFields(); 1692 1847 1693 1848 // Search and rebuild all reference object of enabled fields, and transform 1694 this->solveAllRefOfEnabledFieldsAndTransform( false);1849 this->solveAllRefOfEnabledFieldsAndTransform(); 1695 1850 1696 1851 // Find all fields with read access from the public API … … 1700 1855 1701 1856 isPostProcessed = true; 1857 } 1858 CATCH_DUMP_ATTR 1859 1860 void CContext::createCouplerInterCommunicator(void) 1861 TRY 1862 { 1863 // juste for test now, in future need an scheduler to avoid dead-lock 1864 for(auto it=enabledCouplerOut.begin();it!=enabledCouplerOut.end();++it) 1865 { 1866 (*it)->createInterCommunicator() ; 1867 } 1868 1869 for(auto it=enabledCouplerIn.begin();it!=enabledCouplerIn.end();++it) 1870 { 1871 (*it)->createInterCommunicator() ; 1872 } 1702 1873 } 1703 1874 CATCH_DUMP_ATTR … … 1953 2124 TRY 1954 2125 { 1955 std::set<StdString> gridIds; 2126 std::set<pair<StdString,CContextClient*>> gridIds; 2127 1956 2128 int sizeFile = activeFiles.size(); 1957 2129 CFile* filePtr(NULL); … … 1966 2138 { 1967 2139 if (0 != enabledFields[numField]->getRelGrid()) 1968 gridIds.insert( CGrid::get(enabledFields[numField]->getRelGrid())->getId());2140 gridIds.insert(make_pair(CGrid::get(enabledFields[numField]->getRelGrid())->getId(),enabledFields[numField]->getContextClient())); 1969 2141 } 1970 2142 } … … 1973 2145 StdString gridDefRoot("grid_definition"); 1974 2146 CGridGroup* gridPtr = CGridGroup::get(gridDefRoot); 1975 std::set<StdString>::const_iterator it, itE = gridIds.end(); 1976 for (it = gridIds.begin(); it != itE; ++it) 1977 { 1978 gridPtr->sendCreateChild(*it); 1979 CGrid::get(*it)->sendAllAttributesToServer(); 1980 CGrid::get(*it)->sendAllDomains(); 1981 CGrid::get(*it)->sendAllAxis(); 1982 CGrid::get(*it)->sendAllScalars(); 2147 for (auto it = gridIds.begin(); it != gridIds.end(); ++it) 2148 { 2149 gridPtr->sendCreateChild(it->first,it->second); 2150 CGrid::get(it->first)->sendAllAttributesToServer(it->second); 2151 CGrid::get(it->first)->sendAllDomains(it->second); 2152 CGrid::get(it->first)->sendAllAxis(it->second); 2153 CGrid::get(it->first)->sendAllScalars(it->second); 1983 2154 } 1984 2155 } … … 1989 2160 TRY 1990 2161 { 1991 std::set< StdString> domainIds, axisIds, scalarIds;2162 std::set<pair<StdString,CContextClient*>> domainIds, axisIds, scalarIds; 1992 2163 1993 2164 // Find all reference domain and axis of all active fields … … 1999 2170 for (int j = 0; j < numEnabledFields; ++j) 2000 2171 { 2172 CContextClient* contextClient=enabledFields[j]->getContextClient() ; 2001 2173 const std::vector<StdString>& prDomAxisScalarId = enabledFields[j]->getRefDomainAxisIds(); 2002 if ("" != prDomAxisScalarId[0]) domainIds.insert( prDomAxisScalarId[0]);2003 if ("" != prDomAxisScalarId[1]) axisIds.insert( prDomAxisScalarId[1]);2004 if ("" != prDomAxisScalarId[2]) scalarIds.insert( prDomAxisScalarId[2]);2174 if ("" != prDomAxisScalarId[0]) domainIds.insert(make_pair(prDomAxisScalarId[0],contextClient)); 2175 if ("" != prDomAxisScalarId[1]) axisIds.insert(make_pair(prDomAxisScalarId[1],contextClient)); 2176 if ("" != prDomAxisScalarId[2]) scalarIds.insert(make_pair(prDomAxisScalarId[2],contextClient)); 2005 2177 } 2006 2178 } … … 2012 2184 StdString scalarDefRoot("scalar_definition"); 2013 2185 CScalarGroup* scalarPtr = CScalarGroup::get(scalarDefRoot); 2014 itE = scalarIds.end();2015 for ( itScalar = scalarIds.begin(); itScalar != itE; ++itScalar)2016 { 2017 if (!itScalar-> empty())2186 2187 for (auto itScalar = scalarIds.begin(); itScalar != scalarIds.end(); ++itScalar) 2188 { 2189 if (!itScalar->first.empty()) 2018 2190 { 2019 scalarPtr->sendCreateChild( *itScalar);2020 CScalar::get( *itScalar)->sendAllAttributesToServer();2191 scalarPtr->sendCreateChild(itScalar->first,itScalar->second); 2192 CScalar::get(itScalar->first)->sendAllAttributesToServer(itScalar->second); 2021 2193 } 2022 2194 } … … 2024 2196 StdString axiDefRoot("axis_definition"); 2025 2197 CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); 2026 itE = axisIds.end();2027 for ( itAxis = axisIds.begin(); itAxis != itE; ++itAxis)2028 { 2029 if (!itAxis-> empty())2198 2199 for (auto itAxis = axisIds.begin(); itAxis != axisIds.end(); ++itAxis) 2200 { 2201 if (!itAxis->first.empty()) 2030 2202 { 2031 axisPtr->sendCreateChild( *itAxis);2032 CAxis::get( *itAxis)->sendAllAttributesToServer();2203 axisPtr->sendCreateChild(itAxis->first, itAxis->second); 2204 CAxis::get(itAxis->first)->sendAllAttributesToServer(itAxis->second); 2033 2205 } 2034 2206 } … … 2037 2209 StdString domDefRoot("domain_definition"); 2038 2210 CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); 2039 itE = domainIds.end();2040 for ( itDom = domainIds.begin(); itDom != itE; ++itDom)2041 { 2042 if (!itDom-> empty()) {2043 domPtr->sendCreateChild( *itDom);2044 CDomain::get( *itDom)->sendAllAttributesToServer();2211 2212 for (auto itDom = domainIds.begin(); itDom != domainIds.end(); ++itDom) 2213 { 2214 if (!itDom->first.empty()) { 2215 domPtr->sendCreateChild(itDom->first, itDom->second); 2216 CDomain::get(itDom->first)->sendAllAttributesToServer(itDom->second); 2045 2217 } 2046 2218 }
Note: See TracChangeset
for help on using the changeset viewer.