Difficulties in reading from HDF5 file

Issue #70 resolved
Shyam Sankaran created an issue

While I was able to create a dump file, I'm unable to read from it using PETSc(I'm able to read the data just fine with h5py). I'd stored a petsc4py.PETSc._DMDA_Vec_array having size of(32, 3) with dof = 32 with the key 'distribution_function' inside 'file.h5'. This is what I tried to read from it:

viewer = PETSc.Viewer().createHDF5('file.h5', PETSc.Viewer.Mode.READ)
vec = PETSc.Vec().create()
vec.setName('distribution_function')
vec.load(viewer)

However, this gives me the error:

Error: error code 79
[0] VecLoad() line 975 in /home/hyperion/petsc/src/vec/vec/interface/vector.c
[0] VecLoad_Default() line 409 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
[0] VecLoad_HDF5() line 308 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
[0] Unexpected data in file
[0] Dimension of array in file is 3, not 1 as expected

Is there another way I'm supposed to go about this?

Comments (8)

  1. Lisandro Dalcin

    Could you please show the code you used to generate the file? I think you should not store the petsc4py.PETSc._DMDA_Vec_array object, this is just a convenience wrapper for global indexing around the underlying Vec's array.

  2. Shyam Sankaran reporter

    Sure. This is what I'm using:

    glob_f_value[:] = f #the distribution function array 
    viewer = PETSc.Viewer().createHDF5('file.h5', 'w')
    viewer(glob_f)
    

    where, I'd defined:

    da_f = PETSc.DMDA().create([32, 3],
                               dof=3,
                               stencil_width=3,
                               boundary_type=('periodic', 'periodic'),
                               proc_sizes=(PETSc.DECIDE, PETSc.DECIDE),
                               stencil_type=1,
                               comm=PETSc.COMM_WORLD)
    glob_f       = da_f.createGlobalVec()
    glob_f_value = da_f.getVecArray(glob_f)
    PETSc.Object.setName(glob_f, 'distribution_function')
    
  3. Lisandro Dalcin

    I think the problem is that you have to load to a Vec that is created from a DMDA with the same global sizes as the one you used to dump.

    @knepley Could you please help me with this one?

  4. Matthew Knepley

    Since you have dof=3, the Vec generated from the DA has bs=3. The vector you input has bs=1. It needs to either have bs=3 or bs=-1 (meaning unset) for the load to go through correctly.

  5. Shyam Sankaran reporter

    I tried doing this:

    viewer = PETSc.Viewer().createHDF5('file.h5', PETSc.Viewer.Mode.READ)
    vec = PETSc.Vec().create()
    vec.setBlockSize(3)
    vec.setName('distribution_function')
    vec.load(viewer)
    

    This gave me the following error:

    Error: error code 79
    [0] VecLoad() line 975 in /home/hyperion/petsc/src/vec/vec/interface/vector.c
    [0] VecLoad_Default() line 409 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
    [0] VecLoad_HDF5() line 303 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
    [0] Unexpected data in file
    [0] Block size of array in file is 2, not 3 as expected
    

    Even if I set the block size to 2, I get the error:

    Error: error code 79
    [0] VecLoad() line 975 in /home/hyperion/petsc/src/vec/vec/interface/vector.c
    [0] VecLoad_Default() line 409 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
    [0] VecLoad_HDF5() line 306 in /home/hyperion/petsc/src/vec/vec/utils/vecio.c
    [0] Unexpected data in file
    [0] Dimension of array in file is 3, not 2 as expected with bs = 2
    
  6. Matthew Knepley

    Please send a small code that completely reproduces. I cannot reproduce it here.

    Thanks

     Matt
    
  7. Shyam Sankaran reporter

    So, I've realized that if I create a DMDA object and use that to create the global Vec which will load the data, everything works out fine.

    However, I can't seem to get loading of data to work using PETSc.Vec().

    This snippet shows the test codes I used to create and read the data.

  8. Log in to comment