Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Allow users to set data alignment within netcdf4 files #2178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/nc4dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extern "C" {
EXTERNL int
NC4_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
void* parameters, const NC_Dispatch*, int);
void* parameters, const NC_Dispatch*, int,
size_t, size_t);

EXTERNL int
NC4_open(const char *path, int mode,
Expand Down
3 changes: 2 additions & 1 deletion include/ncdispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ struct NC;

int NC_create(const char *path, int cmode,
size_t initialsz, int basepe, size_t *chunksizehintp,
int useparallel, void *parameters, int *ncidp);
int useparallel, void *parameters, int *ncidp,
size_t alignment_threshold, size_t alignment_interval);
int NC_open(const char *path, int cmode,
int basepe, size_t *chunksizehintp,
int useparallel, void *parameters, int *ncidp);
Expand Down
3 changes: 2 additions & 1 deletion include/netcdf_dispatch.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ struct NC_Dispatch

int (*create)(const char *path, int cmode, size_t initialsz,
int basepe, size_t *chunksizehintp, void *parameters,
const struct NC_Dispatch *table, int ncid);
const struct NC_Dispatch *table, int ncid,
size_t alignment_threshold, size_t alignment_interval);
int (*open)(const char *path, int mode, int basepe, size_t *chunksizehintp,
void *parameters, const struct NC_Dispatch *table, int ncid);

Expand Down
18 changes: 13 additions & 5 deletions libdispatch/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ nc__create(const char *path, int cmode, size_t initialsz,
size_t *chunksizehintp, int *ncidp)
{
return NC_create(path, cmode, initialsz, 0,
chunksizehintp, 0, NULL, ncidp);
chunksizehintp, 0, NULL, ncidp, 1, 1);
}

/** \ingroup datasets
Expand Down Expand Up @@ -508,7 +508,7 @@ nc_create_mem(const char* path, int mode, size_t initialsize, int* ncidp)
{
if(mode & NC_MMAP) return NC_EINVAL;
mode |= NC_INMEMORY; /* Specifically, do not set NC_DISKLESS */
return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp, 1, 1);
}

/**
Expand All @@ -535,7 +535,7 @@ nc__create_mp(const char *path, int cmode, size_t initialsz,
int basepe, size_t *chunksizehintp, int *ncidp)
{
return NC_create(path, cmode, initialsz, basepe,
chunksizehintp, 0, NULL, ncidp);
chunksizehintp, 0, NULL, ncidp, 1, 1);
}

/**
Expand Down Expand Up @@ -1815,6 +1815,12 @@ check_create_mode(int mode)
* @param parameters Pointer to MPI comm and info.
* @param ncidp Pointer to location where returned netCDF ID is to be
* stored.
* @param alignment_threshold Desired data alignment threshold within
* the created file. For HDF5 based files, this is passed to
* H5Pset_alignment. Default value: 1 (no alignment threshold).
* @param alignment_interval Desired data alignment interval within
* the created file. For HDF5 based files, this is passed to
* H5Pset_alignment. Default value: 1 (no alignment).
*
* @returns ::NC_NOERR No error.
* @ingroup dispatch
Expand All @@ -1823,7 +1829,8 @@ check_create_mode(int mode)
int
NC_create(const char *path0, int cmode, size_t initialsz,
int basepe, size_t *chunksizehintp, int useparallel,
void* parameters, int *ncidp)
void* parameters, int *ncidp,
size_t alignment_threshold, size_t alignment_interval)
{
int stat = NC_NOERR;
NC* ncp = NULL;
Expand Down Expand Up @@ -1924,7 +1931,8 @@ NC_create(const char *path0, int cmode, size_t initialsz,

/* Assume create will fill in remaining ncp fields */
if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
parameters, dispatcher, ncp->ext_ncid))) {
parameters, dispatcher, ncp->ext_ncid,
alignment_threshold, alignment_interval))) {
del_from_NCList(ncp); /* oh well */
free_NC(ncp);
} else {
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dparallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int nc_create_par(const char *path, int cmode, MPI_Comm comm,

data.comm = comm;
data.info = info;
return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp);
return NC_create(path, cmode, 0, 0, NULL, 1, &data, ncidp, 1, 1);
#endif /* USE_PARALLEL */
}

Expand Down
18 changes: 14 additions & 4 deletions libhdf5/hdf5create.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ extern int NC4_create_image_file(NC_FILE_INFO_T* h5, size_t);
* in-memory netCDF-4/HDF5 files only).
* @param parameters extra parameter info (like MPI communicator).
* @param ncid The already-assigned ncid for this file (aka ext_ncid).
* @param alignment_threshold The HDF5 alignment threshold. Passed to H5Pset_alignment. Default value: 1.
* @param alignment_interval The HDF5 alignment interval. Passed to H5Pset_alignment. Default value: 1.
*
* @return ::NC_NOERR No error.
* @return ::NC_EINVAL Invalid input (check cmode).
* @return ::NC_EEXIST File exists and NC_NOCLOBBER used.
* @return ::NC_EHDFERR HDF5 returned error.
* @ingroup netcdf4
* @author Ed Hartnett, Dennis Heimbigner
* @author Ed Hartnett, Dennis Heimbigner, Mark Harfouche
*/
static int
nc4_create_file(const char *path, int cmode, size_t initialsz,
void* parameters, int ncid)
void* parameters, int ncid,
size_t alignment_threshold, size_t alignment_interval)
{
hid_t fcpl_id, fapl_id = -1;
unsigned flags;
Expand Down Expand Up @@ -163,6 +166,9 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
__func__, nc4_chunk_cache_size, nc4_chunk_cache_nelems,
nc4_chunk_cache_preemption));
}
if (H5Pset_alignment(fapl_id, alignment_threshold, alignment_interval) < 0) {
BAIL(NC_EHDFERR);
}

#if H5_VERSION_GE(1,10,2)
/* lib versions 1.10.2 and higher */
Expand Down Expand Up @@ -281,6 +287,8 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
* @param dispatch Pointer to the dispatch table for this file.
* @param ncid The ncid that has been assigned by the dispatch layer
* (aka ext_ncid).
* @param alignment_threshold The HDF5 alignment threshold. Passed to H5Pset_alignment. Default value: 1.
* @param alignment_interval The HDF5 alignment interval. Passed to H5Pset_alignment. Default value: 1.
*
* @return ::NC_NOERR No error.
* @return ::NC_EINVAL Invalid input (check cmode).
Expand All @@ -290,7 +298,8 @@ nc4_create_file(const char *path, int cmode, size_t initialsz,
int
NC4_create(const char* path, int cmode, size_t initialsz, int basepe,
size_t *chunksizehintp, void *parameters,
const NC_Dispatch *dispatch, int ncid)
const NC_Dispatch *dispatch, int ncid,
size_t alignment_threshold, size_t alignment_interval)
{
int res;

Expand All @@ -315,7 +324,8 @@ NC4_create(const char* path, int cmode, size_t initialsz, int basepe,
return NC_EINVAL;

/* Create the netCDF-4/HDF5 file. */
res = nc4_create_file(path, cmode, initialsz, parameters, ncid);
res = nc4_create_file(path, cmode, initialsz, parameters, ncid,
alignment_threshold, alignment_interval);

return res;
}
Expand Down