Commit 89bb9ef4 authored by gsell's avatar gsell
Browse files

missing set file property functions implemented, bugfixes

parent d15993ec
......@@ -30,9 +30,9 @@ h5_add_attachment (
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname);
// allowed file modes: O_RDWR, O_WRONLY; O_APPEND
if (f->props->mode == H5_O_RDONLY) {
if (f->props->flags & H5_O_RDONLY) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->props->mode));
h5priv_handle_file_mode_error (f->props->flags));
}
struct stat st;
......@@ -86,11 +86,9 @@ h5_add_attachment (
TRY (loc_id = h5priv_open_group (1, f->file, H5_ATTACHMENT));
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, fname));
if (exists && (f->props->mode == H5_O_RDWR || f->props->mode == H5_O_WRONLY)) {
// remove
} else if (exists && f->props->mode == H5_O_APPEND) {
if (exists && (f->props->flags & H5_O_APPENDONLY)) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->props->mode));
h5priv_handle_file_mode_error (f->props->flags));
}
hid_t diskspace_id;
TRY (diskspace_id = hdf5_create_dataspace (1, &fsize, &fsize));
......@@ -227,18 +225,18 @@ h5_get_attachment (
H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname);
// allowed modes: O_RDWR, O_RDONLY; O_APPEND
// forbidden modes: O_WRONLY
if (f->props->mode == H5_O_WRONLY) {
if (f->props->flags & H5_O_WRONLY) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->props->mode));
h5priv_handle_file_mode_error (f->props->flags));
}
hid_t loc_id;
TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT));
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, fname));
if (f->props->mode == H5_O_WRONLY) {
if (f->props->flags & H5_O_WRONLY) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->props->mode));
h5priv_handle_file_mode_error (f->props->flags));
} else if (!exists) {
H5_PRIV_FUNC_LEAVE (
h5_error (
......
/*
Copyright (c) 2006-2012, The Regents of the University of California,
Copyright (c) 2006-2013, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
......@@ -12,7 +12,7 @@
static h5_errorhandler_t h5_errhandler = h5_report_errorhandler;
h5_err_t h5_errno;
h5_int32_t h5_debug_level = 1;
h5_int32_t h5_debug_level = H5_VERBOSE_ERROR;
struct call_stack h5_call_stack;
char *h5_rfmts[] = {
......@@ -44,12 +44,19 @@ char *h5_rfmts[] = {
/*!
\ingroup h5_core
\defgroup h5_core_errorhandling
TODO: this is broken by design ...
*/
const char* const H5_O_MODES[] = {
"H5_O_RDWR",
"H5_O_RDONLY",
"H5_O_WRONLY",
"H5_O_APPEND"
"unknown", // 0
"H5_O_RDWR", // 1
"H5_O_RDONLY", // 2
"unknown", // 3
"H5_O_WRONLY", // 4
"unknown", // 5
"unknown", // 6
"unknown", // 7
"H5_O_APPENDONLY"
};
/*!
......@@ -71,7 +78,7 @@ h5_set_debuglevel (
const h5_id_t level /*!< debug level */
) {
if (level < 0)
h5_debug_level = (1 << 20) - 1;
h5_debug_level = ((1 << 20) - 1) & ~0x7;
else
h5_debug_level = level;
return H5_SUCCESS;
......@@ -238,6 +245,6 @@ h5_verror (
va_list ap
) {
if (h5_debug_level < 1) return;
if ((h5_debug_level & 0x3) < 1) return;
h5priv_vprintf (stderr, "E", h5_call_stack.entry[0].name, fmt, ap);
}
......@@ -7,7 +7,7 @@
h5_error( \
H5_ERR_BADF, \
"Operation not permitted in mode '%s'", \
H5_O_MODES[mode_id] );
H5_O_MODES[mode_id & 0xff] );
#define HANDLE_H5_OVERFLOW_ERR( max ) \
h5_error( \
......
......@@ -165,7 +165,8 @@ h5_set_throttle (
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_err_t, "f=%p, factor=%d", f, factor);
if ( (f->props->mode & H5_VFD_MPIIO_IND) || (f->props->mode & H5_VFD_MPIPOSIX) ) {
if ( (f->props->flags & H5_VFD_MPIO_INDEPENDENT) ||
(f->props->flags & H5_VFD_MPIO_POSIX) ) {
f->props->throttle = factor;
h5_info (
"Throttling enabled with factor = %lld",
......
......@@ -79,27 +79,30 @@ mpi_init (
TRY (f->props->access_prop = hdf5_create_property(H5P_FILE_ACCESS));
/* select the HDF5 VFD */
if (f->props->mode & H5_VFD_MPIPOSIX) {
if ((f->props->flags & H5_VFD_MPIO_POSIX)) {
h5_info("Selecting MPI-POSIX VFD");
hbool_t use_gpfs = 0; // TODO autodetect GPFS?
TRY (hdf5_set_fapl_mpiposix_property (f->props->access_prop,
f->props->comm, use_gpfs));
} else if (f->props->mode & H5_VFD_CORE) {
} else if ((f->props->flags & H5_VFD_CORE)) {
h5_info("Selecting CORE VFD");
TRY (hdf5_set_fapl_core (f->props->access_prop,
f->props->align, 1));
} else {
h5_info("Selecting MPI-IO VFD");
}
else if ((f->props->flags & H5_VFD_MPIO_INDEPENDENT)){
h5_info("Selecting MPI-IO VFD, using independent mode");
TRY (hdf5_set_fapl_mpio_property (f->props->access_prop,
f->props->comm, MPI_INFO_NULL));
if (f->props->mode & H5_VFD_MPIIO_IND) {
h5_info("MPI-IO: Using independent mode");
} else {
h5_info("MPI-IO: Using collective mode");
TRY (hdf5_set_dxpl_mpio_property (f->props->xfer_prop,
H5FD_MPIO_COLLECTIVE) );
}
TRY (hdf5_set_dxpl_mpio_property (f->props->xfer_prop,
H5FD_MPIO_INDEPENDENT) );
} else {
// default is MPI-IO colloctive mode
h5_info("Selecting MPI-IO VFD, using collective mode");
TRY (hdf5_set_fapl_mpio_property (f->props->access_prop,
f->props->comm, MPI_INFO_NULL));
TRY (hdf5_set_dxpl_mpio_property (f->props->xfer_prop,
H5FD_MPIO_COLLECTIVE) );
}
#ifdef H5_USE_LUSTRE
if (f->flags & H5_FS_LUSTRE) {
......@@ -134,85 +137,145 @@ set_alignment (
static inline h5_err_t
set_default_file_props (
h5_prop_file_t* props
h5_prop_file_t* _props
) {
H5_INLINE_FUNC_ENTER (h5_err_t);
h5_prop_file_t* file_props = (h5_prop_file_t*)props;
bzero (file_props, sizeof (file_props));
file_props->class = H5_PROP_FILE;
TRY (file_props->prefix_step_name = h5_calloc (1, H5_STEPNAME_LEN));
h5_prop_file_p props = (h5_prop_file_p)_props;
bzero (props, sizeof (props));
props->class = H5_PROP_FILE;
TRY (props->prefix_step_name = h5_calloc (1, H5_STEPNAME_LEN));
strncpy (
file_props->prefix_step_name,
props->prefix_step_name,
H5_STEPNAME,
H5_STEPNAME_LEN - 1);
file_props->width_step_idx = H5_STEPWIDTH;
#ifdef PARALLEL_IO
file_props->comm = MPI_COMM_WORLD;
#endif
props->width_step_idx = H5_STEPWIDTH;
props->comm = MPI_COMM_WORLD;
H5_INLINE_FUNC_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_mpio (
h5_prop_t _prop,
h5_set_prop_file_mpio_collective (
h5_prop_t _props,
MPI_Comm* comm
) {
h5_prop_p prop = (h5_prop_p)_prop;
H5_CORE_API_ENTER (h5_err_t, "prop=%p, comm=%p", prop, comm);
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (prop->class != H5_PROP_FILE) {
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)prop->class));
(long long int)props->class));
}
props->flags &= ~(H5_VFD_MPIO_POSIX | H5_VFD_MPIO_INDEPENDENT | H5_VFD_CORE);
props->flags |= H5_VFD_MPIO_COLLECTIVE;
props->comm = *comm;
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_mpio_independent (
h5_prop_t _props,
MPI_Comm* comm
) {
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)props->class));
}
props->flags &= ~(H5_VFD_MPIO_COLLECTIVE | H5_VFD_MPIO_POSIX | H5_VFD_CORE);
props->flags |= H5_VFD_MPIO_INDEPENDENT;
props->comm = *comm;
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_mpio_posix (
h5_prop_t _props,
MPI_Comm* comm
) {
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)props->class));
}
props->flags &= ~(H5_VFD_MPIO_COLLECTIVE | H5_VFD_MPIO_POSIX | H5_VFD_CORE);
props->flags |= H5_VFD_MPIO_INDEPENDENT;
props->comm = *comm;
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_core_vfd (
h5_prop_t _props
) {
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (h5_err_t, "props=%p", props);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)props->class));
}
h5_prop_file_t* file_prop = (h5_prop_file_t*)prop;
file_prop->comm = *comm;
props->flags &= ~(H5_VFD_MPIO_COLLECTIVE | H5_VFD_MPIO_INDEPENDENT | H5_VFD_MPIO_POSIX);
props->flags |= H5_VFD_MPIO_INDEPENDENT;
props->comm = MPI_COMM_SELF;
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_align (
h5_prop_t _prop,
h5_prop_t _props,
h5_int64_t align
) {
h5_prop_p prop = (h5_prop_p)_prop;
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (
h5_err_t,
"prop=%p, align=%lld",
prop, (long long int)align);
if (prop->class != H5_PROP_FILE) {
"props=%p, align=%lld",
props, (long long int)align);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)prop->class));
(long long int)props->class));
}
h5_prop_file_t* file_prop = (h5_prop_file_t*)prop;
file_prop->align = align;
props->align = align;
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_set_prop_file_throttle (
h5_prop_t _prop,
h5_prop_t _props,
h5_int64_t throttle
) {
h5_prop_p prop = (h5_prop_p)_prop;
h5_prop_file_p props = (h5_prop_file_p)_props;
H5_CORE_API_ENTER (
h5_err_t,
"prop=%p, throttle=%lld",
prop, (long long int)throttle);
if (prop->class != H5_PROP_FILE) {
"props=%p, throttle=%lld",
props, (long long int)throttle);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)prop->class));
(long long int)props->class));
}
h5_prop_file_t* file_prop = (h5_prop_file_t*)prop;
file_prop->throttle = throttle;
props->throttle = throttle;
H5_CORE_API_RETURN (H5_SUCCESS);
}
......@@ -272,7 +335,7 @@ open_file (
H5_INLINE_FUNC_ENTER (h5_err_t);
h5_info ("Opening file %s.", filename);
f->props->mode = mode;
f->props->flags |= mode;
f->nprocs = 1; // queried later
f->myproc = 0; // queried later
......@@ -292,19 +355,21 @@ open_file (
TRY (mpi_init (f)); // noop if serial
TRY (set_alignment (f));
if (f->props->mode & H5_O_RDONLY) {
if (f->props->flags & H5_O_RDONLY) {
f->file = H5Fopen (filename, H5F_ACC_RDONLY, f->props->access_prop);
}
else if (f->props->mode & H5_O_WRONLY){
f->file = H5Fcreate (filename, H5F_ACC_TRUNC, f->props->create_prop,
f->props->access_prop);
else if (f->props->flags & H5_O_WRONLY){
f->file = H5Fcreate (
filename, H5F_ACC_TRUNC, f->props->create_prop,
f->props->access_prop);
f->empty = 1;
}
else if (f->props->mode & H5_O_APPEND || f->props->mode & H5_O_RDWR) {
else if (f->props->flags & H5_O_APPENDONLY || f->props->flags & H5_O_RDWR) {
int fd = open (filename, O_RDONLY, 0);
if ((fd == -1) && (errno == ENOENT)) {
f->file = H5Fcreate (filename, H5F_ACC_TRUNC,
f->props->create_prop, f->props->access_prop);
f->file = H5Fcreate (
filename, H5F_ACC_TRUNC,
f->props->create_prop, f->props->access_prop);
f->empty = 1;
}
else if (fd != -1) {
......@@ -318,15 +383,15 @@ open_file (
h5_error (
H5_ERR_INVAL,
"Invalid file access mode '%lld'.",
(long long int)f->props->mode));
(long long int)f->props->flags & 0xff));
}
if (f->file < 0)
H5_PRIV_FUNC_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot open file '%s' with mode '%lld'",
filename, (long long int)f->props->mode));
"Cannot open file '%s' with mode '%s'",
filename, H5_O_MODES[f->props->flags & 0xff]));
TRY (f->root_gid = hdf5_open_group (f->file, "/" ));
TRY (h5upriv_open_file (f));
......@@ -362,7 +427,7 @@ h5_open_file2 (
(long long int)props->class));
}
f->props->comm = props->comm;
f->props->mode |= props->mode;
f->props->flags = props->flags;
f->props->throttle = props->throttle;
f->props->align = props->align;
......@@ -395,7 +460,7 @@ h5_open_file2 (
*/
h5_file_t
h5_open_file (
h5_open_file1 (
const char* filename,
h5_int32_t mode,
MPI_Comm comm,
......@@ -408,7 +473,7 @@ h5_open_file (
h5_prop_file_t* props;
h5_file_t f;
TRY (props = (h5_prop_file_t*)h5_create_prop (H5_PROP_FILE));
TRY (h5_set_prop_file_mpio ((h5_prop_t)props, &comm));
TRY (h5_set_prop_file_mpio_collective ((h5_prop_t)props, &comm));
TRY (h5_set_prop_file_align ((h5_prop_t)props, align));
TRY (f = h5_open_file2 (filename, mode, (h5_prop_t)props));
TRY (h5_close_prop ((h5_prop_t)props));
......
......@@ -44,10 +44,10 @@ h5priv_write_dataset_by_name (
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, dsinfo->name));
if ((exists > 0) && ((f->props->mode==H5_O_WRONLY) || (f->props->mode==H5_O_APPEND))) {
if ((exists > 0) && (f->props->flags & H5_O_APPENDONLY)) {
h5_warn ("Dataset %s/%s already exist.",
hdf5_get_objname (loc_id), dsinfo->name);
H5_PRIV_API_LEAVE (h5priv_handle_file_mode_error(f->props->mode));
H5_PRIV_API_LEAVE (h5priv_handle_file_mode_error(f->props->flags));
}
/*
......@@ -112,7 +112,7 @@ h5priv_write_dataset_by_name (
*/
h5_err_t
h5priv_write_dataset_by_name_id (
const h5_file_p f,
const h5_file_p f,
const hid_t loc_id,
h5_dsinfo_t* dsinfo,
hid_t dset_id,
......@@ -132,10 +132,10 @@ h5priv_write_dataset_by_name_id (
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, dsinfo->name));
if ((exists > 0) && ((f->props->mode==H5_O_WRONLY) || (f->props->mode==H5_O_APPEND))) {
if ((exists > 0) && (f->props->flags & H5_O_APPENDONLY)) {
h5_warn ("Dataset %s/%s already exist.",
hdf5_get_objname (loc_id), dsinfo->name);
H5_PRIV_API_LEAVE (h5priv_handle_file_mode_error(f->props->mode));
H5_PRIV_API_LEAVE (h5priv_handle_file_mode_error(f->props->flags));
}
#ifdef PARALLEL_IO
......
......@@ -13,20 +13,16 @@
#include "h5core/h5_types.h"
#define is_writable(f) (f->props->mode != H5_O_RDONLY)
#define is_readonly(f) (f->props->mode == H5_O_RDONLY)
#define is_appendonly(f) (f->props->mode == H5_O_APPEND)
#define is_writable(f) (f->props->flags & (H5_O_RDWR | H5_O_WRONLY | H5_O_APPENDONLY))
#define is_readable(f) (f->props->flags & (H5_O_RDWR | H5_O_RDONLY))
#define is_readonly(f) (f->props->flags & H5_O_RDONLY)
#define is_appendonly(f) (f->props->flags & H5_O_APPENDONLY)
#define CHECK_WRITABLE_MODE(f) \
TRY (is_writable (f) ? H5_SUCCESS : h5_error ( \
H5_ERR_INVAL, \
"Attempting to write to read-only file"));
#define CHECK_READONLY_MODE(f) \
TRY (is_readonly (f) ? H5_SUCCESS : h5_error ( \
H5_ERR_INVAL, \
"Operation is not allowed on writable files."));
#define CHECK_TIMEGROUP(f) \
TRY ((f->step_gid > 0) ? H5_SUCCESS : h5_error ( \
H5_ERR_INVAL, \
......
......@@ -18,11 +18,10 @@ struct h5_prop { // generic property class
char pad[248]; // sizeof (struct h5_prop) == 256
};
typedef struct { // file property
struct h5_prop_file { // file property
h5_int64_t class; // property class == H5_PROP_FILE
h5_int64_t mode;
h5_int64_t flags;
h5_int64_t align;
h5_int64_t flags; // file access mode (read-write, readonly ...
h5_int64_t align; // HDF5 alignment
h5_int64_t throttle;
MPI_Comm comm;
hid_t xfer_prop; // dataset transfer properties
......@@ -30,8 +29,9 @@ typedef struct { // file property
hid_t create_prop; // file create properties
char* prefix_step_name; // Prefix of step name
int width_step_idx; // pad step index with 0 up to this
} h5_prop_file_t;
};
typedef struct h5_prop_file h5_prop_file_t;
typedef h5_prop_file_t* h5_prop_file_p;
/**
\struct h5_file
......@@ -43,7 +43,7 @@ typedef struct { // file property
*/
struct h5_file {
hid_t file; // HDF5 file id
h5_prop_file_t* props; // file properties
h5_prop_file_p props; // file properties
char empty; // flag (should be int?!)
/* MPI */
......
......@@ -109,10 +109,6 @@ h5u_set_num_particles (
"Invalid number particles: %lld!\n",
(long long)nparticles));
hsize_t hstride = (hsize_t)stride;
if (hstride > 1)
h5_debug ("Striding by %lld elements.", (long long)hstride);
#ifndef PARALLEL_IO
/*
if we are not using parallel-IO, there is enough information
......@@ -139,8 +135,10 @@ h5u_set_num_particles (
/* we need a hyperslab selection if there is striding
* (otherwise, the default H5S_ALL selection is ok)
*/
if (hstride > 1) {
if (stride > 1) {
h5_debug ("Striding by %lld elements.", (long long)stride);
start = 0;
hsize_t hstride = (hsize_t)stride;
count = u->nparticles;
TRY (hdf5_select_hyperslab_of_dataspace (
u->memshape,
......@@ -189,8 +187,8 @@ h5u_set_num_particles (
TRY( u->diskshape = hdf5_create_dataspace(1, &count, NULL) );
count = nparticles;
hstride = 1;
if (count > 0) {
hsize_t hstride = 1;
TRY( hdf5_select_hyperslab_of_dataspace(
u->diskshape,
H5S_SELECT_SET,
......
......@@ -230,7 +230,7 @@ h5u_write_data (
#ifdef PARALLEL_IO
TRY (h5priv_end_throttle (f));
#endif
if (f->props->mode & H5_FLUSH_STEP)
if (f->props->flags & H5_FLUSH_STEP)
TRY (hdf5_flush (f->step_gid, H5F_SCOPE_LOCAL));
TRY (hdf5_close_dataset (dset_id));
......
......@@ -27,13 +27,49 @@ H5CreateFileProp (
H5_API_RETURN (h5_create_prop (H5_PROP_FILE));
}
static inline h5_err_t
H5SetPropFileMPIO (
h5_prop_t prop,
MPI_Comm* comm
) {
H5_API_ENTER (h5_err_t, "prop=%p, comm=%p", (void*)prop, comm);
H5_API_RETURN (h5_set_prop_file_mpio (prop, comm));
H5_API_RETURN (h5_set_prop_file_mpio_collective (prop, comm));
}
static inline h5_err_t
H5SetPropFileMPIOCollective (
h5_prop_t prop,
MPI_Comm* comm
) {
H5_API_ENTER (h5_err_t, "prop=%p, comm=%p", (void*)prop, comm);
H5_API_RETURN (h5_set_prop_file_mpio_collective (prop, comm));
}
static inline h5_err_t
H5SetPropFileMPIOIndependent (
h5_prop_t prop,
MPI_Comm* comm
) {
H5_API_ENTER (h5_err_t, "prop=%p, comm=%p", (void*)prop, comm);
H5_API_RETURN (h5_set_prop_file_mpio_independent (prop, comm));
}
static inline h5_err_t
H5SetPropFileMPIOPosix (
h5_prop_t prop,
MPI_Comm* comm
) {
H5_API_ENTER (h5_err_t, "prop=%p, comm=%p", (void*)prop, comm);
H5_API_RETURN (h5_set_prop_file_mpio_posix (prop, comm));
}
static inline h5_err_t
H5SetPropFileCoreVFD (
h5_prop_t prop