Changeset 586 for XIOS/trunk/src/node/grid.cpp
- Timestamp:
- 04/01/15 17:53:02 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/grid.cpp
- Property svn:executable set to *
r585 r586 24 24 , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 25 25 , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 26 , connectedDataSize_(), connectedServerRank_() 26 , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true) 27 27 { 28 28 setVirtualDomainGroup(); … … 35 35 , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 36 36 , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 37 , connectedDataSize_(), connectedServerRank_() 37 , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true) 38 38 { 39 39 setVirtualDomainGroup(); … … 166 166 StdSize CGrid::getDataSize(void) const 167 167 { 168 StdSize retvalue = 1; 169 if (true == scalar_grid.getValue()) return retvalue; 168 170 std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); 169 StdSize retvalue = 1; 171 170 172 for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; 171 173 return (retvalue); … … 175 177 { 176 178 double secureFactor = 2.5 * sizeof(double) * CXios::bufferServerFactorSize; 177 StdSize retVal ;179 StdSize retVal = 1; 178 180 std::map<int, StdSize> ret; 179 std::map<int, size_t >::const_iterator it = connectedDataSize_.begin(), itE = connectedDataSize_.end(); 180 for (; it != itE; ++it) 181 std::map<int, size_t >::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); 182 183 if (true == scalar_grid.getValue()) 184 { 185 for (it = itb; it != itE; ++it) 186 { 187 retVal *= secureFactor; 188 ret.insert(std::make_pair(it->first, retVal)); 189 } 190 return ret; 191 } 192 193 for (it = itb; it != itE; ++it) 181 194 { 182 195 retVal = it->second; … … 185 198 } 186 199 200 if (connectedDataSize_.empty()) 201 { 202 for (int i = 0; i < connectedServerRank_.size(); ++i) 203 { 204 retVal = 1; 205 retVal *= secureFactor; 206 ret.insert(std::make_pair<int,StdSize>(connectedServerRank_[i], retVal)); 207 } 208 } 209 187 210 return ret; 188 211 } … … 203 226 CContext* context = CContext::getCurrent() ; 204 227 CContextClient* client=context->client ; 228 229 if (true == scalar_grid) 230 { 231 if (context->hasClient) 232 if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } 233 234 if (this->isChecked) return; 235 if (context->hasClient) 236 { 237 this->computeIndexScalarGrid(); 238 } 239 240 this->isChecked = true; 241 return; 242 } 205 243 206 244 if (context->hasClient) … … 315 353 // First of all, compute distribution on client side 316 354 clientDistribution_ = new CDistributionClient(client->clientRank, this); 355 // Get local data index on client 356 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 357 storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 358 isDataDistributed_= clientDistribution_->isDataDistributed(); 359 360 if (!doGridHaveDataDistributed()) 361 { 362 if (0 == client->clientRank) 363 { 364 size_t ssize = clientDistribution_->getLocalDataIndexOnClient().numElements(); 365 for (int rank = 0; rank < client->serverSize; ++rank) 366 connectedDataSize_[rank] = ssize; 367 } 368 return; 369 } 370 371 // Compute mapping between client and server 317 372 size_t globalSizeIndex = 1, indexBegin, indexEnd; 318 373 int range, clientSize = client->clientSize; … … 377 432 378 433 nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 379 380 // Get local data index on client381 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements());382 storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient());383 434 } 384 435 … … 409 460 if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); 410 461 if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_") ; 462 if (domains.empty() && axis.empty()) new_id += StdString("scalar_grid"); 411 463 new_id += StdString("_"); 412 464 … … 427 479 } 428 480 429 grid->computeGridGlobalDimension(domains, axis, grid->axis_domain_order); 481 if (domains.empty() && axis.empty()) grid->scalar_grid = true; 482 else grid->scalar_grid = false; 483 484 grid->computeGridGlobalDimension(domains, axis, grid->axisDomainOrder); 430 485 431 486 return (grid); … … 463 518 for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 464 519 } 520 521 void CGrid::computeIndexScalarGrid() 522 { 523 CContext* context = CContext::getCurrent(); 524 CContextClient* client=context->client; 525 526 storeIndex_client.resize(1); 527 storeIndex_client[0] = 0; 528 if (0 == client->clientRank) 529 { 530 for (int rank = 0; rank < client->serverSize; ++rank) 531 connectedDataSize_[rank] = 1; 532 } 533 isDataDistributed_ = false; 534 } 535 536 void CGrid::sendIndexScalarGrid() 537 { 538 CContext* context = CContext::getCurrent() ; 539 CContextClient* client=context->client ; 540 541 CEventClient event(getType(),EVENT_ID_INDEX); 542 list<shared_ptr<CMessage> > list_msg ; 543 list< CArray<size_t,1>* > listOutIndex; 544 if (0 == client->clientRank) 545 { 546 for (int rank = 0; rank < client->serverSize; ++rank) 547 { 548 int nb = 1; 549 CArray<size_t, 1> outGlobalIndexOnServer(nb); 550 CArray<int, 1> outLocalIndexToServer(nb); 551 for (int k = 0; k < nb; ++k) 552 { 553 outGlobalIndexOnServer(k) = 0; 554 outLocalIndexToServer(k) = 0; 555 } 556 557 storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 558 listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 559 560 list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 561 *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 562 563 event.push(rank, 1, *list_msg.back()); 564 } 565 client->sendEvent(event); 566 } 567 else 568 client->sendEvent(event); 569 570 for(list<CArray<size_t,1>* >::iterator it=listOutIndex.begin();it!=listOutIndex.end();++it) delete *it ; 571 } 465 572 466 573 void CGrid::sendIndex(void) … … 477 584 const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 478 585 479 std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap;480 itbGlobalMap = itGlobalMap = globalIndexOnServer.begin();481 iteGlobalMap = globalIndexOnServer.end();482 483 int nbGlobalIndex = globalIndexSendToServer.numElements();484 std::map<int,std::vector<int> >localIndexTmp;485 std::map<int,std::vector<size_t> > globalIndexTmp;486 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap)487 {488 int serverRank = itGlobalMap->first;489 std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(),490 iteVecGlobal = (itGlobalMap->second).end();491 for (int i = 0; i < nbGlobalIndex; ++i)492 {493 if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i)))494 {495 globalIndexTmp[serverRank].push_back(globalIndexSendToServer(i));496 localIndexTmp[serverRank].push_back(localIndexSendToServer(i));497 }498 }499 }500 501 502 586 if (!doGridHaveDataDistributed()) 503 587 { 504 588 if (0 == client->clientRank) 505 589 { 590 CArray<size_t, 1> outGlobalIndexOnServer = globalIndexSendToServer; 591 CArray<int,1> outLocalIndexToServer = localIndexSendToServer; 506 592 for (rank = 0; rank < client->serverSize; ++rank) 507 593 { 508 int nb = 0; 509 if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 510 nb = globalIndexTmp[rank].size(); 511 512 CArray<size_t, 1> outGlobalIndexOnServer(nb); 513 CArray<int, 1> outLocalIndexToServer(nb); 514 for (int k = 0; k < nb; ++k) 515 { 516 outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 517 outLocalIndexToServer(k) = localIndexTmp[rank].at(k); 518 } 519 520 storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 594 storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer))); 521 595 listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 522 596 523 597 list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 524 *list_msg.back()<<getId()<< *listOutIndex.back();598 *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 525 599 526 600 event.push(rank, 1, *list_msg.back()); … … 533 607 else 534 608 { 609 std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 610 itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 611 iteGlobalMap = globalIndexOnServer.end(); 612 613 int nbGlobalIndex = globalIndexSendToServer.numElements(); 614 std::map<int,std::vector<int> >localIndexTmp; 615 std::map<int,std::vector<size_t> > globalIndexTmp; 616 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 617 { 618 int serverRank = itGlobalMap->first; 619 std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), 620 iteVecGlobal = (itGlobalMap->second).end(); 621 for (int i = 0; i < nbGlobalIndex; ++i) 622 { 623 if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) 624 { 625 globalIndexTmp[serverRank].push_back(globalIndexSendToServer(i)); 626 localIndexTmp[serverRank].push_back(localIndexSendToServer(i)); 627 } 628 } 629 } 630 535 631 for (int ns = 0; ns < connectedServerRank_.size(); ++ns) 536 632 { … … 552 648 553 649 list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 554 *list_msg.back()<<getId()<< *listOutIndex.back();650 *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 555 651 556 652 event.push(rank, nbSenders[rank], *list_msg.back()); … … 612 708 bool CGrid::doGridHaveDataToWrite() 613 709 { 614 // return (0 != serverDistribution_); 615 return (0 != writtenDataSize_); 710 size_t ssize = 0; 711 for (map<int, CArray<size_t, 1>* >::const_iterator it = outIndexFromClient.begin(); 712 it != outIndexFromClient.end(); ++it) 713 { 714 ssize += (it->second)->numElements(); 715 } 716 return (0 != ssize); 616 717 } 617 718 … … 627 728 } 628 729 629 630 730 const CDistributionServer* CGrid::getDistributionServer() const 631 731 { … … 635 735 bool CGrid::doGridHaveDataDistributed() 636 736 { 637 return clientDistribution_->isDataDistributed(); 737 if (true == scalar_grid.getValue()) return false; 738 else 739 return isDataDistributed_; 638 740 } 639 741 640 742 void CGrid::recvIndex(int rank, CBufferIn& buffer) 641 743 { 744 CContext* context = CContext::getCurrent() ; 745 CContextServer* server=context->server ; 746 buffer>>isDataDistributed_; 747 size_t dataSize = 0; 748 749 if (true == scalar_grid) 750 { 751 writtenDataSize_ = 1; 752 CArray<size_t,1> outIndex; 753 buffer>>outIndex; 754 outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 755 std::vector<int> nZoomBegin(1,0), nZoomSize(1,1), nGlob(1,1), nZoomBeginGlobal(1,0); 756 serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, 757 nZoomBeginGlobal, nGlob); 758 return; 759 } 760 761 642 762 if (0 == serverDistribution_) 643 763 { 644 CContext* context = CContext::getCurrent() ;645 CContextServer* server=context->server ;646 int idx = 0, numElement = axis_domain_order.numElements();647 764 int ssize = numElement; 648 765 std::vector<int> indexMap(numElement); … … 687 804 } 688 805 } 689 writtenDataSize_= 1;806 dataSize = 1; 690 807 for (int i = 0; i < nZoomSize.size(); ++i) 691 writtenDataSize_*= nZoomSize[i];808 dataSize *= nZoomSize[i]; 692 809 693 810 serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, … … 697 814 CArray<size_t,1> outIndex; 698 815 buffer>>outIndex; 699 serverDistribution_->computeLocalIndex(outIndex); 816 if (isDataDistributed_) 817 serverDistribution_->computeLocalIndex(outIndex); 818 else 819 { 820 dataSize = outIndex.numElements(); 821 for (int i = 0; i < outIndex.numElements(); ++i) outIndex(i) = i; 822 } 823 writtenDataSize_ += dataSize; 824 700 825 outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 701 826 } … … 1081 1206 axis_domain_order(i) = order[i]; 1082 1207 } 1083 } 1208 scalar_grid = false; 1209 } 1210 else scalar_grid = true; 1084 1211 1085 1212 setDomainList();
Note: See TracChangeset
for help on using the changeset viewer.