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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp

    r2274 r2291  
    276276     This check should be done in the very beginning of work flow 
    277277   */ 
     278    
    278279   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) ; 
    340283      initializeLocalElement() ; 
    341284      addFullView() ; 
     
    345288      checkAttributes_done_ = true ; 
    346289   } 
     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   } 
    347418   CATCH_DUMP_ATTR 
    348  
    349419 
    350420 
     
    352422      Check the validity of data, fill in values if any, and apply mask. 
    353423   */ 
    354    void CAxis::checkData() 
     424   bool CAxis::checkData(bool generateError) 
    355425   TRY 
    356426   { 
     
    363433      else if (data_n.getValue() < 0) 
    364434      { 
    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 ; 
    368439      } 
    369440 
     
    388459        if (data_index.numElements() != data_n) 
    389460        { 
    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 ; 
    393466        } 
    394467        for (int i = 0; i < data_n; ++i) 
     
    398471        } 
    399472      } 
    400  
     473      return true ; 
    401474   } 
    402475   CATCH_DUMP_ATTR 
    403476 
    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) 
    413481   TRY 
    414482   { 
     
    417485        if (mask.extent(0) != n) 
    418486        { 
    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 ; 
    424493        } 
    425494      } 
     
    429498        mask = true; 
    430499      } 
     500      return true ; 
    431501   } 
    432502   CATCH_DUMP_ATTR 
     
    435505     Check validity of bounds info and fill in values if any. 
    436506   */ 
    437    void CAxis::checkBounds() 
     507   bool CAxis::checkBounds(bool generateError) 
    438508   TRY 
    439509   { 
     
    441511     { 
    442512       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 ; 
    447518       hasBounds = true; 
    448519     } 
    449520     else hasBounds = false; 
     521     return true ; 
    450522   } 
    451523   CATCH_DUMP_ATTR 
    452524 
    453   void CAxis::checkLabel() 
     525  bool CAxis::checkLabel(bool generateError) 
    454526  TRY 
    455527  { 
     
    457529    { 
    458530      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 ; 
    463536      hasLabel = true; 
    464537    } 
    465538    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    
    468550 
    469551  
Note: See TracChangeset for help on using the changeset viewer.