Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Sep 6, 2019
2 parents 7c2c7e7 + 49ab208 commit 9c7f67c
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 49 deletions.
3 changes: 3 additions & 0 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ typedef struct var_desc_t
/** Holds the fill value of this var. */
void *fillvalue;

/** Number of dimensions for this var. */
int ndims;

/** Non-zero if fill mode is turned on for this var. */
int use_fill;

Expand Down
16 changes: 10 additions & 6 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,10 @@ pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobuf)
ndims = iodesc->ndims;

/* Get the number of dims for this var in the file. */
if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);
/* if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims))) */
/* return pio_err(ios, file, ierr, __FILE__, __LINE__); */
fndims = vdesc->ndims;
PLOG((3, "fndims %d vdesc->ndims %d", fndims, vdesc->ndims));
#if USE_VARD_READ
if(!ios->async || !ios->ioproc)
ierr = get_gdim0(file, iodesc, vid, fndims, &gdim0);
Expand Down Expand Up @@ -1461,15 +1463,17 @@ pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid,
ndims = iodesc->ndims;

/* Get number of dims for this var. */
if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);
fndims = vdesc->ndims;
/* if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims))) */
/* return pio_err(ios, file, ierr, __FILE__, __LINE__); */

/* If setframe was not called, use a default value of 0. This is
* required for backward compatibility. */
if (fndims == ndims + 1 && vdesc->record < 0)
vdesc->record = 0;
PLOG((3, "fndims %d ndims %d vdesc->record %d", fndims, ndims,
vdesc->record));
PLOG((3, "fndims %d ndims %d vdesc->record %d vdesc->ndims %d", fndims,
ndims, vdesc->record, vdesc->ndims));
/* pioassert(fndims == vdesc->ndims, "bad ndims", __FILE__, __LINE__); */

/* Confirm that we are being called with the correct ndims. */
pioassert((fndims == ndims && vdesc->record < 0) ||
Expand Down
3 changes: 2 additions & 1 deletion src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ extern "C" {

/* List operations for var_desc_t list. */
int add_to_varlist(int varid, int rec_var, int pio_type, int pio_type_size,
MPI_Datatype mpi_type, int mpi_type_size, var_desc_t **varlist);
MPI_Datatype mpi_type, int mpi_type_size, int ndim,
var_desc_t **varlist);
int get_var_desc(int varid, var_desc_t **varlist, var_desc_t **var_desc);
int delete_var_desc(int varid, var_desc_t **varlist);

Expand Down
9 changes: 8 additions & 1 deletion src/clib/pio_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,25 @@ pio_delete_iodesc_from_list(int ioid)
* @param pio_type_size size of the PIO type in bytes
* @param mpi_type the MPI type.
* @param mpi_type_size size of the MPI type in bytes.
* @param ndims the number of dims for this var.
* @param varlist pointer to list to add to.
* @returns 0 for success, error code otherwise.
* @author Ed Hartnett
*/
int
add_to_varlist(int varid, int rec_var, int pio_type, int pio_type_size,
MPI_Datatype mpi_type, int mpi_type_size, var_desc_t **varlist)
MPI_Datatype mpi_type, int mpi_type_size, int ndims,
var_desc_t **varlist)
{
var_desc_t *var_desc;

/* Check inputs. */
pioassert(varid >= 0 && varlist, "invalid input", __FILE__, __LINE__);

PLOG((4, "add_to_varlist varid %d rec_var %d pio_type %d pio_type_size %d "
"mpi_type %d mpi_type_size %d ndims %d", varid, rec_var, pio_type,
pio_type_size, mpi_type, mpi_type_size, ndims));

/* Allocate storage. */
if (!(var_desc = calloc(1, sizeof(var_desc_t))))
return PIO_ENOMEM;
Expand All @@ -327,6 +333,7 @@ add_to_varlist(int varid, int rec_var, int pio_type, int pio_type_size,
var_desc->pio_type_size = pio_type_size;
var_desc->mpi_type = mpi_type;
var_desc->mpi_type_size = mpi_type_size;
var_desc->ndims = ndims;
var_desc->record = -1;

HASH_ADD_INT(*varlist, varid, var_desc);
Expand Down
4 changes: 2 additions & 2 deletions src/clib/pio_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ PIOc_def_dim(int ncid, const char *name, PIO_Offset len, int *idp)
}

/**
* The PIO-C interface for the NetCDF function nc_def_var.
* The PIO-C interface for the NetCDF function nc_def_var
*
* This routine is called collectively by all tasks in the communicator
* ios.union_comm. For more information on the underlying NetCDF commmand
Expand Down Expand Up @@ -2302,7 +2302,7 @@ PIOc_def_var(int ncid, const char *name, nc_type xtype, int ndims,

/* Add to the list of var_desc_t structs for this file. */
if ((ierr = add_to_varlist(varid, rec_var, xtype, (int)pio_type_size, mpi_type,
mpi_type_size, &file->varlist)))
mpi_type_size, ndims, &file->varlist)))
return pio_err(ios, NULL, ierr, __FILE__, __LINE__);
file->nvars++;

Expand Down
74 changes: 54 additions & 20 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,8 @@ check_unlim_use(int ncid)
/**
* Internal function used when opening an existing file. This function
* is called by PIOc_openfile_retry(). It learns some things about the
* metadata in that file. The results end up in the file_desc_t.
* metadata in that file. The results end up in the file_desc_t and
* var_desc_t structs for this file and the vars in it.
*
* @param file pointer to the file_desc_t for this file.
* @param ncid the ncid assigned to the file when opened.
Expand All @@ -2224,21 +2225,29 @@ check_unlim_use(int ncid)
* @param mpi_type_size gets an array (length nvars) of the size of
* the MPI type for each var in the file. This array must be freed by
* caller.
* @param ndim gets an array (length nvars) with the number of
* dimensions of each var.
*
* @return 0 for success, error code otherwise.
* @ingroup PIO_openfile_c
* @author Ed Hartnett
*/
int
inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec_var,
int **pio_type, int **pio_type_size, MPI_Datatype **mpi_type, int **mpi_type_size)
static int
inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars,
int **rec_var, int **pio_type, int **pio_type_size,
MPI_Datatype **mpi_type, int **mpi_type_size, int **ndims)
{
int nunlimdims = 0; /* The number of unlimited dimensions. */
int unlimdimid;
int *unlimdimids;
int mpierr;
int ret;

/* Check inputs. */
pioassert(rec_var && pio_type && pio_type_size && mpi_type && mpi_type_size,
"pointers must be provided", __FILE__, __LINE__);

/* How many vars in the file? */
if (iotype == PIO_IOTYPE_PNETCDF)
{
#ifdef _PNETCDF
Expand All @@ -2252,6 +2261,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec
return pio_err(NULL, file, PIO_ENOMEM, __FILE__, __LINE__);
}

/* Allocate storage for info about each var. */
if (*nvars)
{
if (!(*rec_var = malloc(*nvars * sizeof(int))))
Expand All @@ -2264,6 +2274,8 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec
return PIO_ENOMEM;
if (!(*mpi_type_size = malloc(*nvars * sizeof(int))))
return PIO_ENOMEM;
if (!(*ndims = malloc(*nvars * sizeof(int))))
return PIO_ENOMEM;
}

/* How many unlimited dims for this file? */
Expand Down Expand Up @@ -2323,6 +2335,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec
if ((ret = ncmpi_inq_var(ncid, v, NULL, &my_type, &var_ndims, NULL, NULL)))
return pio_err(NULL, file, ret, __FILE__, __LINE__);
(*pio_type)[v] = (int)my_type;
(*ndims)[v] = var_ndims;
if ((ret = pioc_pnetcdf_inq_type(ncid, (*pio_type)[v], NULL, &type_size)))
return check_netcdf(file, ret, __FILE__, __LINE__);
(*pio_type_size)[v] = type_size;
Expand All @@ -2335,6 +2348,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec
if ((ret = nc_inq_var(ncid, v, NULL, &my_type, &var_ndims, NULL, NULL)))
return pio_err(NULL, file, ret, __FILE__, __LINE__);
(*pio_type)[v] = (int)my_type;
(*ndims)[v] = var_ndims;
if ((ret = nc_inq_type(ncid, (*pio_type)[v], NULL, &type_size)))
return check_netcdf(file, ret, __FILE__, __LINE__);
(*pio_type_size)[v] = type_size;
Expand Down Expand Up @@ -2516,6 +2530,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
int *pio_type_size = NULL;
MPI_Datatype *mpi_type = NULL;
int *mpi_type_size = NULL;
int *ndims = NULL;
int mpierr = MPI_SUCCESS, mpierr2; /** Return code from MPI function codes. */
int ierr = PIO_NOERR; /* Return code from function calls. */

Expand Down Expand Up @@ -2596,18 +2611,21 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
ierr = nc_open(filename, mode, &file->fh);
#else
imode = mode | NC_MPIIO;
if ((ierr = nc_open_par(filename, imode, ios->io_comm, ios->info, &file->fh)))
if ((ierr = nc_open_par(filename, imode, ios->io_comm, ios->info,
&file->fh)))
break;

/* Check the vars for valid use of unlim dims. */
if ((ierr = check_unlim_use(file->fh)))
break;

if ((ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4P, &nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type, &mpi_type_size)))
if ((ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4P,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndims)))
break;
PLOG((2, "PIOc_openfile_retry:nc_open_par filename = %s mode = %d imode = %d ierr = %d",
filename, mode, imode, ierr));
PLOG((2, "PIOc_openfile_retry:nc_open_par filename = %s mode = %d "
"imode = %d ierr = %d", filename, mode, imode, ierr));
#endif
break;

Expand All @@ -2619,8 +2637,10 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
/* Check the vars for valid use of unlim dims. */
if ((ierr = check_unlim_use(file->fh)))
break;
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4C, &nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type, &mpi_type_size);
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4C,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndims);
}
break;
#endif /* _NETCDF4 */
Expand All @@ -2630,8 +2650,10 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
{
if ((ierr = nc_open(filename, mode, &file->fh)))
break;
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF, &nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type, &mpi_type_size);
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndims);
}
break;

Expand All @@ -2643,14 +2665,17 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
if (ierr == PIO_NOERR && (mode & PIO_WRITE))
{
if (ios->iomaster == MPI_ROOT)
PLOG((2, "%d Setting IO buffer %ld", __LINE__, pio_buffer_size_limit));
PLOG((2, "%d Setting IO buffer %ld", __LINE__,
pio_buffer_size_limit));
ierr = ncmpi_buffer_attach(file->fh, pio_buffer_size_limit);
}
PLOG((2, "ncmpi_open(%s) : fd = %d", filename, file->fh));

if (!ierr)
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_PNETCDF, &nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type, &mpi_type_size);
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_PNETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndims);
break;
#endif

Expand Down Expand Up @@ -2680,8 +2705,10 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
{
ierr = nc_open(filename, mode, &file->fh);
if (ierr == PIO_NOERR)
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF, &nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type, &mpi_type_size);
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndims);
}
else
file->do_io = 0;
Expand Down Expand Up @@ -2734,6 +2761,8 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
if (!(mpi_type_size = malloc(nvars * sizeof(int))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
if (!(ndims = malloc(nvars * sizeof(int))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
}
if (nvars)
{
Expand All @@ -2747,6 +2776,8 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
return check_mpi(NULL, file, mpierr, __FILE__, __LINE__);
if ((mpierr = MPI_Bcast(mpi_type_size, nvars, MPI_INT, ios->ioroot, ios->my_comm)))
return check_mpi(NULL, file, mpierr, __FILE__, __LINE__);
if ((mpierr = MPI_Bcast(ndims, nvars, MPI_INT, ios->ioroot, ios->my_comm)))
return check_mpi(NULL, file, mpierr, __FILE__, __LINE__);
}

/* With the netCDF integration layer, the ncid is assigned for PIO
Expand Down Expand Up @@ -2780,8 +2811,9 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,

/* Add info about the variables to the file_desc_t struct. */
for (int v = 0; v < nvars; v++)
if ((ierr = add_to_varlist(v, rec_var[v], pio_type[v], pio_type_size[v], mpi_type[v],
mpi_type_size[v], &file->varlist)))
if ((ierr = add_to_varlist(v, rec_var[v], pio_type[v], pio_type_size[v],
mpi_type[v], mpi_type_size[v], ndims[v],
&file->varlist)))
return pio_err(ios, NULL, ierr, __FILE__, __LINE__);
file->nvars = nvars;

Expand All @@ -2798,6 +2830,8 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
free(mpi_type);
if (mpi_type_size)
free(mpi_type_size);
if (ndims)
free(ndims);
}

#ifdef USE_MPE
Expand Down
5 changes: 3 additions & 2 deletions tests/cunit/test_async_1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char **argv)
/* Make sure we have 4 tasks. */
if (ntasks != TARGET_NTASKS) ERR(ERR_WRONG);

PIOc_set_log_level(4);
/* PIOc_set_log_level(4); */

/* Change error handling so we can test inval parameters. */
if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL)))
Expand All @@ -87,7 +87,8 @@ int main(int argc, char **argv)
int gdimlen[NDIM1] = {DIM_LEN_1};
PIO_Offset compmap[MAPLEN];
int varid;
int data, data_in;
int data;
/* int data_in; */
int ioid;

/* Create a file. */
Expand Down
1 change: 0 additions & 1 deletion tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
if (PIOc_write_darray_multi(ncid, &varid_big, ioid, 1, arraylen, test_data, &frame,
fillvalue, flushtodisk) != PIO_ENOTVAR)
ERR(ERR_WRONG);
// pio_setloglevel(3);
if (PIOc_write_darray_multi(ncid, &wrong_varid, ioid, 1, arraylen, test_data, &frame,
fillvalue, flushtodisk) != PIO_ENOTVAR)
ERR(ERR_WRONG);
Expand Down
Loading

0 comments on commit 9c7f67c

Please sign in to comment.