51 #ifndef _ZOLTAN2_COORDINATEMODEL_HPP_
52 #define _ZOLTAN2_COORDINATEMODEL_HPP_
70 template <
typename Adapter>
75 #ifndef DOXYGEN_SHOULD_SKIP_THIS
76 typedef typename Adapter::scalar_t scalar_t;
81 typedef typename Adapter::userCoord_t userCoord_t;
91 const RCP<const Environment> &env,
92 const RCP<
const Comm<int> > &comm,
94 numGlobalCoordinates_(), env_(env), comm_(comm),
95 coordinateDim_(), gids_(),
96 xyz_(), userNumWeights_(0), weights_()
100 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
105 const RCP<const Environment> &env,
106 const RCP<
const Comm<int> > &comm,
108 numGlobalCoordinates_(), env_(env), comm_(comm),
109 coordinateDim_(), gids_(),
110 xyz_(), userNumWeights_(0), weights_()
112 if (!(ia->coordinatesAvailable()))
113 throw std::logic_error(
"No coordinate info provided to MatrixAdapter.");
117 adapterWithCoords_t *va = ia->getCoordinateInput();
119 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
125 const RCP<const Environment> &env,
126 const RCP<
const Comm<int> > &comm,
128 numGlobalCoordinates_(), env_(env), comm_(comm),
129 coordinateDim_(), gids_(),
130 xyz_(), userNumWeights_(0), weights_()
132 if (!(ia->coordinatesAvailable()))
133 throw std::logic_error(
"No coordinate info provided to GraphAdapter.");
137 adapterWithCoords_t *va = ia->getCoordinateInput();
139 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
145 const RCP<const Environment> &env,
146 const RCP<
const Comm<int> > &comm,
148 numGlobalCoordinates_(), env_(env), comm_(comm),
149 coordinateDim_(), gids_(),
150 xyz_(), userNumWeights_(0), weights_()
154 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
159 const RCP<const Environment> &env,
160 const RCP<
const Comm<int> > &comm,
163 throw std::logic_error(
164 "A coordinate model can not be build from an IdentifierAdapter");
210 ArrayView<input_t> &xyz,
211 ArrayView<input_t> &wgts)
const
213 xyz = xyz_.view(0, coordinateDim_);
214 wgts = weights_.view(0, userNumWeights_);
217 Ids = ArrayView<const gno_t>();
220 Ids = Teuchos::arrayView<const gno_t>(
221 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
235 Kokkos::View<const gno_t *, typename node_t::device_type> &Ids,
237 Kokkos::View<scalar_t **,
238 Kokkos::LayoutLeft,
typename node_t::device_type> &xyz,
239 Kokkos::View<scalar_t **, typename node_t::device_type> &wgts)
const
241 const auto type = ia_->adapterType();
254 ia_->getIDsKokkosView(Ids);
256 if(userNumWeights_ > 0) {
257 ia_->getWeightsKokkosView(wgts);
278 RCP<const BaseAdapter<user_t>> ia_;
280 size_t numGlobalCoordinates_;
281 const RCP<const Environment> env_;
282 const RCP<const Comm<int> > comm_;
285 ArrayRCP<const gno_t> gids_;
286 ArrayRCP<input_t> xyz_;
288 ArrayRCP<input_t> weights_;
290 template <
typename AdapterWithCoords_>
291 void sharedConstructor(
const AdapterWithCoords_ *ia,
292 const RCP<const Environment> &env,
293 const RCP<
const Comm<int> > &comm,
302 template <
typename Adapter>
303 template <
typename AdapterWithCoords_>
304 void CoordinateModel<Adapter>::sharedConstructor(
305 const AdapterWithCoords_ *ia,
306 const RCP<const Environment> &,
307 const RCP<
const Comm<int> > &comm,
310 size_t nLocalIds = ia_->getLocalNumIDs();
315 tmp[0] = ia->getDimension();
316 tmp[1] = ia->getNumWeightsPerID();
317 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, tmp, gtmp);
318 coordinateDim_ = gtmp[0];
319 userNumWeights_ = gtmp[1];
321 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
324 input_t *coordArray =
new input_t [coordinateDim_];
325 input_t *weightArray = NULL;
327 weightArray =
new input_t [userNumWeights_];
329 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
330 coordArray && (!userNumWeights_|| weightArray));
334 const gno_t *gids=NULL;
336 ia->getIDsView(gids);
337 gids_ = arcp(gids, 0, nLocalIds,
false);
339 for (
int dim=0; dim < coordinateDim_; dim++){
341 const scalar_t *coords=NULL;
343 ia->getCoordinatesView(coords, stride, dim);
347 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
348 coordArray[dim] = input_t(cArray, stride);
351 for (
int idx=0; idx < userNumWeights_; idx++){
355 ia->getWeightsView(weights, stride, idx);
359 ArrayRCP<const scalar_t> wArray(weights, 0, nLocalIds*stride,
false);
360 weightArray[idx] = input_t(wArray, stride);
364 xyz_ = arcp(coordArray, 0, coordinateDim_);
367 weights_ = arcp(weightArray, 0, userNumWeights_);
369 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
370 &nLocalIds, &numGlobalCoordinates_);
372 env_->memory(
"After construction of coordinate model");
virtual VectorAdapter< UserCoord > * getCoordinateInput() const =0
global_size_t getGlobalNumCoordinates() const
Returns the global number coordinates.
IdentifierAdapter defines the interface for identifiers.
CoordinateModel(const RCP< const MatrixAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
CoordinateModel(const RCP< const MeshAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
MatrixAdapter defines the adapter interface for matrices.
Defines the Model interface.
void getCoordinatesKokkosView(typename AdapterWithCoords< User >::CoordsDeviceView &elements) const override
GraphAdapter defines the interface for graph-based user data.
Defines the MeshAdapter interface.
MeshAdapter defines the interface for mesh input.
more involved, like validate a graph
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
map_t::global_ordinal_type gno_t
Defines the IdentifierAdapter interface.
Defines the VectorAdapter interface.
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
size_t getCoordinates(ArrayView< const gno_t > &Ids, ArrayView< input_t > &xyz, ArrayView< input_t > &wgts) const
Returns the coordinate ids, values and optional weights.
CoordinateModel(const RCP< const GraphAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
size_t getCoordinatesKokkos(Kokkos::View< const gno_t *, typename node_t::device_type > &Ids, Kokkos::View< scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type > &xyz, Kokkos::View< scalar_t **, typename node_t::device_type > &wgts) const
Returns the coordinate ids, values and optional weights.
VectorAdapter defines the interface for vector input.
size_t getLocalNumObjects() const
Return the local number of objects.
The StridedData class manages lists of weights or coordinates.
size_t getGlobalNumObjects() const
Return the global number of objects.
map_t::local_ordinal_type lno_t
size_t getLocalNumCoordinates() const
Returns the number of coordinates on this process.
int getNumWeightsPerCoordinate() const
Returns the number (0 or greater) of weights per coordinate.
Defines the MatrixAdapter interface.
The base class for all model classes.
Tpetra::global_size_t global_size_t
CoordinateModel(const RCP< const VectorAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
Defines the GraphAdapter interface.
int getCoordinateDim() const
Returns the dimension of the coordinates.
virtual void getCoordinatesKokkosView(CoordsDeviceView &elements) const =0
CoordinateModel(const RCP< const IdentifierAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
This file defines the StridedData class.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t