petsc-master 2019-09-22
Report Typos and Errors


Read a raw array from the HDF5 dataset.


#include "petsclayoutdf5.h"   
#include "petscis.h"   
PetscErrorCode PetscViewerHDF5ReadSizes(PetscViewer viewer, const char name[], PetscInt *bs, PetscInt *N)

Input Parameters

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

Output Parameter

map - The set up layout (with global size and blocksize according to dataset)
newarr - The partitioned array, a memory image of the given dataset


This is intended mainly for internal use; users should use higher level routines such as ISLoad(), VecLoad(), DMLoad(). The array is partitioned according to the given PetscLayout which is converted to an HDF5 hyperslab. This name is relative to the current group returned by PetscViewerHDF5OpenGroup().

Fortran Notes

This routine is not available in Fortran.

See Also

PetscViewerHDF5Open(), PetscViewerHDF5PushGroup(), PetscViewerHDF5OpenGroup(), PetscViewerHDF5ReadSizes(), VecLoad(), ISLoad()
*/ PetscErrorCode PetscViewerHDF5Load(PetscViewer viewer, const char *name, PetscLayout map, hid_t datatype, void **newarr) { HDF5ReadCtx h=NULL; hid_t memspace=0; size_t unitsize; void *arr; PetscErrorCode ierr;

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.

Input Parameters

viewer - The HDF5 viewer
name - The dataset name

Output Parameter

bs - block size
N - global size


The dataset is stored as an HDF5 dataspace with 1-4 dimensions in the order 1) # timesteps (optional), 2) # blocks, 3) # elements per block (optional), 4) real and imaginary part (only for complex).

The dataset can be stored as a 2D dataspace even if its blocksize is 1; see PetscViewerHDF5SetBaseDimension2().

See Also

PetscViewerHDF5Open(), VecLoad(), ISLoad(), VecGetSize(), ISGetSize(), PetscViewerHDF5SetBaseDimension2()




Index of all IS routines
Table of Contents for all manual pages
Index of all manual pages