Logo ROOT  
Reference Guide
ProcessManager.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
5 * IP, Inti Pelupessy, Netherlands eScience Center, i.pelupessy@esciencecenter.nl
6 *
7 * Copyright (c) 2021, CERN
8 *
9 * Redistribution and use in source and binary forms,
10 * with or without modification, are permitted according to the terms
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
12 */
13#ifndef ROOT_ROOFIT_MultiProcess_ProcessManager
14#define ROOT_ROOFIT_MultiProcess_ProcessManager
15
16#include <sys/types.h> // pid_t
17#include <csignal> // sig_atomic_t and for sigterm handling on child processes (in ProcessManager.cxx)
18#include <vector>
19
20// forward declaration
21class Queue;
22
23namespace RooFit {
24namespace MultiProcess {
25
27 friend Queue;
28
29public:
30 explicit ProcessManager(std::size_t N_workers);
32
33 bool is_initialized() const;
34
35 void terminate() noexcept;
37
38 bool is_master() const;
39 bool is_queue() const;
40 bool is_worker() const;
41 std::size_t worker_id() const;
42 std::size_t N_workers() const;
43
44 void identify_processes() const;
45
46 static void handle_sigterm(int signum);
47 static bool sigterm_received();
48
49 // for debugging/testing:
50 pid_t get_queue_pid() const { return queue_pid_; }
51 std::vector<pid_t> get_worker_pids() { return worker_pids_; }
52
53private:
54 void initialize_processes(bool cpu_pinning = true);
55 void shutdown_processes();
56
57 bool is_master_ = false;
58 bool is_queue_ = false;
59 bool is_worker_ = false;
60 std::size_t worker_id_;
61 std::size_t N_workers_;
62
63 // master must wait for workers after completion, for which it needs their PIDs
64 std::vector<pid_t> worker_pids_;
66
67 bool initialized_ = false;
68
69 static volatile sig_atomic_t sigterm_received_;
70};
71
72} // namespace MultiProcess
73} // namespace RooFit
74
75#endif // ROOT_ROOFIT_MultiProcess_ProcessManager
Fork processes for queue and workers.
std::vector< pid_t > get_worker_pids()
void initialize_processes(bool cpu_pinning=true)
Fork processes and activate CPU pinning.
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 des...
void identify_processes() const
Print to stdout which type of process we are on and what its PID is (for debugging)
void terminate() noexcept
Shutdown forked processes if on master and if this process manager is initialized.
ProcessManager(std::size_t N_workers)
void shutdown_processes()
Shutdown forked processes if on master.
static volatile sig_atomic_t sigterm_received_
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18