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 // 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 integer range list parameters. Serial test.
12 
13 #include <Zoltan2_config.h>
14 #include <Zoltan2_Environment.hpp>
16 #include <Teuchos_ParameterList.hpp>
17 #include <Teuchos_DefaultComm.hpp>
18 #include <Teuchos_Array.hpp>
19 #include <Teuchos_ParameterEntryValidator.hpp>
20 
21 typedef Teuchos::Array<int> rangeList_t;
22 
23 int main(int narg, char *arg[])
24 {
25  Tpetra::ScopeGuard tscope(&narg, &arg);
26  Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
27 
28  int rank = comm->getRank();
29 
30  if (rank > 0)
31  return 0;
32 
33  // Set a few parameters, and then validate them.
34 
35  Teuchos::ParameterList validParameters;
36 
37  Teuchos::ParameterList myParams("testParameterList");
38 
39  myParams.set("debug_level", "detailed_status");
40  myParams.set("debug_procs", "all");
41  myParams.set("debug_output_stream", "std::cout");
42 
43  myParams.set("timer_output_file", "appPerformance.txt");
44 
45  // Normally an application would not call this. The
46  // Environment object will validate the entered parameters.
47  // Since debug_procs is an IntegerRangeList,
48  // this call will convert it to a Teuchos::Array that uses
49  // a special flag to indicate "all" or "none".
50 
51  try{
52  Zoltan2::createValidatorList(myParams, validParameters);
53  myParams.validateParametersAndSetDefaults(validParameters);
54  }
55  catch(std::exception &e){
56  std::cerr << "Validate parameters generated an error:" << std::endl;
57  std::cerr << e.what() << std::endl;
58  std::cerr << "FAIL" << std::endl;
59  return 1;
60  }
61 
62  validParameters = Teuchos::ParameterList();
63 
64  std::cout << std::endl;
65  std::cout << "A few parameters after validation: " << std::endl;
66  std::cout << myParams << std::endl;
67 
68  rangeList_t *a1 = myParams.getPtr<rangeList_t>("debug_procs");
69  std::cout << "debug_procs translation: ";
70  Zoltan2::printIntegralRangeList(std::cout, *a1);
71  std::cout << std::endl;
72 
73  // Now let's enter a bad value for a parameter and make sure
74  // we get an error.
75 
76  Teuchos::ParameterList faultyParams("badParameterList");
77  faultyParams.set("debug_procs", "not-even-remotely-an-integer-range");
78  bool failed = false;
79  try{
80  Zoltan2::createValidatorList(faultyParams, validParameters);
81  faultyParams.validateParametersAndSetDefaults(validParameters);
82  }
83  catch(std::exception &e){
84  std::cout << std::endl;
85  std::cout << "Invalid parameter correctly generated an error:" << std::endl;
86  std::cout << e.what() << std::endl;
87  failed = true;
88  }
89 
90  validParameters = Teuchos::ParameterList();
91 
92  if (!failed){
93  std::cerr << "Bad parameter was not detected in parameter list." << std::endl;
94  return 1;
95  }
96 
97  // Now set every parameter to a reasonable value
98 
99  Teuchos::ParameterList all("setAllParametersList");
100  all.set("debug_level", "basic_status");
101 
102  all.set("debug_procs", "1,2,5-10,2");
103  all.set("memory_procs", "1,2,3,4,all");
104 
105  all.set("debug_output_stream", "std::cerr");
106  all.set("timer_output_stream", "std::cout");
107  all.set("memory_output_stream", "/dev/null");
108 
109 
110  all.set("debug_output_file", "/home/me/debug.txt");
111  all.set("timer_output_file", "/home/me/performance.txt");
112  all.set("memory_output_file", "/home/me/memoryUsed.txt");
113 
114  all.set("error_check_level", "basic_assertions");
115 
116  all.set("partitioning_objective", "minimize_cut_edge_weight");
117 
118  all.set("imbalance_tolerance", 1.2);
119 
120  all.set("num_global_parts", 12);
121  all.set("num_local_parts", 2);
122 
123  all.set("partitioning_approach", "partition");
124 
125  all.set("objects_to_partition", "graph_vertices");
126 
127  all.set("model", "hypergraph");
128 
129  all.set("algorithm", "phg");
130 
131  all.set("symmetrize_input", "no");
132  all.set("subset_graph", false); // bool parameter
133 
134  try{
135  Zoltan2::createValidatorList(all, validParameters);
136  all.validateParametersAndSetDefaults(validParameters);
137  }
138  catch(std::exception &e){
139  std::cerr << "Validate parameters generated an error:" << std::endl;
140  std::cerr << e.what() << std::endl;
141  std::cerr << "FAIL" << std::endl;
142  return 1;
143  }
144 
145  std::cout << std::endl;
146  std::cout << "All parameters validated and modified: ";
147  std::cout << all << std::endl;
148 
149  a1 = all.getPtr<rangeList_t>("debug_procs");
150  std::cout << "debug_procs translation: ";
151  Zoltan2::printIntegralRangeList(std::cout, *a1);
152  std::cout << std::endl;
153 
154  a1 = all.getPtr<rangeList_t>("memory_procs");
155  std::cout << "memory_procs translation: ";
156  Zoltan2::printIntegralRangeList(std::cout, *a1);
157  std::cout << std::endl;
158 
159  // Print out all the documentation
160 
161  std::cout << std::endl;
162  std::cout << "Parameter documentation:" << std::endl;
163  Zoltan2::printListDocumentation(validParameters, std::cout, std::string());
164 
165  std::cout << "PASS" << std::endl;
166  return 0;
167 }
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:164
void printListDocumentation(const Teuchos::ParameterList &pl, std::ostream &os, std::string listNames)
Teuchos::Array< int > rangeList_t
Definition: Parameters.cpp:21
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.