Commit 0c003a0b authored by Dubský Jan's avatar Dubský Jan
Browse files

Solution 4.01 (Speed: 25.40)

parent e66adbe9
#ifndef matrixsol_hpp
#define matrixsol_hpp
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <limits>
namespace matrixsol {
template< typename policy>
class matrix {
public:
using matrix_element = std::uint16_t;
#define CACHE_LINE_SIZE 64
matrix(std::size_t vs, std::size_t hs)
{
}
template <typename policy>
class matrix {
public:
using matrix_element = std::uint16_t;
std::size_t vsize() const
{
return 1;
}
matrix(std::size_t vs, std::size_t hs) :
VS(vs), HS(hs), ROW_BYTES(calc_row_bytes(vs, hs)), ROW_SIZE(ROW_BYTES / sizeof(matrix_element)) {
mat = (uint16_t*)std::aligned_alloc(CACHE_LINE_SIZE, VS * ROW_BYTES);
}
std::size_t hsize() const
{
return 1;
}
std::size_t vsize() const {
return VS;
}
void set(std::size_t i, std::size_t j, matrix_element e)
{
}
std::size_t hsize() const {
return HS;
}
void set(std::size_t i, std::size_t j, matrix_element e) {
addr(i, j) = e;
}
matrix_element get(std::size_t i, std::size_t j) const {
return addr(i, j);
}
void assign_mul(const matrix& a, const matrix& b) {
assert(a.VS == VS);
assert(b.HS == HS);
assert(a.HS == b.VS);
matrix_element get(std::size_t i, std::size_t j) const
{
return 1;
for (size_t i = 0; i < VS; ++i) {
for (size_t j = 0; j < HS; ++j) {
matrix_element res = std::numeric_limits<matrix_element>::max();
for (size_t k = 0; k < a.HS; ++k) {
res = std::min(res, (matrix_element)(a.get(i, k) + b.get(k, j)));
}
set(i, j, res);
}
}
}
void assign_mul(const matrix& a, const matrix& b)
{
private:
const size_t VS, HS;
const size_t ROW_BYTES;
const size_t ROW_SIZE;
uint16_t* mat;
matrix_element& addr(size_t row, size_t col) const {
assert(col < HS);
assert(row < VS);
return *(mat + (row * ROW_SIZE) + col);
}
static size_t calc_row_bytes(size_t vs, size_t hs) {
size_t ret = sizeof(matrix_element) * hs;
if (ret % CACHE_LINE_SIZE) {
ret += CACHE_LINE_SIZE;
ret = (ret / CACHE_LINE_SIZE) * CACHE_LINE_SIZE;
}
};
return ret;
}
};
/*
/*
struct policy_scalar {
};
*/
struct policy_sse {
};
struct policy_sse {
};
#ifdef USE_AVX
struct policy_avx {
};
struct policy_avx {
};
#endif
#ifdef USE_AVX512
struct policy_avx512 {
};
struct policy_avx512 {
};
#endif
}
} // namespace matrixsol
#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