Skip to content

Commit

Permalink
Merge pull request #998 from DARMA-tasking/990-nompi-tests
Browse files Browse the repository at this point in the history
990 - Non-MPI tests run without MPI
  • Loading branch information
PhilMiller authored Aug 25, 2020
2 parents b5e7503 + 83b1f75 commit 306d713
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 133 deletions.
20 changes: 4 additions & 16 deletions src/vt/configs/debug/debug_colorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@

#include <string>

namespace vt { namespace config {

inline arguments::AppConfig const* getConfig();

}} /* end namespace vt::config */
namespace vt { namespace debug {
arguments::AppConfig const* preConfig();
}} /* end namespace vt::debug */

namespace vt { namespace debug {

inline bool colorizeOutput() {
return vt::config::getConfig()->colorize_output;
return vt::debug::preConfig()->colorize_output;
}

inline std::string green() { return colorizeOutput() ? "\033[32m" : ""; }
Expand Down Expand Up @@ -87,16 +85,6 @@ inline std::string proc(vt::NodeType const& node) {
return blue() + "[" + std::to_string(node) + "]" + reset();
}

// static bool ttyi(FILE* stream) {
// struct stat stream_stat;
// if (fstat(fileno(stream), &stream_stat) == 0) {
// if (stream_stat.st_mode & S_IFREG) {
// return true;
// }
// }
// return false;
// }

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

#endif /*INCLUDED_VT_CONFIGS_DEBUG_DEBUG_COLORIZE_H*/
47 changes: 8 additions & 39 deletions src/vt/configs/debug/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@
#define vt_proc_print_colorize(proc) \
vt_print_colorize_impl(::vt::debug::blue(), "[" + std::to_string(proc) + "]", "")

#define vt_debug_argument_option(opt) \
::vt::config::getConfig()->vt_debug_ ## opt

#define vt_debug_all_option ::vt::config::getConfig()->vt_debug_all
#define vt_debug_argument_option(opt) \
::vt::debug::preConfig()->vt_debug_ ## opt

#define vt_debug_print_impl(force, inconfig, inmode, cat, ctx, ...) \
vt::config::ApplyOp< \
Expand Down Expand Up @@ -140,64 +138,35 @@

#define vt_print(feature, ...) \
do { \
if (!::vt::config::getConfig()->vt_quiet) { \
if (!::vt::debug::preConfig()->vt_quiet) { \
vt_print_force_impl(feature, node, __VA_ARGS__); \
} \
} while(0);

#define vt_option_check_enabled(mode, bit) ((mode & bit) not_eq 0)

namespace vt { namespace runtime {

struct Runtime;

/**
* \brief Test if the runtime configuration is available at this point in
* startup. Convenience function for use in debug printing without including VT
* runtime headers.
*
* \return whether `theConfig()` is available
*/
bool configLive();

/**
* \brief Get the runtime config before VT is fully initialized. Convenience
* function for use in debug printing without including VT runtime headers.
*
* \return the app config
*/
arguments::AppConfig const* getRuntimeConfig();

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

namespace vt {
extern runtime::Runtime* curRT;
} /* end namespace vt */

namespace vt { namespace debug {
arguments::AppConfig const* preConfig();
NodeType preNode();
}} /* end namespace vt::debug */

namespace vt { namespace config {

/**
* \brief Get the app configuration safely even during startup/shutdown. This
* function will always return a valid pointer if the VT runtime is live even
* when components are not initialized;
*
* \return the app config
*/
inline arguments::AppConfig const* getConfig() {
return runtime::configLive() ? vt::theConfig() : runtime::getRuntimeConfig();
}

template <CatEnum cat, CtxEnum ctx, ModeEnum mod>
struct DebugPrintOp;

template <CatEnum cat, ModeEnum mod, typename Arg, typename... Args>
static inline void debugPrintImpl(NodeType node, Arg&& arg, Args&&... args) {
bool const verb = vt_option_check_enabled(mod, ModeEnum::verbose);
if ((verb and getConfig()->vt_debug_verbose) or not verb) {
if ((verb and vt::debug::preConfig()->vt_debug_verbose) or not verb) {
auto user = fmt::format(std::forward<Arg>(arg),std::forward<Args>(args)...);
fmt::print(
"{} {} {} {}",
Expand All @@ -206,7 +175,7 @@ static inline void debugPrintImpl(NodeType node, Arg&& arg, Args&&... args) {
vt_print_colorize_impl(::vt::debug::green(), PrettyPrintCat<cat>::print(), ":"),
user
);
if (vt_option_check_enabled(mod, ModeEnum::flush) or getConfig()->alwaysFlush()) {
if (vt_option_check_enabled(mod, ModeEnum::flush) or vt::debug::preConfig()->alwaysFlush()) {
fflush(stdout);
}
}
Expand All @@ -216,7 +185,7 @@ template <CatEnum cat, ModeEnum mod>
struct DebugPrintOp<cat, CtxEnum::node, mod> {
template <typename Arg, typename... Args>
void operator()(bool const rt_option, Arg&& arg, Args&&... args) {
if (rt_option or getConfig()->vt_debug_all) {
if (rt_option or vt::debug::preConfig()->vt_debug_all) {
auto no_node = static_cast<NodeType>(-1);
auto node = vt::curRT != nullptr ? vt::debug::preNode() : no_node;
debugPrintImpl<cat,mod>(node,std::forward<Arg>(arg),std::forward<Args>(args)...);
Expand All @@ -228,7 +197,7 @@ template <CatEnum cat, ModeEnum mod>
struct DebugPrintOp<cat, CtxEnum::unknown, mod> {
template <typename Arg, typename... Args>
void operator()(bool const rt_option, Arg&& arg, Args&&... args) {
if (rt_option or getConfig()->vt_debug_all) {
if (rt_option or vt::debug::preConfig()->vt_debug_all) {
debugPrintImpl<cat,mod>(-1,std::forward<Arg>(arg),std::forward<Args>(args)...);
}
}
Expand Down
45 changes: 22 additions & 23 deletions src/vt/runtime/runtime_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,32 @@ trace::Trace* theTrace() { return CUR_RT->theTrace;
pmpi::PMPIComponent* thePMPI() { return CUR_RT->thePMPI; }
#endif

namespace runtime {
#undef CUR_RT
#undef CUR_RT_SAFE
#undef IS_COMM_THREAD

/**
* \brief Test if the runtime configuration is available at this point in
* startup. Convenience function for use in debug printing without including VT
* runtime headers.
*
* \return whether `theConfig()` is available
*/
bool configLive() {
return curRT->theArgConfig != nullptr;
}
} /* end namespace vt */

namespace vt { namespace debug {

// Dummy config that applies outside of RT initialization, much like preNode.
static arguments::AppConfig preInitAppConfig{};

/**
* \brief Get the runtime config before VT is fully initialized. Convenience
* function for use in debug printing without including VT runtime headers.
* \internal
* \brief Returns the config, accessible OUTSIDE of VT initialization.
*
* Much as preNode, this can be accessed safely in debug* methods.
* This allows such methods to be used in code that is unit-test OK.
*
* \return the app config
* \return A configuration; possible a default configuration.
*/
arguments::AppConfig const* getRuntimeConfig() {
return curRT->getAppConfig();
arguments::AppConfig const* preConfig() {
auto const rt = curRT;
if (not rt)
return &preInitAppConfig;
auto const* config = rt->theArgConfig;
return config not_eq nullptr ? &config->config_ : rt->getAppConfig();
}

} /* end namespace runtime */

#undef CUR_RT
#undef CUR_RT_SAFE
#undef IS_COMM_THREAD

} /* end namespace vt */
}} /* end namespace vt::debug */
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/baselb/baselb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void BaseLB::importProcessorData(
void BaseLB::getArgs(PhaseType phase) {
using namespace balance;

bool has_spec = ReadLBSpec::hasSpec();
bool has_spec = ReadLBSpec::openSpec(theConfig()->vt_lb_file_name);
if (has_spec) {
auto spec = ReadLBSpec::entry(phase);
if (spec) {
Expand Down
5 changes: 3 additions & 2 deletions src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ LBType LBManager::decideLBToRun(PhaseType phase, bool try_file) {
return LBType::NoLB;
}

if (theConfig()->vt_lb_file_name != "" and try_file) {
bool const has_spec = ReadLBSpec::hasSpec();
auto& spec_file = theConfig()->vt_lb_file_name;
if (spec_file != "" and try_file) {
bool const has_spec = ReadLBSpec::openSpec(spec_file);
if (has_spec) {
the_lb = ReadLBSpec::getLB(phase);
}
Expand Down
56 changes: 28 additions & 28 deletions src/vt/vrt/collection/balance/read_lb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,44 @@

namespace vt { namespace vrt { namespace collection { namespace balance {

/*static*/ std::string ReadLBSpec::filename = {};
/*static*/ std::string ReadLBSpec::open_filename_ = {};
/*static*/ typename ReadLBSpec::SpecMapType ReadLBSpec::spec_mod_ = {};
/*static*/ typename ReadLBSpec::SpecMapType ReadLBSpec::spec_exact_ = {};
/*static*/ std::vector<SpecIndex> ReadLBSpec::spec_prec_ = {};
/*static*/ bool ReadLBSpec::read_complete_ = false;

/*static*/ bool ReadLBSpec::hasSpec() {
if (read_complete_) {
return true;
/*static*/ bool ReadLBSpec::openSpec(std::string const& filename) {
// No-op if no file specified. Can't be used to clear.
if (filename.empty()) {
return false;
}

auto const file_name = theConfig()->vt_lb_file_name;
if (file_name == "") {
return false;
// Ignore attempt to open same spec.
if (not open_filename_.empty() and open_filename_ == filename) {
return true;
}

bool good = openFile(file_name);
if (not good) {
auto str =
fmt::format("--vt_lb_file_name={} is not a valid file", file_name);
vtAssert(
open_filename_.empty(),
"Spec already opened. Use clear first to load again."
);

// Ensure file can be opened.
std::ifstream file(filename);
if (not file.good()) {
auto str = fmt::format("Unable to open spec file: {}", filename);
vtAbort(str);
}
return good;
}

/*static*/ bool ReadLBSpec::openFile(std::string const name) {
std::ifstream file(name);
filename = name;
return file.good();
// Remember loaded file - multiple calls to same file are idempotent.
open_filename_ = filename;

readFile(filename);

return true;
}

/*static*/ LBType ReadLBSpec::getLB(SpecIndex const& idx) {
if (not read_complete_) {
readFile();
}
auto const lb = entry(idx);
if (lb) {
return lb->getLB();
Expand Down Expand Up @@ -133,11 +136,7 @@ int eatWhitespace(std::ifstream& file) {
return file.eof() ? 0 : file.peek();
}

/*static*/ void ReadLBSpec::readFile() {
if (read_complete_) {
return;
}

/*static*/ void ReadLBSpec::readFile(std::string const& filename) {
std::ifstream file(filename);
vtAssert(file.good(), "must be valid");

Expand Down Expand Up @@ -245,7 +244,7 @@ int eatWhitespace(std::ifstream& file) {

/*static*/ void ReadLBSpec::clear() {
read_complete_ = false;
filename = "";
open_filename_ = "";
spec_mod_.clear();
spec_exact_.clear();
spec_prec_.clear();
Expand Down Expand Up @@ -332,8 +331,9 @@ auto excluded_str = [](SpecIndex idx) -> std::string {
/*static*/ std::string ReadLBSpec::toString() {
std::stringstream ss;

ReadLBSpec::openFile(theConfig()->vt_lb_file_name);
ReadLBSpec::readFile();
if (open_filename_.empty()) {
return "[No LB Spec open]";
}

if (not ReadLBSpec::getExactEntries().empty()) {
ss << fmt::format("{}\tExact specification lines:\n", vt::debug::vtPre());
Expand Down
22 changes: 17 additions & 5 deletions src/vt/vrt/collection/balance/read_lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,35 @@ struct ReadLBSpec {
using SpecMapType = std::map<SpecIndex,SpecEntry>;
using ParamMapType = std::map<std::string, std::string>;

static bool openFile(std::string const name = "");
static void readFile();
/**
* \brief Opens and reads the spec file, if it exists.
*
* This method MUST be called before the other access methods.
*
* \param[in] filename The path to the file to read.
*
* \pre A different spec file is not currently open.
* \pre The filename refers to a valid spec file.
*
* \return True if the spec was opened and can be used.
*/
static bool openSpec(std::string const& filename);

static bool hasSpec();
static SpecIndex numEntries() { return spec_mod_.size() + spec_exact_.size(); }
static SpecEntry* entry(SpecIndex const& idx);
static LBType getLB(SpecIndex const& idx);
static SpecMapType getModEntries() { return spec_mod_; };
static SpecMapType getExactEntries() {return spec_exact_; };
static ParamMapType parseParams(std::vector<std::string> params);
static SpecEntry makeSpecFromParams(std::string params);
static void clear();
static std::string toString();
static void clear();

private:
static void readFile(std::string const& filename);

static bool read_complete_;
static std::string filename;
static std::string open_filename_;
static SpecMapType spec_mod_;
static SpecMapType spec_exact_;
static std::vector<SpecIndex> spec_prec_;
Expand Down
Loading

0 comments on commit 306d713

Please sign in to comment.