Skip to content

Commit

Permalink
Merge pull request #2863 from E3SM-Project/bartgol/eamxx/fix-nanobug-…
Browse files Browse the repository at this point in the history
…in-horiz-remap

EAMxx: avoid nullptr when reading horiz remap sparse matrix entries
  • Loading branch information
bartgol authored Jun 12, 2024
2 parents a15130c + 8a01595 commit 2783f00
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ get_my_triplets (const std::string& map_file) const
int nlweights = scorpio::get_dimlen_local(map_file,"n_s");

// 1.1 Read a chunk of triplets col indices
std::vector<gid_type> cols(nlweights);
std::vector<gid_type> rows(nlweights);
std::vector<Real> S(nlweights);
// NOTE: add 1 so that we don't pass nullptr to scorpio read routines (which would trigger
// a runtime error). Don't worry though: we never access the last entry of these vectors
std::vector<gid_type> cols(nlweights+1,-1);
std::vector<gid_type> rows(nlweights+1,-1);
std::vector<Real> S(nlweights+1,0);

// Figure out if we are reading the right map, that is:
// - n_a or n_b matches the fine grid ncols
Expand All @@ -78,6 +80,12 @@ get_my_triplets (const std::string& map_file) const
scorpio::read_var(map_file,"row",rows.data());
scorpio::read_var(map_file,"S" ,S.data());

// Previously, we added 1 to their length, to avoid nullptr in scorpio::read.
// However, we later do range loops on these vectors, so resize them back to nlweights
cols.resize(nlweights);
rows.resize(nlweights);
S.resize(nlweights);

scorpio::release_file(map_file);

// 1.2 Dofs in grid are likely 0-based, while row/col ids in map file
Expand Down

0 comments on commit 2783f00

Please sign in to comment.