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  )
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  havePerm_ = false;
87  haveInverse_ = false;
88  }
89 
92  bool havePerm()
93  {
94  return havePerm_;
95  }
96 
99  void setHavePerm(bool status)
100  {
101  havePerm_ = status;
102  }
103 
104 
107  bool haveInverse()
108  {
109  return haveInverse_;
110  }
111 
114  void setHaveInverse(bool status)
115  {
116  haveInverse_ = status;
117  }
118 
121  void computePerm()
122  {
123  if (haveInverse_) {
124  for(size_t i=0; i<perm_size_; i++) {
125  perm_[invperm_[i]] = i;
126  }
127  havePerm_ = true;
128  }
129  else {
130  // TODO: throw exception
131  std::cerr << "No inverse!" << std::endl;
132  }
133  }
134 
138  {
139  if (havePerm_) {
140  for(size_t i=0; i<perm_size_; i++) {
141  invperm_[perm_[i]] = i;
142  }
143  havePerm_ = true;
144  }
145  else {
146  // TODO: throw exception
147  std::cerr << "No perm!" << std::endl;
148  }
149  }
150 
151 
153  // Accessor functions, allowing algorithms to get ptrs to solution memory.
154  // Algorithms can then load the memory.
155  // Non-RCP versions are provided for applications to use.
156 
159  inline size_t getPermutationSize() {return perm_size_;}
160 
163  inline ArrayRCP<gno_t> &getGidsRCP() {return gids_;}
164 
170  inline ArrayRCP<lno_t> &getPermutationRCP(bool inverse=false)
171  {
172  if (inverse)
173  return invperm_;
174  else
175  return perm_;
176  }
177 
180  inline ArrayRCP<gno_t> &getGidsRCPConst() const
181  {
182  return const_cast<ArrayRCP<gno_t>& > (gids_);
183  }
184 
190  inline ArrayRCP<lno_t> &getPermutationRCPConst(bool inverse=false) const
191  {
192  if (inverse)
193  return const_cast<ArrayRCP<lno_t>& > (invperm_);
194  else
195  return const_cast<ArrayRCP<lno_t>& > (perm_);
196  }
197 
200  inline gno_t *getGids()
201  {
202  return gids_.getRawPtr();
203  }
204 
210  inline lno_t *getPermutation(bool inverse = false)
211  {
212  if (inverse)
213  return invperm_.getRawPtr();
214  else
215  return perm_.getRawPtr();
216  }
217 
218 protected:
219  // Ordering solution consists of permutation vector(s).
220  // Either perm or invperm should be computed by the algorithm.
221  size_t perm_size_;
222  ArrayRCP<gno_t> gids_; // TODO: Remove?
223  // For now, assume permutations are local. Revisit later (e.g., for Scotch)
224  bool havePerm_; // has perm_ been computed yet?
225  bool haveInverse_; // has invperm_ been computed yet?
226  ArrayRCP<lno_t> perm_; // zero-based local permutation
227  ArrayRCP<lno_t> invperm_; // inverse of permutation above
228 };
229 
230 }
231 
232 #endif
#define HELLO
Defines the Solution base class.
size_t getPermutationSize()
Get (local) size of permutation.
void setHavePerm(bool status)
Set havePerm (intended for ordering algorithms only)
Just a placeholder for now.
void computeInverse()
Compute inverse permutation.
bool havePerm()
Do we have the direct permutation?
OrderingSolution(size_t perm_size)
Constructor allocates memory for the solution.
ArrayRCP< gno_t > & getGidsRCP()
Get (local) permuted GIDs by RCP.
ArrayRCP< lno_t > & getPermutationRCPConst(bool inverse=false) const
Get (local) permutation by const RCP. 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.
ArrayRCP< lno_t > & getPermutationRCP(bool inverse=false)
Get (local) permutation by RCP. If inverse = true, return inverse permutation. By default...
ArrayRCP< gno_t > & getGidsRCPConst() const
Get (local) permuted GIDs by const RCP.
bool haveInverse()
Do we have the inverse permutation?
void computePerm()
Compute direct permutation from inverse.
gno_t * getGids()
Get pointer to (local) GIDs.
lno_t * getPermutation(bool inverse=false)
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.
Gathering definitions used in software development.
void setHaveInverse(bool status)
Set haveInverse (intended for ordering algorithms only)
The class containing ordering solutions.