Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
terminator.cpp
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
8 
9 #include <csignal>
10 #include <cstdlib>
11 #include <iostream>
12 
16 
17 namespace {
22 void signalHandler(int signal)
23 {
24  std::cerr << "[SIGNAL]: Received signal " << signal << " (" << strsignal(signal) << "), exiting" << std::endl;
26 }
27 
28 } // namespace
29 
30 namespace serac {
31 
32 namespace terminator {
33 
35 {
36  std::signal(SIGINT, signalHandler);
37  std::signal(SIGABRT, signalHandler);
38  std::signal(SIGSEGV, signalHandler);
39  std::signal(SIGTERM, signalHandler);
40 }
41 
42 } // namespace terminator
43 
44 void exitGracefully(bool error)
45 {
46  if (axom::slic::isInitialized()) {
47  serac::logger::flush();
48  serac::logger::finalize();
49  }
50 
51  int mpi_initialized = 0;
52  MPI_Initialized(&mpi_initialized);
53  int mpi_finalized = 0;
54  MPI_Finalized(&mpi_finalized);
55  if (mpi_initialized && !mpi_finalized) {
56  MPI_Finalize();
57  }
59 
61 
62  error ? exit(EXIT_FAILURE) : exit(EXIT_SUCCESS);
63 }
64 
65 } // namespace serac
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
This file contains the all the necessary functions and macros required for logging as well as a helpe...
void terminateDevice()
Cleans up the device, if applicable.
Definition: accelerator.cpp:33
void finalize()
Concludes performance monitoring and writes collected data to a file.
Definition: profiling.cpp:56
void registerSignals()
Registers the signalHandler function to handle various fatal signals.
Definition: terminator.cpp:34
Accelerator functionality.
Definition: serac.cpp:38
void exitGracefully(bool error)
Exits the program gracefully after cleaning up necessary tasks.
Definition: terminator.cpp:44
Various helper functions and macros for profiling using Caliper.
Helper functions for exiting Serac cleanly.