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

CarpetX: Reduce termination condition #318

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions CarpetX/src/schedule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1369,41 +1369,45 @@ int Initialise(tFleshConfig *config) {
bool EvolutionIsDone(cGH *restrict const cctkGH) {
DECLARE_CCTK_PARAMETERS;

if (terminate_next || CCTK_TerminationReached(cctkGH))
return true;

if (CCTK_Equals(terminate, "never"))
return false;

const bool max_iteration_reached = cctkGH->cctk_iteration >= cctk_itlast;

const bool max_simulation_time_reached =
cctk_initial_time < cctk_final_time
? cctkGH->cctk_time >= cctk_final_time
: cctkGH->cctk_time <= cctk_final_time;

int runtime = CCTK_RunTime();
MPI_Bcast(&runtime, 1, MPI_INT, 0, MPI_COMM_WORLD);
const int runtime = CCTK_RunTime();
const bool max_runtime_reached = runtime >= 60 * max_runtime;

if (CCTK_Equals(terminate, "iteration"))
return max_iteration_reached;
if (CCTK_Equals(terminate, "time"))
return max_simulation_time_reached;
if (CCTK_Equals(terminate, "runtime"))
return max_runtime_reached;
if (CCTK_Equals(terminate, "any"))
return max_iteration_reached || max_simulation_time_reached ||
max_runtime_reached;
if (CCTK_Equals(terminate, "all"))
return max_iteration_reached && max_simulation_time_reached &&
max_runtime_reached;
if (CCTK_Equals(terminate, "either"))
return max_iteration_reached || max_simulation_time_reached;
if (CCTK_Equals(terminate, "both"))
return max_iteration_reached && max_simulation_time_reached;

assert(0);
bool we_are_done;
if (terminate_next || CCTK_TerminationReached(cctkGH))
we_are_done = true;
else if (CCTK_Equals(terminate, "never"))
we_are_done = false;
else if (CCTK_Equals(terminate, "iteration"))
we_are_done = max_iteration_reached;
else if (CCTK_Equals(terminate, "time"))
we_are_done = max_simulation_time_reached;
else if (CCTK_Equals(terminate, "runtime"))
we_are_done = max_runtime_reached;
else if (CCTK_Equals(terminate, "any"))
we_are_done = max_iteration_reached || max_simulation_time_reached ||
max_runtime_reached;
else if (CCTK_Equals(terminate, "all"))
we_are_done = max_iteration_reached && max_simulation_time_reached &&
max_runtime_reached;
else if (CCTK_Equals(terminate, "either"))
we_are_done = max_iteration_reached || max_simulation_time_reached;
else if (CCTK_Equals(terminate, "both"))
we_are_done = max_iteration_reached && max_simulation_time_reached;
else
CCTK_ERROR("internal error");

// Ensure all processes make the same decision
MPI_Allreduce(MPI_IN_PLACE, &we_are_done, 1, MPI_CXX_BOOL, MPI_LOR,
MPI_COMM_WORLD);

return we_are_done;
}

void InvalidateTimelevels(cGH *restrict const cctkGH) {
Expand Down