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),
127 myRank_(comm->getRank()), numProcs_(comm->getSize()), comm_(comm),
129 unvalidatedParams_(
"emptyList"), params_(
"emptyList"),
130 debugOut_(), timerOut_(), timingOn_(false), memoryOut_(), memoryOn_(false),
141 if (!memoryOutputFile_.is_null())
142 memoryOutputFile_->close();
147 params_ = problemParams;
153 return Teuchos::rcp(
new Teuchos::BoolParameterEntryValidator() );
157 RCP<Teuchos::AnyNumberParameterEntryValidator>
160 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes allTypes;
161 RCP<Teuchos::AnyNumberParameterEntryValidator> any_number_validator =
162 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
163 Teuchos::AnyNumberParameterEntryValidator::PREFER_DOUBLE, allTypes) );
164 return any_number_validator;
168 RCP<Teuchos::AnyNumberParameterEntryValidator>
171 Teuchos::AnyNumberParameterEntryValidator::AcceptedTypes typesNoDoubles;
172 typesNoDoubles.allowDouble(
false);
173 RCP<Teuchos::AnyNumberParameterEntryValidator> int_string_validator =
174 Teuchos::rcp(
new Teuchos::AnyNumberParameterEntryValidator(
175 Teuchos::AnyNumberParameterEntryValidator::PREFER_INT, typesNoDoubles) );
176 return int_string_validator;
184 pl.setName(
"zoltan2ValidatingParameters");
187 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
188 error_check_level_Validator = Teuchos::rcp(
189 new Teuchos::StringToIntegralParameterEntryValidator<int>(
190 Teuchos::tuple<std::string>(
"no_assertions",
"basic_assertions",
191 "complex_assertions",
"debug_mode_assertions" ),
192 Teuchos::tuple<std::string>(
"no assertions will be performed",
193 "typical checks of argument validity",
194 "additional checks, i.e. is input graph a valid graph)",
195 "check for everything including logic errors (slowest)" ),
196 Teuchos::tuple<int>( 0, 1, 2, 3 ),
"error_check_level") );
197 pl.set(
"error_check_level",
"basic_assertions",
"the amount of error checking"
198 " performed (If the compile flag Z2_OMIT_ALL_ERROR_CHECKING was set, then "
199 "error checking code is not executed at runtime.)",
200 error_check_level_Validator);
203 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
204 debug_level_Validator = Teuchos::rcp(
205 new Teuchos::StringToIntegralParameterEntryValidator<int>(
206 Teuchos::tuple<std::string>(
"no_status",
"basic_status",
207 "detailed_status",
"verbose_detailed_status" ),
208 Teuchos::tuple<std::string>(
"library outputs no status information",
209 "library outputs basic status information",
210 "library outputs detailed information",
211 "library outputs very detailed information" ),
212 Teuchos::tuple<int>( 0, 1, 2, 3 ),
214 pl.set(
"debug_level",
"basic_status",
"the amount of status/debugging/warning"
215 " information to print",
216 debug_level_Validator);
219 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
220 timer_type_Validator = Teuchos::rcp(
new
221 Teuchos::StringToIntegralParameterEntryValidator<int>(
222 Teuchos::tuple<std::string>(
"no_timers",
"macro_timers",
223 "micro_timers",
"both_timers",
"test_timers" ),
224 Teuchos::tuple<std::string>(
"No timing data will be collected ",
225 "Time an algorithm (or other entity) as a whole.",
226 "Time the substeps of an entity.",
"Run both MACRO and MICRO timers.",
227 "Run timers added to code for testing, removed later" ),
228 Teuchos::tuple<int>( 0, 1, 2, 3, 4 ),
230 pl.set(
"timer_type",
"no_timers",
" the type of timing information to "
231 "collect (If the compile flag Z2_OMIT_ALL_PROFILING was set, then the "
232 "timing code is not executed at runtime.)",
233 timer_type_Validator);
236 RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
237 output_stream_Validator = Teuchos::rcp(
238 new Teuchos::StringToIntegralParameterEntryValidator<int>(
239 Teuchos::tuple<std::string>(
"std::cout",
"cout",
"stdout",
240 "std::cerr",
"cerr",
"stderr",
"/dev/null",
"null" ),
242 Teuchos::tuple<std::string>(
"",
"",
"",
"",
"",
"",
"",
"" ),
243 Teuchos::tuple<int>( 0, 0, 0, 1, 1, 1, 2, 2 ),
246 pl.set(
"debug_output_stream",
"cout",
247 "output stream for debug/status/warning messages",
248 output_stream_Validator);
250 pl.set(
"timer_output_stream",
"cout",
251 "output stream for timing report",
252 output_stream_Validator);
254 pl.set(
"memory_output_stream",
"cout",
255 "output stream for memory usage messages",
256 output_stream_Validator);
259 RCP<Teuchos::FileNameValidator> file_not_required_validator =
260 Teuchos::rcp(
new Teuchos::FileNameValidator(
false) );
263 pl.set(
"memory_output_file",
"/dev/null",
264 "name of file to which memory profiling information should "
265 "be written (process rank will be included in file name)",
266 file_not_required_validator);
269 pl.set(
"timer_output_file",
"/dev/null",
"name of file to which "
270 "timing information should be written (process rank will be "
271 "included in file name)", file_not_required_validator);
274 pl.set(
"debug_output_file",
"/dev/null",
"name of file to which debug/status"
275 " messages should be written (process rank will be included in file name)",
276 file_not_required_validator);
278 const bool bUnsortedFalse =
false;
279 RCP<Zoltan2::IntegerRangeListValidator<int>> procs_Validator =
283 pl.set(
"debug_procs",
"0",
"list of ranks that output debugging/status "
284 "messages", procs_Validator);
287 pl.set(
"memory_procs",
"0",
"list of ranks that do memory profiling "
288 "information", procs_Validator);
291 void Environment::commitParameters()
293 using Teuchos::Array;
294 using Teuchos::ParameterList;
296 bool emptyList = (params_.begin() == params_.end());
300 ParameterList validParams;
317 params_.validateParametersAndSetDefaults(validParams, 0);
332 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
334 std::string &fname = params_.get<std::string>(
"debug_output_file",
Z2_UNSET_STRING);
344 const Array<int> *reporters =
345 params_.getPtr<Array<int> >(
"debug_procs");
352 catch (std::exception &e){
353 std::ostringstream oss;
354 oss <<
myRank_ <<
": unable to create debug output manager";
355 oss <<
" (" << e.what() <<
")";
356 throw std::runtime_error(oss.str());
362 #ifndef Z2_OMIT_ALL_PROFILING
368 const Array<int> *reporters2 =
369 params_.getPtr<Array<int> >(
"memory_procs");
371 bool doMemory =
true;
379 Teuchos::broadcast<int, long>(*
comm_, 0, 1, &numKbytes);
387 std::string(
"Warning: memory profiling requested but not available."));
396 iPrint = (myRank_ == 0);
401 makeMetricOutputManager<long>(
myRank_, iPrint, f2, os2, memoryOut_,
402 std::string(
"KB"), 10, memoryOutputFile_);
404 catch (std::exception &e){
405 std::ostringstream oss;
406 oss << myRank_ <<
": unable to create memory profiling output manager";
407 oss <<
" (" << e.what() <<
")";
408 throw std::runtime_error(oss.str());
415 #ifdef Z2_OMIT_ALL_ERROR_CHECKING
425 using Teuchos::ParameterList;
426 using Teuchos::ParameterEntry;
428 using Teuchos::rcp_dynamic_cast;
429 ParameterList::ConstIterator next = params.begin();
433 std::string validatorNameInt(
"StringIntegralValidator(int)");
434 std::string validatorNameBool(
"StringIntegralValidator(bool)");
435 typedef Teuchos::StringToIntegralParameterEntryValidator<int> s2int_t;
437 while (next != params.end()){
439 const std::string &name = next->first;
440 ParameterEntry &entry = params.getEntry(name);
443 ParameterList *dummy = NULL;
444 ParameterList &pl = entry.getValue<ParameterList>(dummy);
448 if ((entry.validator()).
get()){
449 if (entry.validator()->getXMLTypeName() == validatorNameInt){
450 std::string dummy(
"");
451 std::string &entryValue = entry.getValue<std::string>(&dummy);
452 RCP<const s2int_t> s2int =
453 Teuchos::rcp_dynamic_cast<
const s2int_t>(entry.validator(),
true);
454 int val = s2int->getIntegralValue(entryValue);
455 entry.setValue<
int>(val);
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.
static void convertStringToInt(Teuchos::ParameterList ¶ms)
Convert parameters of type Teuchos::StringToIntegralParameterEntryValidator<int> to integer...
/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