/usr/include/trilinos/Zoltan2_AlgZoltanCallbacks.hpp is in libtrilinos-zoltan2-dev 12.4.2-2.
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 | // @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);
*ierr = ZOLTAN_OK;
size_t mynObj = adp->getLocalNumIDs();
const typename Adapter::gno_t *myids = NULL;
adp->getIDsView(myids);
for (size_t i = 0; i < mynObj; i++) {
gids[i] = ZOLTAN_ID_TYPE(myids[i]); // TODO TRAITS CONVERSION MAY BE NEEDED
lids[i] = ZOLTAN_ID_TYPE(i); // TODO TRAITS CONVERSION MAY BE NEEDED
}
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)
{
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++)
parts[i] = int(myparts[lids[i]]);
}
/////////////////////
// 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)
{
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++)
coords[i*nDim+d] = double(mycoords[lids[i]*mystride]);
}
}
/////////////////////////////////////////////////////////////////////////////
// MATRIX ADAPTER CALLBACKS
/////////////////////////////////////////////////////////////////////////////
///////////////////////
// ZOLTAN_HG_SIZE_CS_FN
template <typename Adapter>
static void zoltanHGSizeCSForMatrixAdapter(
void *data, int *nEdges, int *nPins,
int *format, int *ierr
)
{
std::cout << "HELLO FROM HGSizeCS with MATRIX ADAPTER" << std::endl;
*ierr = ZOLTAN_FATAL;
}
//////////////////
// ZOLTAN_HG_CS_FN
template <typename Adapter>
static void zoltanHGCSForMatrixAdapter(
void *data, int nGidEnt, int nEdges, int nPins,
int format, ZOLTAN_ID_PTR edgeIds,
int *edgeIdx, ZOLTAN_ID_PTR pinIds, int *ierr
)
{
std::cout << "HELLO FROM HGCS with MATRIX ADAPTER" << std::endl;
*ierr = ZOLTAN_FATAL;
}
/////////////////////////////////////////////////////////////////////////////
// TODO: GRAPH ADAPTER CALLBACKS
/////////////////////////////////////////////////////////////////////////////
// HYPERGRAPH MODEL CALLBACKS
/////////////////////////////////////////////////////////////////////////////
////////////////////
// ZOLTAN_NUM_OBJ_FN
template <typename Adapter>
static int zoltanHGModelNumObj(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 zoltanHGModelObjList(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]) {
lids[j] = i;
gids[j] = Ids[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 zoltanHGModelSizeCSForMeshAdapter(
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 zoltanHGModelCSForMeshAdapter(
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++) {
edgeIds[i]=Ids[i];
edgeIdx[i]=offsets[i];
}
for (int i=0;i<nPins;i++)
pinIds[i] = pinIds_[i];
}
/////////////////////////////////////////////////////////////////////////////
// MESH ADAPTER CALLBACKS
/////////////////////////////////////////////////////////////////////////////
///////////////////////
// ZOLTAN_HG_SIZE_CS_FN
template <typename Adapter>
static void zoltanHGSizeCSForMeshAdapter(
void *data, int *nEdges, 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);
*nEdges = madp->getLocalNumOf(madp->getAdjacencyEntityType());
*nPins = madp->getLocalNumAdjs(madp->getAdjacencyEntityType(),madp->getPrimaryEntityType());
*format = ZOLTAN_COMPRESSED_EDGE;
}
//////////////////
// ZOLTAN_HG_CS_FN
template <typename Adapter>
static void zoltanHGCSForMeshAdapter(
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;
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);
const gno_t *Ids;
madp->getIDsViewOf(madp->getAdjacencyEntityType(),Ids);
const lno_t* offsets;
const gno_t* adjIds;
madp->getAdjsView(madp->getAdjacencyEntityType(), madp->getPrimaryEntityType(),
offsets, adjIds);
for (int i=0;i<nEdges;i++) {
edgeIds[i]=Ids[i];
edgeIdx[i]=offsets[i];
}
for (int i=0;i<nPins;i++)
pinIds[i] = adjIds[i];
}
}
#endif
|