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;
215 const GraphAdapter<user_t, userCoord_t>* adp =
216 static_cast<GraphAdapter<user_t, userCoord_t>*
>(data);
222 const offset_t *offsets;
225 adp->getIDsView(ids);
226 adp->getEdgesView(offsets, adjIds);
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;
266 const GraphAdapter<user_t, userCoord_t>* adp =
267 static_cast<GraphAdapter<user_t, userCoord_t>*
>(data);
269 *nEdges = Teuchos::as<int>(adp->getLocalNumVertices());
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;
294 const GraphAdapter<user_t, userCoord_t>* adp =
295 static_cast<GraphAdapter<user_t, userCoord_t>*
>(data);
301 const offset_t *offsets;
302 const scalar_t *ewgts;
305 adp->getIDsView(ids);
306 adp->getEdgesView(offsets, adjIds);
307 adp->getEdgeWeightsView(ewgts, stride, 0);
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;
345 const MatrixAdapter<user_t>* madp =
static_cast<MatrixAdapter<user_t>*
>(data);
347 *nPins = madp->getLocalNumEntries();
350 if (etype ==
MATRIX_ROW && madp->CRSViewAvailable()) {
351 *nLists = madp->getLocalNumRows();
352 *format = ZOLTAN_COMPRESSED_VERTEX;
354 else if (etype ==
MATRIX_ROW && madp->CCSViewAvailable()) {
355 *nLists = madp->getLocalNumColumns();
356 *format = ZOLTAN_COMPRESSED_EDGE;
358 else if (etype ==
MATRIX_COLUMN && madp->CRSViewAvailable()) {
359 *nLists = madp->getLocalNumRows();
360 *format = ZOLTAN_COMPRESSED_EDGE;
362 else if (etype ==
MATRIX_COLUMN && madp->CCSViewAvailable()) {
363 *nLists = madp->getLocalNumColumns();
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;
390 const MatrixAdapter<user_t>* madp =
static_cast<MatrixAdapter<user_t>*
>(data);
393 ArrayRCP<const gno_t> pIds;
394 ArrayRCP<const offset_t> offsets;
397 if (madp->CRSViewAvailable()) {
399 madp->getRowIDsView(Ids);
400 madp->getCRSView(offsets, pIds);
402 catch (std::exception &) {
403 *ierr = ZOLTAN_FATAL;
406 else if (madp->CCSViewAvailable()) {
408 madp->getColumnIDsView(Ids);
409 madp->getCCSView(offsets, pIds);
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;
456 const MeshAdapter<user_t>* madp =
static_cast<MeshAdapter<user_t>*
>(data);
457 if (madp->availAdjs(madp->getPrimaryEntityType(),
458 madp->getAdjacencyEntityType()))
460 *nLists = madp->getLocalNumOf(madp->getPrimaryEntityType());
461 *nPins = madp->getLocalNumAdjs(madp->getPrimaryEntityType(),
462 madp->getAdjacencyEntityType());
463 *format = ZOLTAN_COMPRESSED_VERTEX;
465 else if (madp->availAdjs(madp->getAdjacencyEntityType(),
466 madp->getPrimaryEntityType()))
468 *nLists = madp->getLocalNumOf(madp->getAdjacencyEntityType());
469 *nPins = madp->getLocalNumAdjs(madp->getAdjacencyEntityType(),
470 madp->getPrimaryEntityType());
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;
498 const MeshAdapter<user_t>* madp =
static_cast<MeshAdapter<user_t>*
>(data);
502 if (format == ZOLTAN_COMPRESSED_VERTEX)
504 listType = madp->getPrimaryEntityType();
505 pinType = madp->getAdjacencyEntityType();
507 else if (format == ZOLTAN_COMPRESSED_EDGE)
509 listType = madp->getAdjacencyEntityType();
510 pinType = madp->getPrimaryEntityType();
513 *ierr = ZOLTAN_FATAL;
516 if (*ierr == ZOLTAN_OK) {
521 madp->getIDsViewOf(listType,Ids);
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>
559 const HyperGraphModel<Adapter>* mdl =
560 static_cast<HyperGraphModel<Adapter>*
>(data);
562 return int(mdl->getLocalNumOwnedVertices());
567template <
typename Adapter>
569 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
570 int wdim,
float *wgts,
int *ierr)
572 const HyperGraphModel<Adapter>* mdl =
573 static_cast<HyperGraphModel<Adapter>*
>(data);
574 typedef typename Adapter::gno_t
gno_t;
575 typedef typename Adapter::lno_t
lno_t;
576 typedef typename Adapter::scalar_t scalar_t;
577 typedef StridedData<lno_t, scalar_t> input_t;
580 ArrayView<const gno_t> Ids;
581 ArrayView<input_t> model_wgts;
582 size_t num_verts = mdl->getVertexList(Ids,model_wgts);
583 ArrayView<bool> isOwner;
584 mdl->getOwnedList(isOwner);
586 for (
size_t i=0;i<num_verts;i++) {
588 ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
590 idPtr = &(lids[j*nLidEnt]);
596 int mywdim = mdl->getNumWeightsPerVertex();
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
628 const HyperGraphModel<Adapter>* mdl =
629 static_cast<HyperGraphModel<Adapter>*
>(data);
630 *nEdges = mdl->getLocalNumHyperEdges();
631 *nPins = mdl->getLocalNumPins();
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
647 const HyperGraphModel<Adapter>* mdl =
648 static_cast<HyperGraphModel<Adapter>*
>(data);
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;
653 typedef StridedData<lno_t, scalar_t> input_t;
655 ArrayView<const gno_t> Ids;
656 ArrayView<input_t> wgts;
657 mdl->getEdgeList(Ids,wgts);
658 ArrayView<const gno_t> pinIds_;
659 ArrayView<const offset_t> offsets;
660 ArrayView<input_t> pin_wgts;
661 mdl->getPinList(pinIds_,offsets,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.
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)