15#ifndef _ZOLTAN2_COORDINATEMODEL_HPP_
16#define _ZOLTAN2_COORDINATEMODEL_HPP_
34template <
typename Adapter>
39#ifndef DOXYGEN_SHOULD_SKIP_THIS
40 typedef typename Adapter::scalar_t scalar_t;
41 typedef typename Adapter::gno_t
gno_t;
42 typedef typename Adapter::lno_t
lno_t;
43 typedef typename Adapter::node_t
node_t;
44 typedef typename Adapter::user_t
user_t;
45 typedef typename Adapter::userCoord_t userCoord_t;
55 const RCP<const Environment> &env,
56 const RCP<
const Comm<int> > &comm,
58 numGlobalCoordinates_(), env_(env), comm_(comm),
59 coordinateDim_(), gids_(),
60 xyz_(), userNumWeights_(0), weights_()
64 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
69 const RCP<const Environment> &env,
70 const RCP<
const Comm<int> > &comm,
72 numGlobalCoordinates_(), env_(env), comm_(comm),
73 coordinateDim_(), gids_(),
74 xyz_(), userNumWeights_(0), weights_()
76 if (!(ia->coordinatesAvailable()))
77 throw std::logic_error(
"No coordinate info provided to MatrixAdapter.");
81 adapterWithCoords_t *va = ia->getCoordinateInput();
83 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
89 const RCP<const Environment> &env,
90 const RCP<
const Comm<int> > &comm,
92 numGlobalCoordinates_(), env_(env), comm_(comm),
93 coordinateDim_(), gids_(),
94 xyz_(), userNumWeights_(0), weights_()
96 if (!(ia->coordinatesAvailable()))
97 throw std::logic_error(
"No coordinate info provided to GraphAdapter.");
101 adapterWithCoords_t *va = ia->getCoordinateInput();
103 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
109 const RCP<const Environment> &env,
110 const RCP<
const Comm<int> > &comm,
112 numGlobalCoordinates_(), env_(env), comm_(comm),
113 coordinateDim_(), gids_(),
114 xyz_(), userNumWeights_(0), weights_()
118 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
123 const RCP<const Environment> &env,
124 const RCP<
const Comm<int> > &comm,
127 throw std::logic_error(
128 "A coordinate model can not be build from an IdentifierAdapter");
174 ArrayView<input_t> &xyz,
175 ArrayView<input_t> &wgts)
const
177 xyz = xyz_.view(0, coordinateDim_);
178 wgts = weights_.view(0, userNumWeights_);
181 Ids = ArrayView<const gno_t>();
184 Ids = Teuchos::arrayView<const gno_t>(
185 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
199 Kokkos::View<const gno_t *, typename node_t::device_type> &Ids,
201 Kokkos::View<scalar_t **,
202 Kokkos::LayoutLeft,
typename node_t::device_type> &xyz,
203 Kokkos::View<scalar_t **, typename node_t::device_type> &wgts)
const
205 const auto type = ia_->adapterType();
218 ia_->getIDsKokkosView(Ids);
220 if(userNumWeights_ > 0) {
221 ia_->getWeightsKokkosView(wgts);
242 RCP<const BaseAdapter<user_t>> ia_;
244 size_t numGlobalCoordinates_;
245 const RCP<const Environment> env_;
246 const RCP<const Comm<int> > comm_;
249 ArrayRCP<const gno_t> gids_;
250 ArrayRCP<input_t> xyz_;
252 ArrayRCP<input_t> weights_;
254 template <
typename AdapterWithCoords_>
255 void sharedConstructor(
const AdapterWithCoords_ *ia,
256 const RCP<const Environment> &env,
257 const RCP<
const Comm<int> > &comm,
266template <
typename Adapter>
267template <
typename AdapterWithCoords_>
268void CoordinateModel<Adapter>::sharedConstructor(
269 const AdapterWithCoords_ *ia,
270 const RCP<const Environment> &,
271 const RCP<
const Comm<int> > &comm,
274 size_t nLocalIds = ia_->getLocalNumIDs();
279 tmp[0] = ia->getDimension();
280 tmp[1] = ia->getNumWeightsPerID();
281 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, tmp, gtmp);
282 coordinateDim_ = gtmp[0];
283 userNumWeights_ = gtmp[1];
285 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
288 input_t *coordArray =
new input_t [coordinateDim_];
289 input_t *weightArray = NULL;
291 weightArray =
new input_t [userNumWeights_];
293 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
294 coordArray && (!userNumWeights_|| weightArray));
298 const gno_t *gids=NULL;
300 ia->getIDsView(gids);
301 gids_ = arcp(gids, 0, nLocalIds,
false);
303 for (
int dim=0; dim < coordinateDim_; dim++){
305 const scalar_t *coords=NULL;
307 ia->getCoordinatesView(coords, stride, dim);
311 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
312 coordArray[dim] = input_t(cArray, stride);
315 for (
int idx=0; idx < userNumWeights_; idx++){
319 ia->getWeightsView(
weights, stride, idx);
323 ArrayRCP<const scalar_t> wArray(
weights, 0, nLocalIds*stride,
false);
324 weightArray[idx] = input_t(wArray, stride);
328 xyz_ = arcp(coordArray, 0, coordinateDim_);
331 weights_ = arcp(weightArray, 0, userNumWeights_);
333 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
334 &nLocalIds, &numGlobalCoordinates_);
336 env_->memory(
"After construction of coordinate model");
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the GraphAdapter interface.
Defines the IdentifierAdapter interface.
Defines the MatrixAdapter interface.
Defines the MeshAdapter interface.
Defines the Model interface.
This file defines the StridedData class.
Defines the VectorAdapter interface.
virtual VectorAdapter< UserCoord > * getCoordinateInput() const =0
virtual void getCoordinatesKokkosView(CoordsDeviceView &elements) const =0
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
global_size_t getGlobalNumCoordinates() const
Returns the global number coordinates.
size_t getGlobalNumObjects() const
Return the global number of objects.
CoordinateModel(const RCP< const VectorAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
size_t getLocalNumObjects() const
Return the local number of objects.
CoordinateModel(const RCP< const IdentifierAdapter< user_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
CoordinateModel(const RCP< const MeshAdapter< user_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.
int getCoordinateDim() const
Returns the dimension of the coordinates.
CoordinateModel(const RCP< const GraphAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
CoordinateModel(const RCP< const MatrixAdapter< user_t, userCoord_t > > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &flags)
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.
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.
GraphAdapter defines the interface for graph-based user data.
IdentifierAdapter defines the interface for identifiers.
MatrixAdapter defines the adapter interface for matrices.
MeshAdapter defines the interface for mesh input.
The base class for all model classes.
The StridedData class manages lists of weights or coordinates.
VectorAdapter defines the interface for vector input.
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
Tpetra::global_size_t global_size_t
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
@ COMPLEX_ASSERTION
more involved, like validate a graph
@ VectorAdapterType
vector data
@ GraphAdapterType
graph data
@ MatrixAdapterType
matrix data
@ MeshAdapterType
mesh data