Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Бессонов Егор. Задача 2. Вариант 12. Топология сетей передачи данных - Звезда #369

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 265 additions & 0 deletions tasks/mpi/bessonov_e_integration_monte_carlo/func_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
#include <gtest/gtest.h>

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <memory>
#include <random>

#include "mpi/bessonov_e_integration_monte_carlo/include/ops_mpi.hpp"

TEST(bessonov_e_integration_monte_carlo_mpi, PositiveRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = 0.0;
double b = 1.0;
int num_points = 1000000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_EQ(testMpiTaskParallel.validation(), true);
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 1e-1);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, NegativeRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = -1.0;
double b = 0.0;
int num_points = 100000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_EQ(testMpiTaskParallel.validation(), true);
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 1e-1);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, VerySmallRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = 0.1;
double b = 0.11;
int num_points = 100000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_EQ(testMpiTaskParallel.validation(), true);
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 3e-8);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, LongRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = -10.0;
double b = 15.0;
int num_points = 100000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_TRUE(testMpiTaskParallel.validation());
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 1e3);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, VeryLongRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = -40.0;
double b = 50.0;
int num_points = 1000000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_TRUE(testMpiTaskParallel.validation());
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 3e4);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, EqualRangeTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
double a = -2.0;
double b = 2.0;
int num_points = 100000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_TRUE(testMpiTaskParallel.validation());
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 2e-1);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, RandomTestMPI) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(-8.0, 8.0);
double a = dis(gen);
double b = dis(gen);

if (a > b) std::swap(a, b);

if (a == b) b += 1.0;

int num_points = 100000;
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}

bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel testMpiTaskParallel(taskDataPar);
ASSERT_TRUE(testMpiTaskParallel.validation());
testMpiTaskParallel.pre_processing();
testMpiTaskParallel.run();
testMpiTaskParallel.post_processing();

if (world.rank() == 0) {
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));

bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();

ASSERT_NEAR(reference_result[0], global_result[0], 2e1);
}
}
48 changes: 48 additions & 0 deletions tasks/mpi/bessonov_e_integration_monte_carlo/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <gtest/gtest.h>

#include <boost/mpi/collectives.hpp>
#include <boost/mpi/communicator.hpp>
#include <functional>
#include <memory>
#include <random>
#include <utility>
#include <vector>

#include "core/task/include/task.hpp"

namespace bessonov_e_integration_monte_carlo_mpi {

class TestMPITaskSequential : public ppc::core::Task {
public:
explicit TestMPITaskSequential(std::shared_ptr<ppc::core::TaskData> taskData_) : Task(std::move(taskData_)) {}
bool pre_processing() override;
bool validation() override;
bool run() override;
bool post_processing() override;
double a, b;
int num_points;
static double exampl_func(double x) { return x * x * x; }

private:
double res{};
};

class TestMPITaskParallel : public ppc::core::Task {
public:
explicit TestMPITaskParallel(std::shared_ptr<ppc::core::TaskData> taskData_) : Task(std::move(taskData_)) {}
bool pre_processing() override;
bool validation() override;
bool run() override;
bool post_processing() override;
double a, b;
int num_points;
static double exampl_func(double x) { return x * x * x; }

private:
double res;
boost::mpi::communicator world;
};

} // namespace bessonov_e_integration_monte_carlo_mpi
81 changes: 81 additions & 0 deletions tasks/mpi/bessonov_e_integration_monte_carlo/perf_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <gtest/gtest.h>

#include <boost/mpi/timer.hpp>
#include <vector>

#include "core/perf/include/perf.hpp"
#include "mpi/bessonov_e_integration_monte_carlo/include/ops_mpi.hpp"

TEST(bessonov_e_integration_monte_carlo_mpi, test_pipeline_run) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
double a = 0.0;
double b = 2.0;
int num_points = 100000000;
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
auto testMpiTaskParallel = std::make_shared<bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel>(taskDataPar);
ASSERT_EQ(testMpiTaskParallel->validation(), true);
testMpiTaskParallel->pre_processing();
testMpiTaskParallel->run();
testMpiTaskParallel->post_processing();
auto perfAttr = std::make_shared<ppc::core::PerfAttr>();
perfAttr->num_running = 10;
const boost::mpi::timer current_timer;
perfAttr->current_timer = [&] { return current_timer.elapsed(); };
auto perfResults = std::make_shared<ppc::core::PerfResults>();
auto perfAnalyzer = std::make_shared<ppc::core::Perf>(testMpiTaskParallel);
perfAnalyzer->pipeline_run(perfAttr, perfResults);
if (world.rank() == 0) {
ppc::core::Perf::print_perf_statistic(perfResults);
std::vector<double> reference_result(1, 0.0);
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t*>(reference_result.data()));
bessonov_e_integration_monte_carlo_mpi::TestMPITaskSequential testMpiTaskSequential(taskDataSeq);
ASSERT_EQ(testMpiTaskSequential.validation(), true);
testMpiTaskSequential.pre_processing();
testMpiTaskSequential.run();
testMpiTaskSequential.post_processing();
ASSERT_NEAR(reference_result[0], global_result[0], 1e-1);
}
}

TEST(bessonov_e_integration_monte_carlo_mpi, test_task_run) {
boost::mpi::communicator world;
std::vector<double> global_result(1, 0.0);
double a = 0.0;
double b = 2.0;
int num_points = 100000000;
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>();
if (world.rank() == 0) {
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&a));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&b));
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(&num_points));
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_result.data()));
}
auto testMpiTaskParallel = std::make_shared<bessonov_e_integration_monte_carlo_mpi::TestMPITaskParallel>(taskDataPar);
ASSERT_EQ(testMpiTaskParallel->validation(), true);
testMpiTaskParallel->pre_processing();
testMpiTaskParallel->run();
testMpiTaskParallel->post_processing();
auto perfAttr = std::make_shared<ppc::core::PerfAttr>();
perfAttr->num_running = 10;
const boost::mpi::timer current_timer;
perfAttr->current_timer = [&] { return current_timer.elapsed(); };
auto perfResults = std::make_shared<ppc::core::PerfResults>();
auto perfAnalyzer = std::make_shared<ppc::core::Perf>(testMpiTaskParallel);
perfAnalyzer->task_run(perfAttr, perfResults);
if (world.rank() == 0) {
ppc::core::Perf::print_perf_statistic(perfResults);
double reference_result = 4.0;
ASSERT_NEAR(reference_result, global_result[0], 1e-1);
}
}
Loading
Loading