Changeset 2386


Ignore:
Timestamp:
07/26/22 15:26:52 (23 months ago)
Author:
jderouillat
Message:

Set the code structure to compute the hash value of an element based on its attributs, use for now before writing an element in a file

Location:
XIOS3/trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/attribute.hpp

    r2146 r2386  
    4444            virtual StdString dumpGraph(void) const = 0; 
    4545            virtual bool isEqual(const CAttribute& ) = 0; 
     46            virtual int computeHash(void) = 0; 
    4647 
    4748            //! Returns true if and only if the attribute should be publicly exposed in the API 
  • XIOS3/trunk/src/attribute_array.hpp

    r2146 r2386  
    4444                         
    4545            bool isEqual(const CAttribute& attr); 
     46            int computeHash(void); 
    4647 
    4748            /// Destructeur /// 
  • XIOS3/trunk/src/attribute_array_impl.hpp

    r2305 r2386  
    117117      else return false;   
    118118    } 
     119   
     120    template <typename T_numtype, int N_rank> 
     121    int CAttributeArray<T_numtype,N_rank>::computeHash(void) 
     122    { 
     123      ERROR("CAttributeArray::computeHash(void)", 
     124       << "NOT IMPLEMENTED FOR NOW !"); 
     125      return std::hash<string>{}( toString() ); 
     126    } 
    119127 
    120128    template <typename T_numtype, int N_rank> 
  • XIOS3/trunk/src/attribute_enum.hpp

    r2146 r2386  
    5252             
    5353            bool isEqual(const CAttribute& attr ); 
     54            int computeHash(void); 
    5455 
    5556            /// Destructeur /// 
  • XIOS3/trunk/src/attribute_enum_impl.hpp

    r2305 r2386  
    126126  } 
    127127 
     128  template <class T> 
     129  int CAttributeEnum<T>::computeHash(void) 
     130  { 
     131    // Basic hash computation through string 
     132    return std::hash<string>{}( toString() ); 
     133  } 
     134 
    128135  //--------------------------------------------------------------- 
    129136 
  • XIOS3/trunk/src/attribute_map.cpp

    r2146 r2386  
    269269      } 
    270270 
     271      /*! 
     272        Compute the hash value of current attribute map excluding some attributs. 
     273        \param [in] excludedAttrs attribute to be excluded from hash computation 
     274      */ 
     275      int CAttributeMap::computeGlobalAttributesHash(const vector<StdString>& excludedAttrs) 
     276      { 
     277         int attrs_hash( 0 ); 
     278         typedef std::pair<StdString, CAttribute*> StdStrAttPair; 
     279 
     280         SuperClassMap::const_iterator it = this->begin(), end = this->end(); 
     281         for (; it != end; it++) 
     282         { 
     283            const StdStrAttPair& el = *it; 
     284            if ( std::find( excludedAttrs.begin(), excludedAttrs.end(), el.first ) == excludedAttrs.end() ) 
     285            { 
     286              if (this->hasAttribute(el.first)) 
     287              { 
     288                if (!el.second->isEmpty()) 
     289                { 
     290                  attrs_hash += el.second->computeHash(); 
     291                } 
     292              } 
     293            } 
     294         } 
     295         return attrs_hash; 
     296      } 
     297   
    271298      //--------------------------------------------------------------- 
    272299/* 
  • XIOS3/trunk/src/attribute_map.hpp

    r2146 r2386  
    3737            void setAttributes(const CAttributeMap * const _parent, bool apply=true); 
    3838            void duplicateAttributes(const CAttributeMap* const _parent); 
     39            int computeGlobalAttributesHash(const vector<StdString>& excludedAttrs); 
    3940            void clearAllAttributes(void); 
    4041            StdString dumpXiosAttributes(void) const; 
  • XIOS3/trunk/src/attribute_template.hpp

    r2146 r2386  
    6161             
    6262            bool isEqual(const CAttribute& attr ); 
     63            int computeHash(void); 
    6364 
    6465            /// Destructeur /// 
  • XIOS3/trunk/src/attribute_template_impl.hpp

    r2305 r2386  
    168168      if (!this->isEmpty() && !attr.isEmpty())  return (this->getValue() == attr.getValue()); 
    169169      else return false; 
     170    } 
     171 
     172    template <class T> 
     173    int CAttributeTemplate<T>::computeHash(void) 
     174    { 
     175      // Basic hash computation through string 
     176      return std::hash<string>{}( toString() ); 
    170177    } 
    171178 
  • XIOS3/trunk/src/io/nc4_data_output.cpp

    r2385 r2386  
    7878         if (!domain->lonvalue.isEmpty() ) 
    7979         { 
    80            int globalSize = domain->ni_glo.getValue()*domain->nj_glo.getValue(); 
    81            CArray<size_t,1> globalIndex; // No redundancy globalIndex will be computed with the connector 
    82            shared_ptr<CGridTransformConnector> gridTransformConnector; 
    83            // Compute a without redundancy element FULL view to enable a consistent hash computation 
    84            domain->getLocalView(CElementView::FULL)->createWithoutRedundancyFullViewConnector( globalSize, comm_file, gridTransformConnector, globalIndex ); 
    85            int localSize = globalIndex.numElements(); 
    86             
    87            CArray<double,1> lon_distributedValue, lat_distributedValue ; 
    88            gridTransformConnector->transfer(domain->lonvalue, lon_distributedValue ); 
    89            gridTransformConnector->transfer(domain->latvalue, lat_distributedValue ); 
    90  
    91            // Compute the distributed hash (v0) of the element 
    92            // it will be associated to the default element name (= map key), and to the name really written 
    93            int localHash = 0; 
    94            for (int iloc=0; iloc<localSize ; iloc++ ) localHash+=globalIndex(iloc)*lon_distributedValue(iloc)*lat_distributedValue(iloc); 
    95            int globalHash(0); 
    96            MPI_Allreduce( &localHash, &globalHash, 1, MPI_INT, MPI_SUM, comm_file  ); 
    97           
     80           // The hash of the element will be associated to the default element name (= map key), and to the name really written 
     81           int globalHash = domain->computeAttributesHash( comm_file ); // Need a MPI_Comm to distribute without redundancy some attributs (value) 
     82 
    9883           StdString defaultNameKey = domain->getDomainOutputName(); 
    9984           if ( !relDomains_.count ( defaultNameKey ) ) 
     
    10561041        if (!axis->value.isEmpty() ) 
    10571042        { 
    1058            int globalSize = axis->n_glo.getValue(); 
    1059            CArray<size_t,1> globalIndex; // No redundancy globalIndex will be computed with the connector 
    1060            shared_ptr<CGridTransformConnector> gridTransformConnector; 
    1061            // Compute a without redundancy element FULL view to enable a consistent hash computation 
    1062            axis->getLocalView(CElementView::FULL)->createWithoutRedundancyFullViewConnector( globalSize, comm_file, gridTransformConnector, globalIndex ); 
    1063            int localSize = globalIndex.numElements(); 
    1064  
    1065           CArray<double,1> distributedValue ; 
    1066           gridTransformConnector->transfer(axis->value, distributedValue ); 
    1067          
    1068           // Compute the distributed hash (v0) of the element 
    1069           // it will be associated to the default element name (= map key), and to the name really written 
    1070           int localHash = 0; 
    1071           for (int iloc=0; iloc<localSize ; iloc++ ) localHash+=globalIndex(iloc)*distributedValue(iloc); 
    1072           int globalHash(0); 
    1073           MPI_Allreduce( &localHash, &globalHash, 1, MPI_INT, MPI_SUM, comm_file  ); 
     1043          // The hash of the element will be associated to the default element name (= map key), and to the name really written 
     1044          int globalHash = axis->computeAttributesHash( comm_file ); // Need a MPI_Comm to distribute without redundancy some attributs (value) 
    10741045 
    10751046          StdString defaultNameKey = axis->getAxisOutputName(); 
  • XIOS3/trunk/src/node/axis.cpp

    r2343 r2386  
    302302     bounds.reset(); 
    303303     label.reset() ; 
     304   } 
     305 
     306   int CAxis::computeAttributesHash( MPI_Comm comm ) 
     307   { 
     308     int axis_hash = 0; 
     309      
     310     // Compute the hash of distributed attributs (value ...) 
     311     int globalSize = this->n_glo.getValue(); 
     312     CArray<size_t,1> globalIndex; // No redundancy globalIndex will be computed with the connector 
     313     shared_ptr<CGridTransformConnector> gridTransformConnector; 
     314     // Compute a without redundancy element FULL view to enable a consistent hash computation (and a distributed globalIndex) 
     315     this->getLocalView(CElementView::FULL)->createWithoutRedundancyFullViewConnector( globalSize, comm, gridTransformConnector, globalIndex ); 
     316     int localSize = globalIndex.numElements(); 
     317 
     318     CArray<double,1> distributedValue ; 
     319     gridTransformConnector->transfer(this->value, distributedValue ); 
     320         
     321     int localHash = 0; 
     322     for (int iloc=0; iloc<localSize ; iloc++ ) localHash+=globalIndex(iloc)*distributedValue(iloc); 
     323     int distributedHash = 0; 
     324     MPI_Allreduce( &localHash, &distributedHash, 1, MPI_INT, MPI_SUM, comm  ); 
     325 
     326     // Compute the hash of global attributs (unit, prec ...) 
     327     vector<StdString> excludedAttr; 
     328     //excludedAttr.push_back("name"); 
     329     // internal attributs 
     330     excludedAttr.insert(excludedAttr.end(), { "index", "data_n", "data_begin", "data_index"  }); 
     331     excludedAttr.insert(excludedAttr.end(), { "begin", "n" });      
     332     excludedAttr.push_back("axis_ref"); 
     333     // in distributed 
     334     excludedAttr.push_back("value"); 
     335     // should be considered in distributed 
     336     excludedAttr.push_back("bounds"); 
     337     excludedAttr.push_back("label"); 
     338     excludedAttr.push_back("mask"); // ??? 
     339 
     340     int globalHash = this->computeGlobalAttributesHash( excludedAttr ); 
     341 
     342     return distributedHash + globalHash; 
    304343   } 
    305344 
  • XIOS3/trunk/src/node/axis.hpp

    r2326 r2386  
    130130         void resetGeometricAttributes(void) ; 
    131131 
     132         int computeAttributesHash( MPI_Comm comm ); 
     133 
    132134         size_t getGlobalWrittenSize(void) ; 
    133135 
  • XIOS3/trunk/src/node/domain.cpp

    r2343 r2386  
    17701770   CATCH_DUMP_ATTR 
    17711771 
     1772   int CDomain::computeAttributesHash( MPI_Comm comm ) 
     1773   { 
     1774     int domain_hash = 0; 
     1775      
     1776     // Compute the hash of distributed attributs (value ...) 
     1777     int globalSize = this->ni_glo.getValue()*this->nj_glo.getValue(); 
     1778     CArray<size_t,1> globalIndex; // No redundancy globalIndex will be computed with the connector 
     1779     shared_ptr<CGridTransformConnector> gridTransformConnector; 
     1780     // Compute a without redundancy element FULL view to enable a consistent hash computation 
     1781     this->getLocalView(CElementView::FULL)->createWithoutRedundancyFullViewConnector( globalSize, comm, gridTransformConnector, globalIndex ); 
     1782     int localSize = globalIndex.numElements(); 
     1783            
     1784     CArray<double,1> lon_distributedValue, lat_distributedValue ; 
     1785     gridTransformConnector->transfer(this->lonvalue, lon_distributedValue ); 
     1786     gridTransformConnector->transfer(this->latvalue, lat_distributedValue ); 
     1787 
     1788     // Compute the distributed hash (v0) of the element 
     1789     // it will be associated to the default element name (= map key), and to the name really written 
     1790     int localHash = 0; 
     1791     for (int iloc=0; iloc<localSize ; iloc++ ) localHash+=globalIndex(iloc)*lon_distributedValue(iloc)*lat_distributedValue(iloc); 
     1792     int distributedHash = 0; 
     1793     MPI_Allreduce( &localHash, &distributedHash, 1, MPI_INT, MPI_SUM, comm  ); 
     1794      
     1795     // Compute the hash of global attributs (unit, prec ...) 
     1796     vector<StdString> excludedAttr; 
     1797     //excludedAttr.push_back("name"); 
     1798     // internal attributs 
     1799     excludedAttr.insert(excludedAttr.end(), { "ibegin", "jbegin", "ni", "nj", "i_index", "j_index" }); 
     1800     excludedAttr.insert(excludedAttr.end(), { "data_ni", "data_nj", "data_ibegin", "data_jbegin" }); 
     1801     excludedAttr.insert(excludedAttr.end(), { "data_i_index", "data_j_index", "domain_ref" }); 
     1802     // in distributed through lonvalue and latvalue 
     1803     excludedAttr.insert(excludedAttr.end(), { "lonvalue_1d", "latvalue_1d", "lonvalue_2d", "latvalue_2d" }); 
     1804     // should be considered in distributed 
     1805     excludedAttr.insert(excludedAttr.end(), { "mask_1d", "mask_2d" }); // ??? 
     1806     excludedAttr.insert(excludedAttr.end(), { "bounds_lon_1d", "bounds_lat_1d", "bounds_lon_2d", "bounds_lat_2d" }); 
     1807     excludedAttr.insert(excludedAttr.end(), { "area" }); 
     1808     // private 
     1809     excludedAttr.insert(excludedAttr.end(), { "lon_start", "lon_end", "lat_start", "lat_end" }); 
     1810     excludedAttr.insert(excludedAttr.end(), { "bounds_lon_start", "bounds_lon_end", "bounds_lat_start", "bounds_lat_end" }); 
     1811     excludedAttr.insert(excludedAttr.end(), { "has_lat_in_read_file", "has_lon_in_read_file", "has_bounds_lat_in_read_file", "has_bounds_lon_in_read_file" }); 
     1812     excludedAttr.insert(excludedAttr.end(), { "lonvalue_rectilinear_read_from_file", "latvalue_rectilinear_read_from_file", "lonvalue_curvilinear_read_from_file", "latvalue_curvilinear_read_from_file" }); 
     1813     excludedAttr.insert(excludedAttr.end(), { "bounds_lonvalue_curvilinear_read_from_file", "bounds_latvalue_curvilinear_read_from_file", "lonvalue_unstructured_read_from_file", "latvalue_unstructured_read_from_file" }); 
     1814     excludedAttr.insert(excludedAttr.end(), { "bounds_lonvalue_unstructured_read_from_file", "bounds_latvalue_unstructured_read_from_file" }); 
     1815      
     1816     int globalHash = this->computeGlobalAttributesHash( excludedAttr ); 
     1817 
     1818     return distributedHash + globalHash; 
     1819   } 
    17721820 
    17731821   void CDomain::initializeLocalElement(void) 
  • XIOS3/trunk/src/node/domain.hpp

    r2326 r2386  
    9191         bool checkAttributes_done_ = false ; 
    9292 
     93         int computeAttributesHash( MPI_Comm comm ); 
    9394          
    9495      ////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.