MyraMath
AssemblyTree.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_MULTIFRONTAL_SYMBOLIC_ASSEMBLYTREE_H
7 #define MYRAMATH_MULTIFRONTAL_SYMBOLIC_ASSEMBLYTREE_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
17 
19 
21 
22 // Required std::libraries.
23 #include <vector>
24 #include <iosfwd>
25 #include <stdint.h>
26 
27 namespace myra {
28 
29 // Forward declarations.
30 class intCRange;
31 class Match;
32 class PatternRange;
33 class InputStream;
34 class OutputStream;
35 class SchurTree;
36 
38 class MYRAMATH_EXPORT AssemblyTree
39  {
40  public:
41 
43  typedef std::pair<const int*,const int*> Range;
45 
46  // Inner class detail, single Node of the AssemblyTree
47  class MYRAMATH_EXPORT Node
48  {
49  public:
50 
51  // Unique identifier for this node.
52  int id;
53 
54  // Number of pivots (p) and nonpivots (q)
55  int p;
56  int q;
57  std::vector<int> pattern;
58 
59  // Number of pivot blocks (P) and nonpivot blocks (Q)
60  int P;
61  int Q;
62  std::vector<int> blocking;
63 
64  // Striding vector, cumsum(blocking)
65  std::vector<int> striding;
66 
67  // Parent/child links.
68  Node* parent;
69  std::vector<Node*> children;
70 
71  // Default constructor, empty Node
72  Node();
73 
74  // InputStream constructor.
75  Node(InputStream& in);
76 
77  // Writes to OutputStream.
78  void write(OutputStream& out);
79 
80  // Returns id of parent (or -1 if *this is a root)
81  int parent_id() const;
82 
83  // Returns id's of all children.
84  std::vector<int> children_ids() const;
85 
86  // Inspection routine, prints debugging information on out.
87  void inspect(std::ostream& out) const;
88 
89  // ------------------------------------ Pattern interrogation.
90 
91  // Returns pattern of pivots.
92  Range p_pattern() const
93  { return Range(pattern.data(), pattern.data()+p); }
94 
95  // Returns pattern of nonpivots.
96  Range q_pattern() const
97  { return Range(pattern.data()+p, pattern.data()+p+q); }
98 
99  // Returns blocking of pivots.
100  Range p_blocking() const
101  { return Range(blocking.data(), blocking.data()+P); }
102 
103  // Returns blocking of nonpivots.
104  Range q_blocking() const
105  { return Range(blocking.data()+P, blocking.data()+P+Q); }
106 
107  // Returns pattern of block b, for b in [0,P+Q]
108  Range block_pattern(int b) const
109  { return Range(pattern.data()+striding[b], pattern.data()+striding[b+1]); }
110 
111  // ------------------------------------ Space/time queries.
112 
113  // Returns (permanent,temporary) storage requirements.
114  std::pair<uint64_t,uint64_t> n_words() const;
115 
116  // Returns work estimate to process this node.
117  uint64_t n_work_llt() const;
118  uint64_t n_work_lu() const;
119 
120  // ------------------------------------ Dependency tracking
121 
122  // Given a contribution block b in [P,P+Q], returns the set of (parent,block)'s that it pushes contributions into.
123  Range block_up(int b) const;
124 
125  // Given a block b, returns the set of children[c] blocks it pulls contributions from.
126  Range block_down(int b, int c) const;
127 
128  private:
129 
130  // Caches the child to parent relationships, exposed by block_up()
131  std::vector<int> up_data;
132  Array1<int> up_begin;
133  Array1<int> up_end;
134 
135  // Caches the parent to child relationships, exposed by block_down()
136  std::vector<int> down_data;
137  Array2<int> down_begin;
138  Array2<int> down_end;
139 
140  // Populates the caches above.
141  void finalize(int blocksize);
142 
143  // Given a contribution block b in [P,P+Q], returns the set of (parent,block)'s that it pushes contributions into.
144  // Implementation detail of finalize()
145  std::vector<int> block_up_finalize(int b, int blocksize) const;
146 
147  // Given a block b, returns the set of children[c] blocks it pulls contributions from.
148  // Implementation detail of finalize()
149  std::vector<int> block_down_finalize(int b, int c, int blocksize) const;
150 
151  // Given a sorted range of indices, finds the match for each one in this->pattern. (or -1, if !found)
152  // Implementation detail of block_up_finalize() and block_down_finalize()
153  std::vector<int> map(Range range) const;
154 
155  friend class AssemblyTree;
156 
157  }; // class Node
158 
160  AssemblyTree();
161 
163  AssemblyTree(const PatternRange& A, const Permutation& P, Options options = Options::create());
164 
166  AssemblyTree(const PatternRange& A, const Match& M, const Permutation& P, Options options = Options::create());
167 
169  AssemblyTree(const AssemblyTree& that);
170 
173 
175  void write(OutputStream& out) const;
176 
178  void swap(AssemblyTree& that);
179 
180 #ifdef MYRAMATH_ENABLE_CPP11
181  AssemblyTree(AssemblyTree&& that);
183 #endif
184 
186  AssemblyTree& operator = (AssemblyTree that);
187 
189  int size() const;
190 
192  int n_nodes() const;
193 
195  const Node& node(int n) const;
196  const Node& at(int n) const;
197 
199  int unknown2node(int i) const;
200 
202  std::vector<int> roots() const;
203 
205  std::vector<int> leaves() const;
206 
208  // High water mark should be approximately the sum of .first + .second
209  std::pair<uint64_t,uint64_t> n_words() const;
210 
212  uint64_t n_work_llt() const;
213 
215  uint64_t n_work_lu() const;
216 
218  const Permutation& permutation() const;
219  intCRange perm() const;
220  intCRange iperm() const;
221  intCRange swaps() const;
222  int perm(int i) const;
223  int iperm(int i) const;
224  int swaps(int i) const;
225 
227  void inspect(std::ostream& out) const;
228 
230  ~AssemblyTree();
231 
232  private:
233 
234  // Implementation detail of constructor, performs symbolic analysis.
235  void constructor_detail(const PatternRange& A, const Match& match, const Permutation& perm, Options options);
236 
237  // Internal contents.
238  std::vector<Node*> nodes;
239 
240  // Size of underlying system.
241  int IJ;
242 
243  // Internal permutation stage.
244  Permutation P;
245 
246  // Maps pivot unknowns to AssemblyTree::Node's that eliminate them.
247  std::vector<int> pivot2node;
248 
249  // Blocksize, required for SchurTree constructor.
250  int blocksize;
251  friend class SchurTree;
252 
253  };
254 
256 std::ostream& operator<< (std::ostream& out, const AssemblyTree& atree);
257 
258 } // namespace myra
259 
260 #endif
Options pack for routines in /multifrontal.
Definition: Options.h:24
Represents a Permutation matrix, used to reorder rows/columns/etc of various numeric containers...
Definition: Permutation.h:34
Symbolic analysis data structure for all multifrontal solvers.
Definition: AssemblyTree.h:38
Container of values, allows random (i) access.
Container of values, allows random (i,j) access.
std::pair< const int *, const int * > Range
Useful typedefs.
Definition: AssemblyTree.h:43
Symbolic analysis data structure for multifrontal schur complement.
Definition: SchurTree.h:42
Definition: syntax.dox:1
Represents an immutable view of a Pattern.
Definition: PatternRange.h:31
Abstraction layer, serializable objects write themselves to these.
Definition: Streams.h:39
Abstraction layer, deserializable objects read themselves from these.
Definition: Streams.h:47
Options pack for routines in /multifrontal.
Aggregates a (perm, iperm, swaps) triple into a vocabulary type.
Definition: AssemblyTree.h:47
Represents a const intRange.
Definition: intRange.h:142