50#ifndef _ZOLTAN2_ADAPTER_HPP_
51#define _ZOLTAN2_ADAPTER_HPP_
53#include <Kokkos_Core.hpp>
100template <
typename User>
127 Kokkos::View<const gno_t *, typename node_t::device_type> kokkosIds;
129 ids = kokkosIds.data();
137 typename node_t::device_type> &ids)
const {
141 const gno_t * ptr_ids;
143 typedef Kokkos::View<gno_t *, typename node_t::device_type> view_t;
145 typename view_t::HostMirror host_ids = Kokkos::create_mirror_view(non_const_ids);
147 host_ids(i) = ptr_ids[i];
149 Kokkos::deep_copy(non_const_ids, host_ids);
162 virtual void getWeightsView(
const scalar_t *&wgt,
int &stride,
167 Kokkos::View<scalar_t **, typename node_t::device_type> kokkos_wgts_2d;
168 getWeightsKokkosView(kokkos_wgts_2d);
169 Kokkos::View<scalar_t *, typename node_t::device_type> kokkos_wgts;
170 wgt = Kokkos::subview(kokkos_wgts_2d, Kokkos::ALL, idx).data();
180 virtual void getWeightsKokkosView(Kokkos::View<
scalar_t **,
181 typename node_t::device_type> & wgt)
const {
185 wgt = Kokkos::View<scalar_t **, typename node_t::device_type>(
187 typename Kokkos::View<scalar_t **, typename node_t::device_type>::HostMirror
188 host_wgt = Kokkos::create_mirror_view(wgt);
192 getWeightsView(ptr_wgts, stride, j);
194 for(
size_t n = 0; n < this->
getLocalNumIDs() * stride; n += stride) {
195 host_wgt(i++,j) = ptr_wgts[n];
198 Kokkos::deep_copy(wgt, host_wgt);
233 template <
typename Adapter>
247 const Teuchos::Comm<int> &comm)
const;
251template <
typename User>
253 const char *fileprefix,
254 const Teuchos::Comm<int> &comm
257 int np = comm.getSize();
258 int me = comm.getRank();
260 size_t nLocalIDs = this->getLocalNumIDs();
267 std::string filenamestr = fileprefix;
268 filenamestr = filenamestr +
".graph";
269 const char *filename = filenamestr.c_str();
272 Teuchos::reduceAll(comm, Teuchos::REDUCE_SUM, 1, &nLocalIDs, &nGlobalIDs);
274 int nWgts = this->getNumWeightsPerID();
276 for (
int p = 0; p < np; p++) {
285 fp.open(filename, std::ios::out);
288 fp << nGlobalIDs <<
" " << 0 <<
" "
289 << (nWgts ?
"010" :
"000") <<
" "
290 << (nWgts > 1 ? std::to_string(nWgts) :
" ") << std::endl;
294 fp.open(filename, std::ios::app);
301 int *strides =
new int[nWgts];
302 for (
int n = 0; n < nWgts; n++)
303 getWeightsView(wgts[n], strides[n], n);
306 for (
size_t i = 0; i < nLocalIDs; i++) {
307 for (
int n = 0; n < nWgts; n++)
308 fp << wgts[n][i*strides[n]] <<
" ";
325 std::string filenamestr = fileprefix;
326 filenamestr = filenamestr +
".assign";
327 const char *filename = filenamestr.c_str();
329 for (
int p = 0; p < np; p++) {
338 fp.open(filename, std::ios::out);
342 fp.open(filename, std::ios::app);
346 this->getPartsView(parts);
348 for (
size_t i = 0; i < nLocalIDs; i++) {
349 fp << (parts != NULL ? parts[i] : me) <<
"\n";
#define Z2_THROW_NOT_IMPLEMENTED
Defines the PartitioningSolution class.
Gathering definitions used in software development.
BaseAdapter defines methods required by all Adapters.
virtual ~BaseAdapterRoot()
virtual int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater....
virtual size_t getLocalNumIDs() const =0
Returns the number of objects on this process.
InputTraits< User >::node_t node_t
void getPartsView(const part_t *&inputPart) const
Provide pointer to a weight array with stride.
InputTraits< User >::offset_t offset_t
InputTraits< User >::part_t part_t
InputTraits< User >::scalar_t scalar_t
void generateWeightFileOnly(const char *fileprefix, const Teuchos::Comm< int > &comm) const
virtual void getIDsView(const gno_t *&ids) const
Provide a pointer to this process' identifiers.
InputTraits< User >::lno_t lno_t
virtual ~BaseAdapter()
Destructor.
virtual void getIDsKokkosView(Kokkos::View< const gno_t *, typename node_t::device_type > &ids) const
Provide a Kokkos view to this process' identifiers.
virtual enum BaseAdapterType adapterType() const =0
Returns the type of adapter.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
Apply a PartitioningSolution to an input.
InputTraits< User >::gno_t gno_t
A PartitioningSolution is a solution to a partitioning problem.
Created by mbenlioglu on Aug 31, 2020.
BaseAdapterType
An enum to identify general types of adapters.
@ VectorAdapterType
vector data
@ InvalidAdapterType
unused value
@ GraphAdapterType
graph data
@ MatrixAdapterType
matrix data
@ MeshAdapterType
mesh data
@ IdentifierAdapterType
identifier data, just a list of IDs