This file is indexed.

/usr/include/trilinos/Zoltan2_OrderingProblem.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
// @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

/*! \file Zoltan2_OrderingProblem.hpp
    \brief Defines the OrderingProblem class.
*/

#ifndef _ZOLTAN2_ORDERINGPROBLEM_HPP_
#define _ZOLTAN2_ORDERINGPROBLEM_HPP_

#include <Zoltan2_Problem.hpp>
#include <Zoltan2_OrderingAlgorithms.hpp>
#include <Zoltan2_OrderingSolution.hpp>
#include <Zoltan2_EvaluateOrdering.hpp>

#include <Zoltan2_GraphModel.hpp>
#include <string>
#ifdef HAVE_ZOLTAN2_OVIS
#include <ovis.h>
#endif

#include <bitset>

using Teuchos::rcp_dynamic_cast;

namespace Zoltan2{

////////////////////////////////////////////////////////////////////////

/*! \brief OrderingProblem sets up ordering problems for the user.
 *
 *  The OrderingProblem is the core of the Zoltan2 ordering API.
 *  Based on the the user's input and parameters, the OrderingProblem
 *  sets up a computational Model, and a Solution object.  When the user
 *  calls the solve() method, the OrderingProblem runs the algorithm,
 *  after which the Solution object may be obtained by the user.
 *  \todo include pointers to examples
 *
 *  The template parameter is the InputAdapter containing the data that
 *  is to be partitioned.
 *
 *  \todo follow ordering with partitioning
 *  \todo - Should Problems and Solution have interfaces for returning
 *          views and for returning RCPs?  Or just one?  At a minimum, 
 *          we should have the word "View" in function names that return views.
 */

template<typename Adapter>
class OrderingProblem : public Problem<Adapter>
{
public:

  typedef typename Adapter::scalar_t scalar_t;
  typedef typename Adapter::gno_t gno_t;
  typedef typename Adapter::lno_t lno_t;
  typedef typename Adapter::user_t user_t;
  typedef typename Adapter::base_adapter_t base_adapter_t;

#ifdef HAVE_ZOLTAN2_MPI
   typedef Teuchos::OpaqueWrapper<MPI_Comm> mpiWrapper_t;
#endif

  /*! \brief Destructor
   */
  virtual ~OrderingProblem() {}

  OrderingProblem(Adapter *A, ParameterList *p,
                  const RCP<const Teuchos::Comm<int> > &comm) :
    Problem<Adapter>(A, p, comm) 
  {
    HELLO;
    createOrderingProblem();
  }

#ifdef HAVE_ZOLTAN2_MPI
  /*! \brief Constructor that takes an MPI communicator
   */
  OrderingProblem(Adapter *A, ParameterList *p, MPI_Comm mpicomm) :
  OrderingProblem(A, p, 
                  rcp<const Comm<int> >(new Teuchos::MpiComm<int>(
                                            Teuchos::opaqueWrapper(mpicomm))))
  {}
#endif

  /*! \brief Constructor that uses a default communicator
   */
  OrderingProblem(Adapter *A, ParameterList *p) : 
  OrderingProblem(A, p, Teuchos::DefaultComm<int>::getComm())
  {}

  /*! \brief Set up validators specific to this Problem
  */
  static void getValidParameters(ParameterList & pl)
  {
    RCP<Teuchos::StringValidator> order_method_Validator =
      Teuchos::rcp( new Teuchos::StringValidator(
        Teuchos::tuple<std::string>( "rcm", "minimum_degree", "natural",
          "random", "sorted_degree", "scotch", "nd" )));
    pl.set("order_method", "rcm", "order algorithm",
      order_method_Validator);

    RCP<Teuchos::StringValidator> order_method_type_Validator =
      Teuchos::rcp( new Teuchos::StringValidator(
        Teuchos::tuple<std::string>( "local", "global", "both" )));
    pl.set("order_method_type", "local", "local or global or both",
      order_method_type_Validator);

    RCP<Teuchos::StringValidator> order_package_Validator = Teuchos::rcp(
      new Teuchos::StringValidator(
        Teuchos::tuple<std::string>( "amd", "package2", "package3" )));
    pl.set("order_package", "amd", "package to use in ordering",
      order_package_Validator);
  }

