Commit 0854369b authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

command-line argument support

improved metadata print
parent 36d9081f
......@@ -46,7 +46,7 @@ endfunction()
function(MAKE_TARGET TARGET_MACRO_SUFFIX TARGET)
set("TARGET_${TARGET_MACRO_SUFFIX}" ${TARGET} PARENT_SCOPE)
add_executable (${TARGET})
add_test(run-${TARGET} ${TARGET})
add_test(run-${TARGET} ${TARGET} ${ARGN})
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 17)
SET_TARGET_OPTIONS(${TARGET} "-msse4.2" "")
if(USE_AVX)
......
......@@ -438,14 +438,14 @@ namespace fmwkng {
template< typename range_tag>
using controller_tag_category = typename decltype(range_tag::enumerator())::controller_tag_category;
template< typename context_t, typename range_tag>
template< typename context_t, typename diff_t>
class context_iterator {
private:
using self_ = context_iterator<context_t, range_tag>;
using self_ = context_iterator<context_t, diff_t>;
public:
using iterator_category = std::input_iterator_tag;
using value_type = context_t;
using difference_type = impl::enumerator_value_t<range_tag>;
using difference_type = diff_t;
using pointer = context_t*;
using reference = context_t&;
......@@ -454,13 +454,13 @@ namespace fmwkng {
{}
self_& operator++()
{
p_ = p_->template advance<range_tag>();
p_ = p_->advance();
return *this;
}
self_ operator++(int)
{
self_ rv(*this);
p_ = p_->template advance<range_tag>();
p_ = p_->advance();
return this;
}
bool operator==(const self_& b) const
......@@ -484,17 +484,17 @@ namespace fmwkng {
context_t* p_;
};
template< typename context_t, typename range_tag>
template< typename context_t, typename diff_t>
class context_range {
public:
using iterator = context_iterator< context_t, range_tag>;
using iterator = context_iterator< context_t, diff_t>;
template< typename ... TL>
context_range(TL&& ... vl)
: c_(std::forward<TL>(vl) ...)
{}
iterator begin()
{
return iterator(&c_);
return iterator(c_.current());
}
iterator end()
{
......@@ -827,7 +827,6 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "{";
}
using data_type = void;
};
......@@ -837,7 +836,6 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "}";
}
using data_type = void;
};
......@@ -850,6 +848,7 @@ namespace fmwkng {
root_data_holder(int argc, char** argv)
{
std::fill(platform_enablers_.begin(), platform_enablers_.end(), true);
process_arguments(std::vector< std::string>(argv + 1, argv + argc));
}
template< typename platform_tag>
bool check_platform() const
......@@ -978,6 +977,36 @@ namespace fmwkng {
std::cout << std::endl;
}
}
void process_arguments(const std::vector< std::string>& arg)
{
for (auto it = arg.begin(); it != arg.end(); ++it)
{
auto& a = *it;
if (a.size() >= 2 && a[0] == '-' && a[1] == '-')
{
auto cit = a.begin() + 2;
auto cite = find(cit, a.end(), '=');
auto& name = std::string_view(&*cit, cite - cit);
std::string_view value;
if (cite != a.end())
{
value = std::string_view(&*cite + 1, a.end() - cite - 1);
}
config_t::ranges::for_each([this, name, value](auto rs) {
using range_tag = pass_t<decltype(rs)>;
if (name == range_tag::name())
{
static constexpr auto index = config_t::ranges::template index_v<range_tag>;
auto&& cfg = std::get<index>(range_configs_);
cfg.config.set_arg(value);
}
});
}
}
}
};
template< typename tag>
......@@ -1043,9 +1072,14 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << platform_tag::name() << "{";
os << "platform:";
}
using data_type = void;
using data_type = std::monostate;
static void data_text(std::ostream& os, const data_type&)
{
os << platform_tag::name();
}
static constexpr bool useful = false;
};
template< typename platform_tag>
......@@ -1053,7 +1087,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "}";
os << ".";
}
using data_type = void;
};
......@@ -1064,7 +1098,7 @@ namespace fmwkng {
template< typename dt_t>
void entry(const dt_t& dt)
{
impl::thread_pointer(dt)->template push_element< platform_tag, element_sense::OPEN>();
impl::thread_pointer(dt)->template push_element< platform_tag, element_sense::OPEN>(std::monostate{});
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "enter_platform<" << platform_tag::name() << ">" << std::endl;
......@@ -1094,7 +1128,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << range_tag::name() << "{";
os << range_tag::name() << ":";
}
using data_type = enumerator_value_t< range_tag>;
static void data_text(std::ostream& os, const data_type& d)
......@@ -1109,7 +1143,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "}";
os << ".";
}
using data_type = void;
};
......@@ -1128,7 +1162,7 @@ namespace fmwkng {
{
static void metadata_marker_open(std::ostream& os)
{
os << range_tag::name() << "(";
os << "(" << range_tag::name();
}
static void metadata_marker_close(std::ostream& os)
{
......@@ -1168,6 +1202,13 @@ namespace fmwkng {
}
}
template< typename dt_t>
bool valid(const dt_t& dt)
{
auto&& c = get_my_config(dt).config;
return c.valid(v_);
}
template< typename dt_t>
bool advance(const dt_t& dt)
{
......@@ -1220,7 +1261,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "[";
os << "thr:";
}
using data_type = std::size_t;
static void data_text(std::ostream& os, const data_type& d)
......@@ -1235,7 +1276,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "]";
os << ".";
}
using data_type = void;
};
......@@ -1450,7 +1491,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << result_tag::name() << "<";
os << "<" << result_tag::name();
}
using data_type = void;
};
......@@ -1528,6 +1569,11 @@ namespace fmwkng {
v = v_first_;
}
bool valid(const value_t& v) const
{
return v <= v_last_;
}
bool advance(value_t& v) const
{
v *= v_factor_;
......@@ -1568,7 +1614,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << "+<";
os << "[";
}
using data_type = void;
/*
......@@ -1586,7 +1632,7 @@ namespace fmwkng {
{
static void metadata_marker(std::ostream& os)
{
os << ">";
os << "ns]";
}
using data_type = clock::duration;
static void data_text(std::ostream& os, const data_type& d)
......@@ -1626,6 +1672,12 @@ namespace fmwkng {
return false;
}
template< typename dt_t>
bool valid(const dt_t& dt)
{
return rch_.config.valid(v_);
}
template< typename dt_t>
bool advance(const dt_t& dt)
{
......@@ -1924,8 +1976,9 @@ namespace fmwkng {
auto for_range() const
{ // !!!
using child_context = tagged_context< range_tag, tags ...>;
using diff_t = impl::enumerator_value_t<range_tag>;
return impl::context_range< child_context, range_tag>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple());
return impl::context_range< child_context, diff_t>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple());
}
template< typename range_tag>
......@@ -1952,8 +2005,9 @@ namespace fmwkng {
{
using my_measurement_tag = impl::auto_measurement_tag< range_tags ...>;
using child_context = tagged_context< my_measurement_tag, tags ...>;
using diff_t = impl::enumerator_value_t<my_measurement_tag>;
return impl::context_range< child_context, my_measurement_tag>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple(), v_last);
return impl::context_range< child_context, diff_t>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple(), v_last);
}
bool stop_for_results()
......@@ -1961,7 +2015,12 @@ namespace fmwkng {
return dt_.get_my_pointer()->stop_for_results(dt_);
}
template< typename range_tag>
self_* current()
{
auto rv = dt_.get_my_pointer()->valid(dt_);
return rv ? this : nullptr;
}
self_* advance()
{
auto rv = dt_.get_my_pointer()->advance(dt_);
......@@ -2069,6 +2128,11 @@ namespace fmwkng {
v = v_first_;
}
bool valid(const value_t& v) const
{
return v <= v_last_;
}
bool advance(value_t& v) const
{
v += v_step_;
......@@ -2102,11 +2166,21 @@ namespace fmwkng {
: v_count_(base.v_count_ * multiplier / divisor)
{}
void set_arg(std::string_view s)
{
v_count_ = std::stoll(std::string(s));
}
void init(value_type& v) const
{
v = 0;
}
bool valid(const value_type& v) const
{
return v < v_count_;
}
bool advance(value_type& v) const
{
++v;
......@@ -2136,6 +2210,51 @@ namespace fmwkng {
private:
value_type v_count_;
};
class flag {
public:
using controller_tag_category = impl::root_tag_category;
using value_type = bool;
flag(value_type v_flag)
: v_flag_(v_flag)
{}
void set_arg(std::string_view s)
{
if (s == "1" || s == "true" || s == "on")
v_flag_ = true;
else
v_flag_ = false;
}
void init(value_type& v) const
{
v = false;
}
bool valid(const value_type& v) const
{
return ! v && v_flag_;
}
bool advance(value_type& v) const
{
v = true;
return false;
}
value_type count() const
{
return v_flag_;
}
void data_text(std::ostream& os) const
{
os << (v_flag_ ? "true" : "false");
}
private:
value_type v_flag_;
};
#pragma endregion
#pragma region public_wrappers
template< typename X>
......
......@@ -52,6 +52,14 @@ namespace macromain {
}
};
struct dump {
using tag_category = fmwkng::range_tag_category;
static auto name() { return "dump"; }
static auto enumerator() {
return fmwkng::flag(false);
}
};
struct output_hash {
using tag_category = fmwkng::result_tag_category;
static auto name() { return "output_hash"; }
......@@ -70,7 +78,7 @@ namespace macromain {
, platform_avx512
#endif
>;
using ranges = fmwkng::ranges<lines>;
using ranges = fmwkng::ranges<lines, dump>;
};
struct run_thread_ftor {
......@@ -83,10 +91,19 @@ namespace macromain {
macroasgn::macrotext_generator mg(
std::mt19937_64::default_seed + ctx2.thread_index()
, 3, 10, 1021, 8, 3, 3, 5, 0);
if ( count<dump>(ctx2))
{
mg.advance(1000);
std::ofstream is("input." + std::to_string(ctx2.thread_index()) + ".txt");
std::ofstream os("output." + std::to_string(ctx2.thread_index()) + ".txt");
auto flags = platform_t<decltype(ctx2)>::name() + std::string(".") + std::to_string(ctx2.thread_index());
auto ifn = "input." + flags + ".txt";
auto ofn = "output." + flags + ".txt";
std::ofstream is(ifn);
std::ofstream os(ofn);
{
auto g = guard(ctx2);
std::cout << "Dumping\t" << ifn << "\t" << ofn << std::endl;
}
macrosol::macroprocessor< macrosol::policy_scalar> mp;
std::string output;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment