Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
paramTest.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 
58 #include <Teuchos_ParameterList.hpp>
59 #include <Teuchos_XMLObject.hpp>
60 #include <Teuchos_XMLParameterListWriter.hpp>
61 #include <Teuchos_ParameterXMLFileReader.hpp>
62 #include <Teuchos_ValidatorXMLConverterDB.hpp>
63 
64 #include <Teuchos_StandardParameterEntryValidators.hpp>
65 #include <Zoltan2_Parameters.hpp>
67 
68 #include <iostream>
69 #include <fstream>
70 #include <sstream>
71 #include <string>
72 
73 using Teuchos::RCP;
74 using Teuchos::rcp;
75 using Teuchos::tuple;
76 
77 using std::string;
78 
79 int main()
80 {
81  // Create a parameter list with each validator type that we use.
82 
83  Teuchos::ParameterList pl("pl");
84 
85  {
86  string parameterName("speed_versus_quality");
87  RCP<const Teuchos::StringValidator> strValidatorP =
88  rcp(new Teuchos::StringValidator(
89  tuple<string>("speed", "balance", "quality")));
90  std::ostringstream docString;
91  strValidatorP->printDoc(
92  "When algorithm choices exist, opt for speed or solution quality?\n"
93  "(Default is a balance of speed and quality)\n",
94  docString);
95  pl.set<string>(parameterName, "balance", docString.str(), strValidatorP);
96  }
97 
98  {
99  string parameterName("debug_output_file");
100  RCP<const Teuchos::FileNameValidator > fnameValidatorP =
101  fnameValidatorP = rcp(new Teuchos::FileNameValidator(false));
102  std::ostringstream docString;
103  fnameValidatorP->printDoc(
104  "name of file to which debug/status messages should be written\n"
105  "(process rank will be included in file name)\n",
106  docString);
107  pl.set<string>(parameterName, "/dev/null", docString.str(),
108  fnameValidatorP);
109  }
110 
111  {
112  string parameterName("random_seed");
113  RCP<const Teuchos::AnyNumberParameterEntryValidator> anyNumValidatorP =
114  rcp(new Teuchos::AnyNumberParameterEntryValidator);
115  std::ostringstream docString;
116  anyNumValidatorP->printDoc("random seed\n", docString);
117  pl.set<string>(parameterName, "0.5", docString.str(), anyNumValidatorP);
118  }
119 
120  {
121  string parameterName("debug_level");
122  RCP<const Teuchos::StringToIntegralParameterEntryValidator<int> >
123  str2intValidatorP =
124  rcp(new Teuchos::StringToIntegralParameterEntryValidator<int>(
125  tuple<string>("no_status",
126  "basic_status",
127  "detailed_status",
128  "verbose_detailed_status"),
129 
130  tuple<string>(
131  "library outputs no status information",
132  "library outputs basic status information (default)",
133  "library outputs detailed information",
134  "library outputs very detailed information"),
135 
136  tuple<int>(0, 1, 2, 3),
137 
138  parameterName));
139 
140  string info("the amount of status/warning/debugging info printed\n");
141  info.append("(If the compile flag Z2_OMIT_ALL_STATUS_MESSAGES was set,\n");
142  info.append("then message output code is not executed at runtime.)\n");
143 
144  std::ostringstream docString;
145  str2intValidatorP->printDoc(info, docString);
146  pl.set<string>(parameterName, "basic_status", docString.str(),
147  str2intValidatorP);
148  }
149 
150  {
151  string parameterName("debug_procs");
153  RCP<const irl_t> intRangeValidatorP = rcp(new irl_t);
154  std::ostringstream docString;
155  intRangeValidatorP->printDoc(
156  "list of ranks that output debugging/status messages (default \"0\")\n",
157  docString);
158  pl.set<string>(parameterName, "0", docString.str(), intRangeValidatorP);
159 
160  // An XML converter for irl_t only needs to be added once to the converter db.
161 
163  RCP<irlConverter_t > converter = rcp(new irlConverter_t);
164  Teuchos::ValidatorXMLConverterDB::addConverter(
165  intRangeValidatorP, // can be a dummy of this type
166  converter);
167  }
168 
169  // Write out to XML
170  Teuchos::XMLParameterListWriter plw;
171  Teuchos::XMLObject obj = plw.toXML(pl);
172 
173  std::cout << "Parameter list: " << std::endl;
174  std::cout << obj << std::endl;
175 
176  std::ofstream of;
177  of.open("params.xml");
178  of << obj << std::endl;
179  of.close();
180 
181  // Read parameter list in from XML file.
182 
183  Teuchos::ParameterXMLFileReader rdr("params.xml");
184  Teuchos::ParameterList newpl = rdr.getParameters();
185  Teuchos::XMLObject objnew = plw.toXML(newpl);
186 
187  std::cout << "After reading in from XML file: " << std::endl;
188  std::cout << objnew << std::endl;
189 }
190 
Defines Parameter related enumerators, declares functions.
XML conversion code for IntegerRangeListValidator.
int main(int narg, char **arg)
Definition: coloring1.cpp:199
A ParameterList validator for integer range lists.
Define IntegerRangeList validator.