From ea4b882923d466b86eb335e65bfbd8076660695f Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Tue, 10 Dec 2024 22:31:21 +0300 Subject: [PATCH] =?UTF-8?q?Revert=20"=D0=9A=D0=B0=D0=B7=D1=83=D0=BD=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0.=20=D0=97=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=B0=202.=20=D0=92=D0=B0=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BD=D1=82=203.=20=D0=9E=D0=B1=D0=B5=D0=B4=D0=B0=D1=8E=D1=89?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BB=D0=BE=D1=81=D0=BE=D1=84=D1=8B?= =?UTF-8?q?.=20(#436)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit eae78c2e1005d51e5781a863071ad9ced8283e25. --- .../func_tests/main.cpp | 109 ------------ .../include/ops_mpi.hpp | 45 ----- .../perf_tests/main.cpp | 128 -------------- .../src/ops_mpi.cpp | 165 ------------------ 4 files changed, 447 deletions(-) delete mode 100644 tasks/mpi/kazunin_n_dining_philosophers/func_tests/main.cpp delete mode 100644 tasks/mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp delete mode 100644 tasks/mpi/kazunin_n_dining_philosophers/perf_tests/main.cpp delete mode 100644 tasks/mpi/kazunin_n_dining_philosophers/src/ops_mpi.cpp diff --git a/tasks/mpi/kazunin_n_dining_philosophers/func_tests/main.cpp b/tasks/mpi/kazunin_n_dining_philosophers/func_tests/main.cpp deleted file mode 100644 index 74575227f24..00000000000 --- a/tasks/mpi/kazunin_n_dining_philosophers/func_tests/main.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include - -#include -#include - -#include "core/task/include/task.hpp" -#include "mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp" - -namespace kazunin_n_dining_philosophers_mpi { - -bool is_valid(int eat_limit, int min_think_time, int max_think_time, int min_eat_time, int max_eat_time) { - return eat_limit > 0 && min_think_time < max_think_time && min_eat_time < max_eat_time && max_think_time < 100 && - min_think_time > 0 && max_eat_time < 100 && min_eat_time > 0; -} - -void start_test(int eat_limit = 3, int min_think_time = 10, int max_think_time = 20, int min_eat_time = 5, - int max_eat_time = 10) { - boost::mpi::communicator world; - if (world.size() < 4) { - GTEST_SKIP(); - } - std::shared_ptr taskDataPar = std::make_shared(); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&eat_limit)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - auto taskParallel = std::make_shared(taskDataPar); - if (is_valid(eat_limit, min_think_time, max_think_time, min_eat_time, max_eat_time)) { - EXPECT_TRUE(taskParallel->validation()); - taskParallel->pre_processing(); - taskParallel->run(); - taskParallel->post_processing(); - } else { - EXPECT_FALSE(taskParallel->validation()); - } - world.barrier(); -} - -} // namespace kazunin_n_dining_philosophers_mpi - -TEST(kazunin_n_dining_philosophers_mpi, defailt) { kazunin_n_dining_philosophers_mpi::start_test(); } - -TEST(kazunin_n_dining_philosophers_mpi, default_eat_limit) { kazunin_n_dining_philosophers_mpi::start_test(4); } - -TEST(kazunin_n_dining_philosophers_mpi, default_min_think_time) { - kazunin_n_dining_philosophers_mpi::start_test(4, 10); -} - -TEST(kazunin_n_dining_philosophers_mpi, default_max_think_time) { - kazunin_n_dining_philosophers_mpi::start_test(4, 10, 15); -} - -TEST(kazunin_n_dining_philosophers_mpi, default_min_eat_time) { - kazunin_n_dining_philosophers_mpi::start_test(4, 10, 15, 10); -} - -TEST(kazunin_n_dining_philosophers_mpi, default_max_eat_time) { - kazunin_n_dining_philosophers_mpi::start_test(4, 10, 15, 10, 15); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_min_eat_limit) { - kazunin_n_dining_philosophers_mpi::start_test(0); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_min_min_think_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, -20); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_min_gt_max_think_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, 30, 20); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_max_max_think_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, 20, 1000); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_min_min_eat_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, 20, 40, -20); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_min_gt_max_eat_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, 20, 40, 30, 20); -} - -TEST(kazunin_n_dining_philosophers_mpi, validation_test_max_max_eat_time) { - kazunin_n_dining_philosophers_mpi::start_test(3, 20, 40, 20, 1000); -} - -TEST(kazunin_n_dining_philosophers_mpi, simulation_10_eat_limit) { kazunin_n_dining_philosophers_mpi::start_test(10); } - -TEST(kazunin_n_dining_philosophers_mpi, simulation_20_eat_limit) { - kazunin_n_dining_philosophers_mpi::start_test(20, 1, 2, 1, 2); -} - -TEST(kazunin_n_dining_philosophers_mpi, simulation_30_eat_limit) { - kazunin_n_dining_philosophers_mpi::start_test(30, 1, 2, 1, 2); -} diff --git a/tasks/mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp b/tasks/mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp deleted file mode 100644 index bdfd4598982..00000000000 --- a/tasks/mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace kazunin_n_dining_philosophers_mpi { - -enum MessageTag : std::uint8_t { REQUEST_FORK = 1, RELEASE_FORK = 2, FORK_GRANTED = 3, TERMINATE_FORK = 4 }; - -inline void request_forks(int id, int left_fork, int right_fork, int N, boost::mpi::communicator& world); -inline void release_forks(int id, int left_fork, int right_fork, int N, boost::mpi::communicator& world); -inline void handle_fork_request(int& philosopher_id, bool& fork_available, std::queue& waiting_queue, - boost::mpi::communicator& world, int id); -inline void handle_fork_release(int& philosopher_id, bool& fork_available, std::queue& waiting_queue, - boost::mpi::communicator& world, int id); -inline bool fork_manager(int id, boost::mpi::communicator& world); -inline bool philosopher(int id, int N, boost::mpi::communicator& world, boost::mpi::communicator& philosophers_comm, - int eat_limit, int min_think_time, int max_think_time, int min_eat_time, int max_eat_time); - -class DiningPhilosophersParallelMPI : public ppc::core::Task { - public: - explicit DiningPhilosophersParallelMPI(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - private: - int eat_limit; - int min_think_time; - int max_think_time; - int min_eat_time; - int max_eat_time; - int N; - int color; - boost::mpi::communicator local_comm; - boost::mpi::communicator world; -}; - -} // namespace kazunin_n_dining_philosophers_mpi diff --git a/tasks/mpi/kazunin_n_dining_philosophers/perf_tests/main.cpp b/tasks/mpi/kazunin_n_dining_philosophers/perf_tests/main.cpp deleted file mode 100644 index d675522b890..00000000000 --- a/tasks/mpi/kazunin_n_dining_philosophers/perf_tests/main.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include - -#include -#include -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp" - -namespace kazunin_n_dining_philosophers_mpi { - -bool is_valid(int eat_limit, int min_think_time, int max_think_time, int min_eat_time, int max_eat_time) { - return eat_limit > 0 && min_think_time < max_think_time && min_eat_time < max_eat_time && max_think_time < 100 && - min_think_time > 0 && max_eat_time < 100 && min_eat_time > 0; -} - -} // namespace kazunin_n_dining_philosophers_mpi - -TEST(kazunin_n_dining_philosophers_mpi, pipeline_run) { - boost::mpi::environment env; - boost::mpi::communicator world; - if (world.size() < 4) { - GTEST_SKIP(); - } - - int eat_limit = 3; - int min_think_time = 20; - int max_think_time = 40; - int min_eat_time = 10; - int max_eat_time = 20; - - std::shared_ptr taskDataPar = std::make_shared(); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&eat_limit)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - auto taskParallel = std::make_shared(taskDataPar); - if (kazunin_n_dining_philosophers_mpi::is_valid(eat_limit, min_think_time, max_think_time, min_eat_time, - max_eat_time)) { - EXPECT_TRUE(taskParallel->validation()); - taskParallel->pre_processing(); - taskParallel->run(); - taskParallel->post_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - auto perfResults = std::make_shared(); - auto perfAnalyzer = std::make_shared(taskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - } - } else { - EXPECT_FALSE(taskParallel->validation()); - } -} - -TEST(kazunin_n_dining_philosophers_mpi, task_run) { - boost::mpi::environment env; - boost::mpi::communicator world; - if (world.size() < 4) { - GTEST_SKIP(); - } - - int eat_limit = 3; - int min_think_time = 20; - int max_think_time = 40; - int min_eat_time = 10; - int max_eat_time = 20; - - std::shared_ptr taskDataPar = std::make_shared(); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&eat_limit)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_think_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&min_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - taskDataPar->inputs.emplace_back(reinterpret_cast(&max_eat_time)); - taskDataPar->inputs_count.emplace_back(1); - - auto taskParallel = std::make_shared(taskDataPar); - if (kazunin_n_dining_philosophers_mpi::is_valid(eat_limit, min_think_time, max_think_time, min_eat_time, - max_eat_time)) { - EXPECT_TRUE(taskParallel->validation()); - taskParallel->pre_processing(); - taskParallel->run(); - taskParallel->post_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(taskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - } - } else { - EXPECT_FALSE(taskParallel->validation()); - } -} diff --git a/tasks/mpi/kazunin_n_dining_philosophers/src/ops_mpi.cpp b/tasks/mpi/kazunin_n_dining_philosophers/src/ops_mpi.cpp deleted file mode 100644 index b6a305edc04..00000000000 --- a/tasks/mpi/kazunin_n_dining_philosophers/src/ops_mpi.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "mpi/kazunin_n_dining_philosophers/include/ops_mpi.hpp" - -#include -#include -#include -#include -#include -#include - -namespace kazunin_n_dining_philosophers_mpi { - -inline bool philosopher(int id, int N, boost::mpi::communicator& world, boost::mpi::communicator& philosophers_comm, - int eat_limit, int min_think_time, int max_think_time, int min_eat_time, int max_eat_time) { - std::mt19937 rng(id + std::chrono::system_clock::now().time_since_epoch().count()); - std::uniform_int_distribution think_dist(min_think_time, max_think_time); - std::uniform_int_distribution eat_dist(min_eat_time, max_eat_time); - - int left_fork = id; - int right_fork = (id + 1) % N; - int eat_count = 0; - - while (eat_count < eat_limit) { - int think_time = think_dist(rng); - std::this_thread::sleep_for(std::chrono::milliseconds(think_time)); - - request_forks(id, left_fork, right_fork, N, world); - - int eat_time = eat_dist(rng); - std::this_thread::sleep_for(std::chrono::milliseconds(eat_time)); - eat_count++; - - release_forks(id, left_fork, right_fork, N, world); - } - - philosophers_comm.barrier(); - - int assigned_fork = N + world.rank(); - world.isend(assigned_fork, TERMINATE_FORK, id); - - return true; -} - -inline bool fork_manager(int id, boost::mpi::communicator& world) { - bool fork_available = true; - bool terminate = false; - std::queue waiting_queue; - int philosopher_id; - - while (!terminate) { - boost::mpi::status s = world.probe(boost::mpi::any_source, boost::mpi::any_tag); - - if (s.tag() == REQUEST_FORK) { - handle_fork_request(philosopher_id, fork_available, waiting_queue, world, id); - } else if (s.tag() == RELEASE_FORK) { - handle_fork_release(philosopher_id, fork_available, waiting_queue, world, id); - } else if (s.tag() == TERMINATE_FORK) { - world.recv(s.source(), TERMINATE_FORK, philosopher_id); - terminate = true; - } - } - - return true; -} - -inline void request_forks(int id, int left_fork, int right_fork, int N, boost::mpi::communicator& world) { - if (id % 2 == 0) { - world.isend(N + left_fork, REQUEST_FORK, id); - int left_reply; - world.recv(N + left_fork, FORK_GRANTED, left_reply); - - world.isend(N + right_fork, REQUEST_FORK, id); - int right_reply; - world.recv(N + right_fork, FORK_GRANTED, right_reply); - } else { - world.isend(N + right_fork, REQUEST_FORK, id); - int right_reply; - world.recv(N + right_fork, FORK_GRANTED, right_reply); - - world.isend(N + left_fork, REQUEST_FORK, id); - int left_reply; - world.recv(N + left_fork, FORK_GRANTED, left_reply); - } -} - -inline void release_forks(int id, int left_fork, int right_fork, int N, boost::mpi::communicator& world) { - if (id % 2 == 0) { - world.isend(N + left_fork, RELEASE_FORK, id); - world.isend(N + right_fork, RELEASE_FORK, id); - } else { - world.isend(N + right_fork, RELEASE_FORK, id); - world.isend(N + left_fork, RELEASE_FORK, id); - } -} - -inline void handle_fork_request(int& philosopher_id, bool& fork_available, std::queue& waiting_queue, - boost::mpi::communicator& world, int id) { - world.recv(world.probe(boost::mpi::any_source, REQUEST_FORK).source(), REQUEST_FORK, philosopher_id); - if (fork_available) { - fork_available = false; - world.isend(philosopher_id, FORK_GRANTED, id); - } else { - waiting_queue.push(philosopher_id); - } -} - -inline void handle_fork_release(int& philosopher_id, bool& fork_available, std::queue& waiting_queue, - boost::mpi::communicator& world, int id) { - world.recv(world.probe(boost::mpi::any_source, RELEASE_FORK).source(), RELEASE_FORK, philosopher_id); - if (!waiting_queue.empty()) { - int next_philosopher = waiting_queue.front(); - waiting_queue.pop(); - world.isend(next_philosopher, FORK_GRANTED, id); - } else { - fork_available = true; - } -} - -} // namespace kazunin_n_dining_philosophers_mpi - -bool kazunin_n_dining_philosophers_mpi::DiningPhilosophersParallelMPI::validation() { - internal_order_test(); - - int val_eat_limit = *reinterpret_cast(taskData->inputs[0]); - int val_min_think_time = *reinterpret_cast(taskData->inputs[1]); - int val_max_think_time = *reinterpret_cast(taskData->inputs[2]); - int val_min_eat_time = *reinterpret_cast(taskData->inputs[3]); - int val_max_eat_time = *reinterpret_cast(taskData->inputs[4]); - - return val_eat_limit > 0 && val_min_think_time < val_max_think_time && val_min_eat_time < val_max_eat_time && - val_max_think_time < 100 && val_min_think_time > 0 && val_max_eat_time < 100 && val_min_eat_time > 0; -} - -bool kazunin_n_dining_philosophers_mpi::DiningPhilosophersParallelMPI::pre_processing() { - internal_order_test(); - - eat_limit = *reinterpret_cast(taskData->inputs[0]); - min_think_time = *reinterpret_cast(taskData->inputs[1]); - max_think_time = *reinterpret_cast(taskData->inputs[2]); - min_eat_time = *reinterpret_cast(taskData->inputs[3]); - max_eat_time = *reinterpret_cast(taskData->inputs[4]); - N = world.size() / 2; - color = (world.rank() < N) ? 0 : 1; - local_comm = world.split(color); - - return true; -} - -bool kazunin_n_dining_philosophers_mpi::DiningPhilosophersParallelMPI::run() { - internal_order_test(); - - if (color == 0) { - philosopher(world.rank(), N, world, local_comm, eat_limit, min_think_time, max_think_time, min_eat_time, - max_eat_time); - } else { - fork_manager(world.rank() - N, world); - } - - return true; -} - -bool kazunin_n_dining_philosophers_mpi::DiningPhilosophersParallelMPI::post_processing() { - internal_order_test(); - - return true; -}