  //!  \brief Direct the problem to create a solution.
  //
  //    \param updateInputData   If true this indicates that either
  //          this is the first attempt at solution, or that we
  //          are computing a new solution and the input data has
  //          changed since the previous solution was computed.
  //          If false, this indicates that we are computing a
  //          new solution using the same input data was used for
  //          the previous solution, even though the parameters
  //          may have been changed.
  //
  //  For the sake of performance, we ask the caller to set \c updateInputData
  //  to false if he/she is computing a new solution using the same input data,
  //  but different problem parameters, than that which was used to compute
  //  the most recent solution.
  
  void solve(bool updateInputData=true);

  //!  \brief Get the local ordering solution to the problem.
  //
  //   \return  a reference to the solution to the most recent solve().

  LocalOrderingSolution<lno_t> * getLocalOrderingSolution() {
    if(localOrderingSolution_ == Teuchos::null) {
      throw std::logic_error( "OrderingProblem was not created with local"
        " ordering. Set parameter order_method_type to local or both."
        " Or use getGlobalOrderingSolution()." );
    }
    return setupSolution(localOrderingSolution_);
  }

  //!  \brief Get the global ordering solution to the problem.
  //
  //   \return  a reference to the solution to the most recent solve().

  GlobalOrderingSolution<gno_t> * getGlobalOrderingSolution() {
    if(globalOrderingSolution_ == Teuchos::null) {
      throw std::logic_error( "OrderingProblem was not created with global"
        " ordering. Set parameter order_method_type to global or both."
        " Or use getLocalOrderingSolution()." );
    }
    return setupSolution(globalOrderingSolution_);
  }

private:
  template<typename ordering_solution_t>
  ordering_solution_t *setupSolution(RCP<ordering_solution_t> solution) {
    // std::cout << "havePerm= " << solution->havePerm() <<  " haveInverse= "
    //   << solution->haveInverse() << std::endl;
    // Compute Perm or InvPerm, if one is missing.
    if (!(solution->havePerm()))
      solution->computePerm();
    if (!(solution->haveInverse()))
      solution->computeInverse();
    return solution.getRawPtr();
  }

  void createOrderingProblem();

