14 #ifndef _ZOLTAN2_ENVIRONMENT_CPP_
15 #define _ZOLTAN2_ENVIRONMENT_CPP_
21 #include <Teuchos_StandardParameterEntryValidators.hpp>
22 #include <Teuchos_RCP.hpp>
43 int level, std::string
fname,
int ost,
44 Teuchos::RCP<DebugManager> &mgr)
49 std::ofstream *dbgFile =
new std::ofstream;
54 dbgFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
56 catch(std::exception &e){
57 throw std::runtime_error(e.what());
60 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, *dbgFile, lvl));
67 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, std::cout, lvl));
69 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, std::cerr, lvl));
71 mgr = Teuchos::rcp(
new DebugManager(rank,
false, std::cout, lvl));
78 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm):
79 myRank_(comm->getRank()), numProcs_(comm->getSize()), comm_(comm),
81 unvalidatedParams_(problemParams), params_(problemParams),
82 debugOut_(), timerOut_(), timingOn_(false), memoryOut_(), memoryOn_(false),
92 myRank_(comm->getRank()), numProcs_(comm->getSize()), comm_(comm),
94 unvalidatedParams_(
"emptyList"), params_(
"emptyList"),
95 debugOut_(), timerOut_(), timingOn_(false), memoryOut_(), memoryOn_(false),
106 if (!memoryOutputFile_.is_null())
107 memoryOutputFile_->close();
112 params_ = problemParams;
118 return Teuchos::rcp(
new Teuchos::BoolParameterEntryValidator() );
122 RCP<Teuchos::AnyNumberParameterEntryValidator>
125 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes allTypes;
126 RCP<Teuchos::AnyNumberParameterEntryValidator> any_number_validator =
127 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
128 Teuchos::AnyNumberParameterEntryValidator::PREFER_DOUBLE, allTypes) );
129 return any_number_validator;
133 RCP<Teuchos::AnyNumberParameterEntryValidator>
136 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes typesNoDoubles;
137 typesNoDoubles.allowDouble(
false);
138 RCP<Teuchos::AnyNumberParameterEntryValidator> int_string_validator =
139 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
140 Teuchos::AnyNumberParameterEntryValidator::PREFER_INT, typesNoDoubles) );
141 return int_string_validator;
149 pl.setName(
"zoltan2ValidatingParameters");
152 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
153 error_check_level_Validator = Teuchos::rcp(
154 new Teuchos::StringToIntegralParameterEntryValidator<int>(
155 Teuchos::tuple<std::string>(
"no_assertions",
"basic_assertions",
156 "complex_assertions",
"debug_mode_assertions" ),
157 Teuchos::tuple<std::string>(
"no assertions will be performed",
158 "typical checks of argument validity",
159 "additional checks, i.e. is input graph a valid graph)",
160 "check for everything including logic errors (slowest)" ),
161 Teuchos::tuple<int>( 0, 1, 2, 3 ),
"error_check_level") );
162 pl.set(
"error_check_level",
"basic_assertions",
"the amount of error checking"
163 " performed (If the compile flag Z2_OMIT_ALL_ERROR_CHECKING was set, then "
164 "error checking code is not executed at runtime.)",
165 error_check_level_Validator);
168 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
169 debug_level_Validator = Teuchos::rcp(
170 new Teuchos::StringToIntegralParameterEntryValidator<int>(
171 Teuchos::tuple<std::string>(
"no_status",
"basic_status",
172 "detailed_status",
"verbose_detailed_status" ),
173 Teuchos::tuple<std::string>(
"library outputs no status information",
174 "library outputs basic status information",
175 "library outputs detailed information",
176 "library outputs very detailed information" ),
177 Teuchos::tuple<int>( 0, 1, 2, 3 ),
179 pl.set(
"debug_level",
"basic_status",
"the amount of status/debugging/warning"
180 " information to print",
181 debug_level_Validator);
184 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
185 timer_type_Validator = Teuchos::rcp(
new
186 Teuchos::StringToIntegralParameterEntryValidator<int>(
187 Teuchos::tuple<std::string>(
"no_timers",
"macro_timers",
188 "micro_timers",
"both_timers",
"test_timers" ),
189 Teuchos::tuple<std::string>(
"No timing data will be collected ",
190 "Time an algorithm (or other entity) as a whole.",
191 "Time the substeps of an entity.",
"Run both MACRO and MICRO timers.",
192 "Run timers added to code for testing, removed later" ),
193 Teuchos::tuple<int>( 0, 1, 2, 3, 4 ),
195 pl.set(
"timer_type",
"no_timers",
" the type of timing information to "
196 "collect (If the compile flag Z2_OMIT_ALL_PROFILING was set, then the "
197 "timing code is not executed at runtime.)",
198 timer_type_Validator);
201 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
202 output_stream_Validator = Teuchos::rcp(
203 new Teuchos::StringToIntegralParameterEntryValidator<int>(
204 Teuchos::tuple<std::string>(
"std::cout",
"cout",
"stdout",
205 "std::cerr",
"cerr",
"stderr",
"/dev/null",
"null" ),
207 Teuchos::tuple<std::string>(
"",
"",
"",
"",
"",
"",
"",
"" ),
208 Teuchos::tuple<int>( 0, 0, 0, 1, 1, 1, 2, 2 ),
211 pl.set(
"debug_output_stream",
"cout",
212 "output stream for debug/status/warning messages",
213 output_stream_Validator);
215 pl.set(
"timer_output_stream",
"cout",
216 "output stream for timing report",
217 output_stream_Validator);
219 pl.set(
"memory_output_stream",
"cout",
220 "output stream for memory usage messages",
221 output_stream_Validator);
224 RCP<Teuchos::FileNameValidator> file_not_required_validator =
225 Teuchos::rcp(
new Teuchos::FileNameValidator(
false) );
228 pl.set(
"memory_output_file",
"/dev/null",
229 "name of file to which memory profiling information should "
230 "be written (process rank will be included in file name)",
231 file_not_required_validator);
234 pl.set(
"timer_output_file",
"/dev/null",
"name of file to which "
235 "timing information should be written (process rank will be "
236 "included in file name)", file_not_required_validator);
239 pl.set(
"debug_output_file",
"/dev/null",
"name of file to which debug/status"
240 " messages should be written (process rank will be included in file name)",
241 file_not_required_validator);
243 const bool bUnsortedFalse =
false;
244 RCP<Zoltan2::IntegerRangeListValidator<int>> procs_Validator =
248 pl.set(
"debug_procs",
"0",
"list of ranks that output debugging/status "
249 "messages", procs_Validator);
252 pl.set(
"memory_procs",
"0",
"list of ranks that do memory profiling "
253 "information", procs_Validator);
256 void Environment::commitParameters()
258 using Teuchos::Array;
259 using Teuchos::ParameterList;
261 bool emptyList = (params_.begin() == params_.end());
265 ParameterList validParams;
282 params_.validateParametersAndSetDefaults(validParams, 0);
292 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
304 const Array<int> *reporters =
305 params_.getPtr<Array<int> >(
"debug_procs");
312 catch (std::exception &e){
313 std::ostringstream oss;
314 oss <<
myRank_ <<
": unable to create debug output manager";
315 oss <<
" (" << e.what() <<
")";
316 throw std::runtime_error(oss.str());
322 #ifndef Z2_OMIT_ALL_PROFILING
328 const Array<int> *reporters2 =
329 params_.getPtr<Array<int> >(
"memory_procs");
331 bool doMemory =
true;
339 Teuchos::broadcast<int, long>(*
comm_, 0, 1, &numKbytes);
347 std::string(
"Warning: memory profiling requested but not available."));
356 iPrint = (myRank_ == 0);
361 makeMetricOutputManager<long>(
myRank_, iPrint, f2, os2, memoryOut_,
362 std::string(
"KB"), 10, memoryOutputFile_);
364 catch (std::exception &e){
365 std::ostringstream oss;
366 oss << myRank_ <<
": unable to create memory profiling output manager";
367 oss <<
" (" << e.what() <<
")";
368 throw std::runtime_error(oss.str());
375 #ifdef Z2_OMIT_ALL_ERROR_CHECKING
fast typical checks for valid arguments
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
MessageOutputLevel
The amount of debugging or status output to print.
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
void makeDebugManager(int rank, bool iPrint, int level, std::string fname, int ost, Teuchos::RCP< DebugManager > &mgr)
Create an output manager for debugging or status information.
Environment(Teuchos::ParameterList &problemParams, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor.
void createValidatorList(const Teuchos::ParameterList &plIn, Teuchos::ParameterList &plOut)
Create a list by adding validators to the users parameter list.
/dev/null: do actions but don't output results
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyDoubleValidator()
Exists to make setting up validators less cluttered.
long getProcessKilobytes()
AssertionLevel
Level of error checking or assertions desired.
A ParameterList validator for integer range lists.
void debug(MessageOutputLevel level, const char *msg) const
Send a message to the debug output manager.
no assertion checks will be done
int myRank_
mpi rank (relative to comm_)
OSType
Output stream types.
Comm_t comm_
communicator for environment
static void getValidParameters(ParameterList &pl)
Collect the paramaters specific to Environment.
void addNumberToFileName(int number, std::string fname, std::string &newf)
Helper method to add number to a file name.
#define Z2_UNSET_STRING
A value to indicate a string parameter that was not set by the user.
bool IsInRangeList(const Integral val, const Teuchos::Array< Integral > &valList, bool sorted=true)
A helper function that determines if a value is in the list.
void resetParameters(Teuchos::ParameterList &problemParams)
resetParameters and validate them - preserve the comm
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyIntValidator()
Exists to make setting up validators less cluttered.
the status at each high level step
~Environment()
Destructor.
Define IntegerRangeList validator.
DebugManager contains the methods that perform output of debug and status messages.
Defines the Environment class.
A gathering of useful namespace methods.
AssertionLevel errorCheckLevel_
level of error checking to do