Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 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);
89  }
90  catch(std::exception &e){
91  std::cerr << "Validate parameters generated an error:" << std::endl;
92  std::cerr << e.what() << std::endl;
93  std::cerr << "FAIL" << std::endl;
94  return 1;
95  }
96 
97  validParameters = Teuchos::ParameterList();
98 
99  std::cout << std::endl;
100  std::cout << "A few parameters after validation: " << std::endl;
101  std::cout << myParams << std::endl;
102 
103  rangeList_t *a1 = myParams.getPtr<rangeList_t>("debug_procs");
104  std::cout << "debug_procs translation: ";
105  Zoltan2::printIntegralRangeList(std::cout, *a1);
106  std::cout << std::endl;
107 
108  // Now let's enter a bad value for a parameter and make sure
109  // we get an error.
110 
111  Teuchos::ParameterList faultyParams("badParameterList");
112  faultyParams.set("debug_procs", "not-even-remotely-an-integer-range");
113  bool failed = false;
114  try{
115  Zoltan2::createValidatorList(faultyParams, validParameters);
116  faultyParams.validateParametersAndSetDefaults(validParameters);
117  }
118  catch(std::exception &e){
119  std::cout << std::endl;
120  std::cout << "Invalid parameter correctly generated an error:" << std::endl;
121  std::cout << e.what() << std::endl;
122  failed = true;
123  }
124 
125  validParameters = Teuchos::ParameterList();
126 
127  if (!failed){
128  std::cerr << "Bad parameter was not detected in parameter list." << std::endl;
129  return 1;
130  }
131 
132  // Now set every parameter to a reasonable value
133 
134  Teuchos::ParameterList all("setAllParametersList");
135  all.set("debug_level", "basic_status");
136 
137  all.set("debug_procs", "1,2,5-10,2");
138  all.set("memory_procs", "1,2,3,4,all");
139 
140  all.set("debug_output_stream", "std::cerr");
141  all.set("timer_output_stream", "std::cout");
142  all.set("memory_output_stream", "/dev/null");
143 
144 
145  all.set("debug_output_file", "/home/me/debug.txt");
146  all.set("timer_output_file", "/home/me/performance.txt");
147  all.set("memory_output_file", "/home/me/memoryUsed.txt");
148 
149  all.set("error_check_level", "basic_assertions");
150 
151  all.set("partitioning_objective", "minimize_cut_edge_weight");
152 
153  all.set("imbalance_tolerance", 1.2);
154 
155  all.set("num_global_parts", 12);
156  all.set("num_local_parts", 2);
157 
158  all.set("partitioning_approach", "partition");
159 
160  all.set("objects_to_partition", "graph_vertices");
161 
162  all.set("model", "hypergraph");
163 
164  all.set("algorithm", "phg");
165 
166  all.set("symmetrize_input", "no");
167  all.set("subset_graph", false); // bool parameter
168 
169  try{
170  Zoltan2::createValidatorList(all, validParameters);
171  all.validateParametersAndSetDefaults(validParameters);
172  }
173  catch(std::exception &e){
174  std::cerr << "Validate parameters generated an error:" << std::endl;
175  std::cerr << e.what() << std::endl;
176  std::cerr << "FAIL" << std::endl;
177  return 1;
178  }
179 
180  std::cout << std::endl;
181  std::cout << "All parameters validated and modified: ";
182  std::cout << all << std::endl;
183 
184  a1 = all.getPtr<rangeList_t>("debug_procs");
185  std::cout << "debug_procs translation: ";
186  Zoltan2::printIntegralRangeList(std::cout, *a1);
187  std::cout << std::endl;
188 
189  a1 = all.getPtr<rangeList_t>("memory_procs");
190  std::cout << "memory_procs translation: ";
191  Zoltan2::printIntegralRangeList(std::cout, *a1);
192  std::cout << std::endl;
193 
194  // Print out all the documentation
195 
196  std::cout << std::endl;
197  std::cout << "Parameter documentation:" << std::endl;
198  Zoltan2::printListDocumentation(validParameters, std::cout, std::string());
199 
200  std::cout << "PASS" << std::endl;
201  return 0;
202 }
void createValidatorList(const Teuchos::ParameterList &plIn, Teuchos::ParameterList &plOut)
Create a list by adding validators to the users parameter list.
int main(int narg, char **arg)
Definition: coloring1.cpp:199
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.