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>
88 typedef Teuchos::RCP<const Teuchos::Comm<int> >
Comm_t;
91 typedef Teuchos::RCP<TimerManager>
Timer_t;
110 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm );
130 void setTimer(RCP<TimerManager> &timer) { timerOut_=timer; timingOn_=
true;}
132 #ifdef Z2_OMIT_ALL_ERROR_CHECKING
149 size_t nobj,
bool ok)
const {}
152 size_t nobj,
bool ok,
const Comm_t &comm=
comm_)
const {}
173 std::ostringstream emsg;
174 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
176 emsg <<
myRank_ <<
": error: " << msg << std::endl;
177 throw std::runtime_error(emsg.str());
198 const Comm_t &comm)
const {
201 int anyFail=0,
fail = (!ok ? 1 : 0);
202 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
205 std::ostringstream emsg;
206 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
208 emsg <<
myRank_ <<
": error: " << msg << std::endl;
210 emsg <<
myRank_ <<
": exiting" << std::endl;
212 throw std::runtime_error(emsg.str());
240 std::ostringstream emsg;
241 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
243 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
244 throw std::logic_error(emsg.str());
271 const Comm_t &comm)
const {
274 int anyFail=0,
fail = (!ok ? 1 : 0);
275 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
279 std::ostringstream emsg;
280 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
282 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
284 emsg <<
myRank_ <<
": exiting" << std::endl;
286 throw std::logic_error(emsg.str());
308 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
309 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
310 throw std::bad_alloc();
330 size_t nobj,
bool ok,
const Comm_t &comm)
const {
332 int anyFail=0,
fail = (!ok ? 1 : 0);
333 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail, &anyFail);
335 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
337 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
339 std::cerr <<
myRank_ <<
": exiting" << std::endl;
341 throw std::bad_alloc();
361 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES
366 debugOut_->print(level, msg);}
368 debugOut_->print(level, msg);}
371 #ifdef Z2_OMIT_ALL_PROFILING
376 int fieldWidth=0)
const {
return;}
378 int fieldWidth=0)
const {
return;}
383 int fieldWidth=0)
const {
return;}
385 int fieldWidth=0)
const {
return;}
392 if (timingOn_) timerOut_->start(tt, timerName); }
395 if (timingOn_) timerOut_->start(tt, timerName); }
400 int fieldWidth=0)
const {
403 oss << timerName <<
" ";
405 oss.width(fieldWidth);
409 timerOut_->start(tt, oss.str());
414 int fieldWidth=0)
const {
417 oss << timerName <<
" ";
419 oss.width(fieldWidth);
423 timerOut_->start(tt, oss.str());
431 if (timingOn_) timerOut_->stop(tt, timerName); }
434 if (timingOn_) timerOut_->stop(tt, timerName); }
440 int fieldWidth=0)
const {
443 oss << timerName <<
" ";
445 oss.width(fieldWidth);
449 timerOut_->stop(tt, oss.str());
454 int fieldWidth=0)
const {
457 oss << timerName <<
" ";
459 oss.width(fieldWidth);
463 timerOut_->stop(tt, oss.str());
484 #ifdef Z2_OMIT_ALL_PROFILING
485 void memory(
const char *msg)
const {
return;}
487 void memory(
const std::string &msg)
const {
return; }
493 void memory(
const std::string &msg)
const
518 #ifdef Z2_OMIT_ALL_STATUS_MESSAGES
519 bool doStatus()
const {
return false;}
544 return unvalidatedParams_; }
565 void commitParameters();
571 Teuchos::ParameterList unvalidatedParams_;
581 Teuchos::ParameterList params_;
590 RCP<std::ofstream> memoryOutputFile_;
596 #define Z2_UNSET_STRING std::string("notSet")
613 template<
typename metric_t>
615 std::string fname,
int ost,
617 std::string units,
int fieldWidth,
618 RCP<std::ofstream> &fptr)
627 if (!haveFname && !haveStreamName){
628 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
634 std::ofstream *oFile = NULL;
636 oFile =
new std::ofstream;
637 std::string newFname;
640 oFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
642 catch(std::exception &e){
643 throw std::runtime_error(e.what());
647 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, *oFile,
true,
653 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
656 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cerr,
true,
659 mgr = Teuchos::rcp(
new manager_t(rank,
false, std::cout,
true,
662 throw std::logic_error(
"invalid metric output stream was not caught");
Environment()
Default Constructor.
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.
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.
void timerStop(TimerType tt, const string &timerName) const
Defines Parameter related enumerators, declares functions.
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
void timerStart(TimerType tt, const string &timerName, int num, int fieldWidth=0) const
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.
void timerStop(TimerType tt, const string &timerName, int num, int fieldWidth=0) const
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
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.
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
~Environment()
Destructor.
MessageOutputLevel getDebugLevel() const
void memory(const std::string &msg) const
bool doTiming() const
Return true if timing was requested, even if this process is not printing out timing messages...
void timerStart(TimerType tt, const string &timerName) const
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.
Teuchos::RCP< DebugManager > DebugManager_t