Changeset 2530


Ignore:
Timestamp:
07/19/23 09:07:54 (10 months ago)
Author:
jderouillat
Message:

Enable parallel compression regarding NetCDF & HDF5 configurations at compile time. Implement an API to use HDF5 lossy compression plugins (SZ is available for now).

Location:
XIOS3/branches/xios-3.0-beta
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/branches/xios-3.0-beta/make_xios

    r2213 r2530  
    212212fi  
    213213 
     214 
     215# Detecting if parallel compression is available : 
     216#   - NetCDF is HDF5 based and >= 4.7.4  ? 
     217#   - HDF5   is parallel   and >= 1.10.3 ? 
     218USE_HDF5=0 
     219if [[ ! -z $NETCDF_INCDIR ]] 
     220then 
     221    NETCDF_LOOKUP=`echo ${NETCDF_INCDIR} | sed 's/\-I/\ /g'` 
     222    netcdf_meta_file=`find $NETCDF_LOOKUP -name netcdf_meta.h 2> /dev/null` 
     223else 
     224    for dir in `echo $CPATH | sed 's/\:/\ /g'` ; do 
     225        if [ -f "$dir/netcdf_meta.h" ] 
     226        then 
     227            netcdf_meta_file=$dir/netcdf_meta.h 
     228            break 
     229        fi 
     230    done 
     231fi 
     232if [[ ! -z $netcdf_meta_file ]] 
     233then 
     234    NC_MAJOR=`grep "NC_VERSION_MAJOR" $netcdf_meta_file | awk '{ print $3 }'` 
     235    NC_MINOR=`grep "NC_VERSION_MINOR" $netcdf_meta_file | awk '{ print $3 }'` 
     236    NC_PATCH=`grep "NC_VERSION_PATCH" $netcdf_meta_file | awk '{ print $3 }'` 
     237    if ( [[ "$NC_MAJOR" -ge 5 || ( "$NC_MAJOR" -eq 4 &&  "$NC_MINOR" -ge 8 )|| ( "$NC_MAJOR" -eq 4 && "$NC_MINOR" -eq 7 && "$NC_PATCH" -ge 4 ) ]] ) 
     238    then 
     239        USE_HDF5=`grep NC_HAS_HDF5 $netcdf_meta_file | awk '{ print $3 }'` 
     240    fi 
     241fi 
     242 
     243if [ "$USE_HDF5" == "1" ] 
     244then 
     245    # https://forum.hdfgroup.org/t/parallel-compression-support-detection/5398     
     246    if [[ ! -z $HDF5_LIBDIR ]] 
     247    then 
     248        HDF5_LOOKUP=`echo ${HDF5_LIBDIR} | sed 's/\-L/\ /g'` 
     249        hdf5_settings_file=`find $HDF5_LOOKUP -name libhdf5.settings 2> /dev/null` 
     250    else 
     251        for dir in `echo $LD_LIBRARY_PATH | sed 's/\:/\ /g'` ; do 
     252            if [ -f "$dir/libhdf5.settings" ] 
     253            then 
     254                hdf5_settings_file=$dir/libhdf5.settings 
     255                break 
     256            fi 
     257        done 
     258    fi 
     259    HDF5_VERSION=`grep "HDF5 Version" $hdf5_settings_file | awk -F  ':' '{ print $2 }'` 
     260    HDF5_MAJOR_VERSION=`echo $HDF5_VERSION | awk -F  '.' '{ print $2 }'` 
     261    HDF5_MINOR_VERSION=`echo $HDF5_VERSION | awk -F  '.' '{ print $3 }'` 
     262    HDF5_PARALLEL=`grep "Parallel HDF5" $hdf5_settings_file | awk -F  ':' '{ print $2 }'` 
     263    HDF5_DEFLATE=`grep "I/O filters (external)" $hdf5_settings_file | awk -F  ':' '{ print $2 }'` 
     264    if ( [[ "$HDF5_MAJOR_VERSION" -ge 11 || ( "$HDF5_MAJOR_VERSION" -eq 10 &&  "$HDF5_MINOR_VERSION" -ge 3 ) ]] ) 
     265    then 
     266        if [[ "$HDF5_PARALLEL" =~ "yes" && "$HDF5_DEFLATE" =~ "zlib" ]] 
     267        then  
     268            XIOS_CPPKEY="$XIOS_CPPKEY PARALLEL_COMPRESSION" 
     269        fi 
     270    fi           
     271fi 
     272if [[ "$XIOS_CPPKEY" =~ "PARALLEL_COMPRESSION" ]] 
     273then 
     274    echo "->Parallel compression is available" 
     275else 
     276    echo "->Parallel compression is NOT available"     
     277fi 
     278# End "Detecting if parallel compression is available" 
     279 
     280 
    214281# Setting path for boost 
    215282if [[ "$use_extern_boost" == "true" ]] 
  • XIOS3/branches/xios-3.0-beta/src/config/field_attribute.conf

    r2478 r2530  
    3333DECLARE_ATTRIBUTE(double,    scale_factor) 
    3434 
     35DECLARE_ATTRIBUTE(StdString, compression_type) 
    3536DECLARE_ATTRIBUTE(int,       compression_level) 
     37DECLARE_ARRAY(double , 1,    compression_params) 
    3638DECLARE_ATTRIBUTE(double,    chunking_blocksize_target) 
    3739 
  • XIOS3/branches/xios-3.0-beta/src/io/nc4_data_output.cpp

    r2516 r2530  
    19481948            if (field->compression_level.isEmpty()) 
    19491949              field->compression_level = field->getRelFile()->compression_level.isEmpty() ? 0 : field->getRelFile()->compression_level; 
    1950             SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 
     1950            else 
     1951              field->compression_type.setValue( "gzip" ); 
     1952            if (field->compression_type.isEmpty()) 
     1953              field->compression_type = "None"; 
     1954            if (field->compression_params.isEmpty()) 
     1955              field->compression_params.resize( 0 ); 
     1956            SuperClassWriter::setCompressionLevel(fieldid, field->compression_type, field->compression_level, field->compression_params); 
    19511957 
    19521958           {  // Ecriture des coordonnes 
  • XIOS3/branches/xios-3.0-beta/src/io/netCdfInterface.cpp

    r2427 r2530  
    1111#include "netCdfException.hpp" 
    1212#include "mem_checker.hpp" 
     13#include <string> 
     14#include <sys/stat.h> 
    1315 
    1416namespace xios 
     
    776778    throw CNetCdfException(e); 
    777779  } 
    778  
     780   
     781  return status; 
     782} 
     783 
     784int CNetCdfInterface::defVarFilter(int ncid, int varId, unsigned int filterId , size_t filterNbrParams, unsigned int* filterParams) 
     785{ 
     786  const char* cplugin = getenv("HDF5_PLUGIN_PATH") ; 
     787  bool filterAvailable( false ); 
     788   
     789  StdString pluginLibName; 
     790  if ( filterId == 32017 ) // 32017 = SZ 
     791  { 
     792    pluginLibName = "libhdf5sz.so"; 
     793  } 
     794  if (cplugin) 
     795  { 
     796    string plugin( cplugin ); 
     797    string libsz( plugin+"/"+pluginLibName ); 
     798    struct stat sb; 
     799    if (stat(libsz.c_str(), &sb) == 0) filterAvailable = true; 
     800  } 
     801  if (!filterAvailable) 
     802  { 
     803    StdStringStream sstr; 
     804    sstr << "Error when calling function nc_def_var_filter(...)" << std::endl; 
     805    sstr << "The SZ filter required for " << varId << " is not available." 
     806         << "Check that $HDF5_PLUGIN_PATH/"<< pluginLibName <<" exists." ; 
     807    StdString e = sstr.str(); 
     808    throw CNetCdfException(e); 
     809  } 
     810  
     811  int status = nc_def_var_filter(ncid, varId, filterId, filterNbrParams, filterParams); 
     812  if (NC_NOERR != status) 
     813  { 
     814    StdString errormsg(nc_strerror(status)); 
     815    StdStringStream sstr; 
     816     
     817    sstr << "Error when calling function nc_def_var_filter(...)" << std::endl; 
     818    sstr << errormsg << std::endl; 
     819    sstr << "Unable to set the compression filter of the variable with id: " << varId 
     820         << " and plugin: " << filterId << std::endl; 
     821    StdString e = sstr.str(); 
     822    throw CNetCdfException(e); 
     823  } 
     824   
    779825  return status; 
    780826} 
  • XIOS3/branches/xios-3.0-beta/src/io/netCdfInterface.hpp

    r1639 r2530  
    116116    static int defVarDeflate(int ncid, int varId, int compressionLevel); 
    117117 
     118    //! Define variable filter 
     119    static int defVarFilter(int ncid, int varId, unsigned int filterId , size_t filterNbrParams, unsigned int* filterParams ); 
     120 
    118121    //! Set or unset the fill mode 
    119122    static int setFill(int ncid, bool fill); 
     
    121124    //! Define variable fill parameters 
    122125    static int defVarFill(int ncid, int varId, int noFill, void* fillValue); 
    123  
    124126 
    125127    //! Change access type of a variable 
  • XIOS3/branches/xios-3.0-beta/src/io/onetcdf4.cpp

    r2480 r2530  
    22 
    33#include "onetcdf4.hpp" 
     4#include "onetcdf4_plugin.hpp" 
    45#include "group_template.hpp" 
    56#include "mpi.hpp" 
     
    505506            CNetCdfInterface::defVarFill(grpid, varid, true, NULL); 
    506507         } 
    507  
    508          setCompressionLevel(name, compressionLevel) ; 
    509508          
    510509         return varid; 
     
    513512      //--------------------------------------------------------------- 
    514513 
    515       void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel) 
     514      void CONetCDF4::setCompressionLevel(const StdString& varname, const StdString& compressionType, int compressionLevel, const CArray<double,1>& compressionParams) 
    516515      { 
    517516         if (compressionLevel < 0 || compressionLevel > 9) 
    518517           ERROR("void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)", 
    519518                 "Invalid compression level for variable \"" << varname << "\", the value should range between 0 and 9."); 
    520          if (compressionLevel && wmpi) 
     519#ifndef PARALLEL_COMPRESSION 
     520         if ( ((compressionLevel)||(compressionParams.numElements())) && wmpi) 
    521521           ERROR("void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)", 
    522522                 "Impossible to use compression for variable \"" << varname << "\" when using parallel mode."); 
     523#endif 
    523524         int grpid = this->getCurrentGroup(); 
    524525         int varid = this->getVariable(varname); 
    525          CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel); 
     526         if (compressionType=="None") 
     527         { 
     528         } 
     529         else if (compressionType=="gzip") 
     530         { 
     531           CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel); 
     532         } 
     533         else 
     534         { 
     535           size_t cd_nelmts; 
     536           unsigned int* cd_values = NULL; 
     537           if (compressionType=="SZ") 
     538           { 
     539             CONetCDF4Plugin::interpretParametersSZ(compressionParams, &cd_nelmts, &cd_values); 
     540             CNetCdfInterface::defVarFilter(grpid, varid, 32017, cd_nelmts, cd_values); 
     541           } 
     542           else 
     543           { 
     544               ERROR("void CONetCDF4::setCompressionLevel(...)", "compression_type = " << compressionType << " is not managed"); 
     545           } 
     546           if (cd_values!=NULL) delete [] cd_values; 
     547         } 
     548                       
    526549      } 
    527550 
  • XIOS3/branches/xios-3.0-beta/src/io/onetcdf4.hpp

    r2480 r2530  
    5959               void setDefaultValue(const StdString& varname, const T* value = NULL); 
    6060 
    61             void setCompressionLevel(const StdString& varname, int compressionLevel); 
     61            void setCompressionLevel(const StdString& varname, const StdString& compressionType, int compressionLevel,  
     62                                     const CArray<double,1>& compressionParam ); 
    6263 
    6364            template <class T>  void addAttribute (const StdString& name, const T& value, const StdString* varname = NULL); 
Note: See TracChangeset for help on using the changeset viewer.