Changeset 1875 for XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
- Timestamp:
- 05/12/20 11:52:13 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
r1871 r1875 102 102 } 103 103 CATCH 104 105 /*! 106 * Get the local data grid size, ie the size of the compressed grid (inside the workflow) 107 * \return The size od the compressed grid 108 */ 109 StdSize CGrid::getLocalDataSize(void) { return getClientDistribution()->getLocalDataSize();} 110 104 111 105 112 /*! … … 326 333 CATCH_DUMP_ATTR 327 334 335 //ym obsolete -> to be removed later 328 336 void CGrid::checkMaskIndex(bool doSendingIndex) 329 337 TRY … … 334 342 if (this->isChecked && doSendingIndex && !isIndexSent) 335 343 { 336 if (isScalarGrid()) sendIndexScalarGrid();337 else sendIndex();344 if (isScalarGrid()) /*sendIndexScalarGrid()*/; 345 else /*sendIndex()*/; 338 346 this->isIndexSent = true; 339 347 } … … 1453 1461 CATCH_DUMP_ATTR 1454 1462 1455 void CGrid::sendIndexScalarGrid() 1456 TRY 1457 { 1463 void CGrid::sendIndexScalarGrid(CContextClient* client, const string& gridId) 1464 TRY 1465 { 1466 if (sendIndexScalarGrid_done_.count(client)!=0) return ; 1467 else sendIndexScalarGrid_done_.insert(client) ; 1468 1458 1469 CContext* context = CContext::getCurrent(); 1459 storeIndex_toSrv_.clear(); 1460 std::list<CContextClient*>::iterator it; 1461 1462 for (it=clients.begin(); it!=clients.end(); ++it) 1463 { 1464 CContextClient* client = *it; 1465 int receiverSize = client->serverSize; 1466 1467 CEventClient event(getType(), EVENT_ID_INDEX); 1468 list<CMessage> listMsg; 1469 list<CArray<size_t,1> > listOutIndex; 1470 1470 1471 string serverGridId = gridId.empty() ? serverGridId=this->getId() : serverGridId=gridId ; 1472 1473 int receiverSize = client->serverSize; 1474 1475 CEventClient event(getType(), EVENT_ID_INDEX); 1476 list<CMessage> listMsg; 1477 list<CArray<size_t,1> > listOutIndex; 1478 1479 if (client->isServerLeader()) 1480 { 1481 const std::list<int>& ranks = client->getRanksServerLeader(); 1482 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1483 { 1484 int rank = *itRank; 1485 int nb = 1; 1486 storeIndex_toSrv_[client].insert(std::make_pair(rank, CArray<int,1>(nb))); 1487 listOutIndex.push_back(CArray<size_t,1>(nb)); 1488 1489 CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; 1490 CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 1491 1492 for (int k = 0; k < nb; ++k) 1493 { 1494 outGlobalIndexOnServer(k) = 0; 1495 outLocalIndexToServer(k) = 0; 1496 } 1497 1498 if (context->getServiceType()==CServicesManager::CLIENT) // -> what about for coupling probably unusefull to be check 1499 storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1500 1501 listMsg.push_back(CMessage()); 1502 listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); 1503 1504 event.push(rank, 1, listMsg.back()); 1505 } 1506 client->sendEvent(event); 1507 } 1508 else 1509 { 1510 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1511 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1512 { 1513 int rank = *itRank; 1514 int nb = 1; 1515 CArray<int, 1> outLocalIndexToServer(nb); 1516 for (int k = 0; k < nb; ++k) 1517 { 1518 outLocalIndexToServer(k) = 0; 1519 } 1520 1521 if (context->getServiceType()==CServicesManager::CLIENT) 1522 storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1523 } 1524 client->sendEvent(event); 1525 } 1526 } 1527 CATCH_DUMP_ATTR 1528 1529 void CGrid::sendIndex(CContextClient* client, const string& gridId) 1530 TRY 1531 { 1532 if (sendIndex_done_.count(client)!=0) return ; 1533 else sendIndex_done_.insert(client) ; 1534 CContext* context = CContext::getCurrent(); 1535 string serverGridId = gridId.empty() ? this->getId() : gridId ; 1536 1537 1538 1539 int receiverSize = client->serverSize; 1540 1541 CEventClient event(getType(), EVENT_ID_INDEX); 1542 int rank; 1543 list<CMessage> listMsg; 1544 list<CArray<size_t,1> > listOutIndex; 1545 const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getClientDistribution()->getGlobalLocalDataSendToServer(); 1546 CDistributionClient::GlobalLocalDataMap::const_iterator itbIndex = globalLocalIndexSendToServer.begin(), itIndex, 1547 iteIndex = globalLocalIndexSendToServer.end(); 1548 itIndex = itbIndex; 1549 1550 if (!doGridHaveDataDistributed(client)) 1551 { 1471 1552 if (client->isServerLeader()) 1472 1553 { 1554 int indexSize = globalLocalIndexSendToServer.size(); 1555 CArray<size_t,1> outGlobalIndexOnServer(indexSize); 1556 CArray<int,1> outLocalIndexToServer(indexSize); 1557 for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 1558 { 1559 outGlobalIndexOnServer(idx) = itIndex->first; 1560 outLocalIndexToServer(idx) = itIndex->second; 1561 } 1562 1473 1563 const std::list<int>& ranks = client->getRanksServerLeader(); 1474 1564 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1475 1565 { 1476 int rank = *itRank; 1477 int nb = 1; 1478 storeIndex_toSrv_[client].insert(std::make_pair(rank, CArray<int,1>(nb))); 1479 listOutIndex.push_back(CArray<size_t,1>(nb)); 1480 1481 CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; 1482 CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 1483 1484 for (int k = 0; k < nb; ++k) 1485 { 1486 outGlobalIndexOnServer(k) = 0; 1487 outLocalIndexToServer(k) = 0; 1488 } 1489 1490 if (context->getServiceType()==CServicesManager::CLIENT) 1491 storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1566 storeIndex_toSrv_[client].insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1567 if (context->getServiceType()==CServicesManager::CLIENT) // -> what about for coupling probably unusefull to be check 1568 storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1569 1570 listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); 1492 1571 1493 1572 listMsg.push_back(CMessage()); 1494 listMsg.back() << getId( )<< isCompressible_ << listOutIndex.back();1495 1496 event.push( rank, 1, listMsg.back());1573 listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); 1574 1575 event.push(*itRank, 1, listMsg.back()); 1497 1576 } 1498 1577 client->sendEvent(event); … … 1500 1579 else 1501 1580 { 1502 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1503 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1581 int indexSize = globalLocalIndexSendToServer.size(); 1582 CArray<int,1> outLocalIndexToServer(indexSize); 1583 for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 1584 { 1585 outLocalIndexToServer(idx) = itIndex->second; 1586 } 1587 1588 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1589 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1590 { 1591 storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1592 } 1593 client->sendEvent(event); 1594 } 1595 } 1596 else 1597 { 1598 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; 1599 itGlobalMap = globalIndexOnServer_[receiverSize].begin(); 1600 iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 1601 1602 std::map<int,std::vector<int> >localIndexTmp; 1603 std::map<int,std::vector<size_t> > globalIndexTmp; 1604 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 1605 { 1606 int serverRank = itGlobalMap->first; 1607 int indexSize = itGlobalMap->second.size(); 1608 const std::vector<size_t>& indexVec = itGlobalMap->second; 1609 for (int idx = 0; idx < indexSize; ++idx) 1504 1610 { 1505 int rank = *itRank; 1506 int nb = 1; 1507 CArray<int, 1> outLocalIndexToServer(nb); 1508 for (int k = 0; k < nb; ++k) 1611 itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); 1612 if (iteIndex != itIndex) 1509 1613 { 1510 outLocalIndexToServer(k) = 0; 1511 } 1512 1513 if (context->getServiceType()==CServicesManager::CLIENT) 1514 storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1515 } 1516 client->sendEvent(event); 1517 } 1518 } 1519 } 1520 CATCH_DUMP_ATTR 1521 1522 void CGrid::sendIndex(void) 1523 TRY 1524 { 1525 CContext* context = CContext::getCurrent(); 1526 storeIndex_toSrv_.clear(); 1527 std::list<CContextClient*>::iterator it; 1528 1529 for (it=clients.begin(); it!=clients.end(); ++it) 1530 { 1531 CContextClient* client = *it; 1532 int receiverSize = client->serverSize; 1533 1534 CEventClient event(getType(), EVENT_ID_INDEX); 1535 int rank; 1536 list<CMessage> listMsg; 1537 list<CArray<size_t,1> > listOutIndex; 1538 const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getClientDistribution()->getGlobalLocalDataSendToServer(); 1539 CDistributionClient::GlobalLocalDataMap::const_iterator itbIndex = globalLocalIndexSendToServer.begin(), itIndex, 1540 iteIndex = globalLocalIndexSendToServer.end(); 1541 itIndex = itbIndex; 1542 1543 if (!doGridHaveDataDistributed(client)) 1544 { 1545 if (client->isServerLeader()) 1546 { 1547 int indexSize = globalLocalIndexSendToServer.size(); 1548 CArray<size_t,1> outGlobalIndexOnServer(indexSize); 1549 CArray<int,1> outLocalIndexToServer(indexSize); 1550 for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 1551 { 1552 outGlobalIndexOnServer(idx) = itIndex->first; 1553 outLocalIndexToServer(idx) = itIndex->second; 1554 } 1555 1556 const std::list<int>& ranks = client->getRanksServerLeader(); 1557 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1558 { 1559 storeIndex_toSrv_[client].insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1560 if (context->getServiceType()==CServicesManager::CLIENT) 1561 storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1562 1563 listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); 1564 1565 listMsg.push_back(CMessage()); 1566 listMsg.back() << getId() << isCompressible_ << listOutIndex.back(); 1567 1568 event.push(*itRank, 1, listMsg.back()); 1569 } 1570 client->sendEvent(event); 1571 } 1572 else 1573 { 1574 int indexSize = globalLocalIndexSendToServer.size(); 1575 CArray<int,1> outLocalIndexToServer(indexSize); 1576 for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 1577 { 1578 outLocalIndexToServer(idx) = itIndex->second; 1579 } 1580 1581 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1582 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1583 { 1584 storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 1585 } 1586 client->sendEvent(event); 1587 } 1588 } 1589 else 1590 { 1591 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; 1592 itGlobalMap = globalIndexOnServer_[receiverSize].begin(); 1593 iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 1594 1595 std::map<int,std::vector<int> >localIndexTmp; 1596 std::map<int,std::vector<size_t> > globalIndexTmp; 1597 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 1598 { 1599 int serverRank = itGlobalMap->first; 1600 int indexSize = itGlobalMap->second.size(); 1601 const std::vector<size_t>& indexVec = itGlobalMap->second; 1602 for (int idx = 0; idx < indexSize; ++idx) 1603 { 1604 itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); 1605 if (iteIndex != itIndex) 1606 { 1607 globalIndexTmp[serverRank].push_back(itIndex->first); 1608 localIndexTmp[serverRank].push_back(itIndex->second); 1609 } 1614 globalIndexTmp[serverRank].push_back(itIndex->first); 1615 localIndexTmp[serverRank].push_back(itIndex->second); 1610 1616 } 1611 1617 } 1612 1613 for (int ns = 0; ns < connectedServerRank_[receiverSize].size(); ++ns) 1618 } 1619 1620 for (int ns = 0; ns < connectedServerRank_[receiverSize].size(); ++ns) 1621 { 1622 rank = connectedServerRank_[receiverSize][ns]; 1623 int nb = 0; 1624 if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 1625 nb = globalIndexTmp[rank].size(); 1626 1627 storeIndex_toSrv_[client].insert(make_pair(rank, CArray<int,1>(nb))); 1628 listOutIndex.push_back(CArray<size_t,1>(nb)); 1629 1630 CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; 1631 CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 1632 1633 for (int k = 0; k < nb; ++k) 1614 1634 { 1615 rank = connectedServerRank_[receiverSize][ns]; 1616 int nb = 0; 1617 if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 1618 nb = globalIndexTmp[rank].size(); 1619 1620 storeIndex_toSrv_[client].insert(make_pair(rank, CArray<int,1>(nb))); 1621 listOutIndex.push_back(CArray<size_t,1>(nb)); 1622 1623 CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv_[client][rank]; 1624 CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 1625 1626 for (int k = 0; k < nb; ++k) 1627 { 1628 outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 1629 outLocalIndexToServer(k) = localIndexTmp[rank].at(k); 1630 } 1631 1632 storeIndex_fromSrv_.insert(make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1633 listMsg.push_back(CMessage()); 1634 listMsg.back() << getId() << isCompressible_ << listOutIndex.back(); 1635 1636 event.push(rank, nbSenders_[receiverSize][rank], listMsg.back()); 1635 outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 1636 outLocalIndexToServer(k) = localIndexTmp[rank].at(k); 1637 1637 } 1638 1638 1639 client->sendEvent(event); 1640 } 1639 storeIndex_fromSrv_.insert(make_pair(rank, CArray<int,1>(outLocalIndexToServer))); 1640 listMsg.push_back(CMessage()); 1641 listMsg.back() << serverGridId << isCompressible_ << listOutIndex.back(); 1642 1643 event.push(rank, nbSenders_[receiverSize][rank], listMsg.back()); 1644 } 1645 client->sendEvent(event); 1641 1646 } 1642 1647 } … … 2235 2240 gridPtr->sendCreateChild(this->getId(),client); 2236 2241 this->sendAllAttributesToServer(client); 2237 if (isScalarGrid()) sendIndexScalarGrid( );2238 else sendIndex( );2242 if (isScalarGrid()) sendIndexScalarGrid(client); 2243 else sendIndex(client); 2239 2244 this->sendAllDomains(client); 2240 2245 this->sendAllAxis(client); 2241 2246 this->sendAllScalars(client); 2247 } 2248 2249 void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) 2250 { 2251 if (sendGridToCouplerOut_done_.count(client)!=0) return ; 2252 else sendGridToCouplerOut_done_.insert(client) ; 2253 string gridId="_grid_of_"+fieldId ; 2254 this->sendAllAttributesToServer(client, gridId); 2255 2256 if (isScalarGrid()) sendIndexScalarGrid(client, gridId); 2257 else sendIndex(client, gridId); 2258 2259 const auto& domVect = getDomains() ; 2260 for (int pos=0; pos<domVect.size();pos++) domVect[pos]->sendDomainToCouplerOut(client, fieldId, pos); 2261 2262 const auto& axisVect=getAxis() ; 2263 for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->sendAxisToCouplerOut(client, getGlobalDimension(), getAxisPositionInGrid()[pos], fieldId, pos); 2264 2265 const auto& scalVect=getScalars() ; 2266 for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->sendScalarToCouplerOut(client, fieldId, pos); 2267 } 2268 2269 void CGrid::makeAliasForCoupling(const string& fieldId) 2270 { 2271 string gridId="_grid_of_"+fieldId ; 2272 createAlias(gridId) ; 2273 2274 const auto& domVect = getDomains() ; 2275 for (int pos=0; pos<domVect.size();pos++) domVect[pos]->makeAliasForCoupling(fieldId, pos); 2276 2277 const auto& axisVect=getAxis() ; 2278 for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->makeAliasForCoupling(fieldId, pos); 2279 2280 const auto& scalVect=getScalars() ; 2281 for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->makeAliasForCoupling(fieldId, pos); 2242 2282 } 2243 2283 … … 2365 2405 other context (coupling) 2366 2406 */ 2367 bool CGrid:: checkIfCompleted(void)2407 bool CGrid::isCompleted(void) 2368 2408 { 2369 2409 setDomainList(); 2370 for (auto domainId : domList_) if (!CDomain::get(domainId)-> checkIfCompleted()) return false ;2410 for (auto domainId : domList_) if (!CDomain::get(domainId)->isCompleted()) return false ; 2371 2411 setAxisList() ; 2372 for (auto axisId : axisList_) if (!CAxis::get(axisId)-> checkIfCompleted()) return false ;2412 for (auto axisId : axisList_) if (!CAxis::get(axisId)->isCompleted()) return false ; 2373 2413 setScalarList() ; 2374 for (auto scalarId : scalarList_) if (!CScalar::get(scalarId)-> checkIfCompleted()) return false ;2414 for (auto scalarId : scalarList_) if (!CScalar::get(scalarId)->isCompleted()) return false ; 2375 2415 return true ; 2416 } 2417 2418 /*! 2419 \brief impose that all elements of the grid are complete 2420 Before make any grid processing, we must be sure that all grid information elements have 2421 been sent, for exemple when reading a grid in a file or when grid elements are sent by an 2422 other context (coupling) 2423 */ 2424 void CGrid::setCompleted(void) 2425 { 2426 setDomainList(); 2427 for (auto domainId : domList_) CDomain::get(domainId)->setCompleted() ; 2428 setAxisList() ; 2429 for (auto axisId : axisList_) CAxis::get(axisId)->setCompleted() ; 2430 setScalarList() ; 2431 for (auto scalarId : scalarList_) CScalar::get(scalarId)->setCompleted() ; 2432 } 2433 2434 /*! 2435 \brief impose that all elements of the grid are incomplete 2436 Before make any grid processing, we must be sure that all grid information elements have 2437 been sent, for exemple when reading a grid in a file or when grid elements are sent by an 2438 other context (coupling) 2439 */ 2440 void CGrid::unsetCompleted(void) 2441 { 2442 setDomainList(); 2443 for (auto domainId : domList_) CDomain::get(domainId)->unsetCompleted() ; 2444 setAxisList() ; 2445 for (auto axisId : axisList_) CAxis::get(axisId)->unsetCompleted() ; 2446 setScalarList() ; 2447 for (auto scalarId : scalarList_) CScalar::get(scalarId)->unsetCompleted() ; 2376 2448 } 2377 2449 … … 2904 2976 clientsSet.insert(contextClient); 2905 2977 } 2906 for ( int i=0; i<this->getDomains().size(); i++)2907 this->getDomains()[i]->setContextClient(contextClient);2908 for ( int i=0; i<this->getAxis().size(); i++)2909 this->getAxis()[i]->setContextClient(contextClient);2978 for (auto domain : getDomains()) domain->setContextClient(contextClient); 2979 for (auto axis : getAxis()) axis->setContextClient(contextClient); 2980 for (auto scalar : getScalars()) scalar->setContextClient(contextClient); 2981 2910 2982 } 2911 2983 CATCH_DUMP_ATTR
Note: See TracChangeset
for help on using the changeset viewer.