Changeset 2318


Ignore:
Timestamp:
03/30/22 13:51:09 (2 years ago)
Author:
jderouillat
Message:

Add a checksum ability in xios_send/recv_field, enabled with info_level > 100.

Location:
XIOS/dev/dev_ym/XIOS_COUPLING/src/node
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp

    r2311 r2318  
    179179 
    180180        template <int N> void setData(const CArray<double, N>& _data); 
     181        void checkSumLike( const double* array, int numElements, bool output ) const; 
    181182        static bool dispatchEvent(CEventServer& event); 
    182183        static bool isCollectiveEvent(CEventServer& event); 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field_impl.hpp

    r1973 r2318  
    2020    { 
    2121      if (check_if_active.isEmpty() || (!check_if_active.isEmpty() && (!check_if_active) || isActive(true))) 
     22      { 
     23        if ( info.getLevel()>100  ) 
     24        { 
     25          const double* array = _data.dataFirst(); 
     26          int numElements( _data.numElements() ); 
     27          checkSumLike( array, numElements, true ); 
     28        } 
    2229        modelToClientSourceFilter_->streamData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 
     30      } 
    2331    } 
    2432    else if (instantDataFilter) 
     
    2735  } 
    2836  CATCH_DUMP_ATTR 
     37   
    2938 
    3039  template <int N> 
     
    3544    { 
    3645      CDataPacket::StatusCode status = clientToModelStoreFilter_->getData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 
     46      if ( info.getLevel()>100  ) 
     47      { 
     48        const double* array = _data.dataFirst(); 
     49        int numElements( _data.numElements() ); 
     50        checkSumLike( array, numElements, false ); 
     51      } 
    3752 
    3853      if (status == CDataPacket::END_OF_STREAM) 
     
    4762  } 
    4863  CATCH 
     64 
     65  void CField::checkSumLike( const double* array, int numElements, bool output ) const 
     66  { 
     67    int rk = CContext::getCurrent()->getIntraCommRank(); 
     68    int sz = CContext::getCurrent()->getIntraCommSize(); 
     69    MPI_Comm comm = CContext::getCurrent()->getIntraComm(); 
     70 
     71    double localSum( 0. ); 
     72    double error( 0. ); 
     73    unsigned long long checkSum( 0 ); 
     74    for ( int i=0 ; i<numElements ; i++ ) { 
     75      bool contributes( true );       
     76      if ( (!output) && ( !default_value.isEmpty() ) ) 
     77      { 
     78        if ( fabs(array[i]) > 0) 
     79          if ( fabs(array[i]-default_value.getValue())/array[i] < 2e-16 ) 
     80            contributes = false; 
     81      } 
     82      if (contributes) 
     83      { 
     84        double y = array[i] - error; 
     85        double t = localSum + y; 
     86        error = (t - localSum) - y; 
     87        localSum = t; 
     88       
     89        checkSum += *((unsigned long long*)(&array[i])); 
     90        checkSum = checkSum%LLONG_MAX; 
     91      } 
     92    } 
     93 
     94    double globalSum( 0. ); 
     95    unsigned long long globalCheck( 0 ); 
     96 
     97    if ( rk ==0 ) 
     98    { 
     99      MPI_Status status; 
     100      globalSum = localSum; // rank 0 contribution 
     101      globalCheck = checkSum; 
     102      for ( int irk = 1 ; irk < sz ; irk++ ) 
     103      { 
     104        MPI_Recv( &localSum, 1, MPI_DOUBLE, irk, 0, comm, &status ); 
     105        double y = localSum - error; 
     106        double t = globalSum + y; 
     107        error = (t - globalSum) - y; 
     108        globalSum = t; 
     109     
     110        MPI_Recv( &checkSum, 1, MPI_UNSIGNED_LONG_LONG, irk, 1, comm, &status ); 
     111        globalCheck += checkSum; 
     112        globalCheck = globalCheck%LLONG_MAX; 
     113      } 
     114    } 
     115    else 
     116    { 
     117      MPI_Send( &localSum, 1, MPI_DOUBLE, 0, 0, comm ); 
     118      MPI_Send( &checkSum, 1, MPI_UNSIGNED_LONG_LONG, 0, 1, comm ); 
     119    } 
     120     
     121    if ( rk == 0 ) 
     122    { 
     123      info(100) << setprecision(DBL_DIG); 
     124      if (output ) 
     125        info(100) << "Check Output key field for : " << getId() << ", key =  " << globalCheck << ", sum = " << globalSum << endl; 
     126      else 
     127        info(100) << "Check Input key field for : " << getId() << ", key =  " << globalCheck << ", sum = " << globalSum << endl; 
     128      info(100) << setprecision(6); 
     129    } 
     130  } 
     131 
    49132} // namespace xios 
    50133 
Note: See TracChangeset for help on using the changeset viewer.