Skip to content
Merged
Show file tree
Hide file tree
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 Oct 25, 2025
5970b45
Define types
Andrew-8705 Oct 29, 2025
685e703
Bugfix in json
Andrew-8705 Oct 29, 2025
aa936d7
mpi and seq realization
Andrew-8705 Oct 29, 2025
5fded4f
some func and perf tests
Andrew-8705 Oct 29, 2025
920394c
Apply clang-format corrections
Andrew-8705 Oct 29, 2025
a98debf
Use size_t for count
Andrew-8705 Oct 30, 2025
2c32510
Update mpi version
Andrew-8705 Oct 30, 2025
7bcf2f6
Small fix in perf tests
Andrew-8705 Oct 30, 2025
8581327
Apply clang-format corrections
Andrew-8705 Oct 30, 2025
6dcc0f7
More func tests
Andrew-8705 Oct 30, 2025
747d49e
Update mpi version
Andrew-8705 Oct 30, 2025
a2533ce
Some changes in mpi version
Andrew-8705 Nov 2, 2025
5877b95
Add debugging information
Andrew-8705 Nov 2, 2025
49815b7
Some changes in mpi version
Andrew-8705 Nov 2, 2025
a046604
Another version of mpi program
Andrew-8705 Nov 2, 2025
745d436
Some changes
Andrew-8705 Nov 3, 2025
11a389e
Add back the tests
Andrew-8705 Nov 3, 2025
c751456
Delete some of the tests
Andrew-8705 Nov 3, 2025
1e2965c
Back to the basics
Andrew-8705 Nov 4, 2025
86f9e89
Correct MPI types for size_t
Andrew-8705 Nov 4, 2025
fd7d4cc
Another implementation
Andrew-8705 Nov 4, 2025
c6a95c0
Merge branch 'learning-process:master' into baldin_a_word_count
Andrew-8705 Nov 5, 2025
a9b2240
Back to the basic implementation
Andrew-8705 Nov 5, 2025
67e642e
Merge branch 'learning-process:master' into baldin_a_word_count
Andrew-8705 Nov 7, 2025
509a134
Add perf test
Andrew-8705 Nov 7, 2025
84963d2
Add back the func tests
Andrew-8705 Nov 7, 2025
b14cc3f
Merge remote-tracking branch 'origin/baldin_a_word_count'
Andrew-8705 Nov 7, 2025
84adbcc
Fix the func tests
Andrew-8705 Nov 7, 2025
dd3c069
Changes for clang-tidy
Andrew-8705 Nov 8, 2025
d171d14
Another change for clang-tidy
Andrew-8705 Nov 8, 2025
952a8cb
One more change for clang-tidy
Andrew-8705 Nov 8, 2025
b6b24e4
Report
Andrew-8705 Nov 10, 2025
1ee33c1
Updated report
Andrew-8705 Nov 10, 2025
f5da712
Improving code coverage
Andrew-8705 Nov 13, 2025
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
16 changes: 16 additions & 0 deletions tasks/baldin_a_word_count/common/include/common.hpp
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 tasks/baldin_a_word_count/data/book-war-and-peace.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tasks/baldin_a_word_count/info.json
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"
}
}
22 changes: 22 additions & 0 deletions tasks/baldin_a_word_count/mpi/include/ops_mpi.hpp
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
126 changes: 126 additions & 0 deletions tasks/baldin_a_word_count/mpi/src/ops_mpi.cpp
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;
Comment thread
allnes marked this conversation as resolved.
}

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;
Comment thread
allnes marked this conversation as resolved.
}
}
Comment thread
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
Loading
Loading