Changeset 1460 for XIOS/dev/branch_openmp/src/transformation
- Timestamp:
- 03/22/18 10:43:20 (6 years ago)
- Location:
- XIOS/dev/branch_openmp/src/transformation
- Files:
-
- 10 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/src/transformation/Functions/reduction.hpp
r1339 r1460 16 16 namespace xios { 17 17 18 /*! 18 /*! 19 19 \class CReductionAlgorithm 20 20 Interface for all reduction alogrithms. -
XIOS/dev/branch_openmp/src/transformation/algo_types.hpp
r976 r1460 18 18 #include "axis_algorithm_interpolate.hpp" 19 19 #include "axis_algorithm_reduce_domain.hpp" 20 #include "axis_algorithm_reduce_axis.hpp" 20 21 #include "axis_algorithm_transformation.hpp" 21 22 #include "axis_algorithm_extract_domain.hpp" 23 #include "axis_algorithm_temporal_splitting.hpp" 22 24 23 25 #include "domain_algorithm_zoom.hpp" … … 25 27 #include "domain_algorithm_compute_connectivity.hpp" 26 28 #include "domain_algorithm_expand.hpp" 29 #include "axis_algorithm_duplicate_scalar.hpp" 30 #include "scalar_algorithm_reduce_scalar.hpp" 31 #include "domain_algorithm_reorder.hpp" 27 32 28 33 -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_extract_domain.cpp
r1339 r1460 13 13 #include "grid.hpp" 14 14 #include "grid_transformation_factory_impl.hpp" 15 //#include "reduction.hpp" 15 16 16 17 namespace xios { -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_interpolate.cpp
r1205 r1460 17 17 #include "grid_transformation_factory_impl.hpp" 18 18 #include "distribution_client.hpp" 19 #include "timer.hpp" 19 20 20 21 namespace xios { … … 63 64 void CAxisAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 64 65 { 66 CTimer::get("CAxisAlgorithmInterpolate::computeIndexSourceMapping_").resume() ; 65 67 CContext* context = CContext::getCurrent(); 66 68 CContextClient* client=context->client; … … 84 86 computeInterpolantPoint(valueSrc, indexVec, idx); 85 87 } 88 CTimer::get("CAxisAlgorithmInterpolate::computeIndexSourceMapping_").suspend() ; 86 89 } 87 90 … … 148 151 while (it < iteRange) 149 152 { 150 while ( itsecond < ite && ((*itsecond -*it) < precision))153 while ( (itsecond < ite) && ((*itsecond -*it) < precision) ) 151 154 { ++itsecond; ++it; } 152 155 int index = std::distance(itb, it); … … 313 316 for (size_t idx = 0; idx < vecAxisValueSize; ++idx) 314 317 { 315 if (dom-> mask_1d(idx)) ++vecAxisValueSizeWithMask;318 if (dom->domainMask(idx)) ++vecAxisValueSizeWithMask; 316 319 } 317 320 … … 324 327 for (size_t idx = 0; idx < vecAxisValueSize; ++idx) 325 328 { 326 if (dom-> mask_1d(idx))329 if (dom->domainMask(idx)) 327 330 { 328 331 transPosition_[indexMask].resize(1); … … 345 348 for (size_t idx = 0; idx < vecAxisValueSize; ++idx) 346 349 { 347 if (dom-> mask_1d(idx))350 if (dom->domainMask(idx)) 348 351 { 349 352 size_t axisValueSize = 0; -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_reduce_domain.cpp
r1339 r1460 13 13 #include "grid.hpp" 14 14 #include "grid_transformation_factory_impl.hpp" 15 //#include "reduction.hpp" 15 16 16 17 namespace xios { … … 73 74 CReductionAlgorithm::initReductionOperation(); 74 75 } 76 //reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]); 75 77 reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations_ptr->at(op)); 78 local = algo->local ; 76 79 } 77 80 … … 107 110 if (iDir == dir_) 108 111 { 109 int nbAxisIdx = axisDstIndex.numElements(); 110 for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) 112 if (local) 111 113 { 112 int globalAxisIdx = axisDstIndex(idxAxis); 113 transMap[globalAxisIdx].resize(ni_glo); 114 transWeight[globalAxisIdx].resize(ni_glo); 115 for (int idx = 0; idx < ni_glo; ++idx) 114 const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; 115 const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; 116 const CArray<bool,1>& localMask = domainSrc_-> localMask ; 117 int nbDomainIdx = i_index.numElements(); 118 119 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) 116 120 { 117 transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx; 118 transWeight[globalAxisIdx][idx] = 1.0; 121 if (localMask(idxDomain)) 122 { 123 transMap[j_index(idxDomain)].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); 124 transWeight[j_index(idxDomain)].push_back(1.0) ; 125 } 126 } 127 } 128 else 129 { 130 int nbAxisIdx = axisDstIndex.numElements(); 131 for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) 132 { 133 int globalAxisIdx = axisDstIndex(idxAxis); 134 transMap[globalAxisIdx].resize(ni_glo); 135 transWeight[globalAxisIdx].resize(ni_glo); 136 for (int idx = 0; idx < ni_glo; ++idx) 137 { 138 transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx; 139 transWeight[globalAxisIdx][idx] = 1.0; 140 } 119 141 } 120 142 } … … 123 145 { 124 146 int nbAxisIdx = axisDstIndex.numElements(); 125 for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)147 if (local) 126 148 { 127 int globalAxisIdx = axisDstIndex(idxAxis); 128 transMap[globalAxisIdx].resize(nj_glo); 129 transWeight[globalAxisIdx].resize(nj_glo); 130 for (int idx = 0; idx < nj_glo; ++idx) 149 const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; 150 const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; 151 const CArray<bool,1>& localMask = domainSrc_-> localMask ; 152 int nbDomainIdx = i_index.numElements(); 153 154 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) 131 155 { 132 transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx; 133 transWeight[globalAxisIdx][idx] = 1.0; 156 if (localMask(idxDomain)) 157 { 158 transMap[i_index(idxDomain)].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); 159 transWeight[i_index(idxDomain)].push_back(1.0) ; 160 } 161 } 162 } 163 else 164 { 165 for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) 166 { 167 int globalAxisIdx = axisDstIndex(idxAxis); 168 transMap[globalAxisIdx].resize(nj_glo); 169 transWeight[globalAxisIdx].resize(nj_glo); 170 for (int idx = 0; idx < nj_glo; ++idx) 171 { 172 transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx; 173 transWeight[globalAxisIdx][idx] = 1.0; 174 } 134 175 } 135 176 } -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_reduce_domain.hpp
r1339 r1460 49 49 50 50 ReduceDirection dir_; 51 bool local ; 52 51 53 protected: 52 54 void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs); -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_transformation.cpp
r895 r1460 19 19 20 20 CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) 21 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource), domainSrc_(0) 21 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource), domainSrc_(0),scalarSrc_(0) 22 22 { 23 23 axisDestGlobalSize_ = axisDestination->n_glo.getValue(); … … 30 30 31 31 CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource) 32 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource) 32 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource),scalarSrc_(0) 33 33 { 34 34 axisDestGlobalSize_ = axisDestination->n_glo.getValue(); … … 40 40 } 41 41 42 CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource) 43 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(0), scalarSrc_(scalarSource) 44 { 45 axisDestGlobalSize_ = axisDestination->n_glo.getValue(); 46 int niDest = axisDestination->n.getValue(); 47 int ibeginDest = axisDestination->begin.getValue(); 48 49 for (int idx = 0; idx < niDest; ++idx) 50 if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); 51 } 42 52 CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() 43 53 { … … 64 74 size_t globalIndex; 65 75 int nIndexSize = 0; 66 if (2 == elementType) nIndexSize = domainSrc_->i_index.numElements(); 67 else if (1 == elementType) nIndexSize = axisSrc_->index.numElements(); 76 CArray<bool,1>* ptLocalMask ; 77 CArray<bool,1> scalarMask(1) ; 78 scalarMask=true ; 79 80 if (2 == elementType) 81 { 82 nIndexSize = domainSrc_->i_index.numElements(); 83 ptLocalMask=&(domainSrc_->localMask) ; 84 } 85 else if (1 == elementType) 86 { 87 nIndexSize = axisSrc_->index.numElements(); 88 ptLocalMask=&(axisSrc_->mask) ; 89 } 90 else 91 { 92 nIndexSize=1 ; // scalar 93 ptLocalMask=&scalarMask ; 94 } 95 CArray<bool,1>& localMask=*ptLocalMask ; 96 68 97 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; 69 98 globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); 70 99 for (int idx = 0; idx < nIndexSize; ++idx) 71 100 { 72 if ( 2 == elementType)101 if (localMask(idx)) 73 102 { 74 globalIndex = domainSrc_->i_index(idx) + domainSrc_->j_index(idx) * domainSrc_->ni_glo; 103 if (2 == elementType) // domain 104 { 105 globalIndex = domainSrc_->i_index(idx) + domainSrc_->j_index(idx) * domainSrc_->ni_glo; 106 } 107 else if (1 == elementType) // axis 108 { 109 globalIndex = axisSrc_->index(idx); 110 } 111 else // scalar 112 { 113 globalIndex = 0; 114 } 115 116 globalIndex2ProcRank[globalIndex].resize(1); 117 globalIndex2ProcRank[globalIndex][0] = clientRank; 75 118 } 76 else if (1 == elementType)77 {78 globalIndex = axisSrc_->index(idx);79 }80 81 globalIndex2ProcRank[globalIndex].resize(1);82 globalIndex2ProcRank[globalIndex][0] = clientRank;83 119 } 84 120 -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_transformation.hpp
r934 r1460 17 17 class CAxis; 18 18 class CDomain; 19 19 class CScalar; 20 20 /*! 21 21 \class CAxisAlgorithmTransformation … … 27 27 CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource); 28 28 CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource); 29 CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource); 29 30 30 31 virtual ~CAxisAlgorithmTransformation(); … … 52 53 //! Domain on grid source 53 54 CDomain* domainSrc_; 55 56 //! Scalar on grid source 57 58 CScalar* scalarSrc_; 54 59 }; 55 60 -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_zoom.cpp
r1334 r1460 63 63 std::sort(zoomIndex_.begin(), zoomIndex_.end()); 64 64 } 65 65 66 } 66 67 … … 70 71 void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 71 72 { 72 this->transformationMapping_.resize(1); 73 this->transformationWeight_.resize(1); 74 75 TransformationIndexMap& transMap = this->transformationMapping_[0]; 76 TransformationWeightMap& transWeight = this->transformationWeight_[0]; 77 73 // We use all index of source and destination to calculate the mapping index of zoom. 74 // The server who receives the "zoomed" fields will decide whether it will forward these fields or write "real zoomed" fields into file 75 // That means servers need to change to cover this problem. 78 76 StdSize niSource = axisSrc_->n.getValue(); 79 77 StdSize ibeginSource = axisSrc_->begin.getValue(); … … 84 82 StdSize ni = iend + 1 - ibegin; 85 83 if (iend < ibegin) ni = 0; 84 85 this->transformationMapping_.resize(1); 86 this->transformationWeight_.resize(1); 87 88 TransformationIndexMap& transMap = this->transformationMapping_[0]; 89 TransformationWeightMap& transWeight = this->transformationWeight_[0]; 86 90 87 91 if (!zoomIndex_.empty()) … … 106 110 107 111 updateZoom(); 108 updateAxisDestinationMask();112 // updateAxisDestinationMask(); 109 113 } 110 114 … … 128 132 correct index be extracted 129 133 */ 130 void CAxisAlgorithmZoom::updateAxisDestinationMask()131 {132 StdSize niMask = axisDest_->mask.numElements();133 StdSize iBeginMask = axisDest_->begin.getValue();134 StdSize globalIndexMask = 0;135 TransformationIndexMap& transMap = this->transformationMapping_[0];136 TransformationIndexMap::const_iterator ite = (transMap).end();137 for (StdSize idx = 0; idx < niMask; ++idx)138 {139 globalIndexMask = iBeginMask + idx;140 if (transMap.find(globalIndexMask) == ite)141 (axisDest_->mask)(idx) = false;142 }143 }134 // void CAxisAlgorithmZoom::updateAxisDestinationMask() 135 // { 136 // StdSize niMask = axisDest_->mask.numElements(); 137 // StdSize iBeginMask = axisDest_->begin.getValue(); 138 // StdSize globalIndexMask = 0; 139 // TransformationIndexMap& transMap = this->transformationMapping_[0]; 140 // TransformationIndexMap::const_iterator ite = (transMap).end(); 141 // for (StdSize idx = 0; idx < niMask; ++idx) 142 // { 143 // globalIndexMask = iBeginMask + idx; 144 // if (transMap.find(globalIndexMask) == ite) 145 // (axisDest_->mask)(idx) = false; 146 // } 147 // } 144 148 145 149 } -
XIOS/dev/branch_openmp/src/transformation/axis_algorithm_zoom.hpp
r1205 r1460 35 35 36 36 private: 37 void updateAxisDestinationMask();37 // void updateAxisDestinationMask(); 38 38 void updateZoom(); 39 39 -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_expand.cpp
r1113 r1460 167 167 int njSrc = domainSource->nj, jbegin = domainSource->jbegin; 168 168 int dataDimSrc = domainSource->data_dim; 169 CArray<bool,1>& mask_1d_src = domainSource-> mask_1d;169 CArray<bool,1>& mask_1d_src = domainSource->domainMask; 170 170 CArray<int,1>& i_index_src = domainSource->i_index; 171 171 CArray<int,1>& j_index_src = domainSource->j_index; … … 174 174 int data_i_begin_src = domainSource->data_ibegin; 175 175 int data_j_begin_src = domainSource->data_jbegin; 176 CArray<double,1>& lon_src = domainSource->lonvalue _client;177 CArray<double,1>& lat_src = domainSource->latvalue _client;176 CArray<double,1>& lon_src = domainSource->lonvalue; 177 CArray<double,1>& lat_src = domainSource->latvalue; 178 178 179 179 // We need to generate boundary for longitude and latitude … … 230 230 domainDestination->global_zoom_nj.setValue(domainSource->global_zoom_nj+2); 231 231 232 CArray<bool,1>& mask_1d_dst = domainDestination-> mask_1d;232 CArray<bool,1>& mask_1d_dst = domainDestination->domainMask; 233 233 CArray<int,1>& i_index_dst = domainDestination->i_index; 234 234 CArray<int,1>& j_index_dst = domainDestination->j_index; … … 252 252 CArray<int,1> data_j_index_dst_full(newNbLocalDst); 253 253 254 domainDestination->lonvalue _client.resizeAndPreserve(newNbLocalDst);255 domainDestination->latvalue _client.resizeAndPreserve(newNbLocalDst);254 domainDestination->lonvalue.resizeAndPreserve(newNbLocalDst); 255 domainDestination->latvalue.resizeAndPreserve(newNbLocalDst); 256 256 domainDestination->bounds_lon_1d.resizeAndPreserve(nVertex, newNbLocalDst); 257 257 domainDestination->bounds_lat_1d.resizeAndPreserve(nVertex, newNbLocalDst); 258 CArray<double,1>& lon_dst = domainDestination->lonvalue _client;259 CArray<double,1>& lat_dst = domainDestination->latvalue _client;258 CArray<double,1>& lon_dst = domainDestination->lonvalue; 259 CArray<double,1>& lat_dst = domainDestination->latvalue; 260 260 CArray<double,2>& bounds_lon_dst = domainDestination->bounds_lon_1d; 261 261 CArray<double,2>& bounds_lat_dst = domainDestination->bounds_lat_1d; … … 452 452 domainDestination->latvalue_1d = (lat_dst); 453 453 } 454 454 domainDestination->mask_1d.resize(domainDestination->domainMask.numElements()) ; 455 domainDestination->mask_1d=domainDestination->domainMask ; 456 domainDestination->computeLocalMask() ; 455 457 } 456 458 … … 484 486 // Now extend domain destination 485 487 int niGlob = domainSource->ni_glo; 486 CArray<bool,1>& mask_1d_src = domainSource-> mask_1d;488 CArray<bool,1>& mask_1d_src = domainSource->domainMask; 487 489 CArray<int,1>& i_index_src = domainSource->i_index; 488 490 CArray<double,1>& lon_src = domainSource->lonvalue_1d; … … 507 509 } 508 510 509 CArray<bool,1>& mask_1d_dst = domainDestination-> mask_1d;511 CArray<bool,1>& mask_1d_dst = domainDestination->domainMask; 510 512 CArray<int,1>& i_index_dst = domainDestination->i_index; 511 513 CArray<int,1>& j_index_dst = domainDestination->j_index; … … 664 666 // Update ni 665 667 domainDestination->ni.setValue(newNbLocalDst); 668 domainDestination->mask_1d.resize(domainDestination->domainMask.numElements()) ; 669 domainDestination->mask_1d=domainDestination->domainMask ; 670 domainDestination->computeLocalMask() ; 666 671 } 667 672 -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_generate_rectilinear.hpp
r827 r1460 20 20 /*! 21 21 \class CDomainAlgorithmGenerateRectilinear 22 Generate a rectilinear domain and fill in necessary its attributes automatically23 A new rectilinear domain will also be distributed automatically among the processes.22 Generate a rectilinear or CURVILINEAR domain and fill in necessary its attributes automatically 23 A new rectilinear (or CURVILINEAR) domain will also be distributed automatically among the processes. 24 24 The number of processes is deduced from the distribution of the grid source. 25 25 */ -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_interpolate.cpp
r1338 r1460 53 53 CContext* context = CContext::getCurrent(); 54 54 interpDomain_->checkValid(domainSource); 55 56 detectMissingValue = interpDomain_->detect_missing_value ; 57 renormalize = interpDomain_->renormalize ; 58 quantity = interpDomain_->quantity ; 59 60 if (interpDomain_->read_write_convention == CInterpolateDomain::read_write_convention_attr::fortran) fortranConvention=true ; 61 else fortranConvention=false ; 62 55 63 fileToReadWrite_ = "xios_interpolation_weights_"; 56 64 … … 100 108 std::vector<double> srcPole(3,0), dstPole(3,0); 101 109 int orderInterp = interpDomain_->order.getValue(); 102 bool renormalize ; 103 bool quantity ; 104 105 if (interpDomain_->renormalize.isEmpty()) renormalize=true; 106 else renormalize = interpDomain_->renormalize; 107 108 if (interpDomain_->quantity.isEmpty()) quantity=false; 109 else quantity = interpDomain_->quantity; 110 110 111 111 112 const double poleValue = 90.0; … … 456 457 recvTemp[recvSourceIndexBuff[idx]] += recvSourceWeightBuff[idx]/nbGlobalPointOnPole; 457 458 else 458 recvTemp[recvSourceIndexBuff[idx]] = 0.0;459 recvTemp[recvSourceIndexBuff[idx]] = recvSourceWeightBuff[idx]/nbGlobalPointOnPole; 459 460 } 460 461 … … 476 477 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 477 478 { 478 if (readFromFile_ && !writeToFile_)479 if (readFromFile_) 479 480 readRemapInfo(); 480 481 else … … 566 567 } 567 568 568 domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp );569 domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp, client->serverSize); 569 570 const CClientServerMapping::GlobalIndexMap& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 570 571 … … 775 776 776 777 int index = 0; 778 int indexOffset=0 ; 779 if (fortranConvention) indexOffset=1 ; 777 780 for (it = itb; it !=ite; ++it) 778 781 { … … 780 783 for (int idx = 0; idx < tmp.size(); ++idx) 781 784 { 782 dst_idx(index) = it->first + 1;783 src_idx(index) = tmp[idx].first + 1;785 dst_idx(index) = it->first + indexOffset; 786 src_idx(index) = tmp[idx].first + indexOffset; 784 787 weights(index) = tmp[idx].second; 785 788 ++index; … … 843 846 size_t nbWeightGlo ; 844 847 848 845 849 CContext* context = CContext::getCurrent(); 846 850 CContextClient* client=context->client; … … 848 852 int clientSize = client->clientSize; 849 853 854 855 { 856 ifstream f(filename.c_str()); 857 if (!f.good()) ERROR("void CDomainAlgorithmInterpolate::readInterpolationInfo", 858 << "Attempt to read file weight :" << filename << " which doesn't seem to exist." << std::endl 859 << "Please check this file "); 860 } 861 850 862 nc_open(filename.c_str(),NC_NOWRITE, &ncid) ; 851 863 nc_inq_dimid(ncid,"n_weight",&weightDimId) ; … … 882 894 nc_get_vara_long(ncid, dstIndexId, &start, &nbWeight, dstIndex) ; 883 895 884 for(size_t ind=0; ind<nbWeight;++ind) 885 interpMapValue[dstIndex[ind]-1].push_back(make_pair(srcIndex[ind]-1,weight[ind])); 886 } 887 888 } 896 int indexOffset=0 ; 897 if (fortranConvention) indexOffset=1 ; 898 for(size_t ind=0; ind<nbWeight;++ind) 899 interpMapValue[dstIndex[ind]-indexOffset].push_back(make_pair(srcIndex[ind]-indexOffset,weight[ind])); 900 } 901 902 void CDomainAlgorithmInterpolate::apply(const std::vector<std::pair<int,double> >& localIndex, 903 const double* dataInput, 904 CArray<double,1>& dataOut, 905 std::vector<bool>& flagInitial, 906 bool ignoreMissingValue, bool firstPass ) 907 { 908 int nbLocalIndex = localIndex.size(); 909 double defaultValue = std::numeric_limits<double>::quiet_NaN(); 910 911 if (detectMissingValue) 912 { 913 if (firstPass && renormalize) 914 { 915 renormalizationFactor.resize(dataOut.numElements()) ; 916 renormalizationFactor=1 ; 917 } 918 919 for (int idx = 0; idx < nbLocalIndex; ++idx) 920 { 921 if (NumTraits<double>::isnan(*(dataInput + idx))) 922 { 923 flagInitial[localIndex[idx].first] = false; 924 if (renormalize) renormalizationFactor(localIndex[idx].first)-=localIndex[idx].second ; 925 } 926 else 927 { 928 dataOut(localIndex[idx].first) += *(dataInput + idx) * localIndex[idx].second; 929 flagInitial[localIndex[idx].first] = true; // Reset flag to indicate not all data source are nan 930 } 931 } 932 933 // If all data source are nan then data destination must be nan 934 for (int idx = 0; idx < nbLocalIndex; ++idx) 935 { 936 if (!flagInitial[localIndex[idx].first]) 937 dataOut(localIndex[idx].first) = defaultValue; 938 } 939 } 940 else 941 { 942 for (int idx = 0; idx < nbLocalIndex; ++idx) 943 { 944 dataOut(localIndex[idx].first) += *(dataInput + idx) * localIndex[idx].second; 945 } 946 } 947 } 948 949 void CDomainAlgorithmInterpolate::updateData(CArray<double,1>& dataOut) 950 { 951 if (detectMissingValue && renormalize) 952 { 953 if (renormalizationFactor.numElements()>0) dataOut/=renormalizationFactor ; // In some case, process doesn't received any data for interpolation (mask) 954 // so renormalizationFactor is not initialized 955 } 956 } 957 958 } -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_interpolate.hpp
r1328 r1460 31 31 virtual ~CDomainAlgorithmInterpolate() {} 32 32 33 virtual void apply(const std::vector<std::pair<int,double> >& localIndex, 34 const double* dataInput, 35 CArray<double,1>& dataOut, 36 std::vector<bool>& flagInitial, 37 bool ignoreMissingValue, bool firstPass); 38 virtual void updateData(CArray<double,1>& dataOut); 39 33 40 static bool registerTrans(); 34 41 protected: … … 47 54 48 55 private: 56 CArray<double,1> renormalizationFactor ; 57 bool detectMissingValue ; 58 bool renormalize ; 59 bool quantity ; 60 49 61 CInterpolateDomain* interpDomain_; 50 62 bool writeToFile_; 51 63 bool readFromFile_; 52 64 StdString fileToReadWrite_; 65 bool fortranConvention ; 53 66 54 67 // class WriteNetCdf; -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_transformation.cpp
r888 r1460 48 48 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; 49 49 globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); 50 CArray<bool,1>& localMask=domainSrc_->localMask ; 50 51 for (int idx = 0; idx < nIndexSize; ++idx) 51 52 { 52 i_ind=domainSrc_->i_index(idx) ; 53 j_ind=domainSrc_->j_index(idx) ; 53 if (localMask(idx)) 54 { 55 i_ind=domainSrc_->i_index(idx) ; 56 j_ind=domainSrc_->j_index(idx) ; 54 57 55 globalIndex = i_ind + j_ind * niGlob; 56 globalIndex2ProcRank[globalIndex].push_back(clientRank); 58 globalIndex = i_ind + j_ind * niGlob; 59 globalIndex2ProcRank[globalIndex].push_back(clientRank); 60 } 57 61 } 58 62 -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_zoom.cpp
r933 r1460 74 74 void CDomainAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 75 75 { 76 int niSource = domainSrc_->ni.getValue();77 int ibeginSource = domainSrc_->ibegin.getValue();78 int iendSource = ibeginSource + niSource - 1;79 80 int ibegin = std::max(ibeginSource, zoomIBegin_);81 int iend = std::min(iendSource, zoomIEnd_);82 int ni = iend + 1 - ibegin;83 if (iend < ibegin) ni = 0;84 85 int njSource = domainSrc_->nj.getValue();86 int jbeginSource = domainSrc_->jbegin.getValue();87 int jendSource = jbeginSource + njSource - 1;88 89 int jbegin = std::max(jbeginSource, zoomJBegin_);90 int jend = std::min(jendSource, zoomJEnd_);91 int nj = jend + 1 - jbegin;92 if (jend < jbegin) nj = 0;93 76 94 77 int niGlob = domainSrc_->ni_glo.getValue(); … … 102 85 103 86 int domainGlobalIndex; 104 for (int j = 0; j < nj; ++j) 87 int iglob ; 88 int jglob ; 89 const CArray<int,1>& i_index = domainSrc_->i_index.getValue() ; 90 const CArray<int,1>& j_index = domainSrc_->j_index.getValue() ; 91 92 int nglo = i_index.numElements() ; 93 for (size_t i = 0; i < nglo ; ++i) 105 94 { 106 for (int i = 0; i < ni; ++i) 95 iglob=i_index(i) ; jglob=j_index(i) ; 96 if (iglob>=zoomIBegin_ && iglob<=zoomIEnd_ && jglob>=zoomJBegin_ && jglob<=zoomJEnd_) 107 97 { 108 domainGlobalIndex = (j+jbegin) * niGlob + (i+ibegin);98 domainGlobalIndex = jglob*niGlob + iglob; 109 99 transMap[domainGlobalIndex].push_back(domainGlobalIndex); 110 100 transWeight[domainGlobalIndex].push_back(1.0); 111 101 } 112 102 } 113 114 103 updateZoom(); 115 updateDomainDestinationMask();116 104 } 117 105 … … 132 120 correct index be extracted 133 121 */ 134 void CDomainAlgorithmZoom::updateDomainDestinationMask()135 {136 int niMask = domainDest_->ni.getValue();137 int iBeginMask = domainDest_->ibegin.getValue();138 int njMask = domainDest_->nj.getValue();139 int jBeginMask = domainDest_->jbegin.getValue();140 int niGlob = domainDest_->ni_glo.getValue();141 int globalIndexMask = 0;122 // void CDomainAlgorithmZoom::updateDomainDestinationMask() 123 // { 124 // int niMask = domainDest_->ni.getValue(); 125 // int iBeginMask = domainDest_->ibegin.getValue(); 126 // int njMask = domainDest_->nj.getValue(); 127 // int jBeginMask = domainDest_->jbegin.getValue(); 128 // int niGlob = domainDest_->ni_glo.getValue(); 129 // int globalIndexMask = 0; 142 130 143 TransformationIndexMap& transMap = this->transformationMapping_[0];144 TransformationIndexMap::const_iterator ite = (transMap).end();145 for (int j = 0; j < njMask; ++j)146 {147 for (int i = 0; i < niMask; ++i)148 {149 globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask);150 if (transMap.find(globalIndexMask) == ite)151 (domainDest_->mask_1d)(i+j*niMask) = false;152 }153 }154 }131 // TransformationIndexMap& transMap = this->transformationMapping_[0]; 132 // TransformationIndexMap::const_iterator ite = (transMap).end(); 133 // for (int j = 0; j < njMask; ++j) 134 // { 135 // for (int i = 0; i < niMask; ++i) 136 // { 137 // globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask); 138 // if (transMap.find(globalIndexMask) == ite) 139 // (domainDest_->mask_1d)(i+j*niMask) = false; 140 // } 141 // } 142 // } 155 143 156 144 } -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_zoom.hpp
r933 r1460 36 36 37 37 private: 38 void updateDomainDestinationMask();38 // void updateDomainDestinationMask(); 39 39 void updateZoom(); 40 40 -
XIOS/dev/branch_openmp/src/transformation/generic_algorithm_transformation.cpp
r1328 r1460 12 12 #include "client_client_dht_template.hpp" 13 13 #include "utils.hpp" 14 #include "timer.hpp" 15 #include "mpi.hpp" 14 16 15 17 namespace xios { … … 17 19 CGenericAlgorithmTransformation::CGenericAlgorithmTransformation() 18 20 : transformationMapping_(), transformationWeight_(), transformationPosition_(), 19 idAuxInputs_(), type_(ELEMENT_NO_MODIFICATION_WITH_DATA) 21 idAuxInputs_(), type_(ELEMENT_NO_MODIFICATION_WITH_DATA), indexElementSrc_(), 22 computedProcSrcNonTransformedElement_(false), eliminateRedondantSrc_(true), isDistributedComputed_(false) 20 23 { 21 24 } … … 112 115 } 113 116 117 bool CGenericAlgorithmTransformation::isDistributedTransformation(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst) 118 { 119 120 if (!isDistributedComputed_) 121 { 122 isDistributedComputed_=true ; 123 if (!eliminateRedondantSrc_) isDistributed_=true ; 124 else 125 { 126 CContext* context = CContext::getCurrent(); 127 CContextClient* client = context->client; 128 129 computePositionElements(gridSrc, gridDst); 130 std::vector<CScalar*> scalarListSrcP = gridSrc->getScalars(); 131 std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); 132 std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); 133 int distributed, distributed_glo ; 134 135 CArray<int,1> axisDomainSrcOrder = gridSrc->axis_domain_order; 136 if (2 == axisDomainSrcOrder(elementPositionInGrid)) // It's domain 137 { 138 distributed=domainListSrcP[elementPositionInGridSrc2DomainPosition_[elementPositionInGrid]]->isDistributed() ; 139 ep_lib::MPI_Allreduce(&distributed,&distributed_glo, 1, MPI_INT, MPI_LOR, client->intraComm) ; 140 141 } 142 else if (1 == axisDomainSrcOrder(elementPositionInGrid))//it's an axis 143 { 144 distributed=axisListSrcP[elementPositionInGridSrc2AxisPosition_[elementPositionInGrid]]->isDistributed() ; 145 ep_lib::MPI_Allreduce(&distributed,&distributed_glo, 1, MPI_INT, MPI_LOR, client->intraComm) ; 146 } 147 else //it's a scalar 148 { 149 distributed_glo=false ; 150 } 151 isDistributed_=distributed_glo ; 152 } 153 } 154 return isDistributed_ ; 155 } 114 156 /*! 115 157 This function computes the global indexes of grid source, which the grid destination is in demand. … … 130 172 131 173 typedef boost::unordered_map<int, std::vector<std::pair<int,double> > > SrcToDstMap; 132 133 size_t indexSrcSize = 0; 134 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 135 { 136 TransformationIndexMap::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap, 137 iteTransMap = transformationMapping_[idxTrans].end(); 138 TransformationWeightMap::const_iterator itbTransWeight = transformationWeight_[idxTrans].begin(), itTransWeight; 139 140 itTransWeight = itbTransWeight; 141 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 142 { 143 indexSrcSize += (itTransMap->second).size(); 144 } 145 } 146 147 bool isTransPosEmpty = transformationPosition_.empty(); 148 CArray<size_t,1> transPos; 149 if (!isTransPosEmpty) transPos.resize(transformationMapping_.size()); 150 CArray<size_t,1> indexSrc(indexSrcSize); 151 indexSrcSize = 0; 152 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 153 { 154 TransformationIndexMap::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap, 155 iteTransMap = transformationMapping_[idxTrans].end(); 156 TransformationWeightMap::const_iterator itbTransWeight = transformationWeight_[idxTrans].begin(), itTransWeight; 157 158 // Build mapping between global source element index and global destination element index. 159 itTransWeight = itbTransWeight; 160 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 161 { 162 const std::vector<int>& srcIndex = itTransMap->second; 163 for (int idx = 0; idx < srcIndex.size(); ++idx) 164 { 165 indexSrc(indexSrcSize) = srcIndex[idx]; 166 ++indexSrcSize; 167 } 168 } 169 170 if (!isTransPosEmpty) 171 { 172 TransformationPositionMap::const_iterator itPosMap = transformationPosition_[idxTrans].begin(); 173 transPos(idxTrans) = itPosMap->second[0]; 174 } 175 } 174 int idx; 176 175 177 176 // compute position of elements on grids … … 184 183 std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); 185 184 std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); 186 CArray<int,1> axisDomainSrcOrder = gridSrc->axis_domain_order; 187 188 // Find out global index source of transformed element on corresponding process. 189 std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc(axisDomainDstOrder.numElements()); 190 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc; 191 for (int idx = 0; idx < axisDomainDstOrder.numElements(); ++idx) 192 { 193 if (idx == elementPositionInGrid) 194 computeExchangeGlobalIndex(indexSrc, axisDomainSrcOrder(idx), globalIndexOfTransformedElementOnProc); //globalElementIndexOnProc[idx]); 195 if (2 == axisDomainDstOrder(idx)) // It's domain 196 { 197 if (idx != elementPositionInGrid) 198 computeExchangeDomainIndex(domainListDestP[elementPositionInGridDst2DomainPosition_[idx]], 199 domainListSrcP[elementPositionInGridSrc2DomainPosition_[idx]], 200 transPos, 201 globalElementIndexOnProc[idx]); 202 203 } 204 else if (1 == axisDomainDstOrder(idx))//it's an axis 205 { 206 if (idx != elementPositionInGrid) 207 computeExchangeAxisIndex(axisListDestP[elementPositionInGridDst2AxisPosition_[idx]], 208 axisListSrcP[elementPositionInGridSrc2AxisPosition_[idx]], 209 transPos, 210 globalElementIndexOnProc[idx]); 211 } 212 else //it's a scalar 213 { 214 if (idx != elementPositionInGrid) 215 computeExchangeScalarIndex(scalarListDestP[elementPositionInGridDst2ScalarPosition_[idx]], 216 scalarListSrcP[elementPositionInGridSrc2ScalarPosition_[idx]], 217 transPos, 218 globalElementIndexOnProc[idx]); 219 220 } 221 } 222 223 if (!isTransPosEmpty) 224 { 225 for (int idx = 0; idx < globalElementIndexOnProc.size(); ++idx) 226 { 227 if (idx != elementPositionInGrid) 228 { 229 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc[idx].begin(), it, 230 ite = globalElementIndexOnProc[idx].end(); 231 for (it = itb; it != ite; ++it) it->second.resize(1); 232 } 233 } 234 } 235 185 CArray<int,1> axisDomainSrcOrder = gridSrc->axis_domain_order; 186 187 bool isTransPosEmpty = transformationPosition_.empty(); 188 CArray<size_t,1> transPos; 189 if (!isTransPosEmpty) transPos.resize(transformationMapping_.size()); 190 std::set<size_t> allIndexSrc; // All index of source, which can be scattered among processes, need for doing transformation 191 192 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 193 { 194 TransformationIndexMap::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap, 195 iteTransMap = transformationMapping_[idxTrans].end(); 196 TransformationWeightMap::const_iterator itbTransWeight = transformationWeight_[idxTrans].begin(), itTransWeight; 197 198 // Build mapping between global source element index and global destination element index. 199 itTransWeight = itbTransWeight; 200 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 201 { 202 const std::vector<int>& srcIndex = itTransMap->second; 203 for (idx = 0; idx < srcIndex.size(); ++idx) 204 allIndexSrc.insert(srcIndex[idx]); 205 } 206 207 if (!isTransPosEmpty) 208 { 209 TransformationPositionMap::const_iterator itPosMap = transformationPosition_[idxTrans].begin(); 210 transPos(idxTrans) = itPosMap->second[0]; 211 } 212 } 213 214 size_t indexSrcSize = 0; 215 CArray<size_t,1> indexSrc(allIndexSrc.size()); 216 for (std::set<size_t>::iterator it = allIndexSrc.begin(); it != allIndexSrc.end(); ++it, ++indexSrcSize) 217 indexSrc(indexSrcSize) = *it; 218 219 // Flag to indicate whether we will recompute distribution of source global index on processes 220 bool computeGlobalIndexOnProc = false; 221 if (indexElementSrc_.size() != allIndexSrc.size()) 222 computeGlobalIndexOnProc = true; 223 else 224 { 225 for (std::set<size_t>::iterator it = allIndexSrc.begin(); it != allIndexSrc.end(); ++it) 226 if (0 == indexElementSrc_.count(*it)) 227 { 228 computeGlobalIndexOnProc = true; 229 break; 230 } 231 } 232 233 if (computeGlobalIndexOnProc) 234 indexElementSrc_.swap(allIndexSrc); 235 236 int sendValue = (computeGlobalIndexOnProc) ? 1 : 0; 237 int recvValue = 0; 238 ep_lib::MPI_Allreduce(&sendValue, &recvValue, 1, MPI_INT, MPI_SUM, client->intraComm); 239 computeGlobalIndexOnProc = (0 < recvValue); 240 241 // CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc; 242 243 if (computeGlobalIndexOnProc || !computedProcSrcNonTransformedElement_) 244 { 245 { 246 CClientClientDHTInt::Index2VectorInfoTypeMap tmp ; 247 globalIndexOfTransformedElementOnProc_.swap(tmp) ; 248 } 249 // Find out global index source of transformed element on corresponding process. 250 if (globalElementIndexOnProc_.empty()) 251 globalElementIndexOnProc_.resize(axisDomainDstOrder.numElements()); 252 253 for (idx = 0; idx < axisDomainDstOrder.numElements(); ++idx) 254 { 255 256 if (idx == elementPositionInGrid) 257 computeExchangeGlobalIndex(indexSrc, axisDomainSrcOrder(idx), globalIndexOfTransformedElementOnProc_); //globalElementIndexOnProc[idx]); 258 if (!computedProcSrcNonTransformedElement_) 259 { 260 if (2 == axisDomainDstOrder(idx)) // It's domain 261 { 262 if (idx != elementPositionInGrid) 263 computeExchangeDomainIndex(domainListDestP[elementPositionInGridDst2DomainPosition_[idx]], 264 domainListSrcP[elementPositionInGridSrc2DomainPosition_[idx]], 265 transPos, 266 globalElementIndexOnProc_[idx]); 267 268 } 269 else if (1 == axisDomainDstOrder(idx))//it's an axis 270 { 271 if (idx != elementPositionInGrid) 272 computeExchangeAxisIndex(axisListDestP[elementPositionInGridDst2AxisPosition_[idx]], 273 axisListSrcP[elementPositionInGridSrc2AxisPosition_[idx]], 274 transPos, 275 globalElementIndexOnProc_[idx]); 276 } 277 else //it's a scalar 278 { 279 if (idx != elementPositionInGrid) 280 computeExchangeScalarIndex(scalarListDestP[elementPositionInGridDst2ScalarPosition_[idx]], 281 scalarListSrcP[elementPositionInGridSrc2ScalarPosition_[idx]], 282 transPos, 283 globalElementIndexOnProc_[idx]); 284 285 } 286 } 287 } 288 289 if (!isTransPosEmpty && !computedProcSrcNonTransformedElement_) 290 { 291 for (idx = 0; idx < globalElementIndexOnProc_.size(); ++idx) 292 { 293 if (idx != elementPositionInGrid) 294 { 295 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc_[idx].begin(), it, 296 ite = globalElementIndexOnProc_[idx].end(); 297 for (it = itb; it != ite; ++it) it->second.resize(1); 298 } 299 } 300 } 301 302 /* 303 if (!computedProcSrcNonTransformedElement_) 304 { 305 for (idx = 0; idx < globalElementIndexOnProc_.size(); ++idx) 306 { 307 if (idx != elementPositionInGrid) 308 { 309 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc_[idx].begin(), it, 310 ite = globalElementIndexOnProc_[idx].end(); 311 for (it = itb; it != ite; ++it) procOfNonTransformedElements_.insert(it->first); 312 if (procOfNonTransformedElements_.size() == nbClient) 313 break; 314 } 315 } 316 } 317 318 // Processes contain the source index of transformed element 319 std::set<int> procOfTransformedElement; 320 CClientClientDHTInt::Index2VectorInfoTypeMap::iterator itIdxb = globalIndexOfTransformedElementOnProc.begin(), 321 itIdxe = globalIndexOfTransformedElementOnProc.end(), itIdx; 322 for (itIdx = itIdxb; itIdx != itIdxe; ++itIdx) 323 { 324 std::vector<int>& tmp = itIdx->second; 325 for (int i = 0; i < tmp.size(); ++i) 326 procOfTransformedElement.insert(tmp[i]); 327 if (tmp.size() == nbClient) 328 break; 329 } 330 331 std::set<int>& commonProc = (procOfTransformedElement.size() < procOfNonTransformedElements_.size()) ? procOfTransformedElement 332 : (!procOfNonTransformedElements_.empty() ? procOfNonTransformedElements_ : procOfTransformedElement); 333 334 std::vector<int> procContainSrcElementIdx(commonProc.size()); 335 int count = 0; 336 for (std::set<int>::iterator it = commonProc.begin(); it != commonProc.end(); ++it) 337 procContainSrcElementIdx[count++] = *it; 338 339 procContainSrcElementIdx_.swap(procContainSrcElementIdx); 340 */ 341 342 if (procElementList_.empty()) procElementList_.resize(axisDomainDstOrder.numElements()) ; 343 for (idx = 0; idx < axisDomainDstOrder.numElements(); ++idx) 344 { 345 std::set<int>& procList=procElementList_[idx] ; 346 std::set<int> commonTmp ; 347 if (idx == elementPositionInGrid) 348 { 349 set<int> tmpSet ; 350 procList.swap(tmpSet) ; 351 CClientClientDHTInt::Index2VectorInfoTypeMap::iterator itIdxb = globalIndexOfTransformedElementOnProc_.begin(), 352 itIdxe = globalIndexOfTransformedElementOnProc_.end(), itIdx; 353 for (itIdx = itIdxb; itIdx != itIdxe; ++itIdx) 354 { 355 std::vector<int>& tmp = itIdx->second; 356 for (int i = 0; i < tmp.size(); ++i) procList.insert(tmp[i]); 357 if (tmp.size() == nbClient) 358 break; 359 } 360 } 361 else 362 { 363 if (!computedProcSrcNonTransformedElement_) 364 { 365 set<int> tmpSet ; 366 procList.swap(tmpSet) ; 367 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc_[idx].begin(), it, 368 ite = globalElementIndexOnProc_[idx].end(); 369 for (it = itb; it != ite; ++it) 370 { 371 procList.insert(it->first); 372 if (procList.size() == nbClient) break; 373 } 374 } 375 } 376 377 if (idx==0) commonProc_= procList ; 378 else 379 { 380 for (std::set<int>::iterator it = commonProc_.begin(); it != commonProc_.end(); ++it) 381 if (procList.count(*it)==1) commonTmp.insert(*it) ; 382 commonProc_.swap(commonTmp) ; 383 } 384 } 385 std::vector<int> procContainSrcElementIdx(commonProc_.size()); 386 int count = 0; 387 for (std::set<int>::iterator it = commonProc_.begin(); it != commonProc_.end(); ++it) procContainSrcElementIdx[count++] = *it; 388 procContainSrcElementIdx_.swap(procContainSrcElementIdx); 389 390 // For the first time, surely we calculate proc containing non transformed elements 391 if (!computedProcSrcNonTransformedElement_) computedProcSrcNonTransformedElement_ = true; 392 } 393 236 394 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 237 395 { … … 243 401 244 402 // Build mapping between global source element index and global destination element index. 245 boost::unordered_map<int,std::vector<size_t> >().swap(globalElementIndexOnProc [elementPositionInGrid]);246 boost::unordered_map<int,int> tmpCounter;403 boost::unordered_map<int,std::vector<size_t> >().swap(globalElementIndexOnProc_[elementPositionInGrid]); 404 std::set<int> tmpCounter; 247 405 itTransWeight = itbTransWeight; 248 406 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) … … 250 408 const std::vector<int>& srcIndex = itTransMap->second; 251 409 const std::vector<double>& weight = itTransWeight->second; 252 for (i nt idx = 0; idx < srcIndex.size(); ++idx)410 for (idx = 0; idx < srcIndex.size(); ++idx) 253 411 { 254 412 src2DstMap[srcIndex[idx]].push_back(make_pair(itTransMap->first, weight[idx])); 255 if (1 == globalIndexOfTransformedElementOnProc.count(srcIndex[idx]) && (0 == tmpCounter.count(srcIndex[idx]))) 256 { 257 tmpCounter[srcIndex[idx]] = 1; 258 std::vector<int>& srcProc = globalIndexOfTransformedElementOnProc[srcIndex[idx]]; 259 for (int j = 0; j < srcProc.size(); ++j) 260 globalElementIndexOnProc[elementPositionInGrid][srcProc[j]].push_back(srcIndex[idx]); 261 } 262 } 263 } 264 413 if (0 == tmpCounter.count(srcIndex[idx])) 414 { 415 tmpCounter.insert(srcIndex[idx]); 416 417 vector<int>& rankSrc = globalIndexOfTransformedElementOnProc_[srcIndex[idx]] ; 418 for (int n=0;n<rankSrc.size();++n) 419 { 420 if (commonProc_.count(rankSrc[n])==1) globalElementIndexOnProc_[elementPositionInGrid][rankSrc[n]].push_back(srcIndex[idx]); 421 } 422 // for (int j = 0; j < procContainSrcElementIdx_.size(); ++j) 423 // globalElementIndexOnProc_[elementPositionInGrid][procContainSrcElementIdx_[j]].push_back(srcIndex[idx]); 424 } 425 } 426 } 427 265 428 if (!isTransPosEmpty) 266 429 { 267 for (i nt idx = 0; idx < globalElementIndexOnProc.size(); ++idx)430 for (idx = 0; idx < globalElementIndexOnProc_.size(); ++idx) 268 431 { 269 432 if (idx != elementPositionInGrid) 270 433 { 271 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc [idx].begin(), it,272 ite = globalElementIndexOnProc [idx].end();434 boost::unordered_map<int,std::vector<size_t> >::iterator itb = globalElementIndexOnProc_[idx].begin(), it, 435 ite = globalElementIndexOnProc_[idx].end(); 273 436 for (it = itb; it != ite; ++it) it->second[0] = transPos(idxTrans); 274 437 } 275 438 } 276 }277 278 std::vector<std::vector<bool> > elementOnProc(axisDomainDstOrder.numElements(), std::vector<bool>(nbClient, false));279 boost::unordered_map<int,std::vector<size_t> >::const_iterator it, itb, ite;280 for (int idx = 0; idx < globalElementIndexOnProc.size(); ++idx)281 {282 itb = globalElementIndexOnProc[idx].begin();283 ite = globalElementIndexOnProc[idx].end();284 for (it = itb; it != ite; ++it) elementOnProc[idx][it->first] = true;285 }286 287 // Determine procs which contain global source index288 std::vector<bool> intersectedProc(nbClient, true);289 for (int idx = 0; idx < axisDomainDstOrder.numElements(); ++idx)290 {291 std::transform(elementOnProc[idx].begin(), elementOnProc[idx].end(),292 intersectedProc.begin(), intersectedProc.begin(),293 std::logical_and<bool>());294 }295 296 std::vector<int> srcRank;297 for (int idx = 0; idx < nbClient; ++idx)298 {299 if (intersectedProc[idx]) srcRank.push_back(idx);300 439 } 301 440 302 441 // Ok, now compute global index of grid source and ones of grid destination 303 442 computeGlobalGridIndexMapping(elementPositionInGrid, 304 srcRank,443 procContainSrcElementIdx_, //srcRank, 305 444 src2DstMap, 306 445 gridSrc, 307 446 gridDst, 308 globalElementIndexOnProc ,447 globalElementIndexOnProc_, 309 448 globaIndexWeightFromSrcToDst); 310 } 449 } 311 450 } 312 451 … … 316 455 \param [in] srcRank rank of client from which we demand global index of element source 317 456 \param [in] src2DstMap mapping of global index of element source and global index of element destination 318 \param [in] gridSrc Grid source319 \param [in] gridDst Grid destination320 \param [in] globalElementIndexOnProc Global index of element source on different client rank321 \param [out] globaIndexWeightFromSrcToDst Mapping of global index of grid source and grid destination457 \param [in] gridSrc Grid source 458 \param [in] gridDst Grid destination 459 \param [in] globalElementIndexOnProc Global index of element source on different client rank 460 \param [out] globaIndexWeightFromSrcToDst Mapping of global index of grid source and grid destination 322 461 */ 323 462 void CGenericAlgorithmTransformation::computeGlobalGridIndexMapping(int elementPositionInGrid, … … 329 468 SourceDestinationIndexMap& globaIndexWeightFromSrcToDst) 330 469 { 470 SourceDestinationIndexMap globaIndexWeightFromSrcToDst_tmp ; 471 472 CContext* context = CContext::getCurrent(); 473 CContextClient* client=context->client; 474 int clientRank = client->clientRank; 475 331 476 std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); 332 477 std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); … … 369 514 size_t globalDstSize = 1; 370 515 domainIndex = axisIndex = scalarIndex = 0; 516 set<size_t> globalSrcStoreIndex ; 517 371 518 for (int idx = 0; idx < nbElement; ++idx) 372 519 { … … 392 539 } 393 540 541 std::map< std::pair<size_t,size_t>, int > rankMap ; 542 std::map< std::pair<size_t,size_t>, int >:: iterator rankMapIt ; 543 394 544 for (int i = 0; i < srcRank.size(); ++i) 395 545 { … … 451 601 for (int k = 0; k < globalElementDstIndexSize; ++k) 452 602 { 453 globaIndexWeightFromSrcToDst[rankSrc][globalSrcIndex].push_back(make_pair(globalDstVecIndex[k],src2DstMap[currentIndexSrc[elementPositionInGrid]][k].second )); 603 604 globaIndexWeightFromSrcToDst_tmp[rankSrc][globalSrcIndex].push_back(make_pair(globalDstVecIndex[k],src2DstMap[currentIndexSrc[elementPositionInGrid]][k].second )); 605 rankMapIt=rankMap.find(make_pair(globalSrcIndex,globalDstVecIndex[k])) ; 606 if (rankMapIt==rankMap.end()) rankMap[make_pair(globalSrcIndex,globalDstVecIndex[k])] = rankSrc ; 607 else if (rankSrc==clientRank) rankMapIt->second = rankSrc ; 454 608 } 455 609 ++idxLoop[0]; … … 458 612 } 459 613 } 614 615 // eliminate redondant global src point owned by differrent processes. 616 // Avoid as possible to tranfer data from an other process if the src point is also owned by current process 617 int rankSrc ; 618 size_t globalSrcIndex ; 619 size_t globalDstIndex ; 620 double weight ; 621 622 SourceDestinationIndexMap::iterator rankIt,rankIte ; 623 boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > >::iterator globalSrcIndexIt, globalSrcIndexIte ; 624 std::vector<std::pair<size_t,double> >::iterator vectIt,vectIte ; 625 626 rankIt=globaIndexWeightFromSrcToDst_tmp.begin() ; rankIte=globaIndexWeightFromSrcToDst_tmp.end() ; 627 for(;rankIt!=rankIte;++rankIt) 628 { 629 rankSrc = rankIt->first ; 630 globalSrcIndexIt = rankIt->second.begin() ; globalSrcIndexIte = rankIt->second.end() ; 631 for(;globalSrcIndexIt!=globalSrcIndexIte;++globalSrcIndexIt) 632 { 633 globalSrcIndex = globalSrcIndexIt->first ; 634 vectIt = globalSrcIndexIt->second.begin() ; vectIte = globalSrcIndexIt->second.end() ; 635 for(vectIt; vectIt!=vectIte; vectIt++) 636 { 637 globalDstIndex = vectIt->first ; 638 weight = vectIt->second ; 639 if (eliminateRedondantSrc_) 640 { 641 if (rankMap[make_pair(globalSrcIndex,globalDstIndex)] == rankSrc) 642 globaIndexWeightFromSrcToDst[rankSrc][globalSrcIndex].push_back(make_pair(globalDstIndex,weight)) ; 643 } 644 else globaIndexWeightFromSrcToDst[rankSrc][globalSrcIndex].push_back(make_pair(globalDstIndex,weight)) ; 645 } 646 } 647 } 648 460 649 } 461 650 … … 507 696 for (int idx = 0; idx < nIndexSize; ++idx) 508 697 { 509 globalIndex = axisSrc->index(idx); 510 globalIndex2ProcRank[globalIndex].push_back(clientRank); 698 if (axisSrc->mask(idx)) 699 { 700 globalIndex = axisSrc->index(idx); 701 globalIndex2ProcRank[globalIndex].push_back(clientRank); 702 } 511 703 } 512 704 … … 574 766 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; 575 767 globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); 768 576 769 if (destGlobalIndexPositionInGrid.isEmpty()) 577 770 { … … 581 774 j_ind=domainSrc->j_index(idx) ; 582 775 583 globalIndex = i_ind + j_ind * niGlobSrc; 584 globalIndex2ProcRank[globalIndex].resize(1); 585 globalIndex2ProcRank[globalIndex][0] = clientRank; 776 if (domainSrc->localMask(idx)) 777 { 778 globalIndex = i_ind + j_ind * niGlobSrc; 779 globalIndex2ProcRank[globalIndex].resize(1); 780 globalIndex2ProcRank[globalIndex][0] = clientRank; 781 } 586 782 } 587 783 } … … 590 786 for (int idx = 0; idx < nIndexSize; ++idx) 591 787 { 592 globalIndex2ProcRank[destGlobalIndexPositionInGrid(idx)].push_back(clientRank); 788 // if (domainSrc->localMask(idx)) -> not necessairy, mask seem to be included in destGlobalIndexPositionInGrid(idx) (ym) 789 globalIndex2ProcRank[destGlobalIndexPositionInGrid(idx)].push_back(clientRank); 593 790 } 594 791 } … … 647 844 } 648 845 } 846 847 848 849 850 851 852 void CGenericAlgorithmTransformation::computeTransformationMappingNonDistributed(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst, 853 vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, vector<bool>& localMaskOnGridDest) 854 { 855 856 CContext* context = CContext::getCurrent(); 857 CContextClient* client = context->client; 858 int nbClient = client->clientSize; 859 860 computePositionElements(gridDst, gridSrc); 861 std::vector<CScalar*> scalarListDstP = gridDst->getScalars(); 862 std::vector<CAxis*> axisListDstP = gridDst->getAxis(); 863 std::vector<CDomain*> domainListDstP = gridDst->getDomains(); 864 CArray<int,1> axisDomainDstOrder = gridDst->axis_domain_order; 865 std::vector<CScalar*> scalarListSrcP = gridSrc->getScalars(); 866 std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); 867 std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); 868 CArray<int,1> axisDomainSrcOrder = gridSrc->axis_domain_order; 869 870 int nElement=axisDomainSrcOrder.numElements() ; 871 int indSrc=1 ; 872 int indDst=1 ; 873 vector<int> nIndexSrc(nElement) ; 874 vector<int> nIndexDst(nElement) ; 875 vector< CArray<bool,1>* > maskSrc(nElement) ; 876 vector< CArray<bool,1>* > maskDst(nElement) ; 877 878 int nlocalIndexSrc=1 ; 879 int nlocalIndexDest=1 ; 880 CArray<bool,1> maskScalar(1) ; 881 maskScalar = true ; 882 883 884 for(int i=0 ; i<nElement; i++) 885 { 886 int dimElement = axisDomainSrcOrder(i); 887 if (2 == dimElement) //domain 888 { 889 CDomain* domain=domainListSrcP[elementPositionInGridSrc2DomainPosition_[i]] ; 890 nIndexSrc[i] = domain->i_index.numElements() ; 891 maskSrc[i]=&domain->localMask ; 892 } 893 else if (1 == dimElement) //axis 894 { 895 CAxis* axis=axisListSrcP[elementPositionInGridSrc2AxisPosition_[i]] ; 896 nIndexSrc[i] = axis->index.numElements() ; 897 maskSrc[i]=&axis->mask ; 898 } 899 else //scalar 900 { 901 nIndexSrc[i]=1 ; 902 maskSrc[i]=&maskScalar ; 903 } 904 nlocalIndexSrc=nlocalIndexSrc*nIndexSrc[i] ; 905 } 906 907 908 909 int offset=1 ; 910 for(int i=0 ; i<nElement; i++) 911 { 912 int dimElement = axisDomainDstOrder(i); 913 if (2 == dimElement) //domain 914 { 915 CDomain* domain=domainListDstP[elementPositionInGridDst2DomainPosition_[i]] ; 916 int nIndex=domain->i_index.numElements() ; 917 CArray<bool,1>& localMask=domain->localMask ; 918 int nbInd=0 ; 919 for(int j=0;j<nIndex;j++) if (localMask(j)) nbInd++ ; 920 nIndexDst[i] = nbInd ; 921 maskDst[i]=&domain->localMask ; 922 } 923 else if (1 == dimElement) //axis 924 { 925 CAxis* axis = axisListDstP[elementPositionInGridDst2AxisPosition_[i]] ; 926 int nIndex=axis->index.numElements() ; 927 CArray<bool,1>& localMask=axis->mask ; 928 int nbInd=0 ; 929 for(int j=0;j<nIndex;j++) if (localMask(j)) nbInd++ ; 930 nIndexDst[i] = nbInd ; 931 maskDst[i]=&axis->mask ; 932 } 933 else //scalar 934 { 935 nIndexDst[i]=1 ; 936 maskDst[i]=&maskScalar ; 937 } 938 if (i<elementPositionInGrid) offset=offset*nIndexDst[i] ; 939 nlocalIndexDest=nlocalIndexDest*nIndexDst[i] ; 940 } 941 942 943 944 945 946 947 vector<int> dstLocalInd ; 948 int dimElement = axisDomainDstOrder(elementPositionInGrid); 949 if (2 == dimElement) //domain 950 { 951 CDomain* domain = domainListDstP[elementPositionInGridDst2DomainPosition_[elementPositionInGrid]] ; 952 int ni_glo=domain->ni_glo ; 953 int nj_glo=domain->nj_glo ; 954 int nindex_glo=ni_glo*nj_glo ; 955 dstLocalInd.resize(nindex_glo,-1) ; 956 int nIndex=domain->i_index.numElements() ; 957 CArray<bool,1>& localMask=domain->localMask ; 958 int unmaskedInd=0 ; 959 int globIndex ; 960 for(int i=0;i<nIndex;i++) 961 { 962 if (localMask(i)) 963 { 964 globIndex=domain->j_index(i)*ni_glo+domain->i_index(i) ; 965 dstLocalInd[globIndex]=unmaskedInd ; 966 unmaskedInd++ ; 967 } 968 } 969 } 970 else if (1 == dimElement) //axis 971 { 972 CAxis* axis = axisListDstP[elementPositionInGridDst2AxisPosition_[elementPositionInGrid]] ; 973 int nindex_glo=axis->n_glo ; 974 dstLocalInd.resize(nindex_glo,-1) ; 975 int nIndex=axis->index.numElements() ; 976 CArray<bool,1>& localMask=axis->mask ; // axis mask must include later data_index 977 int unmaskedInd=0 ; 978 for(int i=0;i<nIndex;i++) 979 { 980 if (localMask(i)) 981 { 982 dstLocalInd[axis->index(i)]=unmaskedInd ; 983 unmaskedInd++ ; 984 } 985 } 986 } 987 else //scalar 988 { 989 dstLocalInd.resize(1) ; 990 dstLocalInd[0]=0 ; 991 } 992 993 // just get the local src mask 994 CArray<bool,1> localMaskOnSrcGrid; 995 gridSrc->getLocalMask(localMaskOnSrcGrid) ; 996 // intermediate grid, mask is not initialized => set up mask to true 997 if (localMaskOnSrcGrid.isEmpty()) 998 { 999 localMaskOnSrcGrid.resize(nlocalIndexSrc) ; 1000 localMaskOnSrcGrid=true ; 1001 } 1002 1003 1004 localMaskOnGridDest.resize(nlocalIndexDest,false) ; 1005 1006 vector<vector<vector<pair<int,double> > > > dstIndWeight(transformationMapping_.size()) ; 1007 1008 for(int t=0;t<transformationMapping_.size();++t) 1009 { 1010 TransformationIndexMap::const_iterator itTransMap = transformationMapping_[t].begin(), 1011 iteTransMap = transformationMapping_[t].end(); 1012 TransformationWeightMap::const_iterator itTransWeight = transformationWeight_[t].begin(); 1013 dstIndWeight[t].resize(nIndexSrc[elementPositionInGrid]) ; 1014 1015 for(;itTransMap!=iteTransMap;++itTransMap,++itTransWeight) 1016 { 1017 int dst=dstLocalInd[itTransMap->first] ; 1018 if (dst!=-1) 1019 { 1020 const vector<int>& srcs=itTransMap->second; 1021 const vector<double>& weights=itTransWeight->second; 1022 for(int i=0;i<srcs.size() ;i++) dstIndWeight[t][srcs[i]].push_back(pair<int,double>(dst*offset+t,weights[i])) ; 1023 } 1024 } 1025 } 1026 int srcInd=0 ; 1027 int currentInd ; 1028 int t=0 ; 1029 int srcIndCompressed=0 ; 1030 1031 nonDistributedrecursiveFunct(nElement-1,true,elementPositionInGrid,maskSrc,maskDst, srcInd, srcIndCompressed, nIndexSrc, t, dstIndWeight, 1032 currentInd,localSrc,localDst,weight, localMaskOnSrcGrid, localMaskOnGridDest ); 1033 1034 } 1035 1036 1037 void CGenericAlgorithmTransformation::nonDistributedrecursiveFunct(int currentPos, bool masked, int elementPositionInGrid, vector< CArray<bool,1>* >& maskSrc, vector< CArray<bool,1>* >& maskDst, int& srcInd, int& srcIndCompressed, vector<int>& nIndexSrc, int& t, vector<vector<vector<pair<int,double> > > >& dstIndWeight, int currentInd, 1038 vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, CArray<bool,1>& localMaskOnGridSrc, vector<bool>& localMaskOnGridDest ) 1039 { 1040 int masked_ ; 1041 if (currentPos!=elementPositionInGrid) 1042 { 1043 if (currentPos!=0) 1044 { 1045 CArray<bool,1>& mask = *maskSrc[currentPos] ; 1046 1047 for(int i=0;i<nIndexSrc[currentPos];i++) 1048 { 1049 masked_=masked ; 1050 if (!mask(i)) masked_=false ; 1051 nonDistributedrecursiveFunct(currentPos-1, masked_, elementPositionInGrid, maskSrc, maskDst, srcInd, srcIndCompressed, nIndexSrc, t, dstIndWeight, currentInd, localSrc, localDst, weight, localMaskOnGridSrc, localMaskOnGridDest) ; 1052 } 1053 } 1054 else 1055 { 1056 CArray<bool,1>& mask = *maskSrc[currentPos] ; 1057 for(int i=0;i<nIndexSrc[currentPos];i++) 1058 { 1059 if (masked && mask(i)) 1060 { 1061 if (dstIndWeight[t][currentInd].size()>0) 1062 { 1063 for(vector<pair<int,double> >::iterator it = dstIndWeight[t][currentInd].begin(); it!=dstIndWeight[t][currentInd].end(); ++it) 1064 { 1065 if (localMaskOnGridSrc(srcInd)) 1066 { 1067 localSrc.push_back(srcIndCompressed) ; 1068 localDst.push_back(it->first) ; 1069 weight.push_back(it->second) ; 1070 localMaskOnGridDest[it->first]=true ; 1071 } 1072 (it->first)++ ; 1073 } 1074 } 1075 if (t < dstIndWeight.size()-1) t++ ; 1076 if (localMaskOnGridSrc(srcInd)) srcIndCompressed ++ ; 1077 } 1078 srcInd++ ; 1079 } 1080 } 1081 } 1082 else 1083 { 1084 1085 if (currentPos!=0) 1086 { 1087 1088 CArray<bool,1>& mask = *maskSrc[currentPos] ; 1089 for(int i=0;i<nIndexSrc[currentPos];i++) 1090 { 1091 t=0 ; 1092 masked_=masked ; 1093 if (!mask(i)) masked_=false ; 1094 nonDistributedrecursiveFunct(currentPos-1, masked_, elementPositionInGrid, maskSrc, maskDst, srcInd, srcIndCompressed, nIndexSrc, t, dstIndWeight , i, localSrc, localDst, weight, localMaskOnGridSrc, localMaskOnGridDest) ; 1095 } 1096 } 1097 else 1098 { 1099 for(int i=0;i<nIndexSrc[currentPos];i++) 1100 { 1101 if (masked) 1102 { 1103 t=0 ; 1104 if (dstIndWeight[t][i].size()>0) 1105 { 1106 for(vector<pair<int,double> >::iterator it = dstIndWeight[t][i].begin(); it!=dstIndWeight[t][i].end(); ++it) 1107 { 1108 if (localMaskOnGridSrc(srcInd)) 1109 { 1110 localSrc.push_back(srcIndCompressed) ; 1111 localDst.push_back(it->first) ; 1112 weight.push_back(it->second) ; 1113 localMaskOnGridDest[it->first]=true ; 1114 } 1115 (it->first)++ ; 1116 } 1117 } 1118 if (t < dstIndWeight.size()-1) t++ ; 1119 if (localMaskOnGridSrc(srcInd)) srcIndCompressed ++ ; 1120 } 1121 srcInd++ ; 1122 } 1123 } 1124 } 1125 1126 } 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 649 1137 650 1138 /*! -
XIOS/dev/branch_openmp/src/transformation/generic_algorithm_transformation.hpp
r1328 r1460 52 52 virtual ~CGenericAlgorithmTransformation() {} 53 53 54 bool isDistributedTransformation(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst) ; 55 54 56 void computeGlobalSourceIndex(int elementPositionInGrid, 55 57 CGrid* gridSrc, … … 85 87 */ 86 88 void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >()); 89 void computeTransformationMappingNonDistributed(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst, 90 vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, vector<bool>& localMaskOnGridDest); 91 void nonDistributedrecursiveFunct(int currentPos, bool masked, int elementPositionInGrid, vector< CArray<bool,1>* >& maskSrc, vector< CArray<bool,1>* >& maskDst, int& srcInd, int& srcIndCompressed, vector<int>& nIndexSrc, int& t, vector<vector<vector<pair<int,double> > > >& dstIndWeight, int currentInd, 92 vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, CArray<bool,1>& localMaskOnGridSrc, vector<bool>& localMaskOnGridDest) ; 87 93 88 94 protected: … … 126 132 127 133 protected: 134 //! indicate if the transformation is performed on a distributed element 135 bool isDistributed_ ; 136 //! indicate if the method isDistributedTransformation has been called before 137 bool isDistributedComputed_ ; 138 128 139 //! Map between global index of destination element and source element 129 140 std::vector<TransformationIndexMap> transformationMapping_; … … 138 149 AlgoTransType type_; 139 150 151 std::set<StdSize> indexElementSrc_; 152 153 std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_; 154 155 std::vector<int> procContainSrcElementIdx_; // List of processes containing source index of transformed elements 156 // std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements 157 std::set<int> commonProc_; 158 std::vector< set<int> > procElementList_ ; // List of processes containing source index of elements 159 160 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc_; 161 162 bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements 163 140 164 std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_; 141 165 std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_; 166 167 bool eliminateRedondantSrc_ ; // flag to indicate if the transformation must select only one global source point for all proc. 168 // In this case it will choose preferentially the current process 142 169 }; 143 170 -
XIOS/dev/branch_openmp/src/transformation/grid_transformation.cpp
r1328 r1460 16 16 #include "grid.hpp" 17 17 #include <boost/unordered_map.hpp> 18 #include "timer.hpp" 18 19 19 20 namespace xios { … … 385 386 (CGenericAlgorithmTransformation::ELEMENT_MODIFICATION_WITH_DATA == algo->type()))) // Only registered transformation can be executed 386 387 { 388 CTimer::get("computeIndexSourceMapping").resume() ; 387 389 algo->computeIndexSourceMapping(dataAuxInputs); 388 390 CTimer::get("computeIndexSourceMapping").suspend() ; 391 389 392 // ComputeTransformation of global index of each element 390 393 int elementPosition = it->first; 391 algo->computeGlobalSourceIndex(elementPosition, 392 gridSource_, 393 tmpGridDestination_, 394 globaIndexWeightFromSrcToDst); 395 396 // Compute transformation of global indexes among grids 397 computeTransformationMapping(globaIndexWeightFromSrcToDst); 398 394 bool nonDistributedActivated = CXios::getin<bool>("activate_non_distributed_transformation",false); 395 396 if (nonDistributedActivated && !algo->isDistributedTransformation(elementPositionInGrid, gridSource_, tmpGridDestination_) ) 397 { 398 vector<int> localSrc ; 399 vector<int> localDst ; 400 vector<double> weight ; 401 localMaskOnGridDest_.push_back(vector<bool>()) ; 402 CTimer::get("computeTransformationMappingNonDistributed").resume(); 403 algo->computeTransformationMappingNonDistributed(elementPosition, gridSource_, tmpGridDestination_, 404 localSrc, localDst, weight, localMaskOnGridDest_.back()) ; 405 CTimer::get("computeTransformationMappingNonDistributed").suspend(); 406 407 CTimer::get("computeTransformationMappingConvert").resume(); 408 nbLocalIndexOnGridDest_.push_back(localMaskOnGridDest_.back().size()) ; 409 int clientRank=client->clientRank ; 410 { 411 SendingIndexGridSourceMap tmp; 412 localIndexToSendFromGridSource_.push_back(tmp) ; 413 SendingIndexGridSourceMap& src=localIndexToSendFromGridSource_.back() ; 414 CArray<int,1> arrayTmp ; 415 src.insert( pair<int,CArray<int,1> >(clientRank,arrayTmp)) ; 416 CArray<int,1>& array=src[clientRank] ; 417 array.resize(localSrc.size()) ; 418 for(int i=0;i< localSrc.size();++i) array(i)=localSrc[i] ; 419 } 420 { 421 RecvIndexGridDestinationMap tmp; 422 localIndexToReceiveOnGridDest_.push_back(tmp) ; 423 RecvIndexGridDestinationMap& dst=localIndexToReceiveOnGridDest_.back() ; 424 vector<pair<int,double> > vectTmp ; 425 dst.insert( pair<int,vector<pair<int,double> > >(clientRank,vectTmp)) ; 426 vector<pair<int,double> >& vect=dst[clientRank] ; 427 vect.resize(localDst.size()) ; 428 for(int i=0;i< localDst.size();++i) vect[i]=pair<int,double>(localDst[i],weight[i]) ; 429 } 430 CTimer::get("computeTransformationMappingConvert").suspend(); 431 } 432 else 433 { 434 CTimer::get("computeGlobalSourceIndex").resume(); 435 algo->computeGlobalSourceIndex(elementPosition, 436 gridSource_, 437 tmpGridDestination_, 438 globaIndexWeightFromSrcToDst); 439 440 CTimer::get("computeGlobalSourceIndex").suspend(); 441 CTimer::get("computeTransformationMapping").resume(); 442 // Compute transformation of global indexes among grids 443 computeTransformationMapping(globaIndexWeightFromSrcToDst); 444 CTimer::get("computeTransformationMapping").suspend(); 445 } 399 446 if (1 < nbNormalAlgos_) 400 447 { -
XIOS/dev/branch_openmp/src/transformation/grid_transformation_selector.cpp
r1328 r1460 23 23 CScalarAlgorithmExtractAxis::registerTrans(); 24 24 CScalarAlgorithmReduceDomain::registerTrans(); 25 CScalarAlgorithmReduceScalar::registerTrans(); 25 26 26 27 //! Axis … … 30 31 CAxisAlgorithmInverse::registerTrans(); 31 32 CAxisAlgorithmReduceDomain::registerTrans(); 33 CAxisAlgorithmReduceAxis::registerTrans(); 34 CAxisAlgorithmTemporalSplitting::registerTrans(); 35 CAxisAlgorithmDuplicateScalar::registerTrans(); 32 36 33 37 //! Domain … … 36 40 CDomainAlgorithmZoom::registerTrans(); 37 41 CDomainAlgorithmExpand::registerTrans(); 42 CDomainAlgorithmReorder::registerTrans(); 38 43 } 39 44 -
XIOS/dev/branch_openmp/src/transformation/grid_transformation_selector.hpp
r1328 r1460 52 52 const std::vector<StdString>& getAuxInputs() const { return auxInputs_; } 53 53 const std::vector<CGenericAlgorithmTransformation*>& getAlgos() const { return algoTransformation_; } 54 const std::map<int, int> getElementPositionInGridSrc2AxisPosition() const { return elementPositionInGridSrc2AxisPosition_ ;} 55 const std::map<int, int> getElementPositionInGridSrc2DomainPosition() const { return elementPositionInGridSrc2DomainPosition_ ;} 56 const std::map<int, int> getElementPositionInGridSrc2ScalarPosition() const { return elementPositionInGridSrc2ScalarPosition_ ;} 57 const std::map<int, int> getElementPositionInGridDst2AxisPosition() const { return elementPositionInGridDst2AxisPosition_ ;} 58 const std::map<int, int> getElementPositionInGridDst2DomainPosition() const { return elementPositionInGridDst2DomainPosition_ ;} 59 const std::map<int, int> getElementPositionInGridDst2ScalarPosition() const { return elementPositionInGridDst2ScalarPosition_ ;} 60 54 61 55 62 protected: -
XIOS/dev/branch_openmp/src/transformation/scalar_algorithm_extract_axis.cpp
r1339 r1460 14 14 #include "grid_transformation_factory_impl.hpp" 15 15 16 //#include "reduction.hpp" 16 17 17 18 namespace xios { -
XIOS/dev/branch_openmp/src/transformation/scalar_algorithm_reduce_axis.cpp
r1341 r1460 13 13 #include "grid.hpp" 14 14 #include "grid_transformation_factory_impl.hpp" 15 //#include "reduction.hpp" 16 15 17 16 18 namespace xios { -
XIOS/dev/branch_openmp/src/transformation/scalar_algorithm_reduce_domain.cpp
r1339 r1460 14 14 #include "grid_transformation_factory_impl.hpp" 15 15 16 //#include "reduction.hpp" 16 17 17 18 namespace xios { … … 45 46 reduction_(0) 46 47 { 48 algo->checkValid(scalarDestination, domainSource); 49 47 50 StdString op; 48 51 switch (algo->operation) … … 82 85 //reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]); 83 86 reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations_ptr->at(op)); 87 local = algo->local ; 84 88 } 85 89 … … 111 115 TransformationWeightMap& transWeight = this->transformationWeight_[0]; 112 116 113 int globalIndexSize = domainSrc_->ni_glo * domainSrc_->nj_glo; 117 int ni_glo = domainSrc_->ni_glo ; 118 int nj_glo = domainSrc_->nj_glo ; 119 int nbDomainIdx ; 120 121 if (local) 122 { 123 const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; 124 const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; 125 const CArray<bool,1>& localMask = domainSrc_-> localMask ; 126 int nbDomainIdx = i_index.numElements(); 114 127 115 transMap[0].resize(globalIndexSize); 116 transWeight[0].resize(globalIndexSize, 1.0); 117 for (int idx = 0; idx < globalIndexSize; ++idx) 118 { 119 transMap[0][idx] = idx; 128 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) 129 { 130 if (localMask(idxDomain)) 131 { 132 transMap[0].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); 133 transWeight[0].push_back(1.0) ; 134 } 135 } 120 136 } 137 else 138 { 139 nbDomainIdx = ni_glo * nj_glo; 140 transMap[0].resize(nbDomainIdx); 141 transWeight[0].resize(nbDomainIdx, 1.0); 142 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) transMap[0][idxDomain] = idxDomain; 143 } 144 121 145 } 122 146 -
XIOS/dev/branch_openmp/src/transformation/scalar_algorithm_reduce_domain.hpp
r1339 r1460 42 42 static bool registerTrans(); 43 43 protected: 44 bool local ; 44 45 void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs); 45 46 -
XIOS/dev/branch_openmp/src/transformation/scalar_algorithm_transformation.cpp
r976 r1460 70 70 CArray<int,1>& jIndex = domainSrc_->j_index; 71 71 int niGlo = domainSrc_->ni_glo; 72 72 CArray<bool,1>& localMask = domainSrc_ -> localMask ; 73 73 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; 74 74 globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); 75 75 for (int idx = 0; idx < nIndexSize; ++idx) 76 76 { 77 globalIndex = jIndex(idx) * niGlo + iIndex(idx); 78 globalIndex2ProcRank[globalIndex].resize(1); 79 globalIndex2ProcRank[globalIndex][0] = clientRank; 77 if (localMask(idx)) 78 { 79 globalIndex = jIndex(idx) * niGlo + iIndex(idx); 80 globalIndex2ProcRank[globalIndex].resize(1); 81 globalIndex2ProcRank[globalIndex][0] = clientRank; 82 } 80 83 } 81 84 … … 90 93 CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank; 91 94 globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor())); 95 CArray<bool,1>& localMask = axisSrc_ -> mask ; 96 92 97 for (int idx = 0; idx < nIndexSize; ++idx) 93 98 { 94 globalIndex = axisSrc_->index(idx); 95 globalIndex2ProcRank[globalIndex].resize(1); 96 globalIndex2ProcRank[globalIndex][0] = clientRank; 99 if (localMask(idx)) 100 { 101 globalIndex = axisSrc_->index(idx); 102 globalIndex2ProcRank[globalIndex].resize(1); 103 globalIndex2ProcRank[globalIndex][0] = clientRank; 104 } 97 105 } 98 106
Note: See TracChangeset
for help on using the changeset viewer.