src/h5/openclose.c
* adaption to renamed members in "struct h5_file" * several changes and additions for H5Fed
This commit is contained in:
+264
-216
@@ -76,23 +76,50 @@ _init ( void ) {
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5block_private
|
||||
\ingroup h5_private
|
||||
|
||||
\internal
|
||||
|
||||
Initialize unstructured data internal data structure.
|
||||
|
||||
\return H5_SUCCESS or error code
|
||||
*/
|
||||
static h5part_int64_t
|
||||
_h5u_open_file (
|
||||
h5_file *f /*!< IN: file handle */
|
||||
) {
|
||||
f->shape = 0;
|
||||
f->diskshape = H5S_ALL;
|
||||
f->memshape = H5S_ALL;
|
||||
f->viewstart = -1;
|
||||
f->viewend = -1;
|
||||
f->pnparticles =
|
||||
(h5part_int64_t*) malloc (f->nprocs * sizeof (h5part_int64_t));
|
||||
if (f->pnparticles == NULL) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5_private
|
||||
|
||||
\internal
|
||||
|
||||
Initialize H5Block internal structure.
|
||||
|
||||
\return H5PART_SUCCESS or error code
|
||||
\return H5_SUCCESS or error code
|
||||
*/
|
||||
static h5part_int64_t
|
||||
_init_block (
|
||||
_h5b_open_file (
|
||||
h5_file *f /*!< IN: file handle */
|
||||
) {
|
||||
h5part_int64_t herr;
|
||||
struct h5b_fdata *b;
|
||||
|
||||
herr = H5_check_filehandle ( f );
|
||||
if ( herr == H5PART_SUCCESS ) return H5PART_SUCCESS;
|
||||
if ( herr == H5_SUCCESS ) return H5_SUCCESS;
|
||||
|
||||
if ( (f == 0) || (f->file == 0) ) return HANDLE_H5PART_BADFD_ERR;
|
||||
|
||||
@@ -112,7 +139,7 @@ _init_block (
|
||||
if ( b->write_layout == NULL ) {
|
||||
return HANDLE_H5PART_NOMEM_ERR;
|
||||
}
|
||||
b->timestep = -1;
|
||||
b->step_idx = -1;
|
||||
b->blockgroup = -1;
|
||||
b->shape = -1;
|
||||
b->diskshape = -1;
|
||||
@@ -120,11 +147,208 @@ _init_block (
|
||||
b->field_group_id = -1;
|
||||
b->have_layout = 0;
|
||||
|
||||
f->close_block = _close_block;
|
||||
|
||||
return H5PART_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
h5_file*
|
||||
H5_open_file (
|
||||
const char *filename, /*!< [in] The name of the data file to open. */
|
||||
unsigned flags, /*!< [in] The access mode for the file. */
|
||||
MPI_Comm comm /*!< [in] MPI communicator */
|
||||
) {
|
||||
|
||||
h5part_int64_t rc = H5PART_SUCCESS;
|
||||
|
||||
if ( _init() < 0 ) {
|
||||
HANDLE_H5PART_INIT_ERR;
|
||||
return NULL;
|
||||
}
|
||||
_h5part_errno = H5PART_SUCCESS;
|
||||
h5_file *f = NULL;
|
||||
|
||||
f = (h5_file*) malloc( sizeof (h5_file) );
|
||||
if( f == NULL ) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
memset (f, 0, sizeof (h5_file));
|
||||
|
||||
f->prefix_step_name = strdup ( H5PART_GROUPNAME_STEP );
|
||||
if( f->prefix_step_name == NULL ) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->width_step_idx = 0;
|
||||
|
||||
f->xfer_prop = f->create_prop = f->access_prop = H5P_DEFAULT;
|
||||
|
||||
f->comm = 0; /* init values for serial case */
|
||||
f->nprocs = 1;
|
||||
f->myproc = 0;
|
||||
|
||||
#ifdef PARALLEL_IO
|
||||
f->comm = comm;
|
||||
if (MPI_Comm_size (comm, &f->nprocs) != MPI_SUCCESS) {
|
||||
HANDLE_MPI_COMM_SIZE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
if (MPI_Comm_rank (comm, &f->myproc) != MPI_SUCCESS) {
|
||||
HANDLE_MPI_COMM_RANK_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
|
||||
/* for the SP2... perhaps different for linux */
|
||||
MPI_Info info = MPI_INFO_NULL;
|
||||
|
||||
/* ks: IBM_large_block_io */
|
||||
MPI_Info_create(&info);
|
||||
MPI_Info_set(info, "IBM_largeblock_io", "true" );
|
||||
if (H5Pset_fapl_mpio (f->access_prop, comm, info) < 0) {
|
||||
HANDLE_H5P_SET_FAPL_MPIO_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
MPI_Info_free(&info);
|
||||
|
||||
f->access_prop = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (f->access_prop < 0) {
|
||||
HANDLE_H5P_CREATE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
/* f->create_prop = H5Pcreate(H5P_FILE_CREATE); */
|
||||
f->create_prop = H5P_DEFAULT;
|
||||
|
||||
/* xfer_prop: also used for parallel I/O, during actual writes
|
||||
rather than the access_prop which is for file creation. */
|
||||
f->xfer_prop = H5Pcreate (H5P_DATASET_XFER);
|
||||
if (f->xfer_prop < 0) {
|
||||
HANDLE_H5P_CREATE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
#ifdef COLLECTIVE_IO
|
||||
if (H5Pset_dxpl_mpio (f->xfer_prop,H5FD_MPIO_COLLECTIVE) < 0) {
|
||||
HANDLE_H5P_SET_DXPL_MPIO_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
#endif /* COLLECTIVE_IO */
|
||||
|
||||
#endif /* PARALLEL_IO */
|
||||
|
||||
if ( flags == H5_O_RDONLY ) {
|
||||
f->file = H5Fopen (filename, H5F_ACC_RDONLY, f->access_prop);
|
||||
}
|
||||
else if ( flags == H5_O_WRONLY ){
|
||||
f->file = H5Fcreate (filename, H5F_ACC_TRUNC, f->create_prop,
|
||||
f->access_prop);
|
||||
f->empty = 1;
|
||||
}
|
||||
else if ( flags == H5_O_APPEND || H5_O_RDWR ) {
|
||||
int fd = open (filename, O_RDONLY, 0);
|
||||
if ( (fd == -1) && (errno == ENOENT) ) {
|
||||
f->file = H5Fcreate(filename, H5F_ACC_TRUNC,
|
||||
f->create_prop, f->access_prop);
|
||||
f->empty = 1;
|
||||
}
|
||||
else if (fd != -1) {
|
||||
close (fd);
|
||||
f->file = H5Fopen (filename, H5F_ACC_RDWR,
|
||||
f->access_prop);
|
||||
}
|
||||
}
|
||||
else {
|
||||
HANDLE_H5PART_FILE_ACCESS_TYPE_ERR ( flags );
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if (f->file < 0) {
|
||||
HANDLE_H5F_OPEN_ERR ( filename, flags );
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->root_gid = H5Gopen( f->file, "/" );
|
||||
if ( f->root_gid < 0 ) {
|
||||
HANDLE_H5G_OPEN_ERR ( "/" );
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->mode = flags;
|
||||
f->step_gid = -1;
|
||||
|
||||
sprintf (
|
||||
f->step_name,
|
||||
"%s#%0*lld",
|
||||
f->prefix_step_name, f->width_step_idx, (long long) f->step_idx );
|
||||
|
||||
if ( _h5u_open_file ( f ) < 0 ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if ( _h5b_open_file ( f ) < 0 ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if ( _h5t_open_file ( f ) < 0 ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
H5_print_debug (
|
||||
"Proc[%d]: Opened file \"%s\" val=%lld",
|
||||
f->myproc,
|
||||
filename,
|
||||
(long long)(size_t)f );
|
||||
|
||||
return f;
|
||||
|
||||
error_cleanup:
|
||||
if (f != NULL ) {
|
||||
if (f->prefix_step_name) {
|
||||
free (f->prefix_step_name);
|
||||
}
|
||||
if (f->pnparticles != NULL) {
|
||||
free (f->pnparticles);
|
||||
}
|
||||
free (f);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5_private
|
||||
|
||||
\internal
|
||||
|
||||
De-initialize H5Block internal structure. Open HDF5 objects are
|
||||
closed and allocated memory freed.
|
||||
|
||||
\return H5PART_SUCCESS or error code
|
||||
*/
|
||||
static h5part_int64_t
|
||||
_h5u_close_file (
|
||||
h5_file *f /*!< IN: file handle */
|
||||
) {
|
||||
_h5part_errno = H5_SUCCESS;
|
||||
if( f->shape > 0 ) {
|
||||
r = H5Sclose( f->shape );
|
||||
if ( r < 0 ) HANDLE_H5S_CLOSE_ERR;
|
||||
f->shape = 0;
|
||||
}
|
||||
if( f->diskshape != H5S_ALL ) {
|
||||
r = H5Sclose( f->diskshape );
|
||||
if ( r < 0 ) HANDLE_H5S_CLOSE_ERR;
|
||||
f->diskshape = 0;
|
||||
}
|
||||
if( f->memshape != H5S_ALL ) {
|
||||
r = H5Sclose( f->memshape );
|
||||
if ( r < 0 ) HANDLE_H5S_CLOSE_ERR;
|
||||
f->memshape = 0;
|
||||
}
|
||||
if( f->pnparticles ) {
|
||||
free( f->pnparticles );
|
||||
}
|
||||
return _h5part_errno;
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5block_private
|
||||
|
||||
@@ -136,7 +360,7 @@ _init_block (
|
||||
\return H5PART_SUCCESS or error code
|
||||
*/
|
||||
static h5part_int64_t
|
||||
_close_block (
|
||||
_h5b_close_file (
|
||||
h5_file *f /*!< IN: file handle */
|
||||
) {
|
||||
|
||||
@@ -165,196 +389,34 @@ _close_block (
|
||||
}
|
||||
free ( f->block );
|
||||
f->block = NULL;
|
||||
f->close_block = NULL;
|
||||
|
||||
return H5PART_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5_private
|
||||
|
||||
h5_file*
|
||||
H5_open_file (
|
||||
const char *filename, /*!< [in] The name of the data file to open. */
|
||||
unsigned flags, /*!< [in] The access mode for the file. */
|
||||
MPI_Comm comm, /*!< [in] MPI communicator */
|
||||
int f_parallel /*!< [in] 0 for serial io otherwise parallel */
|
||||
\internal
|
||||
|
||||
De-initialize topological internal structure. Open HDF5 objects are
|
||||
closed and allocated memory freed.
|
||||
|
||||
\return H5_SUCCESS or error code
|
||||
*/
|
||||
static h5part_int64_t
|
||||
_h5t_close_file (
|
||||
h5_file *fh /*!< IN: file handle */
|
||||
) {
|
||||
|
||||
h5part_int64_t rc = H5PART_SUCCESS;
|
||||
h5_err_t herr = H5_SUCCESS;
|
||||
struct h5t_fdata *t = fh->t;
|
||||
|
||||
if ( _init() < 0 ) {
|
||||
HANDLE_H5PART_INIT_ERR;
|
||||
return NULL;
|
||||
if ( t->levels ) {
|
||||
free ( levels );
|
||||
}
|
||||
_h5part_errno = H5PART_SUCCESS;
|
||||
h5_file *f = NULL;
|
||||
|
||||
f = (h5_file*) malloc( sizeof (h5_file) );
|
||||
if( f == NULL ) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
memset (f, 0, sizeof (h5_file));
|
||||
|
||||
f->groupname_step = strdup ( H5PART_GROUPNAME_STEP );
|
||||
if( f->groupname_step == NULL ) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->stepno_width = 0;
|
||||
|
||||
f->xfer_prop = f->create_prop = f->access_prop = H5P_DEFAULT;
|
||||
|
||||
if ( f_parallel ) {
|
||||
#ifdef PARALLEL_IO
|
||||
/* for the SP2... perhaps different for linux */
|
||||
MPI_Info info = MPI_INFO_NULL;
|
||||
|
||||
/* ks: IBM_large_block_io */
|
||||
MPI_Info_create(&info);
|
||||
MPI_Info_set(info, "IBM_largeblock_io", "true" );
|
||||
|
||||
if (MPI_Comm_size (comm, &f->nprocs) != MPI_SUCCESS) {
|
||||
HANDLE_MPI_COMM_SIZE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
if (MPI_Comm_rank (comm, &f->myproc) != MPI_SUCCESS) {
|
||||
HANDLE_MPI_COMM_RANK_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
f->pnparticles =
|
||||
(h5part_int64_t*) malloc (f->nprocs * sizeof (h5part_int64_t));
|
||||
if (f->pnparticles == NULL) {
|
||||
HANDLE_H5PART_NOMEM_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
f->access_prop = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (f->access_prop < 0) {
|
||||
HANDLE_H5P_CREATE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if (H5Pset_fapl_mpio (f->access_prop, comm, info) < 0) {
|
||||
HANDLE_H5P_SET_FAPL_MPIO_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
/* f->create_prop = H5Pcreate(H5P_FILE_CREATE); */
|
||||
f->create_prop = H5P_DEFAULT;
|
||||
|
||||
/* xfer_prop: also used for parallel I/O, during actual writes
|
||||
rather than the access_prop which is for file creation. */
|
||||
f->xfer_prop = H5Pcreate (H5P_DATASET_XFER);
|
||||
if (f->xfer_prop < 0) {
|
||||
HANDLE_H5P_CREATE_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
#ifdef COLLECTIVE_IO
|
||||
if (H5Pset_dxpl_mpio (f->xfer_prop,H5FD_MPIO_COLLECTIVE) < 0) {
|
||||
HANDLE_H5P_SET_DXPL_MPIO_ERR;
|
||||
goto error_cleanup;
|
||||
}
|
||||
#endif
|
||||
f->comm = comm;
|
||||
|
||||
MPI_Info_free(&info);
|
||||
#else
|
||||
/* f_parallel is true, but compilation is for serial I/O */
|
||||
HANDLE_MPI_UNAVAILABLE_ERR;
|
||||
goto error_cleanup;
|
||||
|
||||
#endif /* PARALLEL_IO */
|
||||
} else {
|
||||
f->comm = 0;
|
||||
f->nprocs = 1;
|
||||
f->myproc = 0;
|
||||
f->pnparticles =
|
||||
(h5part_int64_t*) malloc (f->nprocs * sizeof (h5part_int64_t));
|
||||
}
|
||||
if ( flags == H5PART_READ ) {
|
||||
f->file = H5Fopen (filename, H5F_ACC_RDONLY, f->access_prop);
|
||||
}
|
||||
else if ( flags == H5PART_WRITE ){
|
||||
f->file = H5Fcreate (filename, H5F_ACC_TRUNC, f->create_prop,
|
||||
f->access_prop);
|
||||
f->empty = 1;
|
||||
}
|
||||
else if ( flags == H5PART_APPEND ) {
|
||||
int fd = open (filename, O_RDONLY, 0);
|
||||
if ( (fd == -1) && (errno == ENOENT) ) {
|
||||
f->file = H5Fcreate(filename, H5F_ACC_TRUNC,
|
||||
f->create_prop, f->access_prop);
|
||||
f->empty = 1;
|
||||
}
|
||||
else if (fd != -1) {
|
||||
close (fd);
|
||||
f->file = H5Fopen (filename, H5F_ACC_RDWR,
|
||||
f->access_prop);
|
||||
/*
|
||||
The following function call returns an error,
|
||||
if f->file < 0. But we can safely ignore this.
|
||||
*/
|
||||
f->timestep = H5_get_num_objects_matching_pattern(
|
||||
f->file, "/", H5G_GROUP, f->groupname_step );
|
||||
if ( f->timestep < 0 ) goto error_cleanup;
|
||||
}
|
||||
}
|
||||
else {
|
||||
HANDLE_H5PART_FILE_ACCESS_TYPE_ERR ( flags );
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if (f->file < 0) {
|
||||
HANDLE_H5F_OPEN_ERR ( filename, flags );
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->root_id = H5Gopen( f->file, "/" );
|
||||
if ( f->root_id < 0 ) {
|
||||
HANDLE_H5G_OPEN_ERR ( "/" );
|
||||
goto error_cleanup;
|
||||
}
|
||||
f->mode = flags;
|
||||
f->timegroup = -1;
|
||||
f->shape = 0;
|
||||
f->diskshape = H5S_ALL;
|
||||
f->memshape = H5S_ALL;
|
||||
f->viewstart = -1;
|
||||
f->viewend = -1;
|
||||
|
||||
sprintf (
|
||||
f->index_name,
|
||||
"%s#%0*lld",
|
||||
f->groupname_step, f->stepno_width, (long long) f->timestep );
|
||||
|
||||
rc = _init_block ( f );
|
||||
if ( rc != H5PART_SUCCESS ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
H5_print_debug (
|
||||
"Proc[%d]: Opened file \"%s\" val=%lld",
|
||||
f->myproc,
|
||||
filename,
|
||||
(long long)(size_t)f );
|
||||
|
||||
return f;
|
||||
|
||||
error_cleanup:
|
||||
if (f != NULL ) {
|
||||
if (f->groupname_step) {
|
||||
free (f->groupname_step);
|
||||
}
|
||||
if (f->pnparticles != NULL) {
|
||||
free (f->pnparticles);
|
||||
}
|
||||
free (f);
|
||||
}
|
||||
return NULL;
|
||||
return herr;
|
||||
}
|
||||
|
||||
|
||||
h5part_int64_t
|
||||
H5_close_file (
|
||||
h5_file *f
|
||||
@@ -364,26 +426,15 @@ H5_close_file (
|
||||
|
||||
CHECK_FILEHANDLE ( f );
|
||||
|
||||
if ( f->block && f->close_block ) {
|
||||
(*f->close_block) ( f );
|
||||
f->block = NULL;
|
||||
f->close_block = NULL;
|
||||
}
|
||||
_h5_close_step ( f );
|
||||
_h5u_close_file ( f );
|
||||
_h5b_close_file ( f );
|
||||
_h5t_close_file ( f );
|
||||
|
||||
if( f->shape > 0 ) {
|
||||
r = H5Sclose( f->shape );
|
||||
if ( r < 0 ) HANDLE_H5S_CLOSE_ERR;
|
||||
f->shape = 0;
|
||||
}
|
||||
if( f->timegroup >= 0 ) {
|
||||
r = H5Gclose( f->timegroup );
|
||||
if( f->step_gid >= 0 ) {
|
||||
r = H5Gclose( f->step_gid );
|
||||
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
|
||||
f->timegroup = -1;
|
||||
}
|
||||
if( f->diskshape != H5S_ALL ) {
|
||||
r = H5Sclose( f->diskshape );
|
||||
if ( r < 0 ) HANDLE_H5S_CLOSE_ERR;
|
||||
f->diskshape = 0;
|
||||
f->step_gid = -1;
|
||||
}
|
||||
if( f->xfer_prop != H5P_DEFAULT ) {
|
||||
r = H5Pclose( f->xfer_prop );
|
||||
@@ -400,21 +451,18 @@ H5_close_file (
|
||||
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( "f->create_prop" );
|
||||
f->create_prop = H5P_DEFAULT;
|
||||
}
|
||||
if ( f->root_id >= 0 ) {
|
||||
r = H5Gclose ( f->root_id );
|
||||
if ( f->root_gid >= 0 ) {
|
||||
r = H5Gclose ( f->root_gid );
|
||||
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
|
||||
f->root_id = 0;
|
||||
f->root_gid = 0;
|
||||
}
|
||||
if ( f->file ) {
|
||||
r = H5Fclose( f->file );
|
||||
if ( r < 0 ) HANDLE_H5F_CLOSE_ERR;
|
||||
f->file = 0;
|
||||
}
|
||||
if (f->groupname_step) {
|
||||
free (f->groupname_step);
|
||||
}
|
||||
if( f->pnparticles ) {
|
||||
free( f->pnparticles );
|
||||
if (f->prefix_step_name) {
|
||||
free (f->prefix_step_name);
|
||||
}
|
||||
free( f );
|
||||
|
||||
@@ -427,11 +475,11 @@ H5_define_stepname (
|
||||
const char *name,
|
||||
const h5part_int64_t width
|
||||
) {
|
||||
f->groupname_step = strdup ( name );
|
||||
if( f->groupname_step == NULL ) {
|
||||
f->prefix_step_name = strdup ( name );
|
||||
if( f->prefix_step_name == NULL ) {
|
||||
return HANDLE_H5PART_NOMEM_ERR;
|
||||
}
|
||||
f->stepno_width = (int)width;
|
||||
f->width_step_idx = (int)width;
|
||||
|
||||
return H5PART_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user