45#ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
46#define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
58#include <zoltan_cpp.h>
73template <
typename Adapter>
75 const Adapter *adp =
static_cast<Adapter *
>(data);
77 return int(adp->getLocalNumIDs());
82template <
typename Adapter>
84 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
85 int wdim,
float *wgts,
int *ierr)
87 const Adapter *adp =
static_cast<Adapter *
>(data);
88 typedef typename Adapter::gno_t
gno_t;
89 typedef typename Adapter::lno_t
lno_t;
92 size_t mynObj = adp->getLocalNumIDs();
94 const gno_t *myids = NULL;
95 adp->getIDsView(myids);
96 for (
size_t i = 0; i < mynObj; i++) {
97 ZOLTAN_ID_PTR idPtr = &(gids[i*nGidEnt]);
99 idPtr = &(lids[i*nLidEnt]);
104 int mywdim = adp->getNumWeightsPerID();
105 for (
int w = 0; w < wdim; w++) {
108 const typename Adapter::scalar_t *mywgts;
110 adp->getWeightsView(mywgts, mystride, w);
111 for (
size_t i = 0; i < mynObj; i++)
112 wgts[i*wdim+w] =
float(mywgts[i*mystride]);
116 for (
size_t i = 0; i < mynObj; i++)
125template <
typename Adapter>
127 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
128 int *parts,
int *ierr)
130 typedef typename Adapter::lno_t
lno_t;
131 const Adapter *adp =
static_cast<Adapter *
>(data);
133 const typename Adapter::part_t *myparts;
134 adp->getPartsView(myparts);
136 for (
int i = 0; i < nObj; i++) {
139 parts[i] = int(myparts[lidx]);
145template <
typename Adapter>
148 const Adapter *adp =
static_cast<Adapter *
>(data);
150 return adp->getDimension();
155template <
typename Adapter>
156static void zoltanGeom(
void *data,
int ,
int nLidEnt,
int nObj,
157 ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
158 int nDim,
double *coords,
int *ierr)
160 typedef typename Adapter::lno_t
lno_t;
161 const Adapter *adp =
static_cast<Adapter *
>(data);
164 for (
int d = 0; d < nDim; d++) {
165 const typename Adapter::scalar_t *mycoords;
167 adp->getCoordinatesView(mycoords, mystride, d);
168 for (
int i = 0; i < nObj; i++) {
171 coords[i*nDim+d] = double(mycoords[lidx*mystride]);
185template <
typename Adapter>
187 int *nLists,
int *nPins,
188 int *format,
int *ierr
192 const Adapter *adp =
static_cast<Adapter *
>(data);
195 *nLists = Teuchos::as<int>(adp->getLocalNumVertices());
196 *nPins = Teuchos::as<int>(adp->getLocalNumEdges()+adp->getLocalNumVertices());
198 *format = ZOLTAN_COMPRESSED_EDGE;
203template <
typename Adapter>
206 ZOLTAN_ID_PTR listIds,
int *listIdx,
207 ZOLTAN_ID_PTR pinIds,
int *ierr
211 typedef typename Adapter::gno_t
gno_t;
212 typedef typename Adapter::offset_t offset_t;
213 typedef typename Adapter::user_t
user_t;
214 typedef typename Adapter::userCoord_t userCoord_t;
222 const offset_t *offsets;
228 catch (std::exception &) {
229 *ierr = ZOLTAN_FATAL;
232 if (*ierr == ZOLTAN_OK) {
234 for (
int i=0; i < nLists; i++) {
235 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
237 listIdx[i] = Teuchos::as<int>(offsets[i]+i);
239 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
241 for (
int i=0; i < nLists; i++) {
242 ZOLTAN_ID_PTR idPtr = &(pinIds[pinCnt*nGidEnt]);
245 for (offset_t j = offsets[i]; j < offsets[i+1]; j++) {
246 idPtr = &(pinIds[pinCnt*nGidEnt]);
256template <
typename Adapter>
264 typedef typename Adapter::user_t
user_t;
265 typedef typename Adapter::userCoord_t userCoord_t;
274template <
typename Adapter>
281 ZOLTAN_ID_PTR edgeGids,
282 ZOLTAN_ID_PTR edgeLids,
289 typedef typename Adapter::gno_t
gno_t;
290 typedef typename Adapter::offset_t offset_t;
291 typedef typename Adapter::scalar_t scalar_t;
292 typedef typename Adapter::user_t
user_t;
293 typedef typename Adapter::userCoord_t userCoord_t;
301 const offset_t *offsets;
302 const scalar_t *ewgts;
309 catch (std::exception &) {
310 *ierr = ZOLTAN_FATAL;
312 if (ierr == ZOLTAN_OK) {
313 for (
int i = 0; i < nEdges; i++) {
315 for (offset_t j = offsets[i]; j < offsets[i+1]; j++)
316 sum += ewgts[j*stride];
317 ZOLTAN_ID_PTR idPtr = &(edgeGids[i*nGidEnt]);
320 idPtr = &(edgeLids[i*nLidEnt]);
337template <
typename Adapter>
339 int *nLists,
int *nPins,
340 int *format,
int *ierr
344 typedef typename Adapter::user_t
user_t;
352 *format = ZOLTAN_COMPRESSED_VERTEX;
356 *format = ZOLTAN_COMPRESSED_EDGE;
360 *format = ZOLTAN_COMPRESSED_EDGE;
364 *format = ZOLTAN_COMPRESSED_VERTEX;
370 std::cout <<
"For hypergraph partitioning, "
371 <<
"CRSView or CCSView is needed in MatrixAdapter" << std::endl;
372 *ierr = ZOLTAN_FATAL;
378template <
typename Adapter>
380 int nPins,
int format,
381 ZOLTAN_ID_PTR listIds,
int *listIdx,
382 ZOLTAN_ID_PTR pinIds,
int *ierr
386 typedef typename Adapter::gno_t
gno_t;
388 typedef typename Adapter::offset_t offset_t;
389 typedef typename Adapter::user_t
user_t;
393 ArrayRCP<const gno_t> pIds;
394 ArrayRCP<const offset_t> offsets;
402 catch (std::exception &) {
403 *ierr = ZOLTAN_FATAL;
411 catch (std::exception &) {
412 *ierr = ZOLTAN_FATAL;
417 *ierr = ZOLTAN_FATAL;
420 if (*ierr == ZOLTAN_OK) {
422 for (
int i=0; i < nLists; i++) {
423 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
425 listIdx[i] = Teuchos::as<int>(offsets[i]);
427 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
428 for (
int i=0; i < nPins; i++) {
429 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
449template <
typename Adapter>
451 int *format,
int *ierr
455 typedef typename Adapter::user_t
user_t;
463 *format = ZOLTAN_COMPRESSED_VERTEX;
471 *format = ZOLTAN_COMPRESSED_EDGE;
474 std::cout <<
"For hypergraph partitioning, need first adjacencies "
475 <<
"(availAdjs, getLocalNumAdjs, getAdjsView) "
476 <<
"in MeshAdapter." << std::endl;
479 *format = -1*ZOLTAN_COMPRESSED_VERTEX;
480 *ierr = ZOLTAN_FATAL;
486template <
typename Adapter>
488 void *data,
int nGidEnt,
int nLists,
int nPins,
489 int format, ZOLTAN_ID_PTR listIds,
490 int *listIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
494 typedef typename Adapter::gno_t
gno_t;
496 typedef typename Adapter::user_t
user_t;
497 typedef typename Adapter::offset_t offset_t;
502 if (format == ZOLTAN_COMPRESSED_VERTEX)
507 else if (format == ZOLTAN_COMPRESSED_EDGE)
513 *ierr = ZOLTAN_FATAL;
516 if (*ierr == ZOLTAN_OK) {
523 catch (std::exception &) {
524 *ierr = ZOLTAN_FATAL;
528 const offset_t* offsets;
531 madp->
getAdjsView(listType, pinType, offsets, adjIds);
533 catch (std::exception &) {
534 *ierr = ZOLTAN_FATAL;
538 for (
int i=0; i < nLists; i++) {
539 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
541 listIdx[i] = Teuchos::as<int>(offsets[i]);
543 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
544 for (
int i=0; i < nPins; i++) {
545 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
557template <
typename Adapter>
567template <
typename Adapter>
569 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
570 int wdim,
float *wgts,
int *ierr)
574 typedef typename Adapter::gno_t
gno_t;
575 typedef typename Adapter::lno_t
lno_t;
576 typedef typename Adapter::scalar_t scalar_t;
580 ArrayView<const gno_t> Ids;
581 ArrayView<input_t> model_wgts;
583 ArrayView<bool> isOwner;
586 for (
size_t i=0;i<num_verts;i++) {
588 ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
590 idPtr = &(lids[j*nLidEnt]);
597 for (
int w = 0; w < wdim; w++) {
600 for (
size_t i = 0; i < num_verts; i++) {
602 wgts[j*wdim+w] = float(model_wgts[w][i]);
609 for (
size_t i = 0; i < num_verts; i++) {
622template <
typename Adapter>
624 int *format,
int *ierr
633 *format = ZOLTAN_COMPRESSED_EDGE;
635 *format = ZOLTAN_COMPRESSED_VERTEX;
640template <
typename Adapter>
642 int format, ZOLTAN_ID_PTR edgeIds,
643 int *edgeIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
649 typedef typename Adapter::gno_t
gno_t;
650 typedef typename Adapter::lno_t
lno_t;
651 typedef typename Adapter::offset_t offset_t;
652 typedef typename Adapter::scalar_t scalar_t;
655 ArrayView<const gno_t> Ids;
656 ArrayView<input_t> wgts;
658 ArrayView<const gno_t> pinIds_;
659 ArrayView<const offset_t> offsets;
660 ArrayView<input_t> pin_wgts;
662 for (
int i=0;i<nEdges;i++) {
663 ZOLTAN_ID_PTR idPtr = &(edgeIds[i*nGidEnt]);
665 edgeIdx[i] = Teuchos::as<int>(offsets[i]);
668 for (
int i=0;i<nPins;i++) {
669 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 getLocalNumPins() const
Returns the local number of pins.
size_t getPinList(ArrayView< const gno_t > &pinIds, ArrayView< const offset_t > &offsets, ArrayView< input_t > &wgts) const
Sets pointers to this process' pins global Ids based on the centric view given by getCentricView()
size_t getOwnedList(ArrayView< bool > &isOwner) const
Sets pointer to the ownership of this processes vertices.
size_t getLocalNumOwnedVertices() const
Returns the number vertices on this process that are owned.
size_t getEdgeList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' hyperedge Ids and their weights.
size_t getVertexList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' vertex Ids and their weights.
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
size_t getLocalNumHyperEdges() const
Returns the number of hyper edges on this process. These are all hyper edges that have an adjacency t...
CentricView getCentricView() const
Returns the centric view of the hypergraph.
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
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
static void zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
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 zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins, int *format, 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 int zoltanHGNumObj_withModel(void *data, int *ierr)
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 zoltanHGCS_withModel(void *data, int nGidEnt, int nEdges, int nPins, int format, ZOLTAN_ID_PTR edgeIds, int *edgeIdx, 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)