26namespace MultiProcess {
75 queue_ptr_ = std::make_unique<PriorityQueue>();
117 if (
instance_->process_manager().is_initialized()) {
118 std::stringstream ss;
119 ss <<
"Cannot add Job to JobManager instantiation, forking has already taken place! Instance object at raw "
122 throw std::logic_error(
"Cannot add Job to JobManager instantiation, forking has already taken place! Call "
123 "terminate() on the instance before adding new Jobs.");
136 throw std::runtime_error(
"JobManager::get_job_object: unknown job ID " + std::to_string(job_object_id) +
137 ", the interprocess message stream may be corrupted");
139 return found->second;
146 bool removed_successfully =
job_objects_.erase(job_object_id) == 1;
150 return removed_successfully;
174 bool job_fully_retrieved =
false;
175 while (not job_fully_retrieved) {
178 if (task_result_message.size() <
sizeof(std::size_t)) {
179 throw std::runtime_error(
"JobManager::retrieve: received a task result message that is too short to "
180 "contain a job ID, the interprocess message stream may be corrupted");
182 auto job_object_id = *task_result_message.data<std::size_t>();
184 bool this_job_fully_retrieved =
186 if (requesting_job_id == job_object_id) {
187 job_fully_retrieved = this_job_fully_retrieved;
190 throw std::logic_error(
"in JobManager::retrieve: master received a SIGTERM, aborting");
219 }
catch (
const std::exception &
e) {
220 fprintf(stderr,
"queue process (PID %d) exits after exception: %s\n", getpid(),
e.what());
229 }
catch (
const std::exception &
e) {
230 fprintf(stderr,
"worker process (PID %d) exits after exception: %s\n", getpid(),
e.what());
static unsigned int getDefaultNWorkers()
Main point of access for all MultiProcess infrastructure.
std::unique_ptr< Messenger > messenger_ptr_
std::unique_ptr< Queue > queue_ptr_
static std::size_t add_job_object(Job *job_object)
Messenger & messenger() const
static JobManager * instance()
static std::size_t job_counter_
static Job * get_job_object(std::size_t job_object_id)
ProcessManager & process_manager() const
JobManager(std::size_t N_workers)
Don't construct JobManager objects manually, use the static instance if you need to run multiple jobs...
std::unique_ptr< ProcessManager > process_manager_ptr_
static std::map< std::size_t, Job * > job_objects_
static bool remove_job_object(std::size_t job_object_id)
static std::unique_ptr< JobManager > instance_
void retrieve(std::size_t requesting_job_id)
Retrieve results for a Job.
bool is_activated() const
void activate()
Start queue and worker loops on child processes.
static bool is_instantiated()
interface class for defining the actual work that must be done
virtual bool receive_task_result_on_master(const Message &message)=0
A contiguous byte buffer used as the unit of interprocess communication.
Manages the interprocess communication channels and wraps send and receive calls.
value_t receive_from_worker_on_master(bool *more=nullptr)
Fork processes for queue and workers.
Keeps a queue of tasks for workers and manages the queue process through its event loop.
void loop()
The queue process's event loop.
Thrown when a blocking wait on a Channel is interrupted, e.g.
void worker_loop()
The worker processes' event loop.
bool is_worker_loop_running()
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static QueueType getQueueType()