Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1392a36
start task 1
SonyaMorozova Mar 3, 2026
d494f52
fix: pre-commit
SonyaMorozova Mar 3, 2026
10d9e76
fix: clang-tidy
SonyaMorozova Mar 3, 2026
ca33939
fix: clang-tidy
SonyaMorozova Mar 3, 2026
22f896e
fix: clang-build
SonyaMorozova Mar 3, 2026
9779fbf
fix: clang-tidy
SonyaMorozova Mar 3, 2026
9c473ac
fix: clang-tidy
SonyaMorozova Mar 3, 2026
fb5eb67
fix: clang-tidy
SonyaMorozova Mar 4, 2026
6490d4b
fix: clang-test
SonyaMorozova Mar 4, 2026
8629c31
fix: clang-tidy
SonyaMorozova Mar 4, 2026
116796f
fix: clang-tidy
SonyaMorozova Mar 4, 2026
ad09149
fix: clang-test
SonyaMorozova Mar 4, 2026
030c05e
fix: clang-test
SonyaMorozova Mar 4, 2026
1de2f34
fix: clang-tidy
SonyaMorozova Mar 4, 2026
6d66f9d
fix: clang-tidy
SonyaMorozova Mar 4, 2026
eb5dae0
fix: clang-test
SonyaMorozova Mar 4, 2026
f24a4e9
fix: clang-tidy
SonyaMorozova Mar 4, 2026
bd11036
fix: clang-tidy
SonyaMorozova Mar 4, 2026
b451f8b
fix: clang-test
SonyaMorozova Mar 4, 2026
7bf4066
fix: clang-test
SonyaMorozova Mar 4, 2026
bb8dfe0
fix: clang-test
SonyaMorozova Mar 4, 2026
62b2379
fix: clang-tidy
SonyaMorozova Mar 4, 2026
4b4880d
fix: clang-tidy
SonyaMorozova Mar 4, 2026
ffb757f
fix: clang-tidy
SonyaMorozova Mar 4, 2026
84703b3
fix: clang-tidy
SonyaMorozova Mar 4, 2026
4057b96
Add OpenMP
SonyaMorozova Mar 15, 2026
3a18500
fix tidy
SonyaMorozova Mar 15, 2026
6f17512
Merge branch 'master' into morozova_s_strassen_multiplication_omp
SonyaMorozova Mar 16, 2026
10e45f5
fix tidy
SonyaMorozova Mar 16, 2026
bb14b19
fix tidy
SonyaMorozova Mar 16, 2026
9bf2c4c
fix tidy
SonyaMorozova Mar 16, 2026
76cd006
fix tidy
SonyaMorozova Mar 16, 2026
91e567a
fix tidy
SonyaMorozova Mar 17, 2026
12322c8
fix tidy
SonyaMorozova Mar 17, 2026
1670047
fix omp
SonyaMorozova Mar 17, 2026
4aa5ffc
fix tidy
SonyaMorozova Mar 17, 2026
bb7fa73
fix omp
SonyaMorozova Mar 17, 2026
10204ab
fix omp
SonyaMorozova Mar 18, 2026
0ad5fc2
fix tidy
SonyaMorozova Mar 19, 2026
63cec54
fix tidy
SonyaMorozova Mar 19, 2026
5838b47
fix tidy
SonyaMorozova Mar 19, 2026
50bf4d7
fix tidy
SonyaMorozova Mar 19, 2026
4f4f280
fix omp
SonyaMorozova Mar 19, 2026
9da12ed
fix omp
SonyaMorozova Mar 19, 2026
5cdfd3b
start tbb
SonyaMorozova Mar 26, 2026
3d74ca2
fix tidy
SonyaMorozova Mar 26, 2026
779b2a4
fix codecov
SonyaMorozova Mar 27, 2026
1cb89bf
fix tidy
SonyaMorozova Mar 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <cmath>
#include <cstddef> // для size_t
#include <cstddef>
#include <string>
#include <tuple>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "morozova_s_strassen_multiplication/common/include/common.hpp"
#include "task/include/task.hpp"

namespace morozova_s_strassen_multiplication {

class MorozovaSStrassenMultiplicationOMP : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kOMP;
}
explicit MorozovaSStrassenMultiplicationOMP(const InType &in);

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;

static Matrix AddMatrix(const Matrix &a, const Matrix &b);
static Matrix SubtractMatrix(const Matrix &a, const Matrix &b);
static Matrix MultiplyStrassen(const Matrix &a, const Matrix &b, int leaf_size = 64);
static Matrix MultiplyStandard(const Matrix &a, const Matrix &b);
static void SplitMatrix(const Matrix &m, Matrix &m11, Matrix &m12, Matrix &m21, Matrix &m22);
static Matrix MergeMatrices(const Matrix &m11, const Matrix &m12, const Matrix &m21, const Matrix &m22);

