Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: Dec 23 22:20 RTZ 2 (çèìà)
----------------------------------------------------------
End testing: Dec 23 22:20 RTZ 2 (çèìà)
133 changes: 133 additions & 0 deletions tasks/zhurin_i_edge_sobel/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <fstream>
#include <string>
#include <tuple>
#include <vector>

#include "task/include/task.hpp"

namespace zhurin_i_edge_sobel {

enum class ImageSet : std::uint8_t { kTest1, kTest2, kTest3, kTest4, kTest5, kTest6, kTest7, kTest8, kTest9, kTest10 };

using InType = std::tuple<std::vector<int>, int, int, int>;
using OutType = std::vector<int>;
using TestType = std::tuple<ImageSet, std::string>;
using BaseTask = ppc::task::Task<InType, OutType>;

inline std::tuple<std::vector<int>, int, int> ReadImageFile(const std::string &filename) {
std::ifstream file(filename);
if (!file.is_open()) {
return std::make_tuple(std::vector<int>(), 0, 0);
}

int height = 0;
int width = 0;

file >> height;
file >> width;

std::vector<int> pixels;
pixels.reserve(static_cast<size_t>(height) * width);

for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int pixel = 0;
if (!(file >> pixel)) {
return std::make_tuple(std::vector<int>(), 0, 0);
}
pixels.push_back(pixel);
}
}

file.close();
return std::make_tuple(pixels, height, width);
}

inline std::string GetDirectoryPath(const std::string &full_path) {
std::string result = full_path;
const std::string json_part = "settings.json";

if (result.size() >= json_part.size()) {
size_t pos = result.size() - json_part.size();
if (result.compare(pos, json_part.size(), json_part) == 0) {
result.erase(pos, json_part.size());
}
}

return result;
}

inline std::string GetTestFilename(ImageSet type, const std::string &folder) {
int test_num = 0;
switch (type) {
case ImageSet::kTest1:
test_num = 1;
break;
case ImageSet::kTest2:
test_num = 2;
break;
case ImageSet::kTest3:
test_num = 3;
break;
case ImageSet::kTest4:
test_num = 4;
break;
case ImageSet::kTest5:
test_num = 5;
break;
case ImageSet::kTest6:
test_num = 6;
break;
case ImageSet::kTest7:
test_num = 7;
break;
case ImageSet::kTest8:
test_num = 8;
break;
case ImageSet::kTest9:
test_num = 9;
break;
case ImageSet::kTest10:
test_num = 10;
break;
default:
test_num = 1;
}

return folder + "/test" + std::to_string(test_num) + ".txt";
}

inline std::string GetTestFilename(ImageSet type) {
int test_num = static_cast<int>(type) + 1; // kTest1 -> 1, kTest2 -> 2 и т.д.
return "test" + std::to_string(test_num) + ".txt";
}

inline std::tuple<std::vector<int>, int, int, int> GenerateTestData(ImageSet type) {
std::string full_path = GetDirectoryPath(PPC_SETTINGS_zhurin_i_edge_sobel) + "tasks/zhurin_i_edge_sobel/data/cases/" +
GetTestFilename(type);

std::tuple<std::vector<int>, int, int> read_result = ReadImageFile(full_path);

std::vector<int> pixels = std::get<0>(read_result);
int height = std::get<1>(read_result);
int width = std::get<2>(read_result);

int threshold = 100;

return std::make_tuple(pixels, height, width, threshold);
}

