From 5af50988e4c4f3c50dc554755c8c31c05719babe Mon Sep 17 00:00:00 2001 From: Irina Sharamygina Date: Wed, 4 Dec 2024 15:31:07 +0300 Subject: [PATCH 01/16] First commit --- .../func_tests/main.cpp | 371 ++++++++++++++++++ .../include/ops_mpi.h | 29 ++ .../perf_tests/main.cpp | 116 ++++++ .../src/ops_mpi.cpp | 76 ++++ 4 files changed, 592 insertions(+) create mode 100644 tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp create mode 100644 tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h create mode 100644 tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp create mode 100644 tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp new file mode 100644 index 00000000000..322e7c58852 --- /dev/null +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -0,0 +1,371 @@ +#include + +#include +#include +#include +#include + +#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" + +namespace sharamygina_i_line_topology_mpi { + void generator(std::vector& v) { + std::random_device dev; + std::mt19937 gen(dev()); + for (size_t i = 0; i < v.size(); ++i) { + v[i] = -1000 + gen() % 1000; + } + } +} // namespace sharamygina_i_line_topology_mpi + +TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { + boost::mpi::communicator world; + + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + //ASSERT_EQ(received_data.size(), data.size()); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, transferRandomData) { + boost::mpi::communicator world; + + int size = 20000; + + std::srand(static_cast(std::time(NULL))); + int sendler = std::rand() % (world.size()); + int recipient = sendler + std::rand() % (world.size() - sendler); + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + //ASSERT_EQ(received_data.size(), data.size()); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + +TEST(sharamygina_i_line_topology_mpi, invalidSendler) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = -1; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + +TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { + boost::mpi::communicator world; + + int size = 10000; + int sendler = 0; + int recipient = -1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + +TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { + boost::mpi::communicator world; + + int size = -10; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + +TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == sendler) { + ASSERT_FALSE(testTask.validation()); + } + else { + SUCCEED(); + } +} + +TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { + boost::mpi::communicator world; + + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data; + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == recipient) { + ASSERT_FALSE(testTask.validation()); + } + else { + SUCCEED(); + } +} + +TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { + boost::mpi::communicator world; + + int size = 0; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + +TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } + + if (world.rank() == sendler) { + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); +} + + +TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { + boost::mpi::communicator world; + + int size = 1024; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + //ASSERT_EQ(received_data.size(), data.size()); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + + +TEST(sharamygina_i_line_topology_mpi, smallSetVector) { + boost::mpi::communicator world; + + int size = 12; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data{ 1, 2, 4, -8, 16, 32, -64, 128, 256, -512, 1024, 2048 }; + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + //ASSERT_EQ(received_data.size(), data.size()); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h new file mode 100644 index 00000000000..2672ac4ab34 --- /dev/null +++ b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h @@ -0,0 +1,29 @@ +#pragma once +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace sharamygina_i_line_topology_mpi { + + class line_topology_mpi : public ppc::core::Task { + public: + explicit line_topology_mpi(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 message; + boost::mpi::communicator world; + }; + +} // namespace sharamygina_i_line_topology_mpi \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp new file mode 100644 index 00000000000..7aabbc2a7f3 --- /dev/null +++ b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp @@ -0,0 +1,116 @@ +#include + +#include +#include + +#include "core/perf/include/perf.hpp" +#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" + +TEST(sharamygina_i_line_topology_mpi, test_task_run) { + boost::mpi::communicator world; + int size = 10000000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size, 0); + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + auto testTask = std::make_shared(taskData); + + 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(testTask); + perfAnalyzer->task_run(perfAttr, perfResults); + + if (world.rank() == recipient) { + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, test_pipeline_run) { + boost::mpi::communicator world; + int size = 10000000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size, 0); + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + + if (world.rank() == recipient) { + + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + auto testTask = std::make_shared(taskData); + + // Create Perf attributes + auto perfAttr = std::make_shared(); + perfAttr->num_running = 10; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + + // Create and init perf results + auto perfResults = std::make_shared(); + + // Create Perf analyzer + auto perfAnalyzer = std::make_shared(testTask); + perfAnalyzer->pipeline_run(perfAttr, perfResults); + + if (world.rank() == recipient) { + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp new file mode 100644 index 00000000000..789bec30cf3 --- /dev/null +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -0,0 +1,76 @@ + +#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" + +#include +#include +#include +#include +#include +#include + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { + internal_order_test(); + + int sendler = taskData->inputs_count[0]; + int msize = taskData->inputs_count[2]; + + if (world.rank() == sendler) { + auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); + message.assign(inputBuffer, inputBuffer + msize); + } + + return true; +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { + internal_order_test(); + + if (taskData->inputs_count.size() < 3) return false; + + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; + int msize = taskData->inputs_count[2]; + + return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && + ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && + ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { + internal_order_test(); + + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; + + if (sendler == recipient) { + return true; + } + + if (world.rank() < sendler || world.rank() > recipient) { + return true; + } + if (world.rank() == sendler) { + world.send(world.rank() + 1, 0, message); + } + else { + world.recv(world.rank() - 1, 0, message); + if (world.rank() < recipient) { + world.send(world.rank() + 1, 0, message); + } + } + + return true; +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { + internal_order_test(); + + int recipient = taskData->inputs_count[1]; + + if (world.rank() == recipient) { + auto* mptr = reinterpret_cast(taskData->outputs[0]); + std::copy(message.begin(), message.end(), mptr); + } + + return true; +} \ No newline at end of file From bd8b195a662620a102cb45f7f527511030e812e6 Mon Sep 17 00:00:00 2001 From: Irina Sharamygina Date: Wed, 4 Dec 2024 17:54:42 +0300 Subject: [PATCH 02/16] commit changes --- .../func_tests/main.cpp | 504 +++++++++--------- .../include/ops_mpi.h | 22 +- .../perf_tests/main.cpp | 164 +++--- .../src/ops_mpi.cpp | 81 ++- 4 files changed, 376 insertions(+), 395 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 322e7c58852..58d0650f1f3 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -2,370 +2,354 @@ #include #include -#include #include +#include #include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" namespace sharamygina_i_line_topology_mpi { - void generator(std::vector& v) { - std::random_device dev; - std::mt19937 gen(dev()); - for (size_t i = 0; i < v.size(); ++i) { - v[i] = -1000 + gen() % 1000; - } - } +void generator(std::vector& v) { + std::random_device dev; + std::mt19937 gen(dev()); + for (size_t i = 0; i < v.size(); ++i) { + v[i] = -1000 + gen() % 1000; + } +} } // namespace sharamygina_i_line_topology_mpi TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { - boost::mpi::communicator world; - - int size = 20000; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { + boost::mpi::communicator world; - if (sendler != recipient) { - world.recv(sendler, 0, data); - } + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; - received_data.resize(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - //ASSERT_EQ(received_data.size(), data.size()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } TEST(sharamygina_i_line_topology_mpi, transferRandomData) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; + int size = 20000; - std::srand(static_cast(std::time(NULL))); - int sendler = std::rand() % (world.size()); - int recipient = sendler + std::rand() % (world.size() - sendler); + std::srand(static_cast(std::time(NULL))); + int sendler = std::rand() % (world.size()); + int recipient = sendler + std::rand() % (world.size() - sendler); - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - std::vector data(size); - std::vector received_data; + std::vector data(size); + std::vector received_data; - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); } - if (world.rank() == recipient) { - - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - //ASSERT_EQ(received_data.size(), data.size()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; - int sendler = 0; + int size = 20000; + int sendler = 0; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidSendler) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; - int sendler = -1; - int recipient = world.size() - 1; + int size = 20000; + int sendler = -1; + int recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 10000; - int sendler = 0; - int recipient = -1; + int size = 10000; + int sendler = 0; + int recipient = -1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = -10; - int sendler = 0; - int recipient = world.size() - 1; + int size = -10; + int sendler = 0; + int recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; - int sendler = 0; - int recipient = world.size() - 1; + int size = 20000; + int sendler = 0; + int recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == sendler) { - ASSERT_FALSE(testTask.validation()); - } - else { - SUCCEED(); - } + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == sendler) { + ASSERT_FALSE(testTask.validation()); + } else { + SUCCEED(); + } } TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; - auto sendler = 0; - auto recipient = world.size() - 1; + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - std::vector data; - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - } + std::vector data; + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == recipient) { - ASSERT_FALSE(testTask.validation()); - } - else { - SUCCEED(); - } + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == recipient) { + ASSERT_FALSE(testTask.validation()); + } else { + SUCCEED(); + } } TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 0; - int sendler = 0; - int recipient = world.size() - 1; + int size = 0; + int sendler = 0; + int recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 20000; - int sendler = 0; + int size = 20000; + int sendler = 0; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); - std::vector data(size); - std::vector received_data; + std::vector data(size); + std::vector received_data; - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - } + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } - if (world.rank() == sendler) { - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } + if (world.rank() == sendler) { + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_FALSE(testTask.validation()); } - TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { - boost::mpi::communicator world; - - int size = 1024; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { + boost::mpi::communicator world; + + int size = 1024; + auto sendler = 0; + auto recipient = world.size() - 1; - if (sendler != recipient) { - world.recv(sendler, 0, data); - } + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - received_data.resize(size); + std::vector data(size); + std::vector received_data; - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); + received_data.resize(size); - //ASSERT_EQ(received_data.size(), data.size()); + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } - TEST(sharamygina_i_line_topology_mpi, smallSetVector) { - boost::mpi::communicator world; + boost::mpi::communicator world; - int size = 12; - auto sendler = 0; - auto recipient = world.size() - 1; + int size = 12; + auto sendler = 0; + auto recipient = world.size() - 1; - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); - std::vector data{ 1, 2, 4, -8, 16, 32, -64, 128, 256, -512, 1024, 2048 }; - std::vector received_data; + std::vector data{1, 2, 4, -8, 16, 32, -64, 128, 256, -512, 1024, 2048}; + std::vector received_data; - if (world.rank() == sendler) { - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); } - if (world.rank() == recipient) { - - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); } - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - //ASSERT_EQ(received_data.size(), data.size()); + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h index 2672ac4ab34..de4bd55bea9 100644 --- a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h +++ b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h @@ -13,17 +13,17 @@ namespace sharamygina_i_line_topology_mpi { - class line_topology_mpi : public ppc::core::Task { - public: - explicit line_topology_mpi(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; +class line_topology_mpi : public ppc::core::Task { + public: + explicit line_topology_mpi(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 message; - boost::mpi::communicator world; - }; + private: + std::vector message; + boost::mpi::communicator world; +}; } // namespace sharamygina_i_line_topology_mpi \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp index 7aabbc2a7f3..bfbc7b9a85d 100644 --- a/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp @@ -7,110 +7,108 @@ #include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" TEST(sharamygina_i_line_topology_mpi, test_task_run) { - boost::mpi::communicator world; - int size = 10000000; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size, 0); - std::vector received_data; - - if (world.rank() == sendler) { - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } + boost::mpi::communicator world; + int size = 10000000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size, 0); + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); } + } - if (world.rank() == recipient) { - - if (sendler != recipient) { - world.recv(sendler, 0, data); - } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } - received_data.resize(size); + received_data.resize(size); - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - auto testTask = std::make_shared(taskData); + auto testTask = std::make_shared(taskData); - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + 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 perfResults = std::make_shared(); - auto perfAnalyzer = std::make_shared(testTask); - perfAnalyzer->task_run(perfAttr, perfResults); + auto perfAnalyzer = std::make_shared(testTask); + perfAnalyzer->task_run(perfAttr, perfResults); - if (world.rank() == recipient) { - ppc::core::Perf::print_perf_statistic(perfResults); - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + if (world.rank() == recipient) { + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } TEST(sharamygina_i_line_topology_mpi, test_pipeline_run) { - boost::mpi::communicator world; - int size = 10000000; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size, 0); - std::vector received_data; - - if (world.rank() == sendler) { - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } + boost::mpi::communicator world; + int size = 10000000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size, 0); + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); } + } - if (world.rank() == recipient) { - - if (sendler != recipient) { - world.recv(sendler, 0, data); - } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } - received_data.resize(size); + received_data.resize(size); - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } - auto testTask = std::make_shared(taskData); + auto testTask = std::make_shared(taskData); - // Create Perf attributes - auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; + // Create Perf attributes + auto perfAttr = std::make_shared(); + perfAttr->num_running = 10; + const boost::mpi::timer current_timer; + perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - // Create and init perf results - auto perfResults = std::make_shared(); + // Create and init perf results + auto perfResults = std::make_shared(); - // Create Perf analyzer - auto perfAnalyzer = std::make_shared(testTask); - perfAnalyzer->pipeline_run(perfAttr, perfResults); + // Create Perf analyzer + auto perfAnalyzer = std::make_shared(testTask); + perfAnalyzer->pipeline_run(perfAttr, perfResults); - if (world.rank() == recipient) { - ppc::core::Perf::print_perf_statistic(perfResults); - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } + if (world.rank() == recipient) { + ppc::core::Perf::print_perf_statistic(perfResults); + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); } + } } \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp index 789bec30cf3..bb63d201e0f 100644 --- a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -9,68 +9,67 @@ #include bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { - internal_order_test(); + internal_order_test(); - int sendler = taskData->inputs_count[0]; - int msize = taskData->inputs_count[2]; + int sendler = taskData->inputs_count[0]; + int msize = taskData->inputs_count[2]; - if (world.rank() == sendler) { - auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); - message.assign(inputBuffer, inputBuffer + msize); - } + if (world.rank() == sendler) { + auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); + message.assign(inputBuffer, inputBuffer + msize); + } - return true; + return true; } bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { - internal_order_test(); + internal_order_test(); - if (taskData->inputs_count.size() < 3) return false; + if (taskData->inputs_count.size() < 3) return false; - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; - int msize = taskData->inputs_count[2]; + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; + int msize = taskData->inputs_count[2]; - return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && - ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && - ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); + return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && + ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && + ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); } bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { - internal_order_test(); + internal_order_test(); - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; - if (sendler == recipient) { - return true; - } + if (sendler == recipient) { + return true; + } - if (world.rank() < sendler || world.rank() > recipient) { - return true; - } - if (world.rank() == sendler) { - world.send(world.rank() + 1, 0, message); - } - else { - world.recv(world.rank() - 1, 0, message); - if (world.rank() < recipient) { - world.send(world.rank() + 1, 0, message); - } + if (world.rank() < sendler || world.rank() > recipient) { + return true; + } + if (world.rank() == sendler) { + world.send(world.rank() + 1, 0, message); + } else { + world.recv(world.rank() - 1, 0, message); + if (world.rank() < recipient) { + world.send(world.rank() + 1, 0, message); } + } - return true; + return true; } bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { - internal_order_test(); + internal_order_test(); - int recipient = taskData->inputs_count[1]; + int recipient = taskData->inputs_count[1]; - if (world.rank() == recipient) { - auto* mptr = reinterpret_cast(taskData->outputs[0]); - std::copy(message.begin(), message.end(), mptr); - } + if (world.rank() == recipient) { + auto* mptr = reinterpret_cast(taskData->outputs[0]); + std::copy(message.begin(), message.end(), mptr); + } - return true; + return true; } \ No newline at end of file From 3a435088d84f384ce592457da1b198266a9685b4 Mon Sep 17 00:00:00 2001 From: Irina Sharamygina Date: Wed, 4 Dec 2024 19:59:50 +0300 Subject: [PATCH 03/16] commit changes --- .../func_tests/main.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 58d0650f1f3..b38ee9efe90 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -51,7 +51,7 @@ TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); + if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -99,7 +99,7 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); + if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -122,7 +122,7 @@ TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidSendler) { @@ -138,7 +138,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { @@ -154,7 +154,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { @@ -170,7 +170,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { @@ -232,7 +232,7 @@ TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { @@ -260,7 +260,7 @@ TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { @@ -297,7 +297,7 @@ TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); + if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -342,7 +342,7 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); + if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); testTask.pre_processing(); testTask.run(); testTask.post_processing(); From 45d1b2f882f66cfc3e03439fa8561eecd3f166c7 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:46:19 +0300 Subject: [PATCH 04/16] Add files via upload --- .../func_tests/main.cpp | 728 +++++++++--------- .../include/ops_mpi.h | 56 +- .../src/ops_mpi.cpp | 148 ++-- 3 files changed, 476 insertions(+), 456 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index b38ee9efe90..30ea1ad972b 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -1,355 +1,375 @@ -#include - -#include -#include -#include -#include - -#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" - -namespace sharamygina_i_line_topology_mpi { -void generator(std::vector& v) { - std::random_device dev; - std::mt19937 gen(dev()); - for (size_t i = 0; i < v.size(); ++i) { - v[i] = -1000 + gen() % 1000; - } -} -} // namespace sharamygina_i_line_topology_mpi - -TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { - boost::mpi::communicator world; - - int size = 20000; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); - - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } - } -} - -TEST(sharamygina_i_line_topology_mpi, transferRandomData) { - boost::mpi::communicator world; - - int size = 20000; - - std::srand(static_cast(std::time(NULL))); - int sendler = std::rand() % (world.size()); - int recipient = sendler + std::rand() % (world.size() - sendler); - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); - - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } - } -} - -TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { - boost::mpi::communicator world; - - int size = 20000; - int sendler = 0; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, invalidSendler) { - boost::mpi::communicator world; - - int size = 20000; - int sendler = -1; - int recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { - boost::mpi::communicator world; - - int size = 10000; - int sendler = 0; - int recipient = -1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { - boost::mpi::communicator world; - - int size = -10; - int sendler = 0; - int recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { - boost::mpi::communicator world; - - int size = 20000; - int sendler = 0; - int recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == sendler) { - ASSERT_FALSE(testTask.validation()); - } else { - SUCCEED(); - } -} - -TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { - boost::mpi::communicator world; - - int size = 20000; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data; - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == recipient) { - ASSERT_FALSE(testTask.validation()); - } else { - SUCCEED(); - } -} - -TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { - boost::mpi::communicator world; - - int size = 0; - int sendler = 0; - int recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { - boost::mpi::communicator world; - - int size = 20000; - int sendler = 0; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - } - - if (world.rank() == sendler) { - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_FALSE(testTask.validation()); -} - -TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { - boost::mpi::communicator world; - - int size = 1024; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); - - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } - } -} - -TEST(sharamygina_i_line_topology_mpi, smallSetVector) { - boost::mpi::communicator world; - - int size = 12; - auto sendler = 0; - auto recipient = world.size() - 1; - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data{1, 2, 4, -8, 16, 32, -64, 128, 256, -512, 1024, 2048}; - std::vector received_data; - - if (world.rank() == sendler) { - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) ASSERT_EQ(testTask.validation(), true); - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); - - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } - } +#include + +#include +#include +#include +#include + +#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" + +namespace sharamygina_i_line_topology_mpi { +void generator(std::vector& v) { + std::random_device dev; + std::mt19937 gen(dev()); + for (size_t i = 0; i < v.size(); ++i) { + v[i] = -1000 + gen() % 1000; + } +} +} // namespace sharamygina_i_line_topology_mpi + +TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { + boost::mpi::communicator world; + + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_EQ(testTask.validation(), true); + } + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, transferRandomData) { + boost::mpi::communicator world; + + int size = 20000; + + std::srand(static_cast(std::time(NULL))); + int sendler = std::rand() % (world.size()); + int recipient = sendler + std::rand() % (world.size() - sendler); + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == sendler) { + ASSERT_EQ(testTask.validation(), true); + } + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, invalidSendler) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = -1; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { + boost::mpi::communicator world; + + int size = 10000; + int sendler = 0; + int recipient = -1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { + boost::mpi::communicator world; + + int size = -10; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == sendler) { + ASSERT_FALSE(testTask.validation()); + } else { + SUCCEED(); + } +} + +TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { + boost::mpi::communicator world; + + int size = 20000; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data; + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == recipient) { + ASSERT_FALSE(testTask.validation()); + } else { + SUCCEED(); + } +} + +TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { + boost::mpi::communicator world; + + int size = 0; + int sendler = 0; + int recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { + boost::mpi::communicator world; + + int size = 20000; + int sendler = 0; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + } + + if (world.rank() == sendler) { + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } +} + +TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { + boost::mpi::communicator world; + + int size = 1024; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data(size); + std::vector received_data; + + if (world.rank() == sendler) { + sharamygina_i_line_topology_mpi::generator(data); + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_EQ(testTask.validation(), true); + } + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } +} + +TEST(sharamygina_i_line_topology_mpi, smallSetVector) { + boost::mpi::communicator world; + + int size = 12; + auto sendler = 0; + auto recipient = world.size() - 1; + + std::shared_ptr taskData = std::make_shared(); + taskData->inputs_count.emplace_back(sendler); + taskData->inputs_count.emplace_back(recipient); + taskData->inputs_count.emplace_back(size); + + std::vector data{1, 2, 4, -8, 16, 32, -64, 128, 256, -512, 1024, 2048}; + std::vector received_data; + + if (world.rank() == sendler) { + taskData->inputs.emplace_back(reinterpret_cast(data.data())); + if (sendler != recipient) { + world.send(recipient, 0, data); + } + } + if (world.rank() == recipient) { + if (sendler != recipient) { + world.recv(sendler, 0, data); + } + + received_data.resize(size); + + taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); + taskData->outputs_count.emplace_back(received_data.size()); + } + + sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); + if (world.rank() == 0) { + ASSERT_EQ(testTask.validation(), true); + } + testTask.pre_processing(); + testTask.run(); + testTask.post_processing(); + + if (world.rank() == recipient) { + for (int i = 0; i < size; i++) { + ASSERT_EQ(received_data[i], data[i]); + } + } } \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h index de4bd55bea9..bcaa5f7684b 100644 --- a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h +++ b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h @@ -1,29 +1,29 @@ -#pragma once -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace sharamygina_i_line_topology_mpi { - -class line_topology_mpi : public ppc::core::Task { - public: - explicit line_topology_mpi(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 message; - boost::mpi::communicator world; -}; - +#pragma once +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "core/task/include/task.hpp" + +namespace sharamygina_i_line_topology_mpi { + +class line_topology_mpi : public ppc::core::Task { + public: + explicit line_topology_mpi(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 message; + boost::mpi::communicator world; +}; + } // namespace sharamygina_i_line_topology_mpi \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp index bb63d201e0f..ad9cb6849a4 100644 --- a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -1,75 +1,75 @@ - -#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" - -#include -#include -#include -#include -#include -#include - -bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { - internal_order_test(); - - int sendler = taskData->inputs_count[0]; - int msize = taskData->inputs_count[2]; - - if (world.rank() == sendler) { - auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); - message.assign(inputBuffer, inputBuffer + msize); - } - - return true; -} - -bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { - internal_order_test(); - - if (taskData->inputs_count.size() < 3) return false; - - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; - int msize = taskData->inputs_count[2]; - - return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && - ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && - ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); -} - -bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { - internal_order_test(); - - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; - - if (sendler == recipient) { - return true; - } - - if (world.rank() < sendler || world.rank() > recipient) { - return true; - } - if (world.rank() == sendler) { - world.send(world.rank() + 1, 0, message); - } else { - world.recv(world.rank() - 1, 0, message); - if (world.rank() < recipient) { - world.send(world.rank() + 1, 0, message); - } - } - - return true; -} - -bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { - internal_order_test(); - - int recipient = taskData->inputs_count[1]; - - if (world.rank() == recipient) { - auto* mptr = reinterpret_cast(taskData->outputs[0]); - std::copy(message.begin(), message.end(), mptr); - } - - return true; + +#include "mpi/sharamygina_i_line_topology/include/ops_mpi.h" + +#include +#include +#include +#include +#include +#include + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { + internal_order_test(); + + int sendler = taskData->inputs_count[0]; + int msize = taskData->inputs_count[2]; + + if (world.rank() == sendler) { + auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); + message.assign(inputBuffer, inputBuffer + msize); + } + + return true; +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { + internal_order_test(); + + if (taskData->inputs_count.size() < 3) return false; + + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; + int msize = taskData->inputs_count[2]; + + return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && + ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && + ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { + internal_order_test(); + + int sendler = taskData->inputs_count[0]; + int recipient = taskData->inputs_count[1]; + + if (sendler == recipient) { + return true; + } + + if (world.rank() < sendler || world.rank() > recipient) { + return true; + } + if (world.rank() == sendler) { + world.send(world.rank() + 1, 0, message); + } else { + world.recv(world.rank() - 1, 0, message); + if (world.rank() < recipient) { + world.send(world.rank() + 1, 0, message); + } + } + + return true; +} + +bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { + internal_order_test(); + + int recipient = taskData->inputs_count[1]; + + if (world.rank() == recipient) { + auto* mptr = reinterpret_cast(taskData->outputs[0]); + std::copy(message.begin(), message.end(), mptr); + } + + return true; } \ No newline at end of file From 17f9dfd05d4e008e395a152b2197e9a67dab9e53 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:55:19 +0300 Subject: [PATCH 05/16] Add files via upload --- tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 30ea1ad972b..0cb8fa57267 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -145,7 +145,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); + ASSERT_FALSE(testTask.validation()); } } @@ -163,7 +163,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); + ASSERT_FALSE(testTask.validation()); } } @@ -181,7 +181,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); + ASSERT_FALSE(testTask.validation()); } } From 1b37455db70bfc6593a37f5f3ef598cd5adaa657 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:06:02 +0300 Subject: [PATCH 06/16] Add files via upload From c6f9d17d904b6b69f76e10ae7a9fe47b53aa91ed Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:34:09 +0300 Subject: [PATCH 07/16] Add files via upload From 84be831e8b3c6ada184f8e111cb3821b3f26e4ab Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:35:26 +0300 Subject: [PATCH 08/16] Add files via upload --- tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 0cb8fa57267..4c4f31c1969 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -144,7 +144,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { + if (world.rank() == sendler) { ASSERT_FALSE(testTask.validation()); } } From 7a3e2a709e660cbbd2a586fadfa17d5972395dde Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:47:14 +0300 Subject: [PATCH 09/16] Add files via upload --- .../func_tests/main.cpp | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 4c4f31c1969..50e303427d2 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -51,9 +51,8 @@ TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_EQ(testTask.validation(), true); - } + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -101,9 +100,8 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == sendler) { - ASSERT_EQ(testTask.validation(), true); - } + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -162,9 +160,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { @@ -180,9 +176,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { @@ -244,9 +238,7 @@ TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { @@ -274,9 +266,7 @@ TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { @@ -313,9 +303,8 @@ TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_EQ(testTask.validation(), true); - } + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); testTask.run(); testTask.post_processing(); @@ -360,9 +349,8 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_EQ(testTask.validation(), true); - } + ASSERT_EQ(testTask.validation(), true); + testTask.pre_processing(); testTask.run(); testTask.post_processing(); From c68f00d357e1ebe78580b44e205a57dd06449a20 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sun, 8 Dec 2024 13:28:50 +0300 Subject: [PATCH 10/16] Add files via upload --- .../mpi/sharamygina_i_line_topology/func_tests/main.cpp | 8 ++------ tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 50e303427d2..702063c2ae8 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -124,9 +124,7 @@ TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == 0) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidSendler) { @@ -142,9 +140,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { taskData->inputs_count.emplace_back(size); sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - if (world.rank() == sendler) { - ASSERT_FALSE(testTask.validation()); - } + ASSERT_FALSE(testTask.validation()); } TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp index ad9cb6849a4..8a25d5ebe3d 100644 --- a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -18,7 +18,8 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); message.assign(inputBuffer, inputBuffer + msize); } - + std::cout << world.rank(); + fflush(stdout); return true; } @@ -30,6 +31,8 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { int sendler = taskData->inputs_count[0]; int recipient = taskData->inputs_count[1]; int msize = taskData->inputs_count[2]; + std::cout << world.rank(); + fflush(stdout); return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && @@ -57,6 +60,8 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { world.send(world.rank() + 1, 0, message); } } + std::cout << world.rank(); + fflush(stdout); return true; } @@ -70,6 +75,8 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { auto* mptr = reinterpret_cast(taskData->outputs[0]); std::copy(message.begin(), message.end(), mptr); } + std::cout << world.rank(); + fflush(stdout); return true; } \ No newline at end of file From b3fa5cd68a321a315c1632a159838aad19409793 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:03:16 +0300 Subject: [PATCH 11/16] Add files via upload --- .../func_tests/main.cpp | 29 +++++++++++++++++-- .../src/ops_mpi.cpp | 11 +------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 702063c2ae8..041320298eb 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -19,7 +19,7 @@ void generator(std::vector& v) { TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { boost::mpi::communicator world; - + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; auto sendler = 0; auto recipient = world.size() - 1; @@ -62,10 +62,12 @@ TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { ASSERT_EQ(received_data[i], data[i]); } } + //std::cout << "[MY1] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, transferRandomData) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; @@ -111,10 +113,12 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { ASSERT_EQ(received_data[i], data[i]); } } + //std::cout << "[MY2] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -125,6 +129,7 @@ TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); + //std::cout << "[MY3] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidSendler) { @@ -141,10 +146,12 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); + //std::cout << "[MY4] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 10000; int sendler = 0; @@ -157,6 +164,7 @@ TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); + //std::cout << "[MY5] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { @@ -173,10 +181,12 @@ TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); + //std::cout << "[MY6] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -193,10 +203,12 @@ TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { } else { SUCCEED(); } + //std::cout << "[MY7] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; auto sendler = 0; @@ -219,10 +231,12 @@ TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { } else { SUCCEED(); } + //std::cout << "[MY8] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 0; int sendler = 0; @@ -235,10 +249,12 @@ TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); + //std::cout << "[MY9] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -262,11 +278,15 @@ TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { } sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_FALSE(testTask.validation()); + if (world.rank() == 0) { + ASSERT_FALSE(testTask.validation()); + } + //std::cout << "[MY10] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 1024; auto sendler = 0; @@ -310,10 +330,12 @@ TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { ASSERT_EQ(received_data[i], data[i]); } } + //std::cout << "[MY11] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, smallSetVector) { boost::mpi::communicator world; + //std::cout << "[MY] " << world.rank() << std::endl; int size = 12; auto sendler = 0; @@ -356,4 +378,5 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { ASSERT_EQ(received_data[i], data[i]); } } -} \ No newline at end of file + //std::cout << "[MY12] " << world.rank() << std::endl; + } \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp index 8a25d5ebe3d..353c7f80241 100644 --- a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -18,8 +18,7 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); message.assign(inputBuffer, inputBuffer + msize); } - std::cout << world.rank(); - fflush(stdout); + return true; } @@ -31,8 +30,6 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { int sendler = taskData->inputs_count[0]; int recipient = taskData->inputs_count[1]; int msize = taskData->inputs_count[2]; - std::cout << world.rank(); - fflush(stdout); return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && @@ -41,7 +38,6 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { internal_order_test(); - int sendler = taskData->inputs_count[0]; int recipient = taskData->inputs_count[1]; @@ -60,9 +56,6 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { world.send(world.rank() + 1, 0, message); } } - std::cout << world.rank(); - fflush(stdout); - return true; } @@ -75,8 +68,6 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { auto* mptr = reinterpret_cast(taskData->outputs[0]); std::copy(message.begin(), message.end(), mptr); } - std::cout << world.rank(); - fflush(stdout); return true; } \ No newline at end of file From 0b4c910c291666b7fe4faf5b74d890d4a9dacfd9 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:20:26 +0300 Subject: [PATCH 12/16] Add files via upload --- .../func_tests/main.cpp | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 041320298eb..e0fab421dfa 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -19,7 +19,6 @@ void generator(std::vector& v) { TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; auto sendler = 0; auto recipient = world.size() - 1; @@ -62,12 +61,10 @@ TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { ASSERT_EQ(received_data[i], data[i]); } } - //std::cout << "[MY1] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, transferRandomData) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; @@ -113,12 +110,10 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { ASSERT_EQ(received_data[i], data[i]); } } - //std::cout << "[MY2] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -129,7 +124,6 @@ TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); - //std::cout << "[MY3] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidSendler) { @@ -146,12 +140,10 @@ TEST(sharamygina_i_line_topology_mpi, invalidSendler) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); - //std::cout << "[MY4] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 10000; int sendler = 0; @@ -164,7 +156,6 @@ TEST(sharamygina_i_line_topology_mpi, invalidRecipient) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); - //std::cout << "[MY5] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { @@ -181,12 +172,10 @@ TEST(sharamygina_i_line_topology_mpi, invalidNumberOfElements) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); - //std::cout << "[MY6] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -203,12 +192,10 @@ TEST(sharamygina_i_line_topology_mpi, absenceOfInputData) { } else { SUCCEED(); } - //std::cout << "[MY7] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; auto sendler = 0; @@ -231,12 +218,10 @@ TEST(sharamygina_i_line_topology_mpi, absenceOutputDataOnRecipient) { } else { SUCCEED(); } - //std::cout << "[MY8] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 0; int sendler = 0; @@ -249,12 +234,10 @@ TEST(sharamygina_i_line_topology_mpi, zeroNumberOfElements) { sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); ASSERT_FALSE(testTask.validation()); - //std::cout << "[MY9] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 20000; int sendler = 0; @@ -281,12 +264,10 @@ TEST(sharamygina_i_line_topology_mpi, equalSenderAndRecipient) { if (world.rank() == 0) { ASSERT_FALSE(testTask.validation()); } - //std::cout << "[MY10] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 1024; auto sendler = 0; @@ -330,12 +311,10 @@ TEST(sharamygina_i_line_topology_mpi, vectorOf1024) { ASSERT_EQ(received_data[i], data[i]); } } - //std::cout << "[MY11] " << world.rank() << std::endl; } TEST(sharamygina_i_line_topology_mpi, smallSetVector) { boost::mpi::communicator world; - //std::cout << "[MY] " << world.rank() << std::endl; int size = 12; auto sendler = 0; @@ -378,5 +357,4 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { ASSERT_EQ(received_data[i], data[i]); } } - //std::cout << "[MY12] " << world.rank() << std::endl; - } \ No newline at end of file +} \ No newline at end of file From c19aa6f5cf5ef2d72bc241abd31980f5fd7d422c Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:24:01 +0300 Subject: [PATCH 13/16] Update main.cpp --- tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index e0fab421dfa..d57db226ae6 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -68,7 +68,7 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { int size = 20000; - std::srand(static_cast(std::time(NULL))); + std::srand(static_cast(std::time(nullptr))); int sendler = std::rand() % (world.size()); int recipient = sendler + std::rand() % (world.size() - sendler); @@ -357,4 +357,4 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { ASSERT_EQ(received_data[i], data[i]); } } -} \ No newline at end of file +} From 8a564d2d13c8e1ec304b2d7a9966554ea1236c40 Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:05:36 +0300 Subject: [PATCH 14/16] Add files via upload --- .../func_tests/main.cpp | 7 ++++--- .../include/ops_mpi.h | 3 +++ .../perf_tests/main.cpp | 5 +++-- .../src/ops_mpi.cpp | 21 ++++++++----------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index d57db226ae6..cfb4a743b17 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -11,8 +11,9 @@ namespace sharamygina_i_line_topology_mpi { void generator(std::vector& v) { std::random_device dev; std::mt19937 gen(dev()); + std::uniform_int_distribution dist(-1000, 1000); for (size_t i = 0; i < v.size(); ++i) { - v[i] = -1000 + gen() % 1000; + v[i] = dist(gen); } } } // namespace sharamygina_i_line_topology_mpi @@ -68,7 +69,7 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { int size = 20000; - std::srand(static_cast(std::time(nullptr))); + std::srand(static_cast(std::time(NULL))); int sendler = std::rand() % (world.size()); int recipient = sendler + std::rand() % (world.size() - sendler); @@ -357,4 +358,4 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { ASSERT_EQ(received_data[i], data[i]); } } -} +} \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h index bcaa5f7684b..d216a7cf32d 100644 --- a/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h +++ b/tasks/mpi/sharamygina_i_line_topology/include/ops_mpi.h @@ -24,6 +24,9 @@ class line_topology_mpi : public ppc::core::Task { private: std::vector message; boost::mpi::communicator world; + int sendler; + int recipient; + int msize; }; } // namespace sharamygina_i_line_topology_mpi \ No newline at end of file diff --git a/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp index bfbc7b9a85d..bb69fe24538 100644 --- a/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/perf_tests/main.cpp @@ -18,6 +18,7 @@ TEST(sharamygina_i_line_topology_mpi, test_task_run) { taskData->inputs_count.emplace_back(size); std::vector data(size, 0); + std::iota(data.begin(), data.end(), 0); std::vector received_data; if (world.rank() == sendler) { @@ -60,7 +61,7 @@ TEST(sharamygina_i_line_topology_mpi, test_task_run) { TEST(sharamygina_i_line_topology_mpi, test_pipeline_run) { boost::mpi::communicator world; - int size = 10000000; + int size = 5000000; auto sendler = 0; auto recipient = world.size() - 1; @@ -94,7 +95,7 @@ TEST(sharamygina_i_line_topology_mpi, test_pipeline_run) { // Create Perf attributes auto perfAttr = std::make_shared(); - perfAttr->num_running = 10; + perfAttr->num_running = 9; const boost::mpi::timer current_timer; perfAttr->current_timer = [&] { return current_timer.elapsed(); }; diff --git a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp index 353c7f80241..bb06dcce473 100644 --- a/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/src/ops_mpi.cpp @@ -11,8 +11,9 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::pre_processing() { internal_order_test(); - int sendler = taskData->inputs_count[0]; - int msize = taskData->inputs_count[2]; + sendler = taskData->inputs_count[0]; + recipient = taskData->inputs_count[1]; + msize = taskData->inputs_count[2]; if (world.rank() == sendler) { auto* inputBuffer = reinterpret_cast(taskData->inputs[0]); @@ -27,19 +28,17 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::validation() { if (taskData->inputs_count.size() < 3) return false; - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; - int msize = taskData->inputs_count[2]; + int sendler_ = taskData->inputs_count[0]; + int recipient_ = taskData->inputs_count[1]; + int msize_ = taskData->inputs_count[2]; - return (sendler >= 0 && sendler < world.size() && recipient >= 0 && recipient < world.size() && msize > 0) && - ((world.rank() != sendler) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && - ((world.rank() != recipient) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); + return (sendler_ >= 0 && sendler_ < world.size() && recipient_ >= 0 && recipient_ < world.size() && msize_ > 0) && + ((world.rank() != sendler_) || ((!taskData->inputs.empty()) && (taskData->inputs[0] != nullptr))) && + ((world.rank() != recipient_) || ((!taskData->outputs.empty()) && (taskData->outputs[0] != nullptr))); } bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { internal_order_test(); - int sendler = taskData->inputs_count[0]; - int recipient = taskData->inputs_count[1]; if (sendler == recipient) { return true; @@ -62,8 +61,6 @@ bool sharamygina_i_line_topology_mpi::line_topology_mpi::run() { bool sharamygina_i_line_topology_mpi::line_topology_mpi::post_processing() { internal_order_test(); - int recipient = taskData->inputs_count[1]; - if (world.rank() == recipient) { auto* mptr = reinterpret_cast(taskData->outputs[0]); std::copy(message.begin(), message.end(), mptr); From a81edb58fa6bf431d88ff7fef50637ecfac034ff Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:07:14 +0300 Subject: [PATCH 15/16] Update main.cpp --- tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index cfb4a743b17..26168cc2f8d 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -69,7 +69,7 @@ TEST(sharamygina_i_line_topology_mpi, transferRandomData) { int size = 20000; - std::srand(static_cast(std::time(NULL))); + std::srand(static_cast(std::time(nullptr))); int sendler = std::rand() % (world.size()); int recipient = sendler + std::rand() % (world.size() - sendler); @@ -358,4 +358,4 @@ TEST(sharamygina_i_line_topology_mpi, smallSetVector) { ASSERT_EQ(received_data[i], data[i]); } } -} \ No newline at end of file +} From 614f30fd62c7b91337617d66788e1dad5ce6bd2f Mon Sep 17 00:00:00 2001 From: isharamygina <121282432+isharamygina@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:08:51 +0300 Subject: [PATCH 16/16] Update main.cpp --- .../func_tests/main.cpp | 49 ------------------- 1 file changed, 49 deletions(-) diff --git a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp index 26168cc2f8d..acbf8789651 100644 --- a/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp +++ b/tasks/mpi/sharamygina_i_line_topology/func_tests/main.cpp @@ -64,55 +64,6 @@ TEST(sharamygina_i_line_topology_mpi, checkTransferedData) { } } -TEST(sharamygina_i_line_topology_mpi, transferRandomData) { - boost::mpi::communicator world; - - int size = 20000; - - std::srand(static_cast(std::time(nullptr))); - int sendler = std::rand() % (world.size()); - int recipient = sendler + std::rand() % (world.size() - sendler); - - std::shared_ptr taskData = std::make_shared(); - taskData->inputs_count.emplace_back(sendler); - taskData->inputs_count.emplace_back(recipient); - taskData->inputs_count.emplace_back(size); - - std::vector data(size); - std::vector received_data; - - if (world.rank() == sendler) { - sharamygina_i_line_topology_mpi::generator(data); - taskData->inputs.emplace_back(reinterpret_cast(data.data())); - if (sendler != recipient) { - world.send(recipient, 0, data); - } - } - if (world.rank() == recipient) { - if (sendler != recipient) { - world.recv(sendler, 0, data); - } - - received_data.resize(size); - - taskData->outputs.emplace_back(reinterpret_cast(received_data.data())); - taskData->outputs_count.emplace_back(received_data.size()); - } - - sharamygina_i_line_topology_mpi::line_topology_mpi testTask(taskData); - ASSERT_EQ(testTask.validation(), true); - - testTask.pre_processing(); - testTask.run(); - testTask.post_processing(); - - if (world.rank() == recipient) { - for (int i = 0; i < size; i++) { - ASSERT_EQ(received_data[i], data[i]); - } - } -} - TEST(sharamygina_i_line_topology_mpi, insufficientInputs) { boost::mpi::communicator world;