Skip to content

Commit

Permalink
Merge pull request #126 from Parallel-NetCDF/align_reset
Browse files Browse the repository at this point in the history
Save the alignment hints and reuse them in each ncmpi__enddef
  • Loading branch information
wkliao authored Feb 24, 2024
2 parents 17ce4c6 + fd97bca commit 127648a
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 10 deletions.
2 changes: 2 additions & 0 deletions sneak_peek.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ This is essentially a placeholder for the next release note ...
+ none

* New test program
+ test/testcases/tst_redefine.c - test multiple entries of ncmpi__enddef
[PR #126](https://github.com/Parallel-NetCDF/PnetCDF/pull/126).
+ test/testcases/tst_symlink.c - test NC_CLOBBER on a symbolic link.
+ test/testcases/tst_del_attr.c - test delete attributes. See
[PR #99](https://github.com/Parallel-NetCDF/PnetCDF/pull/99).
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/ncmpio/ncmpio_NC.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ typedef struct NC_buf {
#define NC_NDIRTY 0x400000 /* numrecs has changed */
#define NC_HDIRTY 0x800000 /* header info has changed */
#define NC_HCOLL 0x000001 /* write header collectively */

struct NC {
int ncid; /* file ID */
int flags; /* various modes, i.e. define/data, fill,
Expand All @@ -361,6 +362,9 @@ struct NC {
MPI_Offset h_align; /* file alignment for header size */
MPI_Offset v_align; /* alignment of the beginning of fixed-size variables */
MPI_Offset r_align; /* file alignment for record variable section */
MPI_Offset env_h_align; /* h_align set in environment variable */
MPI_Offset env_v_align; /* v_align set in environment variable */
MPI_Offset env_r_align; /* r_align set in environment variable */
MPI_Offset h_minfree; /* pad at the end of the header section */
MPI_Offset v_minfree; /* pad at the end of the data section for fixed-size variables */
MPI_Offset ibuf_size; /* packing buffer size for flushing noncontig
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/ncmpio/ncmpio_enddef.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,11 @@ ncmpio__enddef(void *ncdp,

num_fix_vars = ncp->vars.ndefined - ncp->vars.num_rec_vars;

/* reset to hints set at file create/open time */
ncp->h_align = ncp->env_h_align;
ncp->v_align = ncp->env_v_align;
ncp->r_align = ncp->env_r_align;

if (ncp->h_align == 0) { /* hint nc_header_align_size is not set */
if (ncp->v_align > 0) /* hint nc_var_align_size is set */
ncp->h_align = ncp->v_align;
Expand All @@ -986,6 +991,7 @@ ncmpio__enddef(void *ncdp,
else if (r_align > 0) /* r_align is passed from ncmpi__enddef */
ncp->h_align = r_align;
}

if (ncp->h_align == 0 && ncp->old == NULL)
/* h_align is still not set. Set h_align only when creating a new
* file. When opening an existing file file, setting h_align here
Expand Down
21 changes: 12 additions & 9 deletions src/drivers/ncmpio/ncmpio_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,45 @@ void ncmpio_set_pnetcdf_hints(NC *ncp,
* a file is created, or opened and later adding more metadata or variable
* data */

ncp->env_h_align = 0;
if (user_info != MPI_INFO_NULL) {
/* aligns the size of header extent of a newly created file */
MPI_Info_get(user_info, "nc_header_align_size", MPI_MAX_INFO_VAL-1, value,
&flag);
if (flag) {
errno = 0; /* errno must set to zero before calling strtoll */
ncp->h_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->h_align = 0;
else if (ncp->h_align < 0) ncp->h_align = 0;
ncp->env_h_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->env_h_align = 0;
else if (ncp->env_h_align < 0) ncp->env_h_align = 0;
}
}
if (!flag) sprintf(value, "%d", FILE_ALIGNMENT_DEFAULT);
MPI_Info_set(info_used, "nc_header_align_size", value);

ncp->env_v_align = 0;
if (user_info != MPI_INFO_NULL) {
/* aligns starting file offsets of individual fixed-size variables */
MPI_Info_get(user_info, "nc_var_align_size", MPI_MAX_INFO_VAL-1, value, &flag);
if (flag) {
errno = 0; /* errno must set to zero before calling strtoll */
ncp->v_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->v_align = 0;
else if (ncp->v_align < 0) ncp->v_align = 0;
ncp->env_v_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->env_v_align = 0;
else if (ncp->env_v_align < 0) ncp->env_v_align = 0;
}
}
if (!flag) sprintf(value, "%d", FILE_ALIGNMENT_DEFAULT);
MPI_Info_set(info_used, "nc_var_align_size", value);

ncp->env_r_align = 0;
if (user_info != MPI_INFO_NULL) {
/* aligns starting file offset of the record variable section */
MPI_Info_get(user_info, "nc_record_align_size", MPI_MAX_INFO_VAL-1, value,
&flag);
if (flag) {
errno = 0; /* errno must set to zero before calling strtoll */
ncp->r_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->r_align = 0;
else if (ncp->r_align < 0) ncp->r_align = 0;
ncp->env_r_align = strtoll(value, NULL, 10);
if (errno != 0) ncp->env_r_align = 0;
else if (ncp->env_r_align < 0) ncp->env_r_align = 0;
}
}
if (!flag) sprintf(value, "%d", FILE_ALIGNMENT_DEFAULT);
Expand Down
3 changes: 2 additions & 1 deletion test/testcases/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ TESTPROGRAMS = ncmpi_vars_null_stride \
tst_free_comm \
flexible_var \
test_get_varn \
tst_del_attr
tst_del_attr \
tst_redefine

M4_SRCS = put_all_kinds.m4 \
erange_fill.m4 \
Expand Down
Loading

0 comments on commit 127648a

Please sign in to comment.