Zoltan2  Version of the Day
Zoltan2_BasicCoordinateInput.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_BASICCOORDINATEINPUT_HPP_
51 #define _ZOLTAN2_BASICCOORDINATEINPUT_HPP_
52 
54 #include <Zoltan2_StridedData.hpp>
55 #include <vector>
56 
57 namespace Zoltan2 {
58 
92 template <typename User>
93  class BasicCoordinateInput : public CoordinateInput<User> {
94 
95 public:
96 
97 #ifndef DOXYGEN_SHOULD_SKIP_THIS
98 
99  typedef typename InputTraits<User>::scalar_t scalar_t;
100  typedef typename InputTraits<User>::lno_t lno_t;
101  typedef typename InputTraits<User>::gno_t gno_t;
102  typedef typename InputTraits<User>::gid_t gid_t;
103  typedef typename InputTraits<User>::node_t node_t;
104  typedef CoordinateInput<User> base_adapter_t;
105  typedef User user_t;
106 
107 #endif
108 
127  BasicCoordinateInput(lno_t numIds, const gid_t *ids,
128  const scalar_t *x, const scalar_t *y, const scalar_t *z,
129  int xStride=1, int yStride=1, int zStride=1);
130 
155  BasicCoordinateInput(lno_t numIds, const gid_t *ids,
156  vector<const scalar_t *> &values, vector<int> &valueStrides,
157  vector<const scalar_t *> &weights, vector<int> &weightStrides);
158 
162 
164  // The InputAdapter interface.
166 
167  string inputAdapterName() const {return string("BasicCoordinate");}
168 
169  size_t getLocalNumberOfObjects() const { return numIds_;}
170 
171  int getNumberOfWeightsPerObject() const { return numWeights_;}
172 
173  size_t getObjectWeights(int dim, const scalar_t *&wgt, int &stride) const
174  {
175  return getCoordinateWeights(dim, wgt, stride);
176  }
177 
179  // The CoordinateInput interface.
181 
182  int getCoordinateDimension() const { return dimension_;}
183 
184  int getNumberOfWeights() const { return numWeights_;}
185 
186  size_t getLocalNumberOfCoordinates() const { return numIds_; }
187 
188  size_t getCoordinates(int dim, const gid_t *&gids, const scalar_t *&coords,
189  int &stride) const
190  {
191  env_->localInputAssertion(__FILE__, __LINE__, "invalid dimension",
192  dim >= 0 && dim < dimension_, BASIC_ASSERTION);
193 
194  gids = idList_;
195 
196  size_t length;
197 
198  coords_[dim].getStridedList(length, coords, stride);
199 
200  return length;
201  }
202 
203  size_t getCoordinateWeights(int dim, const scalar_t *&weights,
204  int &stride) const
205  {
206  env_->localInputAssertion(__FILE__, __LINE__, "invalid dimension",
207  dim >= 0 && dim < numWeights_, BASIC_ASSERTION);
208 
209  size_t length;
210 
211  weights_[dim].getStridedList(length, weights, stride);
212 
213  return length;
214  }
215 
216 private:
217  void initializeData(
218  vector<const scalar_t *> &values, vector<int> &valueStrides,
219  vector<const scalar_t *> &weights, vector<int> &weightStrides);
220 
221  // A default Environment for error handling.
222  RCP<const Environment> env_;
223 
224  lno_t numIds_;
225  const gid_t *idList_;
226 
227  int dimension_;
228  ArrayRCP<StridedData<lno_t, scalar_t> > coords_;
229 
230  int numWeights_;
231  ArrayRCP<StridedData<lno_t, scalar_t> > weights_;
232 };
233 
235 // Definitions
237 
238 template <typename User>
240  lno_t numIds, const gid_t *ids,
241  const scalar_t *x, const scalar_t *y, const scalar_t *z,
242  int xStride, int yStride, int zStride):
243  env_(rcp(new Environment)),
244  numIds_(numIds), idList_(ids),
245  dimension_(0), coords_(),
246  numWeights_(0), weights_()
247 {
248  vector<const scalar_t *> values;
249  vector<int> strides;
250  vector<const scalar_t *> emptyValues;
251  vector<int> emptyStrides;
252 
253  if (x){
254  values.push_back(x);
255  strides.push_back(xStride);
256  dimension_++;
257  if (y){
258  values.push_back(y);
259  strides.push_back(yStride);
260  dimension_++;
261  if (z){
262  values.push_back(z);
263  strides.push_back(zStride);
264  dimension_++;
265  }
266  }
267  }
268 
269  initializeData(values, strides, emptyValues, emptyStrides);
270 }
271 
272 template <typename User>
274  lno_t numIds, const gid_t *ids,
275  vector<const scalar_t *> &values, vector<int> &valueStrides,
276  vector<const scalar_t *> &weights, vector<int> &weightStrides):
277  env_(rcp(new Environment)),
278  numIds_(numIds), idList_(ids),
279  dimension_(values.size()), coords_(),
280  numWeights_(weights.size()), weights_()
281 {
282  initializeData(values, valueStrides, weights, weightStrides);
283 }
284 
285 template <typename User>
287  vector<const scalar_t *> &values, vector<int> &valueStrides,
288  vector<const scalar_t *> &weights, vector<int> &weightStrides)
289 {
291 
292  coords_ = arcp(new input_t [dimension_], 0, dimension_, true);
293 
294  if (numWeights_ > 0)
295  weights_ = arcp(new input_t [numWeights_], 0, numWeights_, true);
296 
297  if (numIds_){
298  int stride = 1;
299  for (int x=0; x < dimension_; x++){
300  if (valueStrides.size())
301  stride = valueStrides[x];
302  ArrayRCP<const scalar_t> coordV(values[x], 0, stride*numIds_, false);
303  coords_[x] = input_t(coordV, stride);
304  }
305 
306  if (numWeights_){
307  stride = 1;
308  for (int w=0; w < numWeights_; w++){
309  if (weightStrides.size())
310  stride = weightStrides[w];
311  ArrayRCP<const scalar_t> wgtV(weights[w], 0, stride*numIds_, false);
312  weights_[w] = input_t(wgtV, stride);
313  }
314  }
315  }
316 }
317 
318 } //namespace Zoltan2
319 
320 #endif
string inputAdapterName() const
Returns a descriptive name that identifies the concrete adapter.
fast typical checks for valid arguments
Zoltan2::StridedData< lno_t, scalar_t > input_t
Definition: GraphModel.cpp:80
size_t getLocalNumberOfCoordinates() const
Return the number of coordinates on this process.
size_t getCoordinateWeights(int dim, const scalar_t *&weights, int &stride) const
Provide a pointer to the weights, if any, corresponding to the coordinates returned in getCoordinates...
Zoltan2::BasicUserTypes< scalar_t, gno_t, lno_t, gno_t > user_t
Defines the CoordinateInput interface.
int getNumberOfWeights() const
Return the number of weights per coordinate.
size_t getObjectWeights(int dim, const scalar_t *&wgt, int &stride) const
Provide pointer to a weight array with stride.
int getCoordinateDimension() const
Return dimension of the coordinates.
size_t getLocalNumberOfObjects() const
Returns the number of objects in the input.
size_t getCoordinates(int dim, const gid_t *&gids, const scalar_t *&coords, int &stride) const
Provide a pointer to one dimension of this process&#39; coordinates.
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.
BasicCoordinateInput(lno_t numIds, const gid_t *ids, const scalar_t *x, const scalar_t *y, const scalar_t *z, int xStride=1, int yStride=1, int zStride=1)
Constructor for dimension 1, 2 or 3 and no weights.
default_gno_t gid_t
The data type that the user uses for global Identifiers.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
default_gno_t gno_t
The ordinal type (e.g., int, long, int64_t) that can represent global counts and identifiers.
int getNumberOfWeightsPerObject() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
Kokkos::DefaultNode::DefaultNodeType node_t
The Kokkos node type. This is only meaningful for users of Tpetra objects.
BasicCoordinateInput represents geometric coordinates that are supplied by the user as pointers to st...
CoordinateInput defines the interface for input geometric coordinates.
default_scalar_t scalar_t
The data type for weights and coordinates.
Kokkos::DefaultNode::DefaultNodeType node_t
This file defines the StridedData class.