Changeset 2291
- Timestamp:
- 02/01/22 15:28:48 (2 years ago)
- Location:
- XIOS/dev/dev_ym/XIOS_COUPLING/src
- Files:
-
- 2 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/config/reduce_axis_to_scalar_attribute.conf
r980 r2291 1 1 DECLARE_ENUM4(operation, min, max, sum, average) 2 DECLARE_ATTRIBUTE(bool, local) 2 3 3 4 5 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.hpp
r2267 r2291 9 9 #include "distributed_view.hpp" 10 10 #include "context_client.hpp" 11 #include "reduction_types.hpp" 11 12 12 13 … … 29 30 30 31 template<typename T> 31 void transfer(int repeat, int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut )32 void transfer(int repeat, int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none) 32 33 { 33 34 // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 35 34 36 size_t dstSlice = dstSize_*sizeT ; 35 37 dataOut.resize(repeat* dstSlice) ; 36 38 37 for(auto& data : dataIn) 38 { 39 40 if (op == EReduction::none) // tranfer without reduction 41 { 42 for(auto& data : dataIn) 43 { 44 T* output = dataOut.dataFirst() ; 45 int rank=data.first ; 46 auto input = data.second.dataFirst() ; 47 auto& connector=connector_[rank] ; 48 auto& mask=mask_[rank] ; 49 int size=mask.size() ; 50 size_t srcSlice = size * sizeT ; 51 for(int l=0; l<repeat; l++) 52 { 53 for(int i=0, j=0 ;i<size;i++) 54 { 55 if (mask[i]) 56 { 57 int cj = connector[j]*sizeT ; 58 int ci = i*sizeT ; 59 for (int k=0;k<sizeT;k++) output[cj+k] = input[ci+k] ; 60 j++ ; 61 } 62 } 63 input+=srcSlice ; 64 output+=dstSlice ; 65 } 66 } 67 } 68 else // with reduction, to be optimized, see how to vectorize 69 { 70 vector<int> vcount(dataOut.size(),0) ; 71 int* count = vcount.data() ; 72 T defaultValue = std::numeric_limits<T>::quiet_NaN(); 73 for(auto& data : dataIn) 74 { 75 T* output = dataOut.dataFirst() ; 76 int rank=data.first ; 77 auto input = data.second.dataFirst() ; 78 auto& connector=connector_[rank] ; 79 auto& mask=mask_[rank] ; 80 int size=mask.size() ; 81 size_t srcSlice = size * sizeT ; 82 for(int l=0; l<repeat; l++) 83 { 84 for(int i=0, j=0 ;i<size;i++) 85 { 86 if (mask[i]) 87 { 88 int cj = connector[j]*sizeT ; 89 int ci = i*sizeT ; 90 for (int k=0;k<sizeT;k++) 91 { 92 if (!std::isnan(input[ci+k])) // manage missing value 93 { 94 if (count[cj+k]==0) output[cj+k] = input[ci+k] ; 95 else 96 { 97 switch(op) 98 { 99 case EReduction::sum : 100 output[cj+k] += input[ci+k] ; 101 break ; 102 case EReduction::min : 103 output[cj+k]= std::min(output[cj+k],input[ci+k]) ; 104 break ; 105 case EReduction::max : 106 output[cj+k]= std::max(output[cj+k],input[ci+k]) ; 107 break ; 108 case EReduction::average : 109 output[cj+k] += input[ci+k] ; 110 break ; 111 default : 112 ERROR("CGathererConnector::transfer", 113 <<"reduction operator "<<(int)op<<" is not defined for this operation") ; 114 break ; 115 } 116 } 117 count[cj+k]++ ; 118 } 119 } 120 j++ ; 121 } 122 } 123 input+=srcSlice ; 124 output+=dstSlice ; 125 count+=dstSlice ; 126 } 127 } 128 39 129 T* output = dataOut.dataFirst() ; 40 int rank=data.first ; 41 auto input = data.second.dataFirst() ; 42 auto& connector=connector_[rank] ; 43 auto& mask=mask_[rank] ; 44 int size=mask.size() ; 45 size_t srcSlice = size * sizeT ; 46 for(int l=0; l<repeat; l++) 47 { 48 for(int i=0, j=0 ;i<size;i++) 49 { 50 if (mask[i]) 51 { 52 int cj = connector[j]*sizeT ; 53 int ci = i*sizeT ; 54 for (int k=0;k<sizeT;k++) output[cj+k] = input[ci+k] ; 55 j++ ; 56 } 57 } 58 input+=srcSlice ; 59 output+=dstSlice ; 60 } 61 } 62 } 63 64 template<typename T> 65 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 66 { 67 transfer(1, sizeT, dataIn, dataOut) ; 130 if (op==EReduction::average) 131 for(int i=0; i < dataOut.size() ; i++) 132 { 133 if (count[i]>0) dataOut[i]/=count[i] ; 134 else dataOut[i] = defaultValue ; 135 } 136 else for(int i=0; i < dataOut.size() ; i++) if (count[i]==0) dataOut[i] = defaultValue ; 137 } 138 } 139 140 template<typename T> 141 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none) 142 { 143 transfer(1, sizeT, dataIn, dataOut, op) ; 68 144 } 69 145 70 146 template<typename T> 71 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut )72 { 73 transfer(1,dataIn,dataOut ) ;74 } 75 76 template<typename T> 77 void transfer(int rank, shared_ptr<CGathererConnector>* connectors, int nConnectors, const T* input, T* output )147 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none) 148 { 149 transfer(1,dataIn,dataOut, op) ; 150 } 151 152 template<typename T> 153 void transfer(int rank, shared_ptr<CGathererConnector>* connectors, int nConnectors, const T* input, T* output, EReduction op = EReduction::none, int* count=nullptr) 78 154 { 79 155 auto& connector = connector_[rank] ; // probably costly, find a better way to avoid the map … … 83 159 if (nConnectors==0) 84 160 { 85 for(int i=0, j=0; i<srcSize; i++) 86 if (mask[i]) 87 { 88 *(output+connector[j]) = *(input + i) ; 89 j++ ; 90 } 161 if (op == EReduction::none) 162 { 163 for(int i=0, j=0; i<srcSize; i++) 164 if (mask[i]) 165 { 166 *(output+connector[j]) = *(input + i) ; 167 j++ ; 168 } 169 } 170 else 171 { 172 switch(op) 173 { 174 case EReduction::sum : 175 for(int i=0, j=0; i<srcSize; i++) 176 if (mask[i]) 177 { 178 if (!std::isnan(*(input + i))) 179 { 180 if (*(count+connector[j])==0) *(output+connector[j]) = *(input + i) ; 181 else *(output+connector[j]) += *(input + i) ; 182 (*(count+connector[j]))++ ; 183 } 184 j++ ; 185 } 186 break ; 187 case EReduction::min : 188 for(int i=0, j=0; i<srcSize; i++) 189 if (mask[i]) 190 { 191 if (!std::isnan(*(input + i))) 192 { 193 if (*(count+connector[j])==0) *(output+connector[j]) = *(input + i) ; 194 else *(output+connector[j]) = std::min(*(output+connector[j]),*(input + i)) ; 195 (*(count+connector[j]))++ ; 196 } 197 j++ ; 198 } 199 break ; 200 case EReduction::max : 201 for(int i=0, j=0; i<srcSize; i++) 202 if (mask[i]) 203 { 204 if (!std::isnan(*(input + i))) 205 { 206 if (*(count+connector[j])==0) *(output+connector[j]) = *(input + i) ; 207 else *(output+connector[j]) = std::max(*(output+connector[j]),*(input + i)) ; 208 (*(count+connector[j]))++ ; 209 } 210 j++ ; 211 } 212 break ; 213 case EReduction::average : 214 for(int i=0, j=0; i<srcSize; i++) 215 if (mask[i]) 216 { 217 if (!std::isnan(*(input + i))) 218 { 219 if (*(count+connector[j])==0) *(output+connector[j]) = *(input + i) ; 220 else *(output+connector[j]) += *(input + i) ; 221 (*(count+connector[j]))++ ; 222 } 223 j++ ; 224 } 225 break ; 226 default : 227 ERROR("CGathererConnector::transfer", 228 <<"reduction operator "<<(int)op<<" is not defined for this operation") ; 229 break ; 230 } 231 } 91 232 92 233 } … … 101 242 if (mask[i]) 102 243 { 103 (*(connectors-1))->transfer(rank, connectors-1, nConnectors-1, in, output+connector[j]*dstSliceSize ) ; // the multiplication must be avoid in further optimization244 (*(connectors-1))->transfer(rank, connectors-1, nConnectors-1, in, output+connector[j]*dstSliceSize, op, count+connector[j]*dstSliceSize) ; // the multiplication must be avoid in further optimization 104 245 j++ ; 105 246 } … … 149 290 150 291 template<typename T> 151 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue )152 { 153 transfer(1, 1, dataIn, dataOut, missingValue );154 } 155 156 template<typename T> 157 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue )158 { 159 transfer(1, sizeT, dataIn, dataOut, missingValue ) ;160 } 161 162 template<typename T> 163 void transfer(int repeat , int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue )292 void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue, EReduction op = EReduction::none) 293 { 294 transfer(1, 1, dataIn, dataOut, missingValue, op); 295 } 296 297 template<typename T> 298 void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue, EReduction op = EReduction::none) 299 { 300 transfer(1, sizeT, dataIn, dataOut, missingValue, op) ; 301 } 302 303 template<typename T> 304 void transfer(int repeat , int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue, EReduction op = EReduction::none) 164 305 { 165 306 dataOut.resize(repeat*dstSize_*sizeT) ; 166 307 dataOut=missingValue ; 167 transfer(repeat, sizeT, dataIn, dataOut ) ;168 } 169 170 template<typename T> 171 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut )308 transfer(repeat, sizeT, dataIn, dataOut, op) ; 309 } 310 311 template<typename T> 312 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, EReduction op = EReduction::none) 172 313 { 173 314 map<int, CArray<T,1>> dataIn ; … … 177 318 (*subEvent.buffer) >> data ; 178 319 } 179 transfer(1, sizeT, dataIn, dataOut ) ;180 } 181 182 template<typename T> 183 void transfer(CEventServer& event, CArray<T,1>& dataOut )184 { 185 transfer(event, 1, dataOut ) ;186 } 187 188 template<typename T> 189 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, T missingValue )320 transfer(1, sizeT, dataIn, dataOut, op) ; 321 } 322 323 template<typename T> 324 void transfer(CEventServer& event, CArray<T,1>& dataOut, EReduction op = EReduction::none) 325 { 326 transfer(event, 1, dataOut, op) ; 327 } 328 329 template<typename T> 330 void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, T missingValue, EReduction op = EReduction::none) 190 331 { 191 332 map<int, CArray<T,1>> dataIn ; … … 195 336 (*subEvent.buffer) >> data ; 196 337 } 197 transfer(1, sizeT, dataIn, dataOut, missingValue ) ;198 } 199 200 template<typename T> 201 void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue )338 transfer(1, sizeT, dataIn, dataOut, missingValue, op) ; 339 } 340 341 template<typename T> 342 void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue, EReduction op = EReduction::none) 202 343 { 203 344 map<int, CArray<T,1>> dataIn ; … … 207 348 (*subEvent.buffer) >> data ; 208 349 } 209 transfer(1, 1, dataIn, dataOut, missingValue ) ;350 transfer(1, 1, dataIn, dataOut, missingValue, op) ; 210 351 } 211 352 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_gatherer_connector.hpp
r2267 r2291 10 10 #include "context_client.hpp" 11 11 #include "gatherer_connector.hpp" 12 #include "reduction_types.hpp" 12 13 13 14 … … 30 31 31 32 template<typename T> 32 void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output )33 void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output, EReduction op = EReduction::none) 33 34 { 34 35 int n = elementsConnector_.size()-1 ; 35 shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;36 shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ; 36 37 output.resize(dstSize_) ; 37 for(auto& rankDataIn : input) 38 39 if (op == EReduction::none) 40 for(auto& rankDataIn : input) 41 elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ; 42 else 38 43 { 39 elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ; 44 T defaultValue = std::numeric_limits<T>::quiet_NaN(); 45 vector<int> count(dstSize_,0) ; 46 for(auto& rankDataIn : input) 47 elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst(), op, count.data()) ; 48 49 for(int i=0;i<dstSize_;i++) if (count[i]==0) output(i)=defaultValue ; 40 50 } 41 51 } … … 55 65 56 66 template<typename T> 57 void transfer(CEventServer& event, CArray<T,1>& dataOut )67 void transfer(CEventServer& event, CArray<T,1>& dataOut, EReduction op = EReduction::none) 58 68 { 59 69 map<int, CArray<T,1>> dataIn ; … … 63 73 (*subEvent.buffer) >> data ; 64 74 } 65 transfer(dataIn, dataOut ) ;75 transfer(dataIn, dataOut, op) ; 66 76 } 67 77 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_remote_connector.cpp
r2267 r2291 114 114 * some redondant ranks can be removed from the elements_ map. 115 115 */ 116 void CGridRemoteConnector::computeConnector(void) 117 { 118 computeViewDistribution() ; 119 computeConnectorMethods() ; 120 computeRedondantRanks() ; 121 for(auto& rank : rankToRemove_) 122 for(auto& element : elements_) element.erase(rank) ; 123 } 116 void CGridRemoteConnector::computeConnector(bool eliminateRedundant) 117 { 118 if (eliminateRedundant) 119 { 120 computeViewDistribution() ; 121 computeConnectorMethods() ; 122 computeRedondantRanks() ; 123 for(auto& rank : rankToRemove_) 124 for(auto& element : elements_) element.erase(rank) ; 125 } 126 else 127 { 128 computeViewDistribution() ; 129 computeConnectorRedundant() ; 130 } 131 } 132 133 /** 134 * \brief Compute the connector, i.e. compute the \b elements_ attribute. 135 * \detail In this routine we don't eliminate redundant cells as it it performed in 136 * computeConnectorMethods. It can be usefull to perform reduce operation over processes. 137 In future, some optimisation could be done considering full redondance of the 138 source view or the destination view. 139 */ 140 void CGridRemoteConnector::computeConnectorRedundant(void) 141 { 142 vector<shared_ptr<CLocalView>> srcView ; 143 vector<shared_ptr<CDistributedView>> dstView ; 144 vector<int> indElements ; 145 elements_.resize(srcView_.size()) ; 146 147 bool srcViewsNonDistributed=true ; // not usefull now but later for optimization 148 for(int i=0;i<srcView_.size();i++) srcViewsNonDistributed = srcViewsNonDistributed && !isSrcViewDistributed_[i] ; 149 150 bool dstViewsNonDistributed=true ; // not usefull now but later for optimization 151 for(int i=0;i<dstView_.size();i++) dstViewsNonDistributed = dstViewsNonDistributed && !isDstViewDistributed_[i] ; 152 153 for(int i=0;i<srcView_.size();i++) 154 { 155 srcView.push_back(srcView_[i]) ; 156 dstView.push_back(dstView_[i]) ; 157 indElements.push_back(i) ; 158 } 159 160 computeGenericMethod(srcView, dstView, indElements) ; 161 162 map<int,bool> ranks ; 163 for(auto& it : elements_[indElements[0]]) 164 { 165 if (it.second.numElements()==0) ranks[it.first] = false ; 166 else ranks[it.first] = true ; 167 } 168 169 } 170 171 124 172 /** 125 173 * \brief Compute the connector, i.e. compute the \b elements_ attribute. … … 426 474 } 427 475 428 476 429 477 /** 430 478 * \brief Generic method the compute the grid remote connector. Only distributed elements are specifed in the source view and remote view. … … 650 698 } 651 699 } 652 700 653 701 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_remote_connector.hpp
r2267 r2291 21 21 CGridRemoteConnector(vector<shared_ptr<CLocalView>>& srcView, vector<shared_ptr<CLocalView>>& dstView, MPI_Comm localComm, int remoteSize) ; 22 22 void computeViewDistribution(void) ; 23 void computeConnector( void) ;23 void computeConnector(bool eliminateRedundant=true) ; 24 24 void computeConnectorMethods(void) ; 25 void computeConnectorRedundant(void) ; 25 26 void computeGenericMethod(vector<shared_ptr<CLocalView>>& srcView, vector<shared_ptr<CDistributedView>>& dstView, vector<int>& indElements) ; 26 27 void computeSrcDstNonDistributed(int i, map<int,bool>& ranks) ; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_transform_connector.cpp
r2267 r2291 4 4 #include "gatherer_connector.hpp" 5 5 #include "grid_remote_connector.hpp" 6 #include "grid_redondant_remote_connector.hpp" 6 7 7 8 8 9 namespace xios 9 10 { 10 void CGridTransformConnector::computeConnector( void)11 void CGridTransformConnector::computeConnector(bool eliminateRedundant) 11 12 { 12 13 int commSize ; … … 17 18 18 19 auto remoteConnector = make_shared<CGridRemoteConnector>(srcViews_, remoteViews_, localComm_, commSize) ; 19 remoteConnector->computeConnector( ) ;20 remoteConnector->computeConnector(eliminateRedundant) ; 20 21 21 22 vector<shared_ptr<CDistributedElement>> sendElements(nElements) ; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_transform_connector.hpp
r2267 r2291 8 8 #include "grid_scatterer_connector.hpp" 9 9 #include "grid_gatherer_connector.hpp" 10 #include "reduction_types.hpp" 10 11 #include "mpi.hpp" 11 12 … … 20 21 CGridTransformConnector(vector<shared_ptr<CLocalView>> srcViews, vector<shared_ptr<CLocalView>> remoteViews, MPI_Comm localComm) 21 22 : srcViews_(srcViews), remoteViews_(remoteViews), localComm_(localComm) 22 { computeConnector();}23 { } 23 24 24 void computeConnector( void) ;25 void computeConnector(bool eliminateRedundant=true) ; 25 26 protected: 26 27 MPI_Comm localComm_ ; … … 36 37 public: 37 38 template<typename T> 38 void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut )39 void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none) 39 40 { 40 41 map<int,CArray<T,1>> tmpArrayIn ; … … 62 63 63 64 const double nanValue = std::numeric_limits<double>::quiet_NaN(); 64 gridGathererConnector_->transfer(tmpArrayOut, dataOut, nanValue) ; 65 66 if (op == EReduction::none) gridGathererConnector_->transfer(tmpArrayOut, dataOut, nanValue) ; 67 else gridGathererConnector_->transfer(tmpArrayOut, dataOut, op) ; 65 68 } 66 69 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/reduce_transform_connector.hpp
r2267 r2291 68 68 { 69 69 vector<bool> touched(repeat* dstSlice, false) ; 70 int pos=0 ; 71 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos+=dstSlice) 72 { 73 const double* in = input; 74 double* out = output ; 75 int k=0 ; 70 int posr=0 ; 71 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 72 { 73 const double* in = input; 74 double* out = output ; 75 int k=0 ; 76 int pos = posr ; 76 77 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 77 78 { … … 97 98 98 99 output = dataOut.dataFirst() ; 99 pos =0 ;100 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos +=dstSlice)101 { 102 const double* in = input; 103 double* out = output ; 104 int k=0 ; 105 int pos= 0;100 posr=0 ; 101 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 102 { 103 const double* in = input; 104 double* out = output ; 105 int k=0 ; 106 int pos=posr ; 106 107 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 107 108 for(int j=0 ; j<nSrc_[i] ; j++,k++) … … 144 145 { 145 146 vector<bool> touched(repeat* dstSlice, false) ; 146 int pos=0 ; 147 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos+=dstSlice) 148 { 149 const double* in = input; 150 double* out = output ; 151 int k=0 ; 147 int posr=0 ; 148 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 149 { 150 const double* in = input; 151 double* out = output ; 152 int k=0 ; 153 int pos=posr ; 152 154 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 153 155 { … … 173 175 174 176 output = dataOut.dataFirst() ; 175 pos =0 ;176 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos +=dstSlice)177 { 178 const double* in = input; 179 double* out = output ; 180 int k=0 ; 181 int pos= 0;177 posr=0 ; 178 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 179 { 180 const double* in = input; 181 double* out = output ; 182 int k=0 ; 183 int pos=posr ; 182 184 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 183 185 for(int j=0 ; j<nSrc_[i] ; j++,k++) … … 220 222 { 221 223 vector<bool> touched(repeat* dstSlice, false) ; 222 int pos=0 ; 223 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos+=dstSlice) 224 { 225 const double* in = input; 226 double* out = output ; 227 int k=0 ; 224 int posr=0 ; 225 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 226 { 227 const double* in = input; 228 double* out = output ; 229 int k=0 ; 230 int pos=posr ; 228 231 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 229 232 { … … 249 252 250 253 output = dataOut.dataFirst() ; 251 pos =0 ;252 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos +=dstSlice)253 { 254 const double* in = input; 255 double* out = output ; 256 int k=0 ; 257 int pos= 0;254 posr=0 ; 255 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 256 { 257 const double* in = input; 258 double* out = output ; 259 int k=0 ; 260 int pos=posr ; 258 261 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 259 262 for(int j=0 ; j<nSrc_[i] ; j++,k++) … … 296 299 { 297 300 vector<int> touched(repeat* dstSlice, 0) ; 298 int pos=0 ; 299 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos+=dstSlice) 300 { 301 const double* in = input; 302 double* out = output ; 303 int k=0 ; 301 int posr=0 ; 302 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 303 { 304 const double* in = input; 305 double* out = output ; 306 int k=0 ; 307 int pos=posr ; 304 308 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 305 309 { … … 331 335 332 336 output = dataOut.dataFirst() ; 333 pos =0 ;334 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, pos +=dstSlice)335 { 336 const double* in = input; 337 double* out = output ; 338 int k=0 ; 339 int pos= 0;337 posr=0 ; 338 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, posr+=dstSlice) 339 { 340 const double* in = input; 341 double* out = output ; 342 int k=0 ; 343 int pos=posr ; 340 344 for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 341 345 for(int j=0 ; j<nSrc_[i] ; j++,k++) -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
r2274 r2291 276 276 This check should be done in the very beginning of work flow 277 277 */ 278 278 279 void CAxis::checkAttributes(void) 279 TRY 280 { 281 if (checkAttributes_done_) return ; 282 283 CContext* context=CContext::getCurrent(); 284 285 if (this->n_glo.isEmpty()) 286 ERROR("CAxis::checkAttributes(void)", 287 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 288 << "The axis is wrongly defined, attribute 'n_glo' must be specified"); 289 StdSize size = this->n_glo.getValue(); 290 291 if (!this->index.isEmpty()) 292 { 293 if (n.isEmpty()) n = index.numElements(); 294 295 // It's not so correct but if begin is not the first value of index 296 // then data on the local axis has user-defined distribution. In this case, begin has no meaning. 297 if (begin.isEmpty()) begin = index(0); 298 } 299 else 300 { 301 if (!this->begin.isEmpty()) 302 { 303 if (begin < 0 || begin > size - 1) 304 ERROR("CAxis::checkAttributes(void)", 305 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 306 << "The axis is wrongly defined, attribute 'begin' (" << begin.getValue() << ") must be non-negative and smaller than size-1 (" << size - 1 << ")."); 307 } 308 else this->begin.setValue(0); 309 310 if (!this->n.isEmpty()) 311 { 312 if (n < 0 || n > size) 313 ERROR("CAxis::checkAttributes(void)", 314 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 315 << "The axis is wrongly defined, attribute 'n' (" << n.getValue() << ") must be non-negative and smaller than size (" << size << ")."); 316 } 317 else this->n.setValue(size); 318 319 { 320 index.resize(n); 321 for (int i = 0; i < n; ++i) index(i) = i+begin; 322 } 323 } 324 325 if (!this->value.isEmpty()) 326 { 327 StdSize true_size = value.numElements(); 328 if (this->n.getValue() != true_size) 329 ERROR("CAxis::checkAttributes(void)", 330 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 331 << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size 332 << ") than the one defined by the \'size\' attribute (" << n.getValue() << ")."); 333 this->hasValue = true; 334 } 335 336 this->checkBounds(); 337 this->checkMask(); 338 this->checkData(); 339 this->checkLabel(); 280 { 281 if (checkAttributes_done_) return ; 282 checkGeometricAttributes(true) ; 340 283 initializeLocalElement() ; 341 284 addFullView() ; … … 345 288 checkAttributes_done_ = true ; 346 289 } 290 291 void CAxis::resetGeometricAttributes(void) 292 { 293 n_glo.reset(); 294 index.reset(); 295 n.reset(); 296 begin.reset(); 297 mask.reset(); 298 data_index.reset(); 299 data_n.reset(); 300 data_begin.reset(); 301 value.reset(); 302 bounds.reset(); 303 label.reset() ; 304 } 305 306 void CAxis::setGeometricAttributes(const CAxis& axisSrc) 307 { 308 resetGeometricAttributes() ; 309 n_glo=axisSrc.n_glo; 310 if (!axisSrc.index.isEmpty()) 311 { 312 index.resize(axisSrc.index.shape()) ; 313 index=axisSrc.index; 314 } 315 316 n=axisSrc.n; 317 begin=axisSrc.begin; 318 if (!axisSrc.mask.isEmpty()) 319 { 320 mask.resize(axisSrc.mask.shape()) ; 321 mask=axisSrc.mask; 322 } 323 if (!axisSrc.data_index.isEmpty()) 324 { 325 data_index.resize(axisSrc.data_index.shape()) ; 326 data_index=axisSrc.data_index; 327 } 328 data_n=axisSrc.data_n; 329 data_begin=axisSrc.data_begin; 330 if (!axisSrc.value.isEmpty()) 331 { 332 value.resize(axisSrc.value.shape()) ; 333 value=axisSrc.value; 334 } 335 336 if (!axisSrc.bounds.isEmpty()) 337 { 338 bounds.resize(axisSrc.bounds.shape()) ; 339 bounds=axisSrc.bounds; 340 } 341 if (!axisSrc.label.isEmpty()) 342 { 343 label.resize(axisSrc.label.shape()) ; 344 label=axisSrc.label; 345 } 346 347 } 348 349 bool CAxis::checkGeometricAttributes(bool generateError) 350 TRY 351 { 352 CContext* context=CContext::getCurrent(); 353 354 if (this->n_glo.isEmpty()) 355 if (generateError) ERROR("CAxis::checkAttributes(void)", 356 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 357 << "The axis is wrongly defined, attribute 'n_glo' must be specified") 358 else return false ; 359 StdSize size = this->n_glo.getValue(); 360 361 if (!this->index.isEmpty()) 362 { 363 if (n.isEmpty()) n = index.numElements(); 364 365 // It's not so correct but if begin is not the first value of index 366 // then data on the local axis has user-defined distribution. In this case, begin has no meaning. 367 if (begin.isEmpty()) begin = index(0); 368 } 369 else 370 { 371 if (!this->begin.isEmpty()) 372 { 373 if (begin < 0 || begin > size - 1) 374 if (generateError) ERROR("CAxis::checkAttributes(void)", 375 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 376 << "The axis is wrongly defined, attribute 'begin' (" 377 << begin.getValue() << ") must be non-negative and smaller than size-1 (" << size - 1 << ").") 378 else return false ; 379 } 380 else this->begin.setValue(0); 381 382 if (!this->n.isEmpty()) 383 { 384 if (n < 0 || n > size) 385 if (generateError) ERROR("CAxis::checkAttributes(void)", 386 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 387 << "The axis is wrongly defined, attribute 'n' (" << n.getValue() << ") must be non-negative and smaller than size (" 388 << size << ").") 389 else return false ; 390 } 391 else this->n.setValue(size); 392 393 { 394 index.resize(n); 395 for (int i = 0; i < n; ++i) index(i) = i+begin; 396 } 397 } 398 399 if (!this->value.isEmpty()) 400 { 401 StdSize true_size = value.numElements(); 402 if (this->n.getValue() != true_size) 403 if (generateError) ERROR("CAxis::checkAttributes(void)", 404 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 405 << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size 406 << ") than the one defined by the \'size\' attribute (" << n.getValue() << ").") 407 else return false ; 408 this->hasValue = true; 409 } 410 411 if (!this->checkBounds(generateError)) return false; 412 if (!this->checkMask(generateError)) return false; 413 if (!this->checkData(generateError)) return false; 414 if (!this->checkLabel(generateError)) return false; 415 416 return true ; 417 } 347 418 CATCH_DUMP_ATTR 348 349 419 350 420 … … 352 422 Check the validity of data, fill in values if any, and apply mask. 353 423 */ 354 void CAxis::checkData()424 bool CAxis::checkData(bool generateError) 355 425 TRY 356 426 { … … 363 433 else if (data_n.getValue() < 0) 364 434 { 365 ERROR("CAxis::checkData(void)", 366 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 367 << "The data size should be strictly positive ('data_n' = " << data_n.getValue() << ")."); 435 if (generateError) ERROR("CAxis::checkData(void)", 436 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 437 << "The data size should be strictly positive ('data_n' = " << data_n.getValue() << ").") 438 else return false ; 368 439 } 369 440 … … 388 459 if (data_index.numElements() != data_n) 389 460 { 390 ERROR("CAxis::checkData(void)", 391 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 392 << "The size of data_index = "<< data_index.numElements() << "is not equal to the data size data_n = " << data_n.getValue() << ")."); 461 if (generateError) ERROR("CAxis::checkData(void)", 462 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 463 << "The size of data_index = "<< data_index.numElements() << "is not equal to the data size data_n = " 464 << data_n.getValue() << ").") 465 else return false ; 393 466 } 394 467 for (int i = 0; i < data_n; ++i) … … 398 471 } 399 472 } 400 473 return true ; 401 474 } 402 475 CATCH_DUMP_ATTR 403 476 404 size_t CAxis::getGlobalWrittenSize(void) 405 { 406 return n_glo ; 407 } 408 409 /*! 410 Check validity of mask info and fill in values if any. 411 */ 412 void CAxis::checkMask() 477 /*! 478 Check validity of mask info and fill in values if any. 479 */ 480 bool CAxis::checkMask(bool generateError) 413 481 TRY 414 482 { … … 417 485 if (mask.extent(0) != n) 418 486 { 419 ERROR("CAxis::checkMask(void)", 420 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 421 << "The mask does not have the same size as the local domain." << std::endl 422 << "Local size is " << n.getValue() << "." << std::endl 423 << "Mask size is " << mask.extent(0) << "."); 487 if (generateError) ERROR("CAxis::checkMask(void)", 488 << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " 489 << "The mask does not have the same size as the local domain." << std::endl 490 << "Local size is " << n.getValue() << "." << std::endl 491 << "Mask size is " << mask.extent(0) << ".") 492 else return false ; 424 493 } 425 494 } … … 429 498 mask = true; 430 499 } 500 return true ; 431 501 } 432 502 CATCH_DUMP_ATTR … … 435 505 Check validity of bounds info and fill in values if any. 436 506 */ 437 void CAxis::checkBounds()507 bool CAxis::checkBounds(bool generateError) 438 508 TRY 439 509 { … … 441 511 { 442 512 if (bounds.extent(0) != 2 || bounds.extent(1) != n) 443 ERROR("CAxis::checkAttributes(void)", 444 << "The bounds array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension 2 x axis size." << std::endl 445 << "Axis size is " << n.getValue() << "." << std::endl 446 << "Bounds size is "<< bounds.extent(0) << " x " << bounds.extent(1) << "."); 513 if (generateError) ERROR("CAxis::checkAttributes(void)", 514 << "The bounds array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension 2 x axis size." << std::endl 515 << "Axis size is " << n.getValue() << "." << std::endl 516 << "Bounds size is "<< bounds.extent(0) << " x " << bounds.extent(1) << ".") 517 else return false ; 447 518 hasBounds = true; 448 519 } 449 520 else hasBounds = false; 521 return true ; 450 522 } 451 523 CATCH_DUMP_ATTR 452 524 453 void CAxis::checkLabel()525 bool CAxis::checkLabel(bool generateError) 454 526 TRY 455 527 { … … 457 529 { 458 530 if (label.extent(0) != n) 459 ERROR("CAxis::checkLabel(void)", 460 << "The label array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension of axis size." << std::endl 461 << "Axis size is " << n.getValue() << "." << std::endl 462 << "label size is "<< label.extent(0)<< " ."); 531 if (generateError) ERROR("CAxis::checkLabel(void)", 532 << "The label array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension of axis size." << std::endl 533 << "Axis size is " << n.getValue() << "." << std::endl 534 << "label size is "<< label.extent(0)<< " .") 535 else return false ; 463 536 hasLabel = true; 464 537 } 465 538 else hasLabel = false; 466 } 467 CATCH_DUMP_ATTR 539 return true ; 540 } 541 CATCH_DUMP_ATTR 542 543 544 size_t CAxis::getGlobalWrittenSize(void) 545 { 546 return n_glo ; 547 } 548 549 468 550 469 551 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.hpp
r2282 r2291 124 124 void checkAttributes(void); 125 125 bool checkAttributes_done_ = false ; 126 bool checkGeometricAttributes(bool generateError) ; 127 void setGeometricAttributes(const CAxis& axisSrc) ; 128 void resetGeometricAttributes(void) ; 126 129 127 130 size_t getGlobalWrittenSize(void) ; … … 173 176 174 177 private: 175 void checkData();176 void checkMask();177 void checkBounds();178 void checkLabel();178 bool checkData(bool generateError); 179 bool checkMask(bool generateError); 180 bool checkBounds(bool generateError); 181 bool checkLabel(bool generateError); 179 182 180 183 public: -
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/reduce_domain_to_axis.cpp
r2270 r2291 48 48 << "Axis destination " << axisDst->getId()); 49 49 50 int axis_n_glo = axisDst->n_glo;51 int domain_ni_glo = domainSrc->ni_glo;52 int domain_nj_glo = domainSrc->nj_glo;53 54 50 if (this->operation.isEmpty()) 55 51 ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", … … 65 61 if (this->local.isEmpty()) local=false ; 66 62 67 switch (direction)68 {69 case direction_attr::jDir:70 if (axis_n_glo != domain_ni_glo)71 ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",72 << "Extract domain along j, axis destination should have n_glo equal to ni_glo of domain source"73 << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_ni_glo << std::endl74 << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo);75 break;76 77 case direction_attr::iDir:78 if (axis_n_glo != domain_nj_glo)79 ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",80 << "Extract domain along i, axis destination should have n_glo equal to nj_glo of domain source"81 << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_nj_glo << std::endl82 << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo);83 break;84 85 default:86 break;87 }88 63 } 89 64 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/Functions/reduction_types.hpp
r1999 r2291 13 13 { 14 14 15 typedef enum reduction_alg urithm_type15 typedef enum reduction_algorithm_type 16 16 { 17 TRANS_REDUCE_SUM = 0, 18 TRANS_REDUCE_MIN = 1, 19 TRANS_REDUCE_MAX = 2, 20 TRANS_REDUCE_EXTRACT = 3, 21 TRANS_REDUCE_AVERAGE = 4 17 TRANS_REDUCE_NONE = 0, 18 TRANS_REDUCE_SUM = 1, 19 TRANS_REDUCE_MIN = 2, 20 TRANS_REDUCE_MAX = 3, 21 TRANS_REDUCE_EXTRACT = 4, 22 TRANS_REDUCE_AVERAGE = 5 22 23 } EReductionType; 23 24 24 25 enum class EReduction 25 26 { 26 sum, min, max, extract, average27 none, sum, min, max, extract, average 27 28 } ; 28 29 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/algorithm_transformation_no_data_modification.cpp
r2270 r2291 12 12 shared_ptr<CGridAlgorithm> CAlgorithmTransformationNoDataModification::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) 13 13 { 14 return make_shared<CGridAlgorithmNoDataModification>(static_pointer_cast<CAlgorithmTransformationNoDataModification>(shared_from_this())) ; 14 auto algo=make_shared<CGridAlgorithmNoDataModification>(static_pointer_cast<CAlgorithmTransformationNoDataModification>(shared_from_this())) ; 15 algo->computeAlgorithm() ; 16 return algo ; 15 17 } 16 18 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/algorithm_transformation_reduce.hpp
r2267 r2291 28 28 shared_ptr<CReduceTransformConnector> reduceTransformConnector_ ; 29 29 bool detectMissingValue_=true ; 30 bool eliminateRedondantSrc_ = true ;31 30 }; 32 31 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm/axis_algorithm_reduce_axis.cpp
r2270 r2291 12 12 #include "grid.hpp" 13 13 #include "grid_transformation_factory_impl.hpp" 14 #include "grid_algorithm_reduce.hpp" 14 15 15 16 … … 50 51 TRY 51 52 { 52 eliminateRedondantSrc_= false ; 53 if (!axisDestination->checkGeometricAttributes(false)) 54 { 55 axisDestination->resetGeometricAttributes(); 56 axisDestination->setGeometricAttributes(*axisSource) ; 57 } 58 axisDestination->checkAttributes() ; 53 59 algo->checkValid(axisDestination, axisSource); 54 axisDestination->checkAttributes() ;60 55 61 56 62 switch (algo->operation) … … 75 81 } 76 82 77 TransformationIndexMap& transMap = this->transformationMapping_; 78 CArray<int,1>& axisDstIndex = axisDestination->index; 79 int nbAxisIdx = axisDstIndex.numElements(); 80 for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) 83 //TransformationIndexMap& transMap = this->transformationMapping_; 84 //CArray<int,1>& axisDstIndex = axisDestination->index; 85 //int nbAxisIdx = axisDstIndex.numElements(); 86 87 88 89 auto& transMap = this->transformationMapping_; 90 91 CArray<size_t,1> dstGlobalIndex ; 92 axisDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 93 size_t nbIdx = dstGlobalIndex.numElements(); 94 95 for (size_t idx = 0; idx < nbIdx; ++idx) 81 96 { 82 int globalAxisIdx = axisDstIndex(idxAxis);83 transMap[global AxisIdx].resize(1);84 transMap[global AxisIdx][0]=globalAxisIdx ;97 size_t globalIdx = dstGlobalIndex(idx); 98 transMap[globalIdx].resize(1); 99 transMap[globalIdx][0]=globalIdx ; 85 100 } 86 101 87 88 axisDestination->checkAttributes() ;89 102 this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; 90 103 } 91 104 CATCH 92 105 106 shared_ptr<CGridAlgorithm> CAxisAlgorithmReduceAxis::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) 107 { 108 auto algo=make_shared<CGridAlgorithmReduce>(gridSrc, gridDst, pos, shared_from_this(), operator_) ; 109 algo->computeAlgorithm(false) ; 110 return algo ; 111 } 93 112 94 113 CAxisAlgorithmReduceAxis::~CAxisAlgorithmReduceAxis() -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm/axis_algorithm_reduce_axis.hpp
r2270 r2291 44 44 std::map<int, int>& elementPositionInGridDst2AxisPosition, 45 45 std::map<int, int>& elementPositionInGridDst2DomainPosition); 46 47 virtual shared_ptr<CGridAlgorithm> createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos); 46 48 static bool dummyRegistered_; 47 49 }; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm/axis_algorithm_reduce_domain.cpp
r2270 r2291 51 51 TRY 52 52 { 53 algo->checkValid(axisDestination, domainSource);54 axisDestination->checkAttributes() ;55 53 switch (algo->operation) 56 54 { … … 74 72 75 73 } 76 74 75 algo->checkValid(axisDestination, domainSource); 77 76 dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction) ? iDir : jDir; 78 bool local = algo->local ; 77 78 bool local = false; 79 if (!algo->local.isEmpty()) local=algo->local ; 80 81 size_t nj_glo = domainSource->nj_glo ; 82 size_t ni_glo = domainSource->ni_glo ; 83 84 bool validAxis = axisDestination->checkGeometricAttributes(false) ; 85 if (validAxis && !local) 86 { 87 88 axisDestination->checkAttributes() ; 89 if (dir_==jDir) 90 { 91 if (axisDestination->n_glo != domainSource->nj_glo) 92 ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", 93 << "Extract domain along j, axis destination should have n_glo equal to nj_glo of domain source" 94 << "Domain source " <<domainSource->getId() << " has nj_glo " << domainSource->nj_glo << std::endl 95 << "Axis destination " << axisDestination->getId() << " has n_glo " << axisDestination->n_glo) 96 } 97 else 98 { 99 if (axisDestination->n_glo != domainSource->ni_glo) 100 ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", 101 << "Extract domain along j, axis destination should have n_glo equal to ni_glo of domain source" 102 << "Domain source " <<domainSource->getId() << " has ni_glo " << domainSource->ni_glo << std::endl 103 << "Axis destination " << axisDestination->getId() << " has n_glo " << axisDestination->n_glo); 104 } 105 } 106 else 107 { 108 // create axis destination from source domain 109 110 axisDestination->resetGeometricAttributes(); 111 if (dir_== jDir) 112 { 113 axisDestination->n_glo = domainSource->nj_glo ; 114 115 CArray<size_t, 1> srcGlobalIndex ; 116 set<size_t> indexFullView; 117 set<size_t> indexWorkflowView; 118 domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 119 for(int i=0; i<srcGlobalIndex.numElements(); i++) indexFullView.insert(srcGlobalIndex(i)/ni_glo) ; 120 domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 121 for(int i=0; i<srcGlobalIndex.numElements(); i++) indexWorkflowView.insert(srcGlobalIndex(i)/ni_glo) ; 122 123 axisDestination-> n = indexFullView.size() ; 124 axisDestination-> index.resize(axisDestination-> n) ; 125 axisDestination-> mask.resize(axisDestination-> n) ; 126 127 map<size_t,int> globalToLocalIndex ; 128 auto it=indexFullView.begin(); 129 for(int i=0; it!=indexFullView.end(); ++i,++it) 130 { 131 axisDestination->index(i) = *it ; 132 if (indexWorkflowView.count(*it)==0) axisDestination->mask(i) = false ; 133 else axisDestination->mask(i) = true ; 134 globalToLocalIndex[*it] = i ; 135 } 136 if (domainSource->hasLonLat && domainSource->type == CDomain::type_attr::rectilinear) 137 { 138 axisDestination->value.resize(axisDestination-> n) ; 139 axisDestination->axis_type.setValue(CAxis::axis_type_attr::Y) ; 140 if (domainSource->hasBounds) axisDestination-> bounds.resize(axisDestination-> n, 2) ; 141 142 domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 143 for(int i=0; i<srcGlobalIndex.numElements(); i++) 144 { 145 axisDestination->value(globalToLocalIndex[srcGlobalIndex(i)/ni_glo]) = domainSource->latvalue(i) ; 146 if (domainSource->hasBounds) 147 { 148 axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)/ni_glo,0]) = domainSource->bounds_latvalue(i,0) ; 149 axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)/ni_glo,1]) = domainSource->bounds_latvalue(i,1) ; 150 } 151 } 152 } 153 154 } 155 else // dir_== iDir 156 { 157 axisDestination->n_glo = domainSource->ni_glo ; 158 159 CArray<size_t, 1> srcGlobalIndex ; 160 set<size_t> indexFullView; 161 set<size_t> indexWorkflowView; 162 domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 163 for(int i=0; i<srcGlobalIndex.numElements(); i++) indexFullView.insert(srcGlobalIndex(i)%ni_glo) ; 164 domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 165 for(int i=0; i<srcGlobalIndex.numElements(); i++) indexWorkflowView.insert(srcGlobalIndex(i)%ni_glo) ; 166 167 axisDestination-> n = indexFullView.size() ; 168 axisDestination-> index.resize(axisDestination-> n) ; 169 axisDestination-> mask.resize(axisDestination-> n) ; 170 map<size_t,int> globalToLocalIndex ; 171 auto it=indexFullView.begin(); 172 for(int i=0; it!=indexFullView.end(); ++i,++it) 173 { 174 axisDestination->index(i) = *it ; 175 if (indexWorkflowView.count(*it)==0) axisDestination->mask(i) = false ; 176 else axisDestination->mask(i) = true ; 177 globalToLocalIndex[*it] = i ; 178 } 179 180 if (domainSource->hasLonLat && domainSource->type == CDomain::type_attr::rectilinear) 181 { 182 axisDestination-> value.resize(axisDestination-> n) ; 183 axisDestination-> axis_type.setValue(CAxis::axis_type_attr::X) ; 184 if (domainSource->hasBounds) axisDestination->bounds.resize(axisDestination-> n, 2) ; 185 186 domainSource->getLocalView(CElementView::FULL)->getGlobalIndexView(srcGlobalIndex) ; 187 for(int i=0; i<srcGlobalIndex.numElements(); i++) 188 { 189 axisDestination->value(globalToLocalIndex[srcGlobalIndex(i)%ni_glo]) = domainSource->lonvalue(i) ; 190 if (domainSource->hasBounds) 191 { 192 axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)%ni_glo,0]) = domainSource->bounds_lonvalue(i,0) ; 193 axisDestination->bounds(globalToLocalIndex[srcGlobalIndex(i)%ni_glo,1]) = domainSource->bounds_lonvalue(i,1) ; 194 } 195 } 196 } 197 198 } 199 200 axisDestination->checkAttributes() ; 201 } 202 203 // compute needed index for tranformation 204 205 TransformationIndexMap& transMap = transformationMapping_; 206 207 CArray<size_t, 1> srcGlobalIndex ; 208 domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 209 CArray<size_t, 1> dstGlobalIndex ; 210 axisDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 211 212 if (local) 213 { 214 215 set<size_t> dstGlobalIndexSet ; 216 for(int i=0; i<dstGlobalIndex.numElements() ; i++) dstGlobalIndexSet.insert(dstGlobalIndex(i)) ; // for mask 217 218 size_t dstInd ; 219 for(int i=0; i<srcGlobalIndex.numElements(); i++) 220 { 221 if (dir_== jDir) dstInd=srcGlobalIndex(i)/ni_glo ; 222 else dstInd=srcGlobalIndex(i)%ni_glo ; 223 if (dstGlobalIndexSet.count(dstInd)!=0) transMap[dstInd].push_back(srcGlobalIndex(i)) ; 224 } 225 } 226 else 227 { 228 for(int i=0; i<dstGlobalIndex.numElements() ;i++) 229 { 230 if (dir_== jDir) 231 for(size_t j=0; j<ni_glo;j++) transMap[dstGlobalIndex(i)].push_back(dstGlobalIndex(i)*ni_glo+j) ; 232 else 233 for(size_t j=0; j<nj_glo;j++) transMap[dstGlobalIndex(i)].push_back(ni_glo*j+dstGlobalIndex(i)) ; 234 } 235 } 236 237 /* 238 79 239 80 240 TransformationIndexMap& transMap = transformationMapping_; … … 148 308 149 309 axisDestination->checkAttributes() ; 310 */ 150 311 this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; 151 312 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/generic_algorithm_transformation.cpp
r2270 r2291 35 35 shared_ptr<CGridAlgorithm> CGenericAlgorithmTransformation::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) 36 36 { 37 return make_shared<CGridAlgorithmGeneric>(gridSrc, gridDst, pos, shared_from_this()) ; 37 auto algo = make_shared<CGridAlgorithmGeneric>(gridSrc, gridDst, pos, shared_from_this()) ; 38 algo->computeAlgorithm() ; 39 return algo ; 38 40 } 39 41 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/grid_algorithm_generic.cpp
r2270 r2291 13 13 : CGridAlgorithm(algo), gridSrc_(gridSrc), gridDst_(gridDst), pos_(pos) 14 14 { 15 computeAlgorithm() ;16 15 } 17 16 18 void CGridAlgorithmGeneric::computeAlgorithm( void)17 void CGridAlgorithmGeneric::computeAlgorithm(bool eliminateRedondant) 19 18 { 20 19 shared_ptr<CGridLocalElements> gridSrcElements = gridSrc_->getGridLocalElements() ; … … 48 47 49 48 gridTransformConnector_ = make_shared<CGridTransformConnector>(srcView->getViews(), remoteViews, comm ) ; 49 gridTransformConnector_->computeConnector(eliminateRedondant) ; 50 50 51 51 } -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/grid_algorithm_generic.hpp
r2270 r2291 26 26 virtual ~CGridAlgorithmGeneric() {} ; 27 27 28 void computeAlgorithm( void) ;28 void computeAlgorithm(bool eliminateRedundant=true) ; 29 29 virtual void apply(const CArray<double,1>& dataIn, CArray<double,1>& dataOut) ; 30 30 virtual void apply(const CArray<double,1>& dataIn, const vector<CArray<double,1>>& auxData, CArray<double,1>& dataOut) ; 31 31 32 32 protected: 33 33 34 shared_ptr<CGridTransformConnector> gridTransformConnector_=nullptr ; 34 35 CGrid* gridSrc_ = nullptr ; -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_axis.cpp
r2270 r2291 79 79 80 80 } 81 82 bool local=false ; 83 if (!algo->local.isEmpty()) local=algo->local ; 81 84 82 int globalIndexSize = axisSource-> n_glo; 83 for (int idx = 0; idx < globalIndexSize; ++idx) transformationMapping_[0].push_back(idx); 85 auto& transMap = this->transformationMapping_; 86 87 if (local) 88 { 89 scalarDestination->n=1 ; // no mask 90 scalarDestination->mask.reset() ; 91 92 CArray<size_t,1> srcGlobalIndex ; 93 axisSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 94 size_t nbIdx = srcGlobalIndex.numElements(); 95 if (nbIdx==0) scalarDestination->n=0 ; 96 scalarDestination->checkAttributes() ; 84 97 85 scalarDestination->checkAttributes() ; 98 for (size_t idx = 0; idx < nbIdx; ++idx) 99 { 100 size_t globalIdx = srcGlobalIndex(idx); 101 transformationMapping_[0].push_back(globalIdx); 102 } 103 104 } 105 else 106 { 107 scalarDestination->checkAttributes() ; 108 109 int globalIndexSize = axisSource->getLocalView(CElementView::WORKFLOW)->getGlobalSize(); 110 CArray<size_t,1> dstGlobalIndex ; 111 scalarDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 112 if (dstGlobalIndex.numElements()!=0) 113 for (int idx = 0; idx < globalIndexSize; ++idx) transformationMapping_[0].push_back(idx); 114 } 115 86 116 this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; 87 117 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_domain.cpp
r2270 r2291 74 74 } 75 75 76 TransformationIndexMap& transMap = this->transformationMapping_; 77 78 int ni_glo = domainSrc_->ni_glo ; 79 int nj_glo = domainSrc_->nj_glo ; 80 int nbDomainIdx ; 76 bool local=false ; 77 if (!algo->local.isEmpty()) local=algo->local ; 81 78 82 bool local = algo->local ;79 auto& transMap = this->transformationMapping_; 83 80 84 81 if (local) 85 82 { 86 const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; 87 const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; 88 const CArray<bool,1>& localMask = domainSrc_-> localMask ; 89 int nbDomainIdx = i_index.numElements(); 83 scalarDestination->n=1 ; // no mask 84 scalarDestination->mask.reset() ; 85 86 CArray<size_t,1> srcGlobalIndex ; 87 domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; 88 size_t nbIdx = srcGlobalIndex.numElements(); 89 if (nbIdx==0) scalarDestination->n=0 ; 90 scalarDestination->checkAttributes() ; 90 91 91 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) 92 { 93 if (localMask(idxDomain)) 94 { 95 transMap[0].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); 96 } 97 } 92 for (size_t idx = 0; idx < nbIdx; ++idx) 93 { 94 size_t globalIdx = srcGlobalIndex(idx); 95 transformationMapping_[0].push_back(globalIdx); 96 } 97 98 98 } 99 99 else 100 { 101 nbDomainIdx = ni_glo * nj_glo; 102 for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) transMap[0].push_back(idxDomain); 100 { 101 scalarDestination->checkAttributes() ; 102 103 int globalIndexSize = domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalSize(); 104 CArray<size_t,1> dstGlobalIndex ; 105 scalarDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 106 if (dstGlobalIndex.numElements()!=0) 107 for (int idx = 0; idx < globalIndexSize; ++idx) transformationMapping_[0].push_back(idx); 103 108 } 104 105 scalarDestination->checkAttributes() ; 109 106 110 this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; 111 107 112 } 108 113 CATCH -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_scalar.cpp
r2270 r2291 10 10 #include "grid_transformation_factory_impl.hpp" 11 11 #include "reduction.hpp" 12 #include "grid_algorithm_reduce.hpp" 13 12 14 13 15 … … 47 49 TRY 48 50 { 49 eliminateRedondantSrc_= false;51 scalarDestination->checkAttributes() ; 50 52 if (algo->operation.isEmpty()) 51 53 ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", … … 75 77 76 78 } 77 transformationMapping_[0].push_back(0) ; 79 80 auto& transMap = this->transformationMapping_; 81 82 CArray<size_t,1> dstGlobalIndex ; 83 scalarDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; 84 size_t nbIdx = dstGlobalIndex.numElements(); 78 85 79 scalarDestination->checkAttributes() ; 86 for (size_t idx = 0; idx < nbIdx; ++idx) 87 { 88 size_t globalIdx = dstGlobalIndex(idx); 89 transMap[globalIdx].resize(1); 90 transMap[globalIdx][0]=globalIdx ; 91 } 92 80 93 this->computeAlgorithm(scalarSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; 81 94 } 82 95 CATCH 96 97 shared_ptr<CGridAlgorithm> CScalarAlgorithmReduceScalar::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) 98 { 99 auto algo=make_shared<CGridAlgorithmReduce>(gridSrc, gridDst, pos, shared_from_this(), operator_) ; 100 algo->computeAlgorithm(false) ; 101 return algo ; 102 } 83 103 84 104 CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar() -
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_scalar.hpp
r2270 r2291 42 42 std::map<int, int>& elementPositionInGridDst2AxisPosition, 43 43 std::map<int, int>& elementPositionInGridDst2DomainPosition); 44 virtual shared_ptr<CGridAlgorithm> createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos); 44 45 static bool dummyRegistered_; 45 46 };
Note: See TracChangeset
for help on using the changeset viewer.