-
Notifications
You must be signed in to change notification settings - Fork 80
Балдин Андрей. Технология SEQ-MPI. Подсчёт числа слов в строке. Вариант 24. #28
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 35 commits into
learning-process:master
from
Andrew-8705:baldin_a_word_count
Dec 10, 2025
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
631366e
Add baldin_a_word_count task structure
Andrew-8705 5970b45
Define types
Andrew-8705 685e703
Bugfix in json
Andrew-8705 aa936d7
mpi and seq realization
Andrew-8705 5fded4f
some func and perf tests
Andrew-8705 920394c
Apply clang-format corrections
Andrew-8705 a98debf
Use size_t for count
Andrew-8705 2c32510
Update mpi version
Andrew-8705 7bcf2f6
Small fix in perf tests
Andrew-8705 8581327
Apply clang-format corrections
Andrew-8705 6dcc0f7
More func tests
Andrew-8705 747d49e
Update mpi version
Andrew-8705 a2533ce
Some changes in mpi version
Andrew-8705 5877b95
Add debugging information
Andrew-8705 49815b7
Some changes in mpi version
Andrew-8705 a046604
Another version of mpi program
Andrew-8705 745d436
Some changes
Andrew-8705 11a389e
Add back the tests
Andrew-8705 c751456
Delete some of the tests
Andrew-8705 1e2965c
Back to the basics
Andrew-8705 86f9e89
Correct MPI types for size_t
Andrew-8705 fd7d4cc
Another implementation
Andrew-8705 c6a95c0
Merge branch 'learning-process:master' into baldin_a_word_count
Andrew-8705 a9b2240
Back to the basic implementation
Andrew-8705 67e642e
Merge branch 'learning-process:master' into baldin_a_word_count
Andrew-8705 509a134
Add perf test
Andrew-8705 84963d2
Add back the func tests
Andrew-8705 b14cc3f
Merge remote-tracking branch 'origin/baldin_a_word_count'
Andrew-8705 84adbcc
Fix the func tests
Andrew-8705 dd3c069
Changes for clang-tidy
Andrew-8705 d171d14
Another change for clang-tidy
Andrew-8705 952a8cb
One more change for clang-tidy
Andrew-8705 b6b24e4
Report
Andrew-8705 1ee33c1
Updated report
Andrew-8705 f5da712
Improving code coverage
Andrew-8705 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 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,16 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <string> | ||
| #include <tuple> | ||
|
|
||
| #include "task/include/task.hpp" | ||
|
|
||
| namespace baldin_a_word_count { | ||
|
|
||
| using InType = std::string; | ||
| using OutType = size_t; | ||
| using TestType = std::tuple<std::string, size_t>; | ||
| using BaseTask = ppc::task::Task<InType, OutType>; | ||
|
|
||
| } // namespace baldin_a_word_count |
63,845 changes: 63,845 additions & 0 deletions
63,845
tasks/baldin_a_word_count/data/book-war-and-peace.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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ФИ3", | ||
| "task_number": "1" | ||
| } | ||
| } |
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 "baldin_a_word_count/common/include/common.hpp" | ||
| #include "task/include/task.hpp" | ||
|
|
||
| namespace baldin_a_word_count { | ||
|
|
||
| class BaldinAWordCountMPI : public BaseTask { | ||
| public: | ||
| static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { | ||
| return ppc::task::TypeOfTask::kMPI; | ||
| } | ||
| explicit BaldinAWordCountMPI(const InType &in); | ||
|
|
||
| private: | ||
| bool ValidationImpl() override; | ||
| bool PreProcessingImpl() override; | ||
| bool RunImpl() override; | ||
| bool PostProcessingImpl() override; | ||
| }; | ||
|
|
||
| } // namespace baldin_a_word_count |
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,126 @@ | ||
| #include "baldin_a_word_count/mpi/include/ops_mpi.hpp" | ||
|
|
||
| #include <mpi.h> | ||
|
|
||
| #include <cctype> | ||
| #include <cstddef> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "baldin_a_word_count/common/include/common.hpp" | ||
|
|
||
| namespace baldin_a_word_count { | ||
|
|
||
| BaldinAWordCountMPI::BaldinAWordCountMPI(const InType &in) { | ||
| SetTypeOfTask(GetStaticTypeOfTask()); | ||
| GetInput() = in; | ||
| GetOutput() = 0; | ||
| } | ||
|
|
||
| bool BaldinAWordCountMPI::ValidationImpl() { | ||
| return true; | ||
| } | ||
|
|
||
| bool BaldinAWordCountMPI::PreProcessingImpl() { | ||
| return true; | ||
| } | ||
|
|
||
| namespace { | ||
|
|
||
| bool IsWordChar(char c) { | ||
| return ((std::isalnum(static_cast<unsigned char>(c)) != 0) || c == '-' || c == '_'); | ||
| } | ||
|
|
||
| size_t CountWords(const std::string &text) { | ||
| size_t count = 0; | ||
| bool in_word = false; | ||
| for (char c : text) { | ||
| if (IsWordChar(c)) { | ||
| if (!in_word) { | ||
| in_word = true; | ||
| count++; | ||
| } | ||
| } else { | ||
| in_word = false; | ||
|
allnes marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
allnes marked this conversation as resolved.
|
||
| return count; | ||
| } | ||
|
|
||
| size_t CountLocalWords(const std::vector<char> &local_buf, int part) { | ||
| size_t local_cnt = 0; | ||
| bool in_word = false; | ||
| for (int i = 0; i < part; i++) { | ||
| if (IsWordChar(local_buf[i])) { | ||
| if (!in_word) { | ||
| in_word = true; | ||
| local_cnt++; | ||
| } | ||
| } else { | ||
| in_word = false; | ||
| } | ||
| } | ||
|
|
||
| if (in_word && (IsWordChar(local_buf[part]))) { | ||
| local_cnt--; | ||
| } | ||
|
|
||
| return local_cnt; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| bool BaldinAWordCountMPI::RunImpl() { | ||
| int rank = 0; | ||
| int world_size = 0; | ||
| MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
| MPI_Comm_size(MPI_COMM_WORLD, &world_size); | ||
|
|
||
| std::string &input = GetInput(); | ||
|
|
||
| if (input.empty()) { | ||
| GetOutput() = 0; | ||
| return true; | ||
| } | ||
|
|
||
| if (static_cast<size_t>(world_size) > input.size()) { | ||
| if (rank == 0) { | ||
| GetOutput() = CountWords(input); | ||
| } | ||
| MPI_Bcast(static_cast<void *>(&GetOutput()), 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); | ||
| return true; | ||
| } | ||
|
|
||
| size_t rem = input.size() % static_cast<size_t>(world_size); | ||
| input.append(static_cast<size_t>(world_size) - rem + 1, ' '); | ||
| size_t part = input.size() / static_cast<size_t>(world_size); | ||
|
|
||
| std::vector<int> send_counts(world_size); | ||
| std::vector<int> displs(world_size); | ||
|
|
||
| if (rank == 0) { | ||
| for (int i = 0; i < world_size; i++) { | ||
| displs[i] = static_cast<int>(i * part); | ||
| send_counts[i] = static_cast<int>(part + 1); | ||
| } | ||
| } | ||
|
|
||
| std::vector<char> local_buf(part + 1); | ||
|
|
||
| MPI_Scatterv(input.data(), send_counts.data(), displs.data(), MPI_CHAR, local_buf.data(), static_cast<int>(part + 1), | ||
| MPI_CHAR, 0, MPI_COMM_WORLD); | ||
|
|
||
| size_t local_cnt = CountLocalWords(local_buf, static_cast<int>(part)); | ||
|
|
||
| size_t global_cnt = 0; | ||
| MPI_Allreduce(&local_cnt, &global_cnt, 1, MPI_UNSIGNED_LONG, MPI_SUM, MPI_COMM_WORLD); | ||
| GetOutput() = global_cnt; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool BaldinAWordCountMPI::PostProcessingImpl() { | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace baldin_a_word_count | ||
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.