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()
151 using Teuchos::Array;
154 using Teuchos::ParameterList;
156 bool emptyList = (params_.begin() == params_.end());
160 ParameterList validParams;
175 params_.validateParametersAndSetDefaults(validParams);
190 #ifndef Z2_OMIT_ALL_STATUS_MESSAGES
192 string &fname = params_.get<
string>(
"debug_output_file",
Z2_UNSET_STRING);
202 const Array<int> *reporters =
203 params_.getPtr<Array<int> >(
"debug_procs");
210 catch (std::exception &e){
211 std::ostringstream oss;
212 oss <<
myRank_ <<
": unable to create debug output manager";
213 oss <<
" (" << e.what() <<
")";
214 throw std::runtime_error(oss.str());
220 #ifndef Z2_OMIT_ALL_PROFILING
226 const Array<int> *reporters2 =
227 params_.getPtr<Array<int> >(
"memory_procs");
229 bool doMemory =
true;
237 Teuchos::broadcast<int, long>(*
comm_, 0, 1, &numKbytes);
245 string(
"Warning: memory profiling requested but not available."));
254 iPrint = (myRank_ == 0);
259 makeMetricOutputManager<long>(
myRank_, iPrint, f2, os2, memoryOut_,
260 string(
"KB"), 10, memoryOutputFile_);
262 catch (std::exception &e){
263 std::ostringstream oss;
264 oss << myRank_ <<
": unable to create memory profiling output manager";
265 oss <<
" (" << e.what() <<
")";
266 throw std::runtime_error(oss.str());
273 #ifdef Z2_OMIT_ALL_ERROR_CHECKING
283 using Teuchos::ParameterList;
284 using Teuchos::ParameterEntry;
286 using Teuchos::rcp_dynamic_cast;
288 ParameterList::ConstIterator next = params.begin();
292 string validatorName(
"StringIntegralValidator(int)");
293 typedef Teuchos::StringToIntegralParameterEntryValidator<int> s2i_t;
295 while (next != params.end()){
297 const std::string &name = next->first;
298 ParameterEntry &entry = params.getEntry(name);
301 ParameterList *dummy = NULL;
302 ParameterList &pl = entry.getValue<ParameterList>(dummy);
306 if ((entry.validator()).
get()){
307 if (entry.validator()->getXMLTypeName() == validatorName){
309 string &entryValue = entry.getValue<
string>(&dummy);
310 RCP<const s2i_t> s2i =
311 Teuchos::rcp_dynamic_cast<
const s2i_t>(entry.validator(),
true);
312 int val = s2i->getIntegralValue(entryValue);
313 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