Zoltan2
AllParameters.cpp
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 //
46 // Testing parameters. Serial test.
47 
48 #include <Zoltan2_config.h>
49 #include <Zoltan2_Environment.hpp>
50 #include <Teuchos_ParameterList.hpp>
51 #include <Teuchos_DefaultComm.hpp>
52 #include <string>
53 
54 using namespace std;
55 using std::cout;
56 using std::cerr;
57 using std::endl;
58 using std::string;
59 
60 //
61 // For all parameters:
62 // parameter name, a valid value, an invalid value
63 
64 // FileNameValidator - a number is invalid
65 
66 #define NUMFN 3
67 static string fnParams[NUMFN][3]={
68  {"debug_output_file", "temp.txt", "5"},
69  {"timer_output_file", "timerInfo.txt", "10.3"},
70  {"memory_output_file", "memory.txt", "3.33"}
71 };
72 
73 // Value value is any integer - a string is invalid
74 
75 #define NUMANYINT 2
76 static string anyIntParams[NUMANYINT][3]={
77  {"bisection_num_test_cuts", "3", "dont_know"},
78  {"parallel_part_calculation_count", "2", "dont_know"}
79 };
80 
81 // Value value is a particular string
82 
83 #define NUMSTR 31
84 static string strParams[NUMSTR][3]={
85  {"error_check_level", "basic_assertions", "invalid_assertion_request"},
86  {"debug_level", "basic_status", "bogus_status"},
87  {"timer_type", "no_timers", "invalid_timers"},
88  {"debug_output_stream", "cout", "invalid_stream"},
89  {"timer_output_stream", "/dev/null", "invalid_stream"},
90  {"memory_output_stream", "cerr", "invalid_stream"},
91  {"debug_procs", "all", "not_a_valid_list_of_any_type"},
92  {"pqParts", "2,3,4", "not_a_valid_list_of_any_type"},
93  {"memory_procs", "2-10", "not_a_valid_list_of_any_type"},
94  {"speed_versus_quality", "balance", "amazing_performance"},
95  {"memory_versus_speed", "memory", "impossible_performance"},
96  {"random_seed", "9.999", "xxx"},
97  {"order_method", "rcm", "rcmNew"},
98  {"order_package", "amd", "amdNew"},
99  {"compute_metrics", "yes", "maybe"},
100  {"topology", "2,3,6", "I_don't_know"},
101  {"randomize_input", "1", "22"},
102  {"partitioning_objective", "balance_object_weight", "get_curry"},
103  {"imbalance_tolerance", "1.1", "intolerant"},
104  {"num_global_parts", "12", "xxx"},
105  {"num_local_parts", "1", "no_idea"},
106  {"partitioning_approach", "repartition", "cut_it_up"},
107  {"objects_to_partition", "graph_vertices", "nothing"},
108  {"model", "graph", "manifold"},
109  {"algorithm", "rcb", "xyz"},
110  {"rectilinear", "yes", "dont_know"},
111  {"average_cuts", "false", "dont_know"},
112  {"symmetrize_input", "transpose", "dont_know"},
113  {"subset_graph", "1", "dont_know"},
114  {"force_binary_search", "true", "dont_know"},
115  {"force_linear_search", "yes", "dont_know"}
116 };
117 
118 
119 template <typename T>
120 int testInvalidValue( Teuchos::ParameterList &pl,
121  string paramName, T badValue)
122 {
123  Teuchos::ParameterList validParameters;
124  pl.set(paramName, badValue);
125  cout << endl;
126  cout << paramName << " = " << badValue << endl;
127 
128  bool failed = false;
129  try{
130  Zoltan2::createValidatorList(pl, validParameters);
131  pl.validateParametersAndSetDefaults(validParameters);
132  }
133  catch(std::exception &e){
134  cout << "Correctly generated an error:" << endl;
135  cout << e.what() << endl;
136  failed = true;
137  }
138 
139  if (!failed){
140  cerr << "Bad parameter was not detected in parameter list." << endl;
141  return 1;
142  }
143  return 0;
144 }
145 
146  // Print out all the documentation
147 
148 int main(int argc, char *argv[])
149 {
150  Teuchos::GlobalMPISession session(&argc, &argv);
151  Teuchos::RCP<const Teuchos::Comm<int> > comm =
152  Teuchos::DefaultComm<int>::getComm();
153 
154  int rank = comm->getRank();
155 
156  if (rank > 0)
157  return 0;
158 
159  // Create a valid parameter list.
160 
161  Teuchos::ParameterList validParameters;
162  Teuchos::ParameterList myParams("testParameterList");
163 
164  for (int i=0; i < NUMSTR; i++){
165  myParams.set(strParams[i][0], strParams[i][1]);
166  }
167 
168  for (int i=0; i < NUMANYINT; i++){
169  istringstream iss(anyIntParams[i][1]);
170  int paramValue;
171  iss >> paramValue;
172  myParams.set(anyIntParams[i][0], paramValue);
173  }
174 
175  for (int i=0; i < NUMFN; i++){
176  myParams.set(fnParams[i][0], fnParams[i][1]);
177  }
178 
179  Teuchos::ParameterList origParams(myParams);
180 
181  // Normally an application would not call this. The
182  // Environment object will validate the entered parameters.
183 
184  try{
185  Zoltan2::createValidatorList(myParams, validParameters);
186  myParams.validateParametersAndSetDefaults(validParameters);
188  }
189  catch(std::exception &e){
190  std::cerr << "Validate parameters generated an error:" << endl;
191  std::cerr << e.what() << endl;
192  std::cerr << "FAIL" << endl;
193  return 1;
194  }
195 
196  cout << endl;
197  cout << "Parameters after validation: " << endl;
198  cout << myParams << endl;
199 
200  // Try invalid parameter values
201 
202  for (int i=0; i < NUMSTR; i++){
203  Teuchos::ParameterList badParams(origParams);
204  int fail =
205  testInvalidValue<string>(badParams, strParams[i][0], strParams[i][2]);
206  if (fail){
207  cout << "FAIL" << endl;
208  return 1;
209  }
210  }
211 
212  for (int i=0; i < NUMANYINT; i++){
213  Teuchos::ParameterList badParams(origParams);
214  int fail =
215  testInvalidValue<string>(badParams, anyIntParams[i][0], anyIntParams[i][2]);
216  if (fail){
217  cout << "FAIL" << endl;
218  return 1;
219  }
220  }
221 
222  for (int i=0; i < NUMFN; i++){
223  Teuchos::ParameterList badParams(origParams);
224  istringstream iss(fnParams[i][2]);
225  double badVal;
226  iss >> badVal;
227  int fail =
228  testInvalidValue<double>(badParams, fnParams[i][0], badVal);
229  if (fail){
230  cout << "FAIL" << endl;
231  return 1;
232  }
233  }
234 
235 
236  // Print out all the documentation
237 
238  cout << endl;
239  cout << "Parameter documentation:" << endl;
240  Zoltan2::printListDocumentation(validParameters, cout, std::string());
241 
242  cout << "PASS" << endl;
243  return 0;
244 }
paramName
Definition: xml2dox.py:207
#define NUMANYINT
static string anyIntParams[NUMANYINT][3]
void createValidatorList(const Teuchos::ParameterList &plIn, Teuchos::ParameterList &plOut)
Create a list by adding validators to the users parameter list.
static void convertStringToInt(Teuchos::ParameterList &params)
Convert parameters of type Teuchos::StringToIntegralParameterEntryValidator<int> to integer...
#define NUMSTR
void printListDocumentation(const Teuchos::ParameterList &pl, std::ostream &os, std::string listNames)
static string fnParams[NUMFN][3]
int main(int argc, char *argv[])
static const std::string fail
#define NUMFN
Defines the Environment class.
int testInvalidValue(Teuchos::ParameterList &pl, string paramName, T badValue)
static string strParams[NUMSTR][3]