14#ifndef _ZOLTAN2_ENVIRONMENT_HPP_
15#define _ZOLTAN2_ENVIRONMENT_HPP_
17#include <Zoltan2_config.h>
25#include <Teuchos_RCP.hpp>
26#include <Teuchos_ParameterList.hpp>
27#include <Teuchos_Comm.hpp>
28#include <Teuchos_DefaultComm.hpp>
29#include <Teuchos_CommHelpers.hpp>
30#include <Teuchos_StandardParameterEntryValidators.hpp>
53 typedef Teuchos::RCP<const Teuchos::Comm<int> >
Comm_t;
56 typedef Teuchos::RCP<TimerManager>
Timer_t;
73 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm );
82 Environment(
const Teuchos::RCP<
const Teuchos::Comm<int> > &comm);
102 static RCP<Teuchos::AnyNumberParameterEntryValidator>
107 static RCP<Teuchos::AnyNumberParameterEntryValidator>
116 void setTimer(RCP<TimerManager> &timer) { timerOut_=timer; timingOn_=
true;}
118#ifdef Z2_OMIT_ALL_ERROR_CHECKING
135 size_t nobj,
bool ok)
const {}
138 size_t nobj,
bool ok,
const Comm_t &comm=
comm_)
const {}
159 std::ostringstream emsg;
160 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
162 emsg <<
myRank_ <<
": error: " << msg << std::endl;
163 throw std::runtime_error(emsg.str());
184 const Comm_t &comm)
const {
187 int anyFail=0,
fail = (!ok ? 1 : 0);
188 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
191 std::ostringstream emsg;
192 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
194 emsg <<
myRank_ <<
": error: " << msg << std::endl;
196 emsg <<
myRank_ <<
": exiting" << std::endl;
198 throw std::runtime_error(emsg.str());
226 std::ostringstream emsg;
227 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
229 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
230 throw std::logic_error(emsg.str());
257 const Comm_t &comm)
const {
260 int anyFail=0,
fail = (!ok ? 1 : 0);
261 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail,
265 std::ostringstream emsg;
266 emsg <<
myRank_<<
": " << file <<
"," << lineNum<< std::endl;
268 emsg <<
myRank_ <<
": bug: " << msg << std::endl;
270 emsg <<
myRank_ <<
": exiting" << std::endl;
272 throw std::logic_error(emsg.str());
294 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
295 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
296 throw std::bad_alloc();
316 size_t nobj,
bool ok,
const Comm_t &comm)
const {
318 int anyFail=0,
fail = (!ok ? 1 : 0);
319 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_MAX, 1, &
fail, &anyFail);
321 std::cerr <<
myRank_ <<
": " << file <<
", " << lineNum<< std::endl;
323 std::cerr <<
myRank_ <<
": " << nobj <<
" objects" << std::endl;
325 std::cerr <<
myRank_ <<
": exiting" << std::endl;
327 throw std::bad_alloc();
347#ifdef Z2_OMIT_ALL_STATUS_MESSAGES
352 inline void debug(
int level,
const char *msg)
const{
return;}
353 inline void debug(
int level,
const std::string& msg)
const{
return;}
356 debugOut_->print(level, msg);
360 debugOut_->print(level, msg);
363 inline void debug(
int level,
const char *msg)
const{
365 debugOut_->print(msg_enum, msg);
368 inline void debug(
int level,
const std::string& msg)
const{
370 debugOut_->print(msg_enum, msg);
374#ifdef Z2_OMIT_ALL_PROFILING
379 int fieldWidth=0)
const {
return;}
381 int fieldWidth=0)
const {
return;}
386 int fieldWidth=0)
const {
return;}
388 int fieldWidth=0)
const {
return;}
395 if (timingOn_) timerOut_->start(tt, timerName); }
398 if (timingOn_) timerOut_->start(tt, timerName); }
403 int fieldWidth=0)
const {
405 std::ostringstream oss;
406 oss << timerName <<
" ";
408 oss.width(fieldWidth);
412 timerOut_->start(tt, oss.str());
417 int fieldWidth=0)
const {
419 std::ostringstream oss;
420 oss << timerName <<
" ";
422 oss.width(fieldWidth);
426 timerOut_->start(tt, oss.str());
434 if (timingOn_) timerOut_->stop(tt, timerName); }
437 if (timingOn_) timerOut_->stop(tt, timerName); }
443 int fieldWidth=0)
const {
445 std::ostringstream oss;
446 oss << timerName <<
" ";
448 oss.width(fieldWidth);
452 timerOut_->stop(tt, oss.str());
457 int fieldWidth=0)
const {
459 std::ostringstream oss;
460 oss << timerName <<
" ";
462 oss.width(fieldWidth);
466 timerOut_->stop(tt, oss.str());
487#ifdef Z2_OMIT_ALL_PROFILING
488 inline void memory(
const char *msg)
const {
return;}
490 inline void memory(
const std::string &msg)
const {
return; }
492 inline void memory(
const char *msg)
const
496 inline void memory(
const std::string &msg)
const
521#ifdef Z2_OMIT_ALL_STATUS_MESSAGES
522 inline bool doStatus()
const {
return false;}
527 return (debugOut_->getDebugLevel() >
NO_STATUS);
530 return debugOut_->getDebugLevel();
533 return debugOut_->getOStream();
554 return unvalidatedParams_; }
571 void commitParameters();
577 Teuchos::ParameterList unvalidatedParams_;
587 Teuchos::ParameterList params_;
596 RCP<std::ofstream> memoryOutputFile_;
602#define Z2_UNSET_STRING std::string("notSet")
619template<
typename metric_t>
621 std::string fname,
int ost,
623 std::string units,
int fieldWidth,
624 RCP<std::ofstream> &fptr)
633 if (!haveFname && !haveStreamName){
634 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
640 std::ofstream *oFile = NULL;
642 oFile =
new std::ofstream;
643 std::string newFname;
646 oFile->open(newFname.c_str(), std::ios::out|std::ios::trunc);
648 catch(std::exception &e){
649 throw std::runtime_error(e.what());
653 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, *oFile,
true,
659 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cout,
true,
662 mgr = Teuchos::rcp(
new manager_t(rank, iPrint, std::cerr,
true,
665 mgr = Teuchos::rcp(
new manager_t(rank,
false, std::cout,
true,
668 throw std::logic_error(
"invalid metric output stream was not caught");
Debug output manager for Zoltan2.
#define Z2_UNSET_STRING
A value to indicate a string parameter that was not set by the user.
Declaration of methods to assist in file input/output.
Defines the MetricOutputManager class.
Defines Parameter related enumerators, declares functions.
Declarations for TimerManager.
A gathering of useful namespace methods.
The user parameters, debug, timing and memory profiling output objects, and error checking methods.
int myRank_
mpi rank (relative to comm_)
void memory(const std::string &msg) const
Teuchos::RCP< TimerManager > Timer_t
Teuchos::RCP< MetricOutputManager< memory_t > > MemoryProfilerManager_t
void localInputAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level) const
Test for valid user input on local process only.
~Environment()
Destructor.
void timerStop(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
void debug(int level, const char *msg) const
const Teuchos::ParameterList & getParameters() const
Returns a reference to the user's parameter list.
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 debug(MessageOutputLevel level, const char *msg) const
Send a message to the debug output manager.
bool doTiming() const
Return true if timing was requested, even if this process is not printing out timing messages.
Comm_t comm_
communicator for environment
const Teuchos::ParameterList & getUnvalidatedParameters() const
Returns a const reference to the user's original list.
void timerStart(TimerType tt, const char *timerName) const
Start a named timer.
void timerStart(TimerType tt, const std::string &timerName) const
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyDoubleValidator()
Exists to make setting up validators less cluttered.
int numProcs_
number of processes (relative to comm_)
bool doStatus() const
Return true if debug output was requested, even if this process is not printing out debug messages.
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyIntValidator()
Exists to make setting up validators less cluttered.
MessageOutputLevel getDebugLevel() const
long memory_t
data type for Kilobytes
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 localBugAssertion(const char *file, int lineNum, const char *msg, bool ok, AssertionLevel level) const
Test for valid library behavior on local process only.
Teuchos::RCP< const Teuchos::Comm< int > > Comm_t
void memory(const char *msg) const
Print a message and the kilobytes in use by this process.
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.
void localMemoryAssertion(const char *file, int lineNum, size_t nobj, bool ok) const
Test for successful memory allocation on local process only.
Teuchos::RCP< DebugManager > DebugManager_t
void resetParameters(Teuchos::ParameterList &problemParams)
resetParameters and validate them - preserve the comm
void timerStop(TimerType tt, const char *timerName) const
Stop a named timer.
void debug(int level, const std::string &msg) 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.
void timerStart(TimerType tt, const std::string &timerName, int num, int fieldWidth=0) const
Teuchos::ParameterList & getParametersNonConst()
Returns a reference to a non-const copy of the parameters.
AssertionLevel errorCheckLevel_
level of error checking to do
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.
void timerStop(TimerType tt, const std::string &timerName) const
bool doMemoryProfiling() const
Return true if memory usage output was requested, even if this process is not printing out memory use...
void setTimer(RCP< TimerManager > &timer)
Provide the Timer object to the Environment.
void debug(MessageOutputLevel level, const std::string &msg) const
std::ostream * getDebugOStream() const
MetricOutputManager handles output of profiling messages.
Created by mbenlioglu on Aug 31, 2020.
void addNumberToFileName(int number, std::string fname, std::string &newf)
Helper method to add number to a file name.
TimerType
The type of timers which should be active.
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.
static const std::string fail
MessageOutputLevel
The amount of debugging or status output to print.
@ NO_STATUS
don't display status/debug messages
OSType
Output stream types.
@ NULL_STREAM
/dev/null: do actions but don't output results
AssertionLevel
Level of error checking or assertions desired.
long getProcessKilobytes()