14 #ifndef _ZOLTAN2_ADAPTER_HPP_
15 #define _ZOLTAN2_ADAPTER_HPP_
17 #include <Kokkos_Core.hpp>
68 template <
typename User>
78 using host_t =
typename Kokkos::HostSpace::memory_space;
127 ids = kokkosIds.data();
139 const gno_t * ptr_ids;
143 auto host_ids = Kokkos::create_mirror_view(non_const_ids);
145 host_ids(i) = ptr_ids[i];
147 Kokkos::deep_copy(non_const_ids, host_ids);
181 Kokkos::View<scalar_t **, device_t> kokkos_wgts_2d;
183 Kokkos::View<scalar_t *, device_t> kokkos_wgts;
184 wgt = Kokkos::subview(kokkos_wgts_2d, Kokkos::ALL, idx).data();
199 wgt = Kokkos::View<scalar_t **, device_t>(
201 auto host_wgt = Kokkos::create_mirror_view(wgt);
207 for(
size_t n = 0; n < this->
getLocalNumIDs() * stride; n += stride) {
208 host_wgt(i++,j) = ptr_wgts[n];
211 Kokkos::deep_copy(wgt, host_wgt);
284 template <
typename Adapter>
298 const Teuchos::Comm<int> &comm)
const;
302 template <
typename User>
308 using host_t =
typename Kokkos::HostSpace::memory_space;
316 int coordDim)
const = 0;
328 template <
typename User>
331 template <
typename User,
typename UserCoord=User>
339 template <
typename User>
341 const char *fileprefix,
342 const Teuchos::Comm<int> &comm
345 int np = comm.getSize();
346 int me = comm.getRank();
348 size_t nLocalIDs = this->getLocalNumIDs();
355 std::string filenamestr = fileprefix;
356 filenamestr = filenamestr +
".graph";
357 const char *filename = filenamestr.c_str();
360 Teuchos::reduceAll(comm, Teuchos::REDUCE_SUM, 1, &nLocalIDs, &nGlobalIDs);
362 int nWgts = this->getNumWeightsPerID();
364 for (
int p = 0; p < np; p++) {
373 fp.open(filename, std::ios::out);
376 fp << nGlobalIDs <<
" " << 0 <<
" "
377 << (nWgts ?
"010" :
"000") <<
" "
378 << (nWgts > 1 ? std::to_string(nWgts) :
" ") << std::endl;
382 fp.open(filename, std::ios::app);
389 int *strides =
new int[nWgts];
390 for (
int n = 0; n < nWgts; n++)
391 getWeightsView(wgts[n], strides[n], n);
394 for (
size_t i = 0; i < nLocalIDs; i++) {
395 for (
int n = 0; n < nWgts; n++)
396 fp << wgts[n][i*strides[n]] <<
" ";
413 std::string filenamestr = fileprefix;
414 filenamestr = filenamestr +
".assign";
415 const char *filename = filenamestr.c_str();
417 for (
int p = 0; p < np; p++) {
426 fp.open(filename, std::ios::out);
430 fp.open(filename, std::ios::app);
434 this->getPartsView(parts);
436 for (
size_t i = 0; i < nLocalIDs; i++) {
437 fp << (parts != NULL ? parts[i] : me) <<
"\n";
Kokkos::View< const scalar_t *, device_t > ConstWeightsDeviceView1D
virtual int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
virtual VectorAdapter< UserCoord > * getCoordinateInput() const =0
virtual void getPartsDeviceView(Kokkos::View< part_t *, device_t > &inputPart) const
virtual void getIDsView(const gno_t *&ids) const
Provide a pointer to this process' identifiers.
typename InputTraits< UserCoord >::scalar_t scalar_t
typename Kokkos::HostSpace::memory_space host_t
Kokkos::View< scalar_t *, device_t > WeightsDeviceView1D
Kokkos::View< scalar_t **, Kokkos::LayoutLeft, device_t > CoordsDeviceView
virtual void getIDsDeviceView(ConstIdsDeviceView &deviceIds) const
Provide a Kokkos view (Device side) to this process' identifiers.
#define Z2_THROW_NOT_IMPLEMENTED
virtual void setCoordinateInput(VectorAdapter< UserCoord > *coordData)=0
typename node_t::device_type device_t
typename ScalarsDeviceView::HostMirror ScalarsHostView
Defines the PartitioningSolution class.
typename InputTraits< UserCoord >::part_t part_t
Kokkos::View< const gno_t *, device_t > ConstIdsDeviceView
typename ConstScalarsDeviceView::HostMirror ConstScalarsHostView
virtual void getWeightsDeviceView(WeightsDeviceView1D &deviceWgts, int idx=0) const
Provide a Kokkos view (Device side) of the weights.
virtual void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const
Provide pointer to a weight array with stride.
virtual void getIDsKokkosView(ConstIdsDeviceView &ids) const
Provide a Kokkos view to this process' identifiers.
typename IdsDeviceView::HostMirror IdsHostView
typename WeightsDeviceView::HostMirror WeightsHostView
Kokkos::View< const scalar_t *, device_t > ConstScalarsDeviceView
typename InputTraits< UserCoord >::node_t node_t
typename CoordsDeviceView::HostMirror CoordsHostView
virtual void getWeightsKokkosView(Kokkos::View< scalar_t **, device_t > &wgt) const
Provide kokkos view of weights.
virtual ~BaseAdapterRoot()=default
A PartitioningSolution is a solution to a partitioning problem.
virtual void getPartsView(const part_t *&inputPart) const
Provide pointer to an array containing the input part assignment for each ID. The input part informat...
typename ConstOffsetsDeviceView::HostMirror ConstOffsetsHostView
typename InputTraits< UserCoord >::gno_t gno_t
typename ConstIdsDeviceView::HostMirror ConstIdsHostView
void generateWeightFileOnly(const char *fileprefix, const Teuchos::Comm< int > &comm) const
BaseAdapterType
An enum to identify general types of adapters.
identifier data, just a list of IDs
VectorAdapter defines the interface for vector input.
typename ConstWeightsDeviceView1D::HostMirror ConstWeightsHostView1D
BaseAdapter defines methods required by all Adapters.
Kokkos::View< gno_t *, device_t > IdsDeviceView
virtual void getPartsHostView(Kokkos::View< part_t *, host_t > &inputPart) const
Kokkos::View< offset_t *, device_t > OffsetsDeviceView
typename InputTraits< UserCoord >::offset_t offset_t
typename WeightsDeviceView1D::HostMirror WeightsHostView1D
virtual void getWeightsHostView(WeightsHostView &hostWgts) const
Provide a Kokkos view (Host side) of the weights.
void applyPartitioningSolution(const User &in, User *&out, const PartitioningSolution< Adapter > &solution) const
Apply a PartitioningSolution to an input.
virtual size_t getLocalNumIDs() const =0
Returns the number of objects on this process.
typename ConstWeightsDeviceView::HostMirror ConstWeightsHostView
virtual void getCoordinatesHostView(CoordsHostView &) const
Gathering definitions used in software development.
virtual void getCoordinatesDeviceView(CoordsDeviceView &elements) const
Kokkos::View< const scalar_t **, device_t > ConstWeightsDeviceView
Kokkos::View< scalar_t **, device_t > WeightsDeviceView
typename OffsetsDeviceView::HostMirror OffsetsHostView
Kokkos::View< scalar_t *, device_t > ScalarsDeviceView
virtual void getCoordinatesKokkosView(CoordsDeviceView &elements) const =0
virtual void getWeightsHostView(WeightsHostView1D &hostWgts, int idx=0) const
Provide a Kokkos view (Host side) of the weights.
virtual void getWeightsDeviceView(WeightsDeviceView &deviceWgts) const
Provide a Kokkos view (Device side) of the weights.
Kokkos::View< const offset_t *, device_t > ConstOffsetsDeviceView
typename InputTraits< UserCoord >::lno_t lno_t
virtual void getCoordinatesView(const scalar_t *&coords, int &stride, int coordDim) const =0
virtual enum BaseAdapterType adapterType() const =0
Returns the type of adapter.
virtual void getIDsHostView(ConstIdsHostView &hostIds) const
Provide a Kokkos view (Host side) to this process' identifiers.