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