Skip to content

Commit 399bec9

Browse files
dqwujayeshkrishna
authored andcommitted
Adding test for large-dimension variables with HDF5 type
For HDF5 type, record variables are currently chunked using the full dimension length. With very large dimensions, this can cause dataset creation to fail in the HDF5 library. This test simulates an output history file from the E3SM G case with extremely large dimension lengths to reproduce the issue. It will also help guide the upcoming fix for the default chunking strategy used by HDF5 type.
1 parent 7932e70 commit 399bec9

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

examples/c/test_hdf5.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ int main(int argc, char* argv[])
4343
int dimid_ncol;
4444
int dimid_sample;
4545
int dimid_ship;
46+
int dimid_nCells;
47+
int dimid_nEdges;
48+
int dimid_nVertices;
49+
int dimid_nVertLevels;
50+
int dimid_nVertLevelsP1;
51+
int dimid_StrLen;
4652

4753
int varid;
4854
int varid_time;
@@ -57,6 +63,7 @@ int main(int argc, char* argv[])
5763
int varid_U;
5864
int varid_sample;
5965
int varid_ship;
66+
int varid_normalVelocity;
6067

6168
int att_id;
6269
int att_type;
@@ -594,6 +601,86 @@ int main(int argc, char* argv[])
594601

595602
ret = PIOc_closefile(ncid); ERR
596603

604+
if (my_rank == 0)
605+
{
606+
printf("Test reading %s with NETCDF4 IO type end\n", filename);
607+
fflush(stdout);
608+
}
609+
#endif
610+
611+
/* Simulate a history file of E3SM G case with large dimension lengths (compset GMPAS-NYF, res T62_oRRS18to6v3) */
612+
snprintf(filename, PIO_MAX_NAME, "test_hdf5_g_case_rearr_%d.nc", rearranger[r]);
613+
614+
if (my_rank == 0)
615+
{
616+
printf("Test writing %s with HDF5 IO type start\n", filename);
617+
fflush(stdout);
618+
}
619+
620+
ncid = -1;
621+
ret = PIOc_createfile(iosysid, &ncid, &format, filename, PIO_CLOBBER); ERR
622+
623+
ret = PIOc_def_dim(ncid, "Time", PIO_UNLIMITED, &dimid_time); ERR
624+
ret = PIOc_def_dim(ncid, "nCells", 3693225, &dimid_nCells); ERR
625+
ret = PIOc_def_dim(ncid, "nEdges", 11135652, &dimid_nEdges); ERR
626+
ret = PIOc_def_dim(ncid, "nVertices", 7441216, &dimid_nVertices); ERR
627+
ret = PIOc_def_dim(ncid, "nVertLevels", 81, &dimid_nVertLevels); ERR
628+
ret = PIOc_def_dim(ncid, "nVertLevelsP1", 81, &dimid_nVertLevelsP1); ERR
629+
ret = PIOc_def_dim(ncid, "StrLen", 64, &dimid_StrLen); ERR
630+
631+
dimids[0] = dimid_time;
632+
dimids[1] = dimid_nEdges;
633+
dimids[2] = dimid_nVertLevels;
634+
ret = PIOc_def_var(ncid, "normalVelocity", PIO_DOUBLE, 3, dimids, &varid_normalVelocity); ERR
635+
636+
ret = PIOc_enddef(ncid); ERR
637+
638+
ret = PIOc_closefile(ncid); ERR
639+
640+
if (my_rank == 0)
641+
{
642+
printf("Test writing %s with HDF5 IO type end\n", filename);
643+
fflush(stdout);
644+
}
645+
646+
#ifdef _NETCDF4
647+
/* Direct read support for HDF5 IO type is not implemented yet: SCORPIO implicitly switches HDF5 type to
648+
* NETCDF4 type for reading back output files (generated by HDF5 type, fully NETCDF4 compatible). */
649+
if (my_rank == 0)
650+
{
651+
printf("Test reading %s with NETCDF4 IO type start\n", filename);
652+
fflush(stdout);
653+
}
654+
655+
ncid = -1;
656+
ret = PIOc_openfile(iosysid, &ncid, &format, filename, PIO_NOWRITE); ERR
657+
658+
ndims = -1;
659+
ret = PIOc_inq_ndims(ncid, &ndims); ERR
660+
assert(ndims == 7);
661+
662+
dimid_time = -1;
663+
ret = PIOc_inq_dimid(ncid, "Time", &dimid_time); ERR
664+
assert(dimid_time >= 0 && dimid_time < ndims);
665+
666+
nvars = -1;
667+
ret = PIOc_inq_nvars(ncid, &nvars); ERR
668+
assert(nvars == 1);
669+
670+
PIO_Offset dimlen_nCells = -1;
671+
ret = PIOc_inq_dimlen(ncid, dimid_nCells, &dimlen_nCells); ERR
672+
assert(dimlen_nCells == 3693225);
673+
674+
PIO_Offset dimlen_nEdges = -1;
675+
ret = PIOc_inq_dimlen(ncid, dimid_nEdges, &dimlen_nEdges); ERR
676+
assert(dimlen_nEdges == 11135652);
677+
678+
PIO_Offset dimlen_nVertices = -1;
679+
ret = PIOc_inq_dimlen(ncid, dimid_nVertices, &dimlen_nVertices); ERR
680+
assert(dimlen_nVertices == 7441216);
681+
682+
ret = PIOc_closefile(ncid); ERR
683+
597684
if (my_rank == 0)
598685
{
599686
printf("Test reading %s with NETCDF4 IO type end\n", filename);

0 commit comments

Comments
 (0)