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;
79 typedef typename Adapter::node_t node_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_()
99 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
104 const RCP<const Environment> &env,
105 const RCP<
const Comm<int> > &comm,
107 numGlobalCoordinates_(), env_(env), comm_(comm),
108 coordinateDim_(), gids_(),
109 xyz_(), userNumWeights_(0), weights_()
111 if (!(ia->coordinatesAvailable()))
112 throw std::logic_error(
"No coordinate info provided to MatrixAdapter.");
115 adapterWithCoords_t *va = ia->getCoordinateInput();
116 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
122 const RCP<const Environment> &env,
123 const RCP<
const Comm<int> > &comm,
125 numGlobalCoordinates_(), env_(env), comm_(comm),
126 coordinateDim_(), gids_(),
127 xyz_(), userNumWeights_(0), weights_()
129 if (!(ia->coordinatesAvailable()))
130 throw std::logic_error(
"No coordinate info provided to GraphAdapter.");
133 adapterWithCoords_t *va = ia->getCoordinateInput();
134 sharedConstructor<adapterWithCoords_t>(va, env, comm, flags);
140 const RCP<const Environment> &env,
141 const RCP<
const Comm<int> > &comm,
143 numGlobalCoordinates_(), env_(env), comm_(comm),
144 coordinateDim_(), gids_(),
145 xyz_(), userNumWeights_(0), weights_()
148 sharedConstructor<adapterWithCoords_t>(&(*ia), env, comm, flags);
153 const RCP<const Environment> &env,
154 const RCP<
const Comm<int> > &comm,
157 throw std::logic_error(
158 "A coordinate model can not be build from an IdentifierAdapter");
204 ArrayView<input_t> &xyz,
205 ArrayView<input_t> &wgts)
const
207 xyz = xyz_.view(0, coordinateDim_);
208 wgts = weights_.view(0, userNumWeights_);
211 Ids = ArrayView<const gno_t>();
214 Ids = Teuchos::arrayView<const gno_t>(
215 reinterpret_cast<const gno_t *
>(gids_.getRawPtr()), nCoord);
229 Kokkos::View<const gno_t *, typename node_t::device_type> &Ids,
231 Kokkos::View<scalar_t **,
232 Kokkos::LayoutLeft,
typename node_t::device_type> &xyz,
233 Kokkos::View<scalar_t **, typename node_t::device_type> &wgts)
const
237 wgts = kokkos_weights_;
256 size_t numGlobalCoordinates_;
257 const RCP<const Environment> env_;
258 const RCP<const Comm<int> > comm_;
265 Kokkos::View<gno_t *, typename node_t::device_type> kokkos_gids_;
267 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> kokkos_xyz_;
268 Kokkos::View<scalar_t **, typename node_t::device_type> kokkos_weights_;
270 ArrayRCP<const gno_t> gids_;
271 ArrayRCP<input_t> xyz_;
273 ArrayRCP<input_t> weights_;
275 template <
typename AdapterWithCoords>
276 void sharedConstructor(
const AdapterWithCoords *ia,
277 const RCP<const Environment> &env,
278 const RCP<
const Comm<int> > &comm,
287 template <
typename Adapter>
288 template <
typename AdapterWithCoords>
289 void CoordinateModel<Adapter>::sharedConstructor(
290 const AdapterWithCoords *ia,
291 const RCP<const Environment> &,
292 const RCP<
const Comm<int> > &comm,
295 size_t nLocalIds = ia->getLocalNumIDs();
300 tmp[0] = ia->getDimension();
301 tmp[1] = ia->getNumWeightsPerID();
302 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 2, tmp, gtmp);
303 coordinateDim_ = gtmp[0];
304 userNumWeights_ = gtmp[1];
306 env_->localBugAssertion(__FILE__, __LINE__,
"coordinate dimension",
309 input_t *coordArray =
new input_t [coordinateDim_];
310 input_t *weightArray = NULL;
312 weightArray =
new input_t [userNumWeights_];
314 env_->localMemoryAssertion(__FILE__, __LINE__, userNumWeights_+coordinateDim_,
315 coordArray && (!userNumWeights_|| weightArray));
319 const gno_t *gids=NULL;
321 ia->getIDsView(gids);
322 gids_ = arcp(gids, 0, nLocalIds,
false);
324 for (
int dim=0; dim < coordinateDim_; dim++){
326 const scalar_t *coords=NULL;
328 ia->getCoordinatesView(coords, stride, dim);
332 ArrayRCP<const scalar_t> cArray(coords, 0, nLocalIds*stride,
false);
333 coordArray[dim] = input_t(cArray, stride);
336 for (
int idx=0; idx < userNumWeights_; idx++){
340 ia->getWeightsView(
weights, stride, idx);
344 ArrayRCP<const scalar_t> wArray(
weights, 0, nLocalIds*stride,
false);
345 weightArray[idx] = input_t(wArray, stride);
349 xyz_ = arcp(coordArray, 0, coordinateDim_);
352 weights_ = arcp(weightArray, 0, userNumWeights_);
355 Kokkos::View<const gno_t *, typename node_t::device_type> kokkos_gids;
356 ia->getIDsKokkosView(kokkos_gids);
357 kokkos_gids_ = Kokkos::View<gno_t *, typename node_t::device_type>(
"kokkos_gids_",kokkos_gids.extent(0));
358 Kokkos::deep_copy(kokkos_gids_, kokkos_gids);
360 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> kokkos_xyz;
361 ia->getCoordinatesKokkosView(kokkos_xyz);
362 kokkos_xyz_ = Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type>(
"kokkos_xyz", kokkos_xyz.extent(0), kokkos_xyz.extent(1));
363 Kokkos::deep_copy(kokkos_xyz_, kokkos_xyz);
365 if(userNumWeights_ > 0) {
366 Kokkos::View<scalar_t **, typename node_t::device_type> kokkos_weights;
367 ia->getWeightsKokkosView(kokkos_weights);
368 kokkos_weights_ = Kokkos::View<scalar_t **, typename node_t::device_type>(
"kokkos_weights_",kokkos_weights.extent(0), kokkos_weights.extent(1));
369 Kokkos::deep_copy(kokkos_weights_, kokkos_weights);
373 Teuchos::reduceAll<int, size_t>(*comm, Teuchos::REDUCE_SUM, 1,
374 &nLocalIds, &numGlobalCoordinates_);
376 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.
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