Skip to content

Commit

Permalink
Merge pull request #318 from EinsteinToolkit/main
Browse files Browse the repository at this point in the history
CarpetX: Reduce termination condition
  • Loading branch information
lucass-carneiro authored Nov 5, 2024
2 parents b8c3a71 + 26d4d11 commit 6836198
Showing 1 changed file with 30 additions and 26 deletions.
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

0 comments on commit 6836198

Please sign in to comment.