Skip to content

Commit a64a551

Browse files
committed
marov: task 1 - count letters (MPI + SEQ)
1 parent 9b0904e commit a64a551

5 files changed

Lines changed: 38 additions & 35 deletions

File tree

tasks/marov_count_letters/mpi/include/ops_mpi.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace marov_count_letters {
77

8-
class MarovCountLettersMPI : public BaseTask {
8+
class MarovCountLettersMpi : public BaseTask {
99
public:
1010
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
1111
return ppc::task::TypeOfTask::kMPI;
1212
}
13-
explicit MarovCountLettersMPI(const InType &in);
13+
explicit MarovCountLettersMpi(const InType& in);
1414

1515
private:
1616
int proc_rank_{0};

tasks/marov_count_letters/mpi/src/ops_mpi.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace marov_count_letters {
1212

13-
MarovCountLettersMPI::MarovCountLettersMPI(const InType &in) {
13+
MarovCountLettersMpi::MarovCountLettersMpi(const InType& in) {
1414
MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank_);
1515
MPI_Comm_size(MPI_COMM_WORLD, &proc_size_);
1616

@@ -19,15 +19,15 @@ MarovCountLettersMPI::MarovCountLettersMPI(const InType &in) {
1919
GetOutput() = 0;
2020
}
2121

22-
bool MarovCountLettersMPI::ValidationImpl() {
22+
bool MarovCountLettersMpi::ValidationImpl() {
2323
return true;
2424
}
2525

26-
bool MarovCountLettersMPI::PreProcessingImpl() {
26+
bool MarovCountLettersMpi::PreProcessingImpl() {
2727
return true;
2828
}
2929

30-
bool MarovCountLettersMPI::RunImpl() {
30+
bool MarovCountLettersMpi::RunImpl() {
3131
std::string input_str;
3232
int str_len = 0;
3333

@@ -36,10 +36,10 @@ bool MarovCountLettersMPI::RunImpl() {
3636
str_len = static_cast<int>(input_str.size());
3737
}
3838

39-
// Рассылка длины строки всем процессам
39+
// Broadcast string length
4040
MPI_Bcast(&str_len, 1, MPI_INT, 0, MPI_COMM_WORLD);
4141

42-
// Разделение данных между процессами
42+
// Split data between processes
4343
const int base = str_len / proc_size_;
4444
const int rem = str_len % proc_size_;
4545

@@ -61,21 +61,22 @@ bool MarovCountLettersMPI::RunImpl() {
6161
const int local_size = base + (proc_rank_ < rem ? 1 : 0);
6262
std::vector<char> local_data(local_size);
6363

64-
MPI_Scatterv(proc_rank_ == 0 ? const_cast<char *>(input_str.data()) : nullptr,
64+
MPI_Scatterv(proc_rank_ == 0 ? const_cast<char*>(input_str.data()) : nullptr,
6565
send_counts.data(), displs.data(), MPI_CHAR,
6666
local_data.data(), local_size, MPI_CHAR, 0, MPI_COMM_WORLD);
6767

68-
// Подсчет буквенных символов локально
68+
// Count letter characters locally
6969
int local_count = 0;
7070
for (int i = 0; i < local_size; ++i) {
71-
if (std::isalpha(static_cast<unsigned char>(local_data[i]))) {
71+
if (std::isalpha(static_cast<unsigned char>(local_data[i])) != 0) {
7272
local_count++;
7373
}
7474
}
7575

76-
// Редукция - сумма всех локальных подсчетов
76+
// Reduction - sum of all local counts
7777
int global_count = 0;
78-
MPI_Reduce(&local_count, &global_count, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
78+
MPI_Reduce(&local_count, &global_count, 1, MPI_INT, MPI_SUM, 0,
79+
MPI_COMM_WORLD);
7980

8081
if (proc_rank_ == 0) {
8182
GetOutput() = global_count;
@@ -84,7 +85,7 @@ bool MarovCountLettersMPI::RunImpl() {
8485
return true;
8586
}
8687

87-
bool MarovCountLettersMPI::PostProcessingImpl() {
88+
bool MarovCountLettersMpi::PostProcessingImpl() {
8889
return true;
8990
}
9091

tasks/marov_count_letters/seq/include/ops_seq.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace marov_count_letters {
77

8-
class MarovCountLettersSEQ : public BaseTask {
8+
class MarovCountLettersSeq : public BaseTask {
99
public:
1010
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
1111
return ppc::task::TypeOfTask::kSEQ;
1212
}
13-
explicit MarovCountLettersSEQ(const InType &in);
13+
explicit MarovCountLettersSeq(const InType& in);
1414

1515
private:
1616
bool ValidationImpl() override;

tasks/marov_count_letters/seq/src/ops_seq.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77

88
namespace marov_count_letters {
99

10-
MarovCountLettersSEQ::MarovCountLettersSEQ(const InType &in) {
10+
MarovCountLettersSeq::MarovCountLettersSeq(const InType& in) {
1111
SetTypeOfTask(GetStaticTypeOfTask());
1212
GetInput() = in;
1313
GetOutput() = 0;
1414
}
1515

16-
bool MarovCountLettersSEQ::ValidationImpl() {
16+
bool MarovCountLettersSeq::ValidationImpl() {
1717
return true;
1818
}
1919

20-
bool MarovCountLettersSEQ::PreProcessingImpl() {
20+
bool MarovCountLettersSeq::PreProcessingImpl() {
2121
return true;
2222
}
2323

24-
bool MarovCountLettersSEQ::RunImpl() {
25-
const std::string &input_str = GetInput();
24+
bool MarovCountLettersSeq::RunImpl() {
25+
const std::string& input_str = GetInput();
2626
int count = 0;
2727

2828
for (char c : input_str) {
29-
if (std::isalpha(static_cast<unsigned char>(c))) {
29+
if (std::isalpha(static_cast<unsigned char>(c)) != 0) {
3030
count++;
3131
}
3232
}
@@ -35,7 +35,7 @@ bool MarovCountLettersSEQ::RunImpl() {
3535
return true;
3636
}
3737

38-
bool MarovCountLettersSEQ::PostProcessingImpl() {
38+
bool MarovCountLettersSeq::PostProcessingImpl() {
3939
return true;
4040
}
4141

tasks/marov_count_letters/tests/functional/main.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#include <gtest/gtest.h>
2-
3-
#include <algorithm>
2+
#include <array>
43
#include <string>
54
#include <tuple>
6-
#include <vector>
75

86
#include "marov_count_letters/common/include/common.hpp"
97
#include "marov_count_letters/mpi/include/ops_mpi.hpp"
108
#include "marov_count_letters/seq/include/ops_seq.hpp"
119
#include "util/include/func_test_util.hpp"
12-
#include "util/include/util.hpp"
1310

1411
namespace marov_count_letters {
1512

16-
class MarovCountLettersFuncTests : public ppc::util::BaseRunFuncTests<InType, OutType, TestType> {
13+
class MarovCountLettersFuncTests
14+
: public ppc::util::BaseRunFuncTests<InType, OutType, TestType> {
1715
public:
18-
static std::string PrintTestParam(const testing::TestParamInfo<ParamType>& info) {
16+
static std::string PrintTestParam(
17+
const testing::TestParamInfo<ParamType>& info) {
1918
return "test_" + std::to_string(info.index);
2019
}
2120

@@ -56,13 +55,16 @@ const std::array kTestCases = {
5655
std::make_tuple(std::string("aBcDeFgHiJkLmNoPqRsTuVwXyZ"), 26),
5756
};
5857

59-
const auto kAllTestTasks = std::tuple_cat(
60-
ppc::util::AddFuncTask<MarovCountLettersMPI, InType>(kTestCases, PPC_SETTINGS_marov_count_letters),
61-
ppc::util::AddFuncTask<MarovCountLettersSEQ, InType>(kTestCases, PPC_SETTINGS_marov_count_letters));
58+
const auto kAllTestTasks =
59+
std::tuple_cat(ppc::util::AddFuncTask<MarovCountLettersMpi, InType>(
60+
kTestCases, PPC_SETTINGS_marov_count_letters),
61+
ppc::util::AddFuncTask<MarovCountLettersSeq, InType>(
62+
kTestCases, PPC_SETTINGS_marov_count_letters));
6263

63-
INSTANTIATE_TEST_SUITE_P(LetterCountFuncTests, MarovCountLettersFuncTests,
64-
ppc::util::ExpandToValues(kAllTestTasks),
65-
MarovCountLettersFuncTests::PrintTestParam);
64+
INSTANTIATE_TEST_SUITE_P(
65+
LetterCountFuncTests, MarovCountLettersFuncTests,
66+
ppc::util::ExpandToValues(kAllTestTasks),
67+
MarovCountLettersFuncTests::PrintTestParam);
6668

6769
} // namespace
6870
} // namespace marov_count_letters

0 commit comments

Comments
 (0)