diff --git a/tasks/mpi/lupsha_e_rect_integration/func_tests/main.cpp b/tasks/mpi/lupsha_e_rect_integration/func_tests/main.cpp deleted file mode 100644 index 78405b94c74..00000000000 --- a/tasks/mpi/lupsha_e_rect_integration/func_tests/main.cpp +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright 2024 Lupsha Egor -#include - -#include -#include -#include -#include -#include - -#include "mpi/lupsha_e_rect_integration/include/ops_mpi.hpp" - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -std::tuple generate_random_data() { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> bounds_dist(0.0, 10.0); - std::uniform_int_distribution<> intervals_dist(100000, 2000000); - - double lower_bound = bounds_dist(gen); - double upper_bound = lower_bound + bounds_dist(gen); - int num_intervals = intervals_dist(gen); - - return std::make_tuple(lower_bound, upper_bound, num_intervals); -} - -TEST(lupsha_e_rect_integration_mpi, Test_Constant) { - boost::mpi::communicator world; - double lower_bound = 0.0; - double upper_bound = 1.0; - int num_intervals = 1000; - std::vector global_sum(1, 0.0); - std::vector result_seq(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - lupsha_e_rect_integration_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - std::function f = [](double x) { return 10.0; }; - testMpiTaskParallel.function_set(f); - - ASSERT_TRUE(testMpiTaskParallel.validation()); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_mpi::TestMPITaskSequential sequential_Task(taskDataSeq); - sequential_Task.function_set([](double x) { return 10.0; }); - - ASSERT_EQ(sequential_Task.validation(), true); - sequential_Task.pre_processing(); - sequential_Task.run(); - sequential_Task.post_processing(); - - ASSERT_NEAR(global_sum[0], result_seq[0], 1e-3); - } -} - -TEST(lupsha_e_rect_integration_mpi, Test_Logarithm) { - boost::mpi::communicator world; - double lower_bound = 0.1; - double upper_bound = 1.0; - int num_intervals = 10000; - std::vector global_sum(1, 0.0); - std::vector result_seq(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - lupsha_e_rect_integration_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - std::function f = [](double x) { return std::log(x); }; - testMpiTaskParallel.function_set(f); - - ASSERT_TRUE(testMpiTaskParallel.validation()); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_mpi::TestMPITaskSequential sequential_Task(taskDataSeq); - sequential_Task.function_set([](double x) { return std::log(x); }); - - ASSERT_EQ(sequential_Task.validation(), true); - sequential_Task.pre_processing(); - sequential_Task.run(); - sequential_Task.post_processing(); - - ASSERT_NEAR(global_sum[0], result_seq[0], 1e-3); - } -} - -TEST(lupsha_e_rect_integration_mpi, Test_Gaussian) { - boost::mpi::communicator world; - double lower_bound = -1.0; - double upper_bound = 1.0; - int num_intervals = 1000; - std::vector global_sum(1, 0.0); - std::vector result_seq(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - lupsha_e_rect_integration_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - std::function f = [](double x) { return std::exp(-x * x); }; - testMpiTaskParallel.function_set(f); - - ASSERT_TRUE(testMpiTaskParallel.validation()); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_mpi::TestMPITaskSequential sequential_Task(taskDataSeq); - sequential_Task.function_set([](double x) { return std::exp(-x * x); }); - - ASSERT_EQ(sequential_Task.validation(), true); - sequential_Task.pre_processing(); - sequential_Task.run(); - sequential_Task.post_processing(); - - ASSERT_NEAR(global_sum[0], result_seq[0], 1e-2); - } -} - -TEST(lupsha_e_rect_integration_mpi, Test_Power) { - boost::mpi::communicator world; - double lower_bound = 0.0; - double upper_bound = 1.0; - int num_intervals = 1000; - std::vector global_sum(1, 0.0); - std::vector result_seq(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - lupsha_e_rect_integration_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - std::function f = [](double x) { return x * x; }; - testMpiTaskParallel.function_set(f); - - ASSERT_TRUE(testMpiTaskParallel.validation()); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_mpi::TestMPITaskSequential sequential_Task(taskDataSeq); - sequential_Task.function_set([](double x) { return x * x; }); - - ASSERT_EQ(sequential_Task.validation(), true); - sequential_Task.pre_processing(); - sequential_Task.run(); - sequential_Task.post_processing(); - - ASSERT_NEAR(global_sum[0], result_seq[0], 1e-2); - } -} - -TEST(lupsha_e_rect_integration_mpi, Test_Power_Random) { - boost::mpi::communicator world; - auto [lower_bound, upper_bound, num_intervals] = generate_random_data(); - std::vector global_sum(1, 0.0); - std::vector result_seq(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - lupsha_e_rect_integration_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar); - - std::function f = [](double x) { return x * x; }; - testMpiTaskParallel.function_set(f); - - ASSERT_TRUE(testMpiTaskParallel.validation()); - testMpiTaskParallel.pre_processing(); - testMpiTaskParallel.run(); - testMpiTaskParallel.post_processing(); - - if (world.rank() == 0) { - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(1); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result_seq.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_mpi::TestMPITaskSequential sequential_Task(taskDataSeq); - sequential_Task.function_set([](double x) { return x * x; }); - - ASSERT_EQ(sequential_Task.validation(), true); - sequential_Task.pre_processing(); - sequential_Task.run(); - sequential_Task.post_processing(); - - ASSERT_NEAR(global_sum[0], result_seq[0], 1e-2); - } -} \ No newline at end of file diff --git a/tasks/mpi/lupsha_e_rect_integration/include/ops_mpi.hpp b/tasks/mpi/lupsha_e_rect_integration/include/ops_mpi.hpp deleted file mode 100644 index db771f376bc..00000000000 --- a/tasks/mpi/lupsha_e_rect_integration/include/ops_mpi.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2024 Lupsha Egor -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "core/task/include/task.hpp" - -namespace lupsha_e_rect_integration_mpi { - -class TestMPITaskSequential : public ppc::core::Task { - public: - explicit TestMPITaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - void function_set(const std::function& func); - - private: - double lower_bound{}; - double upper_bound{}; - int num_intervals{}; - std::function f; - std::vector input_; - std::vector results_; -}; - -class TestMPITaskParallel : public ppc::core::Task { - public: - explicit TestMPITaskParallel(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - void function_set(const std::function& func); - - private: - double integrate(const std::function& f_, double lower_bound_, double upper_bound_, - int num_intervals_); - double lower_bound{}; - double upper_bound{}; - double local_sum_{}; - double global_sum_{}; - int num_intervals{}; - std::function f; - std::vector input_; - std::vector results_; - boost::mpi::communicator world; -}; - -} // namespace lupsha_e_rect_integration_mpi \ No newline at end of file diff --git a/tasks/mpi/lupsha_e_rect_integration/perf_tests/main.cpp b/tasks/mpi/lupsha_e_rect_integration/perf_tests/main.cpp deleted file mode 100644 index 3bcbafe9795..00000000000 --- a/tasks/mpi/lupsha_e_rect_integration/perf_tests/main.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2024 Lupsha Egor - -#include - -#include -#include -#include - -#include "core/perf/include/perf.hpp" -#include "mpi/lupsha_e_rect_integration/include/ops_mpi.hpp" - -std::tuple generate_random_data() { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> bounds_dist(0.0, 10.0); - std::uniform_int_distribution<> intervals_dist(100000, 2000000); - - double lower_bound = bounds_dist(gen); - double upper_bound = lower_bound + bounds_dist(gen); - int num_intervals = intervals_dist(gen); - - return std::make_tuple(lower_bound, upper_bound, num_intervals); -} - -TEST(lupsha_e_rect_integration_mpi, test_pipeline_run) { - boost::mpi::communicator world; - double lower_bound = 0.0; - double upper_bound = 1.0; - int num_intervals = 1000000; - std::vector global_sum(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - testMpiTaskParallel->function_set([](double x) { return x * x; }); - - ASSERT_TRUE(testMpiTaskParallel->validation()); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - double expected_result = (upper_bound * upper_bound * upper_bound - lower_bound * lower_bound * lower_bound) / 3; - ASSERT_NEAR(global_sum[0], expected_result, 1e-5); - } -} - -TEST(lupsha_e_rect_integration_mpi, test_task_run) { - boost::mpi::communicator world; - double lower_bound = 0.0; - double upper_bound = 1.0; - int num_intervals = 1000000; - std::vector global_sum(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - testMpiTaskParallel->function_set([](double x) { return x * x; }); - - ASSERT_TRUE(testMpiTaskParallel->validation()); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->task_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - double expected_result = (upper_bound * upper_bound * upper_bound - lower_bound * lower_bound * lower_bound) / 3; - ASSERT_NEAR(global_sum[0], expected_result, 1e-5); - } -} - -TEST(lupsha_e_rect_integration_mpi, test_pipeline_run_random) { - boost::mpi::communicator world; - auto [lower_bound, upper_bound, num_intervals] = generate_random_data(); - std::vector global_sum(1, 0.0); - - std::shared_ptr taskDataPar = std::make_shared(); - - if (world.rank() == 0) { - taskDataPar->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataPar->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataPar->outputs.emplace_back(reinterpret_cast(global_sum.data())); - taskDataPar->outputs_count.emplace_back(global_sum.size()); - } - - auto testMpiTaskParallel = std::make_shared(taskDataPar); - testMpiTaskParallel->function_set([](double x) { return x * x; }); - - ASSERT_TRUE(testMpiTaskParallel->validation()); - testMpiTaskParallel->pre_processing(); - testMpiTaskParallel->run(); - testMpiTaskParallel->post_processing(); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - const boost::mpi::timer current_timer; - perfAttr->current_timer = [&] { return current_timer.elapsed(); }; - - auto perfResults = std::make_shared(); - - auto perfAnalyzer = std::make_shared(testMpiTaskParallel); - perfAnalyzer->pipeline_run(perfAttr, perfResults); - - if (world.rank() == 0) { - ppc::core::Perf::print_perf_statistic(perfResults); - double expected_result = (std::pow(upper_bound, 3) - std::pow(lower_bound, 3)) / 3.0; - ASSERT_NEAR(global_sum[0], expected_result, 1e-2); - } -} \ No newline at end of file diff --git a/tasks/mpi/lupsha_e_rect_integration/src/ops_mpi.cpp b/tasks/mpi/lupsha_e_rect_integration/src/ops_mpi.cpp deleted file mode 100644 index e14d7199239..00000000000 --- a/tasks/mpi/lupsha_e_rect_integration/src/ops_mpi.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2024 Lupsha Egor -#include "mpi/lupsha_e_rect_integration/include/ops_mpi.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -using namespace std::chrono_literals; - -void lupsha_e_rect_integration_mpi::TestMPITaskSequential::function_set(const std::function& func) { - f = func; -} - -void lupsha_e_rect_integration_mpi::TestMPITaskParallel::function_set(const std::function& func) { - f = func; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskSequential::pre_processing() { - internal_order_test(); - - lower_bound = *reinterpret_cast(taskData->inputs[0]); - upper_bound = *reinterpret_cast(taskData->inputs[1]); - num_intervals = *reinterpret_cast(taskData->inputs[2]); - - results_.resize(1, 0.0); - - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskSequential::validation() { - internal_order_test(); - - if (taskData->inputs.size() < 3) { - return false; - std::cout << "Validation failed: not enough input data." << std::endl; - } - - double validation_lower_bound = *reinterpret_cast(taskData->inputs[0]); - double validation_upper_bound = *reinterpret_cast(taskData->inputs[1]); - if (validation_lower_bound >= validation_upper_bound) { - std::cout << "Validation failed: lower_bound >= upper_bound." << std::endl; - return false; - } - - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskSequential::run() { - internal_order_test(); - - double width = (upper_bound - lower_bound) / num_intervals; - input_.resize(num_intervals); - double sum = 0.0; - - for (int i = 0; i < num_intervals; ++i) { - double x = lower_bound + i * width; - sum += f(x) * width; - } - results_[0] = sum; - - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskSequential::post_processing() { - internal_order_test(); - *reinterpret_cast(taskData->outputs[0]) = results_[0]; - - return true; -} - -double lupsha_e_rect_integration_mpi::TestMPITaskParallel::integrate(const std::function& f_, - double lower_bound_, double upper_bound_, - int num_intervals_) { - int rank = world.rank(); - int size = world.size(); - - double width = (upper_bound_ - lower_bound_) / num_intervals_; - int local_num_intervals = num_intervals_ / size; - int remainder = num_intervals_ % size; - - if (rank < remainder) { - local_num_intervals = local_num_intervals + 1; - } - - double local_start = lower_bound_ + rank * local_num_intervals * width; - - double local_sum = 0.0; - for (int i = 0; i < local_num_intervals; ++i) { - double x = local_start + i * width; - local_sum += f(x) * width; - } - - return local_sum; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskParallel::pre_processing() { - internal_order_test(); - - unsigned int d = 0; - if (world.rank() == 0) { - d = num_intervals / world.size(); - } - MPI_Bcast(&d, 1, MPI_UNSIGNED, 0, world); - - if (world.rank() == 0) { - lower_bound = *reinterpret_cast(taskData->inputs[0]); - upper_bound = *reinterpret_cast(taskData->inputs[1]); - num_intervals = *reinterpret_cast(taskData->inputs[2]); - } - - MPI_Bcast(&lower_bound, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&upper_bound, 1, MPI_DOUBLE, 0, world); - MPI_Bcast(&num_intervals, 1, MPI_INT, 0, world); - - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskParallel::validation() { - internal_order_test(); - if (world.rank() == 0) { - if (taskData->inputs.size() < 3) { - std::cout << "Validation failed: not enough input data." << std::endl; - return false; - } - - double validation_lower_bound = *reinterpret_cast(taskData->inputs[0]); - double validation_upper_bound = *reinterpret_cast(taskData->inputs[1]); - if (validation_lower_bound >= validation_upper_bound) { - std::cout << "Validation failed: lower_bound >= upper_bound." << std::endl; - return false; - } - - int validation_num_intervals = *reinterpret_cast(taskData->inputs[2]); - if (validation_num_intervals <= 0) { - std::cout << "Validation failed: num_intervals <= 0." << std::endl; - return false; - } - } - - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskParallel::run() { - internal_order_test(); - local_sum_ = integrate(f, lower_bound, upper_bound, num_intervals); - MPI_Reduce(&local_sum_, &global_sum_, 1, MPI_DOUBLE, MPI_SUM, 0, world); - return true; -} - -bool lupsha_e_rect_integration_mpi::TestMPITaskParallel::post_processing() { - internal_order_test(); - if (world.rank() == 0) { - *reinterpret_cast(taskData->outputs[0]) = global_sum_; - } - - return true; -} \ No newline at end of file diff --git a/tasks/seq/lupsha_e_rect_integration/func_tests/main.cpp b/tasks/seq/lupsha_e_rect_integration/func_tests/main.cpp deleted file mode 100644 index 9db26ac7019..00000000000 --- a/tasks/seq/lupsha_e_rect_integration/func_tests/main.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2024 Lupsha Egor -#include - -#include -#include - -#include "seq/lupsha_e_rect_integration/include/ops_seq.hpp" - -std::tuple generate_random_data() { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> bounds_dist(0.0, 10.0); - std::uniform_int_distribution<> intervals_dist(100000, 2000000); - - double lower_bound = bounds_dist(gen); - double upper_bound = lower_bound + bounds_dist(gen); - int num_intervals = intervals_dist(gen); - - return std::make_tuple(lower_bound, upper_bound, num_intervals); -} - -TEST(lupsha_e_rect_integration_seq, Test_Rect1) { - double lower_bound = 0.0; - double upper_bound = 1.0; - int num_intervals = 4; - - double expected_result = 0.21875; - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_seq::TestTaskSequential TestTaskSequential(taskDataSeq); - std::function f = [](double x) { return x * x; }; - TestTaskSequential.function_set(f); - ASSERT_TRUE(TestTaskSequential.validation()); - TestTaskSequential.pre_processing(); - TestTaskSequential.run(); - TestTaskSequential.post_processing(); - - ASSERT_DOUBLE_EQ(expected_result, result[0]); -} - -TEST(lupsha_e_rect_integration_seq, Test_Rect2) { - double lower_bound = 0.0; - double upper_bound = 4.0; - int num_intervals = 10000; - - double expected_result = 21.33; - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_seq::TestTaskSequential TestTaskSequential(taskDataSeq); - std::function f = [](double x) { return x * x; }; - TestTaskSequential.function_set(f); - - ASSERT_TRUE(TestTaskSequential.validation()); - TestTaskSequential.pre_processing(); - TestTaskSequential.run(); - TestTaskSequential.post_processing(); - - EXPECT_NEAR(result[0], expected_result, 0.01); -} - -TEST(lupsha_e_rect_integration_seq, Test_Rect_Random) { - auto [lower_bound, upper_bound, num_intervals] = generate_random_data(); - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - lupsha_e_rect_integration_seq::TestTaskSequential TestTaskSequential(taskDataSeq); - std::function f = [](double x) { return x * x; }; - TestTaskSequential.function_set(f); - - ASSERT_TRUE(TestTaskSequential.validation()); - TestTaskSequential.pre_processing(); - TestTaskSequential.run(); - TestTaskSequential.post_processing(); - - double expected_result = (std::pow(upper_bound, 3) - std::pow(lower_bound, 3)) / 3.0; - EXPECT_NEAR(result[0], expected_result, 0.01); -} \ No newline at end of file diff --git a/tasks/seq/lupsha_e_rect_integration/include/ops_seq.hpp b/tasks/seq/lupsha_e_rect_integration/include/ops_seq.hpp deleted file mode 100644 index 87ef7a4240a..00000000000 --- a/tasks/seq/lupsha_e_rect_integration/include/ops_seq.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2024 Lupsha Egor -#pragma once - -#include -#include - -#include "core/task/include/task.hpp" - -namespace lupsha_e_rect_integration_seq { - -class TestTaskSequential : public ppc::core::Task { - public: - explicit TestTaskSequential(std::shared_ptr taskData_) : Task(std::move(taskData_)) {} - bool pre_processing() override; - bool validation() override; - bool run() override; - bool post_processing() override; - - void function_set(const std::function& func); - - private: - double lower_bound{}; - double upper_bound{}; - int num_intervals{}; - std::vector input_; - std::vector results_; - std::function f; -}; - -} // namespace lupsha_e_rect_integration_seq \ No newline at end of file diff --git a/tasks/seq/lupsha_e_rect_integration/perf_tests/main.cpp b/tasks/seq/lupsha_e_rect_integration/perf_tests/main.cpp deleted file mode 100644 index 6ad5863d496..00000000000 --- a/tasks/seq/lupsha_e_rect_integration/perf_tests/main.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2024 Lupsha Egor -#include - -#include -#include - -#include "core/perf/include/perf.hpp" -#include "seq/lupsha_e_rect_integration/include/ops_seq.hpp" - -std::tuple generate_random_data() { - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_real_distribution<> bounds_dist(0.0, 10.0); - std::uniform_int_distribution<> intervals_dist(100000, 2000000); - - double lower_bound = bounds_dist(gen); - double upper_bound = lower_bound + bounds_dist(gen); - int num_intervals = intervals_dist(gen); - - return std::make_tuple(lower_bound, upper_bound, num_intervals); -} - -TEST(lupsha_e_rect_integration_seq, test_pipeline_run) { - double lower_bound = 0.0; - double upper_bound = 2.0; - int num_intervals = 1000000; - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - auto TestTaskSequential = std::make_shared(taskDataSeq); - TestTaskSequential->function_set([](double x) { return x * x; }); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - auto perfResults = std::make_shared(); - auto perfAnalyzer = std::make_shared(TestTaskSequential); - - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - - EXPECT_NEAR(result[0], (8.0 / 3.0), 0.0001); -} - -TEST(lupsha_e_rect_integration_seq, test_task_run) { - double lower_bound = 0.0; - double upper_bound = 2.0; - int num_intervals = 1000000; - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - auto TestTaskSequential = std::make_shared(taskDataSeq); - TestTaskSequential->function_set([](double x) { return x * x; }); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - auto perfResults = std::make_shared(); - auto perfAnalyzer = std::make_shared(TestTaskSequential); - - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - - EXPECT_NEAR(result[0], (8.0 / 3.0), 0.0001); -} - -TEST(lupsha_e_rect_integration_seq, test_pipeline_run_random) { - auto [lower_bound, upper_bound, num_intervals] = generate_random_data(); - - std::shared_ptr taskDataSeq = std::make_shared(); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&lower_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&upper_bound)); - taskDataSeq->inputs.emplace_back(reinterpret_cast(&num_intervals)); - taskDataSeq->inputs_count.emplace_back(3); - - std::vector result(1, 0.0); - taskDataSeq->outputs.emplace_back(reinterpret_cast(result.data())); - taskDataSeq->outputs_count.emplace_back(1); - - auto TestTaskSequential = std::make_shared(taskDataSeq); - TestTaskSequential->function_set([](double x) { return x * x; }); - - auto perfAttr = std::make_shared(); - perfAttr->num_running = 1000; - - const auto t0 = std::chrono::high_resolution_clock::now(); - perfAttr->current_timer = [&] { - auto current_time_point = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(current_time_point - t0).count(); - return static_cast(duration) * 1e-9; - }; - - auto perfResults = std::make_shared(); - auto perfAnalyzer = std::make_shared(TestTaskSequential); - - perfAnalyzer->pipeline_run(perfAttr, perfResults); - ppc::core::Perf::print_perf_statistic(perfResults); - - double expected_result = (std::pow(upper_bound, 3) - std::pow(lower_bound, 3)) / 3.0; - EXPECT_NEAR(result[0], expected_result, 0.0001); -} \ No newline at end of file diff --git a/tasks/seq/lupsha_e_rect_integration/src/ops_seq.cpp b/tasks/seq/lupsha_e_rect_integration/src/ops_seq.cpp deleted file mode 100644 index 6a2325acdca..00000000000 --- a/tasks/seq/lupsha_e_rect_integration/src/ops_seq.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2024 Lupsha Egor -#include "seq/lupsha_e_rect_integration/include/ops_seq.hpp" - -#include - -using namespace std::chrono_literals; - -void lupsha_e_rect_integration_seq::TestTaskSequential::function_set(const std::function& func) { - f = func; -} - -bool lupsha_e_rect_integration_seq::TestTaskSequential::pre_processing() { - internal_order_test(); - - lower_bound = *reinterpret_cast(taskData->inputs[0]); - upper_bound = *reinterpret_cast(taskData->inputs[1]); - num_intervals = *reinterpret_cast(taskData->inputs[2]); - - results_.resize(1, 0.0); - return true; -} - -bool lupsha_e_rect_integration_seq::TestTaskSequential::validation() { - internal_order_test(); - if (taskData->inputs.size() < 3 || !f) { - if (taskData->inputs.size() < 3) { - std::cout << "Validation failed: not enough input data." << std::endl; - } - return false; - } - - return true; -} - -bool lupsha_e_rect_integration_seq::TestTaskSequential::run() { - internal_order_test(); - double width = (upper_bound - lower_bound) / num_intervals; - input_.resize(num_intervals); - double sum = 0.0; - - for (int i = 0; i < num_intervals; ++i) { - double x = lower_bound + i * width; - sum += f(x) * width; - } - results_[0] = sum; - return true; -} - -bool lupsha_e_rect_integration_seq::TestTaskSequential::post_processing() { - internal_order_test(); - *reinterpret_cast(taskData->outputs[0]) = results_[0]; - return true; -} \ No newline at end of file