Hi Matt, Roland and others,
@ Roland, I can create the Vec in Petsc, but want to load it with external
data. I can arrange that data in what ever way with Python. It is about two
vectors, each of length 4.6 x10^6 entries.
I have created a hdf5 file with Python and try to load it into PETSc which
gives me some errors. I added the small test script I am using. The error I am
getting is:
error: ‘PetscViewerHDF5Open’ was not declared in this scope; did you mean
‘PetscViewerVTKOpen’?
Am I using the wrong header?
Best,
Thijs
From: Matthew Knepley <[email protected]>
Sent: 03 March 2021 23:02
To: Smit Thijs <[email protected]>
Cc: [email protected]
Subject: Re: [petsc-users] Loading external array data into PETSc
On Wed, Mar 3, 2021 at 4:23 PM Smit Thijs
<[email protected]<mailto:[email protected]>> wrote:
Hi All,
I would like to readin a fairly large external vector into PETSc to be used
further. My idea was to write a hdf5 file using Python with the vector data.
Then read that hdf5 file into PETSc using PetscViewerHDF5Open and VecLoad. Is
this the advised way or is there a better alternative to achieve the same
(getting this external array data into PETSc)?
I think there are at least two nice ways to do this:
1) Use HDF5. Here you have to name your vector to match the HDF5 object
2) Use raw binary. This is a specific PETSc format, but it is fast and simple.
Thanks,
Matt
Best regards,
Thijs Smit
PhD Candidate
ETH Zurich
Institute for Biomechanics
--
What most experimenters take for granted before they begin their experiments is
infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/<http://www.cse.buffalo.edu/~knepley/>
#include <petsc.h>
#include <petscvec.h>
#include <petscviewerhdf5.h>
static char help[] = "Test HDF5\n\n";
int main(int argc, char* argv[]) {
// Error code for debugging
PetscErrorCode ierr;
// Initialize PETSc / MPI and pass input arguments to PETSc
PetscInitialize(&argc, &argv, PETSC_NULL, help);
Vec xPassive;
VecCreate(PETSC_COMM_WORLD, &xPassive);
PetscObjectSetName((PetscObject) xPassive, "xPassive");
VecSetSizes(xPassive, PETSC_DECIDE, 4614720);
VecSetFromOptions(xPassive);
PetscViewer viewin;
PetscViewerHDF5Open(PETSC_COMM_WORLD, "xPassive.h5", FILE_MODE_READ,
&viewin);
PetscViewerDestroy(&viewin);
VecDestroy(&xPassive);
PetscFinalize();
return 0;
}