static Matrix MultiplyStandardParallel(const Matrix &a, const Matrix &b);

Matrix a_, b_, c_;
int n_{0};
bool valid_data_{true};

static constexpr int kMaxParallelDepth = 2;
};

} // namespace morozova_s_strassen_multiplication
260 changes: 260 additions & 0 deletions tasks/morozova_s_strassen_multiplication/omp/src/ops_omp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
#include "morozova_s_strassen_multiplication/omp/include/ops_omp.hpp"

#include <cmath>
#include <cstddef>
#include <vector>

#include "morozova_s_strassen_multiplication/common/include/common.hpp"

namespace morozova_s_strassen_multiplication {

namespace {

Matrix AddMatrixImpl(const Matrix &a, const Matrix &b) {
int n = a.size;
Matrix result(n);

for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
result(i, j) = a(i, j) + b(i, j);
}
}

return result;
}

Matrix SubtractMatrixImpl(const Matrix &a, const Matrix &b) {
int n = a.size;
Matrix result(n);

for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
result(i, j) = a(i, j) - b(i, j);
}
}

return result;
}

Matrix MultiplyStandardImpl(const Matrix &a, const Matrix &b) {
int n = a.size;
Matrix result(n);

for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
double sum = 0.0;
for (int k = 0; k < n; ++k) {
sum += a(i, k) * b(k, j);
}
result(i, j) = sum;
}
}

return result;
}

void SplitMatrixImpl(const Matrix &m, Matrix &m11, Matrix &m12, Matrix &m21, Matrix &m22) {
int n = m.size;
int half = n / 2;

for (int i = 0; i < half; ++i) {
for (int j = 0; j < half; ++j) {
m11(i, j) = m(i, j);
m12(i, j) = m(i, j + half);
m21(i, j) = m(i + half, j);
m22(i, j) = m(i + half, j + half);
}
}
}

Matrix MergeMatricesImpl(const Matrix &m11, const Matrix &m12, const Matrix &m21, const Matrix &m22) {
int half = m11.size;
int n = 2 * half;
Matrix result(n);

for (int i = 0; i < half; ++i) {
for (int j = 0; j < half; ++j) {
result(i, j) = m11(i, j);
result(i, j + half) = m12(i, j);
result(i + half, j) = m21(i, j);
result(i + half, j + half) = m22(i, j);
}
}

return result;
}

Matrix MultiplyStandardParallelImpl(const Matrix &a, const Matrix &b) {
int n = a.size;
Matrix result(n);

for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
double sum = 0.0;
for (int k = 0; k < n; ++k) {
sum += a(i, k) * b(k, j);
}
result(i, j) = sum;
}
}

return result;
}

Matrix MultiplyStrassenIterative(const Matrix &a, const Matrix &b, int leaf_size) {
int n = a.size;

if (n <= leaf_size || n % 2 != 0) {
return MultiplyStandardParallelImpl(a, b);
}

int half = n / 2;

Matrix a11(half);
Matrix a12(half);
Matrix a21(half);
Matrix a22(half);

Matrix b11(half);
Matrix b12(half);
Matrix b21(half);
Matrix b22(half);

SplitMatrixImpl(a, a11, a12, a21, a22);
SplitMatrixImpl(b, b11, b12, b21, b22);

Matrix p1 = MultiplyStandardParallelImpl(a11, SubtractMatrixImpl(b12, b22));
Matrix p2 = MultiplyStandardParallelImpl(AddMatrixImpl(a11, a12), b22);
Matrix p3 = MultiplyStandardParallelImpl(AddMatrixImpl(a21, a22), b11);
Matrix p4 = MultiplyStandardParallelImpl(a22, SubtractMatrixImpl(b21, b11));
Matrix p5 = MultiplyStandardParallelImpl(AddMatrixImpl(a11, a22), AddMatrixImpl(b11, b22));
Matrix p6 = MultiplyStandardParallelImpl(SubtractMatrixImpl(a12, a22), AddMatrixImpl(b21, b22));
Matrix p7 = MultiplyStandardParallelImpl(SubtractMatrixImpl(a11, a21), AddMatrixImpl(b11, b12));

Matrix c11 = AddMatrixImpl(SubtractMatrixImpl(AddMatrixImpl(p5, p4), p2), p6);
Matrix c12 = AddMatrixImpl(p1, p2);
Matrix c21 = AddMatrixImpl(p3, p4);
Matrix c22 = SubtractMatrixImpl(SubtractMatrixImpl(AddMatrixImpl(p5, p1), p3), p7);

return MergeMatricesImpl(c11, c12, c21, c22);
}

} // namespace

