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 < [email protected]> 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; > } >
