-
Notifications
You must be signed in to change notification settings - Fork 80
Спичек Денис. Технология SEQ-MPI. Скалярное произведение векторов. Вариант 9. #27
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
Merged
allnes
merged 46 commits into
learning-process:master
from
Offsidetax:spichek_d_dot_product_of_vectors
Dec 10, 2025
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
cf5ed27
Add test task
Offsidetax 8a464c5
Fix tests name
Offsidetax 3372f3d
Tests are working correctly
Offsidetax 1f1d15a
Correct tests with any vectors
Offsidetax 810f8ca
Fix line endings
Offsidetax ecc2de5
Fix unused variable in perf tests
Offsidetax 79f5e78
Broadcast vectors data to all MPI processes
Offsidetax 89cf12a
Broadcast vectors data to all MPI processes (second try)
Offsidetax 619a2a9
Fixed deadlock
Offsidetax 8bcb400
Updated logic in mpi
Offsidetax 36b0852
Easier mpi version
Offsidetax 54c57c3
New mpi logic
Offsidetax 9eb1410
Another one mpi version (changed because the last one doesn`t work on…
Offsidetax 3ae94b0
Another one mpi version (changed because the last one doesn`t work on…
Offsidetax b199b91
Reduced vector size in perf test
Offsidetax 82e1d73
Updated data distribution in mpi
Offsidetax 4be148e
Fixed deadlock
Offsidetax d705f9c
Fixed deadlock for mac
Offsidetax d71a524
Second try to fix deadlock for mac
Offsidetax 2cf133e
Third try to fix deadlock for mac and ubuntu
Offsidetax e26cc1c
Fourth try to fix deadlock for mac
Offsidetax 04433c9
Fifth try to fix deadlock for mac
Offsidetax 27fc027
Report added
Offsidetax 25824fa
Report fixed
Offsidetax c3476f6
Report fixed 2
Offsidetax 369ba74
Merge branch 'master' into spichek_d_dot_product_of_vectors
Offsidetax 5d39b5b
Update files to match clang-tidy
Offsidetax fae0ea9
Update files to match clang-tidy
Offsidetax 0e17e66
Update files to match clang-tidy
Offsidetax 55428e5
Update files to match clang-tidy
Offsidetax 833d1e3
Update files to match clang-tidy
Offsidetax 4a0c98a
Added functional tests
Offsidetax 3d28af9
Fixed functional tests
Offsidetax 56c371d
Fixed functional tests
Offsidetax e0e1c6f
Fixed functional tests
Offsidetax 46ce4ec
Fixed functional tests
Offsidetax e61ac49
Fixed work with empty vectors in seq version
Offsidetax 05e990b
Fixed functional tests
Offsidetax b650621
Fix for proper operation of clang-tidy
Offsidetax 7f6fd0e
Removed an unnecessary check from the code
Offsidetax 27c3e2c
Fixed work with memory
Offsidetax 6e8e886
Update report
Offsidetax 5432fc8
Clang-tidy fix
Offsidetax d69d037
Clang-tidy fix
Offsidetax 32c7efb
Correct info.json
Offsidetax debf6b4
Fix
Offsidetax 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
19 changes: 19 additions & 0 deletions
19
tasks/spichek_d_dot_product_of_vectors/common/include/common.hpp
This file contains hidden or 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,19 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <tuple> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "task/include/task.hpp" | ||
|
|
||
| namespace spichek_d_dot_product_of_vectors { | ||
|
|
||
| // Пара векторов как входные данные | ||
| using InType = std::pair<std::vector<int>, std::vector<int>>; | ||
| using OutType = int; | ||
| // Тестовые параметры: (пара_векторов, описание) | ||
| using TestType = std::tuple<std::pair<std::vector<int>, std::vector<int>>, std::string>; | ||
| using BaseTask = ppc::task::Task<InType, OutType>; | ||
|
|
||
| } // namespace spichek_d_dot_product_of_vectors | ||
This file contains hidden or 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,9 @@ | ||
| { | ||
| "student": { | ||
| "first_name": "Денис", | ||
| "last_name": "Спичек", | ||
| "middle_name": "Игоревич", | ||
| "group_number": "3823Б1ФИ1", | ||
| "task_number": "1" | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
tasks/spichek_d_dot_product_of_vectors/mpi/include/ops_mpi.hpp
This file contains hidden or 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,22 @@ | ||
| #pragma once | ||
|
|
||
| #include "spichek_d_dot_product_of_vectors/common/include/common.hpp" | ||
| #include "task/include/task.hpp" | ||
|
|
||
| namespace spichek_d_dot_product_of_vectors { | ||
|
|
||
| class SpichekDDotProductOfVectorsMPI : public BaseTask { | ||
| public: | ||
| static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { | ||
| return ppc::task::TypeOfTask::kMPI; | ||
| } | ||
| explicit SpichekDDotProductOfVectorsMPI(const InType &in); | ||
|
|
||
| private: | ||
| bool ValidationImpl() override; | ||
| bool PreProcessingImpl() override; | ||
| bool RunImpl() override; | ||
| bool PostProcessingImpl() override; | ||
| }; | ||
|
|
||
| } // namespace spichek_d_dot_product_of_vectors |
86 changes: 86 additions & 0 deletions
86
tasks/spichek_d_dot_product_of_vectors/mpi/src/ops_mpi.cpp
This file contains hidden or 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,86 @@ | ||
| #include "spichek_d_dot_product_of_vectors/mpi/include/ops_mpi.hpp" | ||
|
|
||
| #include <mpi.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "spichek_d_dot_product_of_vectors/common/include/common.hpp" | ||
|
|
||
| namespace spichek_d_dot_product_of_vectors { | ||
|
|
||
| SpichekDDotProductOfVectorsMPI::SpichekDDotProductOfVectorsMPI(const InType &in) { | ||
| SetTypeOfTask(GetStaticTypeOfTask()); | ||
| GetInput() = in; | ||
| GetOutput() = 0; | ||
| } | ||
|
|
||
| bool SpichekDDotProductOfVectorsMPI::ValidationImpl() { | ||
| const auto &[vector1, vector2] = GetInput(); | ||
| return vector1.size() == vector2.size(); | ||
| } | ||
|
|
||
| bool SpichekDDotProductOfVectorsMPI::PreProcessingImpl() { | ||
| GetOutput() = 0; | ||
| return true; | ||
| } | ||
|
|
||
| bool SpichekDDotProductOfVectorsMPI::RunImpl() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't scatter vectors across different ranks |
||
| int rank = 0; | ||
| int size = 0; | ||
| MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
| MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
|
allnes marked this conversation as resolved.
|
||
|
|
||
| const auto &[v1, v2] = GetInput(); | ||
| int n = 0; | ||
| if (rank == 0) { | ||
| n = static_cast<int>(v1.size()); | ||
| } | ||
| MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); | ||
|
|
||
| if (n == 0 || (rank == 0 && static_cast<size_t>(n) != v2.size())) { | ||
| GetOutput() = 0; | ||
| return true; | ||
| } | ||
|
|
||
| std::vector<int> counts(size); | ||
| std::vector<int> displs(size); | ||
|
|
||
| int base = n / size; | ||
| int rem = n % size; | ||
|
|
||
| for (int i = 0; i < size; ++i) { | ||
| counts[i] = base + (i < rem ? 1 : 0); | ||
| // [Исправлено] Добавлены скобки для явного приоритета операций | ||
| displs[i] = (i * base) + std::min(i, rem); | ||
| } | ||
|
|
||
| int local_count = counts[rank]; | ||
|
|
||
| std::vector<int> lv1(local_count); | ||
| std::vector<int> lv2(local_count); | ||
|
|
||
| MPI_Scatterv(rank == 0 ? v1.data() : nullptr, counts.data(), displs.data(), MPI_INT, lv1.data(), local_count, MPI_INT, | ||
| 0, MPI_COMM_WORLD); | ||
| MPI_Scatterv(rank == 0 ? v2.data() : nullptr, counts.data(), displs.data(), MPI_INT, lv2.data(), local_count, MPI_INT, | ||
| 0, MPI_COMM_WORLD); | ||
|
|
||
| int64_t local_dot = 0; | ||
| for (int i = 0; i < local_count; ++i) { | ||
| local_dot += static_cast<int64_t>(lv1[i]) * lv2[i]; | ||
| } | ||
|
|
||
| int64_t global_dot = 0; | ||
| MPI_Allreduce(&local_dot, &global_dot, 1, MPI_INT64_T, MPI_SUM, MPI_COMM_WORLD); | ||
|
|
||
| GetOutput() = static_cast<OutType>(global_dot); | ||
| return true; | ||
| } | ||
|
|
||
| bool SpichekDDotProductOfVectorsMPI::PostProcessingImpl() { | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace spichek_d_dot_product_of_vectors | ||
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.
Uh oh!
There was an error while loading. Please reload this page.