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

Add [[noreturn]] attribute to Output::fatal, add SST_Exit() function #1175

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 2 additions & 16 deletions src/sst/core/output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ REENABLE_WARNING

namespace SST {

// Atomic to control access to calling MPI_Abort or exit() in fatal() call
std::atomic<int> fatal_count = 0;

// Initialize The Static Member Variables
Output Output::m_defaultObject;
std::string Output::m_sstGlobalSimFileName = "";
Expand Down Expand Up @@ -159,7 +156,7 @@ Output::getOutputLocation() const
return m_targetLoc;
}

void
[[noreturn]] void
Output::fatal(uint32_t line, const char* file, const char* func, int exit_code, const char* format, ...) const
{
va_list arg1;
Expand Down Expand Up @@ -217,18 +214,7 @@ Output::fatal(uint32_t line, const char* file, const char* func, int exit_code,

Simulation_impl::emergencyShutdown();

int count = fatal_count.fetch_add(1);

// Make sure only one thread calls MPI_Abort() or exit() in the
// case where two threads call fatal() at the same time
if ( count == 0 ) {
#ifdef SST_CONFIG_HAVE_MPI
// If MPI exists, abort
MPI_Abort(MPI_COMM_WORLD, exit_code);
#else
exit(exit_code);
#endif
}
SST_Exit(exit_code);
}

void
Expand Down
3 changes: 2 additions & 1 deletion src/sst/core/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ class Output
@param format Format string. All valid formats for printf are available.
@param ... Arguments for format.
*/
void fatal(uint32_t line, const char* file, const char* func, int exit_code, const char* format, ...) const
[[noreturn]] void
fatal(uint32_t line, const char* file, const char* func, int exit_code, const char* format, ...) const
__attribute__((format(printf, 6, 7)));

// GET / SET METHODS
Expand Down
26 changes: 26 additions & 0 deletions src/sst/core/simulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
#include "sst/core/unitAlgebra.h"
#include "sst/core/warnmacros.h"

#ifdef SST_CONFIG_HAVE_MPI
DISABLE_WARN_MISSING_OVERRIDE
#include <mpi.h>
REENABLE_WARNING
#endif

#include <cinttypes>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -2064,6 +2071,25 @@ Simulation_impl::printPerformanceInfo()
}
#endif

[[noreturn]] void
SST_Exit(int exit_code)
{
// Make sure only one thread calls MPI_Abort() or exit() in the
// case where two threads call fatal() at the same time
// Only one thread initializes the function-local static variable
// Other threads are blocked

#ifdef SST_CONFIG_HAVE_MPI
// If MPI exists, abort
static int exit_once = (MPI_Abort(MPI_COMM_WORLD, exit_code), 0);
#else
static int exit_once = (exit(exit_code), 0);
#endif

// Should never get here
std::terminate();
}

/* Define statics */
Factory* Simulation_impl::factory;
TimeLord Simulation_impl::timeLord;
Expand Down
8 changes: 6 additions & 2 deletions src/sst/core/simulation_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "sst/core/clock.h"
#include "sst/core/componentInfo.h"
#include "sst/core/exit.h"
#include "sst/core/oneshot.h"
#include "sst/core/output.h"
#include "sst/core/profile/profiletool.h"
Expand All @@ -36,6 +37,9 @@ extern int main(int argc, char** argv);

namespace SST {

// Function to exit, guarding against race conditions if multiple threads call it
[[noreturn]] void SST_Exit(int exit_code);

#define _SIM_DBG(fmt, args...) __DBG(DBG_SIM, Sim, fmt, ##args)
#define STATALLFLAG "--ALLSTATS--"

Expand Down Expand Up @@ -243,7 +247,7 @@ class Simulation_impl
if ( nullptr != i ) { return i->getComponent(); }
else {
printf("Simulation::getComponent() couldn't find component with id = %" PRIu64 "\n", id);
exit(1);
SST_Exit(1);
}
}

Expand All @@ -255,7 +259,7 @@ class Simulation_impl
if ( nullptr != i ) { return i; }
else {
printf("Simulation::getComponentInfo() couldn't find component with id = %" PRIu64 "\n", id);
exit(1);
SST_Exit(1);
}
}

Expand Down
Loading