Ignore:
Timestamp:
02/01/22 15:28:48 (2 years ago)
Author:
ymipsl
Message:

Improve reduction transformation

  • make the difference between reduction over geometry or reduction between process.
  • geometrical reduction :

domain -> axis
axis -> scalar
domain -> scalar

  • reduction across processes for redondant geometrical cell :

axis -> axis
scalar -> scalar

Reduction can be local (only for the geometrical cell owned by current process) or global, using the "local" attribute (bool) over the reduction.

YM

Location:
XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_axis.cpp

    r2270 r2291  
    7979 
    8080  }  
     81 
     82  bool local=false ; 
     83  if (!algo->local.isEmpty()) local=algo->local ; 
    8184   
    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() ; 
    8497 
    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 
    86116  this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; 
    87117   
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_domain.cpp

    r2270 r2291  
    7474  } 
    7575 
    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 ; 
    8178   
    82   bool  local = algo->local ; 
     79  auto& transMap = this->transformationMapping_;   
    8380   
    8481  if (local) 
    8582  { 
    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() ; 
    9091 
    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 
    9898  } 
    9999  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); 
    103108  } 
    104    
    105   scalarDestination->checkAttributes() ; 
     109 
    106110  this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; 
     111 
    107112} 
    108113CATCH 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_scalar.cpp

    r2270 r2291  
    1010#include "grid_transformation_factory_impl.hpp" 
    1111#include "reduction.hpp" 
     12#include "grid_algorithm_reduce.hpp" 
     13 
    1214 
    1315 
     
    4749TRY 
    4850{ 
    49   eliminateRedondantSrc_= false ; 
     51  scalarDestination->checkAttributes() ; 
    5052  if (algo->operation.isEmpty()) 
    5153    ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", 
     
    7577 
    7678  } 
    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(); 
    7885 
    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 
    8093  this->computeAlgorithm(scalarSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ;  
    8194} 
    8295CATCH 
     96 
     97shared_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} 
    83103 
    84104CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar() 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/scalar_algorithm/scalar_algorithm_reduce_scalar.hpp

    r2270 r2291  
    4242                                                std::map<int, int>& elementPositionInGridDst2AxisPosition, 
    4343                                                std::map<int, int>& elementPositionInGridDst2DomainPosition); 
     44  virtual shared_ptr<CGridAlgorithm> createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos); 
    4445  static bool dummyRegistered_; 
    4546}; 
Note: See TracChangeset for help on using the changeset viewer.