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();
148 void Environment::commitParameters()
150 using Teuchos::Array;
151 using Teuchos::ParameterList;
153 bool emptyList = (params_.begin() == params_.end());
157 ParameterList validParams;
174 params_.validateParametersAndSetDefaults(validParams, 0);
189 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES 191 std::string &fname = params_.get<std::string>(
"debug_output_file",
Z2_UNSET_STRING);
201 const Array<int> *reporters =
202 params_.getPtr<Array<int> >(
"debug_procs");
209 catch (std::exception &e){
210 std::ostringstream oss;
211 oss <<
myRank_ <<
": unable to create debug output manager";
212 oss <<
" (" << e.what() <<
")";
213 throw std::runtime_error(oss.str());
219 #ifndef Z2_OMIT_ALL_PROFILING 225 const Array<int> *reporters2 =
226 params_.getPtr<Array<int> >(
"memory_procs");
228 bool doMemory =
true;
236 Teuchos::broadcast<int, long>(*
comm_, 0, 1, &numKbytes);
244 std::string(
"Warning: memory profiling requested but not available."));
258 makeMetricOutputManager<long>(
myRank_, iPrint, f2, os2, memoryOut_,
259 std::string(
"KB"), 10, memoryOutputFile_);
261 catch (std::exception &e){
262 std::ostringstream oss;
263 oss <<
myRank_ <<
": unable to create memory profiling output manager";
264 oss <<
" (" << e.what() <<
")";
265 throw std::runtime_error(oss.str());
272 #ifdef Z2_OMIT_ALL_ERROR_CHECKING 282 using Teuchos::ParameterList;
283 using Teuchos::ParameterEntry;
285 using Teuchos::rcp_dynamic_cast;
286 ParameterList::ConstIterator next = params.begin();
290 std::string validatorName(
"StringIntegralValidator(int)");
291 typedef Teuchos::StringToIntegralParameterEntryValidator<int> s2i_t;
293 while (next != params.end()){
295 const std::string &name = next->first;
296 ParameterEntry &entry = params.getEntry(name);
299 ParameterList *dummy = NULL;
300 ParameterList &pl = entry.getValue<ParameterList>(dummy);
304 if ((entry.validator()).
get()){
305 if (entry.validator()->getXMLTypeName() == validatorName){
306 std::string dummy(
"");
307 std::string &entryValue = entry.getValue<std::string>(&dummy);
308 RCP<const s2i_t> s2i =
309 Teuchos::rcp_dynamic_cast<
const s2i_t>(entry.validator(),
true);
310 int val = s2i->getIntegralValue(entryValue);
311 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.
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
long getProcessKilobytes()
AssertionLevel
Level of error checking or assertions desired.
int numProcs_
number of processes (relative to comm_)
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
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.
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