14 #ifndef _ZOLTAN2_ALGMETIS_HPP_
15 #define _ZOLTAN2_ALGMETIS_HPP_
21 #ifdef HAVE_ZOLTAN2_METIS
27 template <
typename Adapter>
32 const RCP<const typename Adapter::base_adapter_t> adapter;
33 const RCP<Teuchos::ParameterList> pl;
34 const RCP<const Teuchos::Comm<int> > comm;
35 RCP<const Environment> env;
41 const RCP<const typename Adapter::base_adapter_t> &adapter__,
42 const RCP<Teuchos::ParameterList> &pl__,
43 const RCP<
const Teuchos::Comm<int> > &comm__,
44 RCP<const Environment> &env__,
46 ) : adapter(adapter__), pl(pl__), comm(comm__), env(env__), graphFlags(graphFlags__)
51 throw std::logic_error(
"AlgMetis does not yet support global ordering.");
57 #ifndef HAVE_ZOLTAN2_METIS
59 throw std::runtime_error(
60 "BUILD ERROR: Metis requested but not compiled into Zoltan2.\n"
61 "Please set CMake flag Zoltan2_ENABLE_METIS:BOOL=ON.");
65 typedef typename Adapter::offset_t offset_t;
66 typedef typename Adapter::scalar_t
scalar_t;
72 const size_t nVtx = model->getLocalNumVertices();
73 const size_t nNnz = model->getLocalNumEdges();
74 lno_t *perm = (lno_t *) (solution->getPermutationRCP().getRawPtr());
76 if (nVtx > 0 && nNnz > 0) {
77 ArrayView<const gno_t> edgeIds;
78 ArrayView<const offset_t> offsets;
79 ArrayView<StridedData<lno_t, scalar_t> > wgts;
80 model->getEdgeList(edgeIds, offsets, wgts);
83 using Zoltan2OffsetView =
typename Kokkos::View<offset_t*, Kokkos::HostSpace>;
84 using Zoltan2EdgeView =
typename Kokkos::View<gno_t*, Kokkos::HostSpace>;
85 Zoltan2OffsetView zoltan2_rowptr (const_cast<offset_t*>(offsets.data()), nVtx+1);
86 Zoltan2EdgeView zoltan2_colidx (const_cast<gno_t*>(edgeIds.data()), nNnz);
88 using MetisIdxView =
typename Kokkos::View<idx_t*, Kokkos::HostSpace>;
89 MetisIdxView metis_rowptr;
90 MetisIdxView metis_colidx;
93 KokkosKernels::Impl::symmetrize_graph_symbolic_hashmap<
94 Zoltan2OffsetView, Zoltan2EdgeView, MetisIdxView, MetisIdxView, Kokkos::HostSpace::execution_space>
95 (nVtx, zoltan2_rowptr, zoltan2_colidx, metis_rowptr, metis_colidx);
101 idx_t nnz = metis_rowptr(0);
103 for (idx_t i = 0; i < metis_nVtx; i++) {
104 for (idx_t k = old_nnz; k < metis_rowptr(i+1); k++) {
105 if (metis_colidx(k) != i) {
106 metis_colidx(nnz) = metis_colidx(k);
110 old_nnz = metis_rowptr(i+1);
111 metis_rowptr(i+1) = nnz;
115 idx_t *metis_perm =
new idx_t[nVtx];
116 idx_t *metis_iperm =
new idx_t[nVtx];
119 int info = METIS_NodeND(&metis_nVtx, metis_rowptr.data(), metis_colidx.data(),
120 NULL, NULL, metis_perm, metis_iperm);
121 if (METIS_OK != info) {
122 throw std::runtime_error(std::string(
"METIS_NodeND returned info = " + info));
126 for (
size_t i = 0; i < nVtx; i++)
129 delete [] metis_iperm;
130 delete [] metis_perm;
132 for (
size_t i = 0; i < nVtx; i++)
136 solution->setHavePerm(
true);
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
map_t::global_ordinal_type gno_t
Defines the OrderingSolution class.
AlgMetis(const RCP< const typename Adapter::base_adapter_t > &adapter__, const RCP< Teuchos::ParameterList > &pl__, const RCP< const Teuchos::Comm< int > > &comm__, RCP< const Environment > &env__, const modelFlag_t &graphFlags__)
Adapter::scalar_t scalar_t
Algorithm defines the base class for all algorithms.
map_t::local_ordinal_type lno_t
static void ASSIGN(first_t &a, second_t b)
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
int globalOrder(const RCP< GlobalOrderingSolution< typename Adapter::gno_t > > &)
Ordering method.
GraphModel defines the interface required for graph models.
int localOrder(const RCP< LocalOrderingSolution< typename Adapter::lno_t > > &solution)
Ordering method.
Defines the GraphModel interface.