  // local or global ordering is determined by which RCP is NULL
  RCP<LocalOrderingSolution<lno_t> > localOrderingSolution_;
  RCP<GlobalOrderingSolution<gno_t> > globalOrderingSolution_;

};

////////////////////////////////////////////////////////////////////////
template <typename Adapter>
void OrderingProblem<Adapter>::solve(bool updateInputData)
{
  HELLO;

  size_t nVtx = this->baseModel_->getLocalNumObjects();

  // TODO: Assuming one MPI process now. nVtx = ngids = nlids
  try
  {
    std::string method_type = this->params_->template
      get<std::string>("order_method_type", "local");

    if(method_type == "local" || method_type == "both") {
      localOrderingSolution_ = rcp(new LocalOrderingSolution<lno_t>(nVtx));
    }
    if(method_type == "global" || method_type == "both") {
      globalOrderingSolution_ = rcp(new GlobalOrderingSolution<gno_t>(nVtx));
    }
  }
  Z2_FORWARD_EXCEPTIONS;

  // Determine which algorithm to use based on defaults and parameters.
  // TODO: Use rcm if graph model is defined, otherwise use natural.
  // Need some exception handling here, too.

  std::string method = this->params_->template
    get<std::string>("order_method", "rcm");
  
  // TODO: Ignore case
  try
  {

  // could be a template... seems maybe more awkward
  // added this to avoid duplicating local/global below
  // so many times.
  #define ZOLTAN2_COMPUTE_ORDERING                      \
      if(localOrderingSolution_ != Teuchos::null) {     \
        alg.localOrder(localOrderingSolution_);         \
      }                                                 \
      if(globalOrderingSolution_ != Teuchos::null) {    \
        alg.globalOrder(globalOrderingSolution_);       \
      }

  if (method.compare("rcm") == 0) {
    AlgRCM<base_adapter_t> alg(this->graphModel_, this->params_, this->comm_);
    ZOLTAN2_COMPUTE_ORDERING
  }
  else if (method.compare("natural") == 0) {
    AlgNatural<base_adapter_t> alg(this->identifierModel_, this->params_,
      this->comm_);
    ZOLTAN2_COMPUTE_ORDERING
  }
  else if (method.compare("random") == 0) {
    AlgRandom<base_adapter_t> alg(this->identifierModel_, this->params_,
      this->comm_);
    ZOLTAN2_COMPUTE_ORDERING
  }
  else if (method.compare("sorted_degree") == 0) {
    AlgSortedDegree<base_adapter_t> alg(this->graphModel_, this->params_,
      this->comm_);
    ZOLTAN2_COMPUTE_ORDERING
  }
  else if (method.compare("minimum_degree") == 0) {
    std::string pkg = this->params_->template get<std::string>(
      "order_package", "amd");
    if (pkg.compare("amd") == 0)
    {
      AlgAMD<base_adapter_t> alg(this->graphModel_,
        this->params_, this->comm_);
      ZOLTAN2_COMPUTE_ORDERING
    }
  }
  else if (method.compare("scotch") == 0) { // BDD Adding scotch ordering
    AlgPTScotch<Adapter> alg(this->envConst_, this->comm_,
      this->baseInputAdapter_);
    ZOLTAN2_COMPUTE_ORDERING
  }

#ifdef INCLUDE_ZOLTAN2_EXPERIMENTAL_WOLF
  else if (method.compare("nd") == 0) {
    AlgND<Adapter> alg(this->envConst_, this->comm_, this->graphModel_,
      this->coordinateModel_,this->baseInputAdapter_);
    ZOLTAN2_COMPUTE_ORDERING
  }
#endif

  }
  Z2_FORWARD_EXCEPTIONS;
}

////////////////////////////////////////////////////////////////////////
//template <typename Adapter>
//void OrderingProblem<Adapter>::redistribute()
//{
//  HELLO;
//}

////////////////////////////////////////////////////////////////////////
//! createOrderingProblem 
//  Method with common functionality for creating a OrderingProblem.
//  Individual constructors do appropriate conversions of input, etc.
//  This method does everything that all constructors must do.

template <typename Adapter>
void OrderingProblem<Adapter>::createOrderingProblem()
{
  HELLO;
  using Teuchos::ParameterList;

  // Determine which parameters are relevant here.
  // For now, assume parameters similar to Zoltan:
  //   MODEL = graph, hypergraph, geometric, ids
  //   ALGORITHM = rcm, random, amd

  ModelType modelType = IdentifierModelType; //default, change later
  std::string method = this->params_->template
    get<std::string>("order_method", "rcm");

  if ((method == std::string("rcm")) || 
      (method == std::string("sorted_degree")) || 
      (method == std::string("minimum_degree"))) {
    modelType = GraphModelType;
  }

#ifdef INCLUDE_ZOLTAN2_EXPERIMENTAL_WOLF
  if ((method == std::string("nd")))
  {
    modelType = GraphModelType;
  }

#endif

  // Select Model based on parameters and InputAdapter type

  std::bitset<NUM_MODEL_FLAGS> graphFlags;
  std::bitset<NUM_MODEL_FLAGS> idFlags;


  //MMW: need to change this to allow multiple models
  //     as I did with partitioning, use modelAvail_

  switch (modelType) {

  case GraphModelType:
    graphFlags.set(REMOVE_SELF_EDGES);
    graphFlags.set(BUILD_LOCAL_GRAPH);
    this->graphModel_ = rcp(new GraphModel<base_adapter_t>(
      this->baseInputAdapter_, this->envConst_, this->comm_, graphFlags));

    this->baseModel_ = rcp_implicit_cast<const Model<base_adapter_t> >(
      this->graphModel_);

    break;


  case IdentifierModelType:
    this->identifierModel_ = rcp(new IdentifierModel<base_adapter_t>(
      this->baseInputAdapter_, this->envConst_, this->comm_, idFlags));

    this->baseModel_ = rcp_implicit_cast<const Model<base_adapter_t> >(
      this->identifierModel_);

    break;

  case HypergraphModelType:
  case CoordinateModelType:
    std::cout << __func__zoltan2__ 
              << " Model type " << modelType << " not yet supported." 
              << std::endl;
    break;

  default:
    std::cout << __func__zoltan2__ << " Invalid model" << modelType 
              << std::endl;
    break;
  }
}
} //namespace Zoltan2
#endif