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

Mark Adams mfadams at lbl.gov
Mon May 16 11:51:47 CDT 2022


https://petsc.org/main/docs/manualpages/Mat/MatLoad/

"Loads a matrix that has been stored in binary/HDF5 format with MatView()."

But there is a discussion on matlab format here.

On Mon, May 16, 2022 at 11:03 AM Martin Schiødt via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> 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
> static char help[] = "Reads a HDF5 into a PETSC matrix.\n\n";
> #include "../../petsc/include/petscsys.h"
> #include "../../petsc/include/petscmat.h"
> #include "../../petsc/include/petscviewerhdf5.h"
> int main (int argc, char **argv)
> {
> Mat Vp;
> PetscViewer viewer;
> char file[PETSC_MAX_PATH_LEN]=
> "../../Desktop/OnewaySimulations/Realization_1.h5";
> char Vp_name[128]="Vp";
> PetscBool flg;
> 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();
> return 0;
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220516/a40d46a6/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/a40d46a6/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/a40d46a6/attachment-0003.png>


More information about the petsc-users mailing list