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

bsearch assignment

parent 827393c2
......@@ -10,6 +10,7 @@ include("CMakeConf.cmake")
MAKE_TARGET("MACRO" "macro")
MAKE_TARGET("LEVEN" "leven")
MAKE_TARGET("BSEARCH" "bsearch")
add_subdirectory ("asgn")
add_subdirectory ("sol")
target_include_directories(${TARGET_MACRO} PUBLIC ".")
target_include_directories(${TARGET_LEVEN} PUBLIC ".")
target_include_directories(${TARGET_BSEARCH} PUBLIC ".")
target_sources(${TARGET_MACRO} PUBLIC "fmwkng.hpp" "macroasgn.hpp" "macroasgn.cpp" "macromain.cpp")
TARGET_GOLD_SOURCES(${TARGET_MACRO} "macrogold")
target_sources(${TARGET_LEVEN} PUBLIC "fmwkng.hpp" "levenasgn.hpp" "levenmain.cpp")
TARGET_GOLD_SOURCES(${TARGET_LEVEN} "levengold")
target_sources(${TARGET_BSEARCH} PUBLIC "fmwkng.hpp" "bsearchasgn.hpp" "bsearchmain.cpp")
#TARGET_GOLD_SOURCES(${TARGET_BSEARCH} "bsearchgold")
#ifndef bsearchasgn_hpp_
#define bsearchasgn_hpp_
#include <cstddef>
#include <memory>
#include <vector>
#include <cassert>
#include <random>
#include "fmwkng.hpp"
//#include <emmintrin.h>
///////////////////////////////
namespace bsearchasgn {
using data_element = std::int32_t;
struct core_generator {
template< typename E>
core_generator(std::size_t opsize, E&& engine)
: data_(opsize)
{
fmwkng::well_defined_uniform uni(0, 0x7FFFFFFF);
for (std::size_t j = 0; j < opsize; ++j)
{
data_[j] = data_element(uni(engine));
}
}
std::vector< data_element> data_;
};
struct core_generator_sorted : public core_generator {
template< typename E>
core_generator_sorted(std::size_t opsize, E&& engine)
: core_generator(opsize, std::forward<E>(engine))
{
std::sort(data_.begin(), data_.end());
}
};
struct generator_3 {
const data_element* inner_data() const
{
return inner_data_.data_.data();
}
std::size_t inner_size() const
{
return inner_data_.data_.size();
}
const data_element* outer_data() const
{
return outer_data_.data_.data();
}
std::size_t outer_size() const
{
return outer_data_.data_.size();
}
generator_3(std::uint_fast64_t seed, std::size_t isize, 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)
{
for (std::size_t j = 0; j < bs; ++j)
{
if (bd[j] < cmp)
{
log.ss() << "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)
{
for (std::size_t j = 0; j < bs; ++j)
{
if (bd[j] >= cmp)
{
log.ss() << "Too high value at bucket[" << k << "][" << j << "]" << std::endl;
}
}
}
template< typename D>
static void final_check(logger& log, const D& data)
{
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);
total += rv.second;
}
for (std::size_t k = 1; k < check.first.second; ++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);
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);
total += rv.second;
}
if (total != check.second)
{
log.ss() << "TOTAL SIZE OF BUCKETS " << total << " DOES NOT MATCH OUTER DATA SIZE " << check.second << std::endl;
}
}
*/
}
namespace bsearchsol {
struct policy_scalar;
struct policy_sse;
struct policy_avx;
struct policy_avx512;
};
namespace bsearchmain {
struct platform_scalar {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "scalar"; }
static auto code_name() { return "bsearchmain::platform_scalar"; }
using policy = bsearchsol::policy_scalar;
};
struct platform_sse {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "sse"; }
static auto code_name() { return "bsearchmain::platform_sse"; }
using policy = bsearchsol::policy_sse;
};
struct platform_avx {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx"; }
static auto code_name() { return "bsearchmain::platform_avx"; }
using policy = bsearchsol::policy_avx;
};
struct platform_avx512 {
using tag_category = fmwkng::platform_tag_category;
static auto name() { return "avx512"; }
static auto code_name() { return "bsearchmain::platform_avx512"; }
using policy = bsearchsol::policy_avx512;
};
struct isize {
using tag_category = fmwkng::range_tag_category;
static auto name() { return "isize"; }
static auto code_name() { return "bsearchmain::isize"; }
static auto enumerator() {
return fmwkng::logarithmic(
0x40,
#ifdef NDEBUG
0x10000,
#else
0x40000,
#endif
#ifdef NDEBUG
0x4
#else
0x10
#endif
);
}
};
struct osize {
using tag_category = fmwkng::range_tag_category;
static auto name() { return "osize"; }
static auto code_name() { return "bsearchmain::osize"; }
static auto enumerator() {
return fmwkng::logarithmic(
0x1000,
#ifdef NDEBUG
0x100000,
#else
0x10000,
#endif
0x10
);
}
};
struct repeats {
using tag_category = fmwkng::range_tag_category;
static auto name() { return "repeats"; }
static auto code_name() { return "bsearchmain::repeats"; }
static auto enumerator() {
return fmwkng::auto_repeat(
#ifdef NDEBUG
0x1000000
#else
0x10000
#endif
);
}
};
std::size_t log2(std::size_t s)
{
std::size_t i = 0;
for (; s; s >>= 1)
++i;
return i;
}
struct repeat_policy {
using ranges = fmwkng::ranges< repeats>;
static auto name() { return "time_per_comparison"; }
static auto code_name() { return "bsearchmain::repeat_policy"; }
template< typename CTX>
static auto complexity(CTX&& ctx)
{
return (std::uint_fast64_t)log2(fmwkng::get<isize>(ctx)) * fmwkng::get<osize>(ctx);
}
static constexpr fmwkng::average_t minimum_count =
#ifdef NDEBUG
1000000000ULL
#else
100000000ULL
#endif
;
};
struct chksum {
using tag_category = fmwkng::result_tag_category;
static auto name() { return "chksum"; }
static auto code_name() { return "bsearchmain::chksum"; }
using value_type = std::size_t;
};
struct root_config {
static auto code_name() { return "bsearchmain::root_config"; }
static auto code_header_name() { return "bsearchasgn.hpp"; }
static auto code_namespace_name() { return "bsearchmain"; }
using platforms = fmwkng::platforms<
platform_scalar
,
platform_sse
#ifdef USE_AVX
, platform_avx
#endif
#ifdef USE_AVX512
, platform_avx512
#endif
>;
using ranges = fmwkng::ranges<isize, osize, repeats>;
};
fmwkng::gold_holder& gold_master();
}
#endif
#include "bsearchsol.hpp"
#include "bsearchasgn.hpp"
#include "fmwkng.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
///////////////////////////////
///////////////////////////////
///////////////////////////////
namespace bsearchmain {
struct run_thread_ftor {
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());
bsearchsol::bsearch_outer<policy> odata(idata, mg.outer_size());
for (auto&& ctx5 : auto_measurement<repeat_policy>(ctx4, 1024))
{
std::size_t h = 0;
for (auto i : for_index<repeats>(ctx5))
{
odata.bucketize(mg.outer_data());
}
if (stop_for_results(ctx5))
{
// final_check
}
}
}
}
}
};
struct run_platform_ftor {
template< typename CTX>
void operator()(CTX&& ctx1) const
{
using namespace fmwkng;
#ifdef NDEBUG
for_parallel(ctx1, run_thread_ftor());
#else
run_thread_ftor()(ctx1);
#endif
}
};
fmwkng::gold_holder& gold_master()
{
static fmwkng::gold_holder the;
return the;
}
}
///////////////////////////////
int main( int argc, char * * argv)
{
using namespace fmwkng;
root<bsearchmain::root_config> ctx1(argc, argv, bsearchmain::gold_master().collect());
//std::cout << "Running..." << std::endl;
for_platforms(ctx1, bsearchmain::run_platform_ftor());
//std::cout << "Done." << std::endl;
return 0;
}
///////////////////////////////
......@@ -2,6 +2,8 @@
#
target_include_directories(${TARGET_MACRO} PUBLIC ".")
target_include_directories(${TARGET_LEVEN} PUBLIC ".")
target_include_directories(${TARGET_BSEARCH} PUBLIC ".")
target_sources(${TARGET_MACRO} PUBLIC "macrosol.hpp" "macrosol.cpp")
target_sources(${TARGET_LEVEN} PUBLIC "levensol.hpp" "levensol.cpp")
target_sources(${TARGET_BSEARCH} PUBLIC "bsearchsol.hpp" "bsearchsol.cpp")
#include "bsearchsol.hpp"
#ifndef bsearchsol_hpp_
#define bsearchsol_hpp_
#include <cstdint>
#include <utility>
///////////////////////////////
namespace bsearchsol {
using data_element = std::int32_t;
template< typename policy>
class bsearch_inner {
public:
bsearch_inner(const data_element* data, std::size_t size)
{
}
};
template< typename policy>
class bsearch_outer {
public:
bsearch_outer(const bsearch_inner< policy>& inner, std::size_t osize)
{
}
void bucketize(const data_element* data) // size of data is osize
{
}
using bucket_rv = std::pair< const data_element*, std::size_t>;
bucket_rv bucket(std::size_t k) const
{
return bucket_rv(0, 0); // return reference to bucket contents
}
};
struct policy_scalar {
};
struct policy_sse {
};
struct policy_avx {
};
struct policy_avx512 {
};
}
#endif
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