generated from learning-process/parallel_programming_course
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Велиев Эльвин. Задача 1. Вариант 11. Сумма значений по строкам матрицы #791
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bfa7ac6
start
ev1ven da4c386
start 2
ev1ven b7d1610
fix
ev1ven 29c8e3d
fix 2
ev1ven 41cc10f
fix 3
ev1ven 53f590c
fix 4
ev1ven 453230b
fix 5
ev1ven 4035a67
fix 6
ev1ven 813c657
fix spec
ev1ven b593cd7
fix (not my fault)
ev1ven 990bdfe
start
ev1ven b43453c
start
ev1ven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <boost/mpi/communicator.hpp> | ||
#include <climits> | ||
#include <random> | ||
#include <vector> | ||
|
||
#include "mpi/veliev_e_sum_rows_matrix/include/ops_mpi.hpp" | ||
|
||
namespace veliev_e_sum_rows_matrix_test_function { | ||
|
||
std::vector<std::vector<int32_t>> getRandomData(uint32_t rows, uint32_t cols) { | ||
std::random_device dev; | ||
std::mt19937 gen(dev()); | ||
std::vector<std::vector<int32_t>> data(rows, std::vector<int32_t>(cols)); | ||
|
||
for (auto &row : data) { | ||
for (auto &el : row) { | ||
el = -200 + gen() % (300 + 200 + 1); | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
} // namespace veliev_e_sum_rows_matrix_test_function | ||
|
||
TEST(veliev_e_sum_rows_matrix_mpi, rectangular_matrix_stretched_horizontally_7x17) { | ||
uint32_t rows = 7; | ||
uint32_t cols = 17; | ||
|
||
boost::mpi::communicator world; | ||
std::vector<std::vector<int32_t>> randomData; | ||
std::vector<int32_t> mpiSum; | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskParallel taskMPI(taskDataPar); | ||
|
||
if (world.rank() == 0) { | ||
randomData = veliev_e_sum_rows_matrix_test_function::getRandomData(rows, cols); | ||
mpiSum.resize(rows); | ||
|
||
for (auto &row : randomData) { | ||
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataPar->inputs_count.push_back(rows); | ||
taskDataPar->inputs_count.push_back(cols); | ||
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t *>(mpiSum.data())); | ||
taskDataPar->outputs_count.push_back(rows); | ||
} | ||
|
||
ASSERT_TRUE(taskMPI.validation()); | ||
ASSERT_TRUE(taskMPI.pre_processing()); | ||
ASSERT_TRUE(taskMPI.run()); | ||
ASSERT_TRUE(taskMPI.post_processing()); | ||
|
||
if (world.rank() == 0) { | ||
std::vector<int32_t> seqSum(rows); | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskSequential taskSeq(taskDataSeq); | ||
|
||
for (auto &row : randomData) { | ||
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataSeq->inputs_count.push_back(rows); | ||
taskDataSeq->inputs_count.push_back(cols); | ||
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(seqSum.data())); | ||
taskDataSeq->outputs_count.push_back(seqSum.size()); | ||
|
||
ASSERT_TRUE(taskSeq.validation()); | ||
ASSERT_TRUE(taskSeq.pre_processing()); | ||
ASSERT_TRUE(taskSeq.run()); | ||
ASSERT_TRUE(taskSeq.post_processing()); | ||
|
||
for (uint32_t i = 0; i < mpiSum.size(); i++) { | ||
ASSERT_EQ(seqSum[i], mpiSum[i]); | ||
} | ||
} | ||
} | ||
|
||
TEST(veliev_e_sum_rows_matrix_mpi, rectangular_matrix_stretched_verticaly_100x75) { | ||
uint32_t rows = 100; | ||
uint32_t cols = 75; | ||
|
||
boost::mpi::communicator world; | ||
std::vector<std::vector<int32_t>> randomData; | ||
std::vector<int32_t> mpiSum; | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskParallel taskMPI(taskDataPar); | ||
|
||
if (world.rank() == 0) { | ||
randomData = veliev_e_sum_rows_matrix_test_function::getRandomData(rows, cols); | ||
mpiSum.resize(rows); | ||
|
||
for (auto &row : randomData) { | ||
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataPar->inputs_count.push_back(rows); | ||
taskDataPar->inputs_count.push_back(cols); | ||
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t *>(mpiSum.data())); | ||
taskDataPar->outputs_count.push_back(rows); | ||
} | ||
|
||
ASSERT_TRUE(taskMPI.validation()); | ||
ASSERT_TRUE(taskMPI.pre_processing()); | ||
ASSERT_TRUE(taskMPI.run()); | ||
ASSERT_TRUE(taskMPI.post_processing()); | ||
|
||
if (world.rank() == 0) { | ||
std::vector<int32_t> seqSum(rows); | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskSequential taskSeq(taskDataSeq); | ||
|
||
for (auto &row : randomData) { | ||
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataSeq->inputs_count.push_back(rows); | ||
taskDataSeq->inputs_count.push_back(cols); | ||
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(seqSum.data())); | ||
taskDataSeq->outputs_count.push_back(seqSum.size()); | ||
|
||
ASSERT_TRUE(taskSeq.validation()); | ||
ASSERT_TRUE(taskSeq.pre_processing()); | ||
ASSERT_TRUE(taskSeq.run()); | ||
ASSERT_TRUE(taskSeq.post_processing()); | ||
|
||
for (uint32_t i = 0; i < mpiSum.size(); i++) { | ||
ASSERT_EQ(seqSum[i], mpiSum[i]); | ||
} | ||
} | ||
} | ||
|
||
TEST(veliev_e_sum_rows_matrix_mpi, squere_matrix_100x100) { | ||
uint32_t rows = 100; | ||
uint32_t cols = 100; | ||
|
||
boost::mpi::communicator world; | ||
std::vector<std::vector<int32_t>> randomData; | ||
std::vector<int32_t> mpiSum; | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskParallel taskMPI(taskDataPar); | ||
|
||
if (world.rank() == 0) { | ||
randomData = veliev_e_sum_rows_matrix_test_function::getRandomData(rows, cols); | ||
mpiSum.resize(rows); | ||
|
||
for (auto &row : randomData) { | ||
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataPar->inputs_count.push_back(rows); | ||
taskDataPar->inputs_count.push_back(cols); | ||
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t *>(mpiSum.data())); | ||
taskDataPar->outputs_count.push_back(rows); | ||
} | ||
|
||
ASSERT_TRUE(taskMPI.validation()); | ||
ASSERT_TRUE(taskMPI.pre_processing()); | ||
ASSERT_TRUE(taskMPI.run()); | ||
ASSERT_TRUE(taskMPI.post_processing()); | ||
|
||
if (world.rank() == 0) { | ||
std::vector<int32_t> seqSum(rows); | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskSequential taskSeq(taskDataSeq); | ||
|
||
for (auto &row : randomData) { | ||
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataSeq->inputs_count.push_back(rows); | ||
taskDataSeq->inputs_count.push_back(cols); | ||
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(seqSum.data())); | ||
taskDataSeq->outputs_count.push_back(seqSum.size()); | ||
|
||
ASSERT_TRUE(taskSeq.validation()); | ||
ASSERT_TRUE(taskSeq.pre_processing()); | ||
ASSERT_TRUE(taskSeq.run()); | ||
ASSERT_TRUE(taskSeq.post_processing()); | ||
|
||
for (uint32_t i = 0; i < mpiSum.size(); i++) { | ||
ASSERT_EQ(seqSum[i], mpiSum[i]); | ||
} | ||
} | ||
} | ||
|
||
TEST(veliev_e_sum_rows_matrix_mpi, matrix_1x1) { | ||
uint32_t rows = 1; | ||
uint32_t cols = 1; | ||
|
||
boost::mpi::communicator world; | ||
std::vector<std::vector<int32_t>> randomData; | ||
std::vector<int32_t> mpiSum; | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskParallel taskMPI(taskDataPar); | ||
|
||
if (world.rank() == 0) { | ||
randomData = veliev_e_sum_rows_matrix_test_function::getRandomData(rows, cols); | ||
mpiSum.resize(rows); | ||
|
||
for (auto &row : randomData) { | ||
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataPar->inputs_count.push_back(rows); | ||
taskDataPar->inputs_count.push_back(cols); | ||
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t *>(mpiSum.data())); | ||
taskDataPar->outputs_count.push_back(rows); | ||
} | ||
|
||
ASSERT_TRUE(taskMPI.validation()); | ||
ASSERT_TRUE(taskMPI.pre_processing()); | ||
ASSERT_TRUE(taskMPI.run()); | ||
ASSERT_TRUE(taskMPI.post_processing()); | ||
|
||
if (world.rank() == 0) { | ||
std::vector<int32_t> seqSum(rows); | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskSequential taskSeq(taskDataSeq); | ||
|
||
for (auto &row : randomData) { | ||
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataSeq->inputs_count.push_back(rows); | ||
taskDataSeq->inputs_count.push_back(cols); | ||
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(seqSum.data())); | ||
taskDataSeq->outputs_count.push_back(seqSum.size()); | ||
|
||
ASSERT_TRUE(taskSeq.validation()); | ||
ASSERT_TRUE(taskSeq.pre_processing()); | ||
ASSERT_TRUE(taskSeq.run()); | ||
ASSERT_TRUE(taskSeq.post_processing()); | ||
|
||
for (uint32_t i = 0; i < mpiSum.size(); i++) { | ||
ASSERT_EQ(seqSum[i], mpiSum[i]); | ||
} | ||
} | ||
} | ||
|
||
TEST(veliev_e_sum_rows_matrix_mpi, test_validation) { | ||
uint32_t rows = 7; | ||
uint32_t cols = 17; | ||
|
||
boost::mpi::communicator world; | ||
std::vector<std::vector<int32_t>> randomData; | ||
std::vector<int32_t> mpiSum; | ||
|
||
std::shared_ptr<ppc::core::TaskData> taskDataPar = std::make_shared<ppc::core::TaskData>(); | ||
veliev_e_sum_rows_matrix_mpi::TestTaskParallel taskMPI(taskDataPar); | ||
|
||
if (world.rank() == 0) { | ||
randomData = veliev_e_sum_rows_matrix_test_function::getRandomData(rows, cols); | ||
mpiSum.resize(rows); | ||
|
||
for (auto &row : randomData) { | ||
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t *>(row.data())); | ||
} | ||
|
||
taskDataPar->inputs_count.push_back(rows); | ||
taskDataPar->inputs_count.push_back(cols); | ||
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t *>(mpiSum.data())); | ||
taskDataPar->outputs_count.push_back(0); | ||
|
||
ASSERT_FALSE(taskMPI.validation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <boost/mpi/collectives.hpp> | ||
#include <boost/mpi/communicator.hpp> | ||
#include <vector> | ||
|
||
#include "core/task/include/task.hpp" | ||
|
||
namespace veliev_e_sum_rows_matrix_mpi { | ||
|
||
class TestTaskSequential : public ppc::core::Task { | ||
public: | ||
explicit TestTaskSequential(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; | ||
|
||
private: | ||
std::vector<std::vector<int32_t>> input_; | ||
std::vector<int32_t> res_; | ||
}; | ||
|
||
class TestTaskParallel : public ppc::core::Task { | ||
public: | ||
explicit TestTaskParallel(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; | ||
|
||
private: | ||
std::vector<std::vector<int32_t>> input_, local_input_; | ||
std::vector<int32_t> res_, local_res_; | ||
uint32_t delta_, ext_; | ||
|
||
boost::mpi::communicator world; | ||
}; | ||
|
||
} // namespace veliev_e_sum_rows_matrix_mpi |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please paramterize it in tests