Skip to content

Commit

Permalink
#869 promote ArgConfig to a component
Browse files Browse the repository at this point in the history
- use Component as a base class for ArgConfig
- use forward declarations to avoid circular dependency
- adjust #includes
  • Loading branch information
cz4rs committed Jul 3, 2020
1 parent 5b7217f commit b82d4e0
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "vt/config.h"
#include "vt/configs/arguments/argparse.h"
#include "vt/configs/arguments/args.h"
//#include "vt/objgroup/manager.h"

#include <string>
#include <vector>
Expand All @@ -55,6 +56,13 @@

namespace vt { namespace arguments {

/*static*/ std::unique_ptr<ArgConfig> ArgConfig::construct() {
auto ptr = std::make_unique<ArgConfig>();
// auto proxy = theObjGroup()->makeCollective<ArgConfig>(ptr.get());
// proxy.get()->setProxy(proxy);
return ptr;
}

void addColorArgs(CLI::App& app) {
auto quiet = "Quiet the output from vt (only errors, warnings)";
auto always = "Colorize output (default)";
Expand Down
16 changes: 13 additions & 3 deletions src/vt/configs/arguments/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@
#if !defined INCLUDED_VT_CONFIGS_ARGUMENTS_ARGS_H
#define INCLUDED_VT_CONFIGS_ARGUMENTS_ARGS_H

// Do not pull in any VT dependencies here
// Do not pull in any other VT dependencies here
namespace vt { namespace arguments {
struct ArgConfig;
}}

#include "vt/runtime/component/component.h"

#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <tuple>

namespace vt { namespace arguments {

struct ArgConfig {
struct ArgConfig : runtime::component::Component<ArgConfig> {

/// Parse the arguments into ArgConfig.
/// Re-assigns argc/argv to remove consumed arguments.
Expand All @@ -63,6 +69,10 @@ struct ArgConfig {
/// with an appropriate display message.
std::tuple<int, std::string> parse(int& argc, char**& argv);

std::string name() override { return "ArgConfig"; }

static std::unique_ptr<ArgConfig> construct();

public:
inline bool user1() { return vt_user_1; }
inline bool user2() { return vt_user_2; }
Expand Down Expand Up @@ -230,7 +240,7 @@ struct ArgConfig {

namespace vt {

arguments::ArgConfig* theArgConfig();
extern arguments::ArgConfig* theArgConfig();

} /* end namespace vt */

Expand Down
3 changes: 1 addition & 2 deletions src/vt/configs/debug/debug_colorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
namespace vt { namespace debug {

inline bool colorizeOutput() {
return theArgConfig()->colorize_output;
return vt::theArgConfig()->colorize_output;
}

inline std::string green() { return colorizeOutput() ? "\033[32m" : ""; }
Expand Down Expand Up @@ -93,5 +93,4 @@ inline std::string proc(vt::NodeType const& node) {

}} /* end namespace vt::debug */


#endif /*INCLUDED_VT_CONFIGS_DEBUG_DEBUG_COLORIZE_H*/
1 change: 1 addition & 0 deletions src/vt/configs/debug/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#if !defined INCLUDED_VT_CONFIGS_DEBUG_DEBUG_PRINT_H
#define INCLUDED_VT_CONFIGS_DEBUG_DEBUG_PRINT_H

#include "vt/configs/arguments/args.h"
#include "vt/configs/types/types_headers.h"
#include "vt/configs/debug/debug_config.h"
#include "vt/configs/debug/debug_colorize.h"
Expand Down
10 changes: 10 additions & 0 deletions src/vt/configs/error/error.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@

#include "fmt/format.h"

namespace vt { namespace debug {

std::string stringizeMessage(
std::string const& msg, std::string const& reason, std::string const& cond,
std::string const& file, int const line, std::string const& func,
ErrorCodeType error
);

}} /* end namespace vt::debug */

namespace vt { namespace error {

template <typename... Args>
Expand Down
16 changes: 11 additions & 5 deletions src/vt/runtime/component/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#if !defined INCLUDED_VT_RUNTIME_COMPONENT_COMPONENT_H
#define INCLUDED_VT_RUNTIME_COMPONENT_COMPONENT_H

#include "vt/configs/error/hard_error.h"
#include "vt/runtime/component/component_registry.h"
#include "vt/runtime/component/component_dep.h"
#include "vt/runtime/component/component_traits.h"
Expand Down Expand Up @@ -186,13 +185,20 @@ struct PollableComponent : Component<T> {
*
* \return number of units processed---zero
*/
virtual int progress() override {
vtAbort("PollableComponent should override the empty progress function");
return 0;
}
virtual int progress() override;

};

}}} /* end namespace vt::runtime::component */

#include "vt/configs/error/hard_error.h"

namespace vt { namespace runtime { namespace component {
template <typename T>
int PollableComponent<T>::progress() {
vtAbort("PollableComponent should override the empty progress function");
return 0;
}
}}}

#endif /*INCLUDED_VT_RUNTIME_COMPONENT_COMPONENT_H*/
7 changes: 6 additions & 1 deletion src/vt/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,12 @@ void Runtime::initializeComponents() {

p_ = std::make_unique<ComponentPack>();

p_->registerComponent<arguments::ArgConfig>(&theArgConfig, Deps<
ctx::Context
>{});

p_->registerComponent<ctx::Context>(
&theContext, Deps<>{},
&theContext, Deps<arguments::ArgConfig>{},
user_argc_, &user_argv_[0], is_interop_, &communicator_
);

Expand Down Expand Up @@ -757,6 +761,7 @@ void Runtime::initializeComponents() {
>{}
);

p_->add<arguments::ArgConfig>();
p_->add<ctx::Context>();
p_->add<util::memory::MemoryUsage>();
p_->add<registry::Registry>();
Expand Down
2 changes: 1 addition & 1 deletion src/vt/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ struct Runtime {
static void termHandler();

public:
ComponentPtrType<arguments::ArgConfig> theArgConfig;
ComponentPtrType<registry::Registry> theRegistry;
ComponentPtrType<messaging::ActiveMessenger> theMsg;
ComponentPtrType<ctx::Context> theContext;
Expand All @@ -391,7 +392,6 @@ struct Runtime {
ComponentPtrType<vrt::collection::balance::ProcStats> theProcStats;
ComponentPtrType<vrt::collection::balance::StatsRestartReader> theStatsReader;
ComponentPtrType<vrt::collection::balance::LBManager> theLBManager;
vt::arguments::ArgConfig theArgConfig;

// Node-level worker-based components for vt (these are optional)
ComponentPtrType<worker::WorkerGroupType> theWorkerGrp;
Expand Down
3 changes: 3 additions & 0 deletions src/vt/runtime/runtime_component_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

namespace vt {

namespace arguments {
struct ArgConfig;
}
namespace registry {
struct Registry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/runtime/runtime_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ util::memory::MemoryUsage* theMemUsage() { return CUR_RT->theMemUsage
vrt::collection::balance::ProcStats* theProcStats() { return CUR_RT->theProcStats; }
vrt::collection::balance::StatsRestartReader* theStatsReader() { return CUR_RT->theStatsReader; }
vrt::collection::balance::LBManager* theLBManager() { return CUR_RT->theLBManager; }
vt::arguments::ArgConfig* theArgConfig() { return &(CUR_RT->theArgConfig); }
vt::arguments::ArgConfig* theArgConfig() { return CUR_RT->theArgConfig; }


#if backend_check_enabled(trace_enabled)
Expand Down
1 change: 1 addition & 0 deletions src/vt/utils/memory/memory_usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*/

#include "vt/config.h"
#include "vt/configs/arguments/args.h"
#include "vt/utils/memory/memory_usage.h"

#include <vector>
Expand Down

0 comments on commit b82d4e0

Please sign in to comment.