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;
111 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm );
135 static RCP<Teuchos::AnyNumberParameterEntryValidator>
140 static RCP<Teuchos::AnyNumberParameterEntryValidator>
149 void setTimer(RCP<TimerManager> &timer) { timerOut_=timer; timingOn_=
true;}
151 #ifdef Z2_OMIT_ALL_ERROR_CHECKING 168 size_t nobj,
bool ok)
const {}
171 size_t nobj,
bool ok,
const Comm_t &comm=
comm_)
const {}
192 std::ostringstream emsg;
193 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
195 emsg <<
myRank_ <<
": error: " << msg << std::endl;
196 throw std::runtime_error(emsg.str());
217 const Comm_t &comm)
const {
220 int anyFail=0,
fail = (!ok ? 1 : 0);
221 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
224 std::ostringstream emsg;
225 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
227 emsg <<
myRank_ <<
": error: " << msg << std::endl;
229 emsg <<
myRank_ <<
": exiting" << std::endl;
231 throw std::runtime_error(emsg.str());
259 std::ostringstream emsg;
260 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
262 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
263 throw std::logic_error(emsg.str());
290 const Comm_t &comm)
const {
293 int anyFail=0,
fail = (!ok ? 1 : 0);
294 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
298 std::ostringstream emsg;
299 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
301 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
303 emsg <<
myRank_ <<
": exiting" << std::endl;
305 throw std::logic_error(emsg.str());
327 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
328 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
329 throw std::bad_alloc();
349 size_t nobj,
bool ok,
const Comm_t &comm)
const {
351 int anyFail=0,
fail = (!ok ? 1 : 0);
352 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail, &anyFail);
354 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
356 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
358 std::cerr <<
myRank_ <<
": exiting" << std::endl;
360 throw std::bad_alloc();
380 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES 385 inline void debug(
int level,
const char *msg)
const{
return;}
386 inline void debug(
int level,
const std::string& msg)
const{
return;}
389 debugOut_->print(level, msg);
393 debugOut_->print(level, msg);
396 inline void debug(
int level,
const char *msg)
const{
398 debugOut_->print(msg_enum, msg);
401 inline void debug(
int level,
const std::string& msg)
const{
403 debugOut_->print(msg_enum, msg);
407 #ifdef Z2_OMIT_ALL_PROFILING 412 int fieldWidth=0)
const {
return;}
414 int fieldWidth=0)
const {
return;}
419 int fieldWidth=0)
const {
return;}
421 int fieldWidth=0)
const {
return;}
428 if (timingOn_) timerOut_->start(tt, timerName); }
431 if (timingOn_) timerOut_->start(tt, timerName); }
436 int fieldWidth=0)
const {
438 std::ostringstream oss;
439 oss << timerName <<
" ";
441 oss.width(fieldWidth);
445 timerOut_->start(tt, oss.str());
450 int fieldWidth=0)
const {
452 std::ostringstream oss;
453 oss << timerName <<
" ";
455 oss.width(fieldWidth);
459 timerOut_->start(tt, oss.str());
467 if (timingOn_) timerOut_->stop(tt, timerName); }
470 if (timingOn_) timerOut_->stop(tt, timerName); }
476 int fieldWidth=0)
const {
478 std::ostringstream oss;
479 oss << timerName <<
" ";
481 oss.width(fieldWidth);
485 timerOut_->stop(tt, oss.str());
490 int fieldWidth=0)
const {
492 std::ostringstream oss;
493 oss << timerName <<
" ";
495 oss.width(fieldWidth);
499 timerOut_->stop(tt, oss.str());
520 #ifdef Z2_OMIT_ALL_PROFILING 521 void memory(
const char *msg)
const {
return;}
523 void memory(
const std::string &msg)
const {
return; }
529 void memory(
const std::string &msg)
const 554 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES 555 inline bool doStatus()
const {
return false;}
560 return (debugOut_->getDebugLevel() >
NO_STATUS);
563 return debugOut_->getDebugLevel();
566 return debugOut_->getOStream();
587 return unvalidatedParams_; }
611 void commitParameters();
617 Teuchos::ParameterList unvalidatedParams_;
627 Teuchos::ParameterList params_;
636 RCP<std::ofstream> memoryOutputFile_;
642 #define Z2_UNSET_STRING std::string("notSet") 659 template<
typename metric_t>
661 std::string fname,
int ost,
663 std::string units,
int fieldWidth,
664 RCP<std::ofstream> &fptr)
673 if (!haveFname && !haveStreamName){
674 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
680 std::ofstream *oFile = NULL;
682 oFile =
new std::ofstream;
683 std::string newFname;
686 oFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
688 catch(std::exception &e){
689 throw std::runtime_error(e.what());
693 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, *oFile,
true,
699 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
702 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cerr,
true,
705 mgr = Teuchos::rcp(
new manager_t(rank,
false, std::cout,
true,
708 throw std::logic_error(
"invalid metric output stream was not caught");
Environment()
Default Constructor.
void memory(const char *msg) const
Print a message and the kilobytes in use by this process.
Defines the MetricOutputManager class.
void debug(int level, const std::string &msg) const
void timerStop(TimerType tt, const std::string &timerName) const
void setTimer(RCP< TimerManager > &timer)
Provide the Timer object to the Environment.
MetricOutputManager handles output of profiling messages.
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.
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.
void memory(const std::string &msg) const
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
static void convertStringToInt(Teuchos::ParameterList ¶ms)
Convert parameters of type Teuchos::StringToIntegralParameterEntryValidator<int> to integer...
MessageOutputLevel getDebugLevel() const
void timerStop(TimerType tt, const char *timerName) const
Stop a named timer.
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.
const Teuchos::ParameterList & getUnvalidatedParameters() const
Returns a const reference to the user's original list.
bool doMemoryProfiling() const
Return true if memory usage output was requested, even if this process is not printing out memory use...
Debug output manager for Zoltan2.
TimerType
The type of timers which should be active.
/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.
void timerStart(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
void timerStart(TimerType tt, const std::string &timerName) const
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyDoubleValidator()
Exists to make setting up validators less cluttered.
Teuchos::RCP< const Teuchos::Comm< int > > Comm_t
long getProcessKilobytes()
AssertionLevel
Level of error checking or assertions desired.
std::ostream * getDebugOStream() const
int numProcs_
number of processes (relative to comm_)
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.
Comm_t comm_
communicator for environment
Teuchos::RCP< MetricOutputManager< memory_t > > MemoryProfilerManager_t
void localBugAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level) const
Test for valid library behavior on local process only.
don't display status/debug messages
static void getValidParameters(ParameterList &pl)
Collect the paramaters specific to Environment.
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.
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.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Teuchos::RCP< TimerManager > Timer_t
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.
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyIntValidator()
Exists to make setting up validators less cluttered.
static const std::string fail
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.
~Environment()
Destructor.
void debug(MessageOutputLevel level, const std::string &msg) const
void timerStart(TimerType tt, const char *timerName) const
Start a named timer.
void timerStop(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
void debug(int level, const char *msg) 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.
const Teuchos::ParameterList & getParameters() const
Returns a reference to the user's parameter list.
bool doStatus() const
Return true if debug output was requested, even if this process is not printing out debug messages...
AssertionLevel errorCheckLevel_
level of error checking to do
void localMemoryAssertion(const char *file, int lineNum, size_t nobj, bool ok) const
Test for successful memory allocation on local process only.
Declarations for TimerManager.
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.
Teuchos::RCP< DebugManager > DebugManager_t