Skip to content

Commit 60b7159

Browse files
committed
when writing to a netcdf4 file we need to set var_par_access to collective
1 parent 4feee88 commit 60b7159

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

src/clib/pio_getput_int.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,6 @@ PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset
10811081
else
10821082
fake_stride = (PIO_Offset *)stride;
10831083
}
1084-
10851084
#ifdef _PNETCDF
10861085
if (file->iotype == PIO_IOTYPE_PNETCDF)
10871086
{
@@ -1137,6 +1136,14 @@ PIOc_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Offset
11371136
{
11381137
PLOG((2, "PIOc_put_vars_tc calling netcdf function file->iotype = %d",
11391138
file->iotype));
1139+
#ifdef _NETCDF4
1140+
if (file->iotype == PIO_IOTYPE_NETCDF4P)
1141+
{
1142+
PLOG((2, "Setting NC_COLLECTIVE mode"));
1143+
if ((ierr = nc_var_par_access(file->fh, varid, NC_COLLECTIVE)))
1144+
return pio_err(ios, file, ierr, __FILE__, __LINE__);
1145+
}
1146+
#endif
11401147
switch(xtype)
11411148
{
11421149
case NC_BYTE:

src/clib/pioc_support.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
27202720
#ifdef _MPISERIAL
27212721
ierr = nc_open(filename, mode, &file->fh);
27222722
#else
2723-
imode = mode | NC_MPIIO;
2723+
imode = mode | NC_MPIIO | NC_NETCDF4;
27242724
if ((ierr = nc_open_par(filename, imode, ios->io_comm, ios->info,
27252725
&file->fh))){
27262726
PLOG((2, "%d: PIOc_openfile_retry nc_open_par ierr=%d",__LINE__,ierr));
@@ -2736,6 +2736,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
27362736
&pio_type_size, &mpi_type,
27372737
&mpi_type_size, &ndims)))
27382738
break;
2739+
27392740
PLOG((2, "PIOc_openfile_retry:nc_open_par filename = %s mode = %d "
27402741
"imode = %d ierr = %d", filename, mode, imode, ierr));
27412742
#endif

tests/cunit/test_pioc_putget.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ int putget_read_vars_nt(int ncid, int *varid, PIO_Offset *start, PIO_Offset *cou
17671767
* @returns 0 for success, error code otherwise.
17681768
*/
17691769
int create_putget_file(int iosysid, int access, int unlim, int flavor, int *dim_len,
1770-
int *varid, const char *filename, int *ncidp)
1770+
int *varid, const char *filename, int *ncidp, int *tsvarid)
17711771
{
17721772
int dimids[NDIM]; /* The dimension IDs. */
17731773
int num_vars = NUM_CLASSIC_TYPES + 1;
@@ -1786,7 +1786,9 @@ int create_putget_file(int iosysid, int access, int unlim, int flavor, int *dim_
17861786
return ret;
17871787

17881788
/* Are we using unlimited dimension? */
1789-
if (!unlim)
1789+
if (unlim)
1790+
dim_len[0] = NC_UNLIMITED;
1791+
else
17901792
dim_len[0] = NUM_TIMESTEPS;
17911793

17921794
/* Define netCDF dimensions and variable. */
@@ -1812,7 +1814,14 @@ int create_putget_file(int iosysid, int access, int unlim, int flavor, int *dim_
18121814
if ((ret = PIOc_def_var(ncid, var_name, my_type, NDIM, dimids, &varid[v])))
18131815
return ret;
18141816
}
1815-
1817+
if(unlim){
1818+
/* create an additional variable with only the unlimdim dimension */
1819+
if ((ret = PIOc_def_var(ncid, "timestep", PIO_INT, 1, dimids, tsvarid)))
1820+
{
1821+
printf("Defined a timestep variable %d\n", ret);
1822+
return ret;
1823+
}
1824+
}
18161825
/* For the first access, also test attributes. */
18171826
if (access == 0)
18181827
if ((ret = test_write_atts(ncid, varid, flavor)))
@@ -1908,7 +1917,8 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
19081917
MPI_Comm test_comm)
19091918
{
19101919
int dim_len[NDIM] = {NC_UNLIMITED, X_DIM_LEN, Y_DIM_LEN};
1911-
1920+
int tsvarid;
1921+
19121922
#define NUM_ACCESS 8
19131923
for (int unlim = 0; unlim < 2; unlim++)
19141924
for (int access = 0; access < NUM_ACCESS; access++)
@@ -1931,15 +1941,15 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
19311941

19321942
/* Create test file with dims and vars defined. */
19331943
if ((ret = create_putget_file(iosysid, access, unlim, flavor[fmt], dim_len, varid,
1934-
filename, &ncid)))
1944+
filename, &ncid, &tsvarid)))
19351945
return ret;
19361946

19371947
/* Write some data. */
19381948
PIO_Offset index[NDIM] = {0, 0, 0};
19391949
PIO_Offset start[NDIM] = {0, 0, 0};
19401950
PIO_Offset count[NDIM] = {1, X_DIM_LEN, Y_DIM_LEN};
19411951
PIO_Offset stride[NDIM] = {1, 1, 1};
1942-
1952+
PIO_Offset index1d = 0;
19431953
switch (access)
19441954
{
19451955
case 0:
@@ -2003,7 +2013,21 @@ int test_putget(int iosysid, int num_flavors, int *flavor, int my_rank,
20032013
/* Check contents of the file. */
20042014
if ((ret = check_file(access, ncid, varid, flavor[fmt], index, start, count, stride, unlim)))
20052015
return ret;
2006-
2016+
if(unlim > 0) {
2017+
/* try advancing the file */
2018+
index1d = 0;
2019+
if ((ret = PIOc_put_var1_int(ncid, tsvarid, &index1d, dim_len)))
2020+
{
2021+
printf("extend file time test %d\n",ret);
2022+
return ret;
2023+
}
2024+
index1d = 1;
2025+
if ((ret = PIOc_put_var1_int(ncid, tsvarid, &index1d, dim_len+1)))
2026+
{
2027+
printf("extend file time test %d\n",ret);
2028+
return ret;
2029+
}
2030+
}
20072031
/* Close the netCDF file. */
20082032
if ((ret = PIOc_closefile(ncid)))
20092033
ERR(ret);

tests/fncint/ftst_pio.f90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ program ftst_pio
2424
integer, dimension(3) :: var_dim
2525
integer :: maplen
2626
integer :: decompid, iosysid
27-
integer :: varid, i
27+
integer :: varid, i, tsvarid
2828
integer :: ierr
2929

3030
! Set up MPI.
@@ -75,13 +75,19 @@ program ftst_pio
7575
! Define a data variable.
7676
ierr = nf_def_var(ncid, VAR_NAME, NF_INT, NDIM3, var_dim, varid)
7777
if (ierr .ne. nf_noerr) call handle_err(ierr)
78+
79+
ierr = nf_def_var(ncid, 'timestep', NF_INT, 1, var_dim(3), tsvarid)
80+
7881
ierr = nf_enddef(ncid)
7982
if (ierr .ne. nf_noerr) call handle_err(ierr)
8083

8184
! Write 1st record with distributed arrays.
8285
ierr = nf_put_vard_int(ncid, varid, decompid, 1, data_buffer)
8386
if (ierr .ne. nf_noerr) call handle_err(ierr)
8487

88+
ierr = nf_put_var(ncid, tsvarid, 2, 2)
89+
if (ierr .ne. nf_noerr) call handle_err(ierr)
90+
8591
! Close the file.
8692
ierr = nf_close(ncid)
8793
if (ierr .ne. nf_noerr) call handle_err(ierr)

0 commit comments

Comments
 (0)