Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_AlgForTestingOnly.hpp
Go to the documentation of this file.
1
// @HEADER
2
//
3
// ***********************************************************************
4
//
5
// Zoltan2: A package of combinatorial algorithms for scientific computing
6
// Copyright 2012 Sandia Corporation
7
//
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Karen Devine (kddevin@sandia.gov)
39
// Erik Boman (egboman@sandia.gov)
40
// Siva Rajamanickam (srajama@sandia.gov)
41
//
42
// ***********************************************************************
43
//
44
// @HEADER
45
#ifndef _ZOLTAN2_ALGFORTESTINGONLY_HPP_
46
#define _ZOLTAN2_ALGFORTESTINGONLY_HPP_
47
48
#include <
Zoltan2_Algorithm.hpp
>
49
#include <
Zoltan2_PartitioningSolution.hpp
>
50
55
57
58
namespace
Zoltan2
{
59
60
template
<
typename
Adapter>
61
class
AlgForTestingOnly
:
public
Algorithm
<Adapter>
62
{
63
private
:
64
typedef
typename
Adapter::part_t part_t;
65
const
RCP<const Environment> env;
66
const
RCP<const Comm<int> > comm;
67
const
RCP<const typename Adapter::base_adapter_t> adapter;
68
69
public
:
70
71
AlgForTestingOnly
(
72
const
RCP<const Environment> &env__,
73
const
RCP<
const
Comm<int> > &problemComm__,
74
const
RCP<const typename Adapter::base_adapter_t> &adapter__):
75
env(env__), comm(problemComm__), adapter(adapter__)
76
{
77
}
78
81
static
void
getValidParameters
(ParameterList & pl)
82
{
83
RCP<Teuchos::EnhancedNumberValidator<int>> forTestingOnlyFlag_Validator =
84
Teuchos::rcp(
new
Teuchos::EnhancedNumberValidator<int>(0, 1000, 1, 0) );
85
pl.set(
"forTestingOnlyFlag"
, 0,
"Used only for testing; look at "
86
"Zoltan2_AlgForTestingOnly for interpretations"
,
87
forTestingOnlyFlag_Validator);
88
}
89
90
void
partition
(
const
RCP<
PartitioningSolution<Adapter>
> &solution)
91
{
92
size_t
nObj = adapter->getLocalNumIDs();
93
ArrayRCP<part_t> partList(
new
part_t[nObj], 0, nObj,
true
);
94
size_t
nGlobalParts = solution->getTargetGlobalNumberOfParts();
95
96
const
Teuchos::ParameterEntry *pe =
97
env->getParameters().getEntryPtr(
"forTestingOnlyFlag"
);
98
int
forTestingOnlyFlag = pe->getValue<
int
>(&forTestingOnlyFlag);
99
100
switch
(forTestingOnlyFlag) {
101
case
0:
102
// rank 0 has all objects in part 0
103
// all other ranks assign to {0, nGlobalParts-1, 0, nGlobalParts-1, ..}
104
if
(comm->getRank() == 0) {
105
for
(
size_t
i = 0; i < nObj; i++) partList[i] = 0;
106
}
107
else
{
108
for
(
size_t
i = 0; i < nObj; i++)
109
if
(i % 2) partList[i] = nGlobalParts - 1;
110
else
partList[i] = 0;
111
}
112
break
;
113
case
1:
114
// rank 0 has all objects in part 0
115
// all other ranks assign to {nGlobalParts-1, 0, nGlobalParts-1, 0, ..}
116
if
(comm->getRank() == 0) {
117
for
(
size_t
i = 0; i < nObj; i++) partList[i] = 0;
118
}
119
else
{
120
for
(
size_t
i = 0; i < nObj; i++)
121
if
(i % 2) partList[i] = 0;
122
else
partList[i] = nGlobalParts - 1;
123
}
124
break
;
125
default
:
126
throw
std::runtime_error(
"invalid forTestingOnlyFlag value"
);
127
}
128
129
std::cout << comm->getRank() <<
" forTestingOnly "
<< forTestingOnlyFlag
130
<<
" partList: "
;
131
for
(
size_t
i = 0; i < nObj; i++)
132
std::cout << partList[i] <<
" "
;
133
std::cout << std::endl;
134
135
solution->setParts(partList);
136
}
137
138
};
139
}
140
141
#endif
Zoltan2_Algorithm.hpp
Zoltan2_PartitioningSolution.hpp
Defines the PartitioningSolution class.
Zoltan2::AlgForTestingOnly::AlgForTestingOnly
AlgForTestingOnly(const RCP< const Environment > &env__, const RCP< const Comm< int > > &problemComm__, const RCP< const typename Adapter::base_adapter_t > &adapter__)
Definition
Zoltan2_AlgForTestingOnly.hpp:71
Zoltan2::AlgForTestingOnly::getValidParameters
static void getValidParameters(ParameterList &pl)
Set up validators specific to this algorithm.
Definition
Zoltan2_AlgForTestingOnly.hpp:81
Zoltan2::AlgForTestingOnly::partition
void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
Definition
Zoltan2_AlgForTestingOnly.hpp:90
Zoltan2::Algorithm
Algorithm defines the base class for all algorithms.
Definition
Zoltan2_Algorithm.hpp:78
Zoltan2::PartitioningSolution
A PartitioningSolution is a solution to a partitioning problem.
Definition
Zoltan2_PartitioningSolution.hpp:92
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:38
core
src
algorithms
Zoltan2_AlgForTestingOnly.hpp
Generated by
1.17.0