Zoltan2
Parameters.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 integer range list parameters. Serial test.
47 
48 #include <Zoltan2_config.h>
49 #include <Zoltan2_Environment.hpp>
51 #include <Teuchos_ParameterList.hpp>
52 #include <Teuchos_DefaultComm.hpp>
53 #include <Teuchos_Array.hpp>
54 #include <Teuchos_ParameterEntryValidator.hpp>
55 
56 typedef Teuchos::Array<int> rangeList_t;
57 
58 int main(int argc, char *argv[])
59 {
60  Teuchos::GlobalMPISession session(&argc, &argv);
61  Teuchos::RCP<const Teuchos::Comm<int> > comm =
62  Teuchos::DefaultComm<int>::getComm();
63 
64  int rank = comm->getRank();
65 
66  if (rank > 0)
67  return 0;
68 
69  // Set a few parameters, and then validate them.
70 
71  Teuchos::ParameterList validParameters;
72 
73  Teuchos::ParameterList myParams("testParameterList");
74 
75  myParams.set("debug_level", "detailed_status");
76  myParams.set("debug_procs", "all");
77  myParams.set("debug_output_stream", "std::cout");
78 
79  myParams.set("timer_output_file", "appPerformance.txt");
80 
81  // Normally an application would not call this. The
82  // Environment object will validate the entered parameters.
83  // Since debug_procs is an IntegerRangeList,
84  // this call will convert it to a Teuchos::Array that uses
85  // a special flag to indicate "all" or "none".
86 
87  try{
88  Zoltan2::createValidatorList(myParams, validParameters);
89  myParams.validateParametersAndSetDefaults(validParameters);
91  }
92  catch(std::exception &e){
93  std::cerr << "Validate parameters generated an error:" << std::endl;
94  std::cerr << e.what() << std::endl;
95  std::cerr << "FAIL" << std::endl;
96  return 1;
97  }
98 
99  validParameters = Teuchos::ParameterList();
100 
101  std::cout << std::endl;
102  std::cout << "A few parameters after validation: " << std::endl;
103  std::cout << myParams << std::endl;
104 
105  rangeList_t *a1 = myParams.getPtr<rangeList_t>("debug_procs");
106  std::cout << "debug_procs translation: ";
107  Zoltan2::printIntegralRangeList(std::cout, *a1);
108  std::cout << std::endl;
109 
110  // Now let's enter a bad value for a parameter and make sure
111  // we get an error.
112 
113  Teuchos::ParameterList faultyParams("badParameterList");
114  faultyParams.set("debug_procs", "not-even-remotely-an-integer-range");
115  bool failed = false;
116  try{
117  Zoltan2::createValidatorList(faultyParams, validParameters);
118  faultyParams.validateParametersAndSetDefaults(validParameters);
119  }
120  catch(std::exception &e){
121  std::cout << std::endl;
122  std::cout << "Invalid parameter correctly generated an error:" << std::endl;
123  std::cout << e.what() << std::endl;
124  failed = true;
125  }
126 
127  validParameters = Teuchos::ParameterList();
128 
129  if (!failed){
130  std::cerr << "Bad parameter was not detected in parameter list." << std::endl;
131  return 1;
132  }
133 
134  // Now set every parameter to a reasonable value
135 
136  Teuchos::ParameterList all("setAllParametersList");
137  all.set("debug_level", "basic_status");
138 
139  all.set("debug_procs", "1,2,5-10,2");
140  all.set("memory_procs", "1,2,3,4,all");
141 
142  all.set("debug_output_stream", "std::cerr");
143  all.set("timer_output_stream", "std::cout");
144  all.set("memory_output_stream", "/dev/null");
145 
146 
147  all.set("debug_output_file", "/home/me/debug.txt");
148  all.set("timer_output_file", "/home/me/performance.txt");
149  all.set("memory_output_file", "/home/me/memoryUsed.txt");
150 
151  all.set("error_check_level", "basic_assertions");
152 
153  all.set("partitioning_objective", "minimize_cut_edge_weight");
154 
155  all.set("imbalance_tolerance", 1.2);
156 
157  all.set("num_global_parts", 12);
158  all.set("num_local_parts", 2);
159 
160  all.set("partitioning_approach", "partition");
161 
162  all.set("objects_to_partition", "graph_vertices");
163 
164  all.set("model", "hypergraph");
165 
166  all.set("algorithm", "phg");
167 
168  all.set("symmetrize_input", "no");
169  all.set("subset_graph", false); // bool parameter
170 
171  try{
172  Zoltan2::createValidatorList(all, validParameters);
173  all.validateParametersAndSetDefaults(validParameters);
175  }
176  catch(std::exception &e){
177  std::cerr << "Validate parameters generated an error:" << std::endl;
178  std::cerr << e.what() << std::endl;
179  std::cerr << "FAIL" << std::endl;
180  return 1;
181  }
182 
183  std::cout << std::endl;
184  std::cout << "All parameters validated and modified: ";
185  std::cout << all << std::endl;
186 
187  a1 = all.getPtr<rangeList_t>("debug_procs");
188  std::cout << "debug_procs translation: ";
189  Zoltan2::printIntegralRangeList(std::cout, *a1);
190  std::cout << std::endl;
191 
192  a1 = all.getPtr<rangeList_t>("memory_procs");
193  std::cout << "memory_procs translation: ";
194  Zoltan2::printIntegralRangeList(std::cout, *a1);
195  std::cout << std::endl;
196 
197  // Print out all the documentation
198 
199  std::cout << std::endl;
200  std::cout << "Parameter documentation:" << std::endl;
201  Zoltan2::printListDocumentation(validParameters, std::cout, std::string());
202 
203  std::cout << "PASS" << std::endl;
204  return 0;
205 }
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...
void printListDocumentation(const Teuchos::ParameterList &pl, std::ostream &os, std::string listNames)
Teuchos::Array< int > rangeList_t
Definition: Parameters.cpp:56
Define IntegerRangeList validator.
Defines the Environment class.
void printIntegralRangeList(std::ostream &os, Teuchos::Array< Integral > &irl)
A helper function that prints the meaning of an encoded integer range list.
int main(int argc, char *argv[])
Definition: Parameters.cpp:58