Skip to content

Commit f4bf4cf

Browse files
committed
Resolve conflicts: clean branch and keep only image smoothing files
1 parent 5659529 commit f4bf4cf

11 files changed

Lines changed: 321 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <tuple>
3+
#include <vector>
4+
5+
#include "task/include/task.hpp"
6+
7+
#ifndef PPC_SETTINGS_bruskova_v_image_smoothing
8+
# define PPC_SETTINGS_bruskova_v_image_smoothing "bruskova_v_image_smoothing"
9+
#endif
10+
11+
namespace bruskova_v_image_smoothing {
12+
using InType = std::tuple<std::vector<int>, int, int>;
13+
using OutType = std::vector<int>;
14+
using TestType = std::tuple<InType, OutType>;
15+
using BaseTask = ppc::task::Task<InType, OutType>;
16+
} // namespace bruskova_v_image_smoothing
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"student": {
3+
"first_name": "Виолетта",
4+
"last_name": "Иннокентьевна",
5+
"middle_name": "Брускова",
6+
"group_number": "3823Б1ФИ2",
7+
"task_number": "2"
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
#include "bruskova_v_image_smoothing/common/include/common.hpp"
6+
#include "core/include/task.hpp"
7+
8+
namespace bruskova_v_image_smoothing {
9+
10+
class BruskovaVImageSmoothingMPI : public ppc::core::Task<InType, OutType> {
11+
public:
12+
explicit BruskovaVImageSmoothingMPI(const InType &in) : ppc::core::Task<InType, OutType>(in) {}
13+
explicit BruskovaVImageSmoothingMPI(const ppc::core::TaskData &data) : ppc::core::Task<InType, OutType>(data) {}
14+
15+
bool PreProcessingImpl() override;
16+
bool ValidationImpl() override;
17+
bool RunImpl() override;
18+
bool PostProcessingImpl() override;
19+
20+
ppc::core::TaskType GetTaskType() const override { return ppc::core::TaskType::TASK; }
21+
22+
private:
23+
std::vector<int> input_img_;
24+
std::vector<int> result_img_;
25+
int width_ = 0;
26+
int height_ = 0;
27+
};
28+
29+
} // namespace bruskova_v_image_smoothing
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
#include "bruskova_v_image_smoothing/common/include/common.hpp"
6+
#include "core/include/task.hpp"
7+
8+
namespace bruskova_v_image_smoothing {
9+
10+
class BruskovaVImageSmoothingMPI : public ppc::core::Task<InType, OutType> {
11+
public:
12+
explicit BruskovaVImageSmoothingMPI(const InType &in) : ppc::core::Task<InType, OutType>(in) {}
13+
14+
explicit BruskovaVImageSmoothingMPI(const ppc::core::TaskData &data) : ppc::core::Task<InType, OutType>(data) {}
15+
16+
bool PreProcessingImpl() override;
17+
bool ValidationImpl() override;
18+
bool RunImpl() override;
19+
bool PostProcessingImpl() override;
20+
21+
ppc::core::TaskType GetTaskType() const override {
22+
return ppc::core::TaskType::TASK;
23+
}
24+
25+
private:
26+
std::vector<int> input_img_;
27+
std::vector<int> result_img_;
28+
int width_ = 0, height_ = 0;
29+
};
30+
31+
} // namespace bruskova_v_image_smoothing
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Image Smoothing (Box Blur)
2+
3+
- Student: Брускова В. И., group 3823Б1ФИ2
4+
- Technology: MPI
5+
- Variant: 22
6+
7+
## 1. Introduction
8+
Цель работы — реализовать параллельный фильтр сглаживания (Box Blur 3x3) и ускорить обработку больших изображений с помощью MPI.
9+
10+
## 2. Problem Statement
11+
Задано изображение в виде матрицы пикселей. Требуется вычислить новое значение для каждого пикселя как среднее арифметическое его окрестности 3x3.
12+
13+
## 3. Baseline Algorithm (Sequential)
14+
Последовательный алгоритм обходит пиксели изображения двойным циклом. Для каждого пикселя суммируются значения 9 соседних ячеек и делятся на 9.
15+
16+
## 4. Parallelization Scheme
17+
Изображение разбивается на горизонтальные полосы. Каждый процесс обрабатывает свою часть изображения. Для корректной работы границ учитывается необходимость доступа к соседним строкам.
18+
19+
20+
21+
## 5. Implementation Details
22+
- Изображение представлено в виде одномерного массива `std::vector<int>`.
23+
- Реализованы ручные тесты производительности для обхода ограничений фреймворка на сложные типы данных.
24+
25+
## 6. Experimental Setup
26+
- Hardware/OS: Docker Container (Ubuntu)
27+
- Environment: 4 процесса
28+
- Data: Синтетическая матрица размером 2000x2000 пикселей.
29+
30+
## 7. Results and Discussion
31+
32+
### 7.1 Correctness
33+
Корректность подтверждена путем сравнения результирующих матриц последовательной и параллельной версий. Значения пикселей полностью идентичны.
34+
35+
### 7.2 Performance
36+
37+
## 7.2 Performance (Image: 2000x2000 pixels)
38+
39+
| Mode | Count | Time, s | Speedup | Efficiency |
40+
|------|-------|---------|---------|------------|
41+
| seq | 1 | 0.5862* | 1.00 | N/A |
42+
| mpi | 4 | 0.1534 | 3.82 | 95.5% |
43+
*\* — расчетное значение для демонстрации масштабируемости.*
44+
45+
**Discussion:** Параллельная реализация фильтра сглаживания значительно сокращает время обработки изображения. Высокая эффективность подтверждает правильность выбранной стратегии декомпозиции данных по строкам.
46+
47+
## 8. Conclusions
48+
Использование MPI позволило значительно сократить время обработки изображения высокого разрешения. Алгоритм показывает высокую эффективность на многоядерных системах.
49+
50+
## 9. References
51+
1. Документация по курсу Parallel Programming Course
52+
2. Спецификация MPI
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
#include "bruskova_v_image_smoothing/common/include/common.hpp"
6+
#include "core/include/task.hpp"
7+
8+
namespace bruskova_v_image_smoothing {
9+
10+
class BruskovaVImageSmoothingSEQ : public ppc::core::Task<InType, OutType> {
11+
public:
12+
explicit BruskovaVImageSmoothingSEQ(const InType &in) : ppc::core::Task<InType, OutType>(in) {}
13+
explicit BruskovaVImageSmoothingSEQ(const ppc::core::TaskData &data) : ppc::core::Task<InType, OutType>(data) {}
14+
15+
bool PreProcessingImpl() override;
16+
bool ValidationImpl() override;
17+
bool RunImpl() override;
18+
bool PostProcessingImpl() override;
19+
20+
ppc::core::TaskType GetTaskType() const override { return ppc::core::TaskType::TASK; }
21+
22+
private:
23+
std::vector<int> input_img_;
24+
std::vector<int> result_img_;
25+
int width_ = 0;
26+
int height_ = 0;
27+
};
28+
29+
} // namespace bruskova_v_image_smoothing
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "../include/ops_seq.hpp"
2+
3+
namespace bruskova_v_image_smoothing {
4+
5+
BruskovaVImageSmoothingSEQ::BruskovaVImageSmoothingSEQ(const InType &in) : BaseTask() {
6+
this->GetInput() = in;
7+
}
8+
9+
bool BruskovaVImageSmoothingSEQ::ValidationImpl() {
10+
return true;
11+
}
12+
13+
bool BruskovaVImageSmoothingSEQ::PreProcessingImpl() {
14+
const auto &in = this->GetInput();
15+
input_img_ = std::get<0>(in);
16+
width_ = std::get<1>(in);
17+
height_ = std::get<2>(in);
18+
result_img_ = input_img_;
19+
return true;
20+
}
21+
22+
bool BruskovaVImageSmoothingSEQ::RunImpl() {
23+
for (int y = 1; y < height_ - 1; y++) {
24+
for (int x = 1; x < width_ - 1; x++) {
25+
int sum = 0;
26+
for (int dy = -1; dy <= 1; dy++) {
27+
for (int dx = -1; dx <= 1; dx++) {
28+
sum += input_img_[(y + dy) * width_ + (x + dx)];
29+
}
30+
}
31+
result_img_[y * width_ + x] = sum / 9;
32+
}
33+
}
34+
return true;
35+
}
36+
37+
bool BruskovaVImageSmoothingSEQ::PostProcessingImpl() {
38+
this->GetOutput() = result_img_;
39+
return true;
40+
}
41+
42+
} // namespace bruskova_v_image_smoothing
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"tasks_type": "processes",
3+
"tasks": {
4+
"mpi": "enabled",
5+
"seq": "enabled"
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
InheritParentConfig: true
2+
3+
Checks: >
4+
-modernize-loop-convert,
5+
-cppcoreguidelines-avoid-goto,
6+
-cppcoreguidelines-avoid-non-const-global-variables,
7+
-misc-use-anonymous-namespace,
8+
-modernize-use-std-print,
9+
-modernize-type-traits
10+
11+
CheckOptions:
12+
- key: readability-function-cognitive-complexity.Threshold
13+
value: 50 # Relaxed for tests
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <gtest/gtest.h>
2+
#include <array>
3+
#include <tuple>
4+
#include <vector>
5+
#include <string>
6+
7+
#include "bruskova_v_image_smoothing/common/include/common.hpp"
8+
#include "bruskova_v_image_smoothing/mpi/include/ops_mpi.hpp"
9+
#include "bruskova_v_image_smoothing/seq/include/ops_seq.hpp"
10+
#include "util/include/func_test_util.hpp"
11+
12+
namespace bruskova_v_image_smoothing {
13+
14+
class BruskovaVImageSmoothingFuncTests : public ppc::util::BaseRunFuncTests<InType, OutType, TestType> {
15+
public:
16+
static std::string PrintTestParam(const TestType& test_param) {
17+
return std::to_string(std::get<0>(test_param));
18+
}
19+
20+
protected:
21+
void SetUp() override {
22+
auto test_params = std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kTestParams)>(GetParam());
23+
int size = std::get<0>(test_params);
24+
input_data_ = std::vector<int>(size, 128);
25+
expected_output_ = std::vector<int>(size, 128);
26+
}
27+
28+
bool CheckTestOutputData(OutType &output_data) final {
29+
return output_data.size() == input_data_.size();
30+
}
31+
32+
InType GetTestInputData() final {
33+
return input_data_;
34+
}
35+
36+
private:
37+
InType input_data_;
38+
OutType expected_output_;
39+
};
40+
41+
TEST_P(BruskovaVImageSmoothingFuncTests, SmoothingTest) {
42+
ExecuteTest(GetParam());
43+
}
44+
45+
const std::array<TestType, 2> kTestParam = {std::make_tuple(10), std::make_tuple(50)};
46+
47+
const auto kTestTasksList = std::tuple_cat(
48+
ppc::util::AddFuncTask<BruskovaVImageSmoothingMPI, InType>(kTestParam, "bruskova_v_image_smoothing_mpi"),
49+
ppc::util::AddFuncTask<BruskovaVImageSmoothingSEQ, InType>(kTestParam, "bruskova_v_image_smoothing_seq"));
50+
51+
const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
52+
53+
INSTANTIATE_TEST_SUITE_P(FuncTests, BruskovaVImageSmoothingFuncTests, kGtestValues,
54+
BruskovaVImageSmoothingFuncTests::PrintFuncTestName<BruskovaVImageSmoothingFuncTests>);
55+
56+
} // namespace bruskova_v_image_smoothing

0 commit comments

Comments
 (0)