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

Merge branch 'master' into 'master'

fmwkng: measurement lead-in/out; macroasgn: decreased data supply overhead

See merge request teaching/nprg054/asgn!3
parents 1e66ee6b 41f78deb
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
\ No newline at end of file
......@@ -1492,6 +1492,11 @@ namespace fmwkng {
: v_first_(v_first), v_last_(v_last), v_factor_(v_factor)
{}
void set_v_last(std::size_t v_last)
{
v_last_ = v_last;
}
void init(value_t& v) const
{
v = v_first_;
......@@ -1568,62 +1573,49 @@ namespace fmwkng {
template< typename ... range_tags>
class auto_measurement_data_holder {
public:
auto_measurement_data_holder()
{}
auto_measurement_data_holder(std::size_t v_last)
: p_(phase::LEAD_IN)
{
rch_.config.set_v_last( v_last);
}
template< typename dt_t>
void entry(const dt_t& dt)
{
p_ = phase::LEAD_IN;
rch_.config.init(v_);
reconfig(dt);
{
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "enter_measurement" << std::endl;
*/
}
impl::thread_pointer(dt)->rendezvous(dt);
impl::thread_pointer(dt)->template push_element<my_tag, element_sense::OPEN>();
push_config_open(dt);
start_ = clock::now();
enter_phase(dt);
}
template< typename dt_t>
bool advance(const dt_t& dt)
{
stop_ = clock::now();
auto delta = stop_ - start_;
push_config_close(dt);
impl::thread_pointer(dt)->template push_element<my_tag, element_sense::CLOSE>(delta);
auto avg = impl::thread_pointer(dt)->rendezvous_average(dt, delta.count());
if (avg < minimum_count)
exit_phase(dt);
if (p_ == phase::LEAD_IN)
{
p_ = phase::TEST;
}
else if (p_ == phase::TEST)
{
p_ = phase::LEAD_OUT;
}
else if (p_ == phase::LEAD_OUT)
{
if (avg_delta_ >= minimum_count)
return false;
auto rv = rch_.config.advance(v_);
if (rv)
{
reconfig(dt);
impl::thread_pointer(dt)->template push_element<my_tag, element_sense::OPEN>();
push_config_open(dt);
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "advance_range<" << tag::name() << ">(" << v_ << ")" << std::endl;
*/
start_ = clock::now();
return true;
}
if (!rv)
return false;
p_ = phase::LEAD_IN;
}
return false;
enter_phase(dt);
return true;
}
template< typename dt_t>
void exit(const dt_t& dt)
{
{
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "exit_measurement(" << delta.count() << ")" << std::endl;
*/
}
}
template< typename range_tag>
......@@ -1634,8 +1626,13 @@ namespace fmwkng {
}
private:
enum class phase { LEAD_IN, TEST, LEAD_OUT };
phase p_;
using time_point = clock::time_point;
using time_delta = clock::duration;
time_point start_, stop_;
time_delta delta_;
average_t avg_delta_;
using my_tag = auto_measurement_tag< range_tags...>;
range_config_holder<my_tag> rch_;
using value_type = enumerator_value_t<my_tag>;
......@@ -1645,16 +1642,16 @@ namespace fmwkng {
typename my_ranges::tuple_t range_configs_;
template< typename dt_t>
void reconfig(const dt_t& dt)
void reconfig(const dt_t& dt, std::size_t multiplier, std::size_t divisor)
{
auto root = impl::root_pointer(dt);
my_ranges::for_each([this, root](auto p) {
my_ranges::for_each([this, root, multiplier, divisor](auto p) {
using range_tag = impl::pass_t<decltype(p)>;
using c_type = typename range_config_holder<range_tag>::enumerator_t;
static constexpr auto index = my_ranges::template index_v<range_tag>;
auto&& base_c = root->template get_range_config<range_tag>();
auto&& my_c = std::get<index>(range_configs_);
my_c.config = c_type(base_c.config, v_);
my_c.config = c_type(base_c.config, multiplier, divisor);
});
}
......@@ -1683,6 +1680,44 @@ namespace fmwkng {
thread->push_element_ptr(std::make_unique<my_config_element>());
});
}
template< typename dt_t>
void enter_phase(const dt_t& dt)
{
reconfig(dt, v_, p_ == phase::TEST ? 1 : 5); // 20% lead-in/out
{
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "enter_measurement" << std::endl;
*/
}
if (p_ == phase::LEAD_IN)
{
impl::thread_pointer(dt)->rendezvous(dt);
impl::thread_pointer(dt)->template push_element<my_tag, element_sense::OPEN>();
push_config_open(dt);
}
if (p_ == phase::TEST)
{
start_ = clock::now();
}
}
template< typename dt_t>
void exit_phase(const dt_t& dt)
{
if (p_ == phase::TEST)
{
stop_ = clock::now();
delta_ = stop_ - start_;
}
if (p_ == phase::LEAD_OUT)
{
push_config_close(dt);
impl::thread_pointer(dt)->template push_element<my_tag, element_sense::CLOSE>(delta_);
avg_delta_ = impl::thread_pointer(dt)->rendezvous_average(dt, delta_.count());
}
}
};
template< typename ... range_tags>
......@@ -1872,12 +1907,12 @@ namespace fmwkng {
}
template< typename ... range_tags>
auto auto_measurement() const
auto auto_measurement(std::size_t v_last) const
{
using my_measurement_tag = impl::auto_measurement_tag< range_tags ...>;
using child_context = tagged_context< my_measurement_tag, tags ...>;
return impl::context_range< child_context, my_measurement_tag>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple());
return impl::context_range< child_context, my_measurement_tag>(dt_.get_my_pointer(), dt_.get_parent_pointer_tuple(), v_last);
}
template< typename range_tag>
......@@ -1925,7 +1960,10 @@ namespace fmwkng {
static std::size_t compute_preferred_concurrency()
{
try {
#pragma warning(push)
#pragma warning(disable: 4996)
auto env1 = std::getenv("SLURM_CPUS_ON_NODE");
#pragma warning(pop)
if (env1)
{
auto num1 = std::stoi(env1);
......@@ -2006,8 +2044,8 @@ namespace fmwkng {
: v_count_(v_count)
{}
auto_repeat(const auto_repeat & base, value_type multiplier)
: v_count_(base.v_count_ * multiplier)
auto_repeat(const auto_repeat & base, value_type multiplier, value_type divisor)
: v_count_(base.v_count_ * multiplier / divisor)
{}
void init(value_type& v) const
......@@ -2104,9 +2142,9 @@ namespace fmwkng {
}
template< typename range_tag, typename ... tags>
auto auto_measurement(const tagged_context< tags ...>& ctx)
auto auto_measurement(const tagged_context< tags ...>& ctx, std::size_t v_last)
{
return ctx.template auto_measurement< range_tag>();
return ctx.template auto_measurement< range_tag>( v_last);
}
template< typename ... tags>
......
......@@ -87,7 +87,8 @@ namespace macroasgn {
{
need_space = true;
}
line.append(level_names[rlx][nix2]);
auto&& nm = level_names[rlx][nix2];
line.insert(line.end(), nm.begin(), nm.end());
space_gen(line);
}
else if (rlx < level_count)
......@@ -115,7 +116,7 @@ namespace macroasgn {
{
need_space = true;
}
line.append(rv.first);
line.insert(line.end(), rv.first.begin(), rv.first.end());
space_gen(line);
break;
}
......@@ -136,7 +137,8 @@ namespace macroasgn {
// generate macro definition for level rm
space_gen(line);
auto lix = name_distro(engine);
line.append(level_names[rm][lix]);
auto&& nm = level_names[rm][lix];
line.insert(line.end(), nm.begin(), nm.end());
space_gen(line);
line.push_back('=');
space_gen(line);
......
......@@ -21,17 +21,17 @@ namespace macroasgn {
limit += i;
}
bool getline(std::string& s)
const std::string * getline()
{
if (index >= limit)
{
return false;
return nullptr;
}
else
{
s = lines[index % lines.size()];
auto p = &lines[index % lines.size()];
++index;
return true;
return p;
}
}
......
......@@ -6,6 +6,8 @@
#include "fmwkng.hpp"
#include <fstream>
#include <string_view>
#include <vector>
namespace macromain {
......@@ -77,21 +79,20 @@ namespace macromain {
std::mt19937_64::default_seed + ctx2.thread_index()
, 3, 10, 1021, 8, 3, 3, 5, 0);
{
//auto ctx4 = measurement(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");
macrosol::macroprocessor< macrosol::policy_scalar> mp;
std::string output;
for (;;)
{
std::string s;
auto rv = mg.getline(s);
auto rv = mg.getline();
if (!rv)
break;
is << s << std::endl;
std::string output;
auto rv2 = mp.process(s, output);
is << *rv << std::endl;
output.clear();
auto rv2 = mp.process(*rv, output);
if (rv2)
{
os << output << std::endl;
......@@ -99,26 +100,22 @@ namespace macromain {
}
}
std::size_t h = 0;
for (auto&& ctx5 : auto_measurement<lines>(ctx2))
for (auto&& ctx5 : auto_measurement<lines>(ctx2, 1024))
{
macrosol::macroprocessor< macrosol::policy_scalar> mp;
mg.advance(count<lines>(ctx5));
std::string output;
for (;;)
{
std::string s;
auto rv = mg.getline(s);
auto rv = mg.getline();
if (!rv)
break;
std::string output;
auto rv2 = mp.process(s, output);
output.clear();
auto rv2 = mp.process(*rv, output);
if (rv2)
h += std::hash<std::string>()(output);
}
}
/*{
auto g = guard(ctx2);
std::cout << thread_index(ctx2) << ": " << h << std::endl;
}*/
}
}
};
......
Markdown is supported
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