This file is indexed.

/usr/include/trilinos/Zoltan2_AlgZoltanCallbacks.hpp is in libtrilinos-zoltan2-dev 12.12.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
// @HEADER
//
// ***********************************************************************
//
//   Zoltan2: A package of combinatorial algorithms for scientific computing
//                  Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Karen Devine      (kddevin@sandia.gov)
//                    Erik Boman        (egboman@sandia.gov)
//                    Siva Rajamanickam (srajama@sandia.gov)
//
// ***********************************************************************
//
// @HEADER
#ifndef _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_
#define _ZOLTAN2_ALGZOLTANCALLBACKS_HPP_

#include <Zoltan2_MeshAdapter.hpp>
#include <Zoltan2_VectorAdapter.hpp>
#include <Zoltan2_GraphAdapter.hpp>
#include <Zoltan2_MatrixAdapter.hpp>
#include <Zoltan2_IdentifierAdapter.hpp>

#include <Zoltan2_HyperGraphModel.hpp>

#include <Zoltan2_Util.hpp>
#include <Zoltan2_TPLTraits.hpp>
#include <zoltan_cpp.h>

////////////////////////////////////////////////////////////////////////
//! \file Zoltan2_AlgZoltanCallbacks.hpp
//! \brief callback functions for the Zoltan package (templated on Adapter)
//  Callbacks based on Adapter; specializations provided where needed

namespace Zoltan2 {

/////////////////////////////////////////////////////////////////////////////
// CALLBACKS SHARED BY MANY ADAPTERS
/////////////////////////////////////////////////////////////////////////////

////////////////////
// ZOLTAN_NUM_OBJ_FN
template <typename Adapter>
static int zoltanNumObj(void *data, int *ierr) {
  const Adapter *adp = static_cast<Adapter *>(data);
  *ierr = ZOLTAN_OK;
  return int(adp->getLocalNumIDs());
}

/////////////////////
// ZOLTAN_OBJ_LIST_FN
template <typename Adapter>
static void zoltanObjList(void *data, int nGidEnt, int nLidEnt, 
                          ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
                          int wdim, float *wgts, int *ierr) 
{
  const Adapter *adp = static_cast<Adapter *>(data);
  typedef typename Adapter::gno_t gno_t;
  typedef typename Adapter::lno_t lno_t;
  *ierr = ZOLTAN_OK;

  size_t mynObj = adp->getLocalNumIDs();

  const gno_t *myids = NULL;
  adp->getIDsView(myids);
  for (size_t i = 0; i < mynObj; i++) {
    ZOLTAN_ID_PTR idPtr = &(gids[i*nGidEnt]);
    TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, myids[i]);
    idPtr = &(lids[i*nLidEnt]);
    TPL_Traits<ZOLTAN_ID_PTR,lno_t>::ASSIGN(idPtr, lno_t(i));
  }

  if (wdim) {
    int mywdim = adp->getNumWeightsPerID();
    for (int w = 0; w < wdim; w++) {
      if (w < mywdim) {
        // copy weights from adapter
        const typename Adapter::scalar_t *mywgts;
        int mystride;
        adp->getWeightsView(mywgts, mystride, w);
        for (size_t i = 0; i < mynObj; i++) 
          wgts[i*wdim+w] = float(mywgts[i*mystride]);
      }
      else {
        // provide uniform weights
        for (size_t i = 0; i < mynObj; i++)
          wgts[i*wdim+w] = 1.;
      }
    }
  }
}

///////////////////////
// ZOLTAN_PART_MULTI_FN
template <typename Adapter>
static void zoltanParts(void *data, int nGidEnt, int nLidEnt, int nObj,
                        ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
                        int *parts, int *ierr)
{
  typedef typename Adapter::lno_t lno_t;
  const Adapter *adp = static_cast<Adapter *>(data);
  *ierr = ZOLTAN_OK;
  const typename Adapter::part_t *myparts;
  adp->getPartsView(myparts);
  // User parts from input adapter
  for (int i = 0; i < nObj; i++) {
    lno_t lidx;
    TPL_Traits<lno_t,ZOLTAN_ID_PTR>::ASSIGN(lidx, &(lids[i*nLidEnt]));
    parts[i] = int(myparts[lidx]);
  }
}

/////////////////////
// ZOLTAN_NUM_GEOM_FN
template <typename Adapter>
static int zoltanNumGeom(void *data, int *ierr) 
{
  const Adapter *adp = static_cast<Adapter *>(data);
  *ierr = ZOLTAN_OK;
  return adp->getDimension();
}

