#include "petsclayoutdf5.h" #include "petscis.h" PetscErrorCode PetscViewerHDF5ReadSizes(PetscViewer viewer, const char name[], PetscInt *bs, PetscInt *N)
viewer | - The HDF5 viewer | |
name | - The dataset name | |
map | - The layout which specifies array partitioning | |
datatype | - The HDF5 datatype of the items in the dataset |
map | - The set up layout (with global size and blocksize according to dataset) | |
newarr | - The partitioned array, a memory image of the given dataset |
PetscFunctionBegin; ierr = PetscViewerHDF5ReadInitialize_Private(viewer, name, &h);CHKERRQ(ierr); #if defined(PETSC_USE_COMPLEX) if (!h->complexVal) { H5T_class_t clazz = H5Tget_class(datatype); if (clazz == H5T_FLOAT) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"File contains real numbers but PETSc is configured for complex. The conversion is not yet implemented. Configure with --with-scalar-type=real."); } #else if (h->complexVal) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"File contains complex numbers but PETSc not configured for them. Configure with --with-scalar-type=complex."); #endif
ierr = PetscViewerHDF5ReadSizes_Private(viewer, h, PETSC_TRUE, &map);CHKERRQ(ierr); ierr = PetscViewerHDF5ReadSelectHyperslab_Private(viewer, h, map, &memspace);CHKERRQ(ierr);
unitsize = H5Tget_size(datatype); if (h->complexVal) unitsize *= 2; if (unitsize <= 0 || unitsize > PetscMax(sizeof(PetscInt),sizeof(PetscScalar))) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Sanity check failed: HDF5 function H5Tget_size(datatype) returned suspicious value %D",unitsize); ierr = PetscMalloc(map->n*unitsize, &arr);CHKERRQ(ierr);
ierr = PetscViewerHDF5ReadArray_Private(viewer, h, datatype, memspace, arr);CHKERRQ(ierr); PetscStackCallHDF5(H5Sclose,(memspace)); ierr = PetscViewerHDF5ReadFinalize_Private(viewer, &h);CHKERRQ(ierr); *newarr = arr; PetscFunctionReturn(0); }
/*@C PetscViewerHDF5ReadSizes - Read block size and global size of a vector (Vec or IS) stored in an HDF5 file.
viewer | - The HDF5 viewer | |
name | - The dataset name |
bs | - block size | |
N | - global size |
The dataset can be stored as a 2D dataspace even if its blocksize is 1; see PetscViewerHDF5SetBaseDimension2().