diff --git a/SU2_CFD/src/drivers/CSinglezoneDriver.cpp b/SU2_CFD/src/drivers/CSinglezoneDriver.cpp
index 6b1bd3eaaaa..627ea9c41f7 100644
--- a/SU2_CFD/src/drivers/CSinglezoneDriver.cpp
+++ b/SU2_CFD/src/drivers/CSinglezoneDriver.cpp
@@ -66,8 +66,8 @@ void CSinglezoneDriver::StartSolver() {
TimeIter = config_container[ZONE_0]->GetRestart_Iter();
/*--- Run the problem until the number of time iterations required is reached. ---*/
- while ( TimeIter < config_container[ZONE_0]->GetnTime_Iter() ) {
-
+ /*--- or until a SIGTERM signal stops the loop. We catch SIGTERM and exit gracefully ---*/
+ while ( TimeIter < config_container[ZONE_0]->GetnTime_Iter()) {
/*--- Perform some preprocessing before starting the time-step simulation. ---*/
Preprocess(TimeIter);
diff --git a/SU2_CFD/src/output/COutput.cpp b/SU2_CFD/src/output/COutput.cpp
index d8aa5c16af9..499d0d69fd5 100644
--- a/SU2_CFD/src/output/COutput.cpp
+++ b/SU2_CFD/src/output/COutput.cpp
@@ -25,6 +25,9 @@
* License along with SU2. If not, see .
*/
+#include
+#include
+
#include "../../../Common/include/geometry/CGeometry.hpp"
#include "../../include/solvers/CSolver.hpp"
@@ -47,6 +50,15 @@
#include "../../include/output/filewriter/CSU2BinaryFileWriter.hpp"
#include "../../include/output/filewriter/CSU2MeshFileWriter.hpp"
+namespace {
+volatile sig_atomic_t STOP;
+
+void signalHandler(int signum) {
+ std::cout << "Interrupt signal (" << signum << ") received, saving files and exiting.\n";
+ STOP = 1;
+}
+}
+
COutput::COutput(const CConfig *config, unsigned short ndim, bool fem_output):
rank(SU2_MPI::GetRank()),
size(SU2_MPI::GetSize()),
@@ -169,7 +181,11 @@ COutput::COutput(const CConfig *config, unsigned short ndim, bool fem_output):
volumeDataSorter = nullptr;
surfaceDataSorter = nullptr;
- headerNeeded = false;
+ headerNeeded = false;
+
+ /*--- Setup a signal handler for SIGTERM. ---*/
+
+ signal(SIGTERM, signalHandler);
}
COutput::~COutput() {
@@ -233,7 +249,7 @@ void COutput::SetHistoryOutput(CGeometry ****geometry, CSolver *****solver, CCon
if (config[ZONE_0]->GetMultizone_Problem())
Iter = OuterIter;
-
+
/*--- Turbomachinery Performance Screen summary output---*/
if (Iter%100 == 0 && rank == MASTER_NODE) {
SetTurboPerformance_Output(TurboPerf, config[val_iZone], TimeIter, OuterIter, InnerIter);
@@ -946,9 +962,13 @@ bool COutput::ConvergenceMonitoring(CConfig *config, unsigned long Iteration) {
if (convFields.empty() || Iteration < config->GetStartConv_Iter()) convergence = false;
+ /*--- If a SIGTERM signal is sent to one of the processes, we set convergence to true. ---*/
+ if (STOP) convergence = true;
+
/*--- Apply the same convergence criteria to all processors. ---*/
unsigned short local = convergence, global = 0;
+
SU2_MPI::Allreduce(&local, &global, 1, MPI_UNSIGNED_SHORT, MPI_MAX, SU2_MPI::GetComm());
convergence = global > 0;