Zoltan2
Zoltan2_AlgZoltanCallbacks.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 #ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
46 #define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
47 
48 #include <Zoltan2_MeshAdapter.hpp>
50 #include <Zoltan2_GraphAdapter.hpp>
53 
55 
56 #include <Zoltan2_Util.hpp>
57 #include <Zoltan2_TPLTraits.hpp>
58 #include <zoltan_cpp.h>
59 
63 // Callbacks based on Adapter; specializations provided where needed
64 
65 namespace Zoltan2 {
66 
68 // CALLBACKS SHARED BY MANY ADAPTERS
70 
72 // ZOLTAN_NUM_OBJ_FN
73 template <typename Adapter>
74 static int zoltanNumObj(void *data, int *ierr) {
75  const Adapter *adp = static_cast<Adapter *>(data);
76  *ierr = ZOLTAN_OK;
77  return int(adp->getLocalNumIDs());
78 }
79 
81 // ZOLTAN_OBJ_LIST_FN
82 template <typename Adapter>
83 static void zoltanObjList(void *data, int nGidEnt, int nLidEnt,
84  ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
85  int wdim, float *wgts, int *ierr)
86 {
87  const Adapter *adp = static_cast<Adapter *>(data);
88  typedef typename Adapter::gno_t gno_t;
89  typedef typename Adapter::lno_t lno_t;
90  *ierr = ZOLTAN_OK;
91 
92  size_t mynObj = adp->getLocalNumIDs();
93 
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]);
101  }
102 
103  if (wdim) {
104  int mywdim = adp->getNumWeightsPerID();
105  for (int w = 0; w < wdim; w++) {
106  if (w < mywdim) {
107  // copy weights from adapter
108  const typename Adapter::scalar_t *mywgts;
109  int mystride;
110  adp->getWeightsView(mywgts, mystride, w);
111  for (size_t i = 0; i < mynObj; i++)
112  wgts[i*wdim+w] = float(mywgts[i*mystride]);
113  }
114  else {
115  // provide uniform weights
116  for (size_t i = 0; i < mynObj; i++)
117  wgts[i*wdim+w] = 1.;
118  }
119  }
120  }
121 }
122 
124 // ZOLTAN_PART_MULTI_FN
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)
129 {
130  typedef typename Adapter::lno_t lno_t;
131  const Adapter *adp = static_cast<Adapter *>(data);
132  *ierr = ZOLTAN_OK;
133  const typename Adapter::part_t *myparts;
134  adp->getPartsView(myparts);
135  // User parts from input adapter
136  for (int i = 0; i < nObj; i++) {
137  lno_t lidx;
138  TPL_Traits<lno_t,ZOLTAN_ID_PTR>::ASSIGN(lidx, &(lids[i*nLidEnt]));
139  parts[i] = int(myparts[lidx]);
140  }
141 }
142 
144 // ZOLTAN_NUM_GEOM_FN
145 template <typename Adapter>
146 static int zoltanNumGeom(void *data, int *ierr)
147 {
148  const Adapter *adp = static_cast<Adapter *>(data);
149  *ierr = ZOLTAN_OK;
150  return adp->getDimension();
151 }
152 
154 // ZOLTAN_GEOM_MULTI_FN
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)
159 {
160  typedef typename Adapter::lno_t lno_t;
161  const Adapter *adp = static_cast<Adapter *>(data);
162  *ierr = ZOLTAN_OK;
163 
164  for (int d = 0; d < nDim; d++) {
165  const typename Adapter::scalar_t *mycoords;
166  int mystride;
167  adp->getCoordinatesView(mycoords, mystride, d);
168  for (int i = 0; i < nObj; i++) {
169  lno_t lidx;
170  TPL_Traits<lno_t,ZOLTAN_ID_PTR>::ASSIGN(lidx, &(lids[i*nLidEnt]));
171  coords[i*nDim+d] = double(mycoords[lidx*mystride]);
172  }
173  }
174 }
175 
177 // HYPERGRAPH CALLBACKS USING A GRAPH ADAPTER
178 // Building the most straightforward hypergraph from a graph and, thus,
179 // avoiding use of HypergraphModel.
180 // Assuming one hyperedge per vertex, containing vertex and all its nbors
182 
184 // ZOLTAN_HG_SIZE_CS_FN
185 template <typename Adapter>
186 static void zoltanHGSizeCS_withGraphAdapter(void *data,
187  int *nLists, int *nPins,
188  int *format, int *ierr
189 )
190 {
191  // Assuming one hyperedge per vertex consisting of vertex and its graph nbors.
192  const Adapter *adp = static_cast<Adapter *>(data);
193  *ierr = ZOLTAN_OK;
194 
195  *nLists = Teuchos::as<int>(adp->getLocalNumVertices());
196  *nPins = Teuchos::as<int>(adp->getLocalNumEdges()+adp->getLocalNumVertices());
197  // number of given edges + self pin for each vertex
198  *format = ZOLTAN_COMPRESSED_EDGE;
199 }
200 
202 // ZOLTAN_HG_CS_FN
203 template <typename Adapter>
204 static void zoltanHGCS_withGraphAdapter(void *data, int nGidEnt, int nLists,
205  int nPins, int format,
206  ZOLTAN_ID_PTR listIds, int *listIdx,
207  ZOLTAN_ID_PTR pinIds, int *ierr
208 )
209 {
210  // Assuming one hyperedge per vertex consisting of vertex and its graph nbors.
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;
216  static_cast<GraphAdapter<user_t, userCoord_t>* >(data);
217 
218  *ierr = ZOLTAN_OK;
219 
220  const gno_t *ids;
221  const gno_t *adjIds;
222  const offset_t *offsets;
223 
224  try {
225  adp->getIDsView(ids);
226  adp->getEdgesView(offsets, adjIds);
227  }
228  catch (std::exception &e) {
229  *ierr = ZOLTAN_FATAL;
230  }
231 
232  if (*ierr == ZOLTAN_OK) {
233  // copy into Zoltan's memory
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); // adding self pin
238  }
239  listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
240  int pinCnt = 0;
241  for (int i=0; i < nLists; i++) {
242  ZOLTAN_ID_PTR idPtr = &(pinIds[pinCnt*nGidEnt]);
244  pinCnt++;
245  for (offset_t j = offsets[i]; j < offsets[i+1]; j++) {
246  idPtr = &(pinIds[pinCnt*nGidEnt]);
247  TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, adjIds[j]);
248  pinCnt++;
249  }
250  }
251  }
252 }
253 
255 // ZOLTAN_HG_SIZE_EDGE_WGTS_FN
256 template <typename Adapter>
258  void *data,
259  int *nEdges,
260  int *ierr
261 )
262 {
263  // Assuming one hyperedge per vertex consisting of vertex and its graph nbors.
264  typedef typename Adapter::user_t user_t;
265  typedef typename Adapter::userCoord_t userCoord_t;
267  static_cast<GraphAdapter<user_t, userCoord_t>* >(data);
268  *ierr = ZOLTAN_OK;
269  *nEdges = Teuchos::as<int>(adp->getLocalNumVertices()); // one edge per vertex
270 }
271 
273 // ZOLTAN_HG_EDGE_WGTS_FN
274 template <typename Adapter>
276  void *data,
277  int nGidEnt,
278  int nLidEnt,
279  int nEdges,
280  int eWgtDim,
281  ZOLTAN_ID_PTR edgeGids,
282  ZOLTAN_ID_PTR edgeLids,
283  float *edgeWgts,
284  int *ierr
285 )
286 {
287  // Assuming one hyperedge per vertex consisting of vertex and its graph nbors.
288  // Hyperedge weight is then sum of edge weights to nbors.
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;
295  static_cast<GraphAdapter<user_t, userCoord_t>* >(data);
296 
297  *ierr = ZOLTAN_OK;
298 
299  const gno_t *ids;
300  const gno_t *adjIds;
301  const offset_t *offsets;
302  const scalar_t *ewgts;
303  int stride;
304  try {
305  adp->getIDsView(ids);
306  adp->getEdgesView(offsets, adjIds);
307  adp->getEdgeWeightsView(ewgts, stride, 0); // Use only first weight
308  }
309  catch (std::exception &e) {
310  *ierr = ZOLTAN_FATAL;
311  }
312  if (ierr == ZOLTAN_OK) {
313  for (int i = 0; i < nEdges; i++) {
314  float sum = 0;
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]);
319  if (nLidEnt) {
320  idPtr = &(edgeLids[i*nLidEnt]);
322  }
323  edgeWgts[i] = sum;
324  }
325  }
326 }
327 
329 // HYPERGRAPH CALLBACKS USING A MATRIX ADAPTER
330 // Building the most straightforward hypergraph from a matrix and, thus,
331 // avoiding use of HypergraphModel.
332 // Assuming vertices are rows or columns, and pins are nonzeros.
334 
336 // ZOLTAN_HG_SIZE_CS_FN
337 template <typename Adapter>
338 static void zoltanHGSizeCS_withMatrixAdapter(void *data,
339  int *nLists, int *nPins,
340  int *format, int *ierr
341 )
342 {
343  *ierr = ZOLTAN_OK;
344  typedef typename Adapter::user_t user_t;
345  const MatrixAdapter<user_t>* madp = static_cast<MatrixAdapter<user_t>* >(data);
346 
347  *nPins = madp->getLocalNumEntries();
348 
349  MatrixEntityType etype = madp->getPrimaryEntityType();
350  if (etype == MATRIX_ROW && madp->CRSViewAvailable()) {
351  *nLists = madp->getLocalNumRows();
352  *format = ZOLTAN_COMPRESSED_VERTEX;
353  }
354  else if (etype == MATRIX_ROW && madp->CCSViewAvailable()) {
355  *nLists = madp->getLocalNumColumns();
356  *format = ZOLTAN_COMPRESSED_EDGE;
357  }
358  else if (etype == MATRIX_COLUMN && madp->CRSViewAvailable()) {
359  *nLists = madp->getLocalNumRows();
360  *format = ZOLTAN_COMPRESSED_EDGE;
361  }
362  else if (etype == MATRIX_COLUMN && madp->CCSViewAvailable()) {
363  *nLists = madp->getLocalNumColumns();
364  *format = ZOLTAN_COMPRESSED_VERTEX;
365  }
366  else {
367  // Need either CRSView or CCSView.
368  // Also, not yet implemented for matrix nonzeros;
369  // may need a hypergraph model.
370  std::cout << "For hypergraph partitioning, "
371  << "CRSView or CCSView is needed in MatrixAdapter" << std::endl;
372  *ierr = ZOLTAN_FATAL;
373  }
374 }
375 
377 // ZOLTAN_HG_CS_FN
378 template <typename Adapter>
379 static void zoltanHGCS_withMatrixAdapter(void *data, int nGidEnt, int nLists,
380  int nPins, int format,
381  ZOLTAN_ID_PTR listIds, int *listIdx,
382  ZOLTAN_ID_PTR pinIds, int *ierr
383 )
384 {
385  *ierr = ZOLTAN_OK;
386  typedef typename Adapter::gno_t gno_t;
387  // typedef typename Adapter::lno_t lno_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);
391 
392  const gno_t *Ids;
393  const gno_t *pIds;
394  const offset_t *offsets;
395 
396  // Get the pins and list IDs.
397  if (madp->CRSViewAvailable()) {
398  try {
399  madp->getRowIDsView(Ids);
400  madp->getCRSView(offsets, pIds);
401  }
402  catch (std::exception &e) {
403  *ierr = ZOLTAN_FATAL;
404  }
405  }
406  else if (madp->CCSViewAvailable()) {
407  try {
408  madp->getColumnIDsView(Ids);
409  madp->getCCSView(offsets, pIds);
410  }
411  catch (std::exception &e) {
412  *ierr = ZOLTAN_FATAL;
413  }
414  }
415  else {
416  // Need either CRSView or CCSView.
417  *ierr = ZOLTAN_FATAL;
418  }
419 
420  if (*ierr == ZOLTAN_OK) {
421  // copy into Zoltan's memory
422  for (int i=0; i < nLists; i++) {
423  ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
425  listIdx[i] = Teuchos::as<int>(offsets[i]);
426  }
427  listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
428  for (int i=0; i < nPins; i++) {
429  ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
431  }
432  }
433 }
434 
436 // TODO: GRAPH ADAPTER CALLBACKS
437 
439 // HYPERGRAPH CALLBACKS USING A MESH ADAPTER
440 // Implement Boman/Chevalier's hypergraph mesh model
441 // Skip explicit construction of a HypergraphModel
442 // Return either (depending on available adjacencies):
443 // + for each primary entity (vtx), the list of assoc adjacency entities (edges)
444 // + for each adjacency entity (edge), the list of assoc primary entities (vtx)
446 
448 // ZOLTAN_HG_SIZE_CS_FN
449 template <typename Adapter>
450 static void zoltanHGSizeCS_withMeshAdapter(void *data, int *nLists, int *nPins,
451  int *format, int *ierr
452 )
453 {
454  *ierr = ZOLTAN_OK;
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()))
459  {
460  *nLists = madp->getLocalNumOf(madp->getPrimaryEntityType());
461  *nPins = madp->getLocalNumAdjs(madp->getPrimaryEntityType(),
462  madp->getAdjacencyEntityType());
463  *format = ZOLTAN_COMPRESSED_VERTEX;
464  }
465  else if (madp->availAdjs(madp->getAdjacencyEntityType(),
466  madp->getPrimaryEntityType()))
467  {
468  *nLists = madp->getLocalNumOf(madp->getAdjacencyEntityType());
469  *nPins = madp->getLocalNumAdjs(madp->getAdjacencyEntityType(),
470  madp->getPrimaryEntityType());
471  *format = ZOLTAN_COMPRESSED_EDGE;
472  }
473  else {
474  std::cout << "For hypergraph partitioning, need first adjacencies "
475  << "(availAdjs, getLocalNumAdjs, getAdjsView) "
476  << "in MeshAdapter." << std::endl;
477  *nLists = 0;
478  *nPins = 0;
479  *format = -1*ZOLTAN_COMPRESSED_VERTEX;
480  *ierr = ZOLTAN_FATAL;
481  }
482 }
483 
485 // ZOLTAN_HG_CS_FN
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
491 )
492 {
493  *ierr = ZOLTAN_OK;
494  typedef typename Adapter::gno_t gno_t;
495  // typedef typename Adapter::lno_t lno_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);
499 
500  // Select listType and pinType based on format specified in ZOLTAN_HG_CS_SIZE_FN
501  MeshEntityType listType, pinType;
502  if (format == ZOLTAN_COMPRESSED_VERTEX)
503  {
504  listType = madp->getPrimaryEntityType();
505  pinType = madp->getAdjacencyEntityType();
506  }
507  else if (format == ZOLTAN_COMPRESSED_EDGE)
508  {
509  listType = madp->getAdjacencyEntityType();
510  pinType = madp->getPrimaryEntityType();
511  }
512  else {
513  *ierr = ZOLTAN_FATAL;
514  }
515 
516  if (*ierr == ZOLTAN_OK) {
517 
518  // get list IDs
519  const gno_t *Ids;
520  try {
521  madp->getIDsViewOf(listType,Ids);
522  }
523  catch (std::exception &e) {
524  *ierr = ZOLTAN_FATAL;
525  }
526 
527  // get pins
528  const offset_t* offsets;
529  const gno_t* adjIds;
530  try {
531  madp->getAdjsView(listType, pinType, offsets, adjIds);
532  }
533  catch (std::exception &e) {
534  *ierr = ZOLTAN_FATAL;
535  }
536 
537  // copy into Zoltan's memory
538  for (int i=0; i < nLists; i++) {
539  ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
541  listIdx[i] = Teuchos::as<int>(offsets[i]);
542  }
543  listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
544  for (int i=0; i < nPins; i++) {
545  ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
546  TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, adjIds[i]);
547  }
548  }
549 }
550 
552 // HYPERGRAPH CALLBACKS FROM A HYPERGRAPH MODEL
554 
556 // ZOLTAN_NUM_OBJ_FN
557 template <typename Adapter>
558 static int zoltanHGNumObj_withModel(void *data, int *ierr) {
559  const HyperGraphModel<Adapter>* mdl =
560  static_cast<HyperGraphModel<Adapter>* >(data);
561  *ierr = ZOLTAN_OK;
562  return int(mdl->getLocalNumOwnedVertices());
563 }
564 
566 // ZOLTAN_OBJ_LIST_FN
567 template <typename Adapter>
568 static void zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt,
569  ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
570  int wdim, float *wgts, int *ierr)
571 {
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;
578 
579  *ierr = ZOLTAN_OK;
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);
585  int j=0;
586  for (size_t i=0;i<num_verts;i++) {
587  if (isOwner[i]) {
588  ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
590  idPtr = &(lids[j*nLidEnt]);
592  j++;
593  }
594  }
595  if (wdim) {
596  int mywdim = mdl->getNumWeightsPerVertex();
597  for (int w = 0; w < wdim; w++) {
598  j=0;
599  if (w < mywdim) {
600  for (size_t i = 0; i < num_verts; i++) {
601  if (isOwner[i]) {
602  wgts[j*wdim+w] = float(model_wgts[w][i]);
603  j++;
604  }
605  }
606  }
607  else {
608  // provide uniform weights
609  for (size_t i = 0; i < num_verts; i++) {
610  if (isOwner[i]) {
611  wgts[j*wdim+w] = 1.;
612  j++;
613  }
614  }
615  }
616  }
617  }
618 }
619 
621 // ZOLTAN_HG_SIZE_CS_FN
622 template <typename Adapter>
623 static void zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins,
624  int *format, int *ierr
625 )
626 {
627  *ierr = ZOLTAN_OK;
628  const HyperGraphModel<Adapter>* mdl =
629  static_cast<HyperGraphModel<Adapter>* >(data);
630  *nEdges = mdl->getLocalNumHyperEdges();
631  *nPins = mdl->getLocalNumPins();
632  if (mdl->getCentricView()==HYPEREDGE_CENTRIC)
633  *format = ZOLTAN_COMPRESSED_EDGE;
634  else
635  *format = ZOLTAN_COMPRESSED_VERTEX;
636 }
637 
639 // ZOLTAN_HG_CS_FN
640 template <typename Adapter>
641 static void zoltanHGCS_withModel(void *data, int nGidEnt, int nEdges, int nPins,
642  int format, ZOLTAN_ID_PTR edgeIds,
643  int *edgeIdx, ZOLTAN_ID_PTR pinIds, int *ierr
644 )
645 {
646  *ierr = ZOLTAN_OK;
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;
654 
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]);
666  }
667 
668  for (int i=0;i<nPins;i++) {
669  ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
670  TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, pinIds_[i]);
671  }
672 }
673 
674 }
675 
676 
677 #endif
Zoltan2::zoltanHGCS_withMeshAdapter
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)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:487
Zoltan2::MATRIX_ROW
Definition: Zoltan2_MatrixAdapter.hpp:59
Zoltan2::zoltanNumObj
static int zoltanNumObj(void *data, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:74
Zoltan2::MatrixAdapter
MatrixAdapter defines the adapter interface for matrices.
Definition: Zoltan2_MatrixAdapter.hpp:106
Zoltan2::MATRIX_COLUMN
Definition: Zoltan2_MatrixAdapter.hpp:60
Zoltan2::MatrixAdapter::getLocalNumEntries
virtual size_t getLocalNumEntries() const =0
Returns the number of nonzeros on this process.
Zoltan2::HyperGraphModel::getLocalNumHyperEdges
size_t getLocalNumHyperEdges() const
Returns the number of hyper edges on this process. These are all hyper edges that have an adjacency t...
Definition: Zoltan2_HyperGraphModel.hpp:177
Zoltan2::MeshAdapter::getAdjacencyEntityType
enum MeshEntityType getAdjacencyEntityType() const
Returns the entity that describes adjacencies between the entities to be partitioned,...
Definition: Zoltan2_MeshAdapter.hpp:361
Zoltan2::zoltanHGCS_withMatrixAdapter
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)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:379
Zoltan2::MeshAdapter::getLocalNumOf
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType.
Zoltan2::MeshAdapter::availAdjs
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
Definition: Zoltan2_MeshAdapter.hpp:251
Zoltan2::HyperGraphModel::getNumWeightsPerVertex
int getNumWeightsPerVertex() const
Returns the number (0 or greater) of weights per vertex.
Definition: Zoltan2_HyperGraphModel.hpp:189
Zoltan2::MeshEntityType
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
Definition: Zoltan2_MeshAdapter.hpp:63
Zoltan2::MeshAdapter::getIDsViewOf
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process' identifiers.
Zoltan2::MatrixAdapter::getCCSView
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....
Definition: Zoltan2_MatrixAdapter.hpp:266
Zoltan2::GraphAdapter::getEdgesView
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.
Zoltan2_HyperGraphModel.hpp
Defines the HyperGraphModel interface.
Zoltan2::MatrixEntityType
MatrixEntityType
Definition: Zoltan2_MatrixAdapter.hpp:58
Zoltan2::zoltanParts
static void zoltanParts(void *data, int nGidEnt, int nLidEnt, int nObj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int *parts, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:126
Zoltan2::zoltanHGSizeCS_withGraphAdapter
static void zoltanHGSizeCS_withGraphAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:186
Zoltan2_MatrixAdapter.hpp
Defines the MatrixAdapter interface.
Zoltan2::MeshAdapter
MeshAdapter defines the interface for mesh input.
Definition: Zoltan2_MeshAdapter.hpp:124
Zoltan2::MatrixAdapter::getCRSView
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....
Definition: Zoltan2_MatrixAdapter.hpp:178
Zoltan2_VectorAdapter.hpp
Defines the VectorAdapter interface.
Zoltan2::zoltanHGSizeCS_withMeshAdapter
static void zoltanHGSizeCS_withMeshAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:450
Zoltan2::HyperGraphModel::getLocalNumPins
size_t getLocalNumPins() const
Returns the local number of pins.
Definition: Zoltan2_HyperGraphModel.hpp:185
Zoltan2::HyperGraphModel::getEdgeList
size_t getEdgeList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' hyperedge Ids and their weights.
Definition: Zoltan2_HyperGraphModel.hpp:266
part_t
SparseMatrixAdapter_t::part_t part_t
Definition: partitioningTree.cpp:74
Zoltan2::MeshAdapter::getLocalNumAdjs
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const
Returns the number of first adjacencies on this process.
Definition: Zoltan2_MeshAdapter.hpp:258
Zoltan2::zoltanHGEdgeWts_withGraphAdapter
static void zoltanHGEdgeWts_withGraphAdapter(void *data, int nGidEnt, int nLidEnt, int nEdges, int eWgtDim, ZOLTAN_ID_PTR edgeGids, ZOLTAN_ID_PTR edgeLids, float *edgeWgts, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:275
Zoltan2::zoltanHGObjList_withModel
static void zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:568
Zoltan2::HyperGraphModel::getCentricView
CentricView getCentricView() const
Returns the centric view of the hypergraph.
Definition: Zoltan2_HyperGraphModel.hpp:155
Zoltan2::zoltanHGCS_withModel
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)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:641
Zoltan2::MatrixAdapter::getLocalNumColumns
virtual size_t getLocalNumColumns() const =0
Returns the number of columns on this process.
Zoltan2::MatrixAdapter::getPrimaryEntityType
enum MatrixEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc. Valid values are MATRIX_ROW,...
Definition: Zoltan2_MatrixAdapter.hpp:366
Zoltan2::HyperGraphModel::getPinList
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()
Definition: Zoltan2_HyperGraphModel.hpp:288
Zoltan2::HyperGraphModel::getVertexList
size_t getVertexList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
Sets pointers to this process' vertex Ids and their weights.
Definition: Zoltan2_HyperGraphModel.hpp:210
Zoltan2::HyperGraphModel::getLocalNumOwnedVertices
size_t getLocalNumOwnedVertices() const
Returns the number vertices on this process that are owned.
Definition: Zoltan2_HyperGraphModel.hpp:167
Zoltan2::zoltanHGSizeCS_withMatrixAdapter
static void zoltanHGSizeCS_withMatrixAdapter(void *data, int *nLists, int *nPins, int *format, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:338
Zoltan2_MeshAdapter.hpp
Defines the MeshAdapter interface.
Zoltan2::zoltanHGSizeCS_withModel
static void zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins, int *format, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:623
Zoltan2::TPL_Traits::ASSIGN
static void ASSIGN(first_t &a, second_t b)
Definition: Zoltan2_TPLTraits.hpp:80
Zoltan2::MatrixAdapter::getRowIDsView
virtual void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
Definition: Zoltan2_MatrixAdapter.hpp:161
Zoltan2_GraphAdapter.hpp
Defines the GraphAdapter interface.
Zoltan2::HyperGraphModel::getOwnedList
size_t getOwnedList(ArrayView< bool > &isOwner) const
Sets pointer to the ownership of this processes vertices.
Definition: Zoltan2_HyperGraphModel.hpp:238
Zoltan2::MeshAdapter::getAdjsView
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process' mesh first adjacencies.
Definition: Zoltan2_MeshAdapter.hpp:272
Zoltan2::HYPEREDGE_CENTRIC
Definition: Zoltan2_HyperGraphModel.hpp:75
Zoltan2::zoltanHGCS_withGraphAdapter
static void zoltanHGCS_withGraphAdapter(void *data, int nGidEnt, int nLists, int nPins, int format, ZOLTAN_ID_PTR listIds, int *listIdx, ZOLTAN_ID_PTR pinIds, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:204
Zoltan2::MatrixAdapter::getLocalNumRows
virtual size_t getLocalNumRows() const =0
Returns the number of rows on this process.
Zoltan2::GraphAdapter::getLocalNumVertices
virtual size_t getLocalNumVertices() const =0
Returns the number of vertices on this process.
Zoltan2::zoltanNumGeom
static int zoltanNumGeom(void *data, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:146
Zoltan2::zoltanHGNumObj_withModel
static int zoltanHGNumObj_withModel(void *data, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:558
Zoltan2::zoltanObjList
static void zoltanObjList(void *data, int nGidEnt, int nLidEnt, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wdim, float *wgts, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:83
Zoltan2
Definition: Zoltan2_AlgSerialGreedy.hpp:56
Zoltan2::HyperGraphModel
HyperGraphModel defines the interface required for hyper graph models.
Definition: Zoltan2_HyperGraphModel.hpp:90
Zoltan2::GraphAdapter::getIDsView
void getIDsView(const gno_t *&Ids) const
Provide a pointer to this process' identifiers.
Definition: Zoltan2_GraphAdapter.hpp:313
Zoltan2_TPLTraits.hpp
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t,...
Zoltan2::MatrixAdapter::CCSViewAvailable
virtual bool CCSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse column (CCS)...
Definition: Zoltan2_MatrixAdapter.hpp:244
Zoltan2::GraphAdapter
GraphAdapter defines the interface for graph-based user data.
Definition: Zoltan2_GraphAdapter.hpp:99
Zoltan2::MatrixAdapter::CRSViewAvailable
virtual bool CRSViewAvailable() const
Indicates whether the MatrixAdapter implements a view of the matrix in compressed sparse row (CRS) fo...
Definition: Zoltan2_MatrixAdapter.hpp:156
Zoltan2::zoltanGeom
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)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:156
Zoltan2_IdentifierAdapter.hpp
Defines the IdentifierAdapter interface.
Zoltan2::zoltanHGSizeEdgeWts_withGraphAdapter
static void zoltanHGSizeEdgeWts_withGraphAdapter(void *data, int *nEdges, int *ierr)
Definition: Zoltan2_AlgZoltanCallbacks.hpp:257
Zoltan2_Util.hpp
A gathering of useful namespace methods.
Zoltan2::StridedData
The StridedData class manages lists of weights or coordinates.
Definition: Zoltan2_StridedData.hpp:76
Zoltan2::MeshAdapter::getPrimaryEntityType
enum MeshEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc.
Definition: Zoltan2_MeshAdapter.hpp:352
Zoltan2::GraphAdapter::getEdgeWeightsView
virtual void getEdgeWeightsView(const scalar_t *&weights, int &stride, int idx=0) const
Provide a pointer to the edge weights, if any.
Definition: Zoltan2_GraphAdapter.hpp:205
Zoltan2::MatrixAdapter::getColumnIDsView
virtual void getColumnIDsView(const gno_t *&colIds) const
Sets pointer to this process' columns' global IDs.
Definition: Zoltan2_MatrixAdapter.hpp:249