Zoltan2  Version of the Day
Zoltan2_Model.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_MODEL_HPP_
51 #define _ZOLTAN2_MODEL_HPP_
52 
53 #include <Zoltan2_Standards.hpp>
55 #include <bitset>
56 
57 namespace Zoltan2 {
58 
61 enum ModelType {
67 } ;
68 
73  // General flags
76  // Graph model flags
88 };
89 
90 typedef std::bitset<NUM_MODEL_FLAGS> modelFlag_t;
91 
106 template <typename Adapter>
107 class Model
108 {
109 public:
110 
111 #ifndef DOXYGEN_SHOULD_SKIP_THIS
112  typedef typename Adapter::lno_t lno_t;
113  typedef typename Adapter::gno_t gno_t;
114  typedef typename Adapter::gid_t gid_t;
115  typedef typename Adapter::scalar_t scalar_t;
116  typedef typename Adapter::user_t user_t;
117  typedef IdentifierMap<user_t> idmap_t;
118 #endif
119 
122  virtual ~Model() {};
123 
126  Model() : idMap_(), weightDim_(0), uniform_() {}
127 
135  RCP<const idmap_t > getIdentifierMap() const { return idMap_; }
136 
144  int getNumWeights() const { return weightDim_;}
145 
151  bool uniformWeight(int weightDim) const { return uniform_[weightDim];}
152 
159  virtual size_t getLocalNumObjects() const = 0;
160 
167  virtual global_size_t getGlobalNumObjects() const = 0;
168 
175  virtual void getGlobalObjectIds(ArrayView<const gno_t> &gnos) const = 0;
176 
177 protected:
178 
184  void setIdentifierMap(RCP<const idmap_t> &map) { idMap_ = map; }
185 
193  void setWeightArrayLengths(const Array<lno_t> &len,
194  const Teuchos::Comm<int> &comm)
195  {
196  weightDim_ = len.size();
197 
198  if (weightDim_ < 1)
199  weightDim_ = 1; // uniform weights are implied
200 
201  int *lval = new int [weightDim_];
202  uniform_ = arcp(lval, 0, weightDim_);
203 
204  if (len.size() < 1){
205  uniform_[0] = 1;
206  return;
207  }
208 
209  for (int i=0; i < weightDim_; i++){
210  if (len[i] > 0)
211  lval[i] = 1;
212  else
213  lval[i] = 0;
214  }
215 
216  int *rval = new int [weightDim_];
217 
218  try{
219  reduceAll<int, int>(comm, Teuchos::REDUCE_MAX, weightDim_, lval, rval);
220  }
222 
223  for (int i=0; i < weightDim_; i++){
224  if (rval[i] > 0)
225  uniform_[i] = 0;
226  else
227  uniform_[i] = 1;
228  }
229 
230  delete [] rval;
231  }
232 
240  template <typename T>
241  static void maxCount(const Comm<int> &comm, Array<T> &countValues)
242  {
243  size_t len = countValues.size();
244  if (comm.getSize() < 2 || len < 1)
245  return;
246  Array<T> globalValues(len);
247  Teuchos::reduceAll<int, T>(comm, Teuchos::REDUCE_MAX, len,
248  countValues.getRawPtr(), globalValues.getRawPtr());
249 
250  countValues = globalValues;
251  }
252 
260  template <typename T>
261  static void maxCount(const Comm<int> &comm, T &value1)
262  {
263  Array<T> values(1, value1);
264  maxCount<T>(comm, values);
265  value1 = values[0];
266  }
267 
275  template <typename T>
276  static void maxCount(const Comm<int> &comm, T &value1, T &value2)
277  {
278  Array<T> values(2);
279  values[0] = value1;
280  values[1] = value2;
281  maxCount<T>(comm, values);
282  value1 = values[0];
283  value2 = values[1];
284  }
285 
286 private:
287 
288  RCP<const idmap_t> idMap_;
289 
290  int weightDim_;
291  ArrayRCP<int> uniform_;
292 };
293 
294 } // namespace Zoltan2
295 
296 #endif
use columns as graph vertices
An IdentifierMap manages a global space of object identifiers.
ModelFlags
Flags are set by a Problem to tell a Model what transformations it may need to do on the user&#39;s input...
Defines the IdentifierMap class.
use mesh nodes as vertices
ModelType
An identifier for the general type of model.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
size_t global_size_t
static void maxCount(const Comm< int > &comm, Array< T > &countValues)
Get the global maximum for each of an array of values.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
algorithm requires consecutive ids
model must symmetrize input
static void maxCount(const Comm< int > &comm, T &value1, T &value2)
Get the global maximums for each of two values.
model must symmetrize input
int getNumWeights() const
Return the number of weights supplied for each object. If the user supplied no weights, dimension one is returned, because one dimension of uniform weights is implied.
Zoltan2::BasicUserTypes< scalar_t, gno_t, lno_t, gno_t > user_t
use matrix rows as graph vertices
use nonzeros as graph vertices
virtual void getGlobalObjectIds(ArrayView< const gno_t > &gnos) const =0
Get a list of the global Ids for the local objects.
static void maxCount(const Comm< int > &comm, T &value1)
Get the global maximum for a value.
double scalar_t
use mesh elements as vertices
bool uniformWeight(int weightDim) const
Return whether the weights are uniform or not.
virtual global_size_t getGlobalNumObjects() const =0
Return the global number of objects.
Gathering definitions used in software development.
virtual size_t getLocalNumObjects() const =0
Return the local number of objects.
The base class for all model classes.
algorithm requires no self edges
RCP< const idmap_t > getIdentifierMap() const
Return the map from user global identifiers to internal Zoltan2 global numbers.
void setWeightArrayLengths(const Array< lno_t > &len, const Teuchos::Comm< int > &comm)
Set the length of each weight array. The Model calls this in the constructor so we know which weights...
ignore invalid neighbors
void setIdentifierMap(RCP< const idmap_t > &map)
Set the IdentifierMap used by the model.