///////////////////////
// ZOLTAN_GEOM_MULTI_FN
template <typename Adapter>
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)
{
  typedef typename Adapter::lno_t lno_t;
  const Adapter *adp = static_cast<Adapter *>(data);
  *ierr = ZOLTAN_OK;

  for (int d = 0; d < nDim; d++) {
    const typename Adapter::scalar_t *mycoords;
    int mystride;
    adp->getCoordinatesView(mycoords, mystride, d);
    for (int i = 0; i < nObj; i++) {
      lno_t lidx;
      TPL_Traits<lno_t,ZOLTAN_ID_PTR>::ASSIGN(lidx, &(lids[i*nLidEnt]));
      coords[i*nDim+d] = double(mycoords[lidx*mystride]);
    }
  }
}

/////////////////////////////////////////////////////////////////////////////
// HYPERGRAPH CALLBACKS USING A MATRIX ADAPTER
// Building the most straightforward hypergraph from a matrix and, thus,
// avoiding use of HypergraphModel.
// Assuming vertices are rows or columns, and pins are nonzeros.
/////////////////////////////////////////////////////////////////////////////

///////////////////////
// ZOLTAN_HG_SIZE_CS_FN
template <typename Adapter>
static void zoltanHGSizeCS_withMatrixAdapter(void *data, int *nLists, int *nPins,
                                             int *format, int *ierr
) 
{
  *ierr = ZOLTAN_OK;  
  typedef typename Adapter::user_t user_t;
  const MatrixAdapter<user_t>* madp = static_cast<MatrixAdapter<user_t>* >(data);

  *nPins = madp->getLocalNumEntries();

  MatrixEntityType etype = madp->getPrimaryEntityType();
  if (etype == MATRIX_ROW && madp->CRSViewAvailable()) {
    *nLists = madp->getLocalNumRows();
    *format = ZOLTAN_COMPRESSED_VERTEX;
  }
  else if (etype == MATRIX_ROW && madp->CCSViewAvailable()) {
    *nLists = madp->getLocalNumColumns();
    *format = ZOLTAN_COMPRESSED_EDGE;
  }
  else if (etype == MATRIX_COLUMN && madp->CRSViewAvailable()) {
    *nLists = madp->getLocalNumRows();
    *format = ZOLTAN_COMPRESSED_EDGE;
  }
  else if (etype == MATRIX_COLUMN && madp->CCSViewAvailable()) {
      *nLists = madp->getLocalNumColumns();
      *format = ZOLTAN_COMPRESSED_VERTEX;
  }
  else {
    // Need either CRSView or CCSView.
    // Also, not yet implemented for matrix nonzeros; 
    // may need a hypergraph model.
    std::cout << "For hypergraph partitioning, "
              << "CRSView or CCSView is needed in MatrixAdapter" << std::endl;
    *ierr = ZOLTAN_FATAL;
  }
}

//////////////////
// ZOLTAN_HG_CS_FN
template <typename Adapter>
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
)
{
  *ierr = ZOLTAN_OK;  
  typedef typename Adapter::gno_t gno_t;
  typedef typename Adapter::lno_t lno_t;  
  typedef typename Adapter::user_t user_t;
  const MatrixAdapter<user_t>* madp = static_cast<MatrixAdapter<user_t>* >(data);

  const gno_t *Ids;
  const gno_t *pIds;
  const lno_t *offsets;

  // Get the pins and list IDs.
  if (madp->CRSViewAvailable()) {
    try {
      madp->getRowIDsView(Ids);
      madp->getCRSView(offsets, pIds);
    }
    catch (std::exception &e) {
      *ierr = ZOLTAN_FATAL;
    }
  }
  else if (madp->CCSViewAvailable()) {
    try {
      madp->getColumnIDsView(Ids);
      madp->getCCSView(offsets, pIds);
    }
    catch (std::exception &e) {
      *ierr = ZOLTAN_FATAL;
    }
  }
  else {
    // Need either CRSView or CCSView.
    *ierr = ZOLTAN_FATAL;
  }

  if (*ierr == ZOLTAN_OK) {
    // copy into Zoltan's memory
    for (int i=0; i < nLists; i++) {
      ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, Ids[i]);
      listIdx[i] = Teuchos::as<int>(offsets[i]);
    }
    listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
    for (int i=0; i < nPins; i++) {
      ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, pIds[i]);
    }
  }
}

