Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MueLu: a start at reducing MueLu's library size #4985

Merged
merged 2 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions packages/muelu/src/Utils/MueLu_Exceptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// @HEADER
//
// ***********************************************************************
//
// MueLu: A package for multigrid based preconditioning
// Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact
// Jonathan Hu ([email protected])
// Andrey Prokopenko ([email protected])
// Ray Tuminaro ([email protected])
//
// ***********************************************************************
//
// @HEADER
#include <Teuchos_Exceptions.hpp>
#include <MueLu_Exceptions.hpp>

#include "MueLu_ConfigDefs.hpp"

namespace MueLu {
namespace Exceptions {

BadCast::BadCast(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

NotImplemented::NotImplemented(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

RuntimeError::RuntimeError(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

Overflow::Overflow(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

Incompatible::Incompatible(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

DependencyError::DependencyError(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}

InvalidArgument::InvalidArgument(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) { }

}
}
14 changes: 7 additions & 7 deletions packages/muelu/src/Utils/MueLu_Exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,44 +56,44 @@ namespace MueLu {
//! Exception indicating invalid cast attempted
class BadCast : public Teuchos::ExceptionBase {
public:
BadCast(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
BadCast(const std::string& what_arg);
};

//! Exception throws when you call an unimplemented method of MueLu
/** Mainly use for development in progress. **/
class NotImplemented : public Teuchos::ExceptionBase {
public:
NotImplemented(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
NotImplemented(const std::string& what_arg);
};

//! Exception throws to report errors in the internal logical of the program.
class RuntimeError : public Teuchos::ExceptionBase {
public:
RuntimeError(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
RuntimeError(const std::string& what_arg);
};

//! Exception throws to report overflows.
class Overflow : public Teuchos::ExceptionBase {
public:
Overflow(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
Overflow(const std::string& what_arg);
};

//! Exception throws to report incompatible objects (like maps).
class Incompatible : public Teuchos::ExceptionBase {
public:
Incompatible(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
Incompatible(const std::string& what_arg);
};

//! Exception throws to report data dependency problems between factories.
class DependencyError : public Teuchos::ExceptionBase {
public:
DependencyError(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) {}
DependencyError(const std::string& what_arg);
};

//! Exception throws to report invalid user entry
class InvalidArgument: public Teuchos::ExceptionBase {
public:
InvalidArgument(const std::string& what_arg) : Teuchos::ExceptionBase(what_arg) { }
InvalidArgument(const std::string& what_arg);
};

}
Expand Down
80 changes: 80 additions & 0 deletions packages/muelu/src/Utils/MueLu_Monitor.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,82 @@
#include "MueLu_Monitor.hpp"
int MueLu::FactoryMonitor::timerIdentifier_=0;

namespace MueLu {
PrintMonitor::PrintMonitor(const BaseClass& object, const std::string& msg, MsgType msgLevel) : object_(object) {
tabbed = false;
if (object_.IsPrint(msgLevel)) {
// Print description and new indent
object_.GetOStream(msgLevel, 0) << msg << std::endl;
object_.getOStream()->pushTab();
tabbed = true;
}
}

PrintMonitor::~PrintMonitor() { if (tabbed) object_.getOStream()->popTab(); }

Monitor::Monitor(const BaseClass& object, const std::string & msg, MsgType msgLevel, MsgType timerLevel)
: printMonitor_(object, msg + " (" + object.description() + ")", msgLevel),
timerMonitor_(object, object.ShortClassName() + ": " + msg + " (total)", timerLevel)
{ }

Monitor::Monitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel, MsgType timerLevel)
: printMonitor_(object, label + msg + " (" + object.description() + ")", msgLevel),
timerMonitor_(object, label + object.ShortClassName() + ": " + msg + " (total)", timerLevel)
{ }

SubMonitor::SubMonitor(const BaseClass& object, const std::string & msg, MsgType msgLevel, MsgType timerLevel)
: printMonitor_(object, msg, msgLevel),
timerMonitor_(object, object.ShortClassName() + ": " + msg + " (sub, total)", timerLevel)
{ }

SubMonitor::SubMonitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel, MsgType timerLevel)
: printMonitor_(object, label + msg, msgLevel),
timerMonitor_(object, label + object.ShortClassName() + ": " + msg + " (sub, total)", timerLevel)
{ }

FactoryMonitor::FactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel, MsgType timerLevel)
: Monitor(object, msg, msgLevel, timerLevel),
timerMonitorExclusive_(object, object.ShortClassName() + ": " + msg, timerLevel)
{
if (object.IsPrint(TimingsByLevel)) {
if (Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, object.ShortClassName() + ": " + msg +
" (total, level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
levelTimeMonitorExclusive_ = rcp(new MutuallyExclusiveTimeMonitor<Level>(object, object.ShortClassName() +
MUELU_TIMER_AS_STRING + ": " + msg + " (level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
}
}

FactoryMonitor::FactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel, MsgType timerLevel)
: Monitor(object, msg, FormattingHelper::getColonLabel(level.getObjectLabel()), msgLevel, timerLevel),
timerMonitorExclusive_(object, FormattingHelper::getColonLabel(level.getObjectLabel()) + object.ShortClassName() + ": " + msg, timerLevel)
{
if (object.IsPrint(TimingsByLevel)) {
std::string label = FormattingHelper::getColonLabel(level.getObjectLabel());
if (Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, label+object.ShortClassName() + ": " + msg +
" (total, level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
levelTimeMonitorExclusive_ = rcp(new MutuallyExclusiveTimeMonitor<Level>(object, label+object.ShortClassName() +
MUELU_TIMER_AS_STRING + ": " + msg + " (level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
}
}

SubFactoryMonitor::SubFactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel, MsgType timerLevel)
: SubMonitor(object, msg, msgLevel, timerLevel)
{
if (object.IsPrint(TimingsByLevel) && Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, object.ShortClassName() + ": " + msg +
" (sub, total, level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
}

SubFactoryMonitor::SubFactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel, MsgType timerLevel)
: SubMonitor(object, msg, FormattingHelper::getColonLabel(level.getObjectLabel()), msgLevel, timerLevel)
{
if (object.IsPrint(TimingsByLevel) && Teuchos::TimeMonitor::getStackedTimer().is_null()) {
std::string label = FormattingHelper::getColonLabel(level.getObjectLabel());
levelTimeMonitor_ = rcp(new TimeMonitor(object, label+object.ShortClassName() + ": " + msg +
" (sub, total, level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
}
}

} //namespace MueLu
79 changes: 11 additions & 68 deletions packages/muelu/src/Utils/MueLu_Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,8 @@ namespace MueLu {
public:

//! Constructor
PrintMonitor(const BaseClass& object, const std::string& msg, MsgType msgLevel = Runtime0) : object_(object) {
tabbed = false;
if (object_.IsPrint(msgLevel)) {
// Print description and new indent
object_.GetOStream(msgLevel, 0) << msg << std::endl;
object_.getOStream()->pushTab();
tabbed = true;
}
}

~PrintMonitor() { if (tabbed) object_.getOStream()->popTab(); }
PrintMonitor(const BaseClass& object, const std::string& msg, MsgType msgLevel = Runtime0);
~PrintMonitor();

private:
PrintMonitor();
Expand Down Expand Up @@ -122,10 +113,7 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
Monitor(const BaseClass& object, const std::string & msg, MsgType msgLevel = Runtime0, MsgType timerLevel = Timings0)
: printMonitor_(object, msg + " (" + object.description() + ")", msgLevel),
timerMonitor_(object, object.ShortClassName() + ": " + msg + " (total)", timerLevel)
{ }
Monitor(const BaseClass& object, const std::string & msg, MsgType msgLevel = Runtime0, MsgType timerLevel = Timings0);

/*! @brief Constructor.

Expand All @@ -135,10 +123,7 @@ namespace MueLu {
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
@param[in] label An optional prefix label.
*/
Monitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel = Runtime0, MsgType timerLevel = Timings0)
: printMonitor_(object, label + msg + " (" + object.description() + ")", msgLevel),
timerMonitor_(object, label + object.ShortClassName() + ": " + msg + " (total)", timerLevel)
{ }
Monitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel = Runtime0, MsgType timerLevel = Timings0);

private:
//! Manages printing.
Expand Down Expand Up @@ -174,10 +159,7 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
SubMonitor(const BaseClass& object, const std::string & msg, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1)
: printMonitor_(object, msg, msgLevel),
timerMonitor_(object, object.ShortClassName() + ": " + msg + " (sub, total)", timerLevel)
{ }
SubMonitor(const BaseClass& object, const std::string & msg, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1);

/*! @brief Constructor.

Expand All @@ -187,10 +169,7 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
SubMonitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1)
: printMonitor_(object, label + msg, msgLevel),
timerMonitor_(object, label + object.ShortClassName() + ": " + msg + " (sub, total)", timerLevel)
{ }
SubMonitor(const BaseClass& object, const std::string & msg, const std::string & label, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1);

private:
PrintMonitor printMonitor_;
Expand Down Expand Up @@ -238,18 +217,7 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
FactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel = static_cast<MsgType>(Test | Runtime0), MsgType timerLevel = Timings0)
: Monitor(object, msg, msgLevel, timerLevel),
timerMonitorExclusive_(object, object.ShortClassName() + ": " + msg, timerLevel)
{
if (object.IsPrint(TimingsByLevel)) {
if (Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, object.ShortClassName() + ": " + msg +
" (total, level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
levelTimeMonitorExclusive_ = rcp(new MutuallyExclusiveTimeMonitor<Level>(object, object.ShortClassName() +
MUELU_TIMER_AS_STRING + ": " + msg + " (level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
}
}
FactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel = static_cast<MsgType>(Test | Runtime0), MsgType timerLevel = Timings0);

/*! @brief Constructor

Expand All @@ -261,19 +229,7 @@ namespace MueLu {

TODO: code factorization
*/
FactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel = static_cast<MsgType>(Test | Runtime0), MsgType timerLevel = Timings0)
: Monitor(object, msg, FormattingHelper::getColonLabel(level.getObjectLabel()), msgLevel, timerLevel),
timerMonitorExclusive_(object, FormattingHelper::getColonLabel(level.getObjectLabel()) + object.ShortClassName() + ": " + msg, timerLevel)
{
if (object.IsPrint(TimingsByLevel)) {
std::string label = FormattingHelper::getColonLabel(level.getObjectLabel());
if (Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, label+object.ShortClassName() + ": " + msg +
" (total, level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
levelTimeMonitorExclusive_ = rcp(new MutuallyExclusiveTimeMonitor<Level>(object, label+object.ShortClassName() +
MUELU_TIMER_AS_STRING + ": " + msg + " (level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
}
}
FactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel = static_cast<MsgType>(Test | Runtime0), MsgType timerLevel = Timings0);

private:
//! Total time spent on this level in this object and all its children.
Expand Down Expand Up @@ -311,13 +267,7 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
SubFactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1)
: SubMonitor(object, msg, msgLevel, timerLevel)
{
if (object.IsPrint(TimingsByLevel) && Teuchos::TimeMonitor::getStackedTimer().is_null())
levelTimeMonitor_ = rcp(new TimeMonitor(object, object.ShortClassName() + ": " + msg +
" (sub, total, level=" + Teuchos::Utils::toString(levelID) + ")", timerLevel));
}
SubFactoryMonitor(const BaseClass& object, const std::string & msg, int levelID, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1);

/*! @brief Constructor

Expand All @@ -327,15 +277,8 @@ namespace MueLu {
@param[in] msgLevel Governs whether information should be printed.
@param[in] timerLevel Governs whether timing information should be *gathered*. Setting this to NoTimeReport prevents the creation of timers.
*/
SubFactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1)
: SubMonitor(object, msg, FormattingHelper::getColonLabel(level.getObjectLabel()), msgLevel, timerLevel)
{
if (object.IsPrint(TimingsByLevel) && Teuchos::TimeMonitor::getStackedTimer().is_null()) {
std::string label = FormattingHelper::getColonLabel(level.getObjectLabel());
levelTimeMonitor_ = rcp(new TimeMonitor(object, label+object.ShortClassName() + ": " + msg +
" (sub, total, level=" + Teuchos::Utils::toString(level.GetLevelID()) + ")", timerLevel));
}
}
SubFactoryMonitor(const BaseClass& object, const std::string & msg, const Level & level, MsgType msgLevel = Runtime1, MsgType timerLevel = Timings1);

private:
//! Total time spent on this level in this object and all children.
RCP<TimeMonitor> levelTimeMonitor_;
Expand Down
Loading