inline std::vector<int> GenerateExpectedOutput(ImageSet type) {
std::string full_path = GetDirectoryPath(PPC_SETTINGS_zhurin_i_edge_sobel) +
"tasks/zhurin_i_edge_sobel/data/expected/" + GetTestFilename(type);

std::tuple<std::vector<int>, int, int> read_result = ReadImageFile(full_path);

return std::get<0>(read_result);
}

} // namespace zhurin_i_edge_sobel
6 changes: 6 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5 5
0 0 0 0 0
0 200 200 200 0
0 200 200 200 0
0 200 200 200 0
0 0 0 0 0
1 change: 1 addition & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
11 changes: 11 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 255 255 0 0 0 0
0 0 0 0 255 255 0 0 0 0
0 0 0 0 255 255 0 0 0 0
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
0 0 0 0 255 255 0 0 0 0
0 0 0 0 255 255 0 0 0 0
0 0 0 0 255 255 0 0 0 0
0 0 0 0 0 0 0 0 0 0
21 changes: 21 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 150 255 255 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 150 255 255 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 150 150 150 255 255 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 150 150 150 255 255 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 150 150 150 150 150 255 255 150 150 150 150 150 150 150 150 150 150 150 0
0 150 150 150 150 150 255 255 150 150 150 150 150 150 150 150 150 150 150 0
0 150 150 150 150 150 150 150 255 255 150 150 150 150 150 150 150 150 150 0
0 150 150 150 150 150 150 150 255 255 150 150 150 150 150 150 150 150 150 0
0 150 150 150 150 150 150 150 150 150 255 255 150 150 150 150 150 150 150 0
0 150 150 150 150 150 150 150 150 150 255 255 150 150 150 150 150 150 150 0
0 150 150 150 150 150 150 150 150 150 150 150 255 255 150 150 150 150 150 0
0 150 150 150 150 150 150 150 150 150 150 150 255 255 150 150 150 150 150 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 255 255 150 150 150 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 255 255 150 150 150 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 255 255 150 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 255 255 150 0
0 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 150 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6 changes: 6 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
255 255 255 255 255 255 255 255 255 255
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
11 changes: 11 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10 5
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
0 0 255 0 0
4 changes: 4 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3
50 50 50
50 255 50
50 50 50
3 changes: 3 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2 2
0 255
255 0
2 changes: 2 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 1
255
4 changes: 4 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/cases/test9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3
10 20 30
40 50 60
70 80 90
6 changes: 6 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5 5
0 0 0 0 0
0 565 800 565 0
0 800 1131 800 0
0 565 800 565 0
0 0 0 0 0
1 change: 1 addition & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0
11 changes: 11 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 360 360 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
21 changes: 21 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 424 424 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6 changes: 6 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
11 changes: 11 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10 5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
4 changes: 4 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3
0 0 0
0 283 0
0 0 0
3 changes: 3 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2 2
0 360
360 0
2 changes: 2 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 1
0
4 changes: 4 additions & 0 deletions tasks/zhurin_i_edge_sobel/data/expected/test9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3
0 40 0
80 127 80
0 40 0
9 changes: 9 additions & 0 deletions tasks/zhurin_i_edge_sobel/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "Иван",
"last_name": "Журин",
"middle_name": "Эдуардович",
"group_number": "3823Б1ПР1",
"task_number": "3"
}
}
59 changes: 59 additions & 0 deletions tasks/zhurin_i_edge_sobel/mpi/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

// #include <mpi.h>

#include <cmath>
// #include <cstddef>
// #include <tuple>
#include <vector>

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

namespace zhurin_i_edge_sobel {

const std::vector<std::vector<int>> kSobelX = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
const std::vector<std::vector<int>> kSobelY = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

class ZhurinIEdgeSobelMPI : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kMPI;
}

explicit ZhurinIEdgeSobelMPI(const InType &in);

private:
int height_ = 0;
int width_ = 0;
int threshold_ = 0;

std::vector<int> input_pixels_;
std::vector<int> local_pixels_;
int local_height_ = 0;
int local_height_with_halo_ = 0;

void BroadcastParameters();
void DistributeRows();
std::vector<int> LocalGradientsComputing();
[[nodiscard]] int GradientX(int x, int y) const;
[[nodiscard]] int GradientY(int x, int y) const;
void GatherResults(const std::vector<int> &local_result);

void RowDistributionComputing(int world_rank, int world_size, int &base_rows, int &remainder, int &real_rows,
int &need_top_halo, int &need_bottom_halo, int &total_rows);

void SendParameters(int world_rank, int world_size, int base_rows, int remainder,
std::vector<int> &real_rows_per_proc, std::vector<int> &send_counts,
std::vector<int> &send_displs) const;

void LocalRowsComputing(int /*unused*/, int /*unused*/);
void DataDistribution(int /*unused*/, const std::vector<int> & /*unused*/, const std::vector<int> & /*unused*/);

bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;
};

} // namespace zhurin_i_edge_sobel
Loading
Loading