MorozovaSStrassenMultiplicationOMP::MorozovaSStrassenMultiplicationOMP(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = OutType();
}

bool MorozovaSStrassenMultiplicationOMP::ValidationImpl() {
return true;
}

bool MorozovaSStrassenMultiplicationOMP::PreProcessingImpl() {
if (GetInput().empty()) {
valid_data_ = false;
return true;
}

double size_val = GetInput()[0];
if (size_val <= 0.0) {
valid_data_ = false;
return true;
}

int n = static_cast<int>(size_val);

if (GetInput().size() != 1 + (2 * static_cast<size_t>(n) * static_cast<size_t>(n))) {
valid_data_ = false;
return true;
}

valid_data_ = true;
n_ = n;

a_ = Matrix(n_);
b_ = Matrix(n_);

int idx = 1;
for (int i = 0; i < n_; ++i) {
for (int j = 0; j < n_; ++j) {
a_(i, j) = GetInput()[idx++];
}
}

for (int i = 0; i < n_; ++i) {
for (int j = 0; j < n_; ++j) {
b_(i, j) = GetInput()[idx++];
}
}

return true;
}

bool MorozovaSStrassenMultiplicationOMP::RunImpl() {
if (!valid_data_) {
return true;
}

const int leaf_size = 64;

if (n_ <= leaf_size) {
c_ = MultiplyStandardParallelImpl(a_, b_);
} else {
c_ = MultiplyStrassenIterative(a_, b_, leaf_size);
}

return true;
}

bool MorozovaSStrassenMultiplicationOMP::PostProcessingImpl() {
OutType &output = GetOutput();
output.clear();

if (!valid_data_) {
return true;
}

output.push_back(static_cast<double>(n_));

for (int i = 0; i < n_; ++i) {
for (int j = 0; j < n_; ++j) {
output.push_back(c_(i, j));
}
}

return true;
}

Matrix MorozovaSStrassenMultiplicationOMP::AddMatrix(const Matrix &a, const Matrix &b) {
return AddMatrixImpl(a, b);
}

Matrix MorozovaSStrassenMultiplicationOMP::SubtractMatrix(const Matrix &a, const Matrix &b) {
return SubtractMatrixImpl(a, b);
}

Matrix MorozovaSStrassenMultiplicationOMP::MultiplyStandard(const Matrix &a, const Matrix &b) {
return MultiplyStandardImpl(a, b);
}

void MorozovaSStrassenMultiplicationOMP::SplitMatrix(const Matrix &m, Matrix &m11, Matrix &m12, Matrix &m21,
Matrix &m22) {
SplitMatrixImpl(m, m11, m12, m21, m22);
}

Matrix MorozovaSStrassenMultiplicationOMP::MergeMatrices(const Matrix &m11, const Matrix &m12, const Matrix &m21,
const Matrix &m22) {
return MergeMatricesImpl(m11, m12, m21, m22);
}

Matrix MorozovaSStrassenMultiplicationOMP::MultiplyStrassen(const Matrix &a, const Matrix &b, int leaf_size) {
return MultiplyStrassenIterative(a, b, leaf_size);
}

Matrix MorozovaSStrassenMultiplicationOMP::MultiplyStandardParallel(const Matrix &a, const Matrix &b) {
return MultiplyStandardParallelImpl(a, b);
}

} // namespace morozova_s_strassen_multiplication
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "morozova_s_strassen_multiplication/common/include/common.hpp"
#include "task/include/task.hpp"

namespace morozova_s_strassen_multiplication {

class MorozovaSStrassenMultiplicationTBB : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kTBB;
}
explicit MorozovaSStrassenMultiplicationTBB(const InType &in);

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;

static Matrix AddMatrix(const Matrix &a, const Matrix &b);
static Matrix SubtractMatrix(const Matrix &a, const Matrix &b);
static Matrix MultiplyStrassen(const Matrix &a, const Matrix &b, int leaf_size = 64);
static Matrix MultiplyStandard(const Matrix &a, const Matrix &b);
static void SplitMatrix(const Matrix &m, Matrix &m11, Matrix &m12, Matrix &m21, Matrix &m22);
static Matrix MergeMatrices(const Matrix &m11, const Matrix &m12, const Matrix &m21, const Matrix &m22);

static Matrix MultiplyStandardParallel(const Matrix &a, const Matrix &b);

Matrix a_, b_, c_;
int n_{0};
bool valid_data_{true};

static constexpr int kMaxParallelDepth = 2;
};

} // namespace morozova_s_strassen_multiplication
Loading
Loading