Zoltan2
Zoltan2_OrderingSolution.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef _ZOLTAN2_ORDERINGSOLUTION_HPP_
51 #define _ZOLTAN2_ORDERINGSOLUTION_HPP_
52 
53 #include <Zoltan2_Standards.hpp>
54 #include <Zoltan2_Solution.hpp>
55 
56 namespace Zoltan2 {
57 
70 template <typename lno_t, typename gno_t>
71  class OrderingSolution : public Solution
72 {
73 public:
74 
78  size_t perm_size // This should be equal to nlids
79  ) : separatorColBlocks_(0)
80  {
81  HELLO;
82  perm_size_ = perm_size;
83  //gids_ = ArrayRCP<gno_t>(perm_size_);
84  perm_ = ArrayRCP<lno_t>(perm_size_);
85  invperm_ = ArrayRCP<lno_t>(perm_size_);
86  separatorRange_ = ArrayRCP<lno_t>(perm_size_+1);
87  separatorTree_ = ArrayRCP<lno_t>(perm_size_);
88 
89  havePerm_ = false;
90  haveInverse_ = false;
91  haveSeparatorRange_ = false;
92  haveSeparatorTree_ = false;
93  }
94 
97  bool havePerm() const
98  {
99  return havePerm_;
100  }
101 
104  void setHavePerm(bool status)
105  {
106  havePerm_ = status;
107  }
108 
109 
112  bool haveInverse() const
113  {
114  return haveInverse_;
115  }
116 
119  void setHaveInverse(bool status)
120  {
121  haveInverse_ = status;
122  }
123 
126  void setHaveSeparator(bool status) {
127  this->setHavePerm(status);
128  this->setHaveInverse(status);
129  this->setHaveSeparatorRange(status);
130  this->setHaveSeparatorTree(status);
131  }
134  bool haveSeparatorRange() const
135  {
136  return haveSeparatorRange_;
137  }
138 
141  void setHaveSeparatorRange(bool status)
142  {
143  haveSeparatorRange_ = status;
144  }
145 
148  bool haveSeparatorTree() const
149  {
150  return haveSeparatorTree_;
151  }
152 
155  bool haveSeparators() const
156  {
157  return haveSeparatorRange() && haveSeparatorTree();
158  }
159 
162  void setHaveSeparatorTree(bool status)
163  {
164  haveSeparatorTree_ = status;
165  }
166 
169  void computePerm()
170  {
171  if (haveInverse_) {
172  for(size_t i=0; i<perm_size_; i++) {
173  perm_[invperm_[i]] = i;
174  }
175  havePerm_ = true;
176  }
177  else {
178  // TODO: throw exception
179  std::cerr << "No inverse!" << std::endl;
180  }
181  }
182 
186  {
187  if (havePerm_) {
188  for(size_t i=0; i<perm_size_; i++) {
189  invperm_[perm_[i]] = i;
190  }
191  havePerm_ = true;
192  }
193  else {
194  // TODO: throw exception
195  std::cerr << "No perm!" << std::endl;
196  }
197  }
198 
201  inline void setNumSeparatorBlocks(lno_t nblks) {separatorColBlocks_ = nblks;}
202 
204  // Accessor functions, allowing algorithms to get ptrs to solution memory.
205  // Algorithms can then load the memory.
206  // Non-RCP versions are provided for applications to use.
207 
210  inline size_t getPermutationSize() const {return perm_size_;}
211 
214  inline lno_t getNumSeparatorBlocks() const {return separatorColBlocks_;}
215 
218  // inline ArrayRCP<lno_t> &getGidsRCP() {return gids_;}
219 
225  inline const ArrayRCP<lno_t> &getPermutationRCP(bool inverse=false) const
226  {
227  if (inverse)
228  return invperm_;
229  else
230  return perm_;
231  }
232 
235  bool getVertexSeparator (lno_t &numBlocks,
236  lno_t *range,
237  lno_t *tree) const {
238 
239  if (this->haveSeparators()) {
240  numBlocks = this->getNumSeparatorBlocks();
241  range = this->getSeparatorRangeView();
242  tree = this->getSeparatorTreeView();
243  return true;
244  }
245 
246  return false;
247  }
248 
251  inline const ArrayRCP<lno_t> &getSeparatorRangeRCP() const
252  {
253  return separatorRange_;
254  }
255 
258  inline const ArrayRCP<lno_t> &getSeparatorTreeRCP() const
259  {
260  return separatorTree_;
261  }
262 
265  // inline ArrayRCP<lno_t> &getGidsRCPConst() const
266  // {
267  // return const_cast<ArrayRCP<lno_t>& > (gids_);
268  // }
269 
275  inline ArrayRCP<lno_t> &getPermutationRCPConst(bool inverse=false) const
276  {
277  if (inverse)
278  return const_cast<ArrayRCP<lno_t>& > (invperm_);
279  else
280  return const_cast<ArrayRCP<lno_t>& > (perm_);
281  }
282 
285  inline ArrayRCP<lno_t> &getSeparatorRangeRCPConst() const
286  {
287  return const_cast<ArrayRCP<lno_t> & > (separatorRange_);
288  }
289 
292  inline ArrayRCP<lno_t> &getSeparatorTreeRCPConst() const
293  {
294  return const_cast<ArrayRCP<lno_t> & > (separatorTree_);
295  }
296 
303  inline lno_t *getPermutationView(bool inverse = false) const
304  {
305  if (perm_size_) {
306  if (inverse)
307  return invperm_.getRawPtr();
308  else
309  return perm_.getRawPtr();
310  }
311  else
312  return NULL;
313  }
314 
317  inline lno_t *getSeparatorRangeView() const
318  {
319  // Here, don't need to check perm_size_ before calling getRawPtr.
320  // separatorRange_ always has some length, since it is allocated larger
321  // than other arrays.
322  return separatorRange_.getRawPtr();
323  }
324 
327  inline lno_t *getSeparatorTreeView() const
328  {
329  if (perm_size_)
330  return separatorTree_.getRawPtr();
331  else
332  return NULL;
333  }
334 
337  inline lno_t &NumSeparatorBlocks()
338  {
339  return separatorColBlocks_;
340  }
341 
342 protected:
343  // Ordering solution consists of permutation vector(s).
344  // Either perm or invperm should be computed by the algorithm.
345  size_t perm_size_;
346  // For now, assume permutations are local. Revisit later (e.g., for Scotch)
347  bool havePerm_; // has perm_ been computed yet?
348  bool haveInverse_; // has invperm_ been computed yet?
349  bool haveSeparatorRange_; // has sepRange_ been computed yet?
350  bool haveSeparatorTree_; // has sepTree_ been computed yet?
351  ArrayRCP<lno_t> perm_; // zero-based local permutation
352  ArrayRCP<lno_t> invperm_; // inverse of permutation above
353  ArrayRCP<lno_t> separatorRange_; // range iterator for separator tree
354  ArrayRCP<lno_t> separatorTree_; // separator tree
355  lno_t separatorColBlocks_; // number of column blocks in separator
356 };
357 
358 }
359 
360 #endif
lno_t * getPermutationView(bool inverse=false) const
Get pointer to (local) permutation. If inverse = true, return inverse permutation. By default, perm[i] is where new index i can be found in the old ordering. When inverse==true, perm[i] is where old index i can be found in the new ordering.
#define HELLO
size_t getPermutationSize() const
Get (local) size of permutation.
ArrayRCP< lno_t > & getPermutationRCPConst(bool inverse=false) const
Get (local) permuted GIDs by const RCP.
lno_t getNumSeparatorBlocks() const
Get number of separator column blocks.
Defines the Solution base class.
lno_t * getSeparatorTreeView() const
Get pointer to (local) separator tree.
const ArrayRCP< lno_t > & getSeparatorRangeRCP() const
Get (local) seperator range by RCP.
bool haveSeparatorTree() const
Do we have the seperator tree?
void setHavePerm(bool status)
Set havePerm (intended for ordering algorithms only)
const ArrayRCP< lno_t > & getSeparatorTreeRCP() const
Get (local) seperator tree by RCP.
Just a placeholder for now.
void computeInverse()
Compute inverse permutation.
void setNumSeparatorBlocks(lno_t nblks)
Set number of separator column blocks.
lno_t & NumSeparatorBlocks()
Get reference to (local) separator column block.
bool havePerm() const
Do we have the direct permutation?
OrderingSolution(size_t perm_size)
Constructor allocates memory for the solution.
tree
Begin.
Definition: xml2dox.py:166
bool getVertexSeparator(lno_t &numBlocks, lno_t *range, lno_t *tree) const
return vertex separator variables by reference.
lno_t * getSeparatorRangeView() const
Get pointer to (local) separator range.
void computePerm()
Compute direct permutation from inverse.
ArrayRCP< lno_t > & getSeparatorRangeRCPConst() const
Get (local) seperator range by const RCP.
ArrayRCP< lno_t > & getSeparatorTreeRCPConst() const
Get (local) seperator tree by const RCP.
void setHaveSeparatorRange(bool status)
Set haveSeparatorRange (intended for ordering algorithms only)
bool haveSeparatorRange() const
Do we have the seperator range?
bool haveSeparators() const
Do we have the seperators?
void setHaveSeparator(bool status)
set all separator flags.
Gathering definitions used in software development.
void setHaveInverse(bool status)
Set haveInverse (intended for ordering algorithms only)
bool haveInverse() const
Do we have the inverse permutation?
The class containing ordering solutions.
const ArrayRCP< lno_t > & getPermutationRCP(bool inverse=false) const
Get (local) permuted GIDs by RCP.
void setHaveSeparatorTree(bool status)
Set haveSeparatorTree (intended for ordering algorithms only)