/////////////////////////////////////////////////////////////////////////////
// TODO:  GRAPH ADAPTER CALLBACKS


/////////////////////////////////////////////////////////////////////////////
// HYPERGRAPH CALLBACKS USING A MESH ADAPTER
// Implement Boman/Chevalier's hypergraph mesh model
// Skip explicit construction of a HypergraphModel
// Return either (depending on available adjacencies):
// +  for each primary entity (vtx), the list of assoc adjacency entities (edges)
// +  for each adjacency entity (edge), the list of assoc primary entities (vtx)
/////////////////////////////////////////////////////////////////////////////

///////////////////////
// ZOLTAN_HG_SIZE_CS_FN
template <typename Adapter>
static void zoltanHGSizeCS_withMeshAdapter(void *data, int *nLists, int *nPins,
                                           int *format, int *ierr
) 
{
  *ierr = ZOLTAN_OK;  
  typedef typename Adapter::user_t user_t;
  const MeshAdapter<user_t>* madp = static_cast<MeshAdapter<user_t>* >(data);
  if (madp->availAdjs(madp->getPrimaryEntityType(),
                      madp->getAdjacencyEntityType()))
  {
    *nLists = madp->getLocalNumOf(madp->getPrimaryEntityType());
    *nPins = madp->getLocalNumAdjs(madp->getPrimaryEntityType(),
                                   madp->getAdjacencyEntityType());
    *format = ZOLTAN_COMPRESSED_VERTEX;
  }
  else if (madp->availAdjs(madp->getAdjacencyEntityType(),
                           madp->getPrimaryEntityType())) 
  {
    *nLists = madp->getLocalNumOf(madp->getAdjacencyEntityType());
    *nPins = madp->getLocalNumAdjs(madp->getAdjacencyEntityType(),
                                   madp->getPrimaryEntityType());
    *format = ZOLTAN_COMPRESSED_EDGE;
  }
  else {
    std::cout << "For hypergraph partitioning, need first adjacencies "
              << "(availAdjs, getLocalNumAdjs, getAdjsView) "
              << "in MeshAdapter."  << std::endl;
    *nLists = 0;
    *nPins = 0;
    *format = -1*ZOLTAN_COMPRESSED_VERTEX;
    *ierr = ZOLTAN_FATAL;
  }
}

//////////////////
// ZOLTAN_HG_CS_FN
template <typename Adapter>
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
)
{
  *ierr = ZOLTAN_OK;
  typedef typename Adapter::gno_t gno_t;
  typedef typename Adapter::lno_t lno_t;  
  typedef typename Adapter::user_t user_t;
  const MeshAdapter<user_t>* madp = static_cast<MeshAdapter<user_t>*>(data);

  // Select listType and pinType based on format specified in ZOLTAN_HG_CS_SIZE_FN
  MeshEntityType listType, pinType;
  if (format == ZOLTAN_COMPRESSED_VERTEX)
  {
    listType = madp->getPrimaryEntityType();
    pinType = madp->getAdjacencyEntityType();
  }
  else if (format == ZOLTAN_COMPRESSED_EDGE)
  {
    listType = madp->getAdjacencyEntityType();
    pinType = madp->getPrimaryEntityType();
  }
  else {
    *ierr = ZOLTAN_FATAL;
  }
  
  if (*ierr == ZOLTAN_OK) {

    // get list IDs
    const gno_t *Ids;
    try {
      madp->getIDsViewOf(listType,Ids);
    }
    catch (std::exception &e) {
      *ierr = ZOLTAN_FATAL;
    }

    // get pins
    const lno_t* offsets;
    const gno_t* adjIds;
    try {
      madp->getAdjsView(listType, pinType, offsets, adjIds);
    }
    catch (std::exception &e) {
      *ierr = ZOLTAN_FATAL;
    }

    // copy into Zoltan's memory
    for (int i=0; i < nLists; i++) {
      ZOLTAN_ID_PTR idPtr = &(listIds[i*nGidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, Ids[i]);
      listIdx[i] = Teuchos::as<int>(offsets[i]);
    }
    listIdx[nLists] = Teuchos::as<int>(offsets[nLists]);
    for (int i=0; i < nPins; i++) {
      ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, adjIds[i]);
    }
  }
}

/////////////////////////////////////////////////////////////////////////////
// HYPERGRAPH CALLBACKS FROM A HYPERGRAPH MODEL
/////////////////////////////////////////////////////////////////////////////

