This file is indexed.

/usr/include/trilinos/Zoltan2_MappingProblem.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
// @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_MappingProblem.hpp
    \brief Defines the MappingProblem class.
*/

#ifndef _ZOLTAN2_MAPPINGPROBLEM_HPP_
#define _ZOLTAN2_MAPPINGPROBLEM_HPP_

#include <Zoltan2_Standards.hpp>

#include <Zoltan2_Problem.hpp>
#include <Zoltan2_MappingSolution.hpp>
#include <Zoltan2_PartitioningSolution.hpp>
#include <Zoltan2_MachineRepresentation.hpp>

#include <Zoltan2_AlgBlockMapping.hpp>
#include <Zoltan2_TaskMapping.hpp>
#include <string>

namespace Zoltan2{

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

/*! \brief MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
 *
 *  The MappingProblem is the core of the Zoltan2 mappin API.
 *  Based on the the user's input and parameters, the MappingProblem
 *  sets up a computational Model, and a Solution object.  When the user
 *  calls the solve() method, the MappingProblem runs the algorithm,
 *  after which the Solution object may be obtained by the user.
 *
 *  The template parameter is the InputAdapter containing the data that
 *  is to be partitioned.
 */

template<typename Adapter, 
         typename MachineRep =   // Default MachineRep type
                  MachineRepresentation<typename Adapter::scalar_t,
                                        typename Adapter::part_t> >
class MappingProblem : 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::part_t part_t;
  typedef typename Adapter::base_adapter_t base_adapter_t;

  typedef PartitioningSolution<Adapter> partsoln_t;
  typedef MappingSolution<Adapter> mapsoln_t;

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

  /*! \brief Constructor that takes an Teuchos communicator
   */
  MappingProblem(Adapter *A_, Teuchos::ParameterList *p_,
                 const Teuchos::RCP<const Teuchos::Comm<int> > &ucomm_,
                 partsoln_t *partition_ = NULL, MachineRep *machine_ = NULL) : 
    Problem<Adapter>(A_, p_, ucomm_) 
  {
    HELLO;
    createMappingProblem(partition_, machine_);
  };

#ifdef HAVE_ZOLTAN2_MPI
  /*! \brief Constructor that takes an MPI communicator
   */
  MappingProblem(Adapter *A_, Teuchos::ParameterList *p_, 
                 MPI_Comm mpicomm_,
                 partsoln_t *partition_ = NULL, MachineRep *machine_ = NULL) :
  MappingProblem(A_, p_,
                 rcp<const Comm<int> >(new Teuchos::MpiComm<int>(
                                           Teuchos::opaqueWrapper(mpicomm_))),
                 partition_, machine_)
  {}
#endif

  //!  \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 Set up validators specific to this Problem
  */
  static void getValidParameters(ParameterList & pl)
  {
    MachineRepresentation <typename Adapter::scalar_t,typename Adapter::part_t>::getValidParameters(pl);
    RCP<Teuchos::StringValidator> mapping_algorithm_Validator =
      Teuchos::rcp( new Teuchos::StringValidator(
        Teuchos::tuple<std::string>( "geometric", "default", "block" )));
    pl.set("mapping_algorithm", "default", "mapping algorithm",
      mapping_algorithm_Validator);


    // bool parameter
    pl.set("distributed_input_adapter", true,
        "Whether the input adapter for mapping is distributed over processes or not",
        Environment::getBoolValidator());

    // bool parameter
    pl.set("divide_prime_first", false,
        "When partitioning into-non power of two, whether to partition for nonpowers of two at the beginning, or at the end",
        Environment::getBoolValidator());

    //TODO: This should be positive integer validator.
    pl.set("ranks_per_node", 1,
        "The number of MPI ranks per node",
        Environment::getAnyIntValidator());
    pl.set("reduce_best_mapping", true,
        "If true, nodes will calculate different mappings with rotations, and best one will be reduced. If not, the result will be the one with longest dimension partitioning.",
        Environment::getBoolValidator());
  }

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

  mapsoln_t *getSolution() { return soln.getRawPtr(); };
  Teuchos::RCP<MachineRep> getMachine(){return machine; }
private:
  void createMappingProblem(partsoln_t *partition_, MachineRep *machine_);

  Teuchos::RCP<mapsoln_t> soln;

  Teuchos::RCP<partsoln_t> partition;
  Teuchos::RCP<MachineRep> machine;
};

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

template <typename Adapter, typename MachineRep>
void MappingProblem<Adapter, MachineRep>::createMappingProblem(
  partsoln_t *partition_,
  MachineRep *machine_)
{
  HELLO;

  // Save pointer to user's partitioning solution.  If not provided, create one.

  if (partition_) {
    // User provided a partitioning solution; use it.
    partition = Teuchos::rcp(partition_, false);
  }
  else {
    // User did not provide a partitioning solution;
    // Use input adapter to create a "fake" solution with the input partition.

    partition = rcp(new partsoln_t(this->env_, this->comm_,
                                   this->inputAdapter_->getNumWeightsPerID()));
    size_t nLocal = this->inputAdapter_->getLocalNumIDs();

    const part_t *inputPartsView = NULL;
    this->inputAdapter_->getPartsView(inputPartsView);
    if (nLocal && inputPartsView == NULL) {
      // User has not provided input parts in input adapter
      int me = this->comm_->getRank();
      ArrayRCP<part_t> inputParts = arcp(new part_t[nLocal], 0, nLocal, true);
      for (size_t i = 0; i < nLocal; i++) inputParts[i] = me;
      partition->setParts(inputParts);
    }
    else {
      // User has provided input parts; use those.
      ArrayRCP<part_t> inputParts = arcp(const_cast<part_t *>(inputPartsView),
                                         0, nLocal, false);
      partition->setParts(inputParts);
    }
  }

  // Save pointer to user's machine.  If not provided, create one.
  if (machine_) 
    machine = Teuchos::rcp(machine_, false);
  else {
    try {
      Teuchos::ParameterList pl = this->env_->getParameters();

      machine = Teuchos::rcp(new MachineRep(*(this->comm_), pl));
    }
    Z2_FORWARD_EXCEPTIONS;
  }
}

