-
Notifications
You must be signed in to change notification settings - Fork 42
Add global WatchDog #1333
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
Open
pgrete
wants to merge
1
commit into
develop
Choose a base branch
from
pgrete/add-watchdog
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add global WatchDog #1333
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| //======================================================================================== | ||
| // Parthenon performance portable AMR framework | ||
| // Copyright(C) 2025 The Parthenon collaboration | ||
| // Licensed under the 3-clause BSD License, see LICENSE file for details | ||
| //======================================================================================== | ||
| // AthenaXXX astrophysical plasma code | ||
| // Copyright(C) 2020 James M. Stone <[email protected]> and the Athena code team | ||
| // Licensed under the 3-clause BSD License (the "LICENSE") | ||
| //======================================================================================== | ||
| //! \file watchdog.cpp | ||
| // \brief WatchDog implementation ported from the Einstein Toolkit and AthenaK | ||
|
|
||
| #include <pthread.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <cstdio> | ||
| #include <ctime> | ||
|
|
||
| #include "globals.hpp" | ||
| #include "utils.hpp" | ||
|
|
||
| namespace parthenon { | ||
| namespace WatchDog { | ||
| static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| static time_t timestamp; | ||
| static struct { | ||
| int timeout_sec; | ||
| int mpi_rank; | ||
| } param; | ||
|
|
||
| static void *patrol(void *args) { | ||
| time_t time_old, time_new, ltime; | ||
| char tstamp[128]; | ||
|
|
||
| pthread_mutex_lock(&mutex); | ||
| time_old = timestamp; | ||
| pthread_mutex_unlock(&mutex); | ||
|
|
||
| if (0 == param.mpi_rank) { | ||
| ltime = time(NULL); | ||
| asctime_r(localtime(<ime), &tstamp[0]); // NOLINT | ||
| tstamp[24] = '\0'; | ||
| fprintf(stderr, "[WATCHDOG (%s)] Starting.\n", tstamp); | ||
| fflush(stderr); | ||
| } | ||
|
|
||
| while (true) { | ||
| unsigned int left = param.timeout_sec; | ||
| while (left > 0) { | ||
| left = sleep(left); | ||
| } | ||
|
|
||
| pthread_mutex_lock(&mutex); | ||
| time_new = timestamp; | ||
| pthread_mutex_unlock(&mutex); | ||
|
|
||
| ltime = time(NULL); | ||
| asctime_r(localtime(<ime), &tstamp[0]); // NOLINT | ||
| tstamp[24] = '\0'; | ||
| if (time_new == time_old) { | ||
| fprintf(stderr, "[WATCHDOG (%s)] Rank %d is not progressing.\n", tstamp, | ||
| param.mpi_rank); | ||
| fprintf(stderr, "[WATCHDOG (%s)] Terminating...\n", tstamp); | ||
| fflush(stderr); | ||
| abort(); | ||
| } else { | ||
| if (0 == param.mpi_rank) { | ||
| fprintf(stderr, "[WATCHDOG (%s)] Everything is fine.\n", tstamp); | ||
| fflush(stderr); | ||
| } | ||
| time_old = time_new; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void WatchDog(int timeout) { | ||
| pthread_mutex_lock(&mutex); | ||
| timestamp = time(NULL); | ||
| pthread_mutex_unlock(&mutex); | ||
|
|
||
| static bool first_time = true; | ||
| if (first_time) { | ||
| param.timeout_sec = timeout; | ||
| param.mpi_rank = Globals::my_rank; | ||
| pthread_t dog; /* not used beyond passed to phread_ceate */ | ||
| int ierr = pthread_create(&dog, NULL, patrol, NULL); | ||
| if (ierr) { | ||
| printf("#### FATAL ERROR in %s at line %d\n", __FILE__, __LINE__); | ||
| puts("Could not start WatchDog thread"); | ||
| std::exit(EXIT_FAILURE); | ||
| } | ||
| first_time = false; | ||
| } | ||
| } | ||
| } // namespace WatchDog | ||
| } // namespace parthenon | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super happy about adding a global variable, but given that the watchdog itself may or may not be tied to the driver, this reduces the amount of "threading through" and also should allow downstream to flexibly call the dog from any place.