[petsc-users] Load Vec from 1D HDF5 dataset

Barry Smith bsmith at mcs.anl.gov
Thu Mar 19 12:17:06 CDT 2015


  Please email the file in.h5 so we can try to reproduce the problem and debug it. Are you using petsc version 3.5.? 

  Barry

> On Mar 19, 2015, at 4:19 AM, Håkon Strandenes <haakon at hakostra.net> wrote:
> 
> Hi,
> 
> I am again in trouble with PETSc and its HDF5-related functions.
> 
> I have a code in which I want to read a 1D dataset from a HDF5 file into a PETSc Vec. The array are "small", and each MPI process should read the entire dataset and store it in its own sequential Vec.
> 
> Currently my code is as follows (somewhat simplified):
> 
> VecCreate(PETSC_COMM_SELF, &v);
> VecSetType(v, VECSEQ);
> PetscObjectSetName((PetscObject)v, "x");
> PetscViewerHDF5Open(PETSC_COMM_WORLD, "in.h5", FILE_MODE_READ, &viewer);
> VecLoad(v, viewer);
> 
> This works, but only if the dataset in the HDF5 file is a 2D dataset, of size Nx1, where N is the number of elements I read. If the dataset in the HDF5 file is of size N (i.e. a 1D dataset) this does not work.
> 
> The error message I get is the following:
> [0]PETSC ERROR: Unexpected data in file
> [0]PETSC ERROR: Dimension of array in file 1 not 2 as expected
> etc. and it points back to the line 296 in file vecio.c, function VecLoad_HDF5().
> 
> Technically this is not a problem. I could of course just go ahead and "reshape" all my datasets into 2D datasets. I do however find this behaviour very un-logical. Why can't I read a 1D dataset into a Vec?
> 
> So my question are:
> 1) Do I do anything wrong when creating my Vec and reading my datasets?
> 2) Is there anything I can do to read my 1D datasets into Vecs?
> 3) Could PETSc perhaps be a little less restrictive in these cases?
> 
> Thanks in advance.
> 
> Regards,
> Håkon Strandenes



More information about the petsc-users mailing list