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

aggregation completely broken

parent f7b2d14e
......@@ -48,6 +48,7 @@ namespace fmwkng {
virtual void metadata_marker(std::ostream& os) const = 0;
virtual bool useful() const = 0;
virtual bool reducible() const = 0;
virtual element_ptr aggregate_init() const = 0;
virtual void aggregate_with(const abstract_element* other) = 0;
virtual element_sense sense() const = 0;
};
......@@ -356,7 +357,11 @@ namespace fmwkng {
{
// first seen
reduction_order.push_back(&*rv.first);
rv.first->second = src.clone();
auto sz = src.size();
for (std::size_t i = 0; i < sz; ++i)
{
rv.first->second.push_back( src[i]->aggregate_init());
}
}
else
{
......@@ -474,6 +479,10 @@ namespace fmwkng {
{
return my_traits::reducible;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<sense_p>>(my_traits::aggregator_data(d_));
}
virtual void aggregate_with(const abstract_element* other)
{
auto p = dynamic_cast<const self_*>(other);
......@@ -519,6 +528,10 @@ namespace fmwkng {
{
return my_traits::reducible;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<sense_p>>();
}
virtual void aggregate_with(const abstract_element* other)
{
}
......@@ -542,6 +555,7 @@ namespace fmwkng {
template< typename tag>
class config_element< tag, element_sense::OPEN> : public abstract_element {
private:
using my_element_traits = element_traits_t<tag, element_sense::OPEN>;
using my_traits = config_element_traits_t<tag>;
using data_t = typename my_traits::data_type;
public:
......@@ -577,6 +591,10 @@ namespace fmwkng {
{
return false;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<element_sense::OPEN>>(my_traits::aggregator_data(d_));
}
virtual void aggregate_with(const abstract_element* other)
{
auto p = dynamic_cast<const self_*>(other);
......@@ -590,6 +608,8 @@ namespace fmwkng {
template< typename tag>
class config_element< tag, element_sense::CLOSE> : public abstract_element {
private:
using my_element_traits = element_traits_t<tag, element_sense::OPEN>;
public:
config_element()
{}
......@@ -621,6 +641,10 @@ namespace fmwkng {
{
return false;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<element_sense::CLOSE>>();
}
virtual void aggregate_with(const abstract_element* other)
{
}
......@@ -1141,6 +1165,10 @@ namespace fmwkng {
struct parallel_tag_category {};
struct measurement_tag_category {};
struct result_tag_category {};
struct all_platforms_tag {
using tag_category = platform_tag_category;
};
#pragma endregion
namespace impl {
#pragma region utils2
......@@ -1168,6 +1196,8 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = element_t< root_tag< config_t>, sense>;
};
template< typename config_t>
......@@ -1178,6 +1208,8 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = element_t< root_tag< config_t>, sense>;
};
template< typename config_t>
......@@ -1444,6 +1476,12 @@ namespace fmwkng {
}
static constexpr bool useful = false;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = config_element< all_platforms_tag, sense>;
static data_type aggregator_data(const data_type&)
{
return {};
}
static void aggregate(data_type&, const data_type&)
{
// NOTHING TO DO WITH MONOSTATE
......@@ -1459,6 +1497,8 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = config_element< all_platforms_tag, sense>;
};
template< typename platform_tag>
......@@ -1492,6 +1532,15 @@ namespace fmwkng {
};
#pragma endregion
#pragma region range
template< typename range_tag>
struct range_config_holder {
using enumerator_t = std::remove_cv_t<std::remove_reference_t<decltype(range_tag::enumerator())>>;
enumerator_t config;
explicit range_config_holder()
: config(range_tag::enumerator())
{}
};
template< typename range_tag>
struct element_traits< range_tag_category, range_tag, element_sense::OPEN>
{
......@@ -1499,16 +1548,24 @@ namespace fmwkng {
{
os << range_tag::name() << ":";
}
using data_type = enumerator_value_t< range_tag>;
using value_data_type = enumerator_value_t< range_tag>;
using aggregator_data_type = typename range_config_holder< range_tag>::enumerator_t;
using data_type = std::pair< value_data_type, aggregator_data_type>;
static void data_text(std::ostream& os, const data_type& d)
{
os << d;
os << d.first;
}
static constexpr bool useful = false;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = config_element< range_tag, sense>;
static aggregator_data_type aggregator_data(const data_type& v)
{
return aggregator_data_type(v.second); // USE THE CONFIG AS THE AGGREGATE
}
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
assert(0); // AGGREGATING TO A RANGE VALUE IS NONSENSE
}
};
......@@ -1521,15 +1578,35 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = config_element< range_tag, sense>;
};
template< typename range_tag>
struct range_config_holder {
using enumerator_t = std::remove_cv_t<std::remove_reference_t<decltype(range_tag::enumerator())>>;
enumerator_t config;
explicit range_config_holder()
: config(range_tag::enumerator())
{}
template<>
struct config_element_traits< platform_tag_category, all_platforms_tag>
{
static void metadata_marker_open(std::ostream& os)
{
os << "platforms:";
}
static void metadata_marker_close(std::ostream& os)
{
os << ".";
}
using data_type = std::monostate;
static void data_text(std::ostream& os, const data_type& d)
{
os << "all";
}
template< element_sense sense>
using aggregator = config_element< all_platforms_tag, sense>;
static data_type aggregator_data(const data_type&)
{
return {};
}
static void aggregate(data_type& r, const data_type& v)
{
}
};
template< typename range_tag>
......@@ -1548,9 +1625,15 @@ namespace fmwkng {
{
d.data_text(os);
}
template< element_sense sense>
using aggregator = config_element< range_tag, sense>;
static data_type aggregator_data(const data_type& v)
{
return v;
}
static void aggregate(data_type& r, const data_type& v)
{
r.aggregate(v); // ???
assert( r == v);
}
};
......@@ -1572,7 +1655,7 @@ namespace fmwkng {
{
auto&& c = get_my_config(dt).config;
c.init(v_);
impl::thread_pointer(dt)->template push_element<tag, element_sense::OPEN>(v_);
impl::thread_pointer(dt)->template push_element<tag, element_sense::OPEN>(std::make_pair(v_, c));
{
/*
auto g = impl::root_pointer(dt)->guard();
......@@ -1596,7 +1679,7 @@ namespace fmwkng {
if (rv)
{
impl::thread_pointer(dt)->template push_element<tag, element_sense::CLOSE>();
impl::thread_pointer(dt)->template push_element<tag, element_sense::OPEN>(v_);
impl::thread_pointer(dt)->template push_element<tag, element_sense::OPEN>(std::make_pair(v_, c));
/*
auto g = impl::root_pointer(dt)->guard();
std::cout << "advance_range<" << tag::name() << ">(" << v_ << ")" << std::endl;
......@@ -1649,6 +1732,8 @@ namespace fmwkng {
}
static constexpr bool useful = false;
static constexpr bool reducible = false;
template< element_sense sense>
using aggregator = config_element< parallel_tag, sense>;
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
......@@ -1823,6 +1908,8 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = config_element< measurement_tag, sense>;
};
template<>
......@@ -1839,9 +1926,46 @@ namespace fmwkng {
}
static constexpr bool useful = true;
static constexpr bool reducible = true;
using aggregator_data_type = std::pair< clock::duration, std::size_t>;
template< element_sense sense>
using aggregator = config_element< measurement_tag, sense>;
static aggregator_data_type aggregator_data(const data_type& v)
{
return aggregator_data_type(v, 1);
}
static void aggregate(aggregator_data_type& r, const data_type& v)
{
r.first += v;
r.second += 1;
}
};
template<>
struct config_element_traits< measurement_tag_category, measurement_tag>
{
static void metadata_marker_open(std::ostream& os)
{
os << "<";
}
static void metadata_marker_close(std::ostream& os)
{
os << ">";
}
using data_type = std::pair< clock::duration, std::size_t>;
static void data_text(std::ostream& os, const data_type& d)
{
os << (d.first.count() / d.second);
}
template< element_sense sense>
using aggregator = config_element< measurement_tag, sense>;
static data_type aggregator_data(const data_type& v)
{
return v;
}
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! DO AVERAGE INSTEAD OF SUM
r.first += v.first;
r.second += v.second;
}
};
......@@ -1898,6 +2022,8 @@ namespace fmwkng {
}
using data_type = void;
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = element_t< result_tag, sense>;
};
template<typename result_tag>
......@@ -1914,6 +2040,8 @@ namespace fmwkng {
}
static constexpr bool useful = true;
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = element_t< result_tag, sense>;
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
......@@ -1993,6 +2121,18 @@ namespace fmwkng {
v *= v_factor_;
return v <= v_last_;
}
bool operator==(const logarithmic& b) const
{
return v_first_ == b.v_first_
&& v_last_ == b.v_last_
&& v_factor_ == b.v_factor_;
}
void data_text(std::ostream& os) const
{
os << "(" << v_first_ << "," << v_last_ << "," << v_factor_ << ")";
}
private:
value_t v_first_;
value_t v_last_;
......@@ -2044,6 +2184,8 @@ namespace fmwkng {
static constexpr bool useful = false;
*/
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = config_element< auto_measurement_tag< measurement_policy>, sense>;
};
template< typename measurement_policy>
......@@ -2060,6 +2202,8 @@ namespace fmwkng {
}
static constexpr bool useful = true;
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = config_element< auto_measurement_tag< measurement_policy>, sense>;
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
......
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