Zoltan2
Loading...
Searching...
No Matches
paramTest.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
22#include <Teuchos_ParameterList.hpp>
23#include <Teuchos_XMLObject.hpp>
24#include <Teuchos_XMLParameterListWriter.hpp>
25#include <Teuchos_ParameterXMLFileReader.hpp>
26#include <Teuchos_ValidatorXMLConverterDB.hpp>
27
28#include <Teuchos_StandardParameterEntryValidators.hpp>
31
32#include <iostream>
33#include <fstream>
34#include <sstream>
35#include <string>
36
37using Teuchos::RCP;
38using Teuchos::rcp;
39using Teuchos::tuple;
40
41using std::string;
42
43int main()
44{
45 // Create a parameter list with each validator type that we use.
46
47 Teuchos::ParameterList pl("pl");
48
49 {
50 string parameterName("speed_versus_quality");
51 RCP<const Teuchos::StringValidator> strValidatorP =
52 rcp(new Teuchos::StringValidator(
53 tuple<string>("speed", "balance", "quality")));
54 std::ostringstream docString;
55 strValidatorP->printDoc(
56 "When algorithm choices exist, opt for speed or solution quality?\n"
57 "(Default is a balance of speed and quality)\n",
58 docString);
59 pl.set<string>(parameterName, "balance", docString.str(), strValidatorP);
60 }
61
62 {
63 string parameterName("debug_output_file");
64 RCP<const Teuchos::FileNameValidator > fnameValidatorP =
65 fnameValidatorP = rcp(new Teuchos::FileNameValidator(false));
66 std::ostringstream docString;
67 fnameValidatorP->printDoc(
68 "name of file to which debug/status messages should be written\n"
69 "(process rank will be included in file name)\n",
70 docString);
71 pl.set<string>(parameterName, "/dev/null", docString.str(),
72 fnameValidatorP);
73 }
74
75 {
76 string parameterName("random_seed");
77 RCP<const Teuchos::AnyNumberParameterEntryValidator> anyNumValidatorP =
78 rcp(new Teuchos::AnyNumberParameterEntryValidator);
79 std::ostringstream docString;
80 anyNumValidatorP->printDoc("random seed\n", docString);
81 pl.set<string>(parameterName, "0.5", docString.str(), anyNumValidatorP);
82 }
83
84 {
85 string parameterName("debug_level");
86 RCP<const Teuchos::StringToIntegralParameterEntryValidator<int> >
87 str2intValidatorP =
88 rcp(new Teuchos::StringToIntegralParameterEntryValidator<int>(
89 tuple<string>("no_status",
90 "basic_status",
91 "detailed_status",
92 "verbose_detailed_status"),
93
94 tuple<string>(
95 "library outputs no status information",
96 "library outputs basic status information (default)",
97 "library outputs detailed information",
98 "library outputs very detailed information"),
99
100 tuple<int>(0, 1, 2, 3),
101
102 parameterName));
103
104 string info("the amount of status/warning/debugging info printed\n");
105 info.append("(If the compile flag Z2_OMIT_ALL_STATUS_MESSAGES was set,\n");
106 info.append("then message output code is not executed at runtime.)\n");
107
108 std::ostringstream docString;
109 str2intValidatorP->printDoc(info, docString);
110 pl.set<string>(parameterName, "basic_status", docString.str(),
111 str2intValidatorP);
112 }
113
114 {
115 string parameterName("debug_procs");
117 RCP<const irl_t> intRangeValidatorP = rcp(new irl_t);
118 std::ostringstream docString;
119 intRangeValidatorP->printDoc(
120 "list of ranks that output debugging/status messages (default \"0\")\n",
121 docString);
122 pl.set<string>(parameterName, "0", docString.str(), intRangeValidatorP);
123
124 // An XML converter for irl_t only needs to be added once to the converter db.
125
127 RCP<irlConverter_t > converter = rcp(new irlConverter_t);
128 Teuchos::ValidatorXMLConverterDB::addConverter(
129 intRangeValidatorP, // can be a dummy of this type
130 converter);
131 }
132
133 // Write out to XML
134 Teuchos::XMLParameterListWriter plw;
135 Teuchos::XMLObject obj = plw.toXML(pl);
136
137 std::cout << "Parameter list: " << std::endl;
138 std::cout << obj << std::endl;
139
140 std::ofstream of;
141 of.open("params.xml");
142 of << obj << std::endl;
143 of.close();
144
145 // Read parameter list in from XML file.
146
147 Teuchos::ParameterXMLFileReader rdr("params.xml");
148 Teuchos::ParameterList newpl = rdr.getParameters();
149 Teuchos::XMLObject objnew = plw.toXML(newpl);
150
151 std::cout << "After reading in from XML file: " << std::endl;
152 std::cout << objnew << std::endl;
153}
154
Define IntegerRangeList validator.
Defines Parameter related enumerators, declares functions.
XML conversion code for IntegerRangeListValidator.
A ParameterList validator for integer range lists.
int main()
Definition paramTest.cpp:43