////////////////////
// ZOLTAN_NUM_OBJ_FN
template <typename Adapter>
static int zoltanHGNumObj_withModel(void *data, int *ierr) {
  const HyperGraphModel<Adapter>* mdl = 
                                  static_cast<HyperGraphModel<Adapter>* >(data);
  *ierr = ZOLTAN_OK;
  return int(mdl->getLocalNumOwnedVertices());
}

/////////////////////
// ZOLTAN_OBJ_LIST_FN
template <typename Adapter>
static void zoltanHGObjList_withModel(void *data, int nGidEnt, int nLidEnt, 
                                      ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
                                      int wdim, float *wgts, int *ierr) 
{
  const HyperGraphModel<Adapter>* mdl = 
                                  static_cast<HyperGraphModel<Adapter>* >(data);
  typedef typename Adapter::gno_t       gno_t;
  typedef typename Adapter::lno_t       lno_t;
  typedef typename Adapter::scalar_t    scalar_t;
  typedef StridedData<lno_t, scalar_t>  input_t;

  *ierr = ZOLTAN_OK;
  ArrayView<const gno_t> Ids;
  ArrayView<input_t> model_wgts;
  size_t num_verts = mdl->getVertexList(Ids,model_wgts);
  ArrayView<bool> isOwner;
  mdl->getOwnedList(isOwner);
  int j=0;
  for (size_t i=0;i<num_verts;i++) {
    if (isOwner[i]) {
      ZOLTAN_ID_PTR idPtr = &(gids[j*nGidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, Ids[i]);
      idPtr = &(lids[j*nLidEnt]);
      TPL_Traits<ZOLTAN_ID_PTR,lno_t>::ASSIGN(idPtr, lno_t(i));
      j++;
    }
  }
  if (wdim) {
    int mywdim = mdl->getNumWeightsPerVertex();
    for (int w = 0; w < wdim; w++) {
      j=0;
      if (w < mywdim) {
        for (size_t i = 0; i < num_verts; i++)  {
          if (isOwner[i]) {
            wgts[j*wdim+w] = float(model_wgts[w][i]);
            j++;
          }
        }
      }
      else {
        // provide uniform weights
        for (size_t i = 0; i < num_verts; i++) {
          if (isOwner[i]) {
            wgts[j*wdim+w] = 1.;
            j++;
          }
        }
      }
    }
  }
}

///////////////////////
// ZOLTAN_HG_SIZE_CS_FN
template <typename Adapter>
static void zoltanHGSizeCS_withModel(void *data, int *nEdges, int *nPins,
                                     int *format, int *ierr
) 
{
  *ierr = ZOLTAN_OK;
  const HyperGraphModel<Adapter>* mdl = 
                                  static_cast<HyperGraphModel<Adapter>* >(data);
  *nEdges = mdl->getLocalNumHyperEdges();
  *nPins = mdl->getLocalNumPins();
  if (mdl->getCentricView()==HYPEREDGE_CENTRIC)
    *format = ZOLTAN_COMPRESSED_EDGE;
  else
    *format = ZOLTAN_COMPRESSED_VERTEX;
}

//////////////////
// ZOLTAN_HG_CS_FN
template <typename Adapter>
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
)
{
  *ierr = ZOLTAN_OK;
  const HyperGraphModel<Adapter>* mdl = 
                                  static_cast<HyperGraphModel<Adapter>* >(data);
  typedef typename Adapter::gno_t       gno_t;
  typedef typename Adapter::lno_t       lno_t;
  typedef typename Adapter::scalar_t    scalar_t;
  typedef StridedData<lno_t, scalar_t>  input_t;

  ArrayView<const gno_t> Ids;
  ArrayView<input_t> wgts;
  mdl->getEdgeList(Ids,wgts);
  ArrayView<const gno_t> pinIds_;
  ArrayView<const lno_t> offsets;
  ArrayView<input_t> pin_wgts;
  mdl->getPinList(pinIds_,offsets,pin_wgts);
  for (int i=0;i<nEdges;i++) {
    ZOLTAN_ID_PTR idPtr = &(edgeIds[i*nGidEnt]);
    TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, Ids[i]);
    edgeIdx[i] = Teuchos::as<int>(offsets[i]);
  }
  
  for (int i=0;i<nPins;i++) {
    ZOLTAN_ID_PTR idPtr = &(pinIds[i*nGidEnt]);
    TPL_Traits<ZOLTAN_ID_PTR,gno_t>::ASSIGN(idPtr, pinIds_[i]);
  }
}

}


#endif