10 #ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_ 
   11 #define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_ 
   19 #ifdef HAVE_ZOLTAN2_HYPERGRAPH 
   25 #include <zoltan_cpp.h> 
   40 template <
typename Adapter>
 
   42   const Adapter *adp = 
static_cast<Adapter *
>(data);
 
   44   return int(adp->getLocalNumIDs());
 
   49 template <
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);
 
   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++)
 
   92 template <
typename Adapter>
 
   93 static void zoltanParts(
void *data, 
int , 
int nLidEnt, 
int nObj,
 
   94                         ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
 
   95                         int *parts, 
int *ierr)
 
   98   const Adapter *adp = 
static_cast<Adapter *
>(data);
 
  101   adp->getPartsView(myparts);
 
  103   for (
int i = 0; i < nObj; i++) {
 
  106     parts[i] = int(myparts[lidx]);
 
  112 template <
typename Adapter>
 
  115   const Adapter *adp = 
static_cast<Adapter *
>(data);
 
  117   return adp->getDimension();
 
  122 template <
typename Adapter>
 
  123 static void zoltanGeom(
void *data, 
int , 
int nLidEnt, 
int nObj,
 
  124                        ZOLTAN_ID_PTR , ZOLTAN_ID_PTR lids,
 
  125                        int nDim, 
double *coords, 
int *ierr)
 
  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]);
 
  152 template <
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;
 
  170 template <
typename Adapter>
 
  173                                         ZOLTAN_ID_PTR listIds, 
int *listIdx,
 
  174                                         ZOLTAN_ID_PTR pinIds, 
int *ierr
 
  179   typedef typename Adapter::offset_t offset_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]);
 
  223 template <
typename Adapter>
 
  232   typedef typename Adapter::userCoord_t userCoord_t;
 
  241 template <
typename Adapter>
 
  248   ZOLTAN_ID_PTR edgeGids, 
 
  249   ZOLTAN_ID_PTR edgeLids, 
 
  257   typedef typename Adapter::offset_t offset_t;
 
  258   typedef typename Adapter::scalar_t scalar_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]);
 
  304 template <
typename Adapter>
 
  306                                              int *nLists, 
int *nPins,
 
  307                                              int *format, 
int *ierr
 
  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;
 
  345 template <
typename Adapter>
 
  347                                          int nPins, 
int format, 
 
  348                                          ZOLTAN_ID_PTR listIds, 
int *listIdx,
 
  349                                          ZOLTAN_ID_PTR pinIds, 
int *ierr
 
  355   typedef typename Adapter::offset_t offset_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]);
 
  416 template <
typename Adapter>
 
  418                                            int *format, 
int *ierr
 
  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;
 
  453 template <
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
 
  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 
  525 template <
typename Adapter>
 
  526 static int zoltanHGNumObj_withModel(
void *data, 
int *ierr) {
 
  527   const HyperGraphModel<Adapter>* mdl = 
 
  528                                   static_cast<HyperGraphModel<Adapter>* 
>(data);
 
  530   return int(mdl->getLocalNumOwnedVertices());
 
  535 template <
typename Adapter>
 
  536 static 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);
 
  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++) {
 
  590 template <
typename Adapter>
 
  591 static 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;
 
  608 template <
typename Adapter>
 
  609 static 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);
 
  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]);
 
  642 #endif // HAVE_ZOLTAN2_HYPERGRAPH 
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const 
Sets pointers to this process' mesh first adjacencies. 
static int zoltanNumGeom(void *data, int *ierr)
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const 
Returns whether a first adjacency combination is available. 
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...
MatrixAdapter defines the adapter interface for matrices. 
GraphAdapter defines the interface for graph-based user data. 
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. 
map_t::global_ordinal_type gno_t
Defines the IdentifierAdapter interface. 
Defines the VectorAdapter interface. 
enum MatrixEntityType getPrimaryEntityType() const 
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW, MATRIX_COLUMN, MATRIX_NONZERO. 
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)
static void zoltanHGSizeEdgeWts_withGraphAdapter(void *data, int *nEdges, 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 int zoltanNumObj(void *data, int *ierr)
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. 
SparseMatrixAdapter_t::part_t part_t
virtual size_t getLocalNumColumns() const =0
Returns the number of columns on this process. 
static void zoltanHGSizeCS_withGraphAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
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)
virtual bool CCSViewAvailable() const 
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse column (CCS)...
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const 
Returns the number of first adjacencies on this process. 
static void zoltanParts(void *data, int, int nLidEnt, int nObj, ZOLTAN_ID_PTR, ZOLTAN_ID_PTR lids, int *parts, int *ierr)
map_t::local_ordinal_type lno_t
void getIDsView(const gno_t *&Ids) const override
Provide a pointer to this process' identifiers. 
static void ASSIGN(first_t &a, second_t b)
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
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 zoltanHGEdgeWts_withGraphAdapter(void *data, int nGidEnt, int nLidEnt, int nEdges, int, ZOLTAN_ID_PTR edgeGids, ZOLTAN_ID_PTR edgeLids, float *edgeWgts, int *ierr)
Defines the HyperGraphModel interface. 
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices. 
Defines the MatrixAdapter interface. 
static void zoltanHGCS_withGraphAdapter(void *data, int nGidEnt, int nLists, int, int, ZOLTAN_ID_PTR listIds, int *listIdx, ZOLTAN_ID_PTR pinIds, int *ierr)
Defines the GraphAdapter interface. 
virtual size_t getLocalNumVertices() const =0
Returns the number of vertices on this process. 
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...
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. All matrix adapters must implement either getCRSView or getCCSView, but implementation of both is not required. 
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. 
enum MeshEntityType getPrimaryEntityType() const 
Returns the entity to be partitioned, ordered, colored, etc. 
virtual void getEdgeWeightsView(const scalar_t *&weights, int &stride, int=0) const 
Provide a pointer to the edge weights, if any. 
virtual void getColumnIDsView(const gno_t *&colIds) const 
Sets pointer to this process' columns' global IDs. 
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t