14#ifndef ZOLTAN2_TPETRAMULTIVECTORADAPTER_HPP
15#define ZOLTAN2_TPETRAMULTIVECTORADAPTER_HPP
22#include <Tpetra_MultiVector.hpp>
41template <
typename User>
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
53 typedef User userCoord_t;
55 typedef Tpetra::MultiVector<scalar_t, lno_t, gno_t, node_t> t_mvector_t;
74 std::vector<const scalar_t *> &
weights, std::vector<int> &weightStrides);
92 ids = map_->getLocalElementList().getRawPtr();
96 Kokkos::View<const gno_t *, typename node_t::device_type> &ids)
const {
97 using device_type =
typename node_t::device_type;
105 ids = Kokkos::create_mirror_view_and_copy(device_type(),
106 vector_->getMap()->getMyGlobalIndices());
113 if(idx<0 || idx >= numWeights_)
115 std::ostringstream emsg;
116 emsg << __FILE__ <<
":" << __LINE__
117 <<
" Invalid weight index " << idx << std::endl;
118 throw std::runtime_error(emsg.str());
122 weights_[idx].getStridedList(length,
weights, stride);
126 typename node_t::device_type> &wgt)
const {
127 typedef Kokkos::View<scalar_t**, typename node_t::device_type> view_t;
128 wgt = view_t(
"wgts", vector_->getLocalLength(), numWeights_);
129 typename view_t::host_mirror_type host_wgt = Kokkos::create_mirror_view(wgt);
130 for(
int idx = 0; idx < numWeights_; ++idx) {
134 weights_[idx].getStridedList(length,
weights, stride);
135 size_t fill_index = 0;
136 for(
size_t n = 0; n < length; n += stride) {
137 host_wgt(fill_index++,idx) =
weights[n];
140 Kokkos::deep_copy(wgt, host_wgt);
153 Kokkos::View<impl_scalar_t **, Kokkos::LayoutLeft,
154 typename node_t::device_type> & elements)
const;
156 template <
typename Adapter>
160 template <
typename Adapter>
166 RCP<const User> invector_;
167 RCP<const t_mvector_t> vector_;
168 RCP<const Tpetra::Map<lno_t, gno_t, node_t> > map_;
171 ArrayRCP<StridedData<lno_t, scalar_t> > weights_;
178template <
typename User>
180 const RCP<const User> &invector,
181 std::vector<const scalar_t *> &
weights, std::vector<int> &weightStrides):
182 invector_(invector), vector_(), map_(),
188 map_ = vector_->getMap();
190 size_t length = vector_->getLocalLength();
192 if (length > 0 && numWeights_ > 0){
194 for (
int w=0; w < numWeights_; w++){
195 if (weightStrides.size())
196 stride = weightStrides[w];
197 ArrayRCP<const scalar_t> wgtV(
weights[w], 0, stride*length,
false);
198 weights_[w] = input_t(wgtV, stride);
205template <
typename User>
207 const RCP<const User> &invector):
208 invector_(invector), vector_(), map_(),
209 numWeights_(0), weights_()
212 map_ = vector_->getMap();
216template <
typename User>
218 const scalar_t *&elements,
int &stride,
int idx)
const
223 vecsize = vector_->getLocalLength();
225 ArrayRCP<const scalar_t> data = vector_->getData(idx);
226 elements = data.get();
231template <
typename User>
234 Kokkos::View<impl_scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> & elements)
const
238 rcp_const_cast<t_mvector_t>(vector_)->getLocalViewDevice(Tpetra::Access::ReadWrite);
245template <
typename User>
246 template <
typename Adapter>
248 const User &in, User *&out,
253 ArrayRCP<gno_t> importList;
257 (solution,
this, importList);
263 importList.getRawPtr());
269template <
typename User>
270 template <
typename Adapter>
272 const User &in, RCP<User> &out,
277 ArrayRCP<gno_t> importList;
281 (solution,
this, importList);
287 importList.getRawPtr());
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Helper functions for Partitioning Problems.
This file defines the StridedData class.
Defines the VectorAdapter interface.
Traits of Xpetra classes, including migration method.
typename BaseAdapter< User >::scalar_t scalar_t
typename InputTraits< User >::node_t node_t
typename InputTraits< User >::lno_t lno_t
typename InputTraits< User >::gno_t gno_t
typename InputTraits< User >::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
The StridedData class manages lists of weights or coordinates.
An adapter for Tpetra::MultiVector.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater....
void getEntriesKokkosView(Kokkos::View< impl_scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type > &elements) const
TpetraMultiVectorAdapter(const RCP< const User > &invector, std::vector< const scalar_t * > &weights, std::vector< int > &weightStrides)
Constructor.
void getWeightsKokkos2dView(Kokkos::View< scalar_t **, typename node_t::device_type > &wgt) const
int getNumEntriesPerID() const
Return the number of vectors.
void getIDsView(const gno_t *&ids) const
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
void getIDsKokkosView(Kokkos::View< const gno_t *, typename node_t::device_type > &ids) const
void getEntriesView(const scalar_t *&elements, int &stride, int idx=0) const
Provide a pointer to the elements of the specified vector.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
VectorAdapter defines the interface for vector input.
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
size_t getImportList(const PartitioningSolution< SolutionAdapter > &solution, const DataAdapter *const data, ArrayRCP< typename DataAdapter::gno_t > &imports)
From a PartitioningSolution, get a list of IDs to be imported. Assumes part numbers in PartitioningSo...
static RCP< User > doMigration(const User &from, size_t numLocalRows, const gno_t *myNewRows)
Migrate the object Given a user object and a new row distribution, create and return a new user objec...