Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process&#39; 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&#39; 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&#39; 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&#39; 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&#39; 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&#39; 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&#39; vertex Ids and their weights.
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS&#39;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&#39; 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&#39; rows&#39; 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&#39; columns&#39; global IDs.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition: Metric.cpp:74