Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_BasicIdentifierAdapter.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #ifndef _ZOLTAN2_BASICIDENTIFIERADAPTER_HPP_
15 #define _ZOLTAN2_BASICIDENTIFIERADAPTER_HPP_
16 
18 #include <Zoltan2_StridedData.hpp>
19 
20 namespace Zoltan2 {
21 
45 template <typename User>
47 
48 public:
50  typedef typename InputTraits<User>::lno_t lno_t;
51  typedef typename InputTraits<User>::gno_t gno_t;
54  typedef User user_t;
55 
70  BasicIdentifierAdapter(lno_t numIds, const gno_t *idPtr,
71  std::vector<const scalar_t *> &weights, std::vector<int> &weightStrides);
72 
80  BasicIdentifierAdapter(lno_t numIds, const gno_t *idPtr):
81  numIds_(numIds), idList_(idPtr), weights_() {}
82 
84  // The Adapter interface.
86 
87  size_t getLocalNumIDs() const { return numIds_; }
88 
89  void getIDsView(const gno_t *&Ids) const { Ids = idList_; }
90 
91  int getNumWeightsPerID() const { return weights_.size(); }
92 
93  void getWeightsView(const scalar_t *&weights, int &stride, int idx) const {
94  if (idx < 0 || idx >= weights_.size()) {
95  std::ostringstream emsg;
96  emsg << __FILE__ << ":" << __LINE__
97  << " Invalid weight index " << idx << std::endl;
98  throw std::runtime_error(emsg.str());
99  }
100  size_t length;
101  weights_[idx].getStridedList(length, weights, stride);
102  }
103 
104 private:
105  lno_t numIds_;
106  const gno_t *idList_;
107  ArrayRCP<StridedData<lno_t, scalar_t> > weights_;
108 };
109 
111 // Definitions
113 
114 template <typename User>
116  lno_t numIds, const gno_t *idPtr,
117  std::vector<const scalar_t *> &weights, std::vector<int> &weightStrides):
118  numIds_(numIds), idList_(idPtr), weights_()
119 {
120  typedef StridedData<lno_t, scalar_t> input_t;
121  size_t numWeights = weights.size();
122 
123  if (numWeights > 0){
124  weights_ = arcp(new input_t [numWeights], 0, numWeights, true);
125 
126  if (numIds > 0){
127  for (size_t i = 0; i < numWeights; i++){
128  int stride = weightStrides.size() ? weightStrides[i] : 1;
129  ArrayRCP<const scalar_t> wgtV(weights[i], 0, stride * numIds, false);
130  weights_[i] = input_t(wgtV, stride);
131  }
132  }
133  }
134 }
135 
136 } //namespace Zoltan2
137 
138 #endif
BasicIdentifierAdapter(lno_t numIds, const gno_t *idPtr, std::vector< const scalar_t * > &weights, std::vector< int > &weightStrides)
Constructor.
IdentifierAdapter defines the interface for identifiers.
void getIDsView(const gno_t *&Ids) const
Provide a pointer to this process&#39; identifiers.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
lno_t size() const
Return the length of the strided array.
default_part_t part_t
The data type to represent part numbers.
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:27
Defines the IdentifierAdapter interface.
This class represents a collection of global Identifiers and their associated weights, if any.
typename InputTraits< User >::gno_t gno_t
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices...
The StridedData class manages lists of weights or coordinates.
map_t::local_ordinal_type lno_t
Definition: mapRemotes.cpp:26
default_gno_t gno_t
The ordinal type (e.g., int, long, int64_t) that can represent global counts and identifiers.
default_node_t node_t
The Kokkos node type. This is only meaningful for users of Tpetra objects.
BasicIdentifierAdapter(lno_t numIds, const gno_t *idPtr)
Constructor.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
size_t getLocalNumIDs() const
Returns the number of objects on this process.
default_scalar_t scalar_t
The data type for weights and coordinates.
This file defines the StridedData class.