TPIE

2362a60
runtime.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet cino+=(0 :
3 // Copyright 2013, 2014, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef TPIE_PIPELINING_RUNTIME_H
21 #define TPIE_PIPELINING_RUNTIME_H
22 
24 #include <tpie/pipelining/tokens.h>
25 #include <tpie/pipelining/node.h>
26 #include <set>
27 #include <unordered_set>
28 
29 namespace tpie {
30 
31 namespace pipelining {
32 
33 namespace bits {
34 
35 template <typename T>
36 class graph;
37 class file_runtime;
38 class memory_runtime;
39 class datastructure_runtime;
40 
41 struct gocontext;
42 struct gocontextdel {
43  void operator()(void *);
44 };
45 typedef std::unique_ptr<gocontext, gocontextdel> gocontext_ptr;
46 
47 
51 class runtime {
52  node_map & m_nodeMap;
53 
54 public:
60  runtime(node_map::ptr nodeMap);
61 
67  size_t get_node_count();
68 
69  gocontext_ptr go_init(stream_size_type items,
70  progress_indicator_base & progress,
71  memory_size_type files,
72  memory_size_type memory,
73  const char * file, const char * function);
74 
75  void go_until(gocontext * gc, node * node=nullptr);
76 
92  void go(stream_size_type items,
93  progress_indicator_base & progress,
94  memory_size_type files,
95  memory_size_type memory,
96  const char * file, const char * function);
97 
107  void get_item_sources(std::vector<node *> & itemSources);
108 
118  void get_item_sinks(std::vector<node *> & itemSinks);
119 
123  void get_phase_map(std::map<node *, size_t> & phaseMap);
124 
128  void get_phase_graph(const std::map<node *, size_t> & phaseMap,
129  graph<size_t> & phaseGraph);
130 
139  static std::vector<size_t> inverse_permutation(const std::vector<size_t> & f);
140 
148  void get_phases(const std::map<node *, size_t> & phaseMap,
149  const graph<size_t> & phaseGraph,
150  std::unordered_set<node_map::id_t> & evacuateWhenDone,
151  std::vector<std::vector<node *> > & phases);
152 
156  void get_item_flow_graphs(std::vector<std::vector<node *> > & phases,
157  std::vector<graph<node *> > & itemFlow);
158 
162  void get_actor_graphs(std::vector<std::vector<node *> > & phases,
163  std::vector<graph<node *> > & actors);
164 
168  void get_graph(std::vector<node *> & phase, graph<node *> & result,
169  bool itemFlow);
170 
177  bool is_initiator(node * n);
178 
182  bool has_initiator(const std::vector<node *> & phase);
183 
189  void ensure_initiators(const std::vector<std::vector<node *> > & phases);
190 
194  void prepare_all(const std::vector<graph<node *> > & itemFlow);
195 
200  void evacuate_all(const std::vector<node *> & phase,
201  const std::unordered_set<node_map::id_t> & evacuateWhenDone);
202 
206  void propagate_all(const graph<node *> & itemFlow);
207 
211  void set_progress_indicators(const std::vector<node *> & phase,
213 
218  void go_initiators(const std::vector<node *> & phase);
219 
223  static void set_resource_being_assigned(const std::vector<node *> & nodes,
224  resource_type type);
225 
229  static void assign_files(const std::vector<std::vector<node *> > & phases,
230  memory_size_type files);
231 
235  static void reassign_files(const std::vector<std::vector<node *> > & phases,
236  memory_size_type phase,
237  memory_size_type files);
238 
242  static double get_files_factor(memory_size_type files,
243  const file_runtime & frt);
244 
248  static void assign_memory(const std::vector<std::vector<node *> > & phases,
249  memory_size_type memory, datastructure_runtime & drt);
250 
254  static void reassign_memory(const std::vector<std::vector<node *> > & phases,
255  memory_size_type phase,
256  memory_size_type memory, const datastructure_runtime & drt);
257 
261  static double get_memory_factor(memory_size_type memory,
262  memory_size_type phase,
263  const memory_runtime & mrt,
264  const datastructure_runtime & drt,
265  bool datastructures_locked);
266 };
267 
268 }
269 
270 }
271 
272 }
273 
274 #endif // TPIE_PIPELINING_RUNTIME_H
void get_phase_map(std::map< node *, size_t > &phaseMap)
Partition nodes into phases (using union-find).
The base class for indicating the progress of some task.
void propagate_all(const graph< node * > &itemFlow)
Call propagate on all nodes in item source to sink order.
runtime(node_map::ptr nodeMap)
Construct a runtime object.
static void reassign_memory(const std::vector< std::vector< node * > > &phases, memory_size_type phase, memory_size_type memory, const datastructure_runtime &drt)
Internal method used by go().
void get_item_flow_graphs(std::vector< std::vector< node * > > &phases, std::vector< graph< node * > > &itemFlow)
Internal method used by go().
Central file abstraction.
Definition: file.h:44
void get_phase_graph(const std::map< node *, size_t > &phaseMap, graph< size_t > &phaseGraph)
Set up phase graph so we can find a topological order.
void go_initiators(const std::vector< node * > &phase)
Call go() on all initiators after setting the given progress indicator.
void get_phases(const std::map< node *, size_t > &phaseMap, const graph< size_t > &phaseGraph, std::unordered_set< node_map::id_t > &evacuateWhenDone, std::vector< std::vector< node * > > &phases)
Compute topological phase order.
static void set_resource_being_assigned(const std::vector< node * > &nodes, resource_type type)
Internal method used by go().
Base class of all nodes.
Definition: node.h:78
void prepare_all(const std::vector< graph< node * > > &itemFlow)
Call prepare on all nodes in item source to sink order.
static void reassign_files(const std::vector< std::vector< node * > > &phases, memory_size_type phase, memory_size_type files)
Internal method used by go().
void set_progress_indicators(const std::vector< node * > &phase, progress_indicator_base &pi)
Call set_progress_indicator on all nodes in the phase.
void get_actor_graphs(std::vector< std::vector< node * > > &phases, std::vector< graph< node * > > &actors)
Internal method used by go().
static void assign_files(const std::vector< std::vector< node * > > &phases, memory_size_type files)
Internal method used by go().
void get_item_sources(std::vector< node * > &itemSources)
Get all sources of the item flow graph.
Pipeline tokens.
size_t get_node_count()
Number of nodes contained in node map.
Fractional progress reporting.
void ensure_initiators(const std::vector< std::vector< node * > > &phases)
Ensure that all phases have at least one initiator.
static std::vector< size_t > inverse_permutation(const std::vector< size_t > &f)
Compute the inverse of a permutation.
void go(stream_size_type items, progress_indicator_base &progress, memory_size_type files, memory_size_type memory, const char *file, const char *function)
Execute the pipeline.
Execute the pipeline contained in a node_map.
Definition: runtime.h:51
static double get_files_factor(memory_size_type files, const file_runtime &frt)
Internal method used by assign_memory().
static void assign_memory(const std::vector< std::vector< node * > > &phases, memory_size_type memory, datastructure_runtime &drt)
Internal method used by go().
bool is_initiator(node *n)
Check if the node is a phase initiator.
void get_item_sinks(std::vector< node * > &itemSinks)
Get all sinks of the item flow graph.
static double get_memory_factor(memory_size_type memory, memory_size_type phase, const memory_runtime &mrt, const datastructure_runtime &drt, bool datastructures_locked)
Internal method used by assign_memory().
void evacuate_all(const std::vector< node * > &phase, const std::unordered_set< node_map::id_t > &evacuateWhenDone)
Call evacuate on all nodes in evacuateWhenDone for which can_evacuate() is true.
bool has_initiator(const std::vector< node * > &phase)
Equivalent to any_of(begin(phase), end(phase), is_initiator).
void get_graph(std::vector< node * > &phase, graph< node * > &result, bool itemFlow)
Internal method used by get_{actor,item_flow}_graphs().