Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restaring from files not containing the derefinement counter (from #1073) #1089

Merged
merged 10 commits into from
May 29, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [[PR 1004]](https://github.com/parthenon-hpc-lab/parthenon/pull/1004) Allow parameter modification from an input file for restarts

### Fixed (not changing behavior/API/variables/...)
- [[PR 1089]](https://github.com/parthenon-hpc-lab/parthenon/pull/1089) Fix loading restart files without derefinement counter
- [[PR 1083]](https://github.com/parthenon-hpc-lab/parthenon/pull/1083) Correctly fill VariableFluxPack for edge fluxes in 2D
- [[PR 1087]](https://github.com/parthenon-hpc-lab/parthenon/pull/1087) Make sure InnerLoopPatternTVR is resolved on device properly when it is the default loop pattern
- [[PR 1071]](https://github.com/parthenon-hpc-lab/parthenon/pull/1070) Fix bug in static mesh refinement related to redefinition of Mesh::root_level
Expand Down
24 changes: 21 additions & 3 deletions src/mesh/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,21 @@ Mesh::Mesh(ParameterInput *pin, ApplicationInput *app_in, RestartReader &rr,
auto lx123 = mesh_info.lx123;
auto locLevelGidLidCnghostGflag = mesh_info.level_gid_lid_cnghost_gflag;
current_level = -1;
// Ugly fix to adjust to the change the number of component for each block when the
// deallocation counter was introduced
// (https://github.com/parthenon-hpc-lab/parthenon/pull/1073) so that restarting older
// files works.
auto NumIDsAndFlags_in_file = NumIDsAndFlags;
if (locLevelGidLidCnghostGflag.size() / nbtotal == 5) {
NumIDsAndFlags_in_file = 5;
} else {
PARTHENON_REQUIRE_THROWS(locLevelGidLidCnghostGflag.size() / nbtotal ==
NumIDsAndFlags,
"Trying to restart with an unexpected number of entries. "
"Did NumIDsAndFlags change?");
}
for (int i = 0; i < nbtotal; i++) {
loclist[i] = LogicalLocation(locLevelGidLidCnghostGflag[NumIDsAndFlags * i],
loclist[i] = LogicalLocation(locLevelGidLidCnghostGflag[NumIDsAndFlags_in_file * i],
lx123[3 * i], lx123[3 * i + 1], lx123[3 * i + 2]);
}

Expand Down Expand Up @@ -692,9 +705,14 @@ Mesh::Mesh(ParameterInput *pin, ApplicationInput *app_in, RestartReader &rr,
block_list[i - nbs] =
MeshBlock::Make(i, i - nbs, loclist[i], block_size, block_bcs, this, pin, app_in,
packages, resolved_packages, gflag, costlist[i]);
if (block_list[i - nbs]->pmr)
if (block_list[i - nbs]->pmr) {
// NumIDsAndFlags == 5 is a "older" format that did not contain the derefinement
// count so it's set to 0 (which was the previous default behavior)
block_list[i - nbs]->pmr->DerefinementCount() =
locLevelGidLidCnghostGflag[NumIDsAndFlags * i + 5];
NumIDsAndFlags_in_file == 5
? 0
: locLevelGidLidCnghostGflag[NumIDsAndFlags * i + 5];
}
}
BuildGMGBlockLists(pin, app_in);
SetMeshBlockNeighbors(GridIdentifier::leaf(), block_list, ranklist);
Expand Down
2 changes: 2 additions & 0 deletions src/outputs/restart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace parthenon {
class Mesh;
class Param;

// If this number changes, the logic for reading previously written restart files in
// mesh.cpp needs to be adjusted.
constexpr int NumIDsAndFlags{6};

class RestartReader {
Expand Down
Loading