////////////////////////////////////////////////////////////////////////
template <typename Adapter, typename MachineRep>
void MappingProblem<Adapter, MachineRep>::solve(bool newData)
{
  HELLO;


  // Determine which algorithm to use based on defaults and parameters.
  std::string algName("block");  

  Teuchos::ParameterList pl = this->env_->getParametersNonConst();
  const Teuchos::ParameterEntry *pe = pl.getEntryPtr("mapping_algorithm");
  if (pe) algName = pe->getValue<std::string>(&algName);

  try {
    if (algName == "default") {
      throw(NotImplemented(__FILE__, __LINE__, __func__zoltan2__));
#ifdef KDDKDD_NOT_READH
      this->algorithm_ = rcp(new AlgDefaultMapping<Adapter,MachineRep>(
                                                   this->comm_, machine,
                                                   this->inputAdapter_,
                                                   partition, this->envConst_));
      this->soln = rcp(new mapsoln_t(this->env_, this->comm_, this->algorithm_));
      this->algorithm_->map(this->soln);
#endif
    }
    else if (algName == "block") {
      this->algorithm_ = rcp(new AlgBlockMapping<Adapter,MachineRep>(
                                                 this->comm_, machine,
                                                 this->inputAdapter_,
                                                 partition, this->envConst_));
      this->soln = rcp(new mapsoln_t(this->env_, this->comm_, this->algorithm_));
      this->algorithm_->map(this->soln);
    }
    else if (algName == "geometric") {

      bool is_input_distributed = true;
      const Teuchos::ParameterEntry *pe_input_adapter = pl.getEntryPtr("distributed_input_adapter");
      if (pe_input_adapter) is_input_distributed = pe_input_adapter->getValue<bool>(&is_input_distributed);


      int ranks_per_node = 1;
      pe_input_adapter = pl.getEntryPtr("ranks_per_node");
      if (pe_input_adapter) ranks_per_node = pe_input_adapter->getValue<int>(&ranks_per_node);

      bool divide_prime_first = false;
      pe_input_adapter = pl.getEntryPtr("divide_prime_first");
      if (pe_input_adapter) divide_prime_first = pe_input_adapter->getValue<bool>(&divide_prime_first);

      bool reduce_best_mapping = true;
      pe_input_adapter = pl.getEntryPtr("reduce_best_mapping");
      if (pe_input_adapter) reduce_best_mapping = pe_input_adapter->getValue<bool>(&reduce_best_mapping);



      this->algorithm_ = 
            rcp(new CoordinateTaskMapper<Adapter,part_t>(this->comm_,
                                                         machine, 
                                                         this->inputAdapter_,
                                                         partition,
                                                         this->envConst_,
                                                         is_input_distributed, ranks_per_node, divide_prime_first, reduce_best_mapping));
      this->soln = rcp(new mapsoln_t(this->env_, this->comm_, this->algorithm_));
      this->algorithm_->map(this->soln);

    }
    else {
      // Add other mapping methods here
      throw std::logic_error("specified mapping_algorithm not supported");
    }
  }
  Z2_FORWARD_EXCEPTIONS;
}

} //namespace Zoltan2

#endif

#ifdef KDDKDD
Case 1
MappingProblem(
  InputAdapter
  partitioningSolution
  MachineRepresentation=NULL
// KDD Don't know how to properly template MachineRepresentation.  Proper types
// KDD probably depend on how it is to be used.  I imagine MJ needs 
// KDD pcoord_t to be scalar_t, right?  But how does user know that at the
// KDD time he calls this constructor?
)
{
  // Create MachineRepresentation if not provided
  // User would have called partitioning problem and provides a solution
  // Mapping vertices are the parts from the partitioning solution
  // Create MappingSolution that can return getRankForPart(part)
}


Case 2
MappingProblem(
  InputAdapter
  MachineRepresentation=NULL
)
{
  // Create MachineRepresentation if not provided
  // Compute mapping vertices based on InputAdapter's partition
  // Assuming input adapter's partition should be used.
  // KDD would use with Exodus/Nemesis input files or PamGen meshes

}


Case 3
MappingProblem(
  InputAdapter
  MachineRepresentation=NULL
)
{
  // Create MachineRepresentation if not provided
  // Call a partitioning algorithm to get mapping vertices that are the parts
  // Mapping vertices are computed from this internal partitioning solution
  // Maybe relevant models can be shared.
  // Similar to what's in PartitioningProblem now and to what LibTopoMap does

}


Case 4
MappingProblem(
  InputAdapter
  MachineRepresentation=NULL
)
{
  // Create MachineRepresentation if not provided
  // Call mapping with mapping vertices == IDs from the input adapter.
  // Similar in spirit to previous case, but runs more slowly since current
  // task mapping is done in serial.
  // Mehmet has done experiments with Scotch, comparing case 3 with 4.
  // Case 3 is faster; case 4 has higher quality.


}


In general, the applyPartitioningSolution method should take an 
optional MappingSolution.

Should MappingSolution provide a re-numbered communicator reflecting the new mapping?

#endif