WarpX
SignalHandling.H
Go to the documentation of this file.
1 /* Copyright 2022 Philip Miller
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef ABLASTR_SIGNAL_HANDLING_H_
9 #define ABLASTR_SIGNAL_HANDLING_H_
10 
11 #include <AMReX_Config.H>
12 
13 #if defined(AMREX_USE_MPI)
14 # include <mpi.h>
15 #endif
16 
17 #include <atomic>
18 #include <string>
19 
20 namespace ablastr::utils {
21 
35 {
36 public:
38  static constexpr int NUM_SIGNALS = 32;
39 
46  SIGNAL_REQUESTS_SIZE = 2 // This should always be 1 greater than the last valid value
47  };
48 
51 
53  static int parseSignalNameToNumber (const std::string &str);
54 
56  static void InitSignalHandling ();
57 
59  static void CheckSignals ();
61  static void WaitSignals ();
62 
64  static bool TestAndResetActionRequestFlag (int action_to_test);
65 
66  // Don't allow clients to incorrectly try to construct and use an instance of this type
67  SignalHandling () = delete;
68 
69 private:
72 
74  static std::atomic<bool> signal_received_flags[NUM_SIGNALS];
75 
76 #if defined(AMREX_USE_MPI)
79 #endif
80 
82  static void SignalSetFlag (int signal_number);
83 
87 };
88 
89 } // namespace ablastr::utils
90 
91 #endif // ABLASTR_SIGNAL_HANDLING_H_
int MPI_Request
Signal handling.
Definition: SignalHandling.H:35
static bool m_any_signal_action_active
Is any signal handling action configured in signal_conf_requests ?
Definition: SignalHandling.H:71
static void WaitSignals()
Complete the asynchronous broadcast of signal flags.
Definition: SignalHandling.cpp:185
static std::atomic< bool > signal_received_flags[NUM_SIGNALS]
On process 0, whether a given signal has been received since the last check.
Definition: SignalHandling.H:74
static int parseSignalNameToNumber(const std::string &str)
Take a string and convert it to a corresponding signal number if possible.
Definition: SignalHandling.cpp:33
static void CheckSignals()
Check and clear signal flags and asynchronously broadcast them from process 0.
Definition: SignalHandling.cpp:145
static bool signal_actions_requested[SIGNAL_REQUESTS_SIZE]
Definition: SignalHandling.H:86
static void SignalSetFlag(int signal_number)
Signal handler to set flags on process 0 (other processes ignore configured signals)
Definition: SignalHandling.cpp:207
signal_action_requested_labels
Labels for indexed positions in signal_actions_requests.
Definition: SignalHandling.H:41
@ SIGNAL_REQUESTS_BREAK
Cleanly stop execution, as if the simulation reached its configured end.
Definition: SignalHandling.H:43
@ SIGNAL_REQUESTS_SIZE
Definition: SignalHandling.H:46
@ SIGNAL_REQUESTS_CHECKPOINT
Produce a checkpoint.
Definition: SignalHandling.H:45
static void InitSignalHandling()
Set up signal handlers based on input configuration provided in signal_conf_requests_*
Definition: SignalHandling.cpp:115
static constexpr int NUM_SIGNALS
The range of signal values to accept.
Definition: SignalHandling.H:38
static MPI_Request signal_mpi_ibcast_request
MPI requests for the asynchronous broadcasts of the signal-requested actions.
Definition: SignalHandling.H:78
static bool TestAndResetActionRequestFlag(int action_to_test)
Check whether a given action has been requested, and reset the associated flag.
Definition: SignalHandling.cpp:199
static bool signal_conf_requests[SIGNAL_REQUESTS_SIZE][NUM_SIGNALS]
Whether configuration requests the code take a particular action on a particular signal.
Definition: SignalHandling.H:50
Definition: Communication.cpp:26
str
Definition: run_alltests_1node.py:72