From 2ceedba67b489bf3bc9e3e6bceaa9f5706602c2b Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Sun, 29 Dec 2024 11:58:46 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"=D0=A1=D0=BE=D0=BB=D0=BE=D0=B2=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=D0=94=D0=B0=D0=BD=D0=B8=D0=BB=D0=B0.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=203.=20=D0=92=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B0=D0=BD=D1=82=2032.=20=D0=9F=D0=BE=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=8B=D0=BF=D1=83=D0=BA=D0=BB?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BE=D0=B1=D0=BE=D0=BB=D0=BE=D1=87=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B4=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 12669b7afb471a3d82ec90d57e9f658f5b70a331. --- .../func_tests/main.cpp | 304 ------------------ .../include/header.hpp | 79 ----- .../perf_tests/main.cpp | 126 -------- .../src/source.cpp | 252 --------------- .../func_tests/main.cpp | 273 ---------------- .../include/header.hpp | 71 ---- .../perf_tests/main.cpp | 112 ------- .../src/source.cpp | 213 ------------ 8 files changed, 1430 deletions(-) delete mode 100644 tasks/mpi/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp delete mode 100644 tasks/mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp delete mode 100644 tasks/mpi/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp delete mode 100644 tasks/mpi/solovyev_d_convex_hull_binary_image_components/src/source.cpp delete mode 100644 tasks/seq/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp delete mode 100644 tasks/seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp delete mode 100644 tasks/seq/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp delete mode 100644 tasks/seq/solovyev_d_convex_hull_binary_image_components/src/source.cpp diff --git a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp b/tasks/mpi/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp deleted file mode 100644 index 377fc615b71..00000000000 --- a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp +++ /dev/null @@ -1,304 +0,0 @@ -#include - -#include -#include -#include -#include - -#include "mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp" - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_Wrong_Input_Dimensions) { - boost::mpi::communicator world; - int dimX = 1; - int dimY = 1; - - std::vector in = {1, 0, 1, 1, 1, 0, 1, 0}; - std::vector> expected = {}; - std::vector> out = {}; - - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - if (world.rank() == 0) { - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), false); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_Empty) { - boost::mpi::communicator world; - int dimX = 0; - int dimY = 0; - std::vector in = {}; - std::vector> expected = {}; - std::vector> out = {}; - - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_OnlyBackground) { - boost::mpi::communicator world; - int dimX = 5; - int dimY = 5; - std::vector in = {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}; - std::vector> expected = {}; - std::vector> out = {}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out[i].size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_1x1) { - boost::mpi::communicator world; - int dimX = 1; - int dimY = 1; - std::vector in = {1}; - std::vector> expected = {{0, 0}}; - std::vector> out = {std::vector(expected[0].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_2x2) { - boost::mpi::communicator world; - int dimX = 2; - int dimY = 2; - std::vector in = {1, 1, 1, 1}; - std::vector> expected = {{1, 1, 1, 0, 0, 0, 0, 1}}; - std::vector> out = {std::vector(expected[0].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_3x3) { - boost::mpi::communicator world; - int dimX = 3; - int dimY = 3; - std::vector in = {1, 1, 1, 0, 0, 0, 1, 1, 1}; - std::vector> expected = {{2, 0, 0, 0}, {2, 2, 0, 2}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_5x5) { - boost::mpi::communicator world; - int dimX = 5; - int dimY = 5; - std::vector in = {0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0}; - std::vector> expected = {{3, 3, 4, 2, 4, 0, 3, 0, 1, 1}, {1, 4, 1, 3, 0, 3, 0, 4}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_4x6) { - boost::mpi::communicator world; - int dimX = 4; - int dimY = 6; - std::vector in = {0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1}; - std::vector> expected = {{3, 3, 3, 0, 1, 1}, {3, 5, 1, 3, 0, 3, 0, 5}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out[i].size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, Test_21x8) { - boost::mpi::communicator world; - int dimX = 21; - int dimY = 8; - std::vector in = {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, - 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, - 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0}; - std::vector> expected = {{6, 7, 6, 3, 3, 0, 0, 3, 0, 7}, - {12, 7, 13, 6, 13, 1, 12, 0, 9, 0, 8, 1, 8, 6, 9, 7}, - {18, 7, 20, 4, 20, 3, 18, 0, 17, 0, 15, 3, 15, 4, 17, 7}}; - std::vector> out = {std::vector(expected[0].size(), 0), std::vector(expected[1].size(), 0), - std::vector(expected[2].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out[i].size()); - } - } - // Create Task - solovyev_d_convex_hull_binary_image_components_mpi::ConvexHullBinaryImageComponentsMPI - ConvexHullBinaryImageComponentsMPI(taskDataPar); - ASSERT_EQ(ConvexHullBinaryImageComponentsMPI.validation(), true); - ConvexHullBinaryImageComponentsMPI.pre_processing(); - ConvexHullBinaryImageComponentsMPI.run(); - ConvexHullBinaryImageComponentsMPI.post_processing(); - if (world.rank() == 0) { - ASSERT_EQ(expected, out); - } -} \ No newline at end of file diff --git a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp b/tasks/mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp deleted file mode 100644 index 72d0d0ba251..00000000000 --- a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace solovyev_d_convex_hull_binary_image_components_mpi { - -struct Point { - int x; - int y; - int value; - double relativeAngle(Point other) const; - template - void serialize(Archive& ar, unsigned int version) { - ar & x; - ar & y; - ar & value; - } -}; - -class Image { - std::vector image; - std::vector components{0}; - - public: - int sizeX; - int sizeY; - - Image(); - Image(std::vector data, int dimX, int dimY); - - Point getPoint(int x, int y); - void setPoint(int x, int y, int value); - - std::vector getComponents(); - int newComponent(); - void clearComponents(); - void removeComponent(int n); - void fixComponents(); -}; - -struct eqUnit { - int replaceable; - int replacement; -}; - -class ConvexHullBinaryImageComponentsMPI : public ppc::core::Task { - public: - explicit ConvexHullBinaryImageComponentsMPI(std::shared_ptr taskData_) - : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - Image image; - std::vector equivalenceTable; - boost::mpi::communicator world; - - static std::vector linearizePoints(std::vector points) { - std::vector linear; - for (size_t i = 0; i < points.size(); i++) { - linear.push_back(points[i].x); - linear.push_back(points[i].y); - } - return linear; - } - - std::vector> results; -}; - -} // namespace solovyev_d_convex_hull_binary_image_components_mpi \ No newline at end of file diff --git a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp b/tasks/mpi/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp deleted file mode 100644 index 18ceb1a9b60..00000000000 --- a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp" - -namespace solovyev_d_convex_hull_binary_image_components_mpi { -std::vector generateVector(int sz) { - std::vector vec(sz); - for (int j = 0; j < 10; j++) { - for (int i = j * sz / 10; i < (j + 1) * sz / 10; i++) { - vec[i] = j % 2; - } - } - return vec; -} -} // namespace solovyev_d_convex_hull_binary_image_components_mpi -TEST(solovyev_d_convex_hull_binary_image_components_mpi, test_pipeline_run) { - boost::mpi::communicator world; - int dimX = 500; - int dimY = 500; - std::vector in = solovyev_d_convex_hull_binary_image_components_mpi::generateVector(500 * 500); - std::vector> expected = {{499, 99, 499, 50, 0, 50, 0, 99}, - {499, 199, 499, 150, 0, 150, 0, 199}, - {499, 299, 499, 250, 0, 250, 0, 299}, - {499, 399, 499, 350, 0, 350, 0, 399}, - {499, 499, 499, 450, 0, 450, 0, 499}}; - std::vector> out = {std::vector(expected[0].size(), 0), std::vector(expected[1].size(), 0), - std::vector(expected[2].size(), 0), std::vector(expected[3].size(), 0), - std::vector(expected[4].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - auto testTaskMPI = - std::make_shared( - taskDataPar); - // Create Perf attributes - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - // Create and init perf results - auto perfResults = std::make_shared(); - - // Create Perf analyzer - auto perfAnalyzer = std::make_shared(testTaskMPI); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(expected, out); - } -} - -TEST(solovyev_d_convex_hull_binary_image_components_mpi, test_task_run) { - boost::mpi::communicator world; - int dimX = 500; - int dimY = 500; - std::vector in = solovyev_d_convex_hull_binary_image_components_mpi::generateVector(500 * 500); - std::vector> expected = {{499, 99, 499, 50, 0, 50, 0, 99}, - {499, 199, 499, 150, 0, 150, 0, 199}, - {499, 299, 499, 250, 0, 250, 0, 299}, - {499, 399, 499, 350, 0, 350, 0, 399}, - {499, 499, 499, 450, 0, 450, 0, 499}}; - std::vector> out = {std::vector(expected[0].size(), 0), std::vector(expected[1].size(), 0), - std::vector(expected[2].size(), 0), std::vector(expected[3].size(), 0), - std::vector(expected[4].size(), 0)}; - // Create data - std::shared_ptr taskDataPar = std::make_shared(); - if (world.rank() == 0) { - // Create TaskData - taskDataPar->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataPar->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataPar->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataPar->outputs_count.emplace_back(out.size()); - } - } - // Create Task - auto testTaskMPI = - std::make_shared( - taskDataPar); - - // Create Perf attributes - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - // Create and init perf results - auto perfResults = std::make_shared(); - - // Create Perf analyzer - auto perfAnalyzer = std::make_shared(testTaskMPI); - perfAnalyzer->task_run(perfAttr, perfResults); - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(expected, out); - } -} \ No newline at end of file diff --git a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/src/source.cpp b/tasks/mpi/solovyev_d_convex_hull_binary_image_components/src/source.cpp deleted file mode 100644 index 7e8d3a7de71..00000000000 --- a/tasks/mpi/solovyev_d_convex_hull_binary_image_components/src/source.cpp +++ /dev/null @@ -1,252 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "mpi/solovyev_d_convex_hull_binary_image_components/include/header.hpp" - -namespace solovyev_d_convex_hull_binary_image_components_mpi { - -double Point::relativeAngle(Point other) const { return std::atan2((other.y * -1) - (y * -1), other.x - x); } - -Image::Image() { - image = std::vector{}; - sizeX = 0; - sizeY = 0; -} - -Image::Image(std::vector data, int dimX, int dimY) { - for (size_t i = 0; i < data.size(); i++) { - int pointY = i / dimX; - int pointX = i - pointY * dimX; - Point point = {pointX, pointY, data[i]}; - image.push_back(point); - } - sizeX = dimX; - sizeY = dimY; -} - -Point Image::getPoint(int x, int y) { - if (x >= 0 && x <= sizeX && y >= 0 && y <= sizeY) { - return image[y * sizeX + x]; - } - Point point = {x, y, 0}; - return point; -} - -void Image::setPoint(int x, int y, int value) { image[y * sizeX + x].value = value; } - -std::vector Image::getComponents() { return components; } - -int Image::newComponent() { - int id = components.back() + 1; - components.push_back(id); - return id; -} - -void Image::clearComponents() { - components.clear(); - components.push_back(0); -} - -void Image::removeComponent(int n) { - auto index = find(components.begin(), components.end(), n); - if (index != components.end()) { - components.erase(index); - } -} - -void Image::fixComponents() { - for (size_t i = 0; i < components.size(); i++) { - components[i] = i; - } -} - -static int crossProduct(Point a, Point b, Point c) { - return (b.x - a.x) * (-1 * c.y - -1 * a.y) - (-1 * b.y - -1 * a.y) * (c.x - a.x); -} - -static std::vector convexHull(std::vector component) { - std::sort(component.begin(), component.end(), [](const Point &L, const Point &R) { return L.y < R.y; }); - Point point = component.back(); - std::sort(component.begin(), component.end(), [&](const Point &L, const Point &R) { - if (point.relativeAngle(L) == point.relativeAngle(R)) { - double distanceL = (L.x - point.x) * (L.x - point.x) + (L.y - point.y) * (L.y - point.y); - double distanceR = (R.x - point.x) * (R.x - point.x) + (R.y - point.y) * (R.y - point.y); - return distanceL < distanceR; - } - return point.relativeAngle(L) < point.relativeAngle(R); - }); - std::stack hull; - hull.push(component[0]); - if (component.size() != 1) { - hull.push(component[1]); - } - for (size_t i = 2; i < component.size(); ++i) { - while (hull.size() > 1) { - Point top = hull.top(); - hull.pop(); - Point nextToTop = hull.top(); - if (crossProduct(nextToTop, top, component[i]) > 0) { - hull.push(top); - break; - } - } - hull.push(component[i]); - } - - std::vector result; - while (!hull.empty()) { - result.push_back(hull.top()); - hull.pop(); - } - std::reverse(result.begin(), result.end()); - return result; -} - -bool ConvexHullBinaryImageComponentsMPI::pre_processing() { - internal_order_test(); - - // Init data vector - if (world.rank() == 0) { - int *input_ = reinterpret_cast(taskData->inputs[0]); - int dimX = *reinterpret_cast(taskData->inputs[1]); - int dimY = *reinterpret_cast(taskData->inputs[2]); - std::vector data(input_, input_ + taskData->inputs_count[0]); - image = Image(data, dimX, dimY); - } - return true; -} - -bool ConvexHullBinaryImageComponentsMPI::validation() { - internal_order_test(); - if (world.rank() == 0) { - bool isSizeCorrect = - ((*reinterpret_cast(taskData->inputs[1])) * (*reinterpret_cast(taskData->inputs[2])) == - (int)(taskData->inputs_count[0])); - return ( - (*reinterpret_cast(taskData->inputs[1]) >= 0 && *reinterpret_cast(taskData->inputs[2]) >= 0) && - isSizeCorrect); - } - return true; -} - -bool ConvexHullBinaryImageComponentsMPI::run() { - internal_order_test(); - // First phase - if (world.rank() == 0) { - image.clearComponents(); - results.clear(); - equivalenceTable.clear(); - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - Point point = image.getPoint(x, y); - Point diag = image.getPoint(x - 1, y - 1); - Point left = image.getPoint(x - 1, y); - Point up = image.getPoint(x, y - 1); - if (point.value != 0) { - if (diag.value != 0) { - image.setPoint(x, y, diag.value); - } else { - if (left.value == 0 && up.value == 0) { - image.setPoint(x, y, image.newComponent()); - } else if (left.value == 0 && up.value != 0) { - image.setPoint(x, y, up.value); - } else if (left.value != 0 && up.value == 0) { - image.setPoint(x, y, left.value); - } else { - image.setPoint(x, y, up.value); - if (up.value != left.value) { - equivalenceTable.push_back(eqUnit{left.value, up.value}); - } - } - } - } - } - } - - // Second phase - std::sort(equivalenceTable.begin(), equivalenceTable.end(), - [&](const eqUnit &L, const eqUnit &R) { return L.replaceable > R.replaceable; }); - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - for (size_t i = 0; i < equivalenceTable.size(); i++) { - if (image.getPoint(x, y).value == equivalenceTable[i].replaceable) { - image.setPoint(x, y, equivalenceTable[i].replacement); - image.removeComponent(equivalenceTable[i].replaceable); - } - } - } - } - - // Third phase - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - for (size_t i = 0; i < image.getComponents().size(); i++) { - if (image.getPoint(x, y).value == image.getComponents()[i]) { - image.setPoint(x, y, i); - } - } - } - } - image.fixComponents(); - } - std::vector> components; - std::vector> localComponents; - - std::vector sendCounts(world.size(), 0); - std::vector displacements(world.size(), 0); - - if (world.rank() == 0) { - for (size_t j = 1; j < image.getComponents().size(); j++) { - std::vector component; - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - if (image.getPoint(x, y).value == (int)j) { - component.push_back(image.getPoint(x, y)); - } - } - } - components.push_back(component); - } - int elementsCount = (components.size() / world.size()); - int remainder = (components.size() % world.size()); - sendCounts = std::vector(world.size(), elementsCount); - sendCounts[0] = sendCounts[0] + remainder; - for (size_t i = 1; i < sendCounts.size(); i++) { - displacements[i] = displacements[i - 1] + sendCounts[i - 1]; - } - } - boost::mpi::broadcast(world, sendCounts, 0); - boost::mpi::broadcast(world, displacements, 0); - localComponents.resize(sendCounts[world.rank()]); - boost::mpi::scatterv(world, components, sendCounts, displacements, localComponents.data(), sendCounts[world.rank()], - 0); - for (size_t i = 0; i < localComponents.size(); i++) { - localComponents[i] = convexHull(localComponents[i]); - } - boost::mpi::gatherv(world, localComponents, components.data(), sendCounts, displacements, 0); - if (world.rank() == 0) { - for (size_t i = 0; i < components.size(); i++) { - results.push_back(linearizePoints(components[i])); - } - } - return true; -} - -bool ConvexHullBinaryImageComponentsMPI::post_processing() { - internal_order_test(); - world.barrier(); - if (world.rank() == 0) { - for (size_t i = 0; i < results.size(); i++) { - for (size_t j = 0; j < results[i].size(); j++) { - reinterpret_cast(taskData->outputs[i])[j] = results[i][j]; - } - } - } - return true; -} -} // namespace solovyev_d_convex_hull_binary_image_components_mpi \ No newline at end of file diff --git a/tasks/seq/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp b/tasks/seq/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp deleted file mode 100644 index 7165a240048..00000000000 --- a/tasks/seq/solovyev_d_convex_hull_binary_image_components/func_tests/main.cpp +++ /dev/null @@ -1,273 +0,0 @@ -#include - -#include -#include - -#include "seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp" - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_Wrong_Input_Dimensions) { - int dimX = 1; - int dimY = 1; - // Create data - std::vector in = {1, 0, 1, 1, 1, 0, 1, 0}; - std::vector> expected = {}; - std::vector> out = {}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), false); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_Empty) { - int dimX = 0; - int dimY = 0; - // Create data - std::vector in = {}; - std::vector> expected = {}; - std::vector> out = {}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_OnlyBackground) { - int dimX = 5; - int dimY = 5; - // Create data - std::vector in = {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}; - std::vector> expected = {}; - std::vector> out = {}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out[i].size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_1x1) { - int dimX = 1; - int dimY = 1; - // Create data - std::vector in = {1}; - std::vector> expected = {{0, 0}}; - std::vector> out = {std::vector(expected[0].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_2x2) { - int dimX = 2; - int dimY = 2; - // Create data - std::vector in = {1, 1, 1, 1}; - std::vector> expected = {{1, 1, 1, 0, 0, 0, 0, 1}}; - std::vector> out = {std::vector(expected[0].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_3x3) { - int dimX = 3; - int dimY = 3; - // Create data - std::vector in = {1, 1, 1, 0, 0, 0, 1, 1, 1}; - std::vector> expected = {{2, 0, 0, 0}, {2, 2, 0, 2}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_5x5) { - int dimX = 5; - int dimY = 5; - // Create data - std::vector in = {0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0}; - std::vector> expected = {{3, 3, 4, 2, 4, 0, 3, 0, 1, 1}, {1, 4, 1, 3, 0, 3, 0, 4}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_4x6) { - int dimX = 4; - int dimY = 6; - // Create data - std::vector in = {0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1}; - std::vector> expected = {{3, 3, 3, 0, 1, 1}, {3, 5, 1, 3, 0, 3, 0, 5}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out[i].size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, Test_21x8) { - int dimX = 21; - int dimY = 8; - // Create data - std::vector in = {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, - 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, - 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, - 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0}; - std::vector> expected = {{6, 7, 6, 3, 3, 0, 0, 3, 0, 7}, - {12, 7, 13, 6, 13, 1, 12, 0, 9, 0, 8, 1, 8, 6, 9, 7}, - {18, 7, 20, 4, 20, 3, 18, 0, 17, 0, 15, 3, 15, 4, 17, 7}}; - std::vector> out = {std::vector(expected[0].size(), 0), std::vector(expected[1].size(), 0), - std::vector(expected[2].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out[i].size()); - } - - // Create Task - solovyev_d_convex_hull_binary_image_components_seq::ConvexHullBinaryImageComponentsSequential - ConvexHullBinaryImageComponentsSequential(taskDataSeq); - ASSERT_EQ(ConvexHullBinaryImageComponentsSequential.validation(), true); - ConvexHullBinaryImageComponentsSequential.pre_processing(); - ConvexHullBinaryImageComponentsSequential.run(); - ConvexHullBinaryImageComponentsSequential.post_processing(); - ASSERT_EQ(expected, out); -} \ No newline at end of file diff --git a/tasks/seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp b/tasks/seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp deleted file mode 100644 index 18c8da5aa0e..00000000000 --- a/tasks/seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp +++ /dev/null @@ -1,71 +0,0 @@ - -#pragma once - -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace solovyev_d_convex_hull_binary_image_components_seq { - -struct Point { - int x; - int y; - int value; - double relativeAngle(Point other) const; -}; - -class Image { - std::vector image; - std::vector components{0}; - - public: - int sizeX; - int sizeY; - - Image(); - Image(std::vector data, int dimX, int dimY); - - Point getPoint(int x, int y); - void setPoint(int x, int y, int value); - - std::vector getComponents(); - int newComponent(); - void clearComponents(); - void removeComponent(int n); - void fixComponents(); -}; - -struct eqUnit { - int replaceable; - int replacement; -}; - -class ConvexHullBinaryImageComponentsSequential : public ppc::core::Task { - public: - explicit ConvexHullBinaryImageComponentsSequential(std::shared_ptr taskData_) - : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - Image image; - std::vector equivalenceTable; - - static std::vector linearizePoints(std::vector points) { - std::vector linear; - for (size_t i = 0; i < points.size(); i++) { - linear.push_back(points[i].x); - linear.push_back(points[i].y); - } - return linear; - } - - std::vector> results; -}; - -} // namespace solovyev_d_convex_hull_binary_image_components_seq \ No newline at end of file diff --git a/tasks/seq/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp b/tasks/seq/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp deleted file mode 100644 index 8b0f74823dc..00000000000 --- a/tasks/seq/solovyev_d_convex_hull_binary_image_components/perf_tests/main.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include - -#include -#include - -#include "core/perf/include/perf.hpp" -#include "seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp" -namespace solovyev_d_convex_hull_binary_image_components_seq { -std::vector generateVector(int sz) { - std::vector vec(sz); - for (int i = 0; i < sz / 4; i++) { - vec[i] = 0; - } - for (int i = sz / 4; i < 2 * sz / 4; i++) { - vec[i] = 1; - } - for (int i = 2 * sz / 4; i < 3 * sz / 4; i++) { - vec[i] = 0; - } - for (int i = 3 * sz / 4; i < sz; i++) { - vec[i] = 1; - } - return vec; -} -} // namespace solovyev_d_convex_hull_binary_image_components_seq -TEST(solovyev_d_convex_hull_binary_image_components_seq, test_pipeline_run) { - int dimX = 500; - int dimY = 500; - // Create data - std::vector in = solovyev_d_convex_hull_binary_image_components_seq::generateVector(500 * 500); - std::vector> expected = {{499, 249, 499, 125, 0, 125, 0, 249}, {499, 499, 499, 375, 0, 375, 0, 499}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - - // Create Task - auto testTaskSequential = - std::make_shared( - taskDataSeq); - // Create Perf attributes - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - // Create and init perf results - auto perfResults = std::make_shared(); - - // Create Perf analyzer - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(expected, out); -} - -TEST(solovyev_d_convex_hull_binary_image_components_seq, test_task_run) { - int dimX = 500; - int dimY = 500; - // Create data - std::vector in = solovyev_d_convex_hull_binary_image_components_seq::generateVector(500 * 500); - std::vector> expected = {{499, 249, 499, 125, 0, 125, 0, 249}, {499, 499, 499, 375, 0, 375, 0, 499}}; - std::vector> out = {std::vector(expected[0].size(), 0), - std::vector(expected[1].size(), 0)}; - - // Create TaskData - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(in.data())); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimX)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&dimY)); - taskDataSeq->inputs_count.emplace_back(in.size()); - for (size_t i = 0; i < out.size(); i++) { - taskDataSeq->outputs.emplace_back(reinterpret_cast(out[i].data())); - taskDataSeq->outputs_count.emplace_back(out.size()); - } - // Create Task - auto testTaskSequential = - std::make_shared( - taskDataSeq); - - // Create Perf attributes - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - // Create and init perf results - auto perfResults = std::make_shared(); - - // Create Perf analyzer - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->task_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(expected, out); -} diff --git a/tasks/seq/solovyev_d_convex_hull_binary_image_components/src/source.cpp b/tasks/seq/solovyev_d_convex_hull_binary_image_components/src/source.cpp deleted file mode 100644 index 1234716c11c..00000000000 --- a/tasks/seq/solovyev_d_convex_hull_binary_image_components/src/source.cpp +++ /dev/null @@ -1,213 +0,0 @@ - -#include -#include -#include -#include - -#include "seq/solovyev_d_convex_hull_binary_image_components/include/header.hpp" - -namespace solovyev_d_convex_hull_binary_image_components_seq { - -double Point::relativeAngle(Point other) const { return std::atan2((other.y * -1) - (y * -1), other.x - x); } - -Image::Image() { - image = std::vector{}; - sizeX = 0; - sizeY = 0; -} - -Image::Image(std::vector data, int dimX, int dimY) { - for (size_t i = 0; i < data.size(); i++) { - int pointY = i / dimX; - int pointX = i - pointY * dimX; - Point point = {pointX, pointY, data[i]}; - image.push_back(point); - } - sizeX = dimX; - sizeY = dimY; -} - -Point Image::getPoint(int x, int y) { - if (x >= 0 && x <= sizeX && y >= 0 && y <= sizeY) { - return image[y * sizeX + x]; - } - Point point = {x, y, 0}; - return point; -} - -void Image::setPoint(int x, int y, int value) { image[y * sizeX + x].value = value; } - -std::vector Image::getComponents() { return components; } - -int Image::newComponent() { - int id = components.back() + 1; - components.push_back(id); - return id; -} - -void Image::clearComponents() { - components.clear(); - components.push_back(0); -} - -void Image::removeComponent(int n) { - auto index = find(components.begin(), components.end(), n); - if (index != components.end()) { - components.erase(index); - } -} - -void Image::fixComponents() { - for (size_t i = 0; i < components.size(); i++) { - components[i] = i; - } -} - -static int crossProduct(Point a, Point b, Point c) { - return (b.x - a.x) * (-1 * c.y - -1 * a.y) - (-1 * b.y - -1 * a.y) * (c.x - a.x); -} - -static std::vector convexHull(std::vector component) { - std::sort(component.begin(), component.end(), [](const Point &L, const Point &R) { return L.y < R.y; }); - Point point = component.back(); - std::sort(component.begin(), component.end(), [&](const Point &L, const Point &R) { - if (point.relativeAngle(L) == point.relativeAngle(R)) { - double distanceL = (L.x - point.x) * (L.x - point.x) + (L.y - point.y) * (L.y - point.y); - double distanceR = (R.x - point.x) * (R.x - point.x) + (R.y - point.y) * (R.y - point.y); - return distanceL < distanceR; - } - return point.relativeAngle(L) < point.relativeAngle(R); - }); - std::stack hull; - hull.push(component[0]); - if (component.size() != 1) { - hull.push(component[1]); - } - for (size_t i = 2; i < component.size(); ++i) { - while (hull.size() > 1) { - Point top = hull.top(); - hull.pop(); - Point nextToTop = hull.top(); - if (crossProduct(nextToTop, top, component[i]) > 0) { - hull.push(top); - break; - } - } - hull.push(component[i]); - } - - std::vector result; - while (!hull.empty()) { - result.push_back(hull.top()); - hull.pop(); - } - std::reverse(result.begin(), result.end()); - return result; -} - -bool ConvexHullBinaryImageComponentsSequential::pre_processing() { - internal_order_test(); - - // Init data vector - int *input_ = reinterpret_cast(taskData->inputs[0]); - int dimX = *reinterpret_cast(taskData->inputs[1]); - int dimY = *reinterpret_cast(taskData->inputs[2]); - std::vector data(input_, input_ + taskData->inputs_count[0]); - image = Image(data, dimX, dimY); - return true; -} - -bool ConvexHullBinaryImageComponentsSequential::validation() { - internal_order_test(); - // Check count elements of output - bool isSizeCorrect = - ((*reinterpret_cast(taskData->inputs[1])) * (*reinterpret_cast(taskData->inputs[2])) == - (int)(taskData->inputs_count[0])); - return ((*reinterpret_cast(taskData->inputs[1]) >= 0 && *reinterpret_cast(taskData->inputs[2]) >= 0) && - isSizeCorrect); -} - -bool ConvexHullBinaryImageComponentsSequential::run() { - internal_order_test(); - image.clearComponents(); - results.clear(); - equivalenceTable.clear(); - // First phase - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - Point point = image.getPoint(x, y); - Point diag = image.getPoint(x - 1, y - 1); - Point left = image.getPoint(x - 1, y); - Point up = image.getPoint(x, y - 1); - if (point.value != 0) { - if (diag.value != 0) { - image.setPoint(x, y, diag.value); - } else { - if (left.value == 0 && up.value == 0) { - image.setPoint(x, y, image.newComponent()); - } else if (left.value == 0 && up.value != 0) { - image.setPoint(x, y, up.value); - } else if (left.value != 0 && up.value == 0) { - image.setPoint(x, y, left.value); - } else { - image.setPoint(x, y, up.value); - if (up.value != left.value) { - equivalenceTable.push_back(eqUnit{left.value, up.value}); - } - } - } - } - } - } - - // Second phase - std::sort(equivalenceTable.begin(), equivalenceTable.end(), - [&](const eqUnit &L, const eqUnit &R) { return L.replaceable > R.replaceable; }); - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - for (size_t i = 0; i < equivalenceTable.size(); i++) { - if (image.getPoint(x, y).value == equivalenceTable[i].replaceable) { - image.setPoint(x, y, equivalenceTable[i].replacement); - image.removeComponent(equivalenceTable[i].replaceable); - } - } - } - } - - // Third phase - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - for (size_t i = 0; i < image.getComponents().size(); i++) { - if (image.getPoint(x, y).value == image.getComponents()[i]) { - image.setPoint(x, y, i); - } - } - } - } - image.fixComponents(); - // Getting hulls for every component - for (size_t j = 1; j < image.getComponents().size(); j++) { - std::vector component; - for (int y = 0; y < image.sizeY; y++) { - for (int x = 0; x < image.sizeX; x++) { - if (image.getPoint(x, y).value == (int)j) { - component.push_back(image.getPoint(x, y)); - } - } - } - std::vector result = linearizePoints(convexHull(component)); - results.push_back(result); - } - return true; -} - -bool ConvexHullBinaryImageComponentsSequential::post_processing() { - internal_order_test(); - for (size_t i = 0; i < results.size(); i++) { - for (size_t j = 0; j < results[i].size(); j++) { - reinterpret_cast(taskData->outputs[i])[j] = results[i][j]; - } - } - return true; -} -} // namespace solovyev_d_convex_hull_binary_image_components_seq \ No newline at end of file