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>
 
  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);
 
  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 , 
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]);
 
  185 template <
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;
 
  203 template <
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;
 
  214   typedef typename Adapter::userCoord_t userCoord_t;
 
  222   const offset_t *offsets;
 
  228   catch (std::exception &e) {
 
  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]);
 
  256 template <
typename Adapter>
 
  265   typedef typename Adapter::userCoord_t userCoord_t;
 
  274 template <
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;
 
  293   typedef typename Adapter::userCoord_t userCoord_t;
 
  301   const offset_t *offsets;
 
  302   const scalar_t *ewgts;
 
  309   catch (std::exception &e) {
 
  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]);
 
  337 template <
typename Adapter>
 
  339                                              int *nLists, 
int *nPins,
 
  340                                              int *format, 
int *ierr
 
  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;
 
  378 template <
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;
 
  394   const offset_t *offsets;
 
  402     catch (std::exception &e) {
 
  403       *ierr = ZOLTAN_FATAL;
 
  411     catch (std::exception &e) {
 
  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]);
 
  449 template <
typename Adapter>
 
  451                                            int *format, 
int *ierr
 
  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;
 
  486 template <
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;
 
  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 &e) {
 
  524       *ierr = ZOLTAN_FATAL;
 
  528     const offset_t* offsets;
 
  531       madp->
getAdjsView(listType, pinType, offsets, adjIds);
 
  533     catch (std::exception &e) {
 
  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]);
 
  557 template <
typename Adapter>
 
  567 template <
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++) {
 
  622 template <
typename Adapter>
 
  624                                      int *format, 
int *ierr
 
  633     *format = ZOLTAN_COMPRESSED_EDGE;
 
  635     *format = ZOLTAN_COMPRESSED_VERTEX;
 
  640 template <
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]);
 
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 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 int zoltanNumGeom(void *data, int *ierr)
 
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const 
Returns whether a first adjacency combination is available. 
 
MatrixAdapter defines the adapter interface for matrices. 
 
GraphAdapter defines the interface for graph-based user data. 
 
Defines the MeshAdapter interface. 
 
CentricView getCentricView() const 
Returns the centric view of the hypergraph. 
 
MeshAdapter defines the interface for mesh input. 
 
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType. 
 
Defines the IdentifierAdapter interface. 
 
Defines the VectorAdapter interface. 
 
virtual void getCCSView(const offset_t *&offsets, const gno_t *&rowIds) const 
Sets pointers to this process' matrix entries using compressed sparse column (CCS) format...
 
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)
 
void getIDsView(const gno_t *&Ids) const 
Provide a pointer to this process' identifiers. 
 
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. 
 
size_t getOwnedList(ArrayView< bool > &isOwner) const 
Sets pointer to the ownership of this processes vertices. 
 
virtual void getCRSView(const offset_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. 
 
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)
 
size_t getEdgeList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const 
Sets pointers to this process' hyperedge Ids and their weights. 
 
static void zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins, int *format, int *ierr)
 
virtual bool CCSViewAvailable() const 
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse column (CCS)...
 
size_t getLocalNumHyperEdges() const 
Returns the number of hyper edges on this process. These are all hyper edges that have an adjacency t...
 
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)
 
The StridedData class manages lists of weights or coordinates. 
 
static void ASSIGN(first_t &a, second_t b)
 
static int zoltanHGNumObj_withModel(void *data, int *ierr)
 
size_t getLocalNumPins() const 
Returns the local number of pins. 
 
size_t getVertexList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const 
Sets pointers to this process' vertex Ids and their weights. 
 
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 zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, 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. 
 
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() ...
 
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...
 
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 MeshEntityType getPrimaryEntityType() const 
Returns the entity to be partitioned, ordered, colored, etc. 
 
int getNumWeightsPerVertex() const 
Returns the number (0 or greater) of weights per vertex. 
 
size_t getLocalNumOwnedVertices() const 
Returns the number vertices on this process that are owned. 
 
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