Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
AllParameters.cpp
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
//
11
// Testing parameters. Serial test.
12
13
#include <Zoltan2_config.h>
14
#include <
Zoltan2_Environment.hpp
>
15
#include <Teuchos_ParameterList.hpp>
16
#include <Teuchos_DefaultComm.hpp>
17
#include <string>
18
19
using
std::string;
20
21
//
22
// For all parameters:
23
// parameter name, a valid value, an invalid value
24
25
// FileNameValidator - a number is invalid
26
27
#define NUMFN 3
28
static
string
fnParams
[
NUMFN
][3]={
29
{
"debug_output_file"
,
"temp.txt"
,
"5"
},
30
{
"timer_output_file"
,
"timerInfo.txt"
,
"10.3"
},
31
{
"memory_output_file"
,
"memory.txt"
,
"3.33"
}
32
};
33
34
// Value is a particular string
35
#ifdef HAVE_ZOLTAN2_PULP
36
#define NUMSTR 38
37
#else
38
#define NUMSTR 35
39
#endif
40
41
static
string
strParams
[
NUMSTR
][3]={
42
{
"error_check_level"
,
"basic_assertions"
,
"invalid_assertion_request"
},
43
{
"debug_level"
,
"basic_status"
,
"invalid_status"
},
44
{
"timer_type"
,
"no_timers"
,
"invalid_timers"
},
45
{
"debug_output_stream"
,
"std::cout"
,
"invalid_stream"
},
46
{
"timer_output_stream"
,
"/dev/null"
,
"invalid_stream"
},
47
{
"memory_output_stream"
,
"std::cerr"
,
"invalid_stream"
},
48
{
"debug_procs"
,
"all"
,
"not_a_valid_list_of_any_type"
},
49
{
"mj_parts"
,
"2,3,4"
,
"not_a_valid_list_of_any_type"
},
50
{
"memory_procs"
,
"2-10"
,
"not_a_valid_list_of_any_type"
},
51
{
"order_method"
,
"rcm"
,
"invalid_method"
},
52
{
"order_method_type"
,
"local"
,
"invalid_method_type"
},
53
{
"order_package"
,
"amd"
,
"invalid_package"
},
54
{
"partitioning_objective"
,
"balance_object_weight"
,
"invalid_objective"
},
55
{
"partitioning_approach"
,
"repartition"
,
"invalid_approach"
},
56
{
"objects_to_partition"
,
"graph_vertices"
,
"invalid_objects"
},
57
{
"model"
,
"graph"
,
"invalid_model"
},
58
{
"algorithm"
,
"rcb"
,
"invalid_algorithm"
},
59
{
"symmetrize_input"
,
"transpose"
,
"invalid_option"
},
60
{
"symmetrize_input"
,
"transpose"
,
"invalid_option"
},
61
{
"mj_concurrent_part_count"
,
"0"
,
"invalid_value"
},
// AnyNumberParameterEntryValidator
62
{
"mj_recursion_depth"
,
"0"
,
"invalid_value"
},
// AnyNumberParameterEntryValidator
63
{
"mapping_type"
,
"0"
,
"invalid_value"
},
// AnyNumberParameterEntryValidator
64
{
"imbalance_tolerance"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
65
{
"mj_minimum_migration_imbalance"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
66
#ifdef HAVE_ZOLTAN2_PULP
67
{
"pulp_vert_imbalance"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
68
{
"pulp_edge_imbalance"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
69
{
"pulp_imbalance"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
70
#endif
// HAVE_ZOLTAN2_PULP
71
{
"scotch_imbalance_ratio"
,
"1.1"
,
"invalid_option"
},
// AnyNumberParameterEntryValidator
72
{
"compute_metrics"
,
"false"
,
"invalid_bool_setting"
},
// BoolParameterEntryValidator - accepts true/false/"true"/"false"
73
{
"rectilinear"
,
"false"
,
"invalid_bool_setting"
},
// BoolParameterEntryValidator - accepts true/false/"true"/"false"
74
{
"subset_graph"
,
"false"
,
"invalid_bool_setting"
},
// BoolParameterEntryValidator - accepts true/false/"true"/"false"
75
{
"mj_enable_rcb"
,
"true"
,
"invalid_bool_setting"
},
// BoolParameterEntryValidator - accepts true/false/"true"/"false"
76
{
"mj_keep_part_boxes"
,
"true"
,
"invalid_bool_setting"
},
// BoolParameterEntryValidator - accepts true/false/"true"/"false"
77
{
"num_global_parts"
,
"1"
,
"invalid_value"
},
// EnhancedNumberValidator
78
{
"num_local_parts"
,
"0"
,
"invalid_value"
},
// EnhancedNumberValidator
79
{
"mj_premigration_option"
,
"1"
,
"invalid_value"
},
// EnhancedNumberValidator
80
{
"mj_migration_option"
,
"2"
,
"invalid_value"
},
// EnhancedNumberValidator
81
{
"mj_num_teams"
,
"60"
,
"invalid_value"
},
// EnhancedNumberValidator
82
};
83
84
template
<
typename
T>
85
int
testInvalidValue
( Teuchos::ParameterList &pl,
86
string
paramName, T badValue)
87
{
88
Teuchos::ParameterList validParameters;
89
pl.set(paramName, badValue);
90
std::cout << std::endl;
91
std::cout << paramName <<
" = "
<< badValue << std::endl;
92
93
bool
failed =
false
;
94
try
{
95
Zoltan2::createValidatorList
(pl, validParameters);
96
pl.validateParametersAndSetDefaults(validParameters);
97
}
98
catch
(std::exception &e){
99
std::cout <<
"Correctly generated an error:"
<< std::endl;
100
std::cout << e.what() << std::endl;
101
failed =
true
;
102
}
103
104
if
(!failed){
105
std::cerr <<
"Bad parameter value was not detected in parameter list."
<< std::endl;
106
return
1;
107
}
108
return
0;
109
}
110
111
// this we can remove later
112
// kept here temporarily for reference
113
int
testForIssue612
()
114
{
115
// Testing AnyNumberParameterEntryValidator
116
117
// Create a parameter list
118
Teuchos::ParameterList valid(
"valid parameter list"
);
119
120
// Create parameter using validator
121
typedef
Teuchos::AnyNumberParameterEntryValidator validator_t;
122
Teuchos::RCP<const validator_t> anyNumVal = Teuchos::rcp(
new
validator_t);
123
125
// Initial test: set parameter to 0.5 in valid parameter list.
126
// Need to use the *expected* data type here.
127
std::cout <<
"set good default value"
<< std::endl;
128
129
std::string parameterName(
"parameterName"
);
130
try
{
131
valid.set(parameterName, 5.0,
"parameterDoc"
, anyNumVal);
132
}
133
catch
(std::exception &e) {
134
std::cout <<
"FAIL error setting good default value "
135
<< e.what() << std::endl;
136
return
-1;
137
}
138
139
double
dd = valid.getEntry(parameterName).getValue<
double
>(&dd);
140
std::cout <<
"good default value <double> = "
<< dd << std::endl;
141
142
// User creates his own parameter list and passes things of various types.
143
// The user list must be validated against the valid list.
144
Teuchos::ParameterList user(
"user"
);
145
146
// This one should work
147
std::cout <<
"test good user value"
<< std::endl;
148
user.set(parameterName,
"0.123"
);
149
try
{
150
user.validateParametersAndSetDefaults(valid);
151
}
152
catch
(std::exception &e) {
153
std::cout <<
"FAIL "
<< e.what() << std::endl;
154
return
-1;
155
}
156
157
dd = user.getEntry(parameterName).getValue<
double
>(&dd);
158
std::cout <<
"good user value <double> = "
<< dd << std::endl;
159
160
// This one should not work; the user's string is not a number
161
std::cout <<
"test bogus user value"
<< std::endl;
162
bool
aok =
false
;
163
164
// MDM note - the fail point will now be on user.set
165
// std::stod will throw on this since we have added the validator
166
try
{
167
user.set(parameterName,
"bogus"
);
168
}
169
catch
(std::exception &e) {
170
// correct behavior
171
std::cout <<
"Parameter list correctly rejected bogus user value."
172
<< std::endl;
173
aok =
true
;
174
}
175
176
if
(!aok) {
177
std::cout <<
"FAIL parameter list accepted a bogus user value"
178
<< std::endl;
179
return
-1;
180
}
181
182
// Test the valid with a bogus default value. This operation should also
183
// not work. The validator should catch the bogus input.
184
std::cout <<
"set bogus default value"
<< std::endl;
185
186
std::string parameterNameToo(
"parameterNameToo"
);
187
aok =
false
;
188
try
{
189
valid.set(parameterNameToo,
"bogus"
,
"parameterDoc"
, anyNumVal);
190
}
191
catch
(std::exception &e) {
192
// correct behavior
193
std::cout <<
"Parameter list correctly rejected bogus default value."
194
<< std::endl;
195
aok =
true
;
196
}
197
198
if
(!aok) {
199
std::cout <<
"FAIL parameter list accepted a bogus default value"
200
<< std::endl;
201
return
-1;
202
}
203
204
std::cout <<
"PASS"
<< std::endl;
205
return
0;
206
}
207
208
// Print out all the documentation
209
210
int
main
(
int
narg,
char
*arg[])
211
{
212
Tpetra::ScopeGuard tscope(&narg, &arg);
213
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
214
215
int
rank = comm->getRank();
216
217
if
(rank > 0)
218
return
0;
219
220
// short term reference - to delete later
221
// this was an example proposed for issue #612
222
// just keeping it here as a reference point to be deleted in the future
223
int
tempTest =
testForIssue612
();
224
if
( tempTest != 0 ) {
225
return
tempTest;
226
}
227
228
// Create a valid parameter list.
229
230
Teuchos::ParameterList validParameters;
231
Teuchos::ParameterList myParams(
"testParameterList"
);
232
233
for
(
int
i=0; i <
NUMSTR
; i++){
234
myParams.set(
strParams
[i][0],
strParams
[i][1]);
235
}
236
237
for
(
int
i=0; i <
NUMFN
; i++){
238
myParams.set(
fnParams
[i][0],
fnParams
[i][1]);
239
}
240
241
Teuchos::ParameterList origParams(myParams);
242
243
// Normally an application would not call this. The
244
// Environment object will validate the entered parameters.
245
246
try
{
247
Zoltan2::createValidatorList
(myParams, validParameters);
248
myParams.validateParametersAndSetDefaults(validParameters);
249
}
250
catch
(std::exception &e){
251
std::cerr <<
"Validate parameters generated an error:"
<< std::endl;
252
std::cerr << e.what() << std::endl;
253
std::cerr <<
"FAIL"
<< std::endl;
254
return
1;
255
}
256
257
std::cout << std::endl;
258
std::cout <<
"Parameters after validation: "
<< std::endl;
259
std::cout << myParams << std::endl;
260
261
// Try invalid parameter values
262
for
(
int
i=0; i <
NUMSTR
; i++){
263
Teuchos::ParameterList badParams(origParams);
264
int
fail
=
265
testInvalidValue<string>
(badParams,
strParams
[i][0],
strParams
[i][2]);
266
if
(
fail
){
267
std::cout <<
"FAIL"
<< std::endl;
268
return
1;
269
}
270
}
271
272
for
(
int
i=0; i <
NUMFN
; i++){
273
Teuchos::ParameterList badParams(origParams);
274
std::istringstream iss(
fnParams
[i][2]);
275
double
badVal;
276
iss >> badVal;
277
int
fail
=
278
testInvalidValue<double>
(badParams,
fnParams
[i][0], badVal);
279
if
(
fail
){
280
std::cout <<
"FAIL"
<< std::endl;
281
return
1;
282
}
283
}
284
285
286
// Print out all the documentation
287
288
std::cout << std::endl;
289
std::cout <<
"Parameter documentation:"
<< std::endl;
290
Zoltan2::printListDocumentation
(validParameters, std::cout, std::string());
291
292
std::cout <<
"PASS"
<< std::endl;
293
return
0;
294
}
NUMFN
#define NUMFN
Definition
AllParameters.cpp:27
strParams
static string strParams[NUMSTR][3]
Definition
AllParameters.cpp:41
testInvalidValue
int testInvalidValue(Teuchos::ParameterList &pl, string paramName, T badValue)
Definition
AllParameters.cpp:85
fnParams
static string fnParams[NUMFN][3]
Definition
AllParameters.cpp:28
NUMSTR
#define NUMSTR
Definition
AllParameters.cpp:38
testForIssue612
int testForIssue612()
Definition
AllParameters.cpp:113
Zoltan2_Environment.hpp
Defines the Environment class.
main
int main()
Definition
absdefinitiontest.cpp:15
fail
static const std::string fail
Definition
findUniqueGids.cpp:45
Zoltan2::printListDocumentation
void printListDocumentation(const Teuchos::ParameterList &pl, std::ostream &os, std::string listNames)
Definition
Zoltan2_Parameters.cpp:131
Zoltan2::createValidatorList
void createValidatorList(const Teuchos::ParameterList &plIn, Teuchos::ParameterList &plOut)
Create a list by adding validators to the users parameter list.
Definition
Zoltan2_Parameters.cpp:115
test
core
unit
environment
AllParameters.cpp
Generated by
1.17.0