49 #ifndef _ZOLTAN2_ENVIRONMENT_CPP_ 50 #define _ZOLTAN2_ENVIRONMENT_CPP_ 56 #include <Teuchos_StandardParameterEntryValidators.hpp> 57 #include <Teuchos_RCP.hpp> 78 int level, std::string fname,
int ost,
79 Teuchos::RCP<DebugManager> &mgr)
84 std::ofstream *dbgFile =
new std::ofstream;
89 dbgFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
91 catch(std::exception &e){
92 throw std::runtime_error(e.what());
95 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, *dbgFile, lvl));
102 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, std::cout, lvl));
104 mgr = Teuchos::rcp(
new DebugManager(rank, iPrint, std::cerr, lvl));
106 mgr = Teuchos::rcp(
new DebugManager(rank,
false, std::cout, lvl));
113 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm):
114 myRank_(comm->getRank()), numProcs_(comm->getSize()), comm_(comm),
116 unvalidatedParams_(problemParams), params_(problemParams),
117 debugOut_(), timerOut_(), timingOn_(false), memoryOut_(), memoryOn_(false),
128 unvalidatedParams_(
"emptyList"), params_(
"emptyList"),
129 debugOut_(), timerOut_(), timingOn_(false), memoryOut_(), memoryOn_(false),
132 comm_ = Teuchos::DefaultComm<int>::getComm();
144 if (!memoryOutputFile_.is_null())
145 memoryOutputFile_->close();
150 return Teuchos::rcp(
new Teuchos::BoolParameterEntryValidator() );
154 RCP<Teuchos::AnyNumberParameterEntryValidator>
157 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes allTypes;
158 RCP<Teuchos::AnyNumberParameterEntryValidator> any_number_validator =
159 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
160 Teuchos::AnyNumberParameterEntryValidator::PREFER_DOUBLE, allTypes) );
161 return any_number_validator;
165 RCP<Teuchos::AnyNumberParameterEntryValidator>
168 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes typesNoDoubles;
169 typesNoDoubles.allowDouble(
false);
170 RCP<Teuchos::AnyNumberParameterEntryValidator> int_string_validator =
171 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
172 Teuchos::AnyNumberParameterEntryValidator::PREFER_INT, typesNoDoubles) );
173 return int_string_validator;
181 pl.setName(
"zoltan2ValidatingParameters");
184 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
185 error_check_level_Validator = Teuchos::rcp(
186 new Teuchos::StringToIntegralParameterEntryValidator<int>(
187 Teuchos::tuple<std::string>(
"no_assertions",
"basic_assertions",
188 "complex_assertions",
"debug_mode_assertions" ),
189 Teuchos::tuple<std::string>(
"no assertions will be performed",
190 "typical checks of argument validity",
191 "additional checks, i.e. is input graph a valid graph)",
192 "check for everything including logic errors (slowest)" ),
193 Teuchos::tuple<int>( 0, 1, 2, 3 ),
"error_check_level") );
194 pl.set(
"error_check_level",
"basic_assertions",
"the amount of error checking" 195 " performed (If the compile flag Z2_OMIT_ALL_ERROR_CHECKING was set, then " 196 "error checking code is not executed at runtime.)",
197 error_check_level_Validator);
200 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
201 debug_level_Validator = Teuchos::rcp(
202 new Teuchos::StringToIntegralParameterEntryValidator<int>(
203 Teuchos::tuple<std::string>(
"no_status",
"basic_status",
204 "detailed_status",
"verbose_detailed_status" ),
205 Teuchos::tuple<std::string>(
"library outputs no status information",
206 "library outputs basic status information",
207 "library outputs detailed information",
208 "library outputs very detailed information" ),
209 Teuchos::tuple<int>( 0, 1, 2, 3 ),
211 pl.set(
"debug_level",
"basic_status",
"the amount of status/debugging/warning" 212 " information to print",
213 debug_level_Validator);
216 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
217 timer_type_Validator = Teuchos::rcp(
new 218 Teuchos::StringToIntegralParameterEntryValidator<int>(
219 Teuchos::tuple<std::string>(
"no_timers",
"macro_timers",
220 "micro_timers",
"both_timers",
"test_timers" ),
221 Teuchos::tuple<std::string>(
"No timing data will be collected ",
222 "Time an algorithm (or other entity) as a whole.",
223 "Time the substeps of an entity.",
"Run both MACRO and MICRO timers.",
224 "Run timers added to code for testing, removed later" ),
225 Teuchos::tuple<int>( 0, 1, 2, 3, 4 ),
227 pl.set(
"timer_type",
"no_timers",
" the type of timing information to " 228 "collect (If the compile flag Z2_OMIT_ALL_PROFILING was set, then the " 229 "timing code is not executed at runtime.)",
230 timer_type_Validator);
233 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
234 output_stream_Validator = Teuchos::rcp(
235 new Teuchos::StringToIntegralParameterEntryValidator<int>(
236 Teuchos::tuple<std::string>(
"std::cout",
"cout",
"stdout",
237 "std::cerr",
"cerr",
"stderr",
"/dev/null",
"null" ),
239 Teuchos::tuple<std::string>(
"",
"",
"",
"",
"",
"",
"",
"" ),
240 Teuchos::tuple<int>( 0, 0, 0, 1, 1, 1, 2, 2 ),
243 pl.set(
"debug_output_stream",
"cout",
244 "output stream for debug/status/warning messages",
245 output_stream_Validator);
247 pl.set(
"timer_output_stream",
"cout",
248 "output stream for timing report",
249 output_stream_Validator);
251 pl.set(
"memory_output_stream",
"cout",
252 "output stream for memory usage messages",
253 output_stream_Validator);
256 RCP<Teuchos::FileNameValidator> file_not_required_validator =
257 Teuchos::rcp(
new Teuchos::FileNameValidator(
false) );
260 pl.set(
"memory_output_file",
"/dev/null",
261 "name of file to which memory profiling information should " 262 "be written (process rank will be included in file name)",
263 file_not_required_validator);
266 pl.set(
"timer_output_file",
"/dev/null",
"name of file to which " 267 "timing information should be written (process rank will be " 268 "included in file name)", file_not_required_validator);
271 pl.set(
"debug_output_file",
"/dev/null",
"name of file to which debug/status" 272 " messages should be written (process rank will be included in file name)",
273 file_not_required_validator);
275 const bool bUnsortedFalse =
false;
276 RCP<Zoltan2::IntegerRangeListValidator<int>> procs_Validator =
280 pl.set(
"debug_procs",
"0",
"list of ranks that output debugging/status " 281 "messages", procs_Validator);
284 pl.set(
"memory_procs",
"0",
"list of ranks that do memory profiling " 285 "information", procs_Validator);
288 void Environment::commitParameters()
290 using Teuchos::Array;
291 using Teuchos::ParameterList;
293 bool emptyList = (params_.begin() == params_.end());
297 ParameterList validParams;
314 params_.validateParametersAndSetDefaults(validParams, 0);
329 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES 331 std::string &fname = params_.get<std::string>(
"debug_output_file",
Z2_UNSET_STRING);
341 const Array<int> *reporters =
342 params_.getPtr<Array<int> >(
"debug_procs");
349 catch (std::exception &e){
350 std::ostringstream oss;
351 oss <<
myRank_ <<
": unable to create debug output manager";
352 oss <<
" (" << e.what() <<
")";
353 throw std::runtime_error(oss.str());
359 #ifndef Z2_OMIT_ALL_PROFILING 365 const Array<int> *reporters2 =
366 params_.getPtr<Array<int> >(
"memory_procs");
368 bool doMemory =
true;
376 Teuchos::broadcast<int, long>(*
comm_, 0, 1, &numKbytes);
384 std::string(
"Warning: memory profiling requested but not available."));
398 makeMetricOutputManager<long>(
myRank_, iPrint, f2, os2, memoryOut_,
399 std::string(
"KB"), 10, memoryOutputFile_);
401 catch (std::exception &e){
402 std::ostringstream oss;
403 oss <<
myRank_ <<
": unable to create memory profiling output manager";
404 oss <<
" (" << e.what() <<
")";
405 throw std::runtime_error(oss.str());
412 #ifdef Z2_OMIT_ALL_ERROR_CHECKING 422 using Teuchos::ParameterList;
423 using Teuchos::ParameterEntry;
425 using Teuchos::rcp_dynamic_cast;
426 ParameterList::ConstIterator next = params.begin();
430 std::string validatorNameInt(
"StringIntegralValidator(int)");
431 std::string validatorNameBool(
"StringIntegralValidator(bool)");
432 typedef Teuchos::StringToIntegralParameterEntryValidator<int> s2int_t;
434 while (next != params.end()){
436 const std::string &name = next->first;
437 ParameterEntry &entry = params.getEntry(name);
440 ParameterList *dummy = NULL;
441 ParameterList &pl = entry.getValue<ParameterList>(dummy);
445 if ((entry.validator()).
get()){
446 if (entry.validator()->getXMLTypeName() == validatorNameInt){
447 std::string dummy(
"");
448 std::string &entryValue = entry.getValue<std::string>(&dummy);
449 RCP<const s2int_t> s2int =
450 Teuchos::rcp_dynamic_cast<
const s2int_t>(entry.validator(),
true);
451 int val = s2int->getIntegralValue(entryValue);
452 entry.setValue<
int>(val);
Environment()
Default Constructor.
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.
void createValidatorList(const Teuchos::ParameterList &plIn, Teuchos::ParameterList &plOut)
Create a list by adding validators to the users parameter list.
static void convertStringToInt(Teuchos::ParameterList ¶ms)
Convert parameters of type Teuchos::StringToIntegralParameterEntryValidator<int> to integer...
/dev/null: do actions but don't output results
void debug(MessageOutputLevel level, const char *msg) const
Send a message to the debug output manager.
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.
int numProcs_
number of processes (relative to comm_)
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.
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