Fork processes for queue and workers.
This class manages three types of processes:
| N_workers | Number of worker processes to spawn. |
Definition at line 27 of file ProcessManager.h.
Public Member Functions | |
| ProcessManager (std::size_t N_workers) | |
| ~ProcessManager () | |
| int | claim_mq_fd () |
| Hand over the master-queue channel end for the current process type. | |
| int | claim_mw_fd (std::size_t worker_ix) |
| Hand over the master-worker channel end for the current process type. | |
| int | claim_qw_fd (std::size_t worker_ix) |
| Hand over the queue-worker channel end for the current process type. | |
| pid_t | get_queue_pid () const |
| std::vector< pid_t > | get_worker_pids () |
| void | identify_processes () const |
| Print to stdout which type of process we are on and what its PID is (for debugging) | |
| bool | is_initialized () const |
| bool | is_master () const |
| bool | is_queue () const |
| bool | is_worker () const |
| std::size_t | N_workers () const |
| void | terminate () noexcept |
| Shutdown forked processes if on master and if this process manager is initialized. | |
| void | wait_for_sigterm_then_exit () |
| std::size_t | worker_id () const |
Static Public Member Functions | |
| static void | handle_sigterm (int signum) |
| We need this to tell the children to die, because we can't talk to them anymore during JobManager destruction, because that kills the Messenger first. | |
| static bool | sigterm_received () |
| static int | sigterm_wake_fd () |
| Read end of the self-pipe that the SIGTERM handler writes to (or -1 on the master process, which installs no handler); used by Channel::wait. | |
Private Member Functions | |
| void | close_channel_fds () |
| Close all channel ends still owned by this ProcessManager (i.e. | |
| void | close_unused_channel_fds () |
| Close the channel ends that do not belong to the current process type. | |
| void | create_channel_fds () |
| Create the socketpairs that connect the processes. | |
| void | initialize_processes (bool cpu_pinning=true) |
| Fork processes and activate CPU pinning. | |
| void | shutdown_processes () |
| Shutdown forked processes if on master. | |
Private Attributes | |
| bool | initialized_ = false |
| bool | is_master_ = false |
| bool | is_queue_ = false |
| bool | is_worker_ = false |
| std::array< int, 2 > | mq_fds_ {{-1, -1}} |
| std::vector< std::array< int, 2 > > | mw_fds_ |
| std::size_t | N_workers_ |
| friend | Queue |
| pid_t | queue_pid_ |
| std::vector< std::array< int, 2 > > | qw_fds_ |
| std::size_t | worker_id_ |
| std::vector< pid_t > | worker_pids_ |
Static Private Attributes | |
| static volatile sig_atomic_t | sigterm_received_ = 0 |
| static int | sigterm_wake_read_fd_ = -1 |
| static int | sigterm_wake_write_fd_ = -1 |
#include </github/home/ROOT-CI/src/roofit/multiprocess/res/RooFit/MultiProcess/ProcessManager.h>
|
explicit |
Definition at line 43 of file ProcessManager.cxx.
| RooFit::MultiProcess::ProcessManager::~ProcessManager | ( | ) |
Definition at line 52 of file ProcessManager.cxx.
| int RooFit::MultiProcess::ProcessManager::claim_mq_fd | ( | ) |
Hand over the master-queue channel end for the current process type.
Definition at line 216 of file ProcessManager.cxx.
| int RooFit::MultiProcess::ProcessManager::claim_mw_fd | ( | std::size_t | worker_ix | ) |
Hand over the master-worker channel end for the current process type.
Definition at line 228 of file ProcessManager.cxx.
| int RooFit::MultiProcess::ProcessManager::claim_qw_fd | ( | std::size_t | worker_ix | ) |
Hand over the queue-worker channel end for the current process type.
Definition at line 222 of file ProcessManager.cxx.
|
private |
Close all channel ends still owned by this ProcessManager (i.e.
not claimed by a Messenger).
Definition at line 204 of file ProcessManager.cxx.
|
private |
Close the channel ends that do not belong to the current process type.
Definition at line 179 of file ProcessManager.cxx.
|
private |
Create the socketpairs that connect the processes.
Must be called before forking; every process then keeps only the ends it needs (see close_unused_channel_fds).
Definition at line 167 of file ProcessManager.cxx.
|
inline |
Definition at line 62 of file ProcessManager.h.
|
inline |
Definition at line 63 of file ProcessManager.h.
|
static |
We need this to tell the children to die, because we can't talk to them anymore during JobManager destruction, because that kills the Messenger first.
We do that with SIGTERMs. The sigterm_received() should be checked in message loops to stop them when it's true. The handler also writes to a self-pipe, so that a poll that is entered after the flag check but before signal delivery still wakes up.
Definition at line 74 of file ProcessManager.cxx.
| void RooFit::MultiProcess::ProcessManager::identify_processes | ( | ) | const |
Print to stdout which type of process we are on and what its PID is (for debugging)
Definition at line 470 of file ProcessManager.cxx.
Fork processes and activate CPU pinning.
| cpu_pinning | Activate CPU pinning if true. Effective on Linux only. |
Definition at line 236 of file ProcessManager.cxx.
| bool RooFit::MultiProcess::ProcessManager::is_initialized | ( | ) | const |
Definition at line 356 of file ProcessManager.cxx.
| bool RooFit::MultiProcess::ProcessManager::is_master | ( | ) | const |
Definition at line 444 of file ProcessManager.cxx.
| bool RooFit::MultiProcess::ProcessManager::is_queue | ( | ) | const |
Definition at line 449 of file ProcessManager.cxx.
| bool RooFit::MultiProcess::ProcessManager::is_worker | ( | ) | const |
Definition at line 454 of file ProcessManager.cxx.
| std::size_t RooFit::MultiProcess::ProcessManager::N_workers | ( | ) | const |
Definition at line 464 of file ProcessManager.cxx.
|
private |
Shutdown forked processes if on master.
Definition at line 418 of file ProcessManager.cxx.
|
static |
Definition at line 92 of file ProcessManager.cxx.
|
static |
Read end of the self-pipe that the SIGTERM handler writes to (or -1 on the master process, which installs no handler); used by Channel::wait.
Definition at line 86 of file ProcessManager.cxx.
|
noexcept |
Shutdown forked processes if on master and if this process manager is initialized.
Definition at line 362 of file ProcessManager.cxx.
| void RooFit::MultiProcess::ProcessManager::wait_for_sigterm_then_exit | ( | ) |
Definition at line 374 of file ProcessManager.cxx.
| std::size_t RooFit::MultiProcess::ProcessManager::worker_id | ( | ) | const |
Definition at line 459 of file ProcessManager.cxx.
Definition at line 82 of file ProcessManager.h.
Definition at line 72 of file ProcessManager.h.
Definition at line 73 of file ProcessManager.h.
Definition at line 74 of file ProcessManager.h.
|
private |
Definition at line 87 of file ProcessManager.h.
|
private |
Definition at line 89 of file ProcessManager.h.
|
private |
Definition at line 76 of file ProcessManager.h.
|
private |
Definition at line 28 of file ProcessManager.h.
|
private |
Definition at line 80 of file ProcessManager.h.
|
private |
Definition at line 88 of file ProcessManager.h.
|
staticprivate |
Definition at line 91 of file ProcessManager.h.
|
staticprivate |
Definition at line 92 of file ProcessManager.h.
|
staticprivate |
Definition at line 93 of file ProcessManager.h.
|
private |
Definition at line 75 of file ProcessManager.h.
|
private |
Definition at line 79 of file ProcessManager.h.