Changeset 1027 for XIOS/dev/dev_olga/src/node/axis.cpp
- Timestamp:
- 01/11/17 16:50:27 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/node/axis.cpp
r1025 r1027 453 453 { 454 454 CContext* context = CContext::getCurrent(); 455 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 456 int nbServer = client->serverSize; 457 int range, clientSize = client->clientSize; 458 int rank = client->clientRank; 459 460 // size_t ni = this->n.getValue(); 461 // size_t ibegin = this->begin.getValue(); 462 // size_t zoom_end = global_zoom_begin+global_zoom_n-1; 463 // size_t nZoomCount = 0; 464 size_t nbIndex = index.numElements(); 465 for (size_t idx = 0; idx < nbIndex; ++idx) 466 { 467 globalLocalIndexMap_[index(idx)] = idx; 468 // size_t globalIndex = index(idx); 469 // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) ++nZoomCount; 470 } 471 472 // CArray<size_t,1> globalIndexAxis(nbIndex); 473 // std::vector<size_t> globalAxisZoom(nZoomCount); 474 // nZoomCount = 0; 475 // for (size_t idx = 0; idx < nbIndex; ++idx) 476 // { 477 // size_t globalIndex = index(idx); 478 // globalIndexAxis(idx) = globalIndex; 479 // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) 480 // { 481 // globalAxisZoom[nZoomCount] = globalIndex; 482 // ++nZoomCount; 483 // } 484 // } 485 486 // std::set<int> writtenInd; 487 // if (isCompressible_) 488 // { 489 // for (int idx = 0; idx < data_index.numElements(); ++idx) 490 // { 491 // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); 492 493 // if (ind >= 0 && ind < ni && mask(ind)) 494 // { 495 // ind += ibegin; 496 // if (ind >= global_zoom_begin && ind <= zoom_end) 497 // writtenInd.insert(ind); 498 // } 499 // } 500 // } 501 502 CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer, distType); 503 int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); 504 CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; 505 if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* 506 { 507 std::vector<int> nGlobAxis(1); 508 nGlobAxis[0] = n_glo.getValue(); 509 510 size_t globalSizeIndex = 1, indexBegin, indexEnd; 511 for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; 512 indexBegin = 0; 513 if (globalSizeIndex <= clientSize) 514 { 515 indexBegin = rank%globalSizeIndex; 516 indexEnd = indexBegin; 455 int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 456 for (int i = 0; i < nbSrvPools; ++i) 457 { 458 CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; 459 int nbServer = client->serverSize; 460 int range, clientSize = client->clientSize; 461 int rank = client->clientRank; 462 463 // size_t ni = this->n.getValue(); 464 // size_t ibegin = this->begin.getValue(); 465 // size_t zoom_end = global_zoom_begin+global_zoom_n-1; 466 // size_t nZoomCount = 0; 467 size_t nbIndex = index.numElements(); 468 for (size_t idx = 0; idx < nbIndex; ++idx) 469 { 470 globalLocalIndexMap_[index(idx)] = idx; 471 // size_t globalIndex = index(idx); 472 // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) ++nZoomCount; 473 } 474 475 // CArray<size_t,1> globalIndexAxis(nbIndex); 476 // std::vector<size_t> globalAxisZoom(nZoomCount); 477 // nZoomCount = 0; 478 // for (size_t idx = 0; idx < nbIndex; ++idx) 479 // { 480 // size_t globalIndex = index(idx); 481 // globalIndexAxis(idx) = globalIndex; 482 // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) 483 // { 484 // globalAxisZoom[nZoomCount] = globalIndex; 485 // ++nZoomCount; 486 // } 487 // } 488 489 // std::set<int> writtenInd; 490 // if (isCompressible_) 491 // { 492 // for (int idx = 0; idx < data_index.numElements(); ++idx) 493 // { 494 // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); 495 496 // if (ind >= 0 && ind < ni && mask(ind)) 497 // { 498 // ind += ibegin; 499 // if (ind >= global_zoom_begin && ind <= zoom_end) 500 // writtenInd.insert(ind); 501 // } 502 // } 503 // } 504 505 CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer, distType); 506 int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); 507 CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; 508 if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* 509 { 510 std::vector<int> nGlobAxis(1); 511 nGlobAxis[0] = n_glo.getValue(); 512 513 size_t globalSizeIndex = 1, indexBegin, indexEnd; 514 for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; 515 indexBegin = 0; 516 if (globalSizeIndex <= clientSize) 517 { 518 indexBegin = rank%globalSizeIndex; 519 indexEnd = indexBegin; 520 } 521 else 522 { 523 for (int i = 0; i < clientSize; ++i) 524 { 525 range = globalSizeIndex / clientSize; 526 if (i < (globalSizeIndex%clientSize)) ++range; 527 if (i == client->clientRank) break; 528 indexBegin += range; 529 } 530 indexEnd = indexBegin + range - 1; 531 } 532 533 CArray<size_t,1> globalIndex(index.numElements()); 534 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 535 globalIndex(idx) = index(idx); 536 537 CServerDistributionDescription serverDescription(nGlobAxis, nbServer); 538 serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd)); 539 CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 540 clientServerMap->computeServerIndexMapping(globalIndex); 541 globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 542 delete clientServerMap; 517 543 } 518 544 else 519 545 { 520 for (int i = 0; i < clientSize; ++i) 521 { 522 range = globalSizeIndex / clientSize; 523 if (i < (globalSizeIndex%clientSize)) ++range; 524 if (i == client->clientRank) break; 525 indexBegin += range; 526 } 527 indexEnd = indexBegin + range - 1; 528 } 529 530 CArray<size_t,1> globalIndex(index.numElements()); 531 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 532 globalIndex(idx) = index(idx); 533 534 CServerDistributionDescription serverDescription(nGlobAxis, nbServer); 535 serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd)); 536 CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 537 clientServerMap->computeServerIndexMapping(globalIndex); 538 globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 539 delete clientServerMap; 540 } 541 else 542 { 543 std::vector<size_t> globalIndexServer(n_glo.getValue()); 544 for (size_t idx = 0; idx < n_glo.getValue(); ++idx) 545 { 546 globalIndexServer[idx] = idx; 547 } 548 549 for (int idx = 0; idx < nbServer; ++idx) 550 { 551 globalIndexAxisOnServer[idx] = globalIndexServer; 552 } 553 } 554 555 indSrv_.swap(globalIndexAxisOnServer); 556 557 // CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexAxisOnServer.begin(), 558 // ite = globalIndexAxisOnServer.end(); 559 CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_.begin(), 560 ite = indSrv_.end(); 561 // std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), 562 // iteVec = (globalAxisZoom).end(); 563 // indSrv_.clear(); 564 // indWrittenSrv_.clear(); 565 // for (; it != ite; ++it) 566 // { 567 // int rank = it->first; 568 // const std::vector<size_t>& globalIndexTmp = it->second; 569 // int nb = globalIndexTmp.size(); 570 571 // for (int i = 0; i < nb; ++i) 572 // { 573 // if (std::binary_search(itbVec, iteVec, globalIndexTmp[i])) 574 // { 575 // indSrv_[rank].push_back(globalIndexTmp[i]); 576 // } 577 578 // if (writtenInd.count(globalIndexTmp[i])) 579 // { 580 // indWrittenSrv_[rank].push_back(globalIndexTmp[i]); 581 // } 582 // } 583 // } 584 585 connectedServerRank_.clear(); 586 for (it = indSrv_.begin(); it != ite; ++it) { 587 connectedServerRank_.push_back(it->first); 588 } 589 590 // if (!indSrv_.empty()) 591 // { 592 // std::map<int, vector<size_t> >::const_iterator itIndSrv = indSrv_.begin(), 593 // iteIndSrv = indSrv_.end(); 594 // connectedServerRank_.clear(); 595 // for (; itIndSrv != iteIndSrv; ++itIndSrv) 596 // connectedServerRank_.push_back(itIndSrv->first); 597 // } 598 nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 546 std::vector<size_t> globalIndexServer(n_glo.getValue()); 547 for (size_t idx = 0; idx < n_glo.getValue(); ++idx) 548 { 549 globalIndexServer[idx] = idx; 550 } 551 552 for (int idx = 0; idx < nbServer; ++idx) 553 { 554 globalIndexAxisOnServer[idx] = globalIndexServer; 555 } 556 } 557 558 indSrv_.swap(globalIndexAxisOnServer); 559 560 // CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexAxisOnServer.begin(), 561 // ite = globalIndexAxisOnServer.end(); 562 CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_.begin(), 563 ite = indSrv_.end(); 564 // std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), 565 // iteVec = (globalAxisZoom).end(); 566 // indSrv_.clear(); 567 // indWrittenSrv_.clear(); 568 // for (; it != ite; ++it) 569 // { 570 // int rank = it->first; 571 // const std::vector<size_t>& globalIndexTmp = it->second; 572 // int nb = globalIndexTmp.size(); 573 574 // for (int i = 0; i < nb; ++i) 575 // { 576 // if (std::binary_search(itbVec, iteVec, globalIndexTmp[i])) 577 // { 578 // indSrv_[rank].push_back(globalIndexTmp[i]); 579 // } 580 581 // if (writtenInd.count(globalIndexTmp[i])) 582 // { 583 // indWrittenSrv_[rank].push_back(globalIndexTmp[i]); 584 // } 585 // } 586 // } 587 588 connectedServerRank_.clear(); 589 for (it = indSrv_.begin(); it != ite; ++it) { 590 connectedServerRank_.push_back(it->first); 591 } 592 593 // if (!indSrv_.empty()) 594 // { 595 // std::map<int, vector<size_t> >::const_iterator itIndSrv = indSrv_.begin(), 596 // iteIndSrv = indSrv_.end(); 597 // connectedServerRank_.clear(); 598 // for (; itIndSrv != iteIndSrv; ++itIndSrv) 599 // connectedServerRank_.push_back(itIndSrv->first); 600 // } 601 nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 602 } 599 603 } 600 604 … … 744 748 { 745 749 CContext* context = CContext::getCurrent(); 746 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client;750 int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 747 751 748 CEventClient event(getType(), EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES); 749 size_t nbIndex = index.numElements(); 750 size_t nbDataIndex = 0; 751 752 for (int idx = 0; idx < data_index.numElements(); ++idx) 753 { 754 int ind = data_index(idx); 755 if (ind >= 0 && ind < nbIndex) ++nbDataIndex; 756 } 757 758 CArray<int,1> dataIndex(nbDataIndex); 759 nbDataIndex = 0; 760 for (int idx = 0; idx < data_index.numElements(); ++idx) 761 { 762 int ind = data_index(idx); 763 if (ind >= 0 && ind < nbIndex) 764 { 765 dataIndex(nbDataIndex) = ind; 766 ++nbDataIndex; 767 } 768 } 769 770 if (client->isServerLeader()) 771 { 772 std::list<CMessage> msgs; 773 774 const std::list<int>& ranks = client->getRanksServerLeader(); 775 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 776 { 777 msgs.push_back(CMessage()); 778 CMessage& msg = msgs.back(); 779 msg << this->getId(); 780 msg << index.getValue() << dataIndex << zoom_index.getValue() << mask.getValue(); 781 msg << hasValue; 782 if (hasValue) msg << value.getValue(); 783 784 msg << hasBounds_; 785 if (hasBounds_) msg << bounds.getValue(); 786 787 event.push(*itRank, 1, msg); 788 } 789 client->sendEvent(event); 790 } 791 else client->sendEvent(event); 752 for (int i = 0; i < nbSrvPools; ++i) 753 { 754 CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; 755 756 CEventClient event(getType(), EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES); 757 size_t nbIndex = index.numElements(); 758 size_t nbDataIndex = 0; 759 760 for (int idx = 0; idx < data_index.numElements(); ++idx) 761 { 762 int ind = data_index(idx); 763 if (ind >= 0 && ind < nbIndex) ++nbDataIndex; 764 } 765 766 CArray<int,1> dataIndex(nbDataIndex); 767 nbDataIndex = 0; 768 for (int idx = 0; idx < data_index.numElements(); ++idx) 769 { 770 int ind = data_index(idx); 771 if (ind >= 0 && ind < nbIndex) 772 { 773 dataIndex(nbDataIndex) = ind; 774 ++nbDataIndex; 775 } 776 } 777 778 if (client->isServerLeader()) 779 { 780 std::list<CMessage> msgs; 781 782 const std::list<int>& ranks = client->getRanksServerLeader(); 783 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 784 { 785 msgs.push_back(CMessage()); 786 CMessage& msg = msgs.back(); 787 msg << this->getId(); 788 msg << index.getValue() << dataIndex << zoom_index.getValue() << mask.getValue(); 789 msg << hasValue; 790 if (hasValue) msg << value.getValue(); 791 792 msg << hasBounds_; 793 if (hasBounds_) msg << bounds.getValue(); 794 795 event.push(*itRank, 1, msg); 796 } 797 client->sendEvent(event); 798 } 799 else client->sendEvent(event); 800 } 792 801 } 793 802 … … 845 854 int ns, n, i, j, ind, nv, idx; 846 855 CContext* context = CContext::getCurrent(); 847 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 848 849 CEventClient eventData(getType(), EVENT_ID_DISTRIBUTED_ATTRIBUTES); 850 851 list<CMessage> listData; 852 list<CArray<int,1> > list_indi, list_dataInd, list_zoomInd; 853 list<CArray<bool,1> > list_mask; 854 list<CArray<double,1> > list_val; 855 list<CArray<double,2> > list_bounds; 856 857 int nbIndex = index.numElements(); 858 CArray<int,1> dataIndex(nbIndex); 859 dataIndex = -1; 860 for (int idx = 0; idx < data_index.numElements(); ++idx) 861 { 862 if (0 <= data_index(idx) && data_index(idx) < nbIndex) 863 dataIndex(idx) = data_index(idx); 864 } 865 866 boost::unordered_map<int, std::vector<size_t> >::const_iterator it, iteMap; 867 iteMap = indSrv_.end(); 868 for (int k = 0; k < connectedServerRank_.size(); ++k) 869 { 870 int nbData = 0; 871 int rank = connectedServerRank_[k]; 872 int nbSendingClient = nbConnectedClients_[rank]; 873 it = indSrv_.find(rank); 874 if (iteMap != it) 875 nbData = it->second.size(); 876 877 list_indi.push_back(CArray<int,1>(nbData)); 878 list_dataInd.push_back(CArray<int,1>(nbData)); 879 list_zoomInd.push_back(CArray<int,1>(nbData)); 880 list_mask.push_back(CArray<bool,1>(nbData)); 881 882 883 if (hasValue) 884 list_val.push_back(CArray<double,1>(nbData)); 885 886 if (hasBounds_) 887 { 888 list_bounds.push_back(CArray<double,2>(2,nbData)); 889 } 890 891 CArray<int,1>& indi = list_indi.back(); 892 CArray<int,1>& dataIndi = list_dataInd.back(); 893 CArray<int,1>& zoomIndi = list_zoomInd.back(); 894 CArray<bool,1>& maskIndi = list_mask.back(); 895 896 for (n = 0; n < nbData; ++n) 897 { 898 idx = static_cast<int>(it->second[n]); 899 indi(n) = idx; 900 901 ind = globalLocalIndexMap_[idx]; 902 dataIndi(n) = dataIndex(ind); 903 maskIndi(n) = mask(ind); 904 zoomIndi(n) = zoom_index(ind); 856 int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 857 858 for (int i = 0; i < nbSrvPools; ++i) 859 { 860 CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; 861 862 CEventClient eventData(getType(), EVENT_ID_DISTRIBUTED_ATTRIBUTES); 863 864 list<CMessage> listData; 865 list<CArray<int,1> > list_indi, list_dataInd, list_zoomInd; 866 list<CArray<bool,1> > list_mask; 867 list<CArray<double,1> > list_val; 868 list<CArray<double,2> > list_bounds; 869 870 int nbIndex = index.numElements(); 871 CArray<int,1> dataIndex(nbIndex); 872 dataIndex = -1; 873 for (int inx = 0; inx < data_index.numElements(); ++inx) 874 { 875 if (0 <= data_index(inx) && data_index(inx) < nbIndex) 876 dataIndex(inx) = data_index(inx); 877 } 878 879 boost::unordered_map<int, std::vector<size_t> >::const_iterator it, iteMap; 880 iteMap = indSrv_.end(); 881 for (int k = 0; k < connectedServerRank_.size(); ++k) 882 { 883 int nbData = 0; 884 int rank = connectedServerRank_[k]; 885 int nbSendingClient = nbConnectedClients_[rank]; 886 it = indSrv_.find(rank); 887 if (iteMap != it) 888 nbData = it->second.size(); 889 890 list_indi.push_back(CArray<int,1>(nbData)); 891 list_dataInd.push_back(CArray<int,1>(nbData)); 892 list_zoomInd.push_back(CArray<int,1>(nbData)); 893 list_mask.push_back(CArray<bool,1>(nbData)); 894 905 895 906 896 if (hasValue) 907 { 908 CArray<double,1>& val = list_val.back(); 909 val(n) = value(ind); 910 } 897 list_val.push_back(CArray<double,1>(nbData)); 911 898 912 899 if (hasBounds_) 913 900 { 914 CArray<double,2>& boundsVal = list_bounds.back(); 915 boundsVal(0, n) = bounds(0,n); 916 boundsVal(1, n) = bounds(1,n); 917 } 918 } 919 920 listData.push_back(CMessage()); 921 listData.back() << this->getId() 922 << list_indi.back() << list_dataInd.back() << list_zoomInd.back() << list_mask.back() 923 << hasValue; 924 if (hasValue) 925 listData.back() << list_val.back(); 926 listData.back() << hasBounds_; 927 if (hasBounds_) 928 listData.back() << list_bounds.back(); 929 930 eventData.push(rank, nbConnectedClients_[rank], listData.back()); 931 } 932 933 client->sendEvent(eventData); 901 list_bounds.push_back(CArray<double,2>(2,nbData)); 902 } 903 904 CArray<int,1>& indi = list_indi.back(); 905 CArray<int,1>& dataIndi = list_dataInd.back(); 906 CArray<int,1>& zoomIndi = list_zoomInd.back(); 907 CArray<bool,1>& maskIndi = list_mask.back(); 908 909 for (n = 0; n < nbData; ++n) 910 { 911 idx = static_cast<int>(it->second[n]); 912 indi(n) = idx; 913 914 ind = globalLocalIndexMap_[idx]; 915 dataIndi(n) = dataIndex(ind); 916 maskIndi(n) = mask(ind); 917 zoomIndi(n) = zoom_index(ind); 918 919 if (hasValue) 920 { 921 CArray<double,1>& val = list_val.back(); 922 val(n) = value(ind); 923 } 924 925 if (hasBounds_) 926 { 927 CArray<double,2>& boundsVal = list_bounds.back(); 928 boundsVal(0, n) = bounds(0,n); 929 boundsVal(1, n) = bounds(1,n); 930 } 931 } 932 933 listData.push_back(CMessage()); 934 listData.back() << this->getId() 935 << list_indi.back() << list_dataInd.back() << list_zoomInd.back() << list_mask.back() 936 << hasValue; 937 if (hasValue) 938 listData.back() << list_val.back(); 939 listData.back() << hasBounds_; 940 if (hasBounds_) 941 listData.back() << list_bounds.back(); 942 943 eventData.push(rank, nbConnectedClients_[rank], listData.back()); 944 } 945 946 client->sendEvent(eventData); 947 } 934 948 } 935 949 … … 1114 1128 // *buffer >> axisId; 1115 1129 // get(axisId)->recvServerAttribut(*buffer); 1116 {1117 CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i]1118 }1119 1130 1120 1131 // CContext* context = CContext::getCurrent();
Note: See TracChangeset
for help on using the changeset viewer.