From 7e8e1222ebdbd0ebed7a073e14c07b59aeb63e31 Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 10 Jan 2003 10:50:42 +0000 Subject: Reduce the local termination flag from all processors and have DoneMainLoop() return this global value. This prevents potential deadlocks, especially with the max_runtime termination condition. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@402 b61c5cb5-eaca-4651-9a7a-d64986f99364 --- src/Evolve.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Evolve.c b/src/Evolve.c index 910ce43..d3b54f5 100644 --- a/src/Evolve.c +++ b/src/Evolve.c @@ -187,7 +187,7 @@ int PUGH_Evolve(tFleshConfig *config) static int DoneMainLoop (const cGH *GH, CCTK_REAL simulation_time,int iteration) { int max_iteration_reached, max_simulation_time_reached, max_runtime_reached; - int retval; + CCTK_INT local, global; #ifdef HAVE_TIME_GETTIMEOFDAY struct timeval runtime; static struct timeval starttime = {0, 0}; @@ -203,8 +203,8 @@ static int DoneMainLoop (const cGH *GH, CCTK_REAL simulation_time,int iteration) } #endif - retval = terminate_next || CCTK_TerminationReached (GH); - if (! retval && ! CCTK_Equals (terminate, "never")) + local = terminate_next || CCTK_TerminationReached (GH); + if (! local && ! CCTK_Equals (terminate, "never")) { max_iteration_reached = iteration >= cctk_itlast; @@ -231,38 +231,47 @@ static int DoneMainLoop (const cGH *GH, CCTK_REAL simulation_time,int iteration) if (CCTK_Equals (terminate, "iteration")) { - retval = max_iteration_reached; + local = max_iteration_reached; } else if (CCTK_Equals (terminate, "time")) { - retval = max_simulation_time_reached; + local = max_simulation_time_reached; } else if (CCTK_Equals (terminate, "runtime")) { - retval = max_runtime_reached; + local = max_runtime_reached; } else if (CCTK_Equals (terminate, "any")) { - retval = max_iteration_reached || max_simulation_time_reached || + local = max_iteration_reached || max_simulation_time_reached || max_runtime_reached; } else if (CCTK_Equals (terminate, "all")) { - retval = max_iteration_reached && max_simulation_time_reached && + local = max_iteration_reached && max_simulation_time_reached && max_runtime_reached; } /* the following two conditions are deprecated in BETA14 */ else if (CCTK_Equals (terminate, "either")) { - retval = max_iteration_reached || max_simulation_time_reached; + local = max_iteration_reached || max_simulation_time_reached; } else /* if (CCTK_Equals (terminate, "both")) */ { - retval = max_iteration_reached && max_simulation_time_reached; + local = max_iteration_reached && max_simulation_time_reached; } } - return (retval); +#ifdef CCTK_MPI + /* reduce the local flags from all processors + into a single global termination flag */ + CACTUS_MPI_ERROR (MPI_Allreduce (&local, &global, 1, PUGH_MPI_INT, MPI_LAND, + PUGH_pGH (GH)->PUGH_COMM_WORLD)); +#else + global = local; +#endif + + return (global); } -- cgit v1.2.3