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

bsearch shares inner data among threads; gold check files

parent 3b548e33
......@@ -10,4 +10,4 @@ target_sources(${TARGET_LEVEN} PUBLIC "fmwkng.hpp" "levenasgn.hpp" "levenmain.cp
TARGET_GOLD_SOURCES(${TARGET_LEVEN} "levengold")
target_sources(${TARGET_BSEARCH} PUBLIC "fmwkng.hpp" "bsearchasgn.hpp" "bsearchmain.cpp")
#TARGET_GOLD_SOURCES(${TARGET_BSEARCH} "bsearchgold")
TARGET_GOLD_SOURCES(${TARGET_BSEARCH} "bsearchgold")
......@@ -43,7 +43,7 @@ namespace bsearchasgn {
}
};
struct generator_3 {
struct generator_inner {
const data_element* inner_data() const
{
......@@ -56,6 +56,19 @@ namespace bsearchasgn {
return inner_data_.data_.size();
}
generator_inner(std::uint_fast64_t seed, std::size_t isize)
: engine_(seed),
inner_data_(isize, engine_)
{
}
private:
std::mt19937_64 engine_;
core_generator_sorted inner_data_;
};
struct generator_outer {
const data_element* outer_data() const
{
return outer_data_.data_.data();
......@@ -66,73 +79,88 @@ namespace bsearchasgn {
return outer_data_.data_.size();
}
generator_3(std::uint_fast64_t seed, std::size_t isize, std::size_t osize)
generator_outer(std::uint_fast64_t seed, std::size_t osize)
: engine_(seed),
inner_data_(isize, engine_),
outer_data_(osize, engine_)
{
}
private:
std::mt19937_64 engine_;
core_generator_sorted inner_data_;
core_generator outer_data_;
};
// data.outer.bucketize(data.outer_data);
/*
inline void check_low(logger& log, const data_element* bd, std::size_t bs, data_element cmp, std::size_t k)
inline void check_low(std::ostream& log, const data_element* bd, std::size_t bs, data_element cmp, std::size_t k)
{
for (std::size_t j = 0; j < bs; ++j)
{
if (bd[j] < cmp)
{
log.ss() << "Too low value at bucket[" << k << "][" << j << "]" << std::endl;
log << "Too low value at bucket[" << k << "][" << j << "]" << std::endl;
}
}
}
inline void check_high(logger& log, const data_element* bd, std::size_t bs, data_element cmp, std::size_t k)
inline void check_high(std::ostream& log, const data_element* bd, std::size_t bs, data_element cmp, std::size_t k)
{
for (std::size_t j = 0; j < bs; ++j)
{
if (bd[j] >= cmp)
{
log.ss() << "Too high value at bucket[" << k << "][" << j << "]" << std::endl;
log << "Too high value at bucket[" << k << "][" << j << "]" << std::endl;
}
}
}
template< typename D>
static void final_check(logger& log, const D& data)
inline void final_check(std::ostream & log, const generator_inner& igen, const generator_outer& ogen, const D& output)
{
std::size_t total = 0;
{
// inspect first bucket
std::pair< const data_element*, std::size_t> rv = data.outer.bucket(0);
check_high(log, rv.first, rv.second, check.first.first[0], 0);
std::pair< const data_element*, std::size_t> rv = output.bucket(0);
check_high(log, rv.first, rv.second, igen.inner_data()[0], 0);
total += rv.second;
}
for (std::size_t k = 1; k < check.first.second; ++k)
for (std::size_t k = 1; k < igen.inner_size(); ++k)
{
// inspect k-th bucket
std::pair< const data_element*, std::size_t> rv = data.outer.bucket(k);
check_low(log, rv.first, rv.second, check.first.first[k - 1], k);
check_high(log, rv.first, rv.second, check.first.first[k], k);
std::pair< const data_element*, std::size_t> rv = output.bucket(k);
check_low(log, rv.first, rv.second, igen.inner_data()[k - 1], k);
check_high(log, rv.first, rv.second, igen.inner_data()[k], k);
total += rv.second;
}
{
// inspect last bucket
std::pair< const data_element*, std::size_t> rv = data.outer.bucket(check.first.second);
check_low(log, rv.first, rv.second, check.first.first[check.first.second - 1], check.first.second);
std::pair< const data_element*, std::size_t> rv = output.bucket(igen.inner_size());
check_low(log, rv.first, rv.second, igen.inner_data()[igen.inner_size() - 1], igen.inner_size());
total += rv.second;
}
if (total != check.second)
if (total != ogen.outer_size())
{
log << "TOTAL SIZE OF BUCKETS " << total << " DOES NOT MATCH OUTER DATA SIZE " << ogen.outer_size() << std::endl;
}
}
template< typename D>
inline std::uint_fast64_t chksum(const generator_inner& igen, const D& output)
{
std::uint_fast64_t total = 0;
for (std::size_t k = 0; k <= igen.inner_size(); ++k)
{
log.ss() << "TOTAL SIZE OF BUCKETS " << total << " DOES NOT MATCH OUTER DATA SIZE " << check.second << std::endl;
// inspect k-th bucket
std::pair< const data_element*, std::size_t> rv = output.bucket(k);
std::uint_fast64_t chash = 0;
for (std::size_t i = 0; i < rv.second; ++i)
{
static constexpr auto prime = (std::uint_fast64_t(1) << 61) - 1;
auto v = rv.first[i];
chash += prime / v;
}
total = (total << 7) ^ (total >> 57) ^ chash;
}
return total;
}
*/
}
namespace bsearchsol {
......@@ -225,7 +253,7 @@ namespace bsearchmain {
}
};
std::size_t log2(std::size_t s)
inline std::size_t log2(std::size_t s)
{
std::size_t i = 0;
for (; s; s >>= 1)
......
This diff is collapsed.
This diff is collapsed.
......@@ -13,39 +13,44 @@
namespace bsearchmain {
template< typename policy>
struct run_thread_ftor {
run_thread_ftor(const bsearchasgn::generator_inner & igen, const bsearchsol::bsearch_inner<policy> & idata)
: igen(igen), idata(idata)
{}
template< typename CTX>
void operator()(CTX&& ctx2) const
{
using namespace fmwkng;
using policy = typename platform_t<decltype(ctx2)>::policy;
for (auto&& ctx3 : for_range<isize>(ctx2))
{
for (auto&& ctx4 : for_range<osize>(ctx3))
{
bsearchasgn::generator_3 mg(
std::mt19937_64::default_seed + ctx2.thread_index(),
get<isize>(ctx4), get<osize>(ctx4));
bsearchsol::bsearch_inner<policy> idata(mg.inner_data(), mg.inner_size());
for (auto&& ctx4 : for_range<osize>(ctx2))
{
bsearchasgn::generator_outer ogen(
std::mt19937_64::default_seed + 1 + ctx4.thread_index(),
get<osize>(ctx4));
bsearchsol::bsearch_outer<policy> odata(idata, mg.outer_size());
bsearchsol::bsearch_outer<policy> odata(idata, ogen.outer_size());
for (auto&& ctx5 : auto_measurement<repeat_policy>(ctx4, 1024))
for (auto&& ctx5 : auto_measurement<repeat_policy>(ctx4, 1024))
{
for (auto i : for_index<repeats>(ctx5))
{
std::size_t h = 0;
for (auto i : for_index<repeats>(ctx5))
{
odata.bucketize(mg.outer_data());
}
if (stop_for_results(ctx5))
{
// final_check
}
odata.bucketize(ogen.outer_data());
}
if (stop_for_results(ctx5))
{
#ifndef NDEBUG
bsearchasgn::final_check(std::cerr, igen, ogen, odata);
#endif
auto h = bsearchasgn::chksum(igen, odata);
store_result<chksum>(ctx5, h);
}
}
}
}
const bsearchasgn::generator_inner& igen;
const bsearchsol::bsearch_inner<policy>& idata;
};
struct run_platform_ftor {
......@@ -53,11 +58,20 @@ namespace bsearchmain {
void operator()(CTX&& ctx1) const
{
using namespace fmwkng;
#ifdef NDEBUG
for_parallel(ctx1, run_thread_ftor());
#else
run_thread_ftor()(ctx1);
#endif
using policy = typename platform_t<decltype(ctx1)>::policy;
for (auto&& ctx3 : for_range<isize>(ctx1))
{
bsearchasgn::generator_inner igen(
std::mt19937_64::default_seed,
get<isize>(ctx3));
bsearchsol::bsearch_inner<policy> idata(igen.inner_data(), igen.inner_size());
//#ifdef NDEBUG
for_parallel(ctx3, run_thread_ftor<policy>(igen, idata));
//#else
// run_thread_ftor<policy>(igen, idata)(ctx3);
//#endif
}
}
};
......
......@@ -2114,6 +2114,11 @@ namespace fmwkng {
all_el_.push_back(std::move(el));
}
void clear_paired() const
{
el_.clear_paired();
}
const element_list& el() const
{
return el_;
......@@ -3707,10 +3712,12 @@ namespace fmwkng {
switch (rv.index()) {
case impl::worker_master_message_type::CONTINUE:
++n_continue;
my_root_pointer()->clear_paired();
break;
case impl::worker_master_message_type::COMPUTE_AVERAGE:
++n_average;
sum_average += std::get<impl::worker_master_message_type::COMPUTE_AVERAGE>(rv);
my_root_pointer()->clear_paired();
break;
case impl::worker_master_message_type::SEND_ELEMENTS:
++n_elements;
......
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