From 1e60cc18e58988d682248e60f8a454b407586860 Mon Sep 17 00:00:00 2001 From: wkliao Date: Wed, 11 Sep 2024 13:18:20 -0500 Subject: [PATCH] Handle case when D*.fill_starts variables are not available in map files PR #174 added a feature to write missing values from the map files. It add a new variable D*.fill_starts into the map file. This commit checks if it is available. If not, it ignores that variable and use D*.nreqs, as if there is no missing values. --- src/read_decomp.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/read_decomp.cpp b/src/read_decomp.cpp index 2a8c7f15..dc85c9e3 100644 --- a/src/read_decomp.cpp +++ b/src/read_decomp.cpp @@ -112,7 +112,7 @@ int read_decomp (e3sm_io_config *cfg, e3sm_io_decom *decom) { char name[128]; int err, rank, nprocs, ncid, varid, proc_start, proc_count; int i, j, k, nreqs, *all_nreqs, *all_raw_nreqs, dimids[3], id; - int *fill_nreqs = NULL, has_raw_decom, decomp_nprocs; + int *fill_nreqs = NULL, has_fill_starts, has_raw_decom, decomp_nprocs; MPI_Offset mpi_num, mpi_decomp_nprocs, start, count; MPI_Info info = MPI_INFO_NULL; e3sm_io_config decom_cfg; @@ -230,6 +230,22 @@ int read_decomp (e3sm_io_config *cfg, e3sm_io_decom *decom) { for (i=0; indims[id]; i++) decom->dims[id][i] = (MPI_Offset)dims_int[i]; + /* Obtain varid of request variable Dx.fill_starts, the starting index + * in offsets[] and lengths[] for elements to be filled with fill + * value. Note use Dx.fill_starts as the number of write requests, so + * writes stop at this index, without filling the missing elements. + * + * First, check if variable D*.fill_starts is available. The older + * versions, prior to PR #174, do not include this variable. + */ + sprintf (name, "D%d.fill_starts", id + 1); + err = driver->inq_varid (ncid, name, &varid); + has_fill_starts = 1; + if (err == NC_ENOTVAR) + has_fill_starts = 0; + else + CHECK_ERR + if (cfg->fill_mode && cfg->strategy == canonical) { /* Read variable Dx.fill_starts, which stores the index of Dx.nreqs * pointing to the first request that needs to be filled with fill @@ -237,13 +253,11 @@ int read_decomp (e3sm_io_config *cfg, e3sm_io_decom *decom) { * Dx.fill_starts[i] and (Dx.nreqs[i] - Dx.fill_starts[i]) is the * number of requests that need to be filled. */ - sprintf (name, "D%d.fill_starts", id + 1); - err = driver->inq_varid (ncid, name, &varid); - CHECK_ERR - - fill_nreqs = (int *)malloc (decomp_nprocs * sizeof (int)); - err = driver->get_vara (ncid, varid, MPI_INT, NULL, NULL, fill_nreqs, coll); - CHECK_ERR + if (has_fill_starts) { + fill_nreqs = (int *)malloc (decomp_nprocs * sizeof (int)); + err = driver->get_vara (ncid, varid, MPI_INT, NULL, NULL, fill_nreqs, coll); + CHECK_ERR + } /* Obtain varid of request variable Dx.nreqs. Note Dx.nreqs * includes the missing elements to be filled if there is any @@ -253,24 +267,13 @@ int read_decomp (e3sm_io_config *cfg, e3sm_io_decom *decom) { err = driver->inq_varid (ncid, name, &varid); CHECK_ERR } - else { - /* Obtain varid of request variable Dx.fill_starts, the starting - * index in offsets[] and lengths[] for elements to be filled with - * fill value. Note use Dx.fill_starts as the number of write - * requests, so writes stop at this index, without filling the - * missing elements. - */ - sprintf (name, "D%d.fill_starts", id + 1); - err = driver->inq_varid (ncid, name, &varid); - CHECK_ERR - } /* read all process's numbers of requests */ all_nreqs = (int *)malloc (decomp_nprocs * sizeof (int)); err = driver->get_vara (ncid, varid, MPI_INT, NULL, NULL, all_nreqs, coll); CHECK_ERR - if (cfg->fill_mode && cfg->strategy == canonical) { + if (cfg->fill_mode && cfg->strategy == canonical && has_fill_starts) { for (i=0; i