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

Зиновьев Александр Задача 1 Вариант 12 Сумма значений по столбцам матрицы #282

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

kobych
Copy link

@kobych kobych commented Nov 13, 2024

Здесь представлены последовательная и параллельная реализации суммы значений по столбцам матрицы. В последовательной реализуем вложенный цикл, проходя по каждому столбцу матрицы, суммируя значения её элементов. Итоговые суммы помещаются в отдельный вектор. В параллельной распределяем столбцы матрицы в зависимости от числа доступных процессов. Определяем величину, которая обозначает количество столбцов, отведенных каждому процессу, а также индекс последнего обрабатываемого столбца для каждого процесса. Каждая группа столбцов суммируется с использованием функции, аналогичной той, что применяется в последовательной версии. Полученные результаты затем консолидируются в общий вектор.

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 98.91892% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (5daf9ab) to head (43f254a).
Report is 183 commits behind head on master.

Files with missing lines Patch % Lines
...sks/mpi/zinoviev_a_sum_cols_matrix/src/ops_mpi.cpp 98.61% 0 Missing and 1 partial ⚠️
...q/zinoviev_readers_and_writers/include/ops_seq.hpp 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #282      +/-   ##
==========================================
- Coverage   97.12%   96.34%   -0.78%     
==========================================
  Files          87      445     +358     
  Lines        2263    11421    +9158     
  Branches      786     4808    +4022     
==========================================
+ Hits         2198    11004    +8806     
- Misses         29      136     +107     
- Partials       36      281     +245     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


#include <thread>

using namespace std::chrono_literals;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#include <thread>
#include <vector>

using namespace std::chrono_literals;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


using namespace std::chrono_literals;

std::vector<int> zinoviev_a_sum_cols_matrix_mpi::generateRandomVector(int sz) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests are failed because there function generateRandomVector has parametr - int sz, but in include function generateRandomVector has parametr - int size. Thats why tests give an error zinoviev_a_sum_cols_matrix_mpi::generateRandomVector has a definition with different parameter names. Change parametr name - give the parematr only one name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
return sums;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In functions computeLinearCoordinates and calculateMatrixSumSequential the same problem. Change parametr name - give the parematr only one name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 11 to 20
std::vector<int> zinoviev_a_sum_cols_matrix_mpi::generateRandomVector(int size) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(size);
for (int i = 0; i < size; i++) {
vec[i] = gen() % 100;
}
return vec;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move test functions to the test module

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 81 to 85
broadcast(mpiWorld, numCols, 0);
broadcast(mpiWorld, numRows, 0);

if (mpiWorld.rank() == 0) {
// Initialize the input vector
inputData_ = std::vector<int>(taskData->inputs_count[0]);
auto* temp_ptr = reinterpret_cast<int*>(taskData->inputs[0]);
for (unsigned int i = 0; i < taskData->inputs_count[0]; i++) {
inputData_[i] = temp_ptr[i];
}
} else {
inputData_ = std::vector<int>(numCols * numRows);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move MPI data transfer to ::run()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not modify common files!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

std::mt19937 gen(dev());
std::vector<int> vec(size);
for (int i = 0; i < size; i++) {
vec[i] = gen() % 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use negative values too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants