More elegantly handle SIGINT - #1446
Conversation
Make signalflag a counter, and add intelligence to SetSignalFlag to throw an error if some number (3) SIGINTs have been received since the flag was last cleared. Also, update FS check to use std::filesystem::exists now that we're C++17
|
@Yurlungur @nbowden045 here's the updated version of the SIGINT handling PR. Basically: it's sometimes impossible to make your MPI runtime forward one SIGINT. But, I think we can still behave consistently under most circumstances: repeated SIGINT (and overzealous MPI implementations) just cause the program to die, but add a touch/trigger file |
Yurlungur
left a comment
There was a problem hiding this comment.
We still try to die gracefully after the first signal, right?
|
Yes! Until the counter hits 3 Parthenon has still just set the flag to end after the next step. To be clear, I still need to implement the file option, and test it. Not sure if our regression infra supports "send signal/create file after N seconds" but I could add a test if so. |
pgrete
left a comment
There was a problem hiding this comment.
So far so good. Looking forward to the exit_now trigger (and maybe die_now to kill the sim without outputs).
| switch (s) { | ||
| case SIGTERM: | ||
| signalflag[ITERM] = 1; | ||
| signalflag[ITERM] += 1; |
There was a problem hiding this comment.
Do you also plan to use the counter here or why is the "+"=1 important?
| break; | ||
| case SIGALRM: | ||
| signalflag[IALRM] = 1; | ||
| signalflag[IALRM] += 1; |
|
|
||
|
|
||
| ### Changed (changing behavior/API/variables/...) | ||
| - [[PR 782]](https://github.com/parthenon-hpc-lab/parthenon/pull/782) Die on repeatedly receiving SIGINT |
There was a problem hiding this comment.
| - [[PR 782]](https://github.com/parthenon-hpc-lab/parthenon/pull/782) Die on repeatedly receiving SIGINT | |
| - [[PR 1446]](https://github.com/parthenon-hpc-lab/parthenon/pull/1446) Die on repeatedly receiving SIGINT |
Currently, Parthenon has custom handlers for SIGINT, SIGTERM, and SIGALRM, which all set a flag, wait until the end of the next step, output any final files, and then terminate the program (a 'clean exit', as opposed to immediate termination).
This PR adds a fallback to exit immediately if more than three SIGINTs or SIGTERMs are received before the next file output -- i.e., if the program is hung, and the user is repeatedly pressing ^C. It will also add a trigger file
stop_nowwhich triggers a clean exit upon discovering its existence, just like the currentoutput_nowfile.PR Summary
This makes the "signalflag" array in SignalHandler into a counter of signals received since the last reset. It then adds intelligence to SetSignalFlag to throw an error if some number (currently 3) SIGINTs have been received since the flag was last cleared.
The number/behavior is not currently runtime-configurable -- I think that so long as we only die on 3+ SIGINT we're just never triggered by an MPI runtime (acting alone).
However, there are some runtimes in which it's impossible to send one SIGINT without ungracefully killing the program. Thus I'm also planning to monitor for a
stop_nowfile.(For reference: some frontends (srun) eat the first SIGINT and do nothing, whereas others (OpenMPI) effectively do nothing on 2 or more SIGINTs as they exit immediately themselves upon receiving the second. In fact, OpenMPI will never actually send a SIGINT specifically -- when it receives one, it upgrades it to a SIGTERM before sending it on, and after a timer sends SIGKILL.)
Thus we will have a general trigger:
stop_nowto request an elegant stop, but without any power to actually kill the programPR Checklist