45 #ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_ 46 #define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_ 58 #include <zoltan_cpp.h> 73 template <
typename Adapter>
75 const Adapter *adp =
static_cast<Adapter *
>(data);
77 return int(adp->getLocalNumIDs());
82 template <
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++)
125 template <
typename Adapter>
126 static void zoltanParts(
void *data,
int nGidEnt,
int nLidEnt,
int nObj,
127 ZOLTAN_ID_PTR gids, 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]);
145 template <
typename Adapter>
148 const Adapter *adp =
static_cast<Adapter *
>(data);
150 return adp->getDimension();
155 template <
typename Adapter>
156 static void zoltanGeom(
void *data,
int nGidEnt,
int nLidEnt,
int nObj,
157 ZOLTAN_ID_PTR gids, 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]);
185 template <
typename Adapter>
187 int *format,
int *ierr
191 typedef typename Adapter::user_t user_t;
199 *format = ZOLTAN_COMPRESSED_VERTEX;
203 *format = ZOLTAN_COMPRESSED_EDGE;
207 *format = ZOLTAN_COMPRESSED_EDGE;
211 *format = ZOLTAN_COMPRESSED_VERTEX;
217 std::cout <<
"For hypergraph partitioning, " 218 <<
"CRSView or CCSView is needed in MatrixAdapter" << std::endl;
219 *ierr = ZOLTAN_FATAL;
225 template <
typename Adapter>
227 int nPins,
int format,
228 ZOLTAN_ID_PTR listIds,
int *listIdx,
229 ZOLTAN_ID_PTR pinIds,
int *ierr
233 typedef typename Adapter::gno_t gno_t;
234 typedef typename Adapter::lno_t lno_t;
235 typedef typename Adapter::user_t user_t;
240 const lno_t *offsets;
248 catch (std::exception &e) {
249 *ierr = ZOLTAN_FATAL;
257 catch (std::exception &e) {
258 *ierr = ZOLTAN_FATAL;
263 *ierr = ZOLTAN_FATAL;
266 if (*ierr == ZOLTAN_OK) {
268 for (
int i=0; i < nLists; i++) {
269 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
271 listIdx[i] = Teuchos::as<int>(offsets[i]);
273 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
274 for (
int i=0; i < nPins; i++) {
275 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
296 template <
typename Adapter>
298 int *format,
int *ierr
302 typedef typename Adapter::user_t user_t;
310 *format = ZOLTAN_COMPRESSED_VERTEX;
318 *format = ZOLTAN_COMPRESSED_EDGE;
321 std::cout <<
"For hypergraph partitioning, need first adjacencies " 322 <<
"(availAdjs, getLocalNumAdjs, getAdjsView) " 323 <<
"in MeshAdapter." << std::endl;
326 *format = -1*ZOLTAN_COMPRESSED_VERTEX;
327 *ierr = ZOLTAN_FATAL;
333 template <
typename Adapter>
335 void *data,
int nGidEnt,
int nLists,
int nPins,
336 int format, ZOLTAN_ID_PTR listIds,
337 int *listIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
341 typedef typename Adapter::gno_t gno_t;
342 typedef typename Adapter::lno_t lno_t;
343 typedef typename Adapter::user_t user_t;
348 if (format == ZOLTAN_COMPRESSED_VERTEX)
353 else if (format == ZOLTAN_COMPRESSED_EDGE)
359 *ierr = ZOLTAN_FATAL;
362 if (*ierr == ZOLTAN_OK) {
369 catch (std::exception &e) {
370 *ierr = ZOLTAN_FATAL;
374 const lno_t* offsets;
377 madp->
getAdjsView(listType, pinType, offsets, adjIds);
379 catch (std::exception &e) {
380 *ierr = ZOLTAN_FATAL;
384 for (
int i=0; i < nLists; i++) {
385 ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
387 listIdx[i] = Teuchos::as<int>(offsets[i]);
389 listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
390 for (
int i=0; i < nPins; i++) {
391 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
403 template <
typename Adapter>
413 template <
typename Adapter>
415 ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
416 int wdim,
float *wgts,
int *ierr)
420 typedef typename Adapter::gno_t gno_t;
421 typedef typename Adapter::lno_t lno_t;
422 typedef typename Adapter::scalar_t scalar_t;
426 ArrayView<const gno_t> Ids;
427 ArrayView<input_t> model_wgts;
429 ArrayView<bool> isOwner;
432 for (
size_t i=0;i<num_verts;i++) {
434 ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
436 idPtr = &(lids[j*nLidEnt]);
443 for (
int w = 0; w < wdim; w++) {
446 for (
size_t i = 0; i < num_verts; i++) {
448 wgts[j*wdim+w] = float(model_wgts[w][i]);
455 for (
size_t i = 0; i < num_verts; i++) {
468 template <
typename Adapter>
470 int *format,
int *ierr
479 *format = ZOLTAN_COMPRESSED_EDGE;
481 *format = ZOLTAN_COMPRESSED_VERTEX;
486 template <
typename Adapter>
488 int format, ZOLTAN_ID_PTR edgeIds,
489 int *edgeIdx, ZOLTAN_ID_PTR pinIds,
int *ierr
495 typedef typename Adapter::gno_t gno_t;
496 typedef typename Adapter::lno_t lno_t;
497 typedef typename Adapter::scalar_t scalar_t;
500 ArrayView<const gno_t> Ids;
501 ArrayView<input_t> wgts;
503 ArrayView<const gno_t> pinIds_;
504 ArrayView<const lno_t> offsets;
505 ArrayView<input_t> pin_wgts;
507 for (
int i=0;i<nEdges;i++) {
508 ZOLTAN_ID_PTR idPtr = &(edgeIds[i*nGidEnt]);
510 edgeIdx[i] = Teuchos::as<int>(offsets[i]);
513 for (
int i=0;i<nPins;i++) {
514 ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
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)
size_t getEdgeList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' hyperedge Ids and their weights.
static int zoltanNumGeom(void *data, int *ierr)
MatrixAdapter defines the adapter interface for matrices.
virtual void getColumnIDsView(const gno_t *&colIds) const
Sets pointer to this process' columns' global IDs.
Defines the MeshAdapter interface.
MeshAdapter defines the interface for mesh input.
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType.
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
size_t getLocalNumOwnedVertices() const
Returns the number vertices on this process that are owned.
Defines the IdentifierAdapter interface.
Defines the VectorAdapter interface.
enum MeshEntityType getAdjacencyEntityType() const
Returns the entity that describes adjacencies between the entities to be partitioned, ordered, colored, etc. That is, a primaryEntityType that contains an adjacencyEntityType are adjacent.
static void zoltanObjList(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
virtual void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const
Returns the number of first adjacencies on this process.
size_t getVertexList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' vertex Ids and their weights.
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 int zoltanNumObj(void *data, int *ierr)
virtual size_t getLocalNumColumns() const =0
Returns the number of columns on this process.
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process' identifiers.
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 zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins, int *format, int *ierr)
virtual void getCCSView(const lno_t *&offsets, const gno_t *&rowIds) const
Sets pointers to this process' matrix entries using compressed sparse column (CCS) format...
virtual bool CCSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse column (CCS)...
static void zoltanGeom(void *data, int nGidEnt, int nLidEnt, int nObj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int nDim, double *coords, int *ierr)
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const lno_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process' mesh first adjacencies.
size_t getLocalNumPins() const
Returns the local number of pins.
virtual bool CRSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse row (CRS) fo...
size_t getOwnedList(ArrayView< bool > &isOwner) const
Sets pointer to the ownership of this processes vertices.
The StridedData class manages lists of weights or coordinates.
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
static void ASSIGN(first_t &a, second_t b)
static int zoltanHGNumObj_withModel(void *data, int *ierr)
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
static void zoltanParts(void *data, int nGidEnt, int nLidEnt, int nObj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int *parts, int *ierr)
virtual void getCRSView(const lno_t *&offsets, const gno_t *&colIds) const
Sets pointers to this process' matrix entries using compressed sparse row (CRS) format. All matrix adapters must implement either getCRSView or getCCSView, but implementation of both is not required.
size_t getPinList(ArrayView< const gno_t > &pinIds, ArrayView< const lno_t > &offsets, ArrayView< input_t > &wgts) const
Sets pointers to this process' pins global Ids based on the centric view given by getCentricView() ...
static void zoltanHGSizeCS_withMeshAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
static void zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
enum MeshEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc.
Defines the HyperGraphModel interface.
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
Defines the MatrixAdapter interface.
size_t getLocalNumHyperEdges() const
Returns the number of hyper edges on this process. These are all hyper edges that have an adjacency t...
Defines the GraphAdapter interface.
static void zoltanHGSizeCS_withMatrixAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
virtual size_t getLocalNumRows() const =0
Returns the number of rows on this process.
virtual size_t getLocalNumEntries() const =0
Returns the number of nonzeros on this process.
A gathering of useful namespace methods.
HyperGraphModel defines the interface required for hyper graph models.
enum MatrixEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW, MATRIX_COLUMN, MATRIX_NONZERO.
CentricView getCentricView() const
Returns the centric view of the hypergraph.