TPIE

v1.1rc1-6-g0c97303
graph.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2012, 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 
23 
24 #ifndef __TPIE_PIPELINING_GRAPH_H__
25 #define __TPIE_PIPELINING_GRAPH_H__
26 
27 #include <tpie/disjoint_sets.h>
28 #include <tpie/dummy_progress.h>
29 #include <tpie/tpie_assert.h>
30 #include <vector>
31 #include <stack>
33 
34 namespace tpie {
35 
36 namespace pipelining {
37 
38 namespace bits {
39 
45 class phase {
46 public:
47  class node_graph;
48 
49  phase();
50  phase(const phase &);
51  phase & operator=(const phase &);
52  ~phase();
53 
54  bool is_initiator(node * s);
55 
56  void add(node * s);
57 
58  void add_successor(node * from, node * to, bool push);
59 
60  inline size_t count(node * s) {
61  for (size_t i = 0; i < m_nodes.size(); ++i) {
62  if (m_nodes[i] == s) return 1;
63  }
64  return 0;
65  }
66 
67  void go(progress_indicator_base & pi);
68 
69  void evacuate_all() const;
70 
71  void assign_memory(memory_size_type m) const;
72 
73  void print_memory(std::ostream & os) const;
74 
75  const std::string & get_name() const;
76 
77  std::string get_unique_id() const;
78 
79 private:
82  std::auto_ptr<node_graph> itemFlowGraph;
83 
86  std::auto_ptr<node_graph> actorGraph;
87 
89  std::vector<node *> m_nodes;
90 
91  void assign_minimum_memory() const;
92 
102  memory_size_type sum_assigned_memory(double factor) const;
103 };
104 
112 public:
113  typedef std::vector<phase> phases_t;
114  typedef phases_t::iterator phaseit;
115  typedef std::vector<node *> nodes_t;
116  typedef nodes_t::iterator nodeit;
118 
119  static memory_size_type memory_usage(size_t phases);
120 
121  graph_traits(const node_map & map);
122 
123  const phases_t & phases() {
124  return m_phases;
125  }
126 
127  const nodes_t & item_sources() {
128  return m_itemSources;
129  }
130 
131  const nodes_t & item_sinks() {
132  return m_itemSinks;
133  }
134 
135  void go_all(stream_size_type n, Progress::base & pi);
136 
137 private:
138  const node_map & map;
139  phases_t m_phases;
140  std::vector<bool> m_evacuatePrevious;
141  nodes_t m_itemSources;
142  nodes_t m_itemSinks;
143 
144  void calc_phases();
145 
146 };
147 
148 } // namespace bits
149 
150 } // namespace pipelining
151 
152 } // namespace tpie
153 
154 #endif // __TPIE_PIPELINING_GRAPH_H__
Defines the tp_assert macro.
The base class for indicating the progress of some task.
Compute phases and execute pipelining program.
Definition: graph.h:111
Base class of all nodes.
Definition: node.h:58
Management of a single pipelining phase.
Definition: graph.h:45
Generic internal disjoint_sets (union find) implementation.
Predeclarations of some pipelining classes.
For applications where you wish to disable progress indicators via a template parameter, refer to progress_types members names sub, fp and base.
Progress indicator concept in an efficient non-inheritance way.