Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PriorityQueue.cxx
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) 2022, 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
17#include "PriorityQueue.h"
18
19#include <algorithm> // std::copy
20
21namespace RooFit {
22namespace MultiProcess {
23
24/** \class PriorityQueue
25 * \brief Queue that orders tasks according to specified task priorities.
26 */
27
28/// See Queue::pop.
30{
31 if (queue_.empty()) {
32 return false;
33 }
34 job_task = queue_.top().jobTask;
35 queue_.pop();
36 return true;
37}
38
39/// See Queue::add.
41{
42 auto& jobManager = *JobManager::instance();
43 if (jobManager.process_manager().is_master()) {
44 jobManager.messenger().send_from_master_to_queue(M2Q::enqueue, job_task.job_id, job_task.state_id,
45 job_task.task_id);
46 } else if (jobManager.process_manager().is_queue()) {
47 std::size_t priority = 0; // default priority if no task_priority_ vector was set for this Job
48 if (task_priority_.find(job_task.job_id) != task_priority_.end()) {
49 priority = task_priority_[job_task.job_id][job_task.task_id];
50 }
51 queue_.emplace(job_task, priority);
52 } else {
53 throw std::logic_error("calling Communicator::to_master_queue from slave process");
54 }
55}
56
57/// Set the desired order for executing tasks of a Job.
58///
59/// See Config::Queue::suggestTaskOrder.
60void PriorityQueue::suggestTaskOrder(std::size_t job_id, const std::vector<Task>& task_order)
61{
62 std::vector<std::size_t> task_priorities(task_order.size());
63 for (std::size_t ix = 0; ix < task_order.size(); ++ix) {
64 task_priorities[task_order[ix]] = task_order.size() - ix;
65 }
66 setTaskPriorities(job_id, task_priorities);
67}
68
69/// Set the priority for Job tasks.
70///
71/// See Config::Queue::setTaskPriorities.
72void PriorityQueue::setTaskPriorities(std::size_t job_id, const std::vector<std::size_t>& task_priorities)
73{
74 task_priority_.clear();
75 task_priority_.reserve(task_priorities.size());
76 std::copy(task_priorities.cbegin(), task_priorities.cend(), std::back_inserter(task_priority_[job_id]));
77}
78
79} // namespace MultiProcess
80} // namespace RooFit
static JobManager * instance()
void setTaskPriorities(std::size_t job_id, const std::vector< std::size_t > &task_priorities)
Set the priority for Job tasks.
void add(JobTask job_task) override
See Queue::add.
void suggestTaskOrder(std::size_t job_id, const std::vector< Task > &task_order)
Set the desired order for executing tasks of a Job.
std::unordered_map< std::size_t, std::vector< std::size_t > > task_priority_
std::priority_queue< OrderedJobTask > queue_
bool pop(JobTask &job_task) override
See Queue::pop.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
combined job_object, state and task identifier type
Definition types.h:25