[petsc-users] Loading contents of hdf5 file into Mat object

Martin Schiødt maschi at mek.dtu.dk
Mon May 16 09:40:23 CDT 2022


Dear petsc-expert!

I am having trouble loading the contents of my hdf5 dataset - "Vp" - 
into the Mat object Vp using MatLoad. When I try to do this, I get the 
error message displayed below.

The hdf5 file I am trying to read, was originally created in Matlab with 
their built in function h5write. I am wondering whether this is the 
source of the problem? Nonetheless, a screendump of the file's structure 
can be seen here:

I have tried following a few of your examples as inspiration, however 
there may of course still be a problem in my code. I have appended the 
code below here (it is a short program, so I hope it is ok! - and please 
disregard the red error-squiggles - these are not true).

I hope you are able to help with my problem.

Best regards,

Martin

staticcharhelp[]= "Reads a HDF5 into a PETSC matrix.\n\n";
#include"../../petsc/include/petscsys.h"
#include"../../petsc/include/petscmat.h"
#include"../../petsc/include/petscviewerhdf5.h"
intmain(intargc, char**argv)
{
MatVp;
PetscViewerviewer;
charfile[PETSC_MAX_PATH_LEN]="../../Desktop/OnewaySimulations/Realization_1.h5";
charVp_name[128]="Vp";
PetscBoolflg;
PetscInitialize(&argc, &argv, (char*)0, help);
// Determine from which file we read the matrix
PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);
// Read
PetscViewerHDF5Open(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);
// Load matrix
MatCreate(PETSC_COMM_WORLD, &Vp);
PetscObjectSetName((PetscObject)Vp, Vp_name);
MatSetFromOptions(Vp);
MatLoad(Vp,viewer);
// Destroy
PetscViewerDestroy(&viewer);
MatDestroy(&Vp);
PetscFinalize();
return0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220516/d3c783fd/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AA0qWUjvJt0LdFH6.png
Type: image/png
Size: 69771 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220516/d3c783fd/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: e6nBGT0GcsizHRnE.png
Type: image/png
Size: 8314 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220516/d3c783fd/attachment-0003.png>


More information about the petsc-users mailing list