Zoltan2
Loading...
Searching...
No Matches
Zoltan2_AlgForTestingOnly.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef _ZOLTAN2_ALGFORTESTINGONLY_HPP_
11#define _ZOLTAN2_ALGFORTESTINGONLY_HPP_
12
13#include <Zoltan2_Algorithm.hpp>
15
20
22
23namespace Zoltan2 {
24
25template <typename Adapter>
26class AlgForTestingOnly : public Algorithm<Adapter>
27{
28private:
29 typedef typename Adapter::part_t part_t;
30 const RCP<const Environment> env;
31 const RCP<const Comm<int> > comm;
32 const RCP<const typename Adapter::base_adapter_t> adapter;
33
34public:
35
37 const RCP<const Environment> &env__,
38 const RCP<const Comm<int> > &problemComm__,
39 const RCP<const typename Adapter::base_adapter_t> &adapter__):
40 env(env__), comm(problemComm__), adapter(adapter__)
41 {
42 }
43
46 static void getValidParameters(ParameterList & pl)
47 {
48 RCP<Teuchos::EnhancedNumberValidator<int>> forTestingOnlyFlag_Validator =
49 Teuchos::rcp( new Teuchos::EnhancedNumberValidator<int>(0, 1000, 1, 0) );
50 pl.set("forTestingOnlyFlag", 0, "Used only for testing; look at "
51 "Zoltan2_AlgForTestingOnly for interpretations",
52 forTestingOnlyFlag_Validator);
53 }
54
55 void partition(const RCP<PartitioningSolution<Adapter> > &solution)
56 {
57 size_t nObj = adapter->getLocalNumIDs();
58 ArrayRCP<part_t> partList(new part_t[nObj], 0, nObj, true);
59 size_t nGlobalParts = solution->getTargetGlobalNumberOfParts();
60
61 const Teuchos::ParameterEntry *pe =
62 env->getParameters().getEntryPtr("forTestingOnlyFlag");
63 int forTestingOnlyFlag = pe->getValue<int>(&forTestingOnlyFlag);
64
65 switch (forTestingOnlyFlag) {
66 case 0:
67 // rank 0 has all objects in part 0
68 // all other ranks assign to {0, nGlobalParts-1, 0, nGlobalParts-1, ..}
69 if (comm->getRank() == 0) {
70 for (size_t i = 0; i < nObj; i++) partList[i] = 0;
71 }
72 else {
73 for (size_t i = 0; i < nObj; i++)
74 if (i % 2) partList[i] = nGlobalParts - 1;
75 else partList[i] = 0;
76 }
77 break;
78 case 1:
79 // rank 0 has all objects in part 0
80 // all other ranks assign to {nGlobalParts-1, 0, nGlobalParts-1, 0, ..}
81 if (comm->getRank() == 0) {
82 for (size_t i = 0; i < nObj; i++) partList[i] = 0;
83 }
84 else {
85 for (size_t i = 0; i < nObj; i++)
86 if (i % 2) partList[i] = 0;
87 else partList[i] = nGlobalParts - 1;
88 }
89 break;
90 default:
91 throw std::runtime_error("invalid forTestingOnlyFlag value");
92 }
93
94 std::cout << comm->getRank() << " forTestingOnly " << forTestingOnlyFlag
95 << " partList: ";
96 for (size_t i = 0; i < nObj; i++)
97 std::cout << partList[i] << " ";
98 std::cout << std::endl;
99
100 solution->setParts(partList);
101 }
102
103};
104}
105
106#endif
Defines the PartitioningSolution class.
AlgForTestingOnly(const RCP< const Environment > &env__, const RCP< const Comm< int > > &problemComm__, const RCP< const typename Adapter::base_adapter_t > &adapter__)
static void getValidParameters(ParameterList &pl)
Set up validators specific to this algorithm.
void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
Algorithm defines the base class for all algorithms.
A PartitioningSolution is a solution to a partitioning problem.
Created by mbenlioglu on Aug 31, 2020.