Skip to content

Commit

Permalink
now store ndims in var_desc_t and no longer need to look it up in rea…
Browse files Browse the repository at this point in the history
…d_darray()
  • Loading branch information
edhartnett committed Sep 6, 2019
1 parent 0020927 commit f07cbec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
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
4 changes: 4 additions & 0 deletions src/clib/pio_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ add_to_varlist(int varid, int rec_var, int pio_type, int pio_type_size,
/* 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 Down
29 changes: 15 additions & 14 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ check_unlim_use(int ncid)
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 **ndim)
MPI_Datatype **mpi_type, int **mpi_type_size, int **ndims)
{
int nunlimdims = 0; /* The number of unlimited dimensions. */
int unlimdimid;
Expand Down Expand Up @@ -2274,7 +2274,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars,
return PIO_ENOMEM;
if (!(*mpi_type_size = malloc(*nvars * sizeof(int))))
return PIO_ENOMEM;
if (!(*ndim = malloc(*nvars * sizeof(int))))
if (!(*ndims = malloc(*nvars * sizeof(int))))
return PIO_ENOMEM;
}

Expand Down Expand Up @@ -2335,6 +2335,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars,
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 @@ -2347,7 +2348,7 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars,
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;
(*ndim)[v] = var_ndims;
(*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 @@ -2529,7 +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 *ndim = 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 @@ -2621,7 +2622,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
if ((ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4P,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndim)))
&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));
Expand All @@ -2639,7 +2640,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF4C,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndim);
&mpi_type_size, &ndims);
}
break;
#endif /* _NETCDF4 */
Expand All @@ -2652,7 +2653,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndim);
&mpi_type_size, &ndims);
}
break;

Expand All @@ -2674,7 +2675,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_PNETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndim);
&mpi_type_size, &ndims);
break;
#endif

Expand Down Expand Up @@ -2707,7 +2708,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
ierr = inq_file_metadata(file, file->fh, PIO_IOTYPE_NETCDF,
&nvars, &rec_var, &pio_type,
&pio_type_size, &mpi_type,
&mpi_type_size, &ndim);
&mpi_type_size, &ndims);
}
else
file->do_io = 0;
Expand Down Expand Up @@ -2760,7 +2761,7 @@ 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 (!(ndim = malloc(nvars * sizeof(int))))
if (!(ndims = malloc(nvars * sizeof(int))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
}
if (nvars)
Expand All @@ -2775,7 +2776,7 @@ 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(ndim, nvars, MPI_INT, ios->ioroot, ios->my_comm)))
if ((mpierr = MPI_Bcast(ndims, nvars, MPI_INT, ios->ioroot, ios->my_comm)))
return check_mpi(NULL, file, mpierr, __FILE__, __LINE__);
}

Expand Down Expand Up @@ -2811,7 +2812,7 @@ 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], ndim[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 @@ -2829,8 +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 (ndim)
free(ndim);
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
6 changes: 3 additions & 3 deletions tests/ncint/tst_pio_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ main(int argc, char **argv)

/* Calculate a decomposition for distributed arrays. */
elements_per_pe = DIM_LEN_X * DIM_LEN_Y / (ntasks - num_io_procs);
printf("my_rank %d elements_per_pe %ld\n", my_rank, elements_per_pe);
/* printf("my_rank %d elements_per_pe %ld\n", my_rank, elements_per_pe); */
if (!(compdof = malloc(elements_per_pe * sizeof(size_t))))
PERR;
for (i = 0; i < elements_per_pe; i++)
{
compdof[i] = (my_rank - num_io_procs) * elements_per_pe + i;
printf("my_rank %d compdof[%d]=%ld\n", my_rank, i, compdof[i]);
/* printf("my_rank %d compdof[%d]=%ld\n", my_rank, i, compdof[i]); */
}

/* Create the PIO decomposition for this test. */
Expand Down Expand Up @@ -121,7 +121,7 @@ main(int argc, char **argv)
for (i = 0; i < elements_per_pe; i++)
{
compdof2[i] = (my_rank - num_io_procs) * elements_per_pe + i;
printf("my_rank %d compdof2[%d]=%lld\n", my_rank, i, compdof2[i]);
/* printf("my_rank %d compdof2[%d]=%lld\n", my_rank, i, compdof2[i]); */
}

if (PIOc_init_decomp(iosysid, PIO_INT, NDIM2, &dimlen[1], elements_per_pe, compdof2,
Expand Down
2 changes: 1 addition & 1 deletion tests/ncint/tst_pio_udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ main(int argc, char **argv)
int i;

/* Turn on logging for PIO library. */
PIOc_set_log_level(3);
/* PIOc_set_log_level(3); */

/* Initialize the intracomm. */
if (nc_def_iosystemm(MPI_COMM_WORLD, 1, 1, 0, 0, &iosysid)) PERR;
Expand Down

0 comments on commit f07cbec

Please sign in to comment.