50 #ifndef _ZOLTAN2_ENVIRONMENT_HPP_
51 #define _ZOLTAN2_ENVIRONMENT_HPP_
53 #include <Zoltan2_config.h>
61 #include <Teuchos_RCP.hpp>
62 #include <Teuchos_ParameterList.hpp>
63 #include <Teuchos_Comm.hpp>
64 #include <Teuchos_DefaultComm.hpp>
65 #include <Teuchos_CommHelpers.hpp>
66 #include <Teuchos_StandardParameterEntryValidators.hpp>
89 typedef Teuchos::RCP<const Teuchos::Comm<int> >
Comm_t;
92 typedef Teuchos::RCP<TimerManager>
Timer_t;
109 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm );
118 Environment(
const Teuchos::RCP<
const Teuchos::Comm<int> > &comm);
138 static RCP<Teuchos::AnyNumberParameterEntryValidator>
143 static RCP<Teuchos::AnyNumberParameterEntryValidator>
152 void setTimer(RCP<TimerManager> &timer) { timerOut_=timer; timingOn_=
true;}
154 #ifdef Z2_OMIT_ALL_ERROR_CHECKING
171 size_t nobj,
bool ok)
const {}
174 size_t nobj,
bool ok,
const Comm_t &comm=
comm_)
const {}
195 std::ostringstream emsg;
196 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
198 emsg <<
myRank_ <<
": error: " << msg << std::endl;
199 throw std::runtime_error(emsg.str());
220 const Comm_t &comm)
const {
223 int anyFail=0,
fail = (!ok ? 1 : 0);
224 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
227 std::ostringstream emsg;
228 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
230 emsg <<
myRank_ <<
": error: " << msg << std::endl;
232 emsg <<
myRank_ <<
": exiting" << std::endl;
234 throw std::runtime_error(emsg.str());
262 std::ostringstream emsg;
263 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
265 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
266 throw std::logic_error(emsg.str());
293 const Comm_t &comm)
const {
296 int anyFail=0,
fail = (!ok ? 1 : 0);
297 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
301 std::ostringstream emsg;
302 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
304 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
306 emsg <<
myRank_ <<
": exiting" << std::endl;
308 throw std::logic_error(emsg.str());
330 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
331 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
332 throw std::bad_alloc();
352 size_t nobj,
bool ok,
const Comm_t &comm)
const {
354 int anyFail=0,
fail = (!ok ? 1 : 0);
355 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail, &anyFail);
357 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
359 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
361 std::cerr <<
myRank_ <<
": exiting" << std::endl;
363 throw std::bad_alloc();
383 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES
388 inline void debug(
int level,
const char *msg)
const{
return;}
389 inline void debug(
int level,
const std::string& msg)
const{
return;}
392 debugOut_->print(level, msg);
396 debugOut_->print(level, msg);
399 inline void debug(
int level,
const char *msg)
const{
401 debugOut_->print(msg_enum, msg);
404 inline void debug(
int level,
const std::string& msg)
const{
406 debugOut_->print(msg_enum, msg);
410 #ifdef Z2_OMIT_ALL_PROFILING
415 int fieldWidth=0)
const {
return;}
417 int fieldWidth=0)
const {
return;}
422 int fieldWidth=0)
const {
return;}
424 int fieldWidth=0)
const {
return;}
431 if (timingOn_) timerOut_->start(tt, timerName); }
434 if (timingOn_) timerOut_->start(tt, timerName); }
439 int fieldWidth=0)
const {
441 std::ostringstream oss;
442 oss << timerName <<
" ";
444 oss.width(fieldWidth);
448 timerOut_->start(tt, oss.str());
453 int fieldWidth=0)
const {
455 std::ostringstream oss;
456 oss << timerName <<
" ";
458 oss.width(fieldWidth);
462 timerOut_->start(tt, oss.str());
470 if (timingOn_) timerOut_->stop(tt, timerName); }
473 if (timingOn_) timerOut_->stop(tt, timerName); }
479 int fieldWidth=0)
const {
481 std::ostringstream oss;
482 oss << timerName <<
" ";
484 oss.width(fieldWidth);
488 timerOut_->stop(tt, oss.str());
493 int fieldWidth=0)
const {
495 std::ostringstream oss;
496 oss << timerName <<
" ";
498 oss.width(fieldWidth);
502 timerOut_->stop(tt, oss.str());
523 #ifdef Z2_OMIT_ALL_PROFILING
524 inline void memory(
const char *msg)
const {
return;}
526 inline void memory(
const std::string &msg)
const {
return; }
528 inline void memory(
const char *msg)
const
532 inline void memory(
const std::string &msg)
const
557 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES
558 inline bool doStatus()
const {
return false;}
563 return (debugOut_->getDebugLevel() >
NO_STATUS);
566 return debugOut_->getDebugLevel();
569 return debugOut_->getOStream();
590 return unvalidatedParams_; }
614 void commitParameters();
620 Teuchos::ParameterList unvalidatedParams_;
630 Teuchos::ParameterList params_;
639 RCP<std::ofstream> memoryOutputFile_;
645 #define Z2_UNSET_STRING std::string("notSet")
662 template<
typename metric_t>
664 std::string fname,
int ost,
666 std::string units,
int fieldWidth,
667 RCP<std::ofstream> &fptr)
676 if (!haveFname && !haveStreamName){
677 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
683 std::ofstream *oFile = NULL;
685 oFile =
new std::ofstream;
686 std::string newFname;
689 oFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
691 catch(std::exception &e){
692 throw std::runtime_error(e.what());
696 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, *oFile,
true,
702 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
705 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cerr,
true,
708 mgr = Teuchos::rcp(
new manager_t(rank,
false, std::cout,
true,
711 throw std::logic_error(
"invalid metric output stream was not caught");
const Teuchos::ParameterList & getParameters() const
Returns a reference to the user's parameter list.
void globalMemoryAssertion(const char *file, int lineNum, size_t nobj, bool ok, const Comm_t &comm) const
Test for successful memory allocation on every process.
bool doStatus() const
Return true if debug output was requested, even if this process is not printing out debug messages...
void timerStop(TimerType tt, const char *timerName, int num, int fieldWidth=0) const
Stop a named timer, with a number as part of the name.
std::ostream * getDebugOStream() const
Defines the MetricOutputManager class.
void setTimer(RCP< TimerManager > &timer)
Provide the Timer object to the Environment.
MetricOutputManager handles output of profiling messages.
void timerStart(TimerType tt, const char *timerName, int num, int fieldWidth=0) const
Start a named timer, with a number as part of the name.
void localInputAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level) const
Test for valid user input on local process only.
MessageOutputLevel
The amount of debugging or status output to print.
Defines Parameter related enumerators, declares functions.
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
Environment(Teuchos::ParameterList &problemParams, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Constructor.
static void convertStringToInt(Teuchos::ParameterList ¶ms)
Convert parameters of type Teuchos::StringToIntegralParameterEntryValidator<int> to integer...
void makeMetricOutputManager(int rank, bool iPrint, std::string fname, int ost, Teuchos::RCP< MetricOutputManager< metric_t > > &mgr, std::string units, int fieldWidth, RCP< std::ofstream > &fptr)
Create an output manager for a metric value.
Debug output manager for Zoltan2.
TimerType
The type of timers which should be active.
void localMemoryAssertion(const char *file, int lineNum, size_t nobj, bool ok) const
Test for successful memory allocation on local process only.
/dev/null: do actions but don't output results
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyDoubleValidator()
Exists to make setting up validators less cluttered.
void globalBugAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level, const Comm_t &comm) const
Test for valid library behavior on every process.
Teuchos::RCP< const Teuchos::Comm< int > > Comm_t
bool doMemoryProfiling() const
Return true if memory usage output was requested, even if this process is not printing out memory use...
long getProcessKilobytes()
void globalInputAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level, const Comm_t &comm) const
Test globally for valid user input.
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.
void timerStop(TimerType tt, const char *timerName) const
Stop a named timer.
Teuchos::ParameterList & getParametersNonConst()
Returns a reference to a non-const copy of the parameters.
Declaration of methods to assist in file input/output.
int myRank_
mpi rank (relative to comm_)
OSType
Output stream types.
void debug(int level, const char *msg) const
Comm_t comm_
communicator for environment
void debug(MessageOutputLevel level, const std::string &msg) const
Teuchos::RCP< MetricOutputManager< memory_t > > MemoryProfilerManager_t
const Teuchos::ParameterList & getUnvalidatedParameters() const
Returns a const reference to the user's original list.
don't display status/debug messages
void localBugAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level) const
Test for valid library behavior on local process only.
static void getValidParameters(ParameterList &pl)
Collect the paramaters specific to Environment.
void debug(int level, const std::string &msg) const
long memory_t
data type for Kilobytes
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.
void memory(const char *msg) const
Print a message and the kilobytes in use by this process.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Teuchos::RCP< TimerManager > Timer_t
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.
static const std::string fail
~Environment()
Destructor.
void timerStop(TimerType tt, const std::string &timerName) const
MessageOutputLevel getDebugLevel() const
void timerStart(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
void memory(const std::string &msg) const
void timerStop(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
bool doTiming() const
Return true if timing was requested, even if this process is not printing out timing messages...
A gathering of useful namespace methods.
void timerStart(TimerType tt, const char *timerName) const
Start a named timer.
AssertionLevel errorCheckLevel_
level of error checking to do
Declarations for TimerManager.
void timerStart(TimerType tt, const std::string &timerName) const
Teuchos::RCP< DebugManager > DebugManager_t