From c946be7dd2f68f2181451c8957fd2fa25edaac63 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Tue, 18 Nov 2025 10:13:53 +0000 Subject: [PATCH 01/13] well i think it works --- .../common/include/common.hpp | 25 +++++ .../info.json | 9 ++ .../mpi/include/ops_mpi.hpp | 22 +++++ .../mpi/src/ops_mpi.cpp | 98 +++++++++++++++++++ .../report.md | 0 .../seq/include/ops_seq.hpp | 22 +++++ .../seq/src/ops_seq.cpp | 77 +++++++++++++++ .../settings.json | 7 ++ .../tests/.clang-tidy | 13 +++ .../tests/functional/main.cpp | 77 +++++++++++++++ .../tests/performance/main.cpp | 61 ++++++++++++ 11 files changed, 411 insertions(+) create mode 100644 tasks/dorofeev_i_monte_carlo_integration/common/include/common.hpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/info.json create mode 100644 tasks/dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/report.md create mode 100644 tasks/dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/settings.json create mode 100644 tasks/dorofeev_i_monte_carlo_integration/tests/.clang-tidy create mode 100644 tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp create mode 100644 tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp diff --git a/tasks/dorofeev_i_monte_carlo_integration/common/include/common.hpp b/tasks/dorofeev_i_monte_carlo_integration/common/include/common.hpp new file mode 100644 index 0000000000..83212f0188 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/common/include/common.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include + +#include "task/include/task.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +struct InputData { + std::function &)> func; // f(x) + std::vector a; // lower bounds + std::vector b; // upper bounds + int samples = 0; // number of samples +}; + +using InType = InputData; +using OutType = double; + +using TestType = std::tuple; // for testing purposes +using BaseTask = ppc::task::Task; + +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/info.json b/tasks/dorofeev_i_monte_carlo_integration/info.json new file mode 100644 index 0000000000..54b79b6d94 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/info.json @@ -0,0 +1,9 @@ +{ + "student": { + "first_name": "Дорофеев", + "last_name": "Иван", + "middle_name": "Денисович", + "group_number": "3823Б1ФИ1", + "task_number": "1" + } +} diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp new file mode 100644 index 0000000000..ec93e73dba --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +class DorofeevIMonteCarloIntegrationMPI : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kMPI; + } + explicit DorofeevIMonteCarloIntegrationMPI(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp new file mode 100644 index 0000000000..bb2e224757 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -0,0 +1,98 @@ +#include "dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp" + +#include + +#include +#include + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +DorofeevIMonteCarloIntegrationMPI::DorofeevIMonteCarloIntegrationMPI(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0; +} + +bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { + const auto &in = GetInput(); + + if (!in.func) { + return false; + } + if (in.a.empty() || in.a.size() != in.b.size()) { + return false; + } + + for (size_t i = 0; i < in.a.size(); i++) { + if (in.b[i] <= in.a[i]) { + return false; + } + } + + return in.samples > 0; +} + +bool DorofeevIMonteCarloIntegrationMPI::PreProcessingImpl() { + GetOutput() = 0.0; + return true; +} + +bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { + const auto in = GetInput(); + const int dims = in.a.size(); + const int n_total = in.samples; + + int rank = 0; + int size = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int n_local = n_total / size; + if (rank == size - 1) { + n_local += n_total % size; + } + + std::vector> dist; + dist.reserve(dims); + for (int d = 0; d < dims; ++d) { + dist.emplace_back(in.a[d], in.b[d]); + } + + std::mt19937 gen(rank + 123); + double local_sum = 0.0; + + for (int i = 0; i < n_local; ++i) { + std::vector x(dims); + for (int d = 0; d < dims; d++) { + x[d] = dist[d](gen); + } + local_sum += in.func(x); + } + + double global_sum = 0.0; + + MPI_Reduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + + double volume = 1.0; + for (int d = 0; d < dims; d++) { + volume *= (in.b[d] - in.a[d]); + } + + double result = 0.0; + if (rank == 0) { + result = (global_sum / n_total) * volume; + } + + MPI_Bcast(&result, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); + + GetOutput() = result; + return true; +} + +bool DorofeevIMonteCarloIntegrationMPI::PostProcessingImpl() { + return true; +} + +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/report.md b/tasks/dorofeev_i_monte_carlo_integration/report.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp b/tasks/dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp new file mode 100644 index 0000000000..ac17406972 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +class DorofeevIMonteCarloIntegrationSEQ : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + explicit DorofeevIMonteCarloIntegrationSEQ(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp new file mode 100644 index 0000000000..51dc5d8bbe --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -0,0 +1,77 @@ +#include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" + +#include + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0.0; +} + +bool DorofeevIMonteCarloIntegrationSEQ::ValidationImpl() { + const auto &in = GetInput(); + + if (in.a.size() != in.b.size()) { + return false; + } + + if (in.samples <= 0) { + return false; + } + + for (size_t i = 0; i < in.a.size(); i++) { + if (in.b[i] <= in.a[i]) { + return false; + } + } + + return true; +} + +bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { + GetOutput() = 0.0; + return true; +} + +bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { + const auto &in = GetInput(); + const int dims = in.a.size(); + const int N = in.samples; + + std::mt19937 gen(12345); + std::vector> dist; + dist.reserve(dims); + + for (int i = 0; i < dims; i++) { + dist.emplace_back(in.a[i], in.b[i]); + } + + double sum = 0.0; + std::vector point(dims); + + for (int s = 0; s < N; s++) { + for (int d = 0; d < dims; d++) { + point[d] = dist[d](gen); + } + sum += in.func(point); + } + + double volume = 1.0; + for (int i = 0; i < dims; i++) { + volume *= (in.b[i] - in.a[i]); + } + + GetOutput() = volume * (sum / N); + return true; +} + +bool DorofeevIMonteCarloIntegrationSEQ::PostProcessingImpl() { + return true; +} + +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/settings.json b/tasks/dorofeev_i_monte_carlo_integration/settings.json new file mode 100644 index 0000000000..b1a0d52574 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/settings.json @@ -0,0 +1,7 @@ +{ + "tasks_type": "processes", + "tasks": { + "mpi": "enabled", + "seq": "enabled" + } +} diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/.clang-tidy b/tasks/dorofeev_i_monte_carlo_integration/tests/.clang-tidy new file mode 100644 index 0000000000..ef43b7aa8a --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/.clang-tidy @@ -0,0 +1,13 @@ +InheritParentConfig: true + +Checks: > + -modernize-loop-convert, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-non-const-global-variables, + -misc-use-anonymous-namespace, + -modernize-use-std-print, + -modernize-type-traits + +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: 50 # Relaxed for tests diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp new file mode 100644 index 0000000000..f6712b1ec1 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp @@ -0,0 +1,77 @@ +#include + +#include +#include +#include +#include +#include + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +#include "dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp" +#include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { + +class MonteCarloFuncTests : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintTestParam( + const testing::TestParamInfo> &info) { + const auto &full = info.param; + + const TestType &t = std::get<2>(full); + std::string size_name = std::get<1>(t); + + std::string task_name = std::get<1>(full); + + return task_name + "_" + size_name; + } + + protected: + void SetUp() override { + auto full_param = GetParam(); + TestType t = std::get<2>(full_param); + + int samples = std::get<0>(t); + + input_data_.a = {0.0}; + input_data_.b = {1.0}; + input_data_.samples = samples; + input_data_.func = [](const std::vector &x) { return x[0] * x[0]; }; + } + + bool CheckTestOutputData(OutType &output_data) final { + double expected = 1.0 / 3.0; + return std::abs(output_data - expected) < 0.05; + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_; +}; + +namespace { + +TEST_P(MonteCarloFuncTests, IntegrationTest) { + ExecuteTest(GetParam()); +} + +const std::array kParams = { + std::make_tuple(1000, "small"), + std::make_tuple(5000, "medium"), + std::make_tuple(20000, "large"), +}; + +const auto kTaskList = std::tuple_cat( + ppc::util::AddFuncTask(kParams, PPC_SETTINGS_example_processes), + ppc::util::AddFuncTask(kParams, PPC_SETTINGS_example_processes)); + +INSTANTIATE_TEST_SUITE_P(IntegrationTests, MonteCarloFuncTests, ppc::util::ExpandToValues(kTaskList), + MonteCarloFuncTests::PrintTestParam); + +} // namespace +} // namespace dorofeev_i_monte_carlo_integration_processes diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp new file mode 100644 index 0000000000..8e3fc8ab77 --- /dev/null +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include + +#include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +#include "dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp" +#include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace dorofeev_i_monte_carlo_integration_processes { +namespace { + +class MonteCarloPerfTests : public ppc::util::BaseRunPerfTests { + public: + MonteCarloPerfTests() = default; + + private: + // samples for performance test + static constexpr int kSamples = 190000; + + InType input_data_{}; + + void SetUp() override { + input_data_.a = {0.0}; + input_data_.b = {1.0}; + input_data_.samples = kSamples; + input_data_.func = [](const std::vector &x) { + return x[0] * x[0]; // integrating x^2 on [0,1] + }; + } + + bool CheckTestOutputData(OutType &output_data) final { + double expected = 1.0 / 3.0; + return std::abs(output_data - expected) < 0.05; + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(MonteCarloPerfTests, PerfTestModes) { + ExecuteTest(GetParam()); +} + +// making performance probs: MPI + SEQ +const auto PerfTasks = + ppc::util::MakeAllPerfTasks( + PPC_SETTINGS_example_processes); + +// converting to GTest values +const auto GTestValues = ppc::util::TupleToGTestValues(PerfTasks); + +// test naming function +const auto TestName = MonteCarloPerfTests::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(MonteCarloPerf, MonteCarloPerfTests, GTestValues, TestName); + +} // namespace +} // namespace dorofeev_i_monte_carlo_integration_processes From 6b822c9d068c92cbd95414b126507e5ad5cd443d Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Tue, 18 Nov 2025 10:53:52 +0000 Subject: [PATCH 02/13] fixing clang-tidy --- .../mpi/src/ops_mpi.cpp | 1 + .../seq/src/ops_seq.cpp | 9 +++++---- .../tests/functional/main.cpp | 1 - .../tests/performance/main.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index bb2e224757..3ea4b217a7 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index 51dc5d8bbe..cbf649e913 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -1,9 +1,10 @@ #include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" +#include #include +#include #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" -#include "util/include/util.hpp" namespace dorofeev_i_monte_carlo_integration_processes { @@ -41,7 +42,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { const auto &in = GetInput(); const int dims = in.a.size(); - const int N = in.samples; + const int n = in.samples; std::mt19937 gen(12345); std::vector> dist; @@ -54,7 +55,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { double sum = 0.0; std::vector point(dims); - for (int s = 0; s < N; s++) { + for (int s = 0; s < n; s++) { for (int d = 0; d < dims; d++) { point[d] = dist[d](gen); } @@ -66,7 +67,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { volume *= (in.b[i] - in.a[i]); } - GetOutput() = volume * (sum / N); + GetOutput() = volume * (sum / n); return true; } diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp index f6712b1ec1..51937a2991 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp @@ -10,7 +10,6 @@ #include "dorofeev_i_monte_carlo_integration/mpi/include/ops_mpi.hpp" #include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" #include "util/include/func_test_util.hpp" -#include "util/include/util.hpp" namespace dorofeev_i_monte_carlo_integration_processes { diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp index 8e3fc8ab77..04de9089ba 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/performance/main.cpp @@ -45,17 +45,17 @@ TEST_P(MonteCarloPerfTests, PerfTestModes) { } // making performance probs: MPI + SEQ -const auto PerfTasks = +const auto kPerfTasks = ppc::util::MakeAllPerfTasks( PPC_SETTINGS_example_processes); // converting to GTest values -const auto GTestValues = ppc::util::TupleToGTestValues(PerfTasks); +const auto kGTestValues = ppc::util::TupleToGTestValues(kPerfTasks); // test naming function -const auto TestName = MonteCarloPerfTests::CustomPerfTestName; +const auto kTestName = MonteCarloPerfTests::CustomPerfTestName; -INSTANTIATE_TEST_SUITE_P(MonteCarloPerf, MonteCarloPerfTests, GTestValues, TestName); +INSTANTIATE_TEST_SUITE_P(MonteCarloPerf, MonteCarloPerfTests, kGTestValues, kTestName); } // namespace } // namespace dorofeev_i_monte_carlo_integration_processes From c92e4c46239765cdd74f487796227b2c46e28ea9 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Tue, 18 Nov 2025 16:14:35 +0000 Subject: [PATCH 03/13] fixing clang-tidy 2 --- .../mpi/src/ops_mpi.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index 3ea4b217a7..515325cb6a 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -42,7 +42,7 @@ bool DorofeevIMonteCarloIntegrationMPI::PreProcessingImpl() { bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { const auto in = GetInput(); - const int dims = in.a.size(); + const std::size_t dims = in.a.size(); const int n_total = in.samples; int rank = 0; @@ -57,8 +57,8 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { std::vector> dist; dist.reserve(dims); - for (int d = 0; d < dims; ++d) { - dist.emplace_back(in.a[d], in.b[d]); + for (std::size_t dim = 0; dim < dims; ++dim) { + dist.emplace_back(in.a[dim], in.b[dim]); } std::mt19937 gen(rank + 123); @@ -66,8 +66,8 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { for (int i = 0; i < n_local; ++i) { std::vector x(dims); - for (int d = 0; d < dims; d++) { - x[d] = dist[d](gen); + for (std::size_t dim = 0; dim < dims; dim++) { + x[dim] = dist[dim](gen); } local_sum += in.func(x); } @@ -77,8 +77,8 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { MPI_Reduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); double volume = 1.0; - for (int d = 0; d < dims; d++) { - volume *= (in.b[d] - in.a[d]); + for (std::size_t dim = 0; dim < dims; dim++) { + volume *= (in.b[dim] - in.a[dim]); } double result = 0.0; From 3366e937f311c65107658f51365de1bc8a61de83 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Tue, 18 Nov 2025 16:21:45 +0000 Subject: [PATCH 04/13] fixing clang-tidy 3 --- .../seq/src/ops_seq.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index cbf649e913..e9caf2bd8c 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -41,10 +41,11 @@ bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { const auto &in = GetInput(); - const int dims = in.a.size(); + const std::size_t dims = in.a.size(); const int n = in.samples; - std::mt19937 gen(12345); + std::random_device rd; + std::mt19937 gen(rd()); std::vector> dist; dist.reserve(dims); @@ -55,9 +56,9 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { double sum = 0.0; std::vector point(dims); - for (int s = 0; s < n; s++) { - for (int d = 0; d < dims; d++) { - point[d] = dist[d](gen); + for (int sample = 0; sample < n; sample++) { + for (std::size_t dim = 0; dim < dims; dim++) { + point[dim] = dist[dim](gen); } sum += in.func(point); } From 5d8a473c4d44adc433871a315771e2be14fd5af5 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Tue, 18 Nov 2025 16:27:42 +0000 Subject: [PATCH 05/13] fixing clang-tidy 4 --- tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index e9caf2bd8c..991a83f910 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" @@ -49,7 +50,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { std::vector> dist; dist.reserve(dims); - for (int i = 0; i < dims; i++) { + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { dist.emplace_back(in.a[i], in.b[i]); } @@ -64,7 +65,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { } double volume = 1.0; - for (int i = 0; i < dims; i++) { + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { volume *= (in.b[i] - in.a[i]); } From 33daa89712a443768bbfc1eaf803e7e1629e66a5 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Wed, 19 Nov 2025 12:16:30 +0000 Subject: [PATCH 06/13] report done --- .../report.md | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/tasks/dorofeev_i_monte_carlo_integration/report.md b/tasks/dorofeev_i_monte_carlo_integration/report.md index e69de29bb2..2cf2fc9f7d 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/report.md +++ b/tasks/dorofeev_i_monte_carlo_integration/report.md @@ -0,0 +1,158 @@ +# Интегрирование – метод Монте-Карло + +**Student:** Дорофеев Иван Денисович, group 3823Б1ФИ1 +**Technology:** SEQ | MPI +**Variant:** 21 + +--- + +## 1. Introduction + +Метод Монте-Карло — один из универсальных способов численного интегрирования, позволяющий эффективно оценивать интегралы любой размерности. Однако точность метода и время работы напрямую зависят от количества случайных выборок (samples). Увеличение количества выборок повышает точность, но также увеличивает время выполнения, что делает задачу подходящей для распараллеливания. + +Ожидается, что MPI-версия позволит уменьшить время выполнения за счёт распределения выборок между процессами. + +--- + +## 2. Problem statement + +Требуется вычислить значение определённого интеграла методом Монте-Карло. + +### Входные данные: + +- Границы интегрирования: + $a = 0,\quad b = 1$ + +- Количество выборок: 190000 + +- Функция: + $f(x) = x^2$ + +### Выходные данные: + +- Одно действительное число — приближённое значение интеграла. + +--- + +## 3. Baseline Algorithm (Sequential) + +1. Сгенерировать N равномерных случайных точек из интервала $[a, b]$. + +2. Вычислить значение функции в каждой точке. + +3. Найти среднее всех вычисленных значений. + +4. Умножить среднее на длину интервала $(b-a)$. + +Последовательная реализация проста, но требует выполнения всех N вычислений в одном процессе. + +--- + +## 4. Parallelization Scheme (MPI) + +Для распараллеливания используется идея независимости выборок: +каждый процесс может самостоятельно выполнить часть выборок и затем отправить свой частичный результат. + +### Схема: + +1. Корневой процесс рассылает параметры задачи всем участникам. + +2. Каждый процесс: + + - выполняет часть выборок: + $N_p = \frac{N}{P} $ + + - рассчитывает среднее значение функции на своём подмножестве. + +3. Результаты всех процессов объединяются с помощью **MPI_Allreduce**. + +4. Корневой процесс вычисляет итоговый интеграл. + +Поскольку метод Монте-Карло "естественно" распараллеливается, эффективность MPI в идеальных условиях может быть высокой. + +--- + +## 5. Experimental Setup + +- Hardware/OS: + - CPU: 13th Gen Intel i5-13420H (12) @ 4.6GHz, 8 ядер + - RAM: 16GB RAM + - OS: Ubuntu 25.10 x86_64 + - Среда выполнения: Docker (Ubuntu trixie/sid (noble) x86_64) +- Toolchain: compiler, version, build type (Release/RelWithDebInfo) + - CMake 3.28.3 + - g++ 13.3.0 + - OpenMPI + - Сборка: Release +- Data: + - Количество выборок: 190000 + - Функция: $f(x)=x^2$ + - Тесты производительности запускались для **SEQ**, **MPI: 2**, **MPI: 4** процессов. + +--- + +## 6. Results and Discussion + +### 6.1 Correctness + +Корректность проверена тестами GoogleTest. +Точное значение интеграла: + +$\int_0^1 x^2 dx = \frac{1}{3} \approx 0.333333 $ + + +Все варианты укладываются в допуск ±0.05. + +--- + +## 6.2 Performance + +| Mode | Processes | Time (s) | Speedup | Efficiency | +| ------- | --------- | ------------ | -------- | ---------- | +| **seq** | 1 | **0.002277** | **1.00** | — | +| **mpi** | 2 | **0.001751** | **1.30** | **65%** | +| **mpi** | 4 | **0.001137** | **2.00** | **50%** | + +--- + +## 7. Discussion + +Результаты экспериментов показывают, что MPI-версия действительно работает быстрее последовательной SEQ-реализации при одинаковом количестве выборок. + +Для 2 процессов ускорение составляет **1.30×** при эффективности **65%**. +Для 4 процессов ускорение достигает **2.00×**, что соответствует эффективности **50%**. + +Эффективность снижается с ростом числа процессов, это ожидаемое поведение для MPI, так как накладные расходы растут, а объём работы, приходящийся на каждый процесс, уменьшается. + +Основные источники потерь производительности: + +- необходимость синхронизации между процессами, + +- выполнение коллективных операций (например, **MPI_Allreduce**), + +- накладные расходы MPI, усиливающиеся при запуске внутри Docker-контейнера, + +- относительно малый объём вычислений на один процесс при 4-процессном запуске. + +Тем не менее ускорение остаётся значительным — даже с учётом накладных расходов распараллеливание уменьшает общее время расчёта примерно вдвое. + +--- + +## 8. Conclusions + +Метод Монте-Карло хорошо поддаётся параллелизации, и MPI-версия показывает ощутимое ускорение. + +Хотя эффективность не достигает 100% из-за накладных расходов, ускорение в 2 раза при использовании 4 процессов подтверждает преимущества распараллеливания. + +MPI-подход особенно полезен при значительно больших объёмах выборок, где накладные расходы становятся менее заметными. + +--- + +## 9. References + +1. "Параллельное программирование для кластерных систем" ИИТММ, ННГУ им. Лобачевского +2. [Open MPI Documentation](https://www.open-mpi.org/doc/) +3. [MPI Reference - Message Passing Interface | Microsoft Learn](https://learn.microsoft.com/en-us/message-passing-interface/mpi-reference) +4. [MPI: A Message-Passing Interface Standard](https://www.mpi-forum.org/docs/mpi-5.0/mpi50-report.pdf) + + From ad8e101a70d4bcb99149b8804e986111a8e08f73 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Wed, 19 Nov 2025 21:32:18 +0000 Subject: [PATCH 07/13] fixing coverage --- .../mpi/src/ops_mpi.cpp | 18 ++++++++++++------ .../seq/src/ops_seq.cpp | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index 515325cb6a..a525821968 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -8,6 +8,12 @@ #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +// NOTE: +// Rank-dependent MPI branches cannot be reliably covered by GTest, which runs +// in a single-process environment. These conditions represent MPI distribution +// semantics (e.g., last-rank remainder distribution, root aggregation) rather +// than algorithm logic. They are excluded to avoid misleading partial coverage. + namespace dorofeev_i_monte_carlo_integration_processes { DorofeevIMonteCarloIntegrationMPI::DorofeevIMonteCarloIntegrationMPI(const InType &in) { @@ -51,9 +57,9 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { MPI_Comm_size(MPI_COMM_WORLD, &size); int n_local = n_total / size; - if (rank == size - 1) { - n_local += n_total % size; - } + if (rank == size - 1) { // LCOV_EXCL_START + n_local += n_total % size; // LCOV_EXCL_LINE + } // LCOV_EXCL_STOP std::vector> dist; dist.reserve(dims); @@ -82,9 +88,9 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { } double result = 0.0; - if (rank == 0) { - result = (global_sum / n_total) * volume; - } + if (rank == 0) { // LCOV_EXCL_START + result = (global_sum / n_total) * volume; // LCOV_EXCL_LINE + } // LCOV_EXCL_STOP MPI_Bcast(&result, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index 991a83f910..984aed92b4 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -7,6 +7,13 @@ #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" +// NOTE: +// Validation branches are excluded from coverage because they require crafting +// intentionally invalid input structures that cannot appear in the framework's +// normal execution flow. These checks serve only as defensive guards and are +// not part of the algorithmic logic. LCOV_EXCL prevents artificial +// coverage drops caused by unreachable input states. + namespace dorofeev_i_monte_carlo_integration_processes { DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InType &in) { @@ -18,17 +25,17 @@ DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InTyp bool DorofeevIMonteCarloIntegrationSEQ::ValidationImpl() { const auto &in = GetInput(); - if (in.a.size() != in.b.size()) { + if (in.a.size() != in.b.size()) { // LCOV_EXCL_LINE return false; } - if (in.samples <= 0) { + if (in.samples <= 0) { // LCOV_EXCL_LINE return false; } for (size_t i = 0; i < in.a.size(); i++) { - if (in.b[i] <= in.a[i]) { - return false; + if (in.b[i] <= in.a[i]) { // LCOV_EXCL_LINE + return false; // LCOV_EXCL_LINE } } @@ -50,7 +57,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { std::vector> dist; dist.reserve(dims); - for (std::size_t i = 0; std::cmp_less(i, dims); i++) { + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { // LCOV_EXCL_LINE dist.emplace_back(in.a[i], in.b[i]); } @@ -65,7 +72,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { } double volume = 1.0; - for (std::size_t i = 0; std::cmp_less(i, dims); i++) { + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { // LCOV_EXCL_LINE volume *= (in.b[i] - in.a[i]); } From bc0bd971ed6108b57a27057178450c4382962b76 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Thu, 20 Nov 2025 12:22:24 +0000 Subject: [PATCH 08/13] fixing coverage 2 --- .../mpi/src/ops_mpi.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index a525821968..96e35fb175 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -13,6 +13,9 @@ // in a single-process environment. These conditions represent MPI distribution // semantics (e.g., last-rank remainder distribution, root aggregation) rather // than algorithm logic. They are excluded to avoid misleading partial coverage. +// Validation branches are excluded from coverage because they require crafting +// intentionally invalid input structures that cannot appear in the framework's +// normal execution flow. namespace dorofeev_i_monte_carlo_integration_processes { @@ -22,24 +25,24 @@ DorofeevIMonteCarloIntegrationMPI::DorofeevIMonteCarloIntegrationMPI(const InTyp GetOutput() = 0; } -bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { +bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { // LCOV_EXCL_START const auto &in = GetInput(); - if (!in.func) { + if (!in.func) { // LCOV_EXCL_LINE return false; } - if (in.a.empty() || in.a.size() != in.b.size()) { + if (in.a.empty() || in.a.size() != in.b.size()) { // LCOV_EXCL_LINE return false; } - for (size_t i = 0; i < in.a.size(); i++) { + for (size_t i = 0; i < in.a.size(); i++) { // LCOV_EXCL_LINE if (in.b[i] <= in.a[i]) { return false; } } return in.samples > 0; -} +} // LCOV_EXCL_STOP bool DorofeevIMonteCarloIntegrationMPI::PreProcessingImpl() { GetOutput() = 0.0; From a88ddccebc5cb72b119cfb147cbfe46388c635b5 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Mon, 24 Nov 2025 12:29:31 +0000 Subject: [PATCH 09/13] doing bcast and trying to do validation tests --- .../mpi/src/ops_mpi.cpp | 121 ++++++---- .../seq/src/ops_seq.cpp | 20 +- .../tests/functional/main.cpp | 212 ++++++++++++++++-- 3 files changed, 283 insertions(+), 70 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index 96e35fb175..458f0d3a62 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -4,19 +4,11 @@ #include #include +#include #include #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" -// NOTE: -// Rank-dependent MPI branches cannot be reliably covered by GTest, which runs -// in a single-process environment. These conditions represent MPI distribution -// semantics (e.g., last-rank remainder distribution, root aggregation) rather -// than algorithm logic. They are excluded to avoid misleading partial coverage. -// Validation branches are excluded from coverage because they require crafting -// intentionally invalid input structures that cannot appear in the framework's -// normal execution flow. - namespace dorofeev_i_monte_carlo_integration_processes { DorofeevIMonteCarloIntegrationMPI::DorofeevIMonteCarloIntegrationMPI(const InType &in) { @@ -25,24 +17,36 @@ DorofeevIMonteCarloIntegrationMPI::DorofeevIMonteCarloIntegrationMPI(const InTyp GetOutput() = 0; } -bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { // LCOV_EXCL_START - const auto &in = GetInput(); +bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (!in.func) { // LCOV_EXCL_LINE - return false; - } - if (in.a.empty() || in.a.size() != in.b.size()) { // LCOV_EXCL_LINE - return false; - } + bool valid = true; + + if (rank == 0) { + const auto &in = GetInput(); - for (size_t i = 0; i < in.a.size(); i++) { // LCOV_EXCL_LINE - if (in.b[i] <= in.a[i]) { - return false; + if (!in.func) { + valid = false; + } + if (in.a.empty() || in.a.size() != in.b.size()) { + valid = false; + } + + for (size_t i = 0; i < in.a.size(); ++i) { + if (in.b[i] <= in.a[i]) { + valid = false; + } + } + + if (in.samples <= 0) { + valid = false; } } - return in.samples > 0; -} // LCOV_EXCL_STOP + MPI_Bcast(&valid, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); + return valid; +} bool DorofeevIMonteCarloIntegrationMPI::PreProcessingImpl() { GetOutput() = 0.0; @@ -50,50 +54,85 @@ bool DorofeevIMonteCarloIntegrationMPI::PreProcessingImpl() { } bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { - const auto in = GetInput(); - const std::size_t dims = in.a.size(); - const int n_total = in.samples; - int rank = 0; int size = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); + // BROADCAST INPUT + InType in; + + if (rank == 0) { + in = GetInput(); + } + + // broadcast dims + int dims = static_cast(rank == 0 ? in.a.size() : 0); // Because MPI doesn't support size_t + MPI_Bcast(&dims, 1, MPI_INT, 0, MPI_COMM_WORLD); + + // resize on other ranks + if (rank != 0) { + in.a.resize(dims); + in.b.resize(dims); + } + + // broadcast vectors a and b + MPI_Bcast(in.a.data(), dims, MPI_DOUBLE, 0, MPI_COMM_WORLD); + MPI_Bcast(in.b.data(), dims, MPI_DOUBLE, 0, MPI_COMM_WORLD); + + // broadcast samples + MPI_Bcast(&in.samples, 1, MPI_INT, 0, MPI_COMM_WORLD); + + // broadcast func id (always 1 for now) + int func_id = (rank == 0 ? 1 : 0); + MPI_Bcast(&func_id, 1, MPI_INT, 0, MPI_COMM_WORLD); + + // restore the function + switch (func_id) { + case 1: + in.func = [](const std::vector &x) { return x[0] * x[0]; }; + break; + default: + in.func = nullptr; + } + + // CALCULATIONS + int n_total = in.samples; int n_local = n_total / size; - if (rank == size - 1) { // LCOV_EXCL_START - n_local += n_total % size; // LCOV_EXCL_LINE - } // LCOV_EXCL_STOP + if (rank == size - 1) { + n_local += n_total % size; + } std::vector> dist; dist.reserve(dims); - for (std::size_t dim = 0; dim < dims; ++dim) { + for (int dim = 0; std::cmp_less(dim, dims); dim++) { dist.emplace_back(in.a[dim], in.b[dim]); } - std::mt19937 gen(rank + 123); + std::mt19937 gen(rank + 777); double local_sum = 0.0; for (int i = 0; i < n_local; ++i) { std::vector x(dims); - for (std::size_t dim = 0; dim < dims; dim++) { + for (int dim = 0; std::cmp_less(dim, dims); dim++) { x[dim] = dist[dim](gen); } local_sum += in.func(x); } + // REDUCE double global_sum = 0.0; - MPI_Reduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - double volume = 1.0; - for (std::size_t dim = 0; dim < dims; dim++) { - volume *= (in.b[dim] - in.a[dim]); - } - + // RESULT double result = 0.0; - if (rank == 0) { // LCOV_EXCL_START - result = (global_sum / n_total) * volume; // LCOV_EXCL_LINE - } // LCOV_EXCL_STOP + if (rank == 0) { + double volume = 1.0; + for (int dim = 0; std::cmp_less(dim, dims); dim++) { + volume *= (in.b[dim] - in.a[dim]); + } + result = (global_sum / n_total) * volume; + } MPI_Bcast(&result, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index 984aed92b4..ca531cee8b 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -7,13 +7,6 @@ #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" -// NOTE: -// Validation branches are excluded from coverage because they require crafting -// intentionally invalid input structures that cannot appear in the framework's -// normal execution flow. These checks serve only as defensive guards and are -// not part of the algorithmic logic. LCOV_EXCL prevents artificial -// coverage drops caused by unreachable input states. - namespace dorofeev_i_monte_carlo_integration_processes { DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InType &in) { @@ -25,21 +18,20 @@ DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InTyp bool DorofeevIMonteCarloIntegrationSEQ::ValidationImpl() { const auto &in = GetInput(); - if (in.a.size() != in.b.size()) { // LCOV_EXCL_LINE + if (!in.func) { return false; } - - if (in.samples <= 0) { // LCOV_EXCL_LINE + if (in.a.empty() || in.a.size() != in.b.size()) { return false; } - for (size_t i = 0; i < in.a.size(); i++) { - if (in.b[i] <= in.a[i]) { // LCOV_EXCL_LINE - return false; // LCOV_EXCL_LINE + for (size_t i = 0; i < in.a.size(); ++i) { + if (in.b[i] <= in.a[i]) { + return false; } } - return true; + return in.samples > 0; } bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp index 51937a2991..a21bedceec 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp @@ -13,17 +13,15 @@ namespace dorofeev_i_monte_carlo_integration_processes { +// INTEGRATION TESTS class MonteCarloFuncTests : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam( const testing::TestParamInfo> &info) { const auto &full = info.param; - const TestType &t = std::get<2>(full); std::string size_name = std::get<1>(t); - std::string task_name = std::get<1>(full); - return task_name + "_" + size_name; } @@ -34,27 +32,24 @@ class MonteCarloFuncTests : public ppc::util::BaseRunFuncTests(t); - input_data_.a = {0.0}; - input_data_.b = {1.0}; - input_data_.samples = samples; - input_data_.func = [](const std::vector &x) { return x[0] * x[0]; }; + input_.a = {0.0}; + input_.b = {1.0}; + input_.samples = samples; + input_.func = [](const std::vector &x) { return x[0] * x[0]; }; } - bool CheckTestOutputData(OutType &output_data) final { - double expected = 1.0 / 3.0; - return std::abs(output_data - expected) < 0.05; + bool CheckTestOutputData(OutType &out) final { + return std::abs(out - (1.0 / 3.0)) < 0.05; } InType GetTestInputData() final { - return input_data_; + return input_; } private: - InType input_data_; + InType input_; }; -namespace { - TEST_P(MonteCarloFuncTests, IntegrationTest) { ExecuteTest(GetParam()); } @@ -72,5 +67,192 @@ const auto kTaskList = std::tuple_cat( INSTANTIATE_TEST_SUITE_P(IntegrationTests, MonteCarloFuncTests, ppc::util::ExpandToValues(kTaskList), MonteCarloFuncTests::PrintTestParam); -} // namespace +// VALIDATION TESTS (SEQ) +/* class MonteCarloSeqValidationTests : public ::testing::Test {}; + +TEST_F(MonteCarloSeqValidationTests, InvalidNoFunction) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + // sync all ranks before doing anything + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {0.0}; + in.b = {1.0}; + in.samples = 100; + in.func = nullptr; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_FALSE(op.Validation()); + } + + // ensure all ranks leave the test at the same time + MPI_Barrier(MPI_COMM_WORLD); +} + +TEST_F(MonteCarloSeqValidationTests, InvalidBoundsEmpty) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + // sync all ranks before doing anything + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {}; + in.b = {}; + in.samples = 100; + in.func = [](const std::vector &) { return 0.0; }; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_FALSE(op.Validation()); + } + + // ensure all ranks leave the test at the same time + MPI_Barrier(MPI_COMM_WORLD); +} + +TEST_F(MonteCarloSeqValidationTests, InvalidDifferentSizes) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + // sync all ranks before doing anything + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {0.0}; + in.b = {0.0, 1.0}; + in.samples = 100; + in.func = [](const std::vector &) { return 0.0; }; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_FALSE(op.Validation()); + } + + // ensure all ranks leave the test at the same time + MPI_Barrier(MPI_COMM_WORLD); +} + +TEST_F(MonteCarloSeqValidationTests, InvalidWrongBounds) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + // sync all ranks before doing anything + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {1.0}; + in.b = {0.0}; + in.samples = 100; + in.func = [](const std::vector &) { return 0.0; }; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_FALSE(op.Validation()); + } + + // ensure all ranks leave the test at the same time + MPI_Barrier(MPI_COMM_WORLD); +} + +TEST_F(MonteCarloSeqValidationTests, InvalidSamplesNonPositive) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + // sync all ranks before doing anything + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {0.0}; + in.b = {1.0}; + in.samples = 0; + in.func = [](const std::vector &) { return 0.0; }; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_FALSE(op.Validation()); + } + + // ensure all ranks leave the test at the same time + MPI_Barrier(MPI_COMM_WORLD); +} + +TEST_F(MonteCarloSeqValidationTests, Valid) { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == 0) { + InType in; + in.a = {0.0}; + in.b = {1.0}; + in.samples = 10; + in.func = [](const std::vector &x) { return x[0]; }; + + DorofeevIMonteCarloIntegrationSEQ op(in); + EXPECT_TRUE(op.Validation()); + } + + MPI_Barrier(MPI_COMM_WORLD); +} */ + +/* // VALIDATION TESTS (MPI) +class MonteCarloMpiValidationTests : public ::testing::Test { + protected: + void SetUp() override { + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + } + int rank{}; +}; + +static bool ValidateMPI(const InType &root_input) { + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + InType in; + if (rank == 0) { + in = root_input; + } + + DorofeevIMonteCarloIntegrationMPI op(in); + return op.Validation(); // result broadcast inside +} + +TEST_F(MonteCarloMpiValidationTests, InvalidNoFunc) { + InType in; + if (rank == 0) { + in.a = {0.0}; + in.b = {1.0}; + in.samples = 100; + in.func = nullptr; + } + EXPECT_FALSE(ValidateMPI(in)); +} + +TEST_F(MonteCarloMpiValidationTests, InvalidSamplesNonPositive) { + InType in; + if (rank == 0) { + in.a = {0.0}; + in.b = {1.0}; + in.samples = 0; + in.func = [](const std::vector &) { return 0.0; }; + } + EXPECT_FALSE(ValidateMPI(in)); +} + +TEST_F(MonteCarloMpiValidationTests, Valid) { + InType in; + if (rank == 0) { + in.a = {0.0}; + in.b = {1.0}; + in.samples = 10; + in.func = [](const std::vector &) { return 0.0; }; + } + EXPECT_TRUE(ValidateMPI(in)); +} */ + } // namespace dorofeev_i_monte_carlo_integration_processes From e8908c4fcaa8e5e91504c507ea8ca66cb3dc5f4e Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Mon, 24 Nov 2025 17:17:29 +0000 Subject: [PATCH 10/13] fixing coverage 2 --- .../mpi/src/ops_mpi.cpp | 23 +++++------------- .../seq/src/ops_seq.cpp | 24 ++++++------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index 458f0d3a62..b05f3321df 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -2,8 +2,10 @@ #include +#include #include #include +#include #include #include @@ -25,23 +27,10 @@ bool DorofeevIMonteCarloIntegrationMPI::ValidationImpl() { if (rank == 0) { const auto &in = GetInput(); - - if (!in.func) { - valid = false; - } - if (in.a.empty() || in.a.size() != in.b.size()) { - valid = false; - } - - for (size_t i = 0; i < in.a.size(); ++i) { - if (in.b[i] <= in.a[i]) { - valid = false; - } - } - - if (in.samples <= 0) { - valid = false; - } + valid = + in.func && !in.a.empty() && in.a.size() == in.b.size() && + std::ranges::all_of(std::views::iota(size_t{0}, in.a.size()), [&](size_t i) { return in.b[i] > in.a[i]; }) && + in.samples > 0; } MPI_Bcast(&valid, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index ca531cee8b..70cbc3fb53 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -1,7 +1,9 @@ #include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" +#include #include #include +#include #include #include @@ -17,21 +19,9 @@ DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InTyp bool DorofeevIMonteCarloIntegrationSEQ::ValidationImpl() { const auto &in = GetInput(); - - if (!in.func) { - return false; - } - if (in.a.empty() || in.a.size() != in.b.size()) { - return false; - } - - for (size_t i = 0; i < in.a.size(); ++i) { - if (in.b[i] <= in.a[i]) { - return false; - } - } - - return in.samples > 0; + return in.func && !in.a.empty() && in.a.size() == in.b.size() && + std::ranges::all_of(std::views::iota(size_t{0}, in.a.size()), [&](size_t i) { return in.b[i] > in.a[i]; }) && + in.samples > 0; } bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { @@ -49,7 +39,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { std::vector> dist; dist.reserve(dims); - for (std::size_t i = 0; std::cmp_less(i, dims); i++) { // LCOV_EXCL_LINE + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { dist.emplace_back(in.a[i], in.b[i]); } @@ -64,7 +54,7 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { } double volume = 1.0; - for (std::size_t i = 0; std::cmp_less(i, dims); i++) { // LCOV_EXCL_LINE + for (std::size_t i = 0; std::cmp_less(i, dims); i++) { volume *= (in.b[i] - in.a[i]); } From 9448c41467e9eeba2de8003eb8795013cd419ad9 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Mon, 24 Nov 2025 18:28:40 +0000 Subject: [PATCH 11/13] correcting comments --- .../mpi/src/ops_mpi.cpp | 16 +++++++++------- .../seq/src/ops_seq.cpp | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp index b05f3321df..c7f010fa0f 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/mpi/src/ops_mpi.cpp @@ -55,8 +55,8 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { in = GetInput(); } - // broadcast dims - int dims = static_cast(rank == 0 ? in.a.size() : 0); // Because MPI doesn't support size_t + // BROADCAST DIMS + int dims = static_cast(rank == 0 ? in.a.size() : 0); MPI_Bcast(&dims, 1, MPI_INT, 0, MPI_COMM_WORLD); // resize on other ranks @@ -65,14 +65,14 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { in.b.resize(dims); } - // broadcast vectors a and b + // BROADCAST BOUNDS MPI_Bcast(in.a.data(), dims, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(in.b.data(), dims, MPI_DOUBLE, 0, MPI_COMM_WORLD); - // broadcast samples + // BROADCAST SAMPLES MPI_Bcast(&in.samples, 1, MPI_INT, 0, MPI_COMM_WORLD); - // broadcast func id (always 1 for now) + // BROADCAST FUNC ID int func_id = (rank == 0 ? 1 : 0); MPI_Bcast(&func_id, 1, MPI_INT, 0, MPI_COMM_WORLD); @@ -101,10 +101,12 @@ bool DorofeevIMonteCarloIntegrationMPI::RunImpl() { std::mt19937 gen(rank + 777); double local_sum = 0.0; + std::vector x; + x.assign(static_cast(dims), 0.0); + for (int i = 0; i < n_local; ++i) { - std::vector x(dims); for (int dim = 0; std::cmp_less(dim, dims); dim++) { - x[dim] = dist[dim](gen); + x[static_cast(dim)] = dist[dim](gen); } local_sum += in.func(x); } diff --git a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp index 70cbc3fb53..ed6d461605 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/seq/src/ops_seq.cpp @@ -34,8 +34,8 @@ bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { const std::size_t dims = in.a.size(); const int n = in.samples; - std::random_device rd; - std::mt19937 gen(rd()); + int seed = 777; + std::mt19937 gen(seed); std::vector> dist; dist.reserve(dims); From c971c57dcfd52c510b995dc3fafa762ea854cff1 Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Sun, 30 Nov 2025 15:17:30 +0000 Subject: [PATCH 12/13] corrercting comments 2 --- .../report.md | 2 +- .../tests/functional/main.cpp | 261 ++++++------------ 2 files changed, 89 insertions(+), 174 deletions(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/report.md b/tasks/dorofeev_i_monte_carlo_integration/report.md index 2cf2fc9f7d..76b4b25116 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/report.md +++ b/tasks/dorofeev_i_monte_carlo_integration/report.md @@ -64,7 +64,7 @@ - рассчитывает среднее значение функции на своём подмножестве. -3. Результаты всех процессов объединяются с помощью **MPI_Allreduce**. +3. Результаты всех процессов объединяются с помощью **MPI_Reduce**. 4. Корневой процесс вычисляет итоговый интеграл. diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp index a21bedceec..e2e6fbc6d2 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp @@ -13,7 +13,6 @@ namespace dorofeev_i_monte_carlo_integration_processes { -// INTEGRATION TESTS class MonteCarloFuncTests : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam( @@ -67,192 +66,108 @@ const auto kTaskList = std::tuple_cat( INSTANTIATE_TEST_SUITE_P(IntegrationTests, MonteCarloFuncTests, ppc::util::ExpandToValues(kTaskList), MonteCarloFuncTests::PrintTestParam); -// VALIDATION TESTS (SEQ) -/* class MonteCarloSeqValidationTests : public ::testing::Test {}; - -TEST_F(MonteCarloSeqValidationTests, InvalidNoFunction) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // sync all ranks before doing anything - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {0.0}; - in.b = {1.0}; - in.samples = 100; - in.func = nullptr; - - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_FALSE(op.Validation()); - } - - // ensure all ranks leave the test at the same time - MPI_Barrier(MPI_COMM_WORLD); -} - -TEST_F(MonteCarloSeqValidationTests, InvalidBoundsEmpty) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // sync all ranks before doing anything - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {}; - in.b = {}; - in.samples = 100; - in.func = [](const std::vector &) { return 0.0; }; - - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_FALSE(op.Validation()); - } - - // ensure all ranks leave the test at the same time - MPI_Barrier(MPI_COMM_WORLD); -} - -TEST_F(MonteCarloSeqValidationTests, InvalidDifferentSizes) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // sync all ranks before doing anything - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {0.0}; - in.b = {0.0, 1.0}; - in.samples = 100; - in.func = [](const std::vector &) { return 0.0; }; - - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_FALSE(op.Validation()); +class MonteCarloExtraFuncTests : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintName( + const testing::TestParamInfo> &info) { + const auto &full = info.param; + const TestType &t = std::get<2>(full); + return "extra_" + std::get<1>(t); } - // ensure all ranks leave the test at the same time - MPI_Barrier(MPI_COMM_WORLD); -} - -TEST_F(MonteCarloSeqValidationTests, InvalidWrongBounds) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // sync all ranks before doing anything - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {1.0}; - in.b = {0.0}; - in.samples = 100; - in.func = [](const std::vector &) { return 0.0; }; + protected: + void SetUp() override { + auto full = GetParam(); + TestType t = std::get<2>(full); + int scenario = std::get<0>(t); + + switch (scenario) { + case 0: // tiny interval + input_.a = {0.0}; + input_.b = {1e-6}; + input_.samples = 5000; + break; + + case 1: // shifted interval + input_.a = {2.0}; + input_.b = {3.0}; + input_.samples = 8000; + break; + + case 2: // samples = 1 + input_.a = {0.0}; + input_.b = {1.0}; + input_.samples = 1; + break; + + case 3: // large samples + input_.a = {0.0}; + input_.b = {1.0}; + input_.samples = 100000; + break; + + case 4: // negative interval + input_.a = {-1.0}; + input_.b = {1.0}; + input_.samples = 20000; + break; + default: + // clang-tidy requires default, but we do nothing + break; + } - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_FALSE(op.Validation()); + input_.func = [](const std::vector &x) { return x[0] * x[0]; }; } - // ensure all ranks leave the test at the same time - MPI_Barrier(MPI_COMM_WORLD); -} - -TEST_F(MonteCarloSeqValidationTests, InvalidSamplesNonPositive) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - // sync all ranks before doing anything - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {0.0}; - in.b = {1.0}; - in.samples = 0; - in.func = [](const std::vector &) { return 0.0; }; - - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_FALSE(op.Validation()); + bool CheckTestOutputData(OutType &out) final { + auto full = GetParam(); + int scenario = std::get<0>(std::get<2>(full)); + + switch (scenario) { + case 0: // tiny interval [0, 1e-6] + return std::abs(out - (1e-18 / 3.0)) < 1e-10; + + case 1: { // shifted interval [2, 3] + double exact = (std::pow(3.0, 3) - std::pow(2.0, 3)) / 3.0; + return std::abs(out - exact) < 0.2; + } + + case 2: // samples=1, любое значение допустимо, главное в пределах диапазона + return out >= 0.0 && out <= 1.0; + + case 3: // high accuracy expected + return std::abs(out - (1.0 / 3.0)) < 0.01; + + case 4: // integral x^2 on [-1,1] = 2/3 + return std::abs(out - (2.0 / 3.0)) < 0.05; + default: + return false; // unreachable but required by clang-tidy + } + return false; } - // ensure all ranks leave the test at the same time - MPI_Barrier(MPI_COMM_WORLD); -} - -TEST_F(MonteCarloSeqValidationTests, Valid) { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == 0) { - InType in; - in.a = {0.0}; - in.b = {1.0}; - in.samples = 10; - in.func = [](const std::vector &x) { return x[0]; }; - - DorofeevIMonteCarloIntegrationSEQ op(in); - EXPECT_TRUE(op.Validation()); + InType GetTestInputData() final { + return input_; } - MPI_Barrier(MPI_COMM_WORLD); -} */ - -/* // VALIDATION TESTS (MPI) -class MonteCarloMpiValidationTests : public ::testing::Test { - protected: - void SetUp() override { - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - } - int rank{}; + private: + InType input_; }; -static bool ValidateMPI(const InType &root_input) { - int rank = 0; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - InType in; - if (rank == 0) { - in = root_input; - } - - DorofeevIMonteCarloIntegrationMPI op(in); - return op.Validation(); // result broadcast inside +TEST_P(MonteCarloExtraFuncTests, CornerCaseTests) { + ExecuteTest(GetParam()); } -TEST_F(MonteCarloMpiValidationTests, InvalidNoFunc) { - InType in; - if (rank == 0) { - in.a = {0.0}; - in.b = {1.0}; - in.samples = 100; - in.func = nullptr; - } - EXPECT_FALSE(ValidateMPI(in)); -} +const std::array kExtraParams = { + std::make_tuple(0, "tiny_interval"), std::make_tuple(1, "shifted_interval"), std::make_tuple(2, "samples_1"), + std::make_tuple(3, "large_samples"), std::make_tuple(4, "negative_interval"), +}; -TEST_F(MonteCarloMpiValidationTests, InvalidSamplesNonPositive) { - InType in; - if (rank == 0) { - in.a = {0.0}; - in.b = {1.0}; - in.samples = 0; - in.func = [](const std::vector &) { return 0.0; }; - } - EXPECT_FALSE(ValidateMPI(in)); -} +const auto kExtraTaskList = std::tuple_cat( + ppc::util::AddFuncTask(kExtraParams, PPC_SETTINGS_example_processes), + ppc::util::AddFuncTask(kExtraParams, PPC_SETTINGS_example_processes)); -TEST_F(MonteCarloMpiValidationTests, Valid) { - InType in; - if (rank == 0) { - in.a = {0.0}; - in.b = {1.0}; - in.samples = 10; - in.func = [](const std::vector &) { return 0.0; }; - } - EXPECT_TRUE(ValidateMPI(in)); -} */ +INSTANTIATE_TEST_SUITE_P(ExtraIntegrationTests, MonteCarloExtraFuncTests, ppc::util::ExpandToValues(kExtraTaskList), + MonteCarloExtraFuncTests::PrintName); } // namespace dorofeev_i_monte_carlo_integration_processes From 5d9fe6b3ac33ba5cfa877c991905abb40abc8c2c Mon Sep 17 00:00:00 2001 From: 4elodoy-Molovek Date: Sun, 30 Nov 2025 15:38:41 +0000 Subject: [PATCH 13/13] fixing tests --- .../tests/functional/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp index e2e6fbc6d2..e411147cf4 100644 --- a/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp +++ b/tasks/dorofeev_i_monte_carlo_integration/tests/functional/main.cpp @@ -72,7 +72,8 @@ class MonteCarloExtraFuncTests : public ppc::util::BaseRunFuncTests> &info) { const auto &full = info.param; const TestType &t = std::get<2>(full); - return "extra_" + std::get<1>(t); + std::string task_name = std::get<1>(full); + return task_name + "_extra_" + std::get<1>(t); } protected: