HDF5 slow writing datasets with fill_time_never

时间:2016-10-19 13:34:53

标签: c++ hdf5

I have a problem regarding hdf5 datasets with H5D_FILL_TIME_NEVER in the follwogin code. It creates an HDF5 File containing the Datasets Matrix1 and Matrix2, both with H5D_FILL_TIME_NEVER. If i remove the last block writing to Matrix2, the code runs in a few milliseconds. If the code is executed completely it seems to fill matrix1 as soon as i acces matrix2 which takes 16 seconds to execute. Is there a way to get reasonable performance here?

My usecase is the following: I retrieve data vector-vise and have to add it as a column to Matrix1 and as a row to Matrix2. There is no way to write Matrix1 first and then write Matrix2, i have to write them at the same time.

I am using HDF5 version 1.8.15 with Visual Studio 2012

auto file = H5::H5File( "E:\\test.h5", H5F_ACC_TRUNC );
file.flush( H5F_SCOPE_GLOBAL );

hsize_t rows = 1000;
hsize_t cols = 1000000;

{
    H5::DSetCreatPropList plist;
    plist.setFillTime( H5D_FILL_TIME_NEVER );
    plist.setAllocTime( H5D_ALLOC_TIME_LATE );
    hsize_t dims[2] = {rows, cols};
    H5::DataSet set1 = file.createDataSet( "/Matrix1", H5::PredType::NATIVE_DOUBLE, H5::DataSpace( 2, dims ), plist );
    set1.close();
    plist.close();
}
{
    H5::DSetCreatPropList plist;
    plist.setFillTime( H5D_FILL_TIME_NEVER );
    plist.setAllocTime( H5D_ALLOC_TIME_LATE );
    hsize_t dims[2] = {rows, cols};
    H5::DataSet set1 = file.createDataSet( "/Matrix2", H5::PredType::NATIVE_DOUBLE, H5::DataSpace( 2, dims ), plist );
    set1.close();
    plist.close();
}

{
    double value = 1;

    H5::DataSet set = file.openDataSet( "/Matrix1" );

    hsize_t matdims[2];
    matdims[0] = 1;
    matdims[1] = 1;
    H5::DataSpace memspace( 2, matdims );

    H5::DataSpace dataspace = set.getSpace();
    dataspace.selectNone();
    const hsize_t count[2] = {1, 1};
    const hsize_t start[2] = {0, 0};
    const hsize_t block[2] = {1, 1};
    dataspace.selectHyperslab( H5S_SELECT_SET, count, start, 0, block );

    set.write( &value,
               H5::PredType::NATIVE_DOUBLE,
               memspace,
               dataspace );

    set.close();
}

{
    double value = 1;

    H5::DataSet set = file.openDataSet( "/Matrix2" );

    hsize_t matdims[2];
    matdims[0] = 1;
    matdims[1] = 1;
    H5::DataSpace memspace( 2, matdims );

    H5::DataSpace dataspace = set.getSpace();
    dataspace.selectNone();
    const hsize_t count[2] = {1, 1};
    const hsize_t start[2] = {0, 0};
    const hsize_t block[2] = {1, 1};
    dataspace.selectHyperslab( H5S_SELECT_SET, count, start, 0, block );

    set.write( &value,
               H5::PredType::NATIVE_DOUBLE,
               memspace,
               dataspace );

    set.close();
}

0 个答案:

没有答案