14#ifndef _ZOLTAN2_XPETRAMULTIVECTORADAPTER_HPP_
15#define _ZOLTAN2_XPETRAMULTIVECTORADAPTER_HPP_
22#if defined(HAVE_ZOLTAN2_EPETRA) && defined(HAVE_XPETRA_EPETRA)
23#include <Xpetra_EpetraMultiVector.hpp>
25#include <Xpetra_TpetraMultiVector.hpp>
46template <
typename User>
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
58 typedef User userCoord_t;
60 typedef Xpetra::MultiVector<scalar_t, lno_t, gno_t, node_t> x_mvector_t;
61 typedef Xpetra::TpetraMultiVector<
81 std::vector<const scalar_t *> &
weights, std::vector<int> &weightStrides);
99 ids = map_->getLocalElementList().getRawPtr();
103 Kokkos::View<const gno_t *, typename node_t::device_type> &ids)
const {
104 if (map_->lib() == Xpetra::UseTpetra) {
105 using device_type =
typename node_t::device_type;
106 const xt_mvector_t *tvector =
107 dynamic_cast<const xt_mvector_t *
>(vector_.get());
115 ids = Kokkos::create_mirror_view_and_copy(device_type(),
116 tvector->getTpetra_MultiVector()->getMap()->getMyGlobalIndices());
118 else if (map_->lib() == Xpetra::UseEpetra) {
119#if defined(HAVE_ZOLTAN2_EPETRA) && defined(HAVE_XPETRA_EPETRA)
123 throw std::logic_error(
"Epetra requested, but Trilinos is not "
124 "built with Epetra");
128 throw std::logic_error(
"getIDsKokkosView called but not on Tpetra or Epetra!");
136 if(idx<0 || idx >= numWeights_)
138 std::ostringstream emsg;
139 emsg << __FILE__ <<
":" << __LINE__
140 <<
" Invalid weight index " << idx << std::endl;
141 throw std::runtime_error(emsg.str());
145 weights_[idx].getStridedList(length,
weights, stride);
149 typename node_t::device_type> &wgt)
const {
150 typedef Kokkos::View<scalar_t**, typename node_t::device_type> view_t;
151 wgt = view_t(
"wgts", vector_->getLocalLength(), numWeights_);
152 typename view_t::host_mirror_type host_wgt = Kokkos::create_mirror_view(wgt);
153 for(
int idx = 0; idx < numWeights_; ++idx) {
157 weights_[idx].getStridedList(length,
weights, stride);
158 size_t fill_index = 0;
159 for(
size_t n = 0; n < length; n += stride) {
160 host_wgt(fill_index++,idx) =
weights[n];
163 Kokkos::deep_copy(wgt, host_wgt);
176 Kokkos::View<impl_scalar_t **, Kokkos::LayoutLeft,
177 typename node_t::device_type> & elements)
const;
179 template <
typename Adapter>
183 template <
typename Adapter>
189 RCP<const User> invector_;
190 RCP<const x_mvector_t> vector_;
191 RCP<const Xpetra::Map<lno_t, gno_t, node_t> > map_;
194 ArrayRCP<StridedData<lno_t, scalar_t> > weights_;
201template <
typename User>
203 const RCP<const User> &invector,
204 std::vector<const scalar_t *> &
weights, std::vector<int> &weightStrides):
205 invector_(invector), vector_(), map_(),
211 RCP<x_mvector_t> tmp =
213 vector_ = rcp_const_cast<const x_mvector_t>(tmp);
217 map_ = vector_->getMap();
219 size_t length = vector_->getLocalLength();
221 if (length > 0 && numWeights_ > 0){
223 for (
int w=0; w < numWeights_; w++){
224 if (weightStrides.size())
225 stride = weightStrides[w];
226 ArrayRCP<const scalar_t> wgtV(
weights[w], 0, stride*length,
false);
227 weights_[w] = input_t(wgtV, stride);
234template <
typename User>
236 const RCP<const User> &invector):
237 invector_(invector), vector_(), map_(),
238 numWeights_(0), weights_()
241 RCP<x_mvector_t> tmp =
243 vector_ = rcp_const_cast<const x_mvector_t>(tmp);
247 map_ = vector_->getMap();
251template <
typename User>
253 const scalar_t *&elements,
int &stride,
int idx)
const
258 if (map_->lib() == Xpetra::UseTpetra){
259 const xt_mvector_t *tvector =
260 dynamic_cast<const xt_mvector_t *
>(vector_.get());
262 vecsize = tvector->getLocalLength();
264 ArrayRCP<const scalar_t> data = tvector->getData(idx);
265 elements = data.get();
268 else if (map_->lib() == Xpetra::UseEpetra){
269#if defined(HAVE_ZOLTAN2_EPETRA) && defined(HAVE_XPETRA_EPETRA)
270 typedef Xpetra::EpetraMultiVectorT<gno_t,node_t> xe_mvector_t;
271 const xe_mvector_t *evector =
272 dynamic_cast<const xe_mvector_t *
>(vector_.get());
274 vecsize = evector->getLocalLength();
276 ArrayRCP<const double> data = evector->getData(idx);
280 elements =
reinterpret_cast<const scalar_t *
>(data.get());
283 throw std::logic_error(
"Epetra requested, but Trilinos is not "
284 "built with Epetra");
288 throw std::logic_error(
"invalid underlying lib");
293template <
typename User>
296 Kokkos::View<impl_scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> & elements)
const
298 if (map_->lib() == Xpetra::UseTpetra){
299 const xt_mvector_t *tvector =
300 dynamic_cast<const xt_mvector_t *
>(vector_.get());
303 tvector->getTpetra_MultiVector()->template getLocalView<typename node_t::device_type>(Tpetra::Access::ReadWrite);
309 else if (map_->lib() == Xpetra::UseEpetra){
310#if defined(HAVE_ZOLTAN2_EPETRA) && defined(HAVE_XPETRA_EPETRA)
311 typedef Xpetra::EpetraMultiVectorT<gno_t,node_t> xe_mvector_t;
312 const xe_mvector_t *evector =
313 dynamic_cast<const xe_mvector_t *
>(vector_.get());
315 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type>
316 (
"elements", evector->getLocalLength(), evector->getNumVectors());
317 if(evector->getLocalLength() > 0) {
318 for(
size_t idx = 0; idx < evector->getNumVectors(); ++idx) {
321 getEntriesView(ptr, stride, idx);
322 for(
size_t n = 0; n < evector->getLocalLength(); ++n) {
323 elements(n, idx) = ptr[n];
328 throw std::logic_error(
"Epetra requested, but Trilinos is not "
329 "built with Epetra");
333 throw std::logic_error(
"getEntriesKokkosView called but not using Tpetra or Epetra!");
338template <
typename User>
339 template <
typename Adapter>
341 const User &in, User *&out,
346 ArrayRCP<gno_t> importList;
350 (solution,
this, importList);
356 importList.getRawPtr());
362template <
typename User>
363 template <
typename Adapter>
365 const User &in, RCP<User> &out,
370 ArrayRCP<gno_t> importList;
374 (solution,
this, importList);
380 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
virtual void getIDsKokkosView(ConstIdsDeviceView &ids) const
Provide a Kokkos view to this process' identifiers.
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.
VectorAdapter defines the interface for vector input.
An adapter for Xpetra::MultiVector.
void getEntriesView(const scalar_t *&elements, int &stride, int idx=0) const
Provide a pointer to the elements of the specified vector.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
void getIDsView(const gno_t *&ids) const
void getWeightsKokkos2dView(Kokkos::View< scalar_t **, typename node_t::device_type > &wgt) const
XpetraMultiVectorAdapter(const RCP< const User > &invector, std::vector< const scalar_t * > &weights, std::vector< int > &weightStrides)
Constructor.
void getIDsKokkosView(Kokkos::View< const gno_t *, typename node_t::device_type > &ids) const
int getNumEntriesPerID() const
Return the number of vectors.
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater....
void getWeightsView(const scalar_t *&weights, int &stride, int idx) const
void getEntriesKokkosView(Kokkos::View< impl_scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type > &elements) const
size_t getLocalNumIDs() const
Returns the number of objects on this process.
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...
static RCP< User > convertToXpetra(const RCP< User > &a)
Convert the object to its Xpetra wrapped version.