Changeset 1918 for XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp
- Timestamp:
- 07/16/20 17:18:01 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp
r1879 r1918 18 18 #include "server_distribution_description.hpp" 19 19 #include "client_server_mapping_distributed.hpp" 20 #include "local_connector.hpp" 21 #include "grid_local_connector.hpp" 22 #include "remote_connector.hpp" 23 #include "gatherer_connector.hpp" 24 #include "scatterer_connector.hpp" 25 #include "grid_scatterer_connector.hpp" 26 #include "grid_gatherer_connector.hpp" 27 28 29 20 30 21 31 #include <algorithm> … … 1734 1744 this->computeLocalMask() ; 1735 1745 this->completeLonLatClient(); 1746 this->initializeLocalElement() ; 1747 this->addFullView() ; 1748 this->addWorkflowView() ; 1749 this->addModelView() ; 1750 // testing ? 1751 CLocalView* local = localElement_->getView(CElementView::WORKFLOW) ; 1752 CLocalView* model = localElement_->getView(CElementView::MODEL) ; 1753 1754 CLocalConnector test1(model, local) ; 1755 test1.computeConnector() ; 1756 CLocalConnector test2(local, model) ; 1757 test2.computeConnector() ; 1758 CGridLocalConnector gridTest1(vector<CLocalConnector*>{&test1}) ; 1759 CGridLocalConnector gridTest2(vector<CLocalConnector*>{&test2}) ; 1760 1761 1762 CArray<int,1> out1 ; 1763 CArray<int,1> out2 ; 1764 test1.transfer(data_i_index,out1,-111) ; 1765 test2.transfer(out1,out2,-111) ; 1766 1767 out1 = 0 ; 1768 out2 = 0 ; 1769 gridTest1.transfer(data_i_index,out1,-111) ; 1770 gridTest2.transfer(out1, out2,-111) ; 1771 1736 1772 this->checkAttributes_done_ = true; 1737 1773 } 1738 1774 CATCH_DUMP_ATTR 1775 1776 1777 void CDomain::initializeLocalElement(void) 1778 { 1779 // after checkDomain i_index and j_index of size (ni*nj) 1780 int nij = ni*nj ; 1781 CArray<size_t, 1> ij_index(ni*nj) ; 1782 for(int ij=0; ij<nij ; ij++) ij_index(ij) = i_index(ij)+j_index(ij)*ni_glo ; 1783 int rank = CContext::getCurrent()->getIntraCommRank() ; 1784 localElement_ = new CLocalElement(rank, ni_glo*nj_glo, ij_index) ; 1785 } 1786 1787 void CDomain::addFullView(void) 1788 { 1789 CArray<int,1> index(ni*nj) ; 1790 int nij=ni*nj ; 1791 for(int ij=0; ij<nij ; ij++) index(ij)=ij ; 1792 localElement_ -> addView(CElementView::FULL, index) ; 1793 } 1794 1795 void CDomain::addWorkflowView(void) 1796 { 1797 // information for workflow view is stored in localMask 1798 int nij=ni*nj ; 1799 int nMask=0 ; 1800 for(int ij=0; ij<nij ; ij++) if (localMask(ij)) nMask++ ; 1801 CArray<int,1> index(nMask) ; 1802 1803 nMask=0 ; 1804 for(int ij=0; ij<nij ; ij++) 1805 if (localMask(ij)) 1806 { 1807 index(nMask)=ij ; 1808 nMask++ ; 1809 } 1810 localElement_ -> addView(CElementView::WORKFLOW, index) ; 1811 } 1812 1813 void CDomain::addModelView(void) 1814 { 1815 // information for model view is stored in data_i_index/data_j_index 1816 // very weird, do not mix data_i_index and data_i_begin => in future only keep data_i_index 1817 int dataSize = data_i_index.numElements() ; 1818 CArray<int,1> index(dataSize) ; 1819 int i,j ; 1820 for(int k=0;k<dataSize;k++) 1821 { 1822 i=data_i_index(k)+data_ibegin ; // bad 1823 j=data_j_index(k)+data_jbegin ; // bad 1824 if (i>=0 && i<ni && j>=0 && j<nj) index(k)=i+j*ni ; 1825 else index(k)=-1 ; 1826 } 1827 localElement_->addView(CElementView::MODEL, index) ; 1828 } 1829 1830 void CDomain::computeModelToWorkflowConnector(void) 1831 { 1832 CLocalView* srcView=getLocalView(CElementView::MODEL) ; 1833 CLocalView* dstView=getLocalView(CElementView::WORKFLOW) ; 1834 modelToWorkflowConnector_ = new CLocalConnector(srcView, dstView); 1835 modelToWorkflowConnector_->computeConnector() ; 1836 } 1837 1739 1838 1740 1839 //---------------------------------------------------------------- … … 2099 2198 this->sendArea(client); 2100 2199 this->sendDataIndex(client); 2200 2201 // test new connector functionnality 2202 this->sendDomainDistribution(client) ; 2101 2203 } 2102 2204 … … 2129 2231 this->createAlias(domainId) ; 2130 2232 } 2233 2234 2235 void CDomain::sendDomainDistribution(CContextClient* client, const string& domainId) 2236 TRY 2237 { 2238 string serverDomainId = domainId.empty() ? this->getId() : domainId ; 2239 CContext* context = CContext::getCurrent(); 2240 int nbServer = client->serverSize; 2241 std::vector<int> nGlobDomain(2); 2242 nGlobDomain[0] = this->ni_glo; 2243 nGlobDomain[1] = this->nj_glo; 2244 2245 CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 2246 int distributedPosition ; 2247 if (isUnstructed_) distributedPosition = 0 ; 2248 else distributedPosition = 1 ; 2249 2250 serverDescription.computeServerDistribution(false, distributedPosition); 2251 2252 std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 2253 std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); 2254 2255 vector<unordered_map<size_t,vector<int>>> indexServerOnElement ; 2256 CArray<int,1> axisDomainOrder(1) ; axisDomainOrder(0)=2 ; 2257 auto zeroIndex=serverDescription.computeServerGlobalByElement(indexServerOnElement, context->getIntraCommRank(), context->getIntraCommSize(), 2258 axisDomainOrder,distributedPosition) ; 2259 // distribution is very bad => to redo 2260 // convert indexServerOnElement => map<int,CArray<size_t,1>> - need to be changed later 2261 map<int, vector<size_t>> vectGlobalIndex ; 2262 for(auto& indexRanks : indexServerOnElement[0]) 2263 { 2264 size_t index=indexRanks.first ; 2265 auto& ranks=indexRanks.second ; 2266 for(int rank : ranks) vectGlobalIndex[rank].push_back(index) ; 2267 } 2268 map<int, CArray<size_t,1>> globalIndex ; 2269 for(auto& vect : vectGlobalIndex ) globalIndex.emplace(vect.first, CArray<size_t,1>(vect.second.data(), shape(vect.second.size()))) ; 2270 2271 CDistributedElement remoteElement(ni_glo*nj_glo, globalIndex) ; 2272 remoteElement.addFullView() ; 2273 2274 CRemoteConnector remoteConnector(localElement_->getView(CElementView::FULL), remoteElement.getView(CElementView::FULL),context->getIntraComm()) ; 2275 remoteConnector.computeConnector() ; 2276 CDistributedElement scatteredElement(remoteElement.getGlobalSize(), remoteConnector.getDistributedGlobalIndex()) ; 2277 scatteredElement.addFullView() ; 2278 CScattererConnector scatterConnector(localElement_->getView(CElementView::FULL), scatteredElement.getView(CElementView::FULL), context->getIntraComm()) ; 2279 scatterConnector.computeConnector() ; 2280 CGridScattererConnector gridScatter({&scatterConnector}) ; 2281 2282 CEventClient event0(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2283 CMessage message0 ; 2284 message0<<serverDomainId<<0 ; 2285 remoteElement.sendToServer(client,event0,message0) ; 2286 2287 CEventClient event1(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2288 CMessage message1 ; 2289 message1<<serverDomainId<<1<<localElement_->getView(CElementView::FULL)->getGlobalSize() ; 2290 scatterConnector.transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event1,message1) ; 2291 2292 CEventClient event2(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2293 CMessage message2 ; 2294 message2<<serverDomainId<<2 ; 2295 // scatterConnector.transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event2,message2) ; 2296 scatterConnector.transfer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event2,message2) ; 2297 2298 /* 2299 localElement_->getView(CElementView::FULL)->sendRemoteElement(remoteConnector, client, event1, message1) ; 2300 CEventClient event2(getType(), EVENT_ID_DOMAIN_DISTRIBUTION); 2301 CMessage message2 ; 2302 message2<<serverDomainId<<2 ; 2303 remoteConnector.transferToServer(localElement_->getView(CElementView::FULL)->getGlobalIndex(),client,event2,message2) ; 2304 */ 2305 2306 } 2307 CATCH 2308 2309 2310 void CDomain::recvDomainDistribution(CEventServer& event) 2311 TRY 2312 { 2313 string domainId; 2314 int phasis ; 2315 for (auto& subEvent : event.subEvents) (*subEvent.buffer) >> domainId >> phasis ; 2316 get(domainId)->receivedDomainDistribution(event, phasis); 2317 } 2318 CATCH 2319 2320 void CDomain::receivedDomainDistribution(CEventServer& event, int phasis) 2321 TRY 2322 { 2323 CContext* context = CContext::getCurrent(); 2324 if (phasis==0) 2325 { 2326 localElement_ = new CLocalElement(context->getIntraCommRank(),event) ; 2327 localElement_->addFullView() ; 2328 } 2329 else if (phasis==1) 2330 { 2331 CContext* context = CContext::getCurrent(); 2332 CDistributedElement* elementFrom = new CDistributedElement(event) ; 2333 elementFrom->addFullView() ; 2334 gathererConnector_ = new CGathererConnector(elementFrom->getView(CElementView::FULL), localElement_->getView(CElementView::FULL)) ; 2335 gathererConnector_->computeConnector() ; 2336 } 2337 else if (phasis==2) 2338 { 2339 CArray<size_t,1> globalIndex ; 2340 //gathererConnector_->transfer(event,globalIndex) ; 2341 CGridGathererConnector gridGathererConnector({gathererConnector_}) ; 2342 gridGathererConnector.transfer(event, globalIndex) ; 2343 } 2344 else if (phasis==3) 2345 { 2346 2347 } 2348 } 2349 CATCH 2350 2351 2131 2352 2132 2353 /*! … … 2482 2703 return true; 2483 2704 break; 2705 case EVENT_ID_DOMAIN_DISTRIBUTION: 2706 recvDomainDistribution(event); 2707 return true; 2708 break; 2484 2709 default: 2485 2710 ERROR("bool CDomain::dispatchEvent(CEventServer& event)",
Note: See TracChangeset
for help on using the changeset viewer.