@@ -311,10 +311,8 @@ NC_begins(NC *ncp)
311
311
if (ncp -> format == 1 && end_var > X_OFF_MAX )
312
312
DEBUG_RETURN_ERROR (NC_EVARSIZE )
313
313
314
- /* this will pad out non-record variables with zero to the
315
- * requested alignment. record variables are a bit trickier.
316
- * we don't do anything special with them */
317
- ncp -> vars .value [i ]-> begin = D_RNDUP (end_var , ncp -> fx_v_align );
314
+ /* this will pad out non-record variables with the 4-byte alignment */
315
+ ncp -> vars .value [i ]-> begin = D_RNDUP (end_var , 4 );
318
316
319
317
if (ncp -> old != NULL ) {
320
318
/* move to the next fixed variable */
@@ -336,19 +334,14 @@ NC_begins(NC *ncp)
336
334
337
335
/* end_var now is pointing to the end of last non-record variable */
338
336
339
- /* only (re)calculate begin_rec if there is not sufficient
340
- * space at end of non-record variables or if start of record
341
- * variables is not aligned as requested by ncp->r_align.
342
- * If the existing begin_rec is already >= index, then leave the
343
- * begin_rec as is (in case some non-record variables are deleted)
337
+ /* only (re)calculate begin_rec if there is no sufficient space at end of
338
+ * non-record variables or if the start of record variables is not aligned
339
+ * as requested by ncp->r_align.
344
340
*/
345
- if (ncp -> begin_rec < end_var ||
346
- ncp -> begin_rec != D_RNDUP (ncp -> begin_rec , ncp -> fx_v_align ))
347
- ncp -> begin_rec = D_RNDUP (end_var , ncp -> fx_v_align );
348
-
349
- /* expand free space for fixed variable section */
350
341
if (ncp -> begin_rec < end_var + ncp -> v_minfree )
351
- ncp -> begin_rec = D_RNDUP (end_var + ncp -> v_minfree , ncp -> fx_v_align );
342
+ ncp -> begin_rec = end_var + ncp -> v_minfree ;
343
+
344
+ ncp -> begin_rec = D_RNDUP (ncp -> begin_rec , 4 );
352
345
353
346
/* align the starting offset for record variable section */
354
347
if (ncp -> r_align > 1 )
@@ -921,11 +914,13 @@ ncmpio_NC_check_voffs(NC *ncp)
921
914
922
915
/*----< ncmpio__enddef() >---------------------------------------------------*/
923
916
/* This is a collective subroutine.
924
- * h_minfree Sets the pad at the end of the "header" section.
917
+ * h_minfree Sets the pad at the end of the "header" section, i.e. at least
918
+ * this amount of free space includes at the end of header extent.
925
919
* v_align Controls the alignment of the beginning of the data section for
926
920
* fixed size variables.
927
921
* v_minfree Sets the pad at the end of the data section for fixed size
928
- * variables.
922
+ * variables, i.e. at least this amount of free space between the
923
+ * fixed-size variable section and record variable section.
929
924
* r_align Controls the alignment of the beginning of the data section for
930
925
* variables which have an unlimited dimension (record variables).
931
926
*/
@@ -936,89 +931,83 @@ ncmpio__enddef(void *ncdp,
936
931
MPI_Offset v_minfree ,
937
932
MPI_Offset r_align )
938
933
{
939
- int i , flag , striping_unit , mpireturn , err = NC_NOERR , status = NC_NOERR ;
934
+ int i , num_fix_vars , mpireturn , err = NC_NOERR , status = NC_NOERR ;
940
935
char value [MPI_MAX_INFO_VAL ];
941
- MPI_Offset all_fix_var_size ;
942
936
NC * ncp = (NC * )ncdp ;
943
937
938
+ /* negative values of h_minfree, v_align, v_minfree, r_align have been
939
+ * checked at dispatchers.
940
+ */
941
+
944
942
/* sanity check for NC_ENOTINDEFINE, NC_EINVAL, NC_EMULTIDEFINE_FNC_ARGS
945
943
* has been done at dispatchers */
946
944
ncp -> h_minfree = h_minfree ;
947
945
ncp -> v_minfree = v_minfree ;
948
946
949
- /* calculate a good align size for PnetCDF level hints:
950
- * header_align_size and var_align_size based on the MPI-IO hint
951
- * striping_unit. This hint can be either supplied by the user or obtained
952
- * from MPI-IO (for example, ROMIO's Lustre driver makes a system call to
953
- * get the striping parameters of a file).
947
+ /* calculate a good file extent alignment size based on:
948
+ * + hints set by users in the environment variable PNETCDF_HINTS
949
+ * nc_header_align_size and nc_var_align_size
950
+ * + v_align set in the call to ncmpi__enddef()
951
+ * Hints set in the environment variable PNETCDF_HINTS have the higher
952
+ * precedence than the ones set in the API calls.
953
+ * The precedence of hints and arguments:
954
+ * 1. hints set in PNETCDF_HINTS environment variable at run time
955
+ * 2. hints set in the source codes, for example, a call to
956
+ * MPI_Info_set("nc_header_align_size", "1048576");
957
+ * 3. source codes calling ncmpi__enddef(). For example,
958
+ * MPI_Offset v_align = 1048576;
959
+ * ncmpi__enddef(ncid, 0, v_align, 0, 0);
960
+ * 4. defaults
961
+ * 0 for h_minfree
962
+ * 512 for v_align
963
+ * 0 for v_minfree
964
+ * 4 for r_align
954
965
*/
955
- MPI_Info_get (ncp -> mpiinfo , "striping_unit" , MPI_MAX_INFO_VAL - 1 , value ,
956
- & flag );
957
- striping_unit = 0 ;
958
- if (flag ) {
959
- errno = 0 ;
960
- striping_unit = (int )strtol (value ,NULL ,10 );
961
- if (errno != 0 ) striping_unit = 0 ;
962
- }
963
- ncp -> striping_unit = striping_unit ;
964
-
965
- all_fix_var_size = 0 ; /* sum of all defined fixed-size variables */
966
- for (i = 0 ; i < ncp -> vars .ndefined ; i ++ ) {
967
- if (IS_RECVAR (ncp -> vars .value [i ])) continue ;
968
- all_fix_var_size += ncp -> vars .value [i ]-> len ;
969
- }
970
966
971
967
/* ncp->h_align, ncp->v_align, ncp->r_align, and ncp->chunk have been
972
968
* set during file create/open */
973
969
974
- if (ncp -> h_align == 0 ) { /* user info does not set nc_header_align_size */
975
- if (v_align > 0 )
970
+ num_fix_vars = ncp -> vars .ndefined - ncp -> vars .num_rec_vars ;
971
+
972
+ if (ncp -> h_align == 0 ) { /* hint nc_header_align_size is not set */
973
+ if (ncp -> v_align > 0 ) /* hint nc_var_align_size is set */
974
+ ncp -> h_align = ncp -> v_align ;
975
+ else if (v_align > 0 ) /* v_align is passed from ncmpi__enddef */
976
976
ncp -> h_align = v_align ;
977
- else if (all_fix_var_size > 0 && r_align > 0 ) /* no fixed-size variable */
978
- ncp -> h_align = r_align ;
979
- else if (striping_unit &&
980
- all_fix_var_size > FILE_ALIGNMENT_LB * striping_unit )
981
- /* if striping_unit is available and file size sufficiently large */
982
- ncp -> h_align = striping_unit ;
983
- else
977
+
978
+ /* if no fixed-size variables is defined, use r_align */
979
+ if (ncp -> h_align == 0 && num_fix_vars == 0 ) {
980
+ if (ncp -> r_align > 0 ) /* hint nc_record_align_size is set */
981
+ ncp -> h_align = ncp -> r_align ;
982
+ else if (r_align > 0 ) /* r_align is passed from ncmpi__enddef */
983
+ ncp -> h_align = r_align ;
984
+ }
985
+ if (ncp -> h_align == 0 ) /* still not set */
984
986
ncp -> h_align = FILE_ALIGNMENT_DEFAULT ;
985
987
}
986
988
/* else respect user hint */
987
989
988
990
if (ncp -> v_align == 0 ) { /* user info does not set nc_var_align_size */
989
- if (v_align > 0 ) /* else respect user hint */
991
+ if (v_align > 0 ) /* v_align is passed from ncmpi__enddef */
990
992
ncp -> v_align = v_align ;
991
- #ifdef USE_AGGRESSIVE_ALIGN
992
- else if (striping_unit &&
993
- all_fix_var_size > FILE_ALIGNMENT_LB * striping_unit )
994
- /* if striping_unit is available and file size sufficiently large */
995
- ncp -> v_align = striping_unit ;
996
- else
997
- ncp -> v_align = FILE_ALIGNMENT_DEFAULT ;
998
- #endif
993
+ /* else ncp->v_align is already set by user/env, ignore the one passed
994
+ * by the argument v_align of this subroutine.
995
+ */
999
996
}
1000
997
1001
- if (ncp -> r_align == 0 ) { /* user info/env does not set nc_record_align_size */
1002
- if (r_align > 0 ) /* else respect user hint */
998
+ if (ncp -> r_align == 0 ) { /* user info does not set nc_record_align_size */
999
+ if (r_align > 0 ) /* r_align is passed from ncmpi__enddef */
1003
1000
ncp -> r_align = r_align ;
1004
- #ifdef USE_AGGRESSIVE_ALIGN
1005
- if (striping_unit )
1006
- ncp -> r_align = striping_unit ;
1007
- else
1008
- ncp -> r_align = FILE_ALIGNMENT_DEFAULT ;
1009
- #endif
1001
+ /* else ncp->r_align is already set by user/env, ignore the one passed
1002
+ * by the argument r_align of this subroutine.
1003
+ */
1010
1004
}
1011
- /* else ncp->r_align is already set by user/env, ignore the one passed by
1012
- * the argument r_align of this subroutine.
1013
- */
1014
1005
1015
1006
/* all CDF formats require 4-bytes alignment */
1016
1007
if (ncp -> h_align == 0 ) ncp -> h_align = 4 ;
1017
1008
else ncp -> h_align = D_RNDUP (ncp -> h_align , 4 );
1018
1009
if (ncp -> v_align == 0 ) ncp -> v_align = 4 ;
1019
1010
else ncp -> v_align = D_RNDUP (ncp -> v_align , 4 );
1020
- if (ncp -> fx_v_align == 0 ) ncp -> fx_v_align = 4 ;
1021
- else ncp -> fx_v_align = D_RNDUP (ncp -> fx_v_align , 4 );
1022
1011
if (ncp -> r_align == 0 ) ncp -> r_align = 4 ;
1023
1012
else ncp -> r_align = D_RNDUP (ncp -> r_align , 4 );
1024
1013
@@ -1027,7 +1016,7 @@ ncmpio__enddef(void *ncdp,
1027
1016
*/
1028
1017
sprintf (value , "%lld" , ncp -> h_align );
1029
1018
MPI_Info_set (ncp -> mpiinfo , "nc_header_align_size" , value );
1030
- sprintf (value , "%lld" , ncp -> fx_v_align );
1019
+ sprintf (value , "%lld" , ncp -> v_align );
1031
1020
MPI_Info_set (ncp -> mpiinfo , "nc_var_align_size" , value );
1032
1021
sprintf (value , "%lld" , ncp -> r_align );
1033
1022
MPI_Info_set (ncp -> mpiinfo , "nc_record_align_size" , value );
0 commit comments