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);
102 size_t numIds = adp->getLocalNumIDs();
105 for (
int i = 0; i < nObj; i++) {
107 if (lids && (
static_cast<size_t>(i*nLidEnt)<numIds)) {
109 parts[i] = int(myparts[lidx]);
116template <
typename Adapter>
119 const Adapter *adp =
static_cast<Adapter *
>(data);
121 return adp->getDimension();
126template <
typename Adapter>
127static void zoltanGeom(
void *data,
int ,
int nLidEnt,
int nObj,
128 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
129 int nDim,
double *coords,
int *ierr)
131 typedef typename Adapter::lno_t
lno_t;
132 const Adapter *adp =
static_cast<Adapter *
>(data);
134 size_t numIds = adp->getLocalNumIDs();
136 for (
int d = 0; d < nDim; d++) {
137 const typename Adapter::scalar_t *mycoords;
139 adp->getCoordinatesView(mycoords, mystride, d);
140 for (
int i = 0; i < nObj; i++) {
142 if (lids && (
static_cast<size_t>(i*nLidEnt)<numIds)) {
144 coords[i*nDim+d] = double(mycoords[lidx*mystride]);
159template <
typename Adapter>
161 int *nLists,
int *nPins,
162 int *format,
int *ierr
166 const Adapter *adp =
static_cast<Adapter *
>(data);
169 *nLists = Teuchos::as<int>(adp->getLocalNumVertices());
170 *nPins = Teuchos::as<int>(adp->getLocalNumEdges()+adp->getLocalNumVertices());
172 *format = ZOLTAN_COMPRESSED_EDGE;
177template <
typename Adapter>
180 ZOLTAN_ID_PTR listIds,
int *listIdx,
181 ZOLTAN_ID_PTR pinIds,
int *ierr
185 typedef typename Adapter::gno_t
gno_t;
186 typedef typename Adapter::offset_t
offset_t;
187 typedef typename Adapter::user_t
user_t;
188 typedef typename Adapter::userCoord_t userCoord_t;
202 catch (std::exception &) {
203 *ierr = ZOLTAN_FATAL;
206 if (*ierr == ZOLTAN_OK) {
208 for (
int i=0; i < nLists; i++) {
209 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
211 listIdx[i] = Teuchos::as<int>(offsets[i]+i);
213 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
215 for (
int i=0; i < nLists; i++) {
216 ZOLTAN_ID_PTR idPtr = &(pinIds[pinCnt*nGidEnt]);
219 for (
offset_t j = offsets[i]; j < offsets[i+1]; j++) {
220 idPtr = &(pinIds[pinCnt*nGidEnt]);
230template <
typename Adapter>
238 typedef typename Adapter::user_t
user_t;
239 typedef typename Adapter::userCoord_t userCoord_t;
248template <
typename Adapter>
255 ZOLTAN_ID_PTR edgeGids,
256 ZOLTAN_ID_PTR edgeLids,
263 typedef typename Adapter::gno_t
gno_t;
264 typedef typename Adapter::offset_t
offset_t;
265 typedef typename Adapter::scalar_t
scalar_t;
266 typedef typename Adapter::user_t
user_t;
267 typedef typename Adapter::userCoord_t userCoord_t;
283 catch (std::exception &) {
284 *ierr = ZOLTAN_FATAL;
286 if (ierr == ZOLTAN_OK) {
287 for (
int i = 0; i < nEdges; i++) {
289 for (
offset_t j = offsets[i]; j < offsets[i+1]; j++)
290 sum += ewgts[j*stride];
291 ZOLTAN_ID_PTR idPtr = &(edgeGids[i*nGidEnt]);
294 idPtr = &(edgeLids[i*nLidEnt]);
311template <
typename Adapter>
313 int *nLists,
int *nPins,
314 int *format,
int *ierr
318 typedef typename Adapter::user_t
user_t;
326 *format = ZOLTAN_COMPRESSED_VERTEX;
330 *format = ZOLTAN_COMPRESSED_EDGE;
334 *format = ZOLTAN_COMPRESSED_EDGE;
338 *format = ZOLTAN_COMPRESSED_VERTEX;
344 std::cout <<
"For hypergraph partitioning, "
345 <<
"CRSView or CCSView is needed in MatrixAdapter" << std::endl;
346 *ierr = ZOLTAN_FATAL;
352template <
typename Adapter>
354 int nPins,
int format,
355 ZOLTAN_ID_PTR listIds,
int *listIdx,
356 ZOLTAN_ID_PTR pinIds,
int *ierr
360 typedef typename Adapter::gno_t
gno_t;
362 typedef typename Adapter::offset_t
offset_t;
363 typedef typename Adapter::user_t
user_t;
367 ArrayRCP<const gno_t> pIds;
368 ArrayRCP<const offset_t> offsets;
376 catch (std::exception &) {
377 *ierr = ZOLTAN_FATAL;
385 catch (std::exception &) {
386 *ierr = ZOLTAN_FATAL;
391 *ierr = ZOLTAN_FATAL;
394 if (*ierr == ZOLTAN_OK) {
396 for (
int i=0; i < nLists; i++) {
397 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
399 listIdx[i] = Teuchos::as<int>(offsets[i]);
401 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
402 for (
int i=0; i < nPins; i++) {
403 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
423template <
typename Adapter>
425 int *format,
int *ierr
429 typedef typename Adapter::user_t
user_t;
437 *format = ZOLTAN_COMPRESSED_VERTEX;
445 *format = ZOLTAN_COMPRESSED_EDGE;
448 std::cout <<
"For hypergraph partitioning, need first adjacencies "
449 <<
"(availAdjs, getLocalNumAdjs, getAdjsView) "
450 <<
"in MeshAdapter." << std::endl;
453 *format = -1*ZOLTAN_COMPRESSED_VERTEX;
454 *ierr = ZOLTAN_FATAL;
460template <
typename Adapter>
462 void *data,
int nGidEnt,
int nLists,
int nPins,
463 int format, ZOLTAN_ID_PTR listIds,
464 int *listIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
468 typedef typename Adapter::gno_t
gno_t;
470 typedef typename Adapter::user_t
user_t;
471 typedef typename Adapter::offset_t
offset_t;
476 if (format == ZOLTAN_COMPRESSED_VERTEX)
481 else if (format == ZOLTAN_COMPRESSED_EDGE)
487 *ierr = ZOLTAN_FATAL;
490 if (*ierr == ZOLTAN_OK) {
497 catch (std::exception &) {
498 *ierr = ZOLTAN_FATAL;
505 madp->
getAdjsView(listType, pinType, offsets, adjIds);
507 catch (std::exception &) {
508 *ierr = ZOLTAN_FATAL;
512 for (
int i=0; i < nLists; i++) {
513 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
515 listIdx[i] = Teuchos::as<int>(offsets[i]);
517 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
518 for (
int i=0; i < nPins; i++) {
519 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
528#ifdef HAVE_ZOLTAN2_HYPERGRAPH
532template <
typename Adapter>
533static int zoltanHGNumObj_withModel(
void *data,
int *ierr) {
534 const HyperGraphModel<Adapter>* mdl =
535 static_cast<HyperGraphModel<Adapter>*
>(data);
537 return int(mdl->getLocalNumOwnedVertices());
542template <
typename Adapter>
543static void zoltanHGObjList_withModel(
void *data,
int nGidEnt,
int nLidEnt,
544 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
545 int wdim,
float *wgts,
int *ierr)
549 typedef typename Adapter::gno_t
gno_t;
550 typedef typename Adapter::lno_t
lno_t;
551 typedef typename Adapter::scalar_t
scalar_t;
555 ArrayView<const gno_t> Ids;
556 ArrayView<input_t> model_wgts;
557 size_t num_verts = mdl->getVertexList(Ids,model_wgts);
558 ArrayView<bool> isOwner;
559 mdl->getOwnedList(isOwner);
561 for (
size_t i=0;i<num_verts;i++) {
563 ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
565 idPtr = &(lids[j*nLidEnt]);
571 int mywdim = mdl->getNumWeightsPerVertex();
572 for (
int w = 0; w < wdim; w++) {
575 for (
size_t i = 0; i < num_verts; i++) {
577 wgts[j*wdim+w] = float(model_wgts[w][i]);
584 for (
size_t i = 0; i < num_verts; i++) {
597template <
typename Adapter>
598static void zoltanHGSizeCS_withModel(
void *data,
int *nEdges,
int *nPins,
599 int *format,
int *ierr
606 *nPins = mdl->getLocalNumPins();
608 *format = ZOLTAN_COMPRESSED_EDGE;
610 *format = ZOLTAN_COMPRESSED_VERTEX;
615template <
typename Adapter>
616static void zoltanHGCS_withModel(
void *data,
int nGidEnt,
int nEdges,
int nPins,
617 int format, ZOLTAN_ID_PTR edgeIds,
618 int *edgeIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
624 typedef typename Adapter::gno_t
gno_t;
625 typedef typename Adapter::lno_t
lno_t;
626 typedef typename Adapter::offset_t
offset_t;
627 typedef typename Adapter::scalar_t
scalar_t;
630 ArrayView<const gno_t> Ids;
631 ArrayView<input_t> wgts;
632 mdl->getEdgeList(Ids,wgts);
633 ArrayView<const gno_t> pinIds_;
634 ArrayView<const offset_t> offsets;
635 ArrayView<input_t> pin_wgts;
636 mdl->getPinList(pinIds_,offsets,pin_wgts);
637 for (
int i=0;i<nEdges;i++) {
638 ZOLTAN_ID_PTR idPtr = &(edgeIds[i*nGidEnt]);
640 edgeIdx[i] = Teuchos::as<int>(offsets[i]);
643 for (
int i=0;i<nPins;i++) {
644 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.
HyperGraphModel defines the interface required for hyper graph models.
size_t getLocalNumHyperEdges() const
Returns the number of hyper edges on this process. These are all hyper edges that have an adjacency t...
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.
The StridedData class manages lists of weights or coordinates.
map_t::local_ordinal_type lno_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)