From 5bfddcdd5d6e02adaaa01f310d724b482865162e Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 2 Dec 2024 22:16:13 +0300 Subject: [PATCH 01/55] add files --- .../func_tests/main.cpp | 102 +++++++++++ .../include/ops_mpi.hpp | 38 ++++ .../perf_tests/main.cpp | 84 +++++++++ .../src/ops_mpi.cpp | 164 ++++++++++++++++++ 4 files changed, 388 insertions(+) create mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp create mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp create mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp create mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp new file mode 100644 index 00000000000..b054c9ed57b --- /dev/null +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -0,0 +1,102 @@ +#include + +#include +#include +#include +#include + +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {0}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation2) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + if (world.size() < 3) { + taskDataPar->inputs_count = {1}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation3) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {1}; + EXPECT_TRUE(testMpiTaskParallel.validation()); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 1; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + ASSERT_EQ(global_res, 0); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + } +} + +//TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { +// boost::mpi::communicator world; +// +// std::shared_ptr taskDataPar = std::make_shared(); +// +// const int max_waiting_chairs = 3; +// int global_res = -1; +// +// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); +// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); +// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); +// +// gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); +// +// if (world.rank() == 0) { +// ASSERT_TRUE(testMpiTaskParallel.validation()); +// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); +// ASSERT_TRUE(testMpiTaskParallel.run()); +// ASSERT_TRUE(testMpiTaskParallel.post_processing()); +// ASSERT_EQ(global_res, 0); +// } else { +// ASSERT_TRUE(testMpiTaskParallel.validation()); +// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); +// ASSERT_TRUE(testMpiTaskParallel.run()); +// ASSERT_TRUE(testMpiTaskParallel.post_processing()); +// } +//} diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp b/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp new file mode 100644 index 00000000000..e02d36d25ef --- /dev/null +++ b/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace gordeeva_t_sleeping_barber_mpi { + +class TestMPITaskParallel : public ppc::core::Task { + public: + explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + private: + size_t max_waiting_chairs; + int result; + boost::mpi::communicator world; + + void barber_logic(); + void dispatcher_logic(); + void client_logic(); + + void serve_next_client(int client_id); +}; +} // namespace gordeeva_t_sleeping_barber_mpi diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp new file mode 100644 index 00000000000..4ef43dcbeae --- /dev/null +++ b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp @@ -0,0 +1,84 @@ +#include + +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" + +TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + bool barber_busy_ = false; + + std::vector global_res(1, 0); + int num_clients = 10; + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; // The number of clients to run + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + std::vector global_res(1, 0); + bool barber_busy_ = false; + + // Create TaskData + std::shared_ptr taskDataPar = std::make_shared(); + int num_clients = 10; + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp new file mode 100644 index 00000000000..c201e6a2326 --- /dev/null +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -0,0 +1,164 @@ +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" + +#include +#include +#include +#include +#include +#include +#include + +using namespace std::chrono_literals; + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::pre_processing() { + internal_order_test(); + result = -1; + + if (world.rank() == 0) { + max_waiting_chairs = taskData->inputs_count[0]; + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { + internal_order_test(); + + if (world.rank() == 0) { + if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { + std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; + return false; + } + + if (world.size() < 3) { + std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; + return false; + } + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { + internal_order_test(); + + if (world.rank() == 0) { + barber_logic(); + } else if (world.rank() == 1) { + dispatcher_logic(); + } else { + client_logic(); + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { + internal_order_test(); + + if (world.rank() == 0) { + if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { + *reinterpret_cast(taskData->outputs[0]) = result; + } else { + return false; + } + } + + return true; +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { + while (true) { + int client_id = -1; + + world.recv(1, 0, client_id); + + if (client_id == -1) { + result = 0; + std::cout << "[BARBER] All clients served. Stopping." << std::endl; + return; + } + + serve_next_client(client_id); + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { + std::queue waiting_clients; + max_waiting_chairs = taskData->inputs_count[0]; + int remaining_clients = world.size() - 2; + bool barber_busy = false; + + while (true) { + int client_id = -1; + + if (world.iprobe(boost::mpi::any_source, 0)) { + world.recv(boost::mpi::any_source, 0, client_id); + + if (static_cast(waiting_clients.size()) < max_waiting_chairs) { + waiting_clients.push(client_id); + world.send(client_id, 1, true); + std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + } else { + world.send(client_id, 1, false); + std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + } + } + + if (!barber_busy && !waiting_clients.empty()) { + int next_client = waiting_clients.front(); + waiting_clients.pop(); + world.send(0, 0, next_client); + barber_busy = true; + std::cout << "[DISPATCHER] Sent client " << next_client << " to barber." << std::endl; + } + + if (world.iprobe(0, 4)) { + int barber_signal; + world.recv(0, 4, barber_signal); + barber_busy = false; + std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; + } + + if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { + std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; + world.send(0, 0, -1); + break; + } + + if (world.iprobe(boost::mpi::any_source, 3)) { + std::cout << "LAST: " << remaining_clients << std::endl; + int done_signal; + world.recv(boost::mpi::any_source, 3, done_signal); + remaining_clients--; + } + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { + int client_id = world.rank(); + bool accepted = false; + + world.send(1, 0, client_id); + + world.recv(1, 1, accepted); + + if (accepted) { + world.recv(0, 2, client_id); + world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; + } else { + world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { + std::cout << "[BARBER] Serving client " << client_id << std::endl; + std::this_thread::sleep_for(20ms); + world.send(client_id, 2, client_id); + std::cout << "[BARBER] Finished client " << client_id << std::endl; + world.send(1, 4, client_id); +} \ No newline at end of file From 6225155a21576ffd72c0d588b5b3db33484de965 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 2 Dec 2024 22:29:01 +0300 Subject: [PATCH 02/55] add files_2 --- .../func_tests/main.cpp | 56 +++++++++---------- .../perf_tests/main.cpp | 2 +- .../src/ops_mpi.cpp | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b054c9ed57b..1d8d1643915 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -5,7 +5,7 @@ #include #include -#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { boost::mpi::communicator world; @@ -73,30 +73,30 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { } } -//TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { -// boost::mpi::communicator world; -// -// std::shared_ptr taskDataPar = std::make_shared(); -// -// const int max_waiting_chairs = 3; -// int global_res = -1; -// -// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); -// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); -// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); -// -// gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); -// -// if (world.rank() == 0) { -// ASSERT_TRUE(testMpiTaskParallel.validation()); -// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); -// ASSERT_TRUE(testMpiTaskParallel.run()); -// ASSERT_TRUE(testMpiTaskParallel.post_processing()); -// ASSERT_EQ(global_res, 0); -// } else { -// ASSERT_TRUE(testMpiTaskParallel.validation()); -// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); -// ASSERT_TRUE(testMpiTaskParallel.run()); -// ASSERT_TRUE(testMpiTaskParallel.post_processing()); -// } -//} +// TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { +// boost::mpi::communicator world; +// +// std::shared_ptr taskDataPar = std::make_shared(); +// +// const int max_waiting_chairs = 3; +// int global_res = -1; +// +// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); +// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); +// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); +// +// gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); +// +// if (world.rank() == 0) { +// ASSERT_TRUE(testMpiTaskParallel.validation()); +// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); +// ASSERT_TRUE(testMpiTaskParallel.run()); +// ASSERT_TRUE(testMpiTaskParallel.post_processing()); +// ASSERT_EQ(global_res, 0); +// } else { +// ASSERT_TRUE(testMpiTaskParallel.validation()); +// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); +// ASSERT_TRUE(testMpiTaskParallel.run()); +// ASSERT_TRUE(testMpiTaskParallel.post_processing()); +// } +// } diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp index 4ef43dcbeae..1ea5a1919a0 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp @@ -4,7 +4,7 @@ #include #include "core/perf/include/perf.hpp" -#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { boost::mpi::communicator world; diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index c201e6a2326..04b232009d2 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -1,4 +1,4 @@ -#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" #include #include From e43a9716543a1de7b7b7a8c9e78a3d673daf961a Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 2 Dec 2024 22:38:17 +0300 Subject: [PATCH 03/55] add files_3 --- .../gordeeva_sleeping_barber_test/func_tests/main.cpp | 10 +++++----- .../gordeeva_sleeping_barber_test/include/ops_mpi.hpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index 1d8d1643915..ec0220fd767 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -75,18 +75,18 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { // TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { // boost::mpi::communicator world; -// +// // std::shared_ptr taskDataPar = std::make_shared(); -// +// // const int max_waiting_chairs = 3; // int global_res = -1; -// +// // taskDataPar->inputs_count.emplace_back(max_waiting_chairs); // taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); // taskDataPar->outputs_count.emplace_back(sizeof(global_res)); -// +// // gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); -// +// // if (world.rank() == 0) { // ASSERT_TRUE(testMpiTaskParallel.validation()); // ASSERT_TRUE(testMpiTaskParallel.pre_processing()); diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp b/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp index e02d36d25ef..ba92cf0ad6f 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp @@ -25,7 +25,7 @@ class TestMPITaskParallel : public ppc::core::Task { bool post_processing() override; private: - size_t max_waiting_chairs; + int max_waiting_chairs; int result; boost::mpi::communicator world; From c49553cd531b3899195dfddb0ef8967bc3cd517f Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 4 Dec 2024 16:17:04 +0300 Subject: [PATCH 04/55] add_files_end --- .../func_tests/main.cpp | 75 +++++++++++-------- .../src/ops_mpi.cpp | 2 + 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index ec0220fd767..8230c951907 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -40,8 +40,13 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation3) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.rank() == 0) { - taskDataPar->inputs_count = {1}; - EXPECT_TRUE(testMpiTaskParallel.validation()); + if (world.size() < 3) { + taskDataPar->inputs_count = {1}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } else { + taskDataPar->inputs_count = {1}; + EXPECT_TRUE(testMpiTaskParallel.validation()); + } } } @@ -59,44 +64,48 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - if (world.rank() == 0) { + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - ASSERT_EQ(global_res, 0); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 3; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - } -} -// TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { -// boost::mpi::communicator world; -// -// std::shared_ptr taskDataPar = std::make_shared(); -// -// const int max_waiting_chairs = 3; -// int global_res = -1; -// -// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); -// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); -// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); -// -// gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); -// -// if (world.rank() == 0) { -// ASSERT_TRUE(testMpiTaskParallel.validation()); -// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); -// ASSERT_TRUE(testMpiTaskParallel.run()); -// ASSERT_TRUE(testMpiTaskParallel.post_processing()); -// ASSERT_EQ(global_res, 0); -// } else { -// ASSERT_TRUE(testMpiTaskParallel.validation()); -// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); -// ASSERT_TRUE(testMpiTaskParallel.run()); -// ASSERT_TRUE(testMpiTaskParallel.post_processing()); -// } -// } + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} \ No newline at end of file diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index 04b232009d2..f73330ac39e 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -42,6 +42,8 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { internal_order_test(); + std::cout << "start" << std::endl; + if (world.rank() == 0) { barber_logic(); } else if (world.rank() == 1) { From 939c863a9d545fcee30512b5c763356ea01c02b0 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 4 Dec 2024 17:08:36 +0300 Subject: [PATCH 05/55] add_files_end_1 --- .../func_tests/main.cpp | 10 +++++----- .../src/ops_mpi.cpp | 17 ----------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index 8230c951907..58edb87775b 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -73,11 +73,11 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { ASSERT_TRUE(testMpiTaskParallel.post_processing()); world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); } - } + } } TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { @@ -103,7 +103,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { ASSERT_TRUE(testMpiTaskParallel.post_processing()); world.barrier(); - + if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index f73330ac39e..63dfa0f3ca1 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -26,12 +26,10 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { if (world.rank() == 0) { if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { - std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; return false; } if (world.size() < 3) { - std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; return false; } } @@ -42,8 +40,6 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { internal_order_test(); - std::cout << "start" << std::endl; - if (world.rank() == 0) { barber_logic(); } else if (world.rank() == 1) { @@ -77,7 +73,6 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { if (client_id == -1) { result = 0; - std::cout << "[BARBER] All clients served. Stopping." << std::endl; return; } @@ -100,12 +95,8 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { if (static_cast(waiting_clients.size()) < max_waiting_chairs) { waiting_clients.push(client_id); world.send(client_id, 1, true); - std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; } else { world.send(client_id, 1, false); - std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; } } @@ -114,24 +105,20 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { waiting_clients.pop(); world.send(0, 0, next_client); barber_busy = true; - std::cout << "[DISPATCHER] Sent client " << next_client << " to barber." << std::endl; } if (world.iprobe(0, 4)) { int barber_signal; world.recv(0, 4, barber_signal); barber_busy = false; - std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; } if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { - std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; world.send(0, 0, -1); break; } if (world.iprobe(boost::mpi::any_source, 3)) { - std::cout << "LAST: " << remaining_clients << std::endl; int done_signal; world.recv(boost::mpi::any_source, 3, done_signal); remaining_clients--; @@ -150,17 +137,13 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { if (accepted) { world.recv(0, 2, client_id); world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; } else { world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { - std::cout << "[BARBER] Serving client " << client_id << std::endl; std::this_thread::sleep_for(20ms); world.send(client_id, 2, client_id); - std::cout << "[BARBER] Finished client " << client_id << std::endl; world.send(1, 4, client_id); } \ No newline at end of file From 5e60842ad65a80968954882560b0af324d550116 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 4 Dec 2024 17:11:56 +0300 Subject: [PATCH 06/55] add_files_end_2 --- tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index 58edb87775b..b265266b5f4 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -73,7 +73,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { ASSERT_TRUE(testMpiTaskParallel.post_processing()); world.barrier(); - + if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } @@ -103,9 +103,9 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { ASSERT_TRUE(testMpiTaskParallel.post_processing()); world.barrier(); - + if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); + ASSERT_EQ(global_res, 0); } } } \ No newline at end of file From 368810151e9c9702a3d9720a2ad08953e3f6e602 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 4 Dec 2024 17:15:27 +0300 Subject: [PATCH 07/55] add_file_enddd --- tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b265266b5f4..b22ca4b9965 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -75,7 +75,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { world.barrier(); if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); + ASSERT_EQ(global_res, 0); } } } @@ -105,7 +105,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { world.barrier(); if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); + ASSERT_EQ(global_res, 0); } } } \ No newline at end of file From 1bdfcf7ac60cefd3269537be425ebf66751fdbb6 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 4 Dec 2024 17:43:02 +0300 Subject: [PATCH 08/55] addd --- tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b22ca4b9965..bf52a6ab17b 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -66,6 +66,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { if (world.size() < 3) { ASSERT_FALSE(testMpiTaskParallel.validation()); + world.barrier(); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); @@ -96,6 +97,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { if (world.size() < 3) { ASSERT_FALSE(testMpiTaskParallel.validation()); + world.barrier(); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); From 63cf69360a528f5f73b76d586ccd479eb9494e24 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 08:15:29 +0300 Subject: [PATCH 09/55] addd_enddd --- tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp | 4 +--- tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index bf52a6ab17b..65d31f04110 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -66,14 +66,13 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { if (world.size() < 3) { ASSERT_FALSE(testMpiTaskParallel.validation()); - world.barrier(); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - world.barrier(); + world.barrier(); if (world.rank() == 0) { ASSERT_EQ(global_res, 0); @@ -97,7 +96,6 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { if (world.size() < 3) { ASSERT_FALSE(testMpiTaskParallel.validation()); - world.barrier(); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index 63dfa0f3ca1..607dee3d862 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -54,6 +54,8 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { internal_order_test(); + world.barrier(); + if (world.rank() == 0) { if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { *reinterpret_cast(taskData->outputs[0]) = result; From 9bdc80ac0f49cdc02216c4c79245861860603b67 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 08:36:21 +0300 Subject: [PATCH 10/55] addd_endddihope --- tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp | 4 +--- tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index 65d31f04110..ab0b2130cd4 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -71,8 +71,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); + if (world.rank() == 0) { ASSERT_EQ(global_res, 0); @@ -102,7 +101,6 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - world.barrier(); if (world.rank() == 0) { ASSERT_EQ(global_res, 0); diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index 607dee3d862..1faac1ecf8f 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -54,7 +54,7 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { internal_order_test(); - world.barrier(); +world.barrier(); if (world.rank() == 0) { if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { From df108ca8c356a35b2234f93ef040accc1f012534 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 08:55:12 +0300 Subject: [PATCH 11/55] addd_endddihope0 --- .../func_tests/main.cpp | 2 ++ .../gordeeva_sleeping_barber_test/src/ops_mpi.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index ab0b2130cd4..69b19a29745 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -72,6 +72,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); + world.barrier(); if (world.rank() == 0) { ASSERT_EQ(global_res, 0); @@ -101,6 +102,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); + world.barrier(); if (world.rank() == 0) { ASSERT_EQ(global_res, 0); diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index 1faac1ecf8f..731b1ee9f25 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -41,10 +41,13 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { internal_order_test(); if (world.rank() == 0) { + std::cout << "1" << std::endl; barber_logic(); } else if (world.rank() == 1) { + std::cout << "2" << std::endl; dispatcher_logic(); } else { + std::cout << "3" << std::endl; client_logic(); } @@ -53,8 +56,10 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { internal_order_test(); + + world.barrier(); + std::cout << "4" < std::endl; -world.barrier(); if (world.rank() == 0) { if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { @@ -74,6 +79,8 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { world.recv(1, 0, client_id); if (client_id == -1) { + std::cout << "br end" << std::endl; + result = 0; return; } @@ -121,6 +128,7 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { } if (world.iprobe(boost::mpi::any_source, 3)) { + std::cout << "d end" << std::endl; int done_signal; world.recv(boost::mpi::any_source, 3, done_signal); remaining_clients--; @@ -137,6 +145,8 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { world.recv(1, 1, accepted); if (accepted) { + std::cout << "cl" << std::endl; + world.recv(0, 2, client_id); world.send(1, 3, client_id); } else { From 6e0e6bef826c15d1e3eccaf746944942d9ccd4e9 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 09:05:44 +0300 Subject: [PATCH 12/55] 111 --- tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index 731b1ee9f25..d1e0094de2d 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -58,7 +58,7 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { internal_order_test(); world.barrier(); - std::cout << "4" < std::endl; + std::cout << "4" << std::endl; if (world.rank() == 0) { From 095e9864f2fd0f1af4d4054f0317d1e84a251626 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 09:24:15 +0300 Subject: [PATCH 13/55] 222 --- .../src/ops_mpi.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index d1e0094de2d..cca05b73d95 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -26,10 +26,12 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { if (world.rank() == 0) { if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { + std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; return false; } if (world.size() < 3) { + std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; return false; } } @@ -41,13 +43,10 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { internal_order_test(); if (world.rank() == 0) { - std::cout << "1" << std::endl; barber_logic(); } else if (world.rank() == 1) { - std::cout << "2" << std::endl; dispatcher_logic(); } else { - std::cout << "3" << std::endl; client_logic(); } @@ -56,10 +55,8 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { internal_order_test(); - - world.barrier(); - std::cout << "4" << std::endl; + world.barrier(); if (world.rank() == 0) { if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { @@ -79,8 +76,7 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { world.recv(1, 0, client_id); if (client_id == -1) { - std::cout << "br end" << std::endl; - + std::cout << "[BARBER] All clients served. Stopping." << std::endl; result = 0; return; } @@ -104,8 +100,12 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { if (static_cast(waiting_clients.size()) < max_waiting_chairs) { waiting_clients.push(client_id); world.send(client_id, 1, true); + std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; } else { world.send(client_id, 1, false); + std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; } } @@ -120,15 +120,17 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { int barber_signal; world.recv(0, 4, barber_signal); barber_busy = false; + std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; } if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { world.send(0, 0, -1); + std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; break; } if (world.iprobe(boost::mpi::any_source, 3)) { - std::cout << "d end" << std::endl; + std::cout << "LAST: " << remaining_clients << std::endl; int done_signal; world.recv(boost::mpi::any_source, 3, done_signal); remaining_clients--; @@ -145,17 +147,19 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { world.recv(1, 1, accepted); if (accepted) { - std::cout << "cl" << std::endl; - world.recv(0, 2, client_id); world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; } else { world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { + std::cout << "[BARBER] Serving client " << client_id << std::endl; std::this_thread::sleep_for(20ms); world.send(client_id, 2, client_id); + std::cout << "[BARBER] Finished client " << client_id << std::endl; world.send(1, 4, client_id); } \ No newline at end of file From 81634fb18ed5d9eb8a4c2b5378043d473db907a3 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 21:45:44 +0300 Subject: [PATCH 14/55] without_perf --- .../func_tests/main.cpp | 2 +- .../perf_tests/main.cpp | 168 +++++++++--------- 2 files changed, 85 insertions(+), 85 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index 69b19a29745..b22ca4b9965 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -71,7 +71,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - + world.barrier(); if (world.rank() == 0) { diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp index 1ea5a1919a0..7d84fd6e77c 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp @@ -1,84 +1,84 @@ -#include - -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" - -TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - bool barber_busy_ = false; - - std::vector global_res(1, 0); - int num_clients = 10; - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; // The number of clients to run - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - std::vector global_res(1, 0); - bool barber_busy_ = false; - - // Create TaskData - std::shared_ptr taskDataPar = std::make_shared(); - int num_clients = 10; - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} +//#include +// +//#include +//#include +// +//#include "core/perf/include/perf.hpp" +//#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" +// +//TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { +// boost::mpi::communicator world; +// const int max_waiting_chairs = 3; +// bool barber_busy_ = false; +// +// std::vector global_res(1, 0); +// int num_clients = 10; +// +// std::shared_ptr taskDataPar = std::make_shared(); +// +// if (world.rank() == 0) { +// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; +// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); +// taskDataPar->outputs_count.emplace_back(global_res.size()); +// } +// +// auto testMpiTaskParallel = std::make_shared(taskDataPar); +// ASSERT_EQ(testMpiTaskParallel->validation(), true); +// testMpiTaskParallel->pre_processing(); +// +// auto perfAttr = std::make_shared(); +// perfAttr->num_running = num_clients; // The number of clients to run +// const boost::mpi::timer current_timer; +// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; +// +// auto perfResults = std::make_shared(); +// +// testMpiTaskParallel->run(); +// testMpiTaskParallel->post_processing(); +// +// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); +// perfAnalyzer->pipeline_run(perfAttr, perfResults); +// +// if (world.rank() == 0) { +// ppc::core::Perf::print_perf_statistic(perfResults); +// ASSERT_EQ(1, global_res[0]); +// } +//} +// +//TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { +// boost::mpi::communicator world; +// const int max_waiting_chairs = 3; +// std::vector global_res(1, 0); +// bool barber_busy_ = false; +// +// // Create TaskData +// std::shared_ptr taskDataPar = std::make_shared(); +// int num_clients = 10; +// if (world.rank() == 0) { +// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; +// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); +// taskDataPar->outputs_count.emplace_back(global_res.size()); +// } +// +// auto testMpiTaskParallel = std::make_shared(taskDataPar); +// ASSERT_EQ(testMpiTaskParallel->validation(), true); +// testMpiTaskParallel->pre_processing(); +// +// auto perfAttr = std::make_shared(); +// perfAttr->num_running = num_clients; +// const boost::mpi::timer current_timer; +// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; +// +// auto perfResults = std::make_shared(); +// +// testMpiTaskParallel->run(); +// testMpiTaskParallel->post_processing(); +// +// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); +// perfAnalyzer->task_run(perfAttr, perfResults); +// +// if (world.rank() == 0) { +// ppc::core::Perf::print_perf_statistic(perfResults); +// ASSERT_EQ(1, global_res[0]); +// } +//} From abf5b131d1ec286fd8bb29f00a3003c9b1c8e9dd Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 22:13:33 +0300 Subject: [PATCH 15/55] 11 --- .../func_tests/main.cpp | 12 +- .../perf_tests/main.cpp | 168 +++++++++--------- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b22ca4b9965..b2b8e870825 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -65,18 +65,18 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); + EXPECT_FALSE(testMpiTaskParallel.validation()); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - world.barrier(); - if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } + world.barrier(); + } } @@ -95,17 +95,17 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); + EXPECT_FALSE(testMpiTaskParallel.validation()); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); - world.barrier(); - if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } + world.barrier(); + } } \ No newline at end of file diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp index 7d84fd6e77c..1ea5a1919a0 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp @@ -1,84 +1,84 @@ -//#include -// -//#include -//#include -// -//#include "core/perf/include/perf.hpp" -//#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" -// -//TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { -// boost::mpi::communicator world; -// const int max_waiting_chairs = 3; -// bool barber_busy_ = false; -// -// std::vector global_res(1, 0); -// int num_clients = 10; -// -// std::shared_ptr taskDataPar = std::make_shared(); -// -// if (world.rank() == 0) { -// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; -// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); -// taskDataPar->outputs_count.emplace_back(global_res.size()); -// } -// -// auto testMpiTaskParallel = std::make_shared(taskDataPar); -// ASSERT_EQ(testMpiTaskParallel->validation(), true); -// testMpiTaskParallel->pre_processing(); -// -// auto perfAttr = std::make_shared(); -// perfAttr->num_running = num_clients; // The number of clients to run -// const boost::mpi::timer current_timer; -// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; -// -// auto perfResults = std::make_shared(); -// -// testMpiTaskParallel->run(); -// testMpiTaskParallel->post_processing(); -// -// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); -// perfAnalyzer->pipeline_run(perfAttr, perfResults); -// -// if (world.rank() == 0) { -// ppc::core::Perf::print_perf_statistic(perfResults); -// ASSERT_EQ(1, global_res[0]); -// } -//} -// -//TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { -// boost::mpi::communicator world; -// const int max_waiting_chairs = 3; -// std::vector global_res(1, 0); -// bool barber_busy_ = false; -// -// // Create TaskData -// std::shared_ptr taskDataPar = std::make_shared(); -// int num_clients = 10; -// if (world.rank() == 0) { -// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; -// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); -// taskDataPar->outputs_count.emplace_back(global_res.size()); -// } -// -// auto testMpiTaskParallel = std::make_shared(taskDataPar); -// ASSERT_EQ(testMpiTaskParallel->validation(), true); -// testMpiTaskParallel->pre_processing(); -// -// auto perfAttr = std::make_shared(); -// perfAttr->num_running = num_clients; -// const boost::mpi::timer current_timer; -// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; -// -// auto perfResults = std::make_shared(); -// -// testMpiTaskParallel->run(); -// testMpiTaskParallel->post_processing(); -// -// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); -// perfAnalyzer->task_run(perfAttr, perfResults); -// -// if (world.rank() == 0) { -// ppc::core::Perf::print_perf_statistic(perfResults); -// ASSERT_EQ(1, global_res[0]); -// } -//} +#include + +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" + +TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + bool barber_busy_ = false; + + std::vector global_res(1, 0); + int num_clients = 10; + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; // The number of clients to run + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + std::vector global_res(1, 0); + bool barber_busy_ = false; + + // Create TaskData + std::shared_ptr taskDataPar = std::make_shared(); + int num_clients = 10; + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} From 467051e37cd8bb97718df858817bbfbdcf125ff3 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 22:30:27 +0300 Subject: [PATCH 16/55] endfinal --- .../func_tests/main.cpp | 12 ++++++------ .../gordeeva_sleeping_barber_test/src/ops_mpi.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b2b8e870825..b22ca4b9965 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -65,18 +65,18 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.size() < 3) { - EXPECT_FALSE(testMpiTaskParallel.validation()); + ASSERT_FALSE(testMpiTaskParallel.validation()); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); + world.barrier(); + if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } - world.barrier(); - } } @@ -95,17 +95,17 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.size() < 3) { - EXPECT_FALSE(testMpiTaskParallel.validation()); + ASSERT_FALSE(testMpiTaskParallel.validation()); } else { ASSERT_TRUE(testMpiTaskParallel.validation()); ASSERT_TRUE(testMpiTaskParallel.pre_processing()); ASSERT_TRUE(testMpiTaskParallel.run()); ASSERT_TRUE(testMpiTaskParallel.post_processing()); + world.barrier(); + if (world.rank() == 0) { ASSERT_EQ(global_res, 0); } - world.barrier(); - } } \ No newline at end of file diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp index cca05b73d95..8481fca5453 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp @@ -29,11 +29,10 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; return false; } - - if (world.size() < 3) { - std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; - return false; - } + } + if (world.size() < 3) { + std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; + return false; } return true; From 775ba7864cd3d4c15726f97f2024b3d5da1afe11 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 5 Dec 2024 23:33:22 +0300 Subject: [PATCH 17/55] wefwepfjw --- .../func_tests/main.cpp | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp index b22ca4b9965..d8241279910 100644 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp @@ -94,6 +94,96 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End3) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 996; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End4) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 999; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End5) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 1024; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + if (world.size() < 3) { ASSERT_FALSE(testMpiTaskParallel.validation()); } else { From 1cf8dbb1682fb6d0df752a4e04744277b782c509 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 00:00:20 +0300 Subject: [PATCH 18/55] result --- .../func_tests/main.cpp | 201 ++++++++++++++++++ .../include/ops_mpi.hpp | 38 ++++ .../perf_tests/main.cpp | 84 ++++++++ .../src/ops_mpi.cpp | 164 ++++++++++++++ 4 files changed, 487 insertions(+) create mode 100644 tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp create mode 100644 tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp create mode 100644 tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp create mode 100644 tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp new file mode 100644 index 00000000000..d8241279910 --- /dev/null +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -0,0 +1,201 @@ +#include + +#include +#include +#include +#include + +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {0}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation2) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + if (world.size() < 3) { + taskDataPar->inputs_count = {1}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation3) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + if (world.size() < 3) { + taskDataPar->inputs_count = {1}; + EXPECT_FALSE(testMpiTaskParallel.validation()); + } else { + taskDataPar->inputs_count = {1}; + EXPECT_TRUE(testMpiTaskParallel.validation()); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 1; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 3; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End3) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 996; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End4) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 999; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End5) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 1024; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} \ No newline at end of file diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp b/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp new file mode 100644 index 00000000000..ba92cf0ad6f --- /dev/null +++ b/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace gordeeva_t_sleeping_barber_mpi { + +class TestMPITaskParallel : public ppc::core::Task { + public: + explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + private: + int max_waiting_chairs; + int result; + boost::mpi::communicator world; + + void barber_logic(); + void dispatcher_logic(); + void client_logic(); + + void serve_next_client(int client_id); +}; +} // namespace gordeeva_t_sleeping_barber_mpi diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp new file mode 100644 index 00000000000..1ea5a1919a0 --- /dev/null +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -0,0 +1,84 @@ +#include + +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" + +TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + bool barber_busy_ = false; + + std::vector global_res(1, 0); + int num_clients = 10; + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; // The number of clients to run + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + std::vector global_res(1, 0); + bool barber_busy_ = false; + + // Create TaskData + std::shared_ptr taskDataPar = std::make_shared(); + int num_clients = 10; + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp new file mode 100644 index 00000000000..8481fca5453 --- /dev/null +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -0,0 +1,164 @@ +#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" + +#include +#include +#include +#include +#include +#include +#include + +using namespace std::chrono_literals; + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::pre_processing() { + internal_order_test(); + result = -1; + + if (world.rank() == 0) { + max_waiting_chairs = taskData->inputs_count[0]; + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { + internal_order_test(); + + if (world.rank() == 0) { + if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { + std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; + return false; + } + } + if (world.size() < 3) { + std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; + return false; + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { + internal_order_test(); + + if (world.rank() == 0) { + barber_logic(); + } else if (world.rank() == 1) { + dispatcher_logic(); + } else { + client_logic(); + } + + return true; +} + +bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { + internal_order_test(); + + world.barrier(); + + if (world.rank() == 0) { + if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { + *reinterpret_cast(taskData->outputs[0]) = result; + } else { + return false; + } + } + + return true; +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { + while (true) { + int client_id = -1; + + world.recv(1, 0, client_id); + + if (client_id == -1) { + std::cout << "[BARBER] All clients served. Stopping." << std::endl; + result = 0; + return; + } + + serve_next_client(client_id); + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { + std::queue waiting_clients; + max_waiting_chairs = taskData->inputs_count[0]; + int remaining_clients = world.size() - 2; + bool barber_busy = false; + + while (true) { + int client_id = -1; + + if (world.iprobe(boost::mpi::any_source, 0)) { + world.recv(boost::mpi::any_source, 0, client_id); + + if (static_cast(waiting_clients.size()) < max_waiting_chairs) { + waiting_clients.push(client_id); + world.send(client_id, 1, true); + std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + } else { + world.send(client_id, 1, false); + std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " + << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + } + } + + if (!barber_busy && !waiting_clients.empty()) { + int next_client = waiting_clients.front(); + waiting_clients.pop(); + world.send(0, 0, next_client); + barber_busy = true; + } + + if (world.iprobe(0, 4)) { + int barber_signal; + world.recv(0, 4, barber_signal); + barber_busy = false; + std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; + } + + if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { + world.send(0, 0, -1); + std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; + break; + } + + if (world.iprobe(boost::mpi::any_source, 3)) { + std::cout << "LAST: " << remaining_clients << std::endl; + int done_signal; + world.recv(boost::mpi::any_source, 3, done_signal); + remaining_clients--; + } + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { + int client_id = world.rank(); + bool accepted = false; + + world.send(1, 0, client_id); + + world.recv(1, 1, accepted); + + if (accepted) { + world.recv(0, 2, client_id); + world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; + } else { + world.send(1, 3, client_id); + std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; + } +} + +void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { + std::cout << "[BARBER] Serving client " << client_id << std::endl; + std::this_thread::sleep_for(20ms); + world.send(client_id, 2, client_id); + std::cout << "[BARBER] Finished client " << client_id << std::endl; + world.send(1, 4, client_id); +} \ No newline at end of file From 59388abd6d26d97d5e5f1de193d2f5aa8a7a09ef Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 00:16:58 +0300 Subject: [PATCH 19/55] res1 --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 2 +- tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp | 2 +- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index d8241279910..e8623706c3a 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -5,7 +5,7 @@ #include #include -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { boost::mpi::communicator world; diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 1ea5a1919a0..4ef43dcbeae 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -4,7 +4,7 @@ #include #include "core/perf/include/perf.hpp" -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { boost::mpi::communicator world; diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 8481fca5453..872165288e4 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -1,4 +1,4 @@ -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" +#include "mpi/gordeeva_t_sleeping_barbers/include/ops_mpi.hpp" #include #include From 892faded32e295a3c4284238bf37422f32924146 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 00:29:22 +0300 Subject: [PATCH 20/55] res_end --- .../func_tests/main.cpp | 201 ------------------ .../include/ops_mpi.hpp | 38 ---- .../perf_tests/main.cpp | 84 -------- .../src/ops_mpi.cpp | 164 -------------- 4 files changed, 487 deletions(-) delete mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp delete mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp delete mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp delete mode 100644 tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp deleted file mode 100644 index d8241279910..00000000000 --- a/tasks/mpi/gordeeva_sleeping_barber_test/func_tests/main.cpp +++ /dev/null @@ -1,201 +0,0 @@ -#include - -#include -#include -#include -#include - -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" - -TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count = {0}; - EXPECT_FALSE(testMpiTaskParallel.validation()); - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation2) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - if (world.size() < 3) { - taskDataPar->inputs_count = {1}; - EXPECT_FALSE(testMpiTaskParallel.validation()); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation3) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - if (world.size() < 3) { - taskDataPar->inputs_count = {1}; - EXPECT_FALSE(testMpiTaskParallel.validation()); - } else { - taskDataPar->inputs_count = {1}; - EXPECT_TRUE(testMpiTaskParallel.validation()); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 1; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 3; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End3) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 996; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End4) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 999; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End5) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 1024; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} \ No newline at end of file diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp b/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp deleted file mode 100644 index ba92cf0ad6f..00000000000 --- a/tasks/mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace gordeeva_t_sleeping_barber_mpi { - -class TestMPITaskParallel : public ppc::core::Task { - public: - explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - private: - int max_waiting_chairs; - int result; - boost::mpi::communicator world; - - void barber_logic(); - void dispatcher_logic(); - void client_logic(); - - void serve_next_client(int client_id); -}; -} // namespace gordeeva_t_sleeping_barber_mpi diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp deleted file mode 100644 index 1ea5a1919a0..00000000000 --- a/tasks/mpi/gordeeva_sleeping_barber_test/perf_tests/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include - -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" - -TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - bool barber_busy_ = false; - - std::vector global_res(1, 0); - int num_clients = 10; - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; // The number of clients to run - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - std::vector global_res(1, 0); - bool barber_busy_ = false; - - // Create TaskData - std::shared_ptr taskDataPar = std::make_shared(); - int num_clients = 10; - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} diff --git a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp b/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp deleted file mode 100644 index 8481fca5453..00000000000 --- a/tasks/mpi/gordeeva_sleeping_barber_test/src/ops_mpi.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include "mpi/gordeeva_sleeping_barber_test/include/ops_mpi.hpp" - -#include -#include -#include -#include -#include -#include -#include - -using namespace std::chrono_literals; - -bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::pre_processing() { - internal_order_test(); - result = -1; - - if (world.rank() == 0) { - max_waiting_chairs = taskData->inputs_count[0]; - } - - return true; -} - -bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { - internal_order_test(); - - if (world.rank() == 0) { - if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { - std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; - return false; - } - } - if (world.size() < 3) { - std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; - return false; - } - - return true; -} - -bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::run() { - internal_order_test(); - - if (world.rank() == 0) { - barber_logic(); - } else if (world.rank() == 1) { - dispatcher_logic(); - } else { - client_logic(); - } - - return true; -} - -bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { - internal_order_test(); - - world.barrier(); - - if (world.rank() == 0) { - if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { - *reinterpret_cast(taskData->outputs[0]) = result; - } else { - return false; - } - } - - return true; -} - -void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { - while (true) { - int client_id = -1; - - world.recv(1, 0, client_id); - - if (client_id == -1) { - std::cout << "[BARBER] All clients served. Stopping." << std::endl; - result = 0; - return; - } - - serve_next_client(client_id); - } -} - -void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { - std::queue waiting_clients; - max_waiting_chairs = taskData->inputs_count[0]; - int remaining_clients = world.size() - 2; - bool barber_busy = false; - - while (true) { - int client_id = -1; - - if (world.iprobe(boost::mpi::any_source, 0)) { - world.recv(boost::mpi::any_source, 0, client_id); - - if (static_cast(waiting_clients.size()) < max_waiting_chairs) { - waiting_clients.push(client_id); - world.send(client_id, 1, true); - std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; - } else { - world.send(client_id, 1, false); - std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; - } - } - - if (!barber_busy && !waiting_clients.empty()) { - int next_client = waiting_clients.front(); - waiting_clients.pop(); - world.send(0, 0, next_client); - barber_busy = true; - } - - if (world.iprobe(0, 4)) { - int barber_signal; - world.recv(0, 4, barber_signal); - barber_busy = false; - std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; - } - - if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { - world.send(0, 0, -1); - std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; - break; - } - - if (world.iprobe(boost::mpi::any_source, 3)) { - std::cout << "LAST: " << remaining_clients << std::endl; - int done_signal; - world.recv(boost::mpi::any_source, 3, done_signal); - remaining_clients--; - } - } -} - -void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { - int client_id = world.rank(); - bool accepted = false; - - world.send(1, 0, client_id); - - world.recv(1, 1, accepted); - - if (accepted) { - world.recv(0, 2, client_id); - world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; - } else { - world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; - } -} - -void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { - std::cout << "[BARBER] Serving client " << client_id << std::endl; - std::this_thread::sleep_for(20ms); - world.send(client_id, 2, client_id); - std::cout << "[BARBER] Finished client " << client_id << std::endl; - world.send(1, 4, client_id); -} \ No newline at end of file From c8195876e39215f03f950b41d06c2c8760004248 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 00:39:25 +0300 Subject: [PATCH 21/55] yrayra --- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 872165288e4..e8a8ad3b2d8 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -1,4 +1,4 @@ -#include "mpi/gordeeva_t_sleeping_barbers/include/ops_mpi.hpp" +#include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" #include #include From 20c5fe3e718feee5e56815cabe44dc3d3f3e82c5 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 11:31:33 +0300 Subject: [PATCH 22/55] reviewer_1 --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 1 - tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index e8623706c3a..3c207c0b9f7 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index e8a8ad3b2d8..4ebd91af268 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -1,12 +1,9 @@ #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" -#include #include #include -#include #include #include -#include using namespace std::chrono_literals; @@ -129,7 +126,6 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { } if (world.iprobe(boost::mpi::any_source, 3)) { - std::cout << "LAST: " << remaining_clients << std::endl; int done_signal; world.recv(boost::mpi::any_source, 3, done_signal); remaining_clients--; From 018aaf5f4967eeb0d50581749822400b8d43e2d4 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Fri, 6 Dec 2024 16:17:06 +0300 Subject: [PATCH 23/55] reviewer_2 --- tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp | 4 ++-- tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp b/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp index ba92cf0ad6f..dffb150d8fb 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp @@ -25,8 +25,8 @@ class TestMPITaskParallel : public ppc::core::Task { bool post_processing() override; private: - int max_waiting_chairs; - int result; + int max_waiting_chairs{}; + int result{}; boost::mpi::communicator world; void barber_logic(); diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 4ef43dcbeae..700d0c0e65d 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -27,7 +27,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { testMpiTaskParallel->pre_processing(); auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; // The number of clients to run + perfAttr->num_running = num_clients; const boost::mpi::timer current_timer; perfAttr->current_timer = [&] { return current_timer.elapsed(); }; @@ -51,7 +51,6 @@ TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { std::vector global_res(1, 0); bool barber_busy_ = false; - // Create TaskData std::shared_ptr taskDataPar = std::make_shared(); int num_clients = 10; if (world.rank() == 0) { From fad7e17563235ccd0ee9e95dfcc8dc91a9e013ca Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 9 Dec 2024 22:15:30 +0300 Subject: [PATCH 24/55] oh --- .../src/ops_mpi.cpp | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 4ebd91af268..12cc8bfefa0 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -23,12 +23,10 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::validation() { if (world.rank() == 0) { if (taskData->inputs_count.empty() || taskData->inputs_count[0] <= 0) { - std::cerr << "[VALIDATION] Invalid number of chairs: " << taskData->inputs_count[0] << std::endl; return false; } } if (world.size() < 3) { - std::cerr << "[VALIDATION] Not enough processes. Need at least 3." << std::endl; return false; } @@ -66,13 +64,13 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { + boost::mpi::request reqs; while (true) { int client_id = -1; - world.recv(1, 0, client_id); - + reqs = world.irecv(1, 0, client_id); + reqs.wait(); if (client_id == -1) { - std::cout << "[BARBER] All clients served. Stopping." << std::endl; result = 0; return; } @@ -82,6 +80,7 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { + //boost::mpi::request reqs; std::queue waiting_clients; max_waiting_chairs = taskData->inputs_count[0]; int remaining_clients = world.size() - 2; @@ -91,70 +90,78 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { int client_id = -1; if (world.iprobe(boost::mpi::any_source, 0)) { - world.recv(boost::mpi::any_source, 0, client_id); + world.irecv(boost::mpi::any_source, 0, client_id); + //reqs.wait(); if (static_cast(waiting_clients.size()) < max_waiting_chairs) { waiting_clients.push(client_id); - world.send(client_id, 1, true); - std::cout << "[DISPATCHER] Client " << client_id << " added to the queue. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + world.isend(client_id, 1, true); + //reqs.wait(); } else { - world.send(client_id, 1, false); - std::cout << "[DISPATCHER] Client " << client_id << " rejected. Queue is full. " - << "Queue size: " << waiting_clients.size() << "/" << max_waiting_chairs << std::endl; + world.isend(client_id, 1, false); + //reqs.wait(); } } if (!barber_busy && !waiting_clients.empty()) { int next_client = waiting_clients.front(); waiting_clients.pop(); - world.send(0, 0, next_client); + world.isend(0, 0, next_client); + //reqs.wait(); barber_busy = true; } if (world.iprobe(0, 4)) { int barber_signal; - world.recv(0, 4, barber_signal); + world.irecv(0, 4, barber_signal); + //reqs.wait(); barber_busy = false; - std::cout << "[DISPATCHER] Barber is now free after serving client " << barber_signal << "." << std::endl; } if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { - world.send(0, 0, -1); - std::cout << "[DISPATCHER] All clients served. Sending stop signal to barber." << std::endl; + world.isend(0, 0, -1); + //reqs.wait(); break; } if (world.iprobe(boost::mpi::any_source, 3)) { int done_signal; - world.recv(boost::mpi::any_source, 3, done_signal); + world.irecv(boost::mpi::any_source, 3, done_signal); + //reqs.wait(); remaining_clients--; } } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { + //boost::mpi::request reqs; int client_id = world.rank(); bool accepted = false; - world.send(1, 0, client_id); + world.isend(1, 0, client_id); + //reqs.wait(); - world.recv(1, 1, accepted); + world.irecv(1, 1, accepted); + //reqs.wait(); if (accepted) { - world.recv(0, 2, client_id); - world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Finished." << std::endl; + world.irecv(0, 2, client_id); + //reqs.wait(); + + world.isend(1, 3, client_id); + //reqs.wait(); } else { - world.send(1, 3, client_id); - std::cout << "[CLIENT " << client_id << "] Queue is full. Leaving." << std::endl; + world.isend(1, 3, client_id); + //reqs.wait(); } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { - std::cout << "[BARBER] Serving client " << client_id << std::endl; + //boost::mpi::request reqs; std::this_thread::sleep_for(20ms); - world.send(client_id, 2, client_id); - std::cout << "[BARBER] Finished client " << client_id << std::endl; - world.send(1, 4, client_id); + world.isend(client_id, 2, client_id); + //reqs.wait(); + + world.isend(1, 4, client_id); + //reqs.wait(); } \ No newline at end of file From fcb3e5005f8fccac29e44ed58529b76cf2c7caa0 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 9 Dec 2024 23:58:39 +0300 Subject: [PATCH 25/55] oh1 --- .../src/ops_mpi.cpp | 110 +++++++++++------- 1 file changed, 70 insertions(+), 40 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 12cc8bfefa0..5bc58d0b53d 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -52,25 +52,29 @@ bool gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::post_processing() { world.barrier(); - if (world.rank() == 0) { - if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { + if (!taskData->outputs.empty() && taskData->outputs_count[0] == sizeof(int)) { + if (world.rank() == 0) { *reinterpret_cast(taskData->outputs[0]) = result; } else { - return false; + *reinterpret_cast(taskData->outputs[0]) = 0; } + } else { + return false; } return true; } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { - boost::mpi::request reqs; while (true) { int client_id = -1; + { + boost::mpi::request req = world.irecv(1, 0, client_id); + req.wait(); + } - reqs = world.irecv(1, 0, client_id); - reqs.wait(); if (client_id == -1) { + // end result = 0; return; } @@ -80,7 +84,6 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { - //boost::mpi::request reqs; std::queue waiting_clients; max_waiting_chairs = taskData->inputs_count[0]; int remaining_clients = world.size() - 2; @@ -90,78 +93,105 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { int client_id = -1; if (world.iprobe(boost::mpi::any_source, 0)) { - world.irecv(boost::mpi::any_source, 0, client_id); - //reqs.wait(); + { + boost::mpi::request req = world.irecv(boost::mpi::any_source, 0, client_id); + req.wait(); + } if (static_cast(waiting_clients.size()) < max_waiting_chairs) { waiting_clients.push(client_id); - world.isend(client_id, 1, true); - //reqs.wait(); + { + boost::mpi::request req = world.isend(client_id, 1, true); + req.wait(); + } } else { - world.isend(client_id, 1, false); - //reqs.wait(); + { + boost::mpi::request req = world.isend(client_id, 1, false); + req.wait(); + } } } if (!barber_busy && !waiting_clients.empty()) { int next_client = waiting_clients.front(); waiting_clients.pop(); - world.isend(0, 0, next_client); - //reqs.wait(); + { + boost::mpi::request req = world.isend(0, 0, next_client); + req.wait(); + } barber_busy = true; } if (world.iprobe(0, 4)) { int barber_signal; - world.irecv(0, 4, barber_signal); - //reqs.wait(); + { + boost::mpi::request req = world.irecv(0, 4, barber_signal); + req.wait(); + } barber_busy = false; } if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { - world.isend(0, 0, -1); - //reqs.wait(); + { + boost::mpi::request req = world.isend(0, 0, -1); + req.wait(); + } break; } if (world.iprobe(boost::mpi::any_source, 3)) { int done_signal; - world.irecv(boost::mpi::any_source, 3, done_signal); - //reqs.wait(); + { + boost::mpi::request req = world.irecv(boost::mpi::any_source, 3, done_signal); + req.wait(); + } remaining_clients--; } } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { - //boost::mpi::request reqs; int client_id = world.rank(); bool accepted = false; - world.isend(1, 0, client_id); - //reqs.wait(); + { + boost::mpi::request req = world.isend(1, 0, client_id); + req.wait(); + } - world.irecv(1, 1, accepted); - //reqs.wait(); + { + boost::mpi::request req = world.irecv(1, 1, accepted); + req.wait(); + } if (accepted) { - world.irecv(0, 2, client_id); - //reqs.wait(); + { + boost::mpi::request req = world.irecv(0, 2, client_id); + req.wait(); + } - world.isend(1, 3, client_id); - //reqs.wait(); + { + boost::mpi::request req = world.isend(1, 3, client_id); + req.wait(); + } } else { - world.isend(1, 3, client_id); - //reqs.wait(); + { + boost::mpi::request req = world.isend(1, 3, client_id); + req.wait(); + } } } void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::serve_next_client(int client_id) { - //boost::mpi::request reqs; - std::this_thread::sleep_for(20ms); - world.isend(client_id, 2, client_id); - //reqs.wait(); - - world.isend(1, 4, client_id); - //reqs.wait(); -} \ No newline at end of file + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + + { + boost::mpi::request req = world.isend(client_id, 2, client_id); + req.wait(); + } + + { + boost::mpi::request req = world.isend(1, 4, client_id); + req.wait(); + } +} From 2a81fa37127a2489bb6e4b05ecb419cd674d77ae Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Tue, 10 Dec 2024 01:28:32 +0300 Subject: [PATCH 26/55] reviewers_3_and_4 --- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 5bc58d0b53d..9c4ec90ebe1 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -2,7 +2,6 @@ #include #include -#include #include using namespace std::chrono_literals; @@ -169,16 +168,10 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { boost::mpi::request req = world.irecv(0, 2, client_id); req.wait(); } - - { - boost::mpi::request req = world.isend(1, 3, client_id); - req.wait(); - } - } else { - { + } + { boost::mpi::request req = world.isend(1, 3, client_id); req.wait(); - } } } From 03f3516b1d36a68af969c7eeb71ac2fc84a1e005 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Tue, 10 Dec 2024 01:29:38 +0300 Subject: [PATCH 27/55] reviewers_3_and_4_end --- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 9c4ec90ebe1..9c0aa561300 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -73,7 +73,6 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::barber_logic() { } if (client_id == -1) { - // end result = 0; return; } From 0ff6e09ddd4febd64f3dafa19ca4408eeca7209b Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Tue, 10 Dec 2024 01:31:58 +0300 Subject: [PATCH 28/55] reviewers_3_and_4_end_1 --- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index 9c0aa561300..d06651ac601 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -169,8 +169,8 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::client_logic() { } } { - boost::mpi::request req = world.isend(1, 3, client_id); - req.wait(); + boost::mpi::request req = world.isend(1, 3, client_id); + req.wait(); } } From a42319058f4540f62935451b2da4584b597517aa Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 18 Dec 2024 21:59:59 +0300 Subject: [PATCH 29/55] 1 --- .../perf_tests/main.cpp | 156 +++++++++--------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 700d0c0e65d..1483341f669 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -5,79 +5,83 @@ #include "core/perf/include/perf.hpp" #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" - -TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - bool barber_busy_ = false; - - std::vector global_res(1, 0); - int num_clients = 10; - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} - -TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { - boost::mpi::communicator world; - const int max_waiting_chairs = 3; - std::vector global_res(1, 0); - bool barber_busy_ = false; - - std::shared_ptr taskDataPar = std::make_shared(); - int num_clients = 10; - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); - } -} +// +//TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { +// boost::mpi::communicator world; +// +// std::shared_ptr taskDataPar = std::make_shared(); +// +// const int max_waiting_chairs = 1; +// int global_res = -1; +// +// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); +// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); +// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); +// +// auto testMpiTaskParallel = std::make_shared(taskDataPar); +// +// if (world.size() < 3) { +// ASSERT_FALSE(testMpiTaskParallel.validation()); +// } else { +// ASSERT_TRUE(testMpiTaskParallel.validation()); +// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); +// +// auto perfAttr = std::make_shared(); +// perfAttr->num_running = num_clients; +// const boost::mpi::timer current_timer; +// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; +// +// auto perfResults = std::make_shared(); +// ASSERT_TRUE(testMpiTaskParallel.run()); +// ASSERT_TRUE(testMpiTaskParallel.post_processing()); +// +// world.barrier(); +// +// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); +// perfAnalyzer->pipeline_run(perfAttr, perfResults); +// +// if (world.rank() == 0) { +// ppc::core::Perf::print_perf_statistic(perfResults); +// ASSERT_EQ(1, global_res[0]); +// } +// } +//} +// +//TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { +// boost::mpi::communicator world; +// const int max_waiting_chairs = 3; +// std::vector global_res(1, 0); +// bool barber_busy_ = false; +// +// std::shared_ptr taskDataPar = std::make_shared(); +// int num_clients = 10; +// if (world.rank() == 0) { +// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; +// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); +// taskDataPar->outputs_count.emplace_back(global_res.size()); +// } +// +// auto testMpiTaskParallel = std::make_shared(taskDataPar); +// ASSERT_EQ(testMpiTaskParallel->validation(), true); +// testMpiTaskParallel->pre_processing(); +// +// auto perfAttr = std::make_shared(); +// perfAttr->num_running = num_clients; +// const boost::mpi::timer current_timer; +// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; +// +// auto perfResults = std::make_shared(); +// +// testMpiTaskParallel->run(); +// testMpiTaskParallel->post_processing(); +// world.barrier(); +// +// +// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); +// perfAnalyzer->task_run(perfAttr, perfResults); +// +// if (world.rank() == 0) { +// ppc::core::Perf::print_perf_statistic(perfResults); +// ASSERT_EQ(1, global_res[0]); +// } +//} From 5c499cc064e1c18ff82441430280425cacef66b8 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Mon, 23 Dec 2024 21:03:53 +0300 Subject: [PATCH 30/55] 1 --- .../perf_tests/main.cpp | 160 +++++++++--------- .../perf_tests/main.cpp | 4 +- .../src/ops_mpi.cpp | 2 +- .../src/ops_seq.cpp | 12 +- 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 1483341f669..1a81faeaeca 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -5,83 +5,83 @@ #include "core/perf/include/perf.hpp" #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" -// -//TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { -// boost::mpi::communicator world; -// -// std::shared_ptr taskDataPar = std::make_shared(); -// -// const int max_waiting_chairs = 1; -// int global_res = -1; -// -// taskDataPar->inputs_count.emplace_back(max_waiting_chairs); -// taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); -// taskDataPar->outputs_count.emplace_back(sizeof(global_res)); -// -// auto testMpiTaskParallel = std::make_shared(taskDataPar); -// -// if (world.size() < 3) { -// ASSERT_FALSE(testMpiTaskParallel.validation()); -// } else { -// ASSERT_TRUE(testMpiTaskParallel.validation()); -// ASSERT_TRUE(testMpiTaskParallel.pre_processing()); -// -// auto perfAttr = std::make_shared(); -// perfAttr->num_running = num_clients; -// const boost::mpi::timer current_timer; -// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; -// -// auto perfResults = std::make_shared(); -// ASSERT_TRUE(testMpiTaskParallel.run()); -// ASSERT_TRUE(testMpiTaskParallel.post_processing()); -// -// world.barrier(); -// -// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); -// perfAnalyzer->pipeline_run(perfAttr, perfResults); -// -// if (world.rank() == 0) { -// ppc::core::Perf::print_perf_statistic(perfResults); -// ASSERT_EQ(1, global_res[0]); -// } -// } -//} -// -//TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { -// boost::mpi::communicator world; -// const int max_waiting_chairs = 3; -// std::vector global_res(1, 0); -// bool barber_busy_ = false; -// -// std::shared_ptr taskDataPar = std::make_shared(); -// int num_clients = 10; -// if (world.rank() == 0) { -// taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; -// taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); -// taskDataPar->outputs_count.emplace_back(global_res.size()); -// } -// -// auto testMpiTaskParallel = std::make_shared(taskDataPar); -// ASSERT_EQ(testMpiTaskParallel->validation(), true); -// testMpiTaskParallel->pre_processing(); -// -// auto perfAttr = std::make_shared(); -// perfAttr->num_running = num_clients; -// const boost::mpi::timer current_timer; -// perfAttr->current_timer = [&] { return current_timer.elapsed(); }; -// -// auto perfResults = std::make_shared(); -// -// testMpiTaskParallel->run(); -// testMpiTaskParallel->post_processing(); -// world.barrier(); -// -// -// auto perfAnalyzer = std::make_shared(testMpiTaskParallel); -// perfAnalyzer->task_run(perfAttr, perfResults); -// -// if (world.rank() == 0) { -// ppc::core::Perf::print_perf_statistic(perfResults); -// ASSERT_EQ(1, global_res[0]); -// } -//} + +TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + + const int max_waiting_chairs = 1; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { + boost::mpi::communicator world; + const int max_waiting_chairs = 3; + std::vector global_res(1, 0); + bool barber_busy_ = false; + + std::shared_ptr taskDataPar = std::make_shared(); + int num_clients = 10; + if (world.rank() == 0) { + taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); + taskDataPar->outputs_count.emplace_back(global_res.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + + auto perfAttr = std::make_shared(); + perfAttr->num_running = num_clients; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + auto perfResults = std::make_shared(); + + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + world.barrier(); + + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + ASSERT_EQ(1, global_res[0]); + } +} diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp index 462eb21ea28..87d314b3929 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -49,8 +49,8 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { std::vector> global_matr; std::vector max_s; std::shared_ptr taskDataPar = std::make_shared(); - int rows = 7000; - int cols = 7000; + int rows = 700; + int cols = 700; if (world.rank() == 0) { global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp index 01d16fa9689..3691d599d9a 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp @@ -70,7 +70,7 @@ std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITas std::vector> matr(rows, std::vector(cols)); for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -500, 500); + matr[i] = rand_vec(cols, 0, 200); } for (int j = 0; j < cols; ++j) { int row_rand = std::rand() % rows; diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp index 6a4b610fb02..8b769fed22b 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -1,3 +1,4 @@ + #include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" #include @@ -25,11 +26,10 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::pre_processing( bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::validation() { internal_order_test(); - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + if ((taskData->inputs.empty() || taskData->outputs.empty()) || + (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) || (taskData->outputs_count.size() != 1) || + (taskData->inputs_count.size() < 2) || (taskData->outputs_count[0] != taskData->inputs_count[1])) + return false; return true; } @@ -68,7 +68,7 @@ std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSe std::vector> matr(rows, std::vector(cols)); for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -500, 500); + matr[i] = rand_vec(cols, 0, 200); } for (int j = 0; j < cols; ++j) { int row_rand = std::rand() % rows; From 52c1ff4842da992927dce4b4b77441cc97fea43c Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Tue, 24 Dec 2024 10:34:48 +0300 Subject: [PATCH 31/55] 1 --- .../perf_tests/main.cpp | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 1a81faeaeca..23f64168927 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -1,87 +1,105 @@ #include +#include +#include #include #include #include "core/perf/include/perf.hpp" #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" +// Òåñò äëÿ pipeline_run TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { boost::mpi::communicator world; - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 1; + const int max_waiting_chairs = 3; int global_res = -1; + std::shared_ptr taskDataPar = std::make_shared(); + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); taskDataPar->outputs_count.emplace_back(sizeof(global_res)); auto testMpiTaskParallel = std::make_shared(taskDataPar); if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); + ASSERT_EQ(testMpiTaskParallel->validation(), false); } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_EQ(testMpiTaskParallel->validation(), true); + ASSERT_TRUE(testMpiTaskParallel->pre_processing()); auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; + perfAttr->num_running = world.size() - 2; // ×èñëî êëèåíòîâ const boost::mpi::timer current_timer; perfAttr->current_timer = [&] { return current_timer.elapsed(); }; auto perfResults = std::make_shared(); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); + ASSERT_TRUE(testMpiTaskParallel->run()); + ASSERT_TRUE(testMpiTaskParallel->post_processing()); - world.barrier(); + world.barrier(); // Ñèíõðîíèçàöèÿ ïðîöåññîâ auto perfAnalyzer = std::make_shared(testMpiTaskParallel); perfAnalyzer->pipeline_run(perfAttr, perfResults); if (world.rank() == 0) { ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); + ASSERT_EQ(global_res, 0); // Îæèäàåìûé ðåçóëüòàò } } } -TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { +// Òåñò äëÿ task_run ñ íåñêîëüêèìè êëèåíòàìè +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run_with_multiple_clients) { boost::mpi::communicator world; - const int max_waiting_chairs = 3; - std::vector global_res(1, 0); - bool barber_busy_ = false; + const int max_waiting_chairs = 3; // Êîëè÷åñòâî ìåñò äëÿ îæèäàíèÿ êëèåíòîâ + int global_res = -1; // Ïåðåìåííàÿ äëÿ õðàíåíèÿ ðåçóëüòàòà + + // Ïîäãîòîâêà äàííûõ çàäà÷è std::shared_ptr taskDataPar = std::make_shared(); - int num_clients = 10; - if (world.rank() == 0) { - taskDataPar->inputs_count = {max_waiting_chairs, static_cast(barber_busy_)}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_res.data())); - taskDataPar->outputs_count.emplace_back(global_res.size()); - } + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); // Êîëè÷åñòâî ìåñò äëÿ îæèäàíèÿ + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); // Óêàçàòåëü íà ðåçóëüòàò + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); // Ðàçìåð ðåçóëüòàòà + + // Ñîçäàíèå îáúåêòà çàäà÷è auto testMpiTaskParallel = std::make_shared(taskDataPar); - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - auto perfAttr = std::make_shared(); - perfAttr->num_running = num_clients; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + // Ïðîâåðêà âàëèäíîñòè çàäà÷è, åñëè íåäîñòàòî÷íî ïðîöåññîâ + if (world.size() < 3) { + ASSERT_EQ(testMpiTaskParallel->validation(), false); // Åñëè ïðîöåññîâ ìåíüøå 3, òåñò íå ïðîéäåò + } else { + ASSERT_EQ(testMpiTaskParallel->validation(), true); // Åñëè âñå â ïîðÿäêå, ïðîäîëæàåì + ASSERT_TRUE(testMpiTaskParallel->pre_processing()); // Âûïîëíåíèå ïðåäâàðèòåëüíîé îáðàáîòêè - auto perfResults = std::make_shared(); + // Íàñòðîéêà àòðèáóòîâ ïðîèçâîäèòåëüíîñòè äëÿ îòñëåæèâàíèÿ + auto perfAttr = std::make_shared(); + perfAttr->num_running = world.size() - 2; // ×èñëî êëèåíòîâ (çà âû÷åòîì áàðáåðà è äèñïåò÷åðà) + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - world.barrier(); + auto perfResults = std::make_shared(); + // Çàïóñê çàäà÷è + ASSERT_TRUE(testMpiTaskParallel->run()); // Çàïóñê çàäà÷è + ASSERT_TRUE(testMpiTaskParallel->post_processing()); // Îáðàáîòêà ïîñëå âûïîëíåíèÿ - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); + // Ñèíõðîíèçàöèÿ âñåõ ïðîöåññîâ + world.barrier(); - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(1, global_res[0]); + // Àíàëèç ïðîèçâîäèòåëüíîñòè + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); // Âàæíûé ìîìåíò: çàìåíåí `pipeline_run` íà `task_run` + + // Ïðîâåðêà ðåçóëüòàòà âûïîëíåíèÿ òîëüêî íà ãëàâíîì ïðîöåññå (rank 0) + if (world.rank() == 0) { + // Îæèäàåì, ÷òî ðåçóëüòàò âûïîëíåíèÿ çàäà÷è áóäåò 0 + ASSERT_EQ(global_res, 0); // Ðåçóëüòàò äîëæåí áûòü 0 ïîñëå âûïîëíåíèÿ çàäà÷è + + // Îïöèîíàëüíî, âûâîä ñòàòèñòèêè ïðîèçâîäèòåëüíîñòè + ppc::core::Perf::print_perf_statistic(perfResults); + } } } From 04661169e3f5998769ec8787ec7d96bafe985992 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 25 Dec 2024 13:00:45 +0300 Subject: [PATCH 32/55] revert2 --- tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp index d06651ac601..067ac1c6a76 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/src/ops_mpi.cpp @@ -129,7 +129,7 @@ void gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel::dispatcher_logic() { barber_busy = false; } - if (waiting_clients.empty() && remaining_clients == 0 && !barber_busy) { + if (waiting_clients.empty() && remaining_clients == 0) { { boost::mpi::request req = world.isend(0, 0, -1); req.wait(); From 7bbfcfc3794cd0c5f979bff9a14c631bc995302a Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 25 Dec 2024 13:04:22 +0300 Subject: [PATCH 33/55] revert_2 --- .../perf_tests/main.cpp | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp index 23f64168927..276f90486b2 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/perf_tests/main.cpp @@ -8,7 +8,6 @@ #include "core/perf/include/perf.hpp" #include "mpi/gordeeva_t_sleeping_barber/include/ops_mpi.hpp" -// Òåñò äëÿ pipeline_run TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { boost::mpi::communicator world; @@ -30,7 +29,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { ASSERT_TRUE(testMpiTaskParallel->pre_processing()); auto perfAttr = std::make_shared(); - perfAttr->num_running = world.size() - 2; // ×èñëî êëèåíòîâ + perfAttr->num_running = world.size() - 2; const boost::mpi::timer current_timer; perfAttr->current_timer = [&] { return current_timer.elapsed(); }; @@ -38,67 +37,56 @@ TEST(gordeeva_t_sleeping_barber_mpi, test_pipeline_run) { ASSERT_TRUE(testMpiTaskParallel->run()); ASSERT_TRUE(testMpiTaskParallel->post_processing()); - world.barrier(); // Ñèíõðîíèçàöèÿ ïðîöåññîâ + world.barrier(); auto perfAnalyzer = std::make_shared(testMpiTaskParallel); perfAnalyzer->pipeline_run(perfAttr, perfResults); if (world.rank() == 0) { ppc::core::Perf::print_perf_statistic(perfResults); - ASSERT_EQ(global_res, 0); // Îæèäàåìûé ðåçóëüòàò + ASSERT_EQ(global_res, 0); } } } -// Òåñò äëÿ task_run ñ íåñêîëüêèìè êëèåíòàìè -TEST(gordeeva_t_sleeping_barber_mpi, test_task_run_with_multiple_clients) { +TEST(gordeeva_t_sleeping_barber_mpi, test_task_run) { boost::mpi::communicator world; - const int max_waiting_chairs = 3; // Êîëè÷åñòâî ìåñò äëÿ îæèäàíèÿ êëèåíòîâ - int global_res = -1; // Ïåðåìåííàÿ äëÿ õðàíåíèÿ ðåçóëüòàòà + const int max_waiting_chairs = 3; + int global_res = -1; - // Ïîäãîòîâêà äàííûõ çàäà÷è std::shared_ptr taskDataPar = std::make_shared(); - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); // Êîëè÷åñòâî ìåñò äëÿ îæèäàíèÿ - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); // Óêàçàòåëü íà ðåçóëüòàò - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); // Ðàçìåð ðåçóëüòàòà + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - // Ñîçäàíèå îáúåêòà çàäà÷è auto testMpiTaskParallel = std::make_shared(taskDataPar); - // Ïðîâåðêà âàëèäíîñòè çàäà÷è, åñëè íåäîñòàòî÷íî ïðîöåññîâ if (world.size() < 3) { - ASSERT_EQ(testMpiTaskParallel->validation(), false); // Åñëè ïðîöåññîâ ìåíüøå 3, òåñò íå ïðîéäåò + ASSERT_EQ(testMpiTaskParallel->validation(), false); } else { - ASSERT_EQ(testMpiTaskParallel->validation(), true); // Åñëè âñå â ïîðÿäêå, ïðîäîëæàåì - ASSERT_TRUE(testMpiTaskParallel->pre_processing()); // Âûïîëíåíèå ïðåäâàðèòåëüíîé îáðàáîòêè + ASSERT_EQ(testMpiTaskParallel->validation(), true); + ASSERT_TRUE(testMpiTaskParallel->pre_processing()); - // Íàñòðîéêà àòðèáóòîâ ïðîèçâîäèòåëüíîñòè äëÿ îòñëåæèâàíèÿ auto perfAttr = std::make_shared(); - perfAttr->num_running = world.size() - 2; // ×èñëî êëèåíòîâ (çà âû÷åòîì áàðáåðà è äèñïåò÷åðà) + perfAttr->num_running = world.size() - 2; const boost::mpi::timer current_timer; perfAttr->current_timer = [&] { return current_timer.elapsed(); }; auto perfResults = std::make_shared(); - // Çàïóñê çàäà÷è - ASSERT_TRUE(testMpiTaskParallel->run()); // Çàïóñê çàäà÷è - ASSERT_TRUE(testMpiTaskParallel->post_processing()); // Îáðàáîòêà ïîñëå âûïîëíåíèÿ + ASSERT_TRUE(testMpiTaskParallel->run()); + ASSERT_TRUE(testMpiTaskParallel->post_processing()); - // Ñèíõðîíèçàöèÿ âñåõ ïðîöåññîâ world.barrier(); - // Àíàëèç ïðîèçâîäèòåëüíîñòè auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); // Âàæíûé ìîìåíò: çàìåíåí `pipeline_run` íà `task_run` + perfAnalyzer->task_run(perfAttr, perfResults); - // Ïðîâåðêà ðåçóëüòàòà âûïîëíåíèÿ òîëüêî íà ãëàâíîì ïðîöåññå (rank 0) if (world.rank() == 0) { - // Îæèäàåì, ÷òî ðåçóëüòàò âûïîëíåíèÿ çàäà÷è áóäåò 0 - ASSERT_EQ(global_res, 0); // Ðåçóëüòàò äîëæåí áûòü 0 ïîñëå âûïîëíåíèÿ çàäà÷è + ASSERT_EQ(global_res, 0); - // Îïöèîíàëüíî, âûâîä ñòàòèñòèêè ïðîèçâîäèòåëüíîñòè ppc::core::Perf::print_perf_statistic(perfResults); } } From 72f4c7c7d34cb5dffaa1a1263175a68c482e6bfe Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Wed, 25 Dec 2024 13:44:14 +0300 Subject: [PATCH 34/55] without lab_1 --- .../func_tests/main.cpp | 210 ------------------ .../include/ops_mpi.hpp | 46 ---- .../perf_tests/main.cpp | 81 ------- .../src/ops_mpi.cpp | 188 ---------------- .../func_tests/main.cpp | 149 ------------- .../include/ops_seq.hpp | 25 --- .../perf_tests/main.cpp | 79 ------- .../src/ops_seq.cpp | 80 ------- 8 files changed, 858 deletions(-) delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp deleted file mode 100644 index cd5ec3ec2d7..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include - -#include -#include -#include - -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(5); - taskDataPar->inputs_count.push_back(5); - taskDataPar->inputs.push_back(reinterpret_cast(new int[25])); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 500; - const int cols = 500; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - ASSERT_EQ(global_max, max_example); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 500; - const int cols = 1000; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - for (int i = 0; i < cols; i++) { - ASSERT_EQ(global_max[i], max_example[i]); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 1000; - const int cols = 3000; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - for (int i = 0; i < cols; i++) { - ASSERT_EQ(global_max[i], max_example[i]); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(2); - taskDataPar->inputs_count.push_back(3); - taskDataPar->inputs.push_back(reinterpret_cast(new int[6])); - taskDataPar->outputs_count.push_back(2); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(10); - taskDataPar->inputs_count.push_back(15); - taskDataPar->inputs.push_back(reinterpret_cast(new int[150])); - taskDataPar->outputs_count.push_back(2); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} \ No newline at end of file diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp deleted file mode 100644 index 702922761ca..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace gordeva_t_max_val_of_column_matrix_mpi { - -class TestMPITaskSequential : public ppc::core::Task { - public: - explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - static std::vector rand_vec(int s, int down = -100, int upp = 100); - static std::vector> rand_matr(int rows, int cols); - - private: - std::vector> input_; - std::vector res; -}; - -class TestMPITaskParallel : public ppc::core::Task { - public: - explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - private: - std::vector> input_, local_input_; - std::vector res; - boost::mpi::communicator world; -}; - -} // namespace gordeva_t_max_val_of_column_matrix_mpi diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp deleted file mode 100644 index 87d314b3929..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include - -#include -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { - boost::mpi::communicator world; - std::vector> global_matr; - std::vector max_s; - - std::shared_ptr taskDataPar = std::make_shared(); - int rows = 5000; - int cols = 5000; - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } - taskDataPar->inputs_count.emplace_back(rows); - taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); - } - - auto testMpiTaskParallel = - std::make_shared(taskDataPar); - - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { - boost::mpi::communicator world; - - std::vector> global_matr; - std::vector max_s; - std::shared_ptr taskDataPar = std::make_shared(); - int rows = 700; - int cols = 700; - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } - - taskDataPar->inputs_count.emplace_back(rows); - taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); - } - } -} diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp deleted file mode 100644 index 3691d599d9a..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -#include -#include -#include -#include -#include -#include - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::pre_processing() { - internal_order_test(); - - int rows = taskData->inputs_count[0]; - int cols = taskData->inputs_count[1]; - - input_.resize(rows, std::vector(cols)); - - for (int i = 0; i < rows; i++) { - int* input_matr = reinterpret_cast(taskData->inputs[i]); - for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; - } - - res.resize(cols); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::validation() { - internal_order_test(); - - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::run() { - internal_order_test(); - for (size_t i = 0; i < input_[0].size(); i++) { - int max_el = input_[0][i]; - for (size_t j = 1; j < input_.size(); j++) - if (input_[j][i] > max_el) max_el = input_[j][i]; - - res[i] = max_el; - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::post_processing() { - internal_order_test(); - - int* output_matr = reinterpret_cast(taskData->outputs[0]); - - std::copy(res.begin(), res.end(), output_matr); - return true; -} - -std::vector gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_vec(int s, int down, int upp) { - std::vector v(s); - for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, 0, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::pre_processing() { - internal_order_test(); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::validation() { - internal_order_test(); - - if (world.rank() == 0) { - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; - } - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::run() { - internal_order_test(); - - size_t delta = 0; - size_t delta_1 = 0; - size_t local_cols = 0; - - if (world.rank() == 0) { - size_t rows = taskData->inputs_count[0]; - size_t cols = taskData->inputs_count[1]; - - delta = rows / world.size(); - delta_1 = rows % world.size(); - - boost::mpi::broadcast(world, delta, 0); - boost::mpi::broadcast(world, delta_1, 0); - - input_.resize(rows, std::vector(cols)); - for (size_t i = 0; i < rows; i++) { - int* input_matr = reinterpret_cast(taskData->inputs[i]); - input_[i].assign(input_matr, input_matr + cols); - } - - for (int proc = 1; proc < world.size(); ++proc) { - size_t start_row = (proc * delta) + std::min(static_cast(proc), delta_1); - size_t rows_to_send = delta + ((static_cast(proc) < delta_1) ? 1 : 0); - - world.send(proc, 0, cols); - - for (size_t i = 0; i < rows_to_send; ++i) { - world.send(proc, 0, input_[start_row + i]); - } - } - - size_t local_input_rows = delta + ((static_cast(world.rank()) < delta_1) ? 1 : 0); - local_cols = cols; - local_input_.assign(input_.begin(), std::next(input_.begin(), static_cast(local_input_rows))); - } else { - boost::mpi::broadcast(world, delta, 0); - boost::mpi::broadcast(world, delta_1, 0); - - size_t local_input_rows = delta + (static_cast(world.rank()) < delta_1 ? 1 : 0); - - world.recv(0, 0, local_cols); - - local_input_.resize(local_input_rows, std::vector(local_cols)); - for (size_t i = 0; i < local_input_rows; ++i) { - world.recv(0, 0, local_input_[i]); - } - } - - res.resize(local_cols); - std::vector tmp_max(local_cols, INT_MIN); - - for (size_t i = 0; i < local_cols; ++i) { - for (size_t j = 0; j < local_input_.size(); ++j) { - tmp_max[i] = std::max(tmp_max[i], local_input_[j][i]); - } - } - - if (world.rank() == 0) { - std::vector max_s(local_cols, INT_MIN); - std::copy(tmp_max.begin(), tmp_max.end(), max_s.begin()); - - for (int proc = 1; proc < world.size(); ++proc) { - std::vector proc_max(local_cols); - world.recv(proc, 0, proc_max); - - for (size_t i = 0; i < local_cols; ++i) { - max_s[i] = std::max(max_s[i], proc_max[i]); - } - } - res = max_s; - } else { - world.send(0, 0, tmp_max); - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::post_processing() { - internal_order_test(); - - if (world.rank() == 0) { - std::copy(res.begin(), res.end(), reinterpret_cast(taskData->outputs[0])); - } - return true; -} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp deleted file mode 100644 index 0b149b9d14e..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include - -#include -#include - -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - ASSERT_FALSE(testTaskSequential.validation()); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyOutput) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(5); - taskDataSeq->inputs_count.push_back(5); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[25])); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) { - const int rows = 500; - const int cols = 500; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_random) { - const int rows = 500; - const int cols = 1000; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_random) { - const int rows = 1000; - const int cols = 3000; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(10); - taskDataSeq->inputs_count.push_back(0); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[10])); - taskDataSeq->outputs_count.push_back(1); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(10); - taskDataSeq->inputs_count.push_back(15); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[150])); - taskDataSeq->outputs_count.push_back(10); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp deleted file mode 100644 index 577b7194572..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "core/task/include/task.hpp" - -namespace gordeva_t_max_val_of_column_matrix_seq { - -class TestTaskSequential : public ppc::core::Task { - public: - explicit TestTaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - static std::vector rand_vec(int size, int down = -100, int upp = 100); - static std::vector> rand_matr(int rows, int cols); - - private: - std::vector> input_; - std::vector res_; -}; - -} // namespace gordeva_t_max_val_of_column_matrix_seq diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp deleted file mode 100644 index 2ee62e9c724..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include - -#include - -#include "core/perf/include/perf.hpp" -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { - const int cols = 5000; - const int rows = 5000; - - std::shared_ptr taskDataSeq = std::make_shared(); - - auto testTaskSequential = std::make_shared(taskDataSeq); - - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - std::vector res_vec(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); - taskDataSeq->outputs_count.emplace_back(res_vec.size()); - - 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; - }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - - for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { - const int cols = 7000; - const int rows = 7000; - - std::shared_ptr taskDataSeq = std::make_shared(); - - auto testTaskSequential = std::make_shared(taskDataSeq); - - std::vector> matr_rand = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); - - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res_vec(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); - taskDataSeq->outputs_count.emplace_back(res_vec.size()); - - 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; - }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->task_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); -} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp deleted file mode 100644 index 8b769fed22b..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -#include - -namespace gordeva_t_max_val_of_column_matrix_seq { - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::pre_processing() { - internal_order_test(); - - int rows = taskData->inputs_count[0]; - int cols = taskData->inputs_count[1]; - int* input_matr; - input_.resize(rows, std::vector(cols)); - - for (int i = 0; i < rows; i++) { - input_matr = reinterpret_cast(taskData->inputs[i]); - for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; - } - - res_.resize(cols); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::validation() { - internal_order_test(); - - if ((taskData->inputs.empty() || taskData->outputs.empty()) || - (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) || (taskData->outputs_count.size() != 1) || - (taskData->inputs_count.size() < 2) || (taskData->outputs_count[0] != taskData->inputs_count[1])) - return false; - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::run() { - internal_order_test(); - - for (size_t i = 0; i < input_[0].size(); i++) { - int max_el = input_[0][i]; - for (size_t j = 1; j < input_.size(); j++) - if (input_[j][i] > max_el) max_el = input_[j][i]; - - res_[i] = max_el; - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing() { - internal_order_test(); - - int* output_matr = reinterpret_cast(taskData->outputs[0]); - - std::copy(res_.begin(), res_.end(), output_matr); - return true; -} - -std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { - std::vector v(size); - for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, 0, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -} // namespace gordeva_t_max_val_of_column_matrix_seq From aed037a4ff9e494502e895a6655ae9921b79330b Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Thu, 26 Dec 2024 18:28:37 +0300 Subject: [PATCH 35/55] 2 --- .../func_tests/main.cpp | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index 3c207c0b9f7..439c0c77f13 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -168,33 +168,3 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End4) { } } } - -TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End5) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - - const int max_waiting_chairs = 1024; - int global_res = -1; - - taskDataPar->inputs_count.emplace_back(max_waiting_chairs); - taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); - taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.size() < 3) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } else { - ASSERT_TRUE(testMpiTaskParallel.validation()); - ASSERT_TRUE(testMpiTaskParallel.pre_processing()); - ASSERT_TRUE(testMpiTaskParallel.run()); - ASSERT_TRUE(testMpiTaskParallel.post_processing()); - - world.barrier(); - - if (world.rank() == 0) { - ASSERT_EQ(global_res, 0); - } - } -} \ No newline at end of file From 88fd67e65e1f3a2a8dfef1ee89660dca5b589d6b Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 11:17:13 +0300 Subject: [PATCH 36/55] correct conflicts --- .../src/ops_mpi.cpp | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tasks/mpi/gordeeva_t_shell_sort_batcher_merge/src/ops_mpi.cpp diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/src/ops_mpi.cpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/src/ops_mpi.cpp new file mode 100644 index 00000000000..3034901561a --- /dev/null +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/src/ops_mpi.cpp @@ -0,0 +1,158 @@ +#include "mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp" + +#include +#include +#include +using namespace std::chrono_literals; + +void gordeeva_t_shell_sort_batcher_merge_mpi::shellSort(std::vector& arr) { + size_t arr_length = arr.size(); + for (size_t step = arr_length / 2; step > 0; step /= 2) { + for (size_t i = step; i < arr_length; i++) { + size_t j = i; + while (j >= step && arr[j - step] > arr[j]) { + std::swap(arr[j], arr[j - step]); + j -= step; + } + } + } +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential::pre_processing() { + internal_order_test(); + + size_t sz = taskData->inputs_count[0]; + auto* input_tmp = reinterpret_cast(taskData->inputs[0]); + input_.assign(input_tmp, input_tmp + sz); + res_.resize(sz); + + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential::validation() { + internal_order_test(); + + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential::run() { + internal_order_test(); + + shellSort(input_); + res_ = input_; + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential::post_processing() { + internal_order_test(); + + int* output_matr = reinterpret_cast(taskData->outputs[0]); + std::copy(res_.begin(), res_.end(), output_matr); + return true; +} + +void gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel::batcher_merge(size_t rank1, size_t rank2, + std::vector& local_input_local) { + size_t rank = world.rank(); + std::vector received_data; + + if (rank == rank1) { + world.send(rank2, 0, local_input_local); + world.recv(rank2, 0, received_data); + } else if (rank == rank2) { + world.recv(rank1, 0, received_data); + world.send(rank1, 0, local_input_local); + } + + if (!received_data.empty()) { + std::vector merged_data(local_input_local.size() + received_data.size()); + std::merge(local_input_local.begin(), local_input_local.end(), received_data.begin(), received_data.end(), + merged_data.begin()); + + if (rank == rank1) { + local_input_local.assign(merged_data.begin(), merged_data.begin() + local_input_local.size()); + } else if (rank == rank2) { + local_input_local.assign(merged_data.end() - local_input_local.size(), merged_data.end()); + } + } +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel::pre_processing() { + internal_order_test(); + + if (world.rank() == 0) { + sz_mpi = taskData->inputs_count[0]; + auto* input_tmp = reinterpret_cast(taskData->inputs[0]); + input_.assign(input_tmp, input_tmp + sz_mpi); + res_.resize(sz_mpi); + } + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel::validation() { + internal_order_test(); + + if (world.rank() == 0) { + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + } + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel::run() { + internal_order_test(); + + size_t rank = world.rank(); + size_t size = world.size(); + + size_t sz_mpi_local = 0; + boost::mpi::broadcast(world, sz_mpi, 0); + sz_mpi_local = sz_mpi; + + size_t delta = sz_mpi_local / size; + size_t ost = sz_mpi_local % size; + + std::vector sz_rk(size, static_cast(delta)); + + for (size_t i = 0; i < ost; ++i) { + sz_rk[i]++; + } + + if (rank != 0) { + input_.resize(sz_mpi_local); + } + boost::mpi::broadcast(world, input_.data(), sz_mpi_local, 0); + + std::vector local_input(sz_rk[rank]); + boost::mpi::scatterv(world, input_, sz_rk, local_input.data(), 0); + + shellSort(local_input); + + for (size_t i = 0; i < size; ++i) { + if (rank % 2 == i % 2 && rank + 1 < size) { + batcher_merge(rank, rank + 1, local_input); + } else if (rank % 2 != i % 2 && rank > 0) { + batcher_merge(rank - 1, rank, local_input); + } + } + + if (rank == 0) { + res_.resize(sz_mpi_local); + } + boost::mpi::gatherv(world, local_input.data(), local_input.size(), res_.data(), sz_rk, 0); + + return true; +} + +bool gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel::post_processing() { + internal_order_test(); + + if (world.rank() == 0 && !taskData->outputs.empty()) { + std::copy(res_.begin(), res_.end(), reinterpret_cast(taskData->outputs[0])); + } + return true; +} From 45d3977dd7d34ab152cfa1f427d8ddb020e9cd38 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:11:37 +0300 Subject: [PATCH 37/55] 2 --- .../func_tests/main.cpp | 210 ++++++++++++++++++ .../include/ops_mpi.hpp | 46 ++++ .../perf_tests/main.cpp | 81 +++++++ .../src/ops_mpi.cpp | 188 ++++++++++++++++ .../func_tests/main.cpp | 149 +++++++++++++ .../include/ops_seq.hpp | 25 +++ .../perf_tests/main.cpp | 79 +++++++ .../src/ops_seq.cpp | 80 +++++++ 8 files changed, 858 insertions(+) create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp new file mode 100644 index 00000000000..cd5ec3ec2d7 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -0,0 +1,210 @@ +#include + +#include +#include +#include + +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(5); + taskDataPar->inputs_count.push_back(5); + taskDataPar->inputs.push_back(reinterpret_cast(new int[25])); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 500; + const int cols = 500; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + ASSERT_EQ(global_max, max_example); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 500; + const int cols = 1000; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + for (int i = 0; i < cols; i++) { + ASSERT_EQ(global_max[i], max_example[i]); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 1000; + const int cols = 3000; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + for (int i = 0; i < cols; i++) { + ASSERT_EQ(global_max[i], max_example[i]); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(2); + taskDataPar->inputs_count.push_back(3); + taskDataPar->inputs.push_back(reinterpret_cast(new int[6])); + taskDataPar->outputs_count.push_back(2); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(10); + taskDataPar->inputs_count.push_back(15); + taskDataPar->inputs.push_back(reinterpret_cast(new int[150])); + taskDataPar->outputs_count.push_back(2); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} \ No newline at end of file diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp new file mode 100644 index 00000000000..702922761ca --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace gordeva_t_max_val_of_column_matrix_mpi { + +class TestMPITaskSequential : public ppc::core::Task { + public: + explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + static std::vector rand_vec(int s, int down = -100, int upp = 100); + static std::vector> rand_matr(int rows, int cols); + + private: + std::vector> input_; + std::vector res; +}; + +class TestMPITaskParallel : public ppc::core::Task { + public: + explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + private: + std::vector> input_, local_input_; + std::vector res; + boost::mpi::communicator world; +}; + +} // namespace gordeva_t_max_val_of_column_matrix_mpi diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp new file mode 100644 index 00000000000..462eb21ea28 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -0,0 +1,81 @@ +#include + +#include +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { + boost::mpi::communicator world; + std::vector> global_matr; + std::vector max_s; + + std::shared_ptr taskDataPar = std::make_shared(); + int rows = 5000; + int cols = 5000; + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } + taskDataPar->inputs_count.emplace_back(rows); + taskDataPar->inputs_count.emplace_back(cols); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); + } + + auto testMpiTaskParallel = + std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + if (world.rank() == 0) { + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { + boost::mpi::communicator world; + + std::vector> global_matr; + std::vector max_s; + std::shared_ptr taskDataPar = std::make_shared(); + int rows = 7000; + int cols = 7000; + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } + + taskDataPar->inputs_count.emplace_back(rows); + taskDataPar->inputs_count.emplace_back(cols); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + if (world.rank() == 0) { + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); + } + } +} diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp new file mode 100644 index 00000000000..54f48dc0476 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp @@ -0,0 +1,188 @@ +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +#include +#include +#include +#include +#include +#include + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::pre_processing() { + internal_order_test(); + + int rows = taskData->inputs_count[0]; + int cols = taskData->inputs_count[1]; + + input_.resize(rows, std::vector(cols)); + + for (int i = 0; i < rows; i++) { + int* input_matr = reinterpret_cast(taskData->inputs[i]); + for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; + } + + res.resize(cols); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::validation() { + internal_order_test(); + + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::run() { + internal_order_test(); + for (size_t i = 0; i < input_[0].size(); i++) { + int max_el = input_[0][i]; + for (size_t j = 1; j < input_.size(); j++) + if (input_[j][i] > max_el) max_el = input_[j][i]; + + res[i] = max_el; + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::post_processing() { + internal_order_test(); + + int* output_matr = reinterpret_cast(taskData->outputs[0]); + + std::copy(res.begin(), res.end(), output_matr); + return true; +} + +std::vector gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_vec(int s, int down, int upp) { + std::vector v(s); + for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(int rows, + int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec(cols, -200, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::pre_processing() { + internal_order_test(); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::validation() { + internal_order_test(); + + if (world.rank() == 0) { + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + } + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::run() { + internal_order_test(); + + size_t delta = 0; + size_t delta_1 = 0; + size_t local_cols = 0; + + if (world.rank() == 0) { + size_t rows = taskData->inputs_count[0]; + size_t cols = taskData->inputs_count[1]; + + delta = rows / world.size(); + delta_1 = rows % world.size(); + + boost::mpi::broadcast(world, delta, 0); + boost::mpi::broadcast(world, delta_1, 0); + + input_.resize(rows, std::vector(cols)); + for (size_t i = 0; i < rows; i++) { + int* input_matr = reinterpret_cast(taskData->inputs[i]); + input_[i].assign(input_matr, input_matr + cols); + } + + for (int proc = 1; proc < world.size(); ++proc) { + size_t start_row = (proc * delta) + std::min(static_cast(proc), delta_1); + size_t rows_to_send = delta + ((static_cast(proc) < delta_1) ? 1 : 0); + + world.send(proc, 0, cols); + + for (size_t i = 0; i < rows_to_send; ++i) { + world.send(proc, 0, input_[start_row + i]); + } + } + + size_t local_input_rows = delta + ((static_cast(world.rank()) < delta_1) ? 1 : 0); + local_cols = cols; + local_input_.assign(input_.begin(), std::next(input_.begin(), static_cast(local_input_rows))); + } else { + boost::mpi::broadcast(world, delta, 0); + boost::mpi::broadcast(world, delta_1, 0); + + size_t local_input_rows = delta + (static_cast(world.rank()) < delta_1 ? 1 : 0); + + world.recv(0, 0, local_cols); + + local_input_.resize(local_input_rows, std::vector(local_cols)); + for (size_t i = 0; i < local_input_rows; ++i) { + world.recv(0, 0, local_input_[i]); + } + } + + res.resize(local_cols); + std::vector tmp_max(local_cols, INT_MIN); + + for (size_t i = 0; i < local_cols; ++i) { + for (size_t j = 0; j < local_input_.size(); ++j) { + tmp_max[i] = std::max(tmp_max[i], local_input_[j][i]); + } + } + + if (world.rank() == 0) { + std::vector max_s(local_cols, INT_MIN); + std::copy(tmp_max.begin(), tmp_max.end(), max_s.begin()); + + for (int proc = 1; proc < world.size(); ++proc) { + std::vector proc_max(local_cols); + world.recv(proc, 0, proc_max); + + for (size_t i = 0; i < local_cols; ++i) { + max_s[i] = std::max(max_s[i], proc_max[i]); + } + } + res = max_s; + } else { + world.send(0, 0, tmp_max); + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::post_processing() { + internal_order_test(); + + if (world.rank() == 0) { + std::copy(res.begin(), res.end(), reinterpret_cast(taskData->outputs[0])); + } + return true; +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp new file mode 100644 index 00000000000..0b149b9d14e --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -0,0 +1,149 @@ +#include + +#include +#include + +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + ASSERT_FALSE(testTaskSequential.validation()); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyOutput) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(5); + taskDataSeq->inputs_count.push_back(5); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[25])); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) { + const int rows = 500; + const int cols = 500; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_random) { + const int rows = 500; + const int cols = 1000; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_random) { + const int rows = 1000; + const int cols = 3000; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(10); + taskDataSeq->inputs_count.push_back(0); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[10])); + taskDataSeq->outputs_count.push_back(1); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(10); + taskDataSeq->inputs_count.push_back(15); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[150])); + taskDataSeq->outputs_count.push_back(10); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp new file mode 100644 index 00000000000..577b7194572 --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "core/task/include/task.hpp" + +namespace gordeva_t_max_val_of_column_matrix_seq { + +class TestTaskSequential : public ppc::core::Task { + public: + explicit TestTaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + static std::vector rand_vec(int size, int down = -100, int upp = 100); + static std::vector> rand_matr(int rows, int cols); + + private: + std::vector> input_; + std::vector res_; +}; + +} // namespace gordeva_t_max_val_of_column_matrix_seq diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp new file mode 100644 index 00000000000..2ee62e9c724 --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -0,0 +1,79 @@ +#include + +#include + +#include "core/perf/include/perf.hpp" +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { + const int cols = 5000; + const int rows = 5000; + + std::shared_ptr taskDataSeq = std::make_shared(); + + auto testTaskSequential = std::make_shared(taskDataSeq); + + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + std::vector res_vec(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); + taskDataSeq->outputs_count.emplace_back(res_vec.size()); + + 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; + }; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testTaskSequential); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + ppc::core::Perf::print_perf_statistic(perfResults); + + for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { + const int cols = 7000; + const int rows = 7000; + + std::shared_ptr taskDataSeq = std::make_shared(); + + auto testTaskSequential = std::make_shared(taskDataSeq); + + std::vector> matr_rand = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); + + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res_vec(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); + taskDataSeq->outputs_count.emplace_back(res_vec.size()); + + 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; + }; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testTaskSequential); + perfAnalyzer->task_run(perfAttr, perfResults); + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp new file mode 100644 index 00000000000..35a9aef24ff --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -0,0 +1,80 @@ +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +#include + +namespace gordeva_t_max_val_of_column_matrix_seq { + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::pre_processing() { + internal_order_test(); + + int rows = taskData->inputs_count[0]; + int cols = taskData->inputs_count[1]; + int* input_matr; + input_.resize(rows, std::vector(cols)); + + for (int i = 0; i < rows; i++) { + input_matr = reinterpret_cast(taskData->inputs[i]); + for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; + } + + res_.resize(cols); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::validation() { + internal_order_test(); + + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::run() { + internal_order_test(); + + for (size_t i = 0; i < input_[0].size(); i++) { + int max_el = input_[0][i]; + for (size_t j = 1; j < input_.size(); j++) + if (input_[j][i] > max_el) max_el = input_[j][i]; + + res_[i] = max_el; + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing() { + internal_order_test(); + + int* output_matr = reinterpret_cast(taskData->outputs[0]); + + std::copy(res_.begin(), res_.end(), output_matr); + return true; +} + +std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { + std::vector v(size); + for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, + int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec(cols, -200, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +} // namespace gordeva_t_max_val_of_column_matrix_seq From 97edfb878859594ebbf0f0f151b69801bf624656 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:12:28 +0300 Subject: [PATCH 38/55] end --- .../func_tests/main.cpp | 149 ------------------ .../include/ops_seq.hpp | 25 --- .../perf_tests/main.cpp | 79 ---------- .../src/ops_seq.cpp | 80 ---------- 4 files changed, 333 deletions(-) delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp delete mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp deleted file mode 100644 index 0b149b9d14e..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include - -#include -#include - -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - ASSERT_FALSE(testTaskSequential.validation()); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyOutput) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(5); - taskDataSeq->inputs_count.push_back(5); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[25])); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) { - const int rows = 500; - const int cols = 500; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_random) { - const int rows = 500; - const int cols = 1000; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_random) { - const int rows = 1000; - const int cols = 3000; - - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); - taskDataSeq->outputs_count.emplace_back(res.size()); - - ASSERT_EQ(testTaskSequential.validation(), true); - ASSERT_TRUE(testTaskSequential.pre_processing()); - ASSERT_TRUE(testTaskSequential.run()); - ASSERT_TRUE(testTaskSequential.post_processing()); - - for (int j = 0; j < cols; j++) { - int max_el = matrix[0][j]; - for (int i = 1; i < rows; i++) { - if (matrix[i][j] > max_el) { - max_el = matrix[i][j]; - } - } - ASSERT_EQ(res[j], max_el); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(10); - taskDataSeq->inputs_count.push_back(0); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[10])); - taskDataSeq->outputs_count.push_back(1); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { - std::shared_ptr taskDataSeq = std::make_shared(); - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - - taskDataSeq->inputs_count.push_back(10); - taskDataSeq->inputs_count.push_back(15); - taskDataSeq->inputs.push_back(reinterpret_cast(new int[150])); - taskDataSeq->outputs_count.push_back(10); - - ASSERT_FALSE(testTaskSequential.validation()); - - delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp deleted file mode 100644 index 577b7194572..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "core/task/include/task.hpp" - -namespace gordeva_t_max_val_of_column_matrix_seq { - -class TestTaskSequential : public ppc::core::Task { - public: - explicit TestTaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - static std::vector rand_vec(int size, int down = -100, int upp = 100); - static std::vector> rand_matr(int rows, int cols); - - private: - std::vector> input_; - std::vector res_; -}; - -} // namespace gordeva_t_max_val_of_column_matrix_seq diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp deleted file mode 100644 index 2ee62e9c724..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include - -#include - -#include "core/perf/include/perf.hpp" -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { - const int cols = 5000; - const int rows = 5000; - - std::shared_ptr taskDataSeq = std::make_shared(); - - auto testTaskSequential = std::make_shared(taskDataSeq); - - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - - for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); - - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - std::vector res_vec(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); - taskDataSeq->outputs_count.emplace_back(res_vec.size()); - - 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; - }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - - for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { - const int cols = 7000; - const int rows = 7000; - - std::shared_ptr taskDataSeq = std::make_shared(); - - auto testTaskSequential = std::make_shared(taskDataSeq); - - std::vector> matr_rand = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); - for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); - - taskDataSeq->inputs_count.emplace_back(rows); - taskDataSeq->inputs_count.emplace_back(cols); - - std::vector res_vec(cols, 0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); - taskDataSeq->outputs_count.emplace_back(res_vec.size()); - - 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; - }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testTaskSequential); - perfAnalyzer->task_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); -} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp deleted file mode 100644 index 35a9aef24ff..00000000000 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" - -#include - -namespace gordeva_t_max_val_of_column_matrix_seq { - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::pre_processing() { - internal_order_test(); - - int rows = taskData->inputs_count[0]; - int cols = taskData->inputs_count[1]; - int* input_matr; - input_.resize(rows, std::vector(cols)); - - for (int i = 0; i < rows; i++) { - input_matr = reinterpret_cast(taskData->inputs[i]); - for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; - } - - res_.resize(cols); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::validation() { - internal_order_test(); - - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::run() { - internal_order_test(); - - for (size_t i = 0; i < input_[0].size(); i++) { - int max_el = input_[0][i]; - for (size_t j = 1; j < input_.size(); j++) - if (input_[j][i] > max_el) max_el = input_[j][i]; - - res_[i] = max_el; - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing() { - internal_order_test(); - - int* output_matr = reinterpret_cast(taskData->outputs[0]); - - std::copy(res_.begin(), res_.end(), output_matr); - return true; -} - -std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { - std::vector v(size); - for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -200, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -} // namespace gordeva_t_max_val_of_column_matrix_seq From f1846cf06be27bcd3bdd053efa718bb5e8550def Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:13:16 +0300 Subject: [PATCH 39/55] 1 --- .../func_tests/main.cpp | 210 ------------------ .../include/ops_mpi.hpp | 46 ---- .../perf_tests/main.cpp | 81 ------- .../src/ops_mpi.cpp | 188 ---------------- 4 files changed, 525 deletions(-) delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp delete mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp deleted file mode 100644 index cd5ec3ec2d7..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include - -#include -#include -#include - -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - ASSERT_FALSE(testMpiTaskParallel.validation()); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(5); - taskDataPar->inputs_count.push_back(5); - taskDataPar->inputs.push_back(reinterpret_cast(new int[25])); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 500; - const int cols = 500; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - ASSERT_EQ(global_max, max_example); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 500; - const int cols = 1000; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - for (int i = 0; i < cols; i++) { - ASSERT_EQ(global_max[i], max_example[i]); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_random) { - boost::mpi::communicator world; - - const int rows = 1000; - const int cols = 3000; - std::vector> global_matr; - std::vector global_max(cols, INT_MIN); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataPar->inputs_count = {rows, cols}; - taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); - taskDataPar->outputs_count.emplace_back(global_max.size()); - } - - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - ASSERT_EQ(testMpiTaskParallel.validation(), true); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::vector max_example(cols, INT_MIN); - - std::shared_ptr taskDataSeq = std::make_shared(); - for (unsigned int i = 0; i < global_matr.size(); i++) { - taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); - } - taskDataSeq->inputs_count = {rows, cols}; - taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); - taskDataSeq->outputs_count.emplace_back(max_example.size()); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); - - ASSERT_EQ(testMpiTaskSequential.validation(), true); - testMpiTaskSequential.pre_processing(); - testMpiTaskSequential.run(); - testMpiTaskSequential.post_processing(); - for (int i = 0; i < cols; i++) { - ASSERT_EQ(global_max[i], max_example[i]); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(2); - taskDataPar->inputs_count.push_back(3); - taskDataPar->inputs.push_back(reinterpret_cast(new int[6])); - taskDataPar->outputs_count.push_back(2); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { - boost::mpi::communicator world; - - std::shared_ptr taskDataPar = std::make_shared(); - gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - if (world.rank() == 0) { - taskDataPar->inputs_count.push_back(10); - taskDataPar->inputs_count.push_back(15); - taskDataPar->inputs.push_back(reinterpret_cast(new int[150])); - taskDataPar->outputs_count.push_back(2); - ASSERT_FALSE(testMpiTaskParallel.validation()); - - delete[] reinterpret_cast(taskDataPar->inputs[0]); - } -} \ No newline at end of file diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp deleted file mode 100644 index 702922761ca..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace gordeva_t_max_val_of_column_matrix_mpi { - -class TestMPITaskSequential : public ppc::core::Task { - public: - explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - static std::vector rand_vec(int s, int down = -100, int upp = 100); - static std::vector> rand_matr(int rows, int cols); - - private: - std::vector> input_; - std::vector res; -}; - -class TestMPITaskParallel : public ppc::core::Task { - public: - explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - private: - std::vector> input_, local_input_; - std::vector res; - boost::mpi::communicator world; -}; - -} // namespace gordeva_t_max_val_of_column_matrix_mpi diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp deleted file mode 100644 index 462eb21ea28..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include - -#include -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { - boost::mpi::communicator world; - std::vector> global_matr; - std::vector max_s; - - std::shared_ptr taskDataPar = std::make_shared(); - int rows = 5000; - int cols = 5000; - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } - taskDataPar->inputs_count.emplace_back(rows); - taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); - } - - auto testMpiTaskParallel = - std::make_shared(taskDataPar); - - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); - } - } -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { - boost::mpi::communicator world; - - std::vector> global_matr; - std::vector max_s; - std::shared_ptr taskDataPar = std::make_shared(); - int rows = 7000; - int cols = 7000; - - if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } - - taskDataPar->inputs_count.emplace_back(rows); - taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - - ASSERT_EQ(testMpiTaskParallel->validation(), true); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); - } - } -} diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp deleted file mode 100644 index 54f48dc0476..00000000000 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" - -#include -#include -#include -#include -#include -#include - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::pre_processing() { - internal_order_test(); - - int rows = taskData->inputs_count[0]; - int cols = taskData->inputs_count[1]; - - input_.resize(rows, std::vector(cols)); - - for (int i = 0; i < rows; i++) { - int* input_matr = reinterpret_cast(taskData->inputs[i]); - for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; - } - - res.resize(cols); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::validation() { - internal_order_test(); - - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::run() { - internal_order_test(); - for (size_t i = 0; i < input_[0].size(); i++) { - int max_el = input_[0][i]; - for (size_t j = 1; j < input_.size(); j++) - if (input_[j][i] > max_el) max_el = input_[j][i]; - - res[i] = max_el; - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::post_processing() { - internal_order_test(); - - int* output_matr = reinterpret_cast(taskData->outputs[0]); - - std::copy(res.begin(), res.end(), output_matr); - return true; -} - -std::vector gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_vec(int s, int down, int upp) { - std::vector v(s); - for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -200, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::pre_processing() { - internal_order_test(); - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::validation() { - internal_order_test(); - - if (world.rank() == 0) { - if (taskData->inputs.empty() || taskData->outputs.empty()) return false; - if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; - if (taskData->outputs_count.size() != 1) return false; - if (taskData->inputs_count.size() < 2) return false; - if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; - } - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::run() { - internal_order_test(); - - size_t delta = 0; - size_t delta_1 = 0; - size_t local_cols = 0; - - if (world.rank() == 0) { - size_t rows = taskData->inputs_count[0]; - size_t cols = taskData->inputs_count[1]; - - delta = rows / world.size(); - delta_1 = rows % world.size(); - - boost::mpi::broadcast(world, delta, 0); - boost::mpi::broadcast(world, delta_1, 0); - - input_.resize(rows, std::vector(cols)); - for (size_t i = 0; i < rows; i++) { - int* input_matr = reinterpret_cast(taskData->inputs[i]); - input_[i].assign(input_matr, input_matr + cols); - } - - for (int proc = 1; proc < world.size(); ++proc) { - size_t start_row = (proc * delta) + std::min(static_cast(proc), delta_1); - size_t rows_to_send = delta + ((static_cast(proc) < delta_1) ? 1 : 0); - - world.send(proc, 0, cols); - - for (size_t i = 0; i < rows_to_send; ++i) { - world.send(proc, 0, input_[start_row + i]); - } - } - - size_t local_input_rows = delta + ((static_cast(world.rank()) < delta_1) ? 1 : 0); - local_cols = cols; - local_input_.assign(input_.begin(), std::next(input_.begin(), static_cast(local_input_rows))); - } else { - boost::mpi::broadcast(world, delta, 0); - boost::mpi::broadcast(world, delta_1, 0); - - size_t local_input_rows = delta + (static_cast(world.rank()) < delta_1 ? 1 : 0); - - world.recv(0, 0, local_cols); - - local_input_.resize(local_input_rows, std::vector(local_cols)); - for (size_t i = 0; i < local_input_rows; ++i) { - world.recv(0, 0, local_input_[i]); - } - } - - res.resize(local_cols); - std::vector tmp_max(local_cols, INT_MIN); - - for (size_t i = 0; i < local_cols; ++i) { - for (size_t j = 0; j < local_input_.size(); ++j) { - tmp_max[i] = std::max(tmp_max[i], local_input_[j][i]); - } - } - - if (world.rank() == 0) { - std::vector max_s(local_cols, INT_MIN); - std::copy(tmp_max.begin(), tmp_max.end(), max_s.begin()); - - for (int proc = 1; proc < world.size(); ++proc) { - std::vector proc_max(local_cols); - world.recv(proc, 0, proc_max); - - for (size_t i = 0; i < local_cols; ++i) { - max_s[i] = std::max(max_s[i], proc_max[i]); - } - } - res = max_s; - } else { - world.send(0, 0, tmp_max); - } - - return true; -} - -bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::post_processing() { - internal_order_test(); - - if (world.rank() == 0) { - std::copy(res.begin(), res.end(), reinterpret_cast(taskData->outputs[0])); - } - return true; -} From 8f5011ae341f3447844e61eb2b2b72cc2dff152b Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:17:23 +0300 Subject: [PATCH 40/55] 11 --- .../func_tests/main.cpp | 210 ++++++++++++++++++ .../include/ops_mpi.hpp | 46 ++++ .../perf_tests/main.cpp | 81 +++++++ .../src/ops_mpi.cpp | 188 ++++++++++++++++ .../func_tests/main.cpp | 149 +++++++++++++ .../include/ops_seq.hpp | 25 +++ .../perf_tests/main.cpp | 79 +++++++ .../src/ops_seq.cpp | 80 +++++++ 8 files changed, 858 insertions(+) create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp create mode 100644 tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp create mode 100644 tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp new file mode 100644 index 00000000000..cd5ec3ec2d7 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -0,0 +1,210 @@ +#include + +#include +#include +#include + +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(5); + taskDataPar->inputs_count.push_back(5); + taskDataPar->inputs.push_back(reinterpret_cast(new int[25])); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 500; + const int cols = 500; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + ASSERT_EQ(global_max, max_example); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 500; + const int cols = 1000; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + for (int i = 0; i < cols; i++) { + ASSERT_EQ(global_max[i], max_example[i]); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_random) { + boost::mpi::communicator world; + + const int rows = 1000; + const int cols = 3000; + std::vector> global_matr; + std::vector global_max(cols, INT_MIN); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataPar->inputs_count = {rows, cols}; + taskDataPar->outputs.emplace_back(reinterpret_cast(global_max.data())); + taskDataPar->outputs_count.emplace_back(global_max.size()); + } + + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + ASSERT_EQ(testMpiTaskParallel.validation(), true); + testMpiTaskParallel.pre_processing(); + testMpiTaskParallel.run(); + testMpiTaskParallel.post_processing(); + + if (world.rank() == 0) { + std::vector max_example(cols, INT_MIN); + + std::shared_ptr taskDataSeq = std::make_shared(); + for (unsigned int i = 0; i < global_matr.size(); i++) { + taskDataSeq->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); + } + taskDataSeq->inputs_count = {rows, cols}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(max_example.data())); + taskDataSeq->outputs_count.emplace_back(max_example.size()); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + for (int i = 0; i < cols; i++) { + ASSERT_EQ(global_max[i], max_example[i]); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(2); + taskDataPar->inputs_count.push_back(3); + taskDataPar->inputs.push_back(reinterpret_cast(new int[6])); + taskDataPar->outputs_count.push_back(2); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.rank() == 0) { + taskDataPar->inputs_count.push_back(10); + taskDataPar->inputs_count.push_back(15); + taskDataPar->inputs.push_back(reinterpret_cast(new int[150])); + taskDataPar->outputs_count.push_back(2); + ASSERT_FALSE(testMpiTaskParallel.validation()); + + delete[] reinterpret_cast(taskDataPar->inputs[0]); + } +} \ No newline at end of file diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp new file mode 100644 index 00000000000..702922761ca --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace gordeva_t_max_val_of_column_matrix_mpi { + +class TestMPITaskSequential : public ppc::core::Task { + public: + explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + static std::vector rand_vec(int s, int down = -100, int upp = 100); + static std::vector> rand_matr(int rows, int cols); + + private: + std::vector> input_; + std::vector res; +}; + +class TestMPITaskParallel : public ppc::core::Task { + public: + explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + private: + std::vector> input_, local_input_; + std::vector res; + boost::mpi::communicator world; +}; + +} // namespace gordeva_t_max_val_of_column_matrix_mpi diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp new file mode 100644 index 00000000000..462eb21ea28 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -0,0 +1,81 @@ +#include + +#include +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { + boost::mpi::communicator world; + std::vector> global_matr; + std::vector max_s; + + std::shared_ptr taskDataPar = std::make_shared(); + int rows = 5000; + int cols = 5000; + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } + taskDataPar->inputs_count.emplace_back(rows); + taskDataPar->inputs_count.emplace_back(cols); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); + } + + auto testMpiTaskParallel = + std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + if (world.rank() == 0) { + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); + } + } +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { + boost::mpi::communicator world; + + std::vector> global_matr; + std::vector max_s; + std::shared_ptr taskDataPar = std::make_shared(); + int rows = 7000; + int cols = 7000; + + if (world.rank() == 0) { + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } + + taskDataPar->inputs_count.emplace_back(rows); + taskDataPar->inputs_count.emplace_back(cols); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); + } + + auto testMpiTaskParallel = std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->post_processing(); + + if (world.rank() == 0) { + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); + } + } +} diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp new file mode 100644 index 00000000000..54f48dc0476 --- /dev/null +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp @@ -0,0 +1,188 @@ +#include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" + +#include +#include +#include +#include +#include +#include + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::pre_processing() { + internal_order_test(); + + int rows = taskData->inputs_count[0]; + int cols = taskData->inputs_count[1]; + + input_.resize(rows, std::vector(cols)); + + for (int i = 0; i < rows; i++) { + int* input_matr = reinterpret_cast(taskData->inputs[i]); + for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; + } + + res.resize(cols); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::validation() { + internal_order_test(); + + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::run() { + internal_order_test(); + for (size_t i = 0; i < input_[0].size(); i++) { + int max_el = input_[0][i]; + for (size_t j = 1; j < input_.size(); j++) + if (input_[j][i] > max_el) max_el = input_[j][i]; + + res[i] = max_el; + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::post_processing() { + internal_order_test(); + + int* output_matr = reinterpret_cast(taskData->outputs[0]); + + std::copy(res.begin(), res.end(), output_matr); + return true; +} + +std::vector gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_vec(int s, int down, int upp) { + std::vector v(s); + for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(int rows, + int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec(cols, -200, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::pre_processing() { + internal_order_test(); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::validation() { + internal_order_test(); + + if (world.rank() == 0) { + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + } + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::run() { + internal_order_test(); + + size_t delta = 0; + size_t delta_1 = 0; + size_t local_cols = 0; + + if (world.rank() == 0) { + size_t rows = taskData->inputs_count[0]; + size_t cols = taskData->inputs_count[1]; + + delta = rows / world.size(); + delta_1 = rows % world.size(); + + boost::mpi::broadcast(world, delta, 0); + boost::mpi::broadcast(world, delta_1, 0); + + input_.resize(rows, std::vector(cols)); + for (size_t i = 0; i < rows; i++) { + int* input_matr = reinterpret_cast(taskData->inputs[i]); + input_[i].assign(input_matr, input_matr + cols); + } + + for (int proc = 1; proc < world.size(); ++proc) { + size_t start_row = (proc * delta) + std::min(static_cast(proc), delta_1); + size_t rows_to_send = delta + ((static_cast(proc) < delta_1) ? 1 : 0); + + world.send(proc, 0, cols); + + for (size_t i = 0; i < rows_to_send; ++i) { + world.send(proc, 0, input_[start_row + i]); + } + } + + size_t local_input_rows = delta + ((static_cast(world.rank()) < delta_1) ? 1 : 0); + local_cols = cols; + local_input_.assign(input_.begin(), std::next(input_.begin(), static_cast(local_input_rows))); + } else { + boost::mpi::broadcast(world, delta, 0); + boost::mpi::broadcast(world, delta_1, 0); + + size_t local_input_rows = delta + (static_cast(world.rank()) < delta_1 ? 1 : 0); + + world.recv(0, 0, local_cols); + + local_input_.resize(local_input_rows, std::vector(local_cols)); + for (size_t i = 0; i < local_input_rows; ++i) { + world.recv(0, 0, local_input_[i]); + } + } + + res.resize(local_cols); + std::vector tmp_max(local_cols, INT_MIN); + + for (size_t i = 0; i < local_cols; ++i) { + for (size_t j = 0; j < local_input_.size(); ++j) { + tmp_max[i] = std::max(tmp_max[i], local_input_[j][i]); + } + } + + if (world.rank() == 0) { + std::vector max_s(local_cols, INT_MIN); + std::copy(tmp_max.begin(), tmp_max.end(), max_s.begin()); + + for (int proc = 1; proc < world.size(); ++proc) { + std::vector proc_max(local_cols); + world.recv(proc, 0, proc_max); + + for (size_t i = 0; i < local_cols; ++i) { + max_s[i] = std::max(max_s[i], proc_max[i]); + } + } + res = max_s; + } else { + world.send(0, 0, tmp_max); + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::post_processing() { + internal_order_test(); + + if (world.rank() == 0) { + std::copy(res.begin(), res.end(), reinterpret_cast(taskData->outputs[0])); + } + return true; +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp new file mode 100644 index 00000000000..0b149b9d14e --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -0,0 +1,149 @@ +#include + +#include +#include + +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + ASSERT_FALSE(testTaskSequential.validation()); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyOutput) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(5); + taskDataSeq->inputs_count.push_back(5); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[25])); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) { + const int rows = 500; + const int cols = 500; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_random) { + const int rows = 500; + const int cols = 1000; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_random) { + const int rows = 1000; + const int cols = 3000; + + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res.data())); + taskDataSeq->outputs_count.emplace_back(res.size()); + + ASSERT_EQ(testTaskSequential.validation(), true); + ASSERT_TRUE(testTaskSequential.pre_processing()); + ASSERT_TRUE(testTaskSequential.run()); + ASSERT_TRUE(testTaskSequential.post_processing()); + + for (int j = 0; j < cols; j++) { + int max_el = matrix[0][j]; + for (int i = 1; i < rows; i++) { + if (matrix[i][j] > max_el) { + max_el = matrix[i][j]; + } + } + ASSERT_EQ(res[j], max_el); + } +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(10); + taskDataSeq->inputs_count.push_back(0); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[10])); + taskDataSeq->outputs_count.push_back(1); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { + std::shared_ptr taskDataSeq = std::make_shared(); + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); + + taskDataSeq->inputs_count.push_back(10); + taskDataSeq->inputs_count.push_back(15); + taskDataSeq->inputs.push_back(reinterpret_cast(new int[150])); + taskDataSeq->outputs_count.push_back(10); + + ASSERT_FALSE(testTaskSequential.validation()); + + delete[] reinterpret_cast(taskDataSeq->inputs[0]); +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp new file mode 100644 index 00000000000..577b7194572 --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "core/task/include/task.hpp" + +namespace gordeva_t_max_val_of_column_matrix_seq { + +class TestTaskSequential : public ppc::core::Task { + public: + explicit TestTaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + static std::vector rand_vec(int size, int down = -100, int upp = 100); + static std::vector> rand_matr(int rows, int cols); + + private: + std::vector> input_; + std::vector res_; +}; + +} // namespace gordeva_t_max_val_of_column_matrix_seq diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp new file mode 100644 index 00000000000..2ee62e9c724 --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -0,0 +1,79 @@ +#include + +#include + +#include "core/perf/include/perf.hpp" +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { + const int cols = 5000; + const int rows = 5000; + + std::shared_ptr taskDataSeq = std::make_shared(); + + auto testTaskSequential = std::make_shared(taskDataSeq); + + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); + + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + std::vector res_vec(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); + taskDataSeq->outputs_count.emplace_back(res_vec.size()); + + 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; + }; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testTaskSequential); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + ppc::core::Perf::print_perf_statistic(perfResults); + + for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { + const int cols = 7000; + const int rows = 7000; + + std::shared_ptr taskDataSeq = std::make_shared(); + + auto testTaskSequential = std::make_shared(taskDataSeq); + + std::vector> matr_rand = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); + + taskDataSeq->inputs_count.emplace_back(rows); + taskDataSeq->inputs_count.emplace_back(cols); + + std::vector res_vec(cols, 0); + taskDataSeq->outputs.emplace_back(reinterpret_cast(res_vec.data())); + taskDataSeq->outputs_count.emplace_back(res_vec.size()); + + 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; + }; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testTaskSequential); + perfAnalyzer->task_run(perfAttr, perfResults); + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp new file mode 100644 index 00000000000..35a9aef24ff --- /dev/null +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -0,0 +1,80 @@ +#include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" + +#include + +namespace gordeva_t_max_val_of_column_matrix_seq { + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::pre_processing() { + internal_order_test(); + + int rows = taskData->inputs_count[0]; + int cols = taskData->inputs_count[1]; + int* input_matr; + input_.resize(rows, std::vector(cols)); + + for (int i = 0; i < rows; i++) { + input_matr = reinterpret_cast(taskData->inputs[i]); + for (int j = 0; j < cols; j++) input_[i][j] = input_matr[j]; + } + + res_.resize(cols); + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::validation() { + internal_order_test(); + + if (taskData->inputs.empty() || taskData->outputs.empty()) return false; + if (taskData->inputs_count[0] <= 0 || taskData->inputs_count[1] <= 0) return false; + if (taskData->outputs_count.size() != 1) return false; + if (taskData->inputs_count.size() < 2) return false; + if (taskData->outputs_count[0] != taskData->inputs_count[1]) return false; + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::run() { + internal_order_test(); + + for (size_t i = 0; i < input_[0].size(); i++) { + int max_el = input_[0][i]; + for (size_t j = 1; j < input_.size(); j++) + if (input_[j][i] > max_el) max_el = input_[j][i]; + + res_[i] = max_el; + } + + return true; +} + +bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing() { + internal_order_test(); + + int* output_matr = reinterpret_cast(taskData->outputs[0]); + + std::copy(res_.begin(), res_.end(), output_matr); + return true; +} + +std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { + std::vector v(size); + for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, + int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec(cols, -200, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +} // namespace gordeva_t_max_val_of_column_matrix_seq From ea0c61ccdcf433edbb1cd73aa4de8031c00c36ac Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:25:38 +0300 Subject: [PATCH 41/55] yra? --- .../src/ops_mpi.cpp | 20 ------------------ .../src/ops_seq.cpp | 21 ------------------- 2 files changed, 41 deletions(-) diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp index 54f48dc0476..b0faa4a3bc0 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/src/ops_mpi.cpp @@ -59,26 +59,6 @@ bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::post_process return true; } -std::vector gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_vec(int s, int down, int upp) { - std::vector v(s); - for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -200, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - bool gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskParallel::pre_processing() { internal_order_test(); diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp index 35a9aef24ff..18a13242ec3 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -56,25 +56,4 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing std::copy(res_.begin(), res_.end(), output_matr); return true; } - -std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { - std::vector v(size); - for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, - int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec(cols, -200, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - } // namespace gordeva_t_max_val_of_column_matrix_seq From f5d66684f48d8ecdc9a33ecbfb95fa9c550a34f4 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 12:27:30 +0300 Subject: [PATCH 42/55] yra?! --- tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp index 18a13242ec3..df2a39e60a0 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -56,4 +56,5 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing std::copy(res_.begin(), res_.end(), output_matr); return true; } + } // namespace gordeva_t_max_val_of_column_matrix_seq From f2d6287746071ff6010a6393d26b73683f39d566 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 13:16:03 +0300 Subject: [PATCH 43/55] pls end --- .../func_tests/main.cpp | 308 ++++++++++++++++++ .../include/ops_mpi.hpp | 46 +++ .../perf_tests/main.cpp | 116 +++++++ 3 files changed, 470 insertions(+) create mode 100644 tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp create mode 100644 tasks/mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp create mode 100644 tasks/mpi/gordeeva_t_shell_sort_batcher_merge/perf_tests/main.cpp diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp new file mode 100644 index 00000000000..5cc25ee70be --- /dev/null +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp @@ -0,0 +1,308 @@ +#include + +#include +#include +#include +#include +#include + +#include "mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp" + +std::vector rand_vec(int size, int down = -100, int upp = 100) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(down, upp); + + std::vector v(size); + for (auto &number : v) { + number = dis(gen); + } + return v; +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_with_fixed) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 10; + std::vector input_vec = {3, 4, 7, 1, 8, 9, 5, 2, 6, 0}; + std::vector result_parallel(size); + std::vector result_seq(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {static_cast(size)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {static_cast(size)}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + ASSERT_TRUE(testPar.validation()); + + ASSERT_TRUE(testPar.pre_processing()); + ASSERT_TRUE(testPar.run()); + ASSERT_TRUE(testPar.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + std::shared_ptr taskDataSeq = std::make_shared(); + taskDataSeq->inputs.emplace_back(reinterpret_cast(input_vec.data())); + + taskDataSeq->inputs_count = {static_cast(size)}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); + taskDataSeq->outputs_count = {static_cast(size)}; + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + } + ASSERT_EQ(result_parallel, result_seq); +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_Zero_Value) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 0; + std::vector input_vec; + std::vector result_parallel(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {size}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {size}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + if (world.rank() == 0) { + ASSERT_FALSE(testPar.validation()); + } +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_Empty_Output) { + boost::mpi::environment env; + boost::mpi::communicator world; + const int size = 0; + + std::vector input_vec; + std::vector result_parallel(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {size}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + if (world.rank() == 0) { + ASSERT_FALSE(testPar.validation()); + } +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_17_with_random) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 17; + std::vector input_vec; + std::vector result_parallel(size); + std::vector result_seq(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {static_cast(size)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {static_cast(size)}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + ASSERT_TRUE(testPar.validation()); + + ASSERT_TRUE(testPar.pre_processing()); + ASSERT_TRUE(testPar.run()); + ASSERT_TRUE(testPar.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + std::shared_ptr taskDataSeq = std::make_shared(); + taskDataSeq->inputs.emplace_back(reinterpret_cast(input_vec.data())); + + taskDataSeq->inputs_count = {static_cast(size)}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); + taskDataSeq->outputs_count = {static_cast(size)}; + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + } + ASSERT_EQ(result_parallel, result_seq); +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_100_with_random) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 100; + std::vector input_vec; + std::vector result_parallel(size); + std::vector result_seq(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {static_cast(size)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {static_cast(size)}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + ASSERT_TRUE(testPar.validation()); + + ASSERT_TRUE(testPar.pre_processing()); + ASSERT_TRUE(testPar.run()); + ASSERT_TRUE(testPar.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + std::shared_ptr taskDataSeq = std::make_shared(); + taskDataSeq->inputs.emplace_back(reinterpret_cast(input_vec.data())); + + taskDataSeq->inputs_count = {static_cast(size)}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); + taskDataSeq->outputs_count = {static_cast(size)}; + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + } + ASSERT_EQ(result_parallel, result_seq); +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_1000_with_random) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 1000; + std::vector input_vec; + std::vector result_parallel(size); + std::vector result_seq(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {static_cast(size)}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {static_cast(size)}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + ASSERT_TRUE(testPar.validation()); + + ASSERT_TRUE(testPar.pre_processing()); + ASSERT_TRUE(testPar.run()); + ASSERT_TRUE(testPar.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + std::shared_ptr taskDataSeq = std::make_shared(); + taskDataSeq->inputs.emplace_back(reinterpret_cast(input_vec.data())); + + taskDataSeq->inputs_count = {static_cast(size)}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); + taskDataSeq->outputs_count = {static_cast(size)}; + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + } + + if (world.rank() == 0) { + ASSERT_EQ(result_parallel, result_seq); + } +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_5000_with_random) { + boost::mpi::environment env; + boost::mpi::communicator world; + + const int size = 5000; + std::vector input_vec; + std::vector result_parallel(size); + std::vector result_seq(size); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_vec = rand_vec(size, 0, 1000); + taskDataPar->inputs.emplace_back(reinterpret_cast(input_vec.data())); + taskDataPar->inputs_count = {size}; + taskDataPar->outputs.emplace_back(reinterpret_cast(result_parallel.data())); + taskDataPar->outputs_count = {size}; + } + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskParallel testPar(taskDataPar); + + ASSERT_TRUE(testPar.validation()); + testPar.pre_processing(); + testPar.run(); + testPar.post_processing(); + + world.barrier(); + + if (world.rank() == 0) { + std::shared_ptr taskDataSeq = std::make_shared(); + taskDataSeq->inputs.emplace_back(reinterpret_cast(input_vec.data())); + + taskDataSeq->inputs_count = {static_cast(size)}; + taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); + taskDataSeq->outputs_count = {static_cast(size)}; + + gordeeva_t_shell_sort_batcher_merge_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq); + + ASSERT_EQ(testMpiTaskSequential.validation(), true); + testMpiTaskSequential.pre_processing(); + testMpiTaskSequential.run(); + testMpiTaskSequential.post_processing(); + } + + if (world.rank() == 0) { + ASSERT_EQ(result_parallel, result_seq); + } +} \ No newline at end of file diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp new file mode 100644 index 00000000000..8d10d48335d --- /dev/null +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace gordeeva_t_shell_sort_batcher_merge_mpi { + +void shellSort(std::vector& arr); + +class TestMPITaskSequential : public ppc::core::Task { + public: + explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + private: + std::vector input_; + std::vector res_; +}; + +class TestMPITaskParallel : public ppc::core::Task { + public: + explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} + bool pre_processing() override; + bool validation() override; + bool run() override; + bool post_processing() override; + + void batcher_merge(size_t rank1, size_t rank2, std::vector& local_input_local); + + private: + std::vector input_, local_input_; + std::vector res_; + size_t sz_mpi = 0; + boost::mpi::communicator world; +}; + +} // namespace gordeeva_t_shell_sort_batcher_merge_mpi \ No newline at end of file diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/perf_tests/main.cpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/perf_tests/main.cpp new file mode 100644 index 00000000000..ca52abaef06 --- /dev/null +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/perf_tests/main.cpp @@ -0,0 +1,116 @@ +#include + +#include +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/gordeeva_t_shell_sort_batcher_merge/include/ops_mpi.hpp" + +std::vector rand_vec(int size, int down = -100, int upp = 100) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(down, upp); + + std::vector v(size); + for (auto &number : v) { + number = dis(gen); + } + return v; +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, test_pipeline_run) { + boost::mpi::communicator world; + const int size = 3000000; + + std::vector input_values; + std::vector output_values(size, 0); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_values = rand_vec(size, 0, 1000); + } + + if (world.rank() == 0) { + taskDataPar->inputs.emplace_back(reinterpret_cast(input_values.data())); + taskDataPar->inputs_count.emplace_back(static_cast(input_values.size())); + + output_values.resize(input_values.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(output_values.data())); + taskDataPar->outputs_count.emplace_back(static_cast(output_values.size())); + } + + auto testMpiTaskParallel = + std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->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(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + + ASSERT_TRUE(std::is_sorted(output_values.begin(), output_values.end())); + } +} + +TEST(gordeeva_t_shell_sort_batcher_merge_mpi, test_task_run) { + boost::mpi::communicator world; + const int size = 3000000; + + std::vector input_values; + std::vector output_values(size, 0); + + std::shared_ptr taskDataPar = std::make_shared(); + + if (world.rank() == 0) { + input_values = rand_vec(size, 0, 1000); + } + + if (world.rank() == 0) { + taskDataPar->inputs.emplace_back(reinterpret_cast(input_values.data())); + taskDataPar->inputs_count.emplace_back(static_cast(input_values.size())); + + output_values.resize(input_values.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(output_values.data())); + taskDataPar->outputs_count.emplace_back(static_cast(output_values.size())); + } + + auto testMpiTaskParallel = + std::make_shared(taskDataPar); + + ASSERT_EQ(testMpiTaskParallel->validation(), true); + + testMpiTaskParallel->pre_processing(); + testMpiTaskParallel->run(); + testMpiTaskParallel->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(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == 0) { + ppc::core::Perf::print_perf_statistic(perfResults); + + ASSERT_TRUE(std::is_sorted(output_values.begin(), output_values.end())); + } +} \ No newline at end of file From 68094dcfda93e92cdf1965cb9a7f7da11ba9b514 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 18:04:20 +0300 Subject: [PATCH 44/55] correct end --- .../func_tests/main.cpp | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index 439c0c77f13..8012c0b8c93 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -84,7 +84,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End2) { std::shared_ptr taskDataPar = std::make_shared(); - const int max_waiting_chairs = 3; + const int max_waiting_chairs = 2; int global_res = -1; taskDataPar->inputs_count.emplace_back(max_waiting_chairs); @@ -114,7 +114,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End3) { std::shared_ptr taskDataPar = std::make_shared(); - const int max_waiting_chairs = 996; + const int max_waiting_chairs = 3; int global_res = -1; taskDataPar->inputs_count.emplace_back(max_waiting_chairs); @@ -144,6 +144,36 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End4) { std::shared_ptr taskDataPar = std::make_shared(); + const int max_waiting_chairs = 996; + int global_res = -1; + + taskDataPar->inputs_count.emplace_back(max_waiting_chairs); + taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); + taskDataPar->outputs_count.emplace_back(sizeof(global_res)); + + gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); + + if (world.size() < 3) { + ASSERT_FALSE(testMpiTaskParallel.validation()); + } else { + ASSERT_TRUE(testMpiTaskParallel.validation()); + ASSERT_TRUE(testMpiTaskParallel.pre_processing()); + ASSERT_TRUE(testMpiTaskParallel.run()); + ASSERT_TRUE(testMpiTaskParallel.post_processing()); + + world.barrier(); + + if (world.rank() == 0) { + ASSERT_EQ(global_res, 0); + } + } +} + +TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End5) { + boost::mpi::communicator world; + + std::shared_ptr taskDataPar = std::make_shared(); + const int max_waiting_chairs = 999; int global_res = -1; From 1471e48c272cd4fe333da636ac1475bcb996165a Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 18:26:08 +0300 Subject: [PATCH 45/55] correct --- .../func_tests/main.cpp | 34 +++-- .../perf_tests/main.cpp | 119 +++++++++++++----- .../func_tests/main.cpp | 37 ++++-- .../perf_tests/main.cpp | 31 +++-- 4 files changed, 168 insertions(+), 53 deletions(-) diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp index cd5ec3ec2d7..9e9a43ba573 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -2,11 +2,31 @@ #include #include +#include #include #include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { +std::vector rand_vec_2(int s, int down, int upp) { + std::vector v(s); + for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> rand_matr_2(int rows, int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec_2(cols, -100, 100); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +TEST(gordeva_t_max_val_of_column_matrix_mpi, Empty_Input) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -17,7 +37,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, Empty_Output) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -44,7 +64,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + global_matr = rand_matr_2(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -90,7 +110,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_ra std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + global_matr = rand_matr_2(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -138,7 +158,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_r std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + global_matr = rand_matr_2(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -175,7 +195,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_r } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_input) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -192,7 +212,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_output) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp index 462eb21ea28..0d196490cfa 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -2,68 +2,110 @@ #include #include +#include #include #include "core/perf/include/perf.hpp" #include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" +std::vector rand_vec_1(int s, int down, int upp) { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(down, upp); + + std::vector v(s); + for (auto& number : v) { + number = dis(gen); + } + return v; +} + +std::vector> rand_matr_1(int rows, int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec_1(cols, 0, 100); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { boost::mpi::communicator world; - std::vector> global_matr; - std::vector max_s; + const int cols = 5000; + const int rows = 5000; + std::vector res_vec_par(cols, 0); + std::vector res_vec(cols, 0); + std::vector> matrix; + + std::vector> matrix_1; std::shared_ptr taskDataPar = std::make_shared(); - int rows = 5000; - int cols = 5000; if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } + matrix = rand_matr_1(rows, cols); + for (auto& i : matrix) taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + taskDataPar->inputs_count.emplace_back(rows); taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(res_vec_par.data())); + taskDataPar->outputs_count.emplace_back(res_vec_par.size()); } - auto testMpiTaskParallel = - std::make_shared(taskDataPar); + auto testMpiTaskParallel = std::make_shared(taskDataPar); ASSERT_EQ(testMpiTaskParallel->validation(), true); testMpiTaskParallel->pre_processing(); testMpiTaskParallel->run(); testMpiTaskParallel->post_processing(); + 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; + }; + + matrix_1 = matrix; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); + for (size_t i = 0; i < cols; i++) { + ASSERT_EQ(100, res_vec_par[i]); } + ppc::core::Perf::print_perf_statistic(perfResults); } } TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { boost::mpi::communicator world; + const int cols = 5000; + const int rows = 5000; + std::vector res_vec_par(cols, 0); + std::vector res_vec(cols, 0); + std::vector> matrix; + + std::vector> matrix_1; - std::vector> global_matr; - std::vector max_s; std::shared_ptr taskDataPar = std::make_shared(); - int rows = 7000; - int cols = 7000; if (world.rank() == 0) { - global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); - max_s.resize(cols, INT_MIN); - - for (auto& i : global_matr) { - taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - } + matrix = rand_matr_1(rows, cols); + for (auto& i : matrix) taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); taskDataPar->inputs_count.emplace_back(rows); taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); - taskDataPar->outputs_count.emplace_back(max_s.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(res_vec_par.data())); + taskDataPar->outputs_count.emplace_back(res_vec_par.size()); } auto testMpiTaskParallel = std::make_shared(taskDataPar); @@ -73,9 +115,26 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { testMpiTaskParallel->run(); testMpiTaskParallel->post_processing(); + 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; + }; + + matrix_1 = matrix; + + auto perfResults = std::make_shared(); + + auto perfAnalyzer = std::make_shared(testMpiTaskParallel); + perfAnalyzer->task_run(perfAttr, perfResults); + if (world.rank() == 0) { - for (size_t j = 0; j < max_s.size(); ++j) { - ASSERT_EQ(max_s[j], 200); + for (size_t i = 0; i < cols; i++) { + ASSERT_EQ(100, res_vec_par[i]); } + ppc::core::Perf::print_perf_statistic(perfResults); } -} +} \ No newline at end of file diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp index 0b149b9d14e..99d6c0cd223 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -5,7 +5,26 @@ #include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" -TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { +std::vector rand_vec_seq_1(int size, int down, int upp) { + std::vector v(size); + for (auto &number : v) number = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> rand_matr_seq_1(int rows, int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec_seq_1(cols, 0, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +TEST(gordeva_t_max_val_of_column_matrix_seq, Empty_Input) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); ASSERT_FALSE(testTaskSequential.validation()); @@ -30,8 +49,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + std::vector> matrix = rand_matr_seq_1(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -62,8 +81,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_ra std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + std::vector> matrix = rand_matr_seq_1(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -94,8 +113,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_r std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + std::vector> matrix = rand_matr_seq_1(rows, cols); + for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -120,7 +139,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_r } } -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_Input) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); @@ -146,4 +165,4 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { ASSERT_FALSE(testTaskSequential.validation()); delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} +} \ No newline at end of file diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp index 2ee62e9c724..2ba96429b47 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -5,6 +5,25 @@ #include "core/perf/include/perf.hpp" #include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" +std::vector rand_vec_seq_2(int size, int down, int upp) { + std::vector v(size); + for (auto &number : v) number = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> rand_matr_seq_2(int rows, int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec_seq_2(cols, 0, 200); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { const int cols = 5000; const int rows = 5000; @@ -13,8 +32,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { auto testTaskSequential = std::make_shared(taskDataSeq); - std::vector> matrix = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + std::vector> matrix = rand_matr_seq_2(rows, cols); for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); @@ -43,15 +61,14 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { } TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { - const int cols = 7000; - const int rows = 7000; + const int cols = 5000; + const int rows = 5000; std::shared_ptr taskDataSeq = std::make_shared(); auto testTaskSequential = std::make_shared(taskDataSeq); - std::vector> matr_rand = - gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); + std::vector> matr_rand = rand_matr_seq_2(rows, cols); for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); taskDataSeq->inputs_count.emplace_back(rows); @@ -76,4 +93,4 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { perfAnalyzer->task_run(perfAttr, perfResults); ppc::core::Perf::print_perf_statistic(perfResults); for (int i = 0; i < cols; i++) ASSERT_EQ(res_vec[i], 200); -} +} \ No newline at end of file From 5cccf694f05bf02aee337ac4210d01a1879d52fd Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 18:31:49 +0300 Subject: [PATCH 46/55] correct --- .../func_tests/main.cpp | 34 ++--- .../perf_tests/main.cpp | 117 +++++------------- .../func_tests/main.cpp | 38 ++---- .../perf_tests/main.cpp | 29 +---- 4 files changed, 52 insertions(+), 166 deletions(-) diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp index 9e9a43ba573..cd5ec3ec2d7 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -2,31 +2,11 @@ #include #include -#include #include #include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" -std::vector rand_vec_2(int s, int down, int upp) { - std::vector v(s); - for (auto& i : v) i = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> rand_matr_2(int rows, int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec_2(cols, -100, 100); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -TEST(gordeva_t_max_val_of_column_matrix_mpi, Empty_Input) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyInput) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -37,7 +17,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Empty_Input) { } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, Empty_Output) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, IsEmptyOutput) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -64,7 +44,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_columns_with_random) std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = rand_matr_2(rows, cols); + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -110,7 +90,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_500_1000_columns_with_ra std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = rand_matr_2(rows, cols); + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -158,7 +138,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_r std::shared_ptr taskDataPar = std::make_shared(); if (world.rank() == 0) { - global_matr = rand_matr_2(rows, cols); + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); for (unsigned int i = 0; i < global_matr.size(); i++) { taskDataPar->inputs.emplace_back(reinterpret_cast(global_matr[i].data())); } @@ -195,7 +175,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Max_val_of_1000_3000_columns_with_r } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_input) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_size_of_input) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); @@ -212,7 +192,7 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_input) { } } -TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_output) { +TEST(gordeva_t_max_val_of_column_matrix_mpi, Incorrect_val_of_output) { boost::mpi::communicator world; std::shared_ptr taskDataPar = std::make_shared(); diff --git a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp index 0d196490cfa..7dd8ef1f6c6 100644 --- a/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ b/tasks/mpi/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -2,110 +2,68 @@ #include #include -#include #include #include "core/perf/include/perf.hpp" #include "mpi/gordeva_t_max_val_of_column_matrix/include/ops_mpi.hpp" -std::vector rand_vec_1(int s, int down, int upp) { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(down, upp); - - std::vector v(s); - for (auto& number : v) { - number = dis(gen); - } - return v; -} - -std::vector> rand_matr_1(int rows, int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec_1(cols, 0, 100); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - TEST(gordeva_t_max_val_of_column_matrix_mpi, test_pipeline_run) { boost::mpi::communicator world; - const int cols = 5000; - const int rows = 5000; - std::vector res_vec_par(cols, 0); - std::vector res_vec(cols, 0); - std::vector> matrix; - - std::vector> matrix_1; + std::vector> global_matr; + std::vector max_s; std::shared_ptr taskDataPar = std::make_shared(); + int rows = 5000; + int cols = 5000; if (world.rank() == 0) { - matrix = rand_matr_1(rows, cols); - for (auto& i : matrix) taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); - + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } taskDataPar->inputs_count.emplace_back(rows); taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(res_vec_par.data())); - taskDataPar->outputs_count.emplace_back(res_vec_par.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); } - auto testMpiTaskParallel = std::make_shared(taskDataPar); + auto testMpiTaskParallel = + std::make_shared(taskDataPar); ASSERT_EQ(testMpiTaskParallel->validation(), true); testMpiTaskParallel->pre_processing(); testMpiTaskParallel->run(); testMpiTaskParallel->post_processing(); - 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; - }; - - matrix_1 = matrix; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - if (world.rank() == 0) { - for (size_t i = 0; i < cols; i++) { - ASSERT_EQ(100, res_vec_par[i]); + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); } - ppc::core::Perf::print_perf_statistic(perfResults); } } TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { boost::mpi::communicator world; - const int cols = 5000; - const int rows = 5000; - std::vector res_vec_par(cols, 0); - std::vector res_vec(cols, 0); - std::vector> matrix; - - std::vector> matrix_1; + std::vector> global_matr; + std::vector max_s; std::shared_ptr taskDataPar = std::make_shared(); + int rows = 7000; + int cols = 7000; if (world.rank() == 0) { - matrix = rand_matr_1(rows, cols); - for (auto& i : matrix) taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + global_matr = gordeva_t_max_val_of_column_matrix_mpi::TestMPITaskSequential::rand_matr(rows, cols); + max_s.resize(cols, INT_MIN); + + for (auto& i : global_matr) { + taskDataPar->inputs.emplace_back(reinterpret_cast(i.data())); + } taskDataPar->inputs_count.emplace_back(rows); taskDataPar->inputs_count.emplace_back(cols); - taskDataPar->outputs.emplace_back(reinterpret_cast(res_vec_par.data())); - taskDataPar->outputs_count.emplace_back(res_vec_par.size()); + taskDataPar->outputs.emplace_back(reinterpret_cast(max_s.data())); + taskDataPar->outputs_count.emplace_back(max_s.size()); } auto testMpiTaskParallel = std::make_shared(taskDataPar); @@ -115,26 +73,9 @@ TEST(gordeva_t_max_val_of_column_matrix_mpi, test_task_run) { testMpiTaskParallel->run(); testMpiTaskParallel->post_processing(); - 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; - }; - - matrix_1 = matrix; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - if (world.rank() == 0) { - for (size_t i = 0; i < cols; i++) { - ASSERT_EQ(100, res_vec_par[i]); + for (size_t j = 0; j < max_s.size(); ++j) { + ASSERT_EQ(max_s[j], 200); } - ppc::core::Perf::print_perf_statistic(perfResults); } } \ No newline at end of file diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp index 99d6c0cd223..b39178160ca 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -1,3 +1,4 @@ + #include #include @@ -5,26 +6,7 @@ #include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" -std::vector rand_vec_seq_1(int size, int down, int upp) { - std::vector v(size); - for (auto &number : v) number = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> rand_matr_seq_1(int rows, int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec_seq_1(cols, 0, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - -TEST(gordeva_t_max_val_of_column_matrix_seq, Empty_Input) { +TEST(gordeva_t_max_val_of_column_matrix_seq, IsEmptyInput) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); ASSERT_FALSE(testTaskSequential.validation()); @@ -49,8 +31,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_columns_with_random) std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = rand_matr_seq_1(rows, cols); - + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -81,8 +63,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_ra std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = rand_matr_seq_1(rows, cols); - + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -113,8 +95,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_r std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); - std::vector> matrix = rand_matr_seq_1(rows, cols); - + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); taskDataSeq->inputs_count.emplace_back(rows); taskDataSeq->inputs_count.emplace_back(cols); @@ -139,7 +121,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_r } } -TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_Input) { +TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_size_of_input) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); @@ -165,4 +147,4 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { ASSERT_FALSE(testTaskSequential.validation()); delete[] reinterpret_cast(taskDataSeq->inputs[0]); -} \ No newline at end of file +} diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp index 2ba96429b47..d6e346114da 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/perf_tests/main.cpp @@ -5,25 +5,6 @@ #include "core/perf/include/perf.hpp" #include "seq/gordeva_t_max_val_of_column_matrix/include/ops_seq.hpp" -std::vector rand_vec_seq_2(int size, int down, int upp) { - std::vector v(size); - for (auto &number : v) number = down + (std::rand() % (upp - down + 1)); - return v; -} - -std::vector> rand_matr_seq_2(int rows, int cols) { - std::vector> matr(rows, std::vector(cols)); - - for (int i = 0; i < rows; ++i) { - matr[i] = rand_vec_seq_2(cols, 0, 200); - } - for (int j = 0; j < cols; ++j) { - int row_rand = std::rand() % rows; - matr[row_rand][j] = 10; - } - return matr; -} - TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { const int cols = 5000; const int rows = 5000; @@ -32,7 +13,8 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { auto testTaskSequential = std::make_shared(taskDataSeq); - std::vector> matrix = rand_matr_seq_2(rows, cols); + std::vector> matrix = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); for (auto &i : matrix) taskDataSeq->inputs.emplace_back(reinterpret_cast(i.data())); @@ -61,14 +43,15 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, test_pipeline_run) { } TEST(gordeva_t_max_val_of_column_matrix_seq, test_task_run) { - const int cols = 5000; - const int rows = 5000; + const int cols = 7000; + const int rows = 7000; std::shared_ptr taskDataSeq = std::make_shared(); auto testTaskSequential = std::make_shared(taskDataSeq); - std::vector> matr_rand = rand_matr_seq_2(rows, cols); + std::vector> matr_rand = + gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(rows, cols); for (auto &row : matr_rand) taskDataSeq->inputs.emplace_back(reinterpret_cast(row.data())); taskDataSeq->inputs_count.emplace_back(rows); From d7f824aa9dd1b1b2636c7f486678d256a1b659e3 Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 18:33:48 +0300 Subject: [PATCH 47/55] 1 --- .../src/ops_seq.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp index df2a39e60a0..7e99938f766 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -57,4 +57,24 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing return true; } -} // namespace gordeva_t_max_val_of_column_matrix_seq +std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { + std::vector v(size); + for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); + return v; +} + +std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, + int cols) { + std::vector> matr(rows, std::vector(cols)); + + for (int i = 0; i < rows; ++i) { + matr[i] = rand_vec(cols, -500, 500); + } + for (int j = 0; j < cols; ++j) { + int row_rand = std::rand() % rows; + matr[row_rand][j] = 10; + } + return matr; +} + +} // namespace gordeva_t_max_val_of_column_matrix_seq \ No newline at end of file From 081d2801cc33abbd6e1ddc587b956a898ad4c4fb Mon Sep 17 00:00:00 2001 From: TayaGordeeva Date: Sun, 29 Dec 2024 19:01:07 +0300 Subject: [PATCH 48/55] 111 --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index 8012c0b8c93..bfd1c5ee6a9 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -60,7 +60,6 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_End_To_End1) { taskDataPar->inputs_count.emplace_back(max_waiting_chairs); taskDataPar->outputs.emplace_back(reinterpret_cast(&global_res)); taskDataPar->outputs_count.emplace_back(sizeof(global_res)); - gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); if (world.size() < 3) { From cc67844726b5e1e422f5b37188e97a11f56d85e6 Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:21:58 +0300 Subject: [PATCH 49/55] plsplspls --- .../seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp index 2b0a7495e7c..bed8f52d305 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/src/ops_seq.cpp @@ -56,15 +56,15 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing std::copy(res_.begin(), res_.end(), output_matr); return true; } - +// done //<<<<<<< gordeeva_sleeping_barber_test -//std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { +// std::vector gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_vec(int size, int down, int upp) { // std::vector v(size); // for (auto& number : v) number = down + (std::rand() % (upp - down + 1)); // return v; //} // -//std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, +// std::vector> gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::rand_matr(int rows, // int cols) { // std::vector> matr(rows, std::vector(cols)); // @@ -82,3 +82,4 @@ bool gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential::post_processing //======= } // namespace gordeva_t_max_val_of_column_matrix_seq //>>>>>>> master +// done From 48cbbc8e9bd6d332469359730f6373762d60dfdc Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:30:19 +0300 Subject: [PATCH 50/55] doooone --- .../seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp index 10b579a8e67..e4eb1ea00e0 100644 --- a/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp +++ b/tasks/seq/gordeva_t_max_val_of_column_matrix/func_tests/main.cpp @@ -108,6 +108,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_500_1000_columns_with_ra } } +// 1 TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_random) { const int rows = 1000; const int cols = 3000; @@ -140,6 +141,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Max_val_of_1000_3000_columns_with_r } } +// 2 TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_Input) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); @@ -154,6 +156,7 @@ TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_Input) { delete[] reinterpret_cast(taskDataSeq->inputs[0]); } +// 3 TEST(gordeva_t_max_val_of_column_matrix_seq, Incorrect_val_of_output) { std::shared_ptr taskDataSeq = std::make_shared(); gordeva_t_max_val_of_column_matrix_seq::TestTaskSequential testTaskSequential(taskDataSeq); From 0d6efab8906317354a5f4c3524ba31c99e161e2d Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:32:33 +0300 Subject: [PATCH 51/55] yees --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index bfd1c5ee6a9..8d11811132b 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -8,7 +8,10 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { boost::mpi::communicator world; - + int i = 0; + int j = 0; + int k = 0; + std::shared_ptr taskDataPar = std::make_shared(); gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); From f20b21d05ab1027f06d8d70d62cde97ef0201f07 Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:34:56 +0300 Subject: [PATCH 52/55] correeeend --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index 8d11811132b..c4f0205b172 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -11,7 +11,7 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { int i = 0; int j = 0; int k = 0; - + std::shared_ptr taskDataPar = std::make_shared(); gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); From 3447da601cc77aa3d3f29d6cb4591ee0055945f6 Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 20:58:52 +0300 Subject: [PATCH 53/55] Done result --- tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp index c4f0205b172..bfd1c5ee6a9 100644 --- a/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_sleeping_barber/func_tests/main.cpp @@ -8,9 +8,6 @@ TEST(gordeeva_t_sleeping_barber_mpi, Test_Validation1) { boost::mpi::communicator world; - int i = 0; - int j = 0; - int k = 0; std::shared_ptr taskDataPar = std::make_shared(); gordeeva_t_sleeping_barber_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); From 4244f4d391a2afaffd01b1b686ca2d9dbb7c1c0b Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:19:44 +0300 Subject: [PATCH 54/55] Update --- .../mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp index 5cc25ee70be..877e637ee40 100644 --- a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp @@ -23,7 +23,6 @@ std::vector rand_vec(int size, int down = -100, int upp = 100) { TEST(gordeeva_t_shell_sort_batcher_merge_mpi, Shell_sort_with_fixed) { boost::mpi::environment env; boost::mpi::communicator world; - const int size = 10; std::vector input_vec = {3, 4, 7, 1, 8, 9, 5, 2, 6, 0}; std::vector result_parallel(size); From 5df62a03223174b7a95ad935996a7363e854d9d8 Mon Sep 17 00:00:00 2001 From: TayaGordeeva <121258487+TayaGordeeva@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:25:03 +0300 Subject: [PATCH 55/55] Update --- .../mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp index 877e637ee40..aa30a9a29cc 100644 --- a/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp +++ b/tasks/mpi/gordeeva_t_shell_sort_batcher_merge/func_tests/main.cpp @@ -12,7 +12,6 @@ std::vector rand_vec(int size, int down = -100, int upp = 100) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(down, upp); - std::vector v(size); for (auto &number : v) { number = dis(gen);