10#ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
11#define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
19#ifdef HAVE_ZOLTAN2_HYPERGRAPH
25#include <zoltan_cpp.h>
40template <
typename Adapter>
42 const Adapter *adp =
static_cast<Adapter *
>(data);
44 return int(adp->getLocalNumIDs());
49template <
typename Adapter>
51 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
52 int wdim,
float *wgts,
int *ierr)
54 const Adapter *adp =
static_cast<Adapter *
>(data);
55 typedef typename Adapter::gno_t
gno_t;
56 typedef typename Adapter::lno_t
lno_t;
59 size_t mynObj = adp->getLocalNumIDs();
61 const gno_t *myids = NULL;
62 adp->getIDsView(myids);
63 for (
size_t i = 0; i < mynObj; i++) {
64 ZOLTAN_ID_PTR idPtr = &(gids[i*nGidEnt]);
66 idPtr = &(lids[i*nLidEnt]);
71 int mywdim = adp->getNumWeightsPerID();
72 for (
int w = 0; w < wdim; w++) {
75 const typename Adapter::scalar_t *mywgts;
77 adp->getWeightsView(mywgts, mystride, w);
78 for (
size_t i = 0; i < mynObj; i++)
79 wgts[i*wdim+w] =
float(mywgts[i*mystride]);
83 for (
size_t i = 0; i < mynObj; i++)
92template <
typename Adapter>
93static void zoltanParts(
void *data,
int ,
int nLidEnt,
int nObj,
94 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
95 int *parts,
int *ierr)
97 typedef typename Adapter::lno_t
lno_t;
98 const Adapter *adp =
static_cast<Adapter *
>(data);
100 const typename Adapter::part_t *myparts;
101 adp->getPartsView(myparts);
103 for (
int i = 0; i < nObj; i++) {
106 parts[i] = int(myparts[lidx]);
112template <
typename Adapter>
115 const Adapter *adp =
static_cast<Adapter *
>(data);
117 return adp->getDimension();
122template <
typename Adapter>
123static void zoltanGeom(
void *data,
int ,
int nLidEnt,
int nObj,
124 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
125 int nDim,
double *coords,
int *ierr)
127 typedef typename Adapter::lno_t
lno_t;
128 const Adapter *adp =
static_cast<Adapter *
>(data);
131 for (
int d = 0; d < nDim; d++) {
132 const typename Adapter::scalar_t *mycoords;
134 adp->getCoordinatesView(mycoords, mystride, d);
135 for (
int i = 0; i < nObj; i++) {
138 coords[i*nDim+d] = double(mycoords[lidx*mystride]);
152template <
typename Adapter>
154 int *nLists,
int *nPins,
155 int *format,
int *ierr
159 const Adapter *adp =
static_cast<Adapter *
>(data);
162 *nLists = Teuchos::as<int>(adp->getLocalNumVertices());
163 *nPins = Teuchos::as<int>(adp->getLocalNumEdges()+adp->getLocalNumVertices());
165 *format = ZOLTAN_COMPRESSED_EDGE;
170template <
typename Adapter>
173 ZOLTAN_ID_PTR listIds,
int *listIdx,
174 ZOLTAN_ID_PTR pinIds,
int *ierr
178 typedef typename Adapter::gno_t
gno_t;
179 typedef typename Adapter::offset_t offset_t;
180 typedef typename Adapter::user_t
user_t;
181 typedef typename Adapter::userCoord_t userCoord_t;
189 const offset_t *offsets;
195 catch (std::exception &) {
196 *ierr = ZOLTAN_FATAL;
199 if (*ierr == ZOLTAN_OK) {
201 for (
int i=0; i < nLists; i++) {
202 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
204 listIdx[i] = Teuchos::as<int>(offsets[i]+i);
206 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
208 for (
int i=0; i < nLists; i++) {
209 ZOLTAN_ID_PTR idPtr = &(pinIds[pinCnt*nGidEnt]);
212 for (offset_t j = offsets[i]; j < offsets[i+1]; j++) {
213 idPtr = &(pinIds[pinCnt*nGidEnt]);
223template <
typename Adapter>
231 typedef typename Adapter::user_t
user_t;
232 typedef typename Adapter::userCoord_t userCoord_t;
241template <
typename Adapter>
248 ZOLTAN_ID_PTR edgeGids,
249 ZOLTAN_ID_PTR edgeLids,
256 typedef typename Adapter::gno_t
gno_t;
257 typedef typename Adapter::offset_t offset_t;
258 typedef typename Adapter::scalar_t scalar_t;
259 typedef typename Adapter::user_t
user_t;
260 typedef typename Adapter::userCoord_t userCoord_t;
268 const offset_t *offsets;
269 const scalar_t *ewgts;
276 catch (std::exception &) {
277 *ierr = ZOLTAN_FATAL;
279 if (ierr == ZOLTAN_OK) {
280 for (
int i = 0; i < nEdges; i++) {
282 for (offset_t j = offsets[i]; j < offsets[i+1]; j++)
283 sum += ewgts[j*stride];
284 ZOLTAN_ID_PTR idPtr = &(edgeGids[i*nGidEnt]);
287 idPtr = &(edgeLids[i*nLidEnt]);
304template <
typename Adapter>
306 int *nLists,
int *nPins,
307 int *format,
int *ierr
311 typedef typename Adapter::user_t
user_t;
319 *format = ZOLTAN_COMPRESSED_VERTEX;
323 *format = ZOLTAN_COMPRESSED_EDGE;
327 *format = ZOLTAN_COMPRESSED_EDGE;
331 *format = ZOLTAN_COMPRESSED_VERTEX;
337 std::cout <<
"For hypergraph partitioning, "
338 <<
"CRSView or CCSView is needed in MatrixAdapter" << std::endl;
339 *ierr = ZOLTAN_FATAL;
345template <
typename Adapter>
347 int nPins,
int format,
348 ZOLTAN_ID_PTR listIds,
int *listIdx,
349 ZOLTAN_ID_PTR pinIds,
int *ierr
353 typedef typename Adapter::gno_t
gno_t;
355 typedef typename Adapter::offset_t offset_t;
356 typedef typename Adapter::user_t
user_t;
360 ArrayRCP<const gno_t> pIds;
361 ArrayRCP<const offset_t> offsets;
369 catch (std::exception &) {
370 *ierr = ZOLTAN_FATAL;
378 catch (std::exception &) {
379 *ierr = ZOLTAN_FATAL;
384 *ierr = ZOLTAN_FATAL;
387 if (*ierr == ZOLTAN_OK) {
389 for (
int i=0; i < nLists; i++) {
390 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
392 listIdx[i] = Teuchos::as<int>(offsets[i]);
394 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
395 for (
int i=0; i < nPins; i++) {
396 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
416template <
typename Adapter>
418 int *format,
int *ierr
422 typedef typename Adapter::user_t
user_t;
430 *format = ZOLTAN_COMPRESSED_VERTEX;
438 *format = ZOLTAN_COMPRESSED_EDGE;
441 std::cout <<
"For hypergraph partitioning, need first adjacencies "
442 <<
"(availAdjs, getLocalNumAdjs, getAdjsView) "
443 <<
"in MeshAdapter." << std::endl;
446 *format = -1*ZOLTAN_COMPRESSED_VERTEX;
447 *ierr = ZOLTAN_FATAL;
453template <
typename Adapter>
455 void *data,
int nGidEnt,
int nLists,
int nPins,
456 int format, ZOLTAN_ID_PTR listIds,
457 int *listIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
461 typedef typename Adapter::gno_t
gno_t;
463 typedef typename Adapter::user_t
user_t;
464 typedef typename Adapter::offset_t offset_t;
469 if (format == ZOLTAN_COMPRESSED_VERTEX)
474 else if (format == ZOLTAN_COMPRESSED_EDGE)
480 *ierr = ZOLTAN_FATAL;
483 if (*ierr == ZOLTAN_OK) {
490 catch (std::exception &) {
491 *ierr = ZOLTAN_FATAL;
495 const offset_t* offsets;
498 madp->
getAdjsView(listType, pinType, offsets, adjIds);
500 catch (std::exception &) {
501 *ierr = ZOLTAN_FATAL;
505 for (
int i=0; i < nLists; i++) {
506 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
508 listIdx[i] = Teuchos::as<int>(offsets[i]);
510 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
511 for (
int i=0; i < nPins; i++) {
512 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
521#ifdef HAVE_ZOLTAN2_HYPERGRAPH
525template <
typename Adapter>
526static int zoltanHGNumObj_withModel(
void *data,
int *ierr) {
527 const HyperGraphModel<Adapter>* mdl =
528 static_cast<HyperGraphModel<Adapter>*
>(data);
530 return int(mdl->getLocalNumOwnedVertices());
535template <
typename Adapter>
536static void zoltanHGObjList_withModel(
void *data,
int nGidEnt,
int nLidEnt,
537 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
538 int wdim,
float *wgts,
int *ierr)
540 const HyperGraphModel<Adapter>* mdl =
541 static_cast<HyperGraphModel<Adapter>*
>(data);
542 typedef typename Adapter::gno_t
gno_t;
543 typedef typename Adapter::lno_t
lno_t;
544 typedef typename Adapter::scalar_t scalar_t;
545 typedef StridedData<lno_t, scalar_t> input_t;
548 ArrayView<const gno_t> Ids;
549 ArrayView<input_t> model_wgts;
550 size_t num_verts = mdl->getVertexList(Ids,model_wgts);
551 ArrayView<bool> isOwner;
552 mdl->getOwnedList(isOwner);
554 for (
size_t i=0;i<num_verts;i++) {
556 ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
558 idPtr = &(lids[j*nLidEnt]);
564 int mywdim = mdl->getNumWeightsPerVertex();
565 for (
int w = 0; w < wdim; w++) {
568 for (
size_t i = 0; i < num_verts; i++) {
570 wgts[j*wdim+w] = float(model_wgts[w][i]);
577 for (
size_t i = 0; i < num_verts; i++) {
590template <
typename Adapter>
591static void zoltanHGSizeCS_withModel(
void *data,
int *nEdges,
int *nPins,
592 int *format,
int *ierr
596 const HyperGraphModel<Adapter>* mdl =
597 static_cast<HyperGraphModel<Adapter>*
>(data);
598 *nEdges = mdl->getLocalNumHyperEdges();
599 *nPins = mdl->getLocalNumPins();
601 *format = ZOLTAN_COMPRESSED_EDGE;
603 *format = ZOLTAN_COMPRESSED_VERTEX;
608template <
typename Adapter>
609static void zoltanHGCS_withModel(
void *data,
int nGidEnt,
int nEdges,
int nPins,
610 int format, ZOLTAN_ID_PTR edgeIds,
611 int *edgeIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
615 const HyperGraphModel<Adapter>* mdl =
616 static_cast<HyperGraphModel<Adapter>*
>(data);
617 typedef typename Adapter::gno_t
gno_t;
618 typedef typename Adapter::lno_t
lno_t;
619 typedef typename Adapter::offset_t offset_t;
620 typedef typename Adapter::scalar_t scalar_t;
621 typedef StridedData<lno_t, scalar_t> input_t;
623 ArrayView<const gno_t> Ids;
624 ArrayView<input_t> wgts;
625 mdl->getEdgeList(Ids,wgts);
626 ArrayView<const gno_t> pinIds_;
627 ArrayView<const offset_t> offsets;
628 ArrayView<input_t> pin_wgts;
629 mdl->getPinList(pinIds_,offsets,pin_wgts);
630 for (
int i=0;i<nEdges;i++) {
631 ZOLTAN_ID_PTR idPtr = &(edgeIds[i*nGidEnt]);
633 edgeIdx[i] = Teuchos::as<int>(offsets[i]);
636 for (
int i=0;i<nPins;i++) {
637 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Defines the GraphAdapter interface.
Defines the HyperGraphModel interface.
Defines the IdentifierAdapter interface.
Defines the MatrixAdapter interface.
Defines the MeshAdapter interface.
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t,...
A gathering of useful namespace methods.
Defines the VectorAdapter interface.
GraphAdapter defines the interface for graph-based user data.
virtual size_t getLocalNumVertices() const =0
Returns the number of vertices on this process.
virtual void getEdgeWeightsView(const scalar_t *&weights, int &stride, int=0) const
Provide a pointer to the edge weights, if any.
virtual void getEdgesView(const offset_t *&offsets, const gno_t *&adjIds) const =0
Gets adjacency lists for all vertices in a compressed sparse row (CSR) format.
void getIDsView(const gno_t *&Ids) const override
Provide a pointer to this process' identifiers.
MatrixAdapter defines the adapter interface for matrices.
virtual size_t getLocalNumEntries() const =0
Returns the number of nonzeros on this process.
virtual void getColumnIDsView(const gno_t *&colIds) const
Sets pointer to this process' columns' global IDs.
virtual void getCCSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &rowIds) const
Sets pointers to this process' matrix entries using compressed sparse column (CCS) format....
virtual size_t getLocalNumColumns() const =0
Returns the number of columns on this process.
virtual bool CCSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse column (CCS)...
virtual void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
virtual bool CRSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse row (CRS) fo...
enum MatrixEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW,...
virtual size_t getLocalNumRows() const =0
Returns the number of rows on this process.
virtual void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) const
Sets pointers to this process' matrix entries using compressed sparse row (CRS) format....
MeshAdapter defines the interface for mesh input.
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
enum MeshEntityType getAdjacencyEntityType() const
Returns the entity that describes adjacencies between the entities to be partitioned,...
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType.
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const
Returns the number of first adjacencies on this process.
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process' identifiers.
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process' mesh first adjacencies.
enum MeshEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc.
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
static void zoltanHGEdgeWts_withGraphAdapter(void *data, int nGidEnt, int nLidEnt, int nEdges, int, ZOLTAN_ID_PTR edgeGids, ZOLTAN_ID_PTR edgeLids, float *edgeWgts, int *ierr)
static void zoltanObjList(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
static void zoltanHGCS_withMeshAdapter(void *data, int nGidEnt, int nLists, int nPins, int format, ZOLTAN_ID_PTR listIds, int *listIdx, ZOLTAN_ID_PTR pinIds, int *ierr)
static void zoltanHGSizeCS_withMatrixAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
static void zoltanHGSizeCS_withGraphAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
static int zoltanNumObj(void *data, int *ierr)
static void zoltanHGCS_withGraphAdapter(void *data, int nGidEnt, int nLists, int, int, ZOLTAN_ID_PTR listIds, int *listIdx, ZOLTAN_ID_PTR pinIds, int *ierr)
static int zoltanNumGeom(void *data, int *ierr)
static void zoltanParts(void *data, int, int nLidEnt, int nObj, ZOLTAN_ID_PTR, ZOLTAN_ID_PTR lids, int *parts, int *ierr)
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
static void zoltanHGSizeCS_withMeshAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
static void zoltanGeom(void *data, int, int nLidEnt, int nObj, ZOLTAN_ID_PTR, ZOLTAN_ID_PTR lids, int nDim, double *coords, int *ierr)
static void zoltanHGCS_withMatrixAdapter(void *data, int nGidEnt, int nLists, int nPins, int format, ZOLTAN_ID_PTR listIds, int *listIdx, ZOLTAN_ID_PTR pinIds, int *ierr)
static void zoltanHGSizeEdgeWts_withGraphAdapter(void *data, int *nEdges, int *ierr)
static void ASSIGN(first_t &a, second_t b)