Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Messenger_decl.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_Messenger_decl
14#define ROOT_ROOFIT_MultiProcess_Messenger_decl
15
19
20#include <iosfwd>
21#include <string>
22#include <vector>
23
24namespace RooFit {
25namespace MultiProcess {
26
27// test messages
28enum class X2X : int { ping = -1, pong = -2, initial_value = 0 };
29
30class Messenger {
31public:
32 explicit Messenger(ProcessManager &process_manager);
34
35 void test_connections(const ProcessManager &process_manager);
36
37 enum class test_snd_pipes {
38 M2Q,
39 Q2M,
40 Q2W,
41 W2Q,
42 };
43
44 enum class test_rcv_pipes {
49 };
50
51 std::pair<Poller, std::size_t> create_queue_poller();
52 std::pair<Poller, std::size_t> create_worker_poller();
53
54 // -- WORKER - QUEUE COMMUNICATION --
55
57 template <typename T, typename... Ts>
59 template <typename value_t>
62 template <typename T, typename... Ts>
63 void send_from_queue_to_worker(std::size_t this_worker_id, T item, Ts... items);
64 template <typename value_t>
66
67 // -- QUEUE - MASTER COMMUNICATION --
68
70
71 template <typename T, typename... Ts>
73 template <typename value_t>
76
77 template <typename T, typename... Ts>
79 template <typename value_t>
81
82 // -- MASTER - WORKER COMMUNICATION --
83
84 template <typename T>
86 template <typename T, typename T2, typename... Ts>
88 template <typename value_t>
89 value_t receive_from_master_on_worker(bool *more = nullptr);
90
91 template <typename T>
93 template <typename T, typename T2, typename... Ts>
95 template <typename value_t>
96 value_t receive_from_worker_on_master(bool *more = nullptr);
97
98 void test_receive(X2X expected_ping_value, test_rcv_pipes rcv_pipe, std::size_t worker_id);
99 void test_send(X2X ping_value, test_snd_pipes snd_pipe, std::size_t worker_id);
100
101private:
102 void debug_print(std::string s);
103
104 /// On master: pick the worker channel to receive the next message from.
105 /// Continues an in-progress multipart message from the same worker;
106 /// otherwise waits for any worker and picks one round-robin.
108 void update_worker_channel_on_master(Channel &channel, bool more);
109
110 // master-queue channel (on master and queue processes)
112 // queue-worker channels (all workers on the queue process, only the own
113 // one on worker processes)
114 std::vector<Channel> qw_;
116 // master-worker channels, carrying both the state updates that were
117 // previously published over PUB-SUB and the task results (all workers on
118 // the master process, only the own one on worker processes)
119 std::vector<Channel> mw_;
121
122 // on master: bookkeeping for receiving from any worker
125 std::size_t mw_next_poll_position_ = 0;
126};
127
128// Messages from master to queue
129enum class M2Q : int {
130 enqueue = 10,
131};
132
133// Messages from worker to queue
134enum class W2Q : int { dequeue = 30 };
135
136// Messages from queue to worker
137enum class Q2W : int {
138 dequeue_rejected = 40,
139 dequeue_accepted = 41,
140};
141
142// stream output operators for debugging
143std::ostream &operator<<(std::ostream &out, const M2Q value);
144std::ostream &operator<<(std::ostream &out, const Q2W value);
145std::ostream &operator<<(std::ostream &out, const W2Q value);
146std::ostream &operator<<(std::ostream &out, const X2X value);
147
148} // namespace MultiProcess
149} // namespace RooFit
150
151#endif // ROOT_ROOFIT_MultiProcess_Messenger_decl
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
One endpoint of a full-duplex interprocess message pipe.
Definition Channel.h:55
Manages the interprocess communication channels and wraps send and receive calls.
void test_receive(X2X expected_ping_value, test_rcv_pipes rcv_pipe, std::size_t worker_id)
Channel & select_worker_channel_on_master()
On master: pick the worker channel to receive the next message from.
void test_connections(const ProcessManager &process_manager)
Test whether the channels between all processes are working.
value_t receive_from_master_on_worker(bool *more=nullptr)
Definition Messenger.h:175
void send_from_worker_to_master(T &&item)
specialization that sends the final part of a message
Definition Messenger.h:190
value_t receive_from_worker_on_master(bool *more=nullptr)
Definition Messenger.h:216
std::pair< Poller, std::size_t > create_worker_poller()
Helper function that creates a poller for worker_loop()
Messenger(ProcessManager &process_manager)
Definition Messenger.cxx:48
std::pair< Poller, std::size_t > create_queue_poller()
Helper function that creates a poller for Queue::loop()
void update_worker_channel_on_master(Channel &channel, bool more)
void debug_print(std::string s)
Function called from send and receive template functions in debug builds used to monitor the messages...
value_t receive_from_worker_on_queue(std::size_t this_worker_id)
Definition Messenger.h:45
void publish_from_master_to_workers(T &&item)
specialization that sends the final part of a message
Definition Messenger.h:145
void send_from_queue_to_worker(std::size_t this_worker_id)
void test_send(X2X ping_value, test_snd_pipes snd_pipe, std::size_t worker_id)
Definition Messenger.cxx:79
Waits for input on a set of registered Channels.
Definition Poller.h:34
Fork processes for queue and workers.
std::ostream & operator<<(std::ostream &out, const Message &msg)
Definition Message.h:72
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73