Changeset 2529 for XIOS3/trunk/src


Ignore:
Timestamp:
07/18/23 15:12:50 (12 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/trunk/src
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/config/field_attribute.conf

    r2479 r2529  
    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/trunk/src/io/nc4_data_output.cpp

    r2507 r2529  
    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/trunk/src/io/netCdfInterface.cpp

    r2426 r2529  
    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/trunk/src/io/netCdfInterface.hpp

    r1639 r2529  
    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/trunk/src/io/onetcdf4.cpp

    r2481 r2529  
    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/trunk/src/io/onetcdf4.hpp

    r2481 r2529  
    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.