Changeset 1637 for XIOS/trunk/src/node/grid.cpp
- Timestamp:
- 01/14/19 13:33:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/grid.cpp
r1622 r1637 364 364 } 365 365 CATCH_DUMP_ATTR 366 bool CGrid::hasMask() const 367 TRY 368 { 369 return (!mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty() || 370 !mask_4d.isEmpty() || !mask_5d.isEmpty() || !mask_6d.isEmpty() || !mask_7d.isEmpty()); 371 } 372 CATCH 366 373 367 374 /* … … 453 460 CATCH_DUMP_ATTR 454 461 455 /*!456 A grid can have multiple dimension, so can its mask in the form of multi-dimension array.457 It's not a good idea to store all multi-dimension arrays corresponding to each mask.458 One of the ways is to convert this array into 1-dimension one and every process is taken place on it.459 \param [in] multi-dimension array grid mask460 */461 462 void CGrid::getLocalMask(CArray<bool,1>& localMask)463 TRY464 {465 std::vector<CDomain*> domainP = this->getDomains();466 std::vector<CAxis*> axisP = this->getAxis();467 int dim = domainP.size() * 2 + axisP.size();468 469 switch (dim)470 {471 case 0:472 getLocalMask(mask_0d, localMask);473 break;474 case 1:475 getLocalMask(mask_1d, localMask);476 break;477 case 2:478 getLocalMask(mask_2d, localMask);479 break;480 case 3:481 getLocalMask(mask_3d, localMask);482 break;483 case 4:484 getLocalMask(mask_4d, localMask);485 break;486 case 5:487 getLocalMask(mask_5d, localMask);488 break;489 case 6:490 getLocalMask(mask_6d, localMask);491 break;492 case 7:493 getLocalMask(mask_7d, localMask);494 break;495 default:496 break;497 }498 }499 CATCH_DUMP_ATTR500 501 462 /* 502 463 Modify value of mask in a certain index … … 736 697 CContext* context = CContext::getCurrent(); 737 698 738 CContextClient* client = context->client; // Here it's not important which contextClient to recuperate699 CContextClient* client = context->client; 739 700 int rank = client->clientRank; 740 701 741 702 clientDistribution_ = new CDistributionClient(rank, this); 742 703 // Get local data index on client 743 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 744 int nbStoreIndex = storeIndex_client.numElements(); 704 int nbStoreIndex = clientDistribution_->getLocalDataIndexOnClient().size(); 705 int nbStoreGridMask = clientDistribution_->getLocalMaskIndexOnClient().size(); 706 // nbStoreGridMask = nbStoreIndex if grid mask is defined, and 0 otherwise 707 storeIndex_client.resize(nbStoreIndex); 708 storeMask_client.resize(nbStoreGridMask); 745 709 for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 710 for (int idx = 0; idx < nbStoreGridMask; ++idx) storeMask_client(idx) = (clientDistribution_->getLocalMaskIndexOnClient())[idx]; 746 711 747 712 if (0 == serverDistribution_) isDataDistributed_= clientDistribution_->isDataDistributed(); … … 884 849 if (connectedServerRank_[receiverSize].empty()) 885 850 connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); 851 852 // Now check if all servers have data to receive. If not, master client will send empty data. 853 // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. 854 std::vector<int> counts (client->clientSize); 855 std::vector<int> displs (client->clientSize); 856 displs[0] = 0; 857 int localCount = connectedServerRank_[receiverSize].size() ; 858 MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; 859 for (int i = 0; i < client->clientSize-1; ++i) 860 { 861 displs[i+1] = displs[i] + counts[i]; 862 } 863 std::vector<int> allConnectedServers(displs[client->clientSize-1]+counts[client->clientSize-1]); 864 MPI_Gatherv(&(connectedServerRank_[receiverSize])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); 865 866 if ((allConnectedServers.size() != receiverSize) && (client->clientRank == 0)) 867 { 868 std::vector<bool> isSrvConnected (receiverSize, false); 869 for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; 870 for (int i = 0; i < receiverSize; ++i) 871 { 872 if (!isSrvConnected[i]) connectedServerRank_[receiverSize].push_back(i); 873 } 874 } 886 875 887 876 nbSenders[receiverSize] = clientServerMap_->computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); … … 1369 1358 CATCH 1370 1359 1360 void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored) const 1361 { 1362 const StdSize size = storeIndex_client.numElements(); 1363 stored.resize(size); 1364 const double nanValue = std::numeric_limits<double>::quiet_NaN(); 1365 1366 if (storeMask_client.numElements() != 0) 1367 for(StdSize i = 0; i < size; i++) stored(i) = (storeMask_client(i)) ? data[storeIndex_client(i)] : nanValue; 1368 else 1369 for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; 1370 } 1371 1371 1372 void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out) const 1372 1373 TRY … … 1836 1837 nGlob.push_back(1); 1837 1838 } 1838 1839 modifyMaskSize(nSize, false);1840 1841 // These below codes are reserved for future1842 CDistributionServer srvDist(server->intraCommRank, nBegin, nSize, nBeginGlobal, nGlob);1843 map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient.begin(),1844 ite = outGlobalIndexFromClient.end(), it;1845 const CDistributionServer::GlobalLocalMap& globalLocalMask = srvDist.getGlobalLocalIndex();1846 CDistributionServer::GlobalLocalMap::const_iterator itSrv;1847 size_t nb = 0;1848 for (it = itb; it != ite; ++it)1849 {1850 CArray<size_t,1>& globalInd = it->second;1851 for (size_t idx = 0; idx < globalInd.numElements(); ++idx)1852 {1853 if (globalLocalMask.end() != globalLocalMask.find(globalInd(idx))) ++nb;1854 }1855 }1856 1857 CArray<int,1> indexToModify(nb);1858 nb = 0;1859 for (it = itb; it != ite; ++it)1860 {1861 CArray<size_t,1>& globalInd = it->second;1862 for (size_t idx = 0; idx < globalInd.numElements(); ++idx)1863 {1864 itSrv = globalLocalMask.find(globalInd(idx));1865 if (globalLocalMask.end() != itSrv)1866 {1867 indexToModify(nb) = itSrv->second;1868 ++nb;1869 }1870 }1871 }1872 1873 modifyMask(indexToModify, true);1874 1839 } 1875 1840
Note: See TracChangeset
for help on using the changeset viewer.