From 9ac1ff2c9aaac5c70cbf340cdf566bbc16cca35c Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Wed, 29 Oct 2025 23:55:24 +0300 Subject: [PATCH 01/40] Add papulina_y_count_of_letters task implementation --- .../common/include/common.hpp | 15 ++ tasks/papulina_y_count_of_letters/info.json | 9 + .../mpi/include/ops_mpi.hpp | 26 ++ .../mpi/src/ops_mpi.cpp | 79 ++++++ tasks/papulina_y_count_of_letters/report.md | 0 .../seq/include/ops_seq.hpp | 23 ++ .../seq/src/ops_seq.cpp | 43 ++++ .../papulina_y_count_of_letters/settings.json | 7 + .../tests/.clang-tidy | 13 + .../tests/functional/main.cpp | 75 ++++++ .../tests/performance/llvm.sh | 233 ++++++++++++++++++ .../tests/performance/main.cpp | 45 ++++ 12 files changed, 568 insertions(+) create mode 100644 tasks/papulina_y_count_of_letters/common/include/common.hpp create mode 100644 tasks/papulina_y_count_of_letters/info.json create mode 100644 tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp create mode 100644 tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp create mode 100644 tasks/papulina_y_count_of_letters/report.md create mode 100644 tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp create mode 100644 tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp create mode 100644 tasks/papulina_y_count_of_letters/settings.json create mode 100644 tasks/papulina_y_count_of_letters/tests/.clang-tidy create mode 100644 tasks/papulina_y_count_of_letters/tests/functional/main.cpp create mode 100644 tasks/papulina_y_count_of_letters/tests/performance/llvm.sh create mode 100644 tasks/papulina_y_count_of_letters/tests/performance/main.cpp diff --git a/tasks/papulina_y_count_of_letters/common/include/common.hpp b/tasks/papulina_y_count_of_letters/common/include/common.hpp new file mode 100644 index 0000000000..3834e885d9 --- /dev/null +++ b/tasks/papulina_y_count_of_letters/common/include/common.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "task/include/task.hpp" + +namespace papulina_y_count_of_letters { + +using InType = std::string; +using OutType = int; +using TestType = std::tuple; // патерн + длина строки +using BaseTask = ppc::task::Task; + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/info.json b/tasks/papulina_y_count_of_letters/info.json new file mode 100644 index 0000000000..b343e6c39b --- /dev/null +++ b/tasks/papulina_y_count_of_letters/info.json @@ -0,0 +1,9 @@ +{ + "student": { + "first_name": "Юлия", + "last_name": "Папулина", + "middle_name": "Андреевна", + "group_number": "3823Б1ФИ3", + "task_number": "1" + } +} diff --git a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp new file mode 100644 index 0000000000..418cb8ba6e --- /dev/null +++ b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp @@ -0,0 +1,26 @@ +#pragma once +#include + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace papulina_y_count_of_letters { + +class PapulinaYCountOfLettersMPI : public BaseTask { + int procNum_ = 0; + + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kMPI; + } + explicit PapulinaYCountOfLettersMPI(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; + int CountOfLetters(const char *s, const int &n); +}; + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp new file mode 100644 index 0000000000..a02ce4739e --- /dev/null +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -0,0 +1,79 @@ +#include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" + +#include + +#include +#include + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace papulina_y_count_of_letters { + +PapulinaYCountOfLettersMPI::PapulinaYCountOfLettersMPI(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0; +} +int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { + int k = 0; + for (int i = 0; i < n; i++) { + if (isalpha(s[i])) { + k++; + } + } + return k; +} +bool PapulinaYCountOfLettersMPI::ValidationImpl() { + MPI_Comm_size(MPI_COMM_WORLD, &procNum_); + return procNum_ > 0; +} + +bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { + return true; +} + +bool PapulinaYCountOfLettersMPI::RunImpl() { + int procRank = 0; + int result = 0; + std::string partOfString = ""; // части строки, которая будет обрабатываться потоком + unsigned int len = 0; // предполагаемая длина обрабатываемой части + unsigned int trueLen = 0; // реальная длина обрабатываемой части + MPI_Comm_size(MPI_COMM_WORLD, &procNum_); + MPI_Comm_rank(MPI_COMM_WORLD, &procRank); + if (procRank == 0) { + std::string s = GetInput(); + len = s.size() / procNum_; + MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + for (int i = 1; i < procNum_; i++) { + int begin = i * len; + int end = (i == procNum_ - 1) ? s.size() : begin + len; // таким образом, если потоков, сильно больше, чем + // длина строки, то последнему уйдет вся работа + trueLen = end - begin; + MPI_Send(&trueLen, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); + if (end - begin != 0) { + MPI_Send(s.substr(begin, end).data(), end - begin, MPI_CHAR, i, 1, MPI_COMM_WORLD); + } else { + MPI_Send("", 0, MPI_CHAR, i, 1, MPI_COMM_WORLD); + } + } + trueLen = std::min(len, (unsigned int)s.size()); + partOfString = s.substr(0, trueLen); + } else { + MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + MPI_Recv(&trueLen, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + partOfString.resize(trueLen); + MPI_Recv(&partOfString[0], trueLen, MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + } + int localResult = CountOfLetters(partOfString.data(), trueLen); + MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); + GetOutput() = result; + return true; +} + +bool PapulinaYCountOfLettersMPI::PostProcessingImpl() { + return GetOutput() >= 0; +} + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/report.md b/tasks/papulina_y_count_of_letters/report.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp new file mode 100644 index 0000000000..c74c9825ae --- /dev/null +++ b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace papulina_y_count_of_letters { + +class PapulinaYCountOfLettersSEQ : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + explicit PapulinaYCountOfLettersSEQ(const InType &in); + + private: + int CountOfLetters(); + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp new file mode 100644 index 0000000000..c6e2492e05 --- /dev/null +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -0,0 +1,43 @@ +#include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" + +#include +#include + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace papulina_y_count_of_letters { + +PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0; +} +int PapulinaYCountOfLettersSEQ::CountOfLetters() { + int k = 0; + for (int i = 0; i < GetInput().size(); i++) { + if (isalpha(GetInput()[i])) { + k++; + } + } + return k; +} +bool PapulinaYCountOfLettersSEQ::ValidationImpl() { + return GetInput().size() >= 0; +} + +bool PapulinaYCountOfLettersSEQ::PreProcessingImpl() { + GetOutput() = 0; + return GetOutput() == 0; +} + +bool PapulinaYCountOfLettersSEQ::RunImpl() { + GetOutput() = CountOfLetters(); + return true; +} + +bool PapulinaYCountOfLettersSEQ::PostProcessingImpl() { + return true; +} + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/settings.json b/tasks/papulina_y_count_of_letters/settings.json new file mode 100644 index 0000000000..b1a0d52574 --- /dev/null +++ b/tasks/papulina_y_count_of_letters/settings.json @@ -0,0 +1,7 @@ +{ + "tasks_type": "processes", + "tasks": { + "mpi": "enabled", + "seq": "enabled" + } +} diff --git a/tasks/papulina_y_count_of_letters/tests/.clang-tidy b/tasks/papulina_y_count_of_letters/tests/.clang-tidy new file mode 100644 index 0000000000..ef43b7aa8a --- /dev/null +++ b/tasks/papulina_y_count_of_letters/tests/.clang-tidy @@ -0,0 +1,13 @@ +InheritParentConfig: true + +Checks: > + -modernize-loop-convert, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-non-const-global-variables, + -misc-use-anonymous-namespace, + -modernize-use-std-print, + -modernize-type-traits + +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: 50 # Relaxed for tests diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp new file mode 100644 index 0000000000..8330ded93d --- /dev/null +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -0,0 +1,75 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" +#include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace papulina_y_count_of_letters { + +class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintTestParam(const TestType &test_param) { + return std::get<0>(test_param) + "_" + std::to_string(std::get<1>(test_param)); + } + + protected: + void SetUp() override { + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + input_data_ = std::string(std::get<0>(params)); + expectedResult_ = std::get<1>(params); + } + + bool CheckTestOutputData(OutType &output_data) final { + return (expectedResult_ == output_data); + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_ = ""; + OutType expectedResult_ = 0; +}; + +namespace { + +TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { + ExecuteTest(GetParam()); +} + +const std::array kTestParam = {std::make_tuple("", 0), + std::make_tuple("abcd", 4), + std::make_tuple("aabcd123abcd123abcd", 13), + std::make_tuple("abcd_____________123abcd", 8), + std::make_tuple("a", 1), + std::make_tuple("1243356", 0), + std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12)}; + +const auto kTestTasksList = std::tuple_cat( + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters)); + +const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); + +const auto kPerfTestName = PapulinaYRunFuncTestsProcesses::PrintFuncTestName; + +INSTANTIATE_TEST_SUITE_P(PicMatrixTests, PapulinaYRunFuncTestsProcesses, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh b/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh new file mode 100644 index 0000000000..b596680923 --- /dev/null +++ b/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh @@ -0,0 +1,233 @@ +#!/bin/bash +################################################################################ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +################################################################################ +# +# This script will install the llvm toolchain on the different +# Debian and Ubuntu versions + +set -eux + +usage() { + set +x + echo "Usage: $0 [llvm_major_version] [all] [OPTIONS]" 1>&2 + echo -e "all\t\t\tInstall all packages." 1>&2 + echo -e "-n=code_name\t\tSpecifies the distro codename, for example bionic" 1>&2 + echo -e "-h\t\t\tPrints this help." 1>&2 + echo -e "-m=repo_base_url\tSpecifies the base URL from which to download." 1>&2 + exit 1; +} + +CURRENT_LLVM_STABLE=20 +BASE_URL="http://apt.llvm.org" + +NEW_DEBIAN_DISTROS=("trixie" "unstable") +# Set default values for commandline arguments +# We default to the current stable branch of LLVM +LLVM_VERSION=$CURRENT_LLVM_STABLE +ALL=0 +DISTRO=$(lsb_release -is) +VERSION_CODENAME=$(lsb_release -cs) +VERSION=$(lsb_release -sr) +UBUNTU_CODENAME="" +CODENAME_FROM_ARGUMENTS="" +# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives) +source /etc/os-release +DISTRO=${DISTRO,,} + +# Check for required tools + +# Check if this is a new Debian distro +is_new_debian=0 +if [[ "${DISTRO}" == "debian" ]]; then + for new_distro in "${NEW_DEBIAN_DISTROS[@]}"; do + if [[ "${VERSION_CODENAME}" == "${new_distro}" ]]; then + is_new_debian=1 + break + fi + done +fi + +# Check for required tools +needed_binaries=(lsb_release wget gpg) +# add-apt-repository is not needed for newer Debian distros +if [[ $is_new_debian -eq 0 ]]; then + needed_binaries+=(add-apt-repository) +fi + +missing_binaries=() +using_curl= +for binary in "${needed_binaries[@]}"; do + if ! command -v $binary &>/dev/null ; then + if [[ "$binary" == "wget" ]] && command -v curl &>/dev/null; then + using_curl=1 + continue + fi + missing_binaries+=($binary) + fi +done + +if [[ ${#missing_binaries[@]} -gt 0 ]] ; then + echo "You are missing some tools this script requires: ${missing_binaries[@]}" + echo "(hint: apt install lsb-release wget software-properties-common gnupg)" + echo "curl is also supported" + exit 4 +fi + +case ${DISTRO} in + debian) + # Debian Trixie has a workaround because of + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383 + if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then + CODENAME=unstable + LINKNAME= + else + # "stable" Debian release + CODENAME=${VERSION_CODENAME} + LINKNAME=-${CODENAME} + fi + ;; + *) + # ubuntu and its derivatives + if [[ -n "${UBUNTU_CODENAME}" ]]; then + CODENAME=${UBUNTU_CODENAME} + if [[ -n "${CODENAME}" ]]; then + LINKNAME=-${CODENAME} + fi + fi + ;; +esac + +# read optional command line arguments +if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then + if [ "$1" != "all" ]; then + LLVM_VERSION=$1 + else + # special case for ./llvm.sh all + ALL=1 + fi + OPTIND=2 + if [ "$#" -ge 2 ]; then + if [ "$2" == "all" ]; then + # Install all packages + ALL=1 + OPTIND=3 + fi + fi +fi + +while getopts ":hm:n:" arg; do + case $arg in + h) + usage + ;; + m) + BASE_URL=${OPTARG} + ;; + n) + CODENAME=${OPTARG} + if [[ "${CODENAME}" == "unstable" ]]; then + # link name does not apply to unstable repository + LINKNAME= + else + LINKNAME=-${CODENAME} + fi + CODENAME_FROM_ARGUMENTS="true" + ;; + esac +done + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root!" + exit 1 +fi + +declare -A LLVM_VERSION_PATTERNS +LLVM_VERSION_PATTERNS[9]="-9" +LLVM_VERSION_PATTERNS[10]="-10" +LLVM_VERSION_PATTERNS[11]="-11" +LLVM_VERSION_PATTERNS[12]="-12" +LLVM_VERSION_PATTERNS[13]="-13" +LLVM_VERSION_PATTERNS[14]="-14" +LLVM_VERSION_PATTERNS[15]="-15" +LLVM_VERSION_PATTERNS[16]="-16" +LLVM_VERSION_PATTERNS[17]="-17" +LLVM_VERSION_PATTERNS[18]="-18" +LLVM_VERSION_PATTERNS[19]="-19" +LLVM_VERSION_PATTERNS[20]="-20" +LLVM_VERSION_PATTERNS[21]="-21" +LLVM_VERSION_PATTERNS[22]="" + +if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then + echo "This script does not support LLVM version $LLVM_VERSION" + exit 3 +fi + +LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} + +# join the repository name +if [[ -n "${CODENAME}" ]]; then + REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main" + # check if the repository exists for the distro and version + if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null && \ + ! curl -sSLI -XHEAD ${BASE_URL}/${CODENAME} &> /dev/null; then + if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then + echo "Specified codename '${CODENAME}' is not supported by this script." + else + echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script." + fi + exit 2 + fi +fi + + +# install everything + +if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then + # download GPG key once + if [[ -z "$using_curl" ]]; then + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + else + curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + fi +fi + +if [[ -z "`apt-key list 2> /dev/null | grep -i llvm`" ]]; then + # Delete the key in the old format + apt-key del AF4F7421 || true +fi + + +# Add repository based on distribution +if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then + # add it twice to workaround: + # https://github.com/llvm/llvm-project/issues/62475 + add-apt-repository -y "${REPO_NAME}" + add-apt-repository -y "${REPO_NAME}" +elif [[ $is_new_debian -eq 1 ]]; then + # workaround missing add-apt-repository in newer Debian and use new source.list format + SOURCES_FILE="/etc/apt/sources.list.d/http_apt_llvm_org_${CODENAME}_-${VERSION_CODENAME}.sources" + TEXT_TO_ADD="Types: deb +Architectures: amd64 arm64 +Signed-By: /etc/apt/trusted.gpg.d/apt.llvm.org.asc +URIs: ${BASE_URL}/${CODENAME}/ +Suites: llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} +Components: main" + echo "$TEXT_TO_ADD" | tee -a "$SOURCES_FILE" > /dev/null +else + add-apt-repository -y "${REPO_NAME}" +fi + +apt-get update +PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION" +if [[ $ALL -eq 1 ]]; then + # same as in test-install.sh + # No worries if we have dups + PKG="$PKG clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION llvm-$LLVM_VERSION-dev lld-$LLVM_VERSION lldb-$LLVM_VERSION llvm-$LLVM_VERSION-tools libomp-$LLVM_VERSION-dev libc++-$LLVM_VERSION-dev libc++abi-$LLVM_VERSION-dev libclang-common-$LLVM_VERSION-dev libclang-$LLVM_VERSION-dev libclang-cpp$LLVM_VERSION-dev liblldb-$LLVM_VERSION-dev libunwind-$LLVM_VERSION-dev" + if test $LLVM_VERSION -gt 14; then + PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev" + fi +fi +apt-get install -y $PKG diff --git a/tasks/papulina_y_count_of_letters/tests/performance/main.cpp b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp new file mode 100644 index 0000000000..4044612c5e --- /dev/null +++ b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp @@ -0,0 +1,45 @@ +#include + +#include "papulina_y_count_of_letters/common/include/common.hpp" +#include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" +#include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace papulina_y_count_of_letters { + +class PapulinaYRunPerfTestProcesses : public ppc::util::BaseRunPerfTests { + const int kCount_ = 10000000; + const std::string s = "abcdabcd"; + InType input_data_{}; + OutType expectedResult = 0; + + void SetUp() override { + for (int i = 0; i < kCount_; i++) { + input_data_ += s; + } + expectedResult = kCount_ * s.size(); + } + + bool CheckTestOutputData(OutType &output_data) final { + return expectedResult == output_data; + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(PapulinaYRunPerfTestProcesses, RunPerfModes) { + ExecuteTest(GetParam()); +} + +const auto kAllPerfTasks = ppc::util::MakeAllPerfTasks( + PPC_SETTINGS_papulina_y_count_of_letters); + +const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); + +const auto kPerfTestName = PapulinaYRunPerfTestProcesses::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(RunModeTests, PapulinaYRunPerfTestProcesses, kGtestValues, kPerfTestName); + +} // namespace papulina_y_count_of_letters From 2422cff18931023e6f6c29a9f25dfb34554a697b Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 00:18:23 +0300 Subject: [PATCH 02/40] Trigger CI rebuild From 2fa34c630b23140c7173029aec036f761fa28768 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 00:18:31 +0300 Subject: [PATCH 03/40] Trigger CI rebuild From 000642235f587d944bc897807c959cb9006c29cb Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 09:20:43 +0300 Subject: [PATCH 04/40] some fixes for clang-format --- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 4 ++-- .../papulina_y_count_of_letters/tests/performance/main.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index c6e2492e05..c7200b882c 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -15,7 +15,7 @@ PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { } int PapulinaYCountOfLettersSEQ::CountOfLetters() { int k = 0; - for (int i = 0; i < GetInput().size(); i++) { + for (site_t i = 0; i < GetInput().size(); i++) { if (isalpha(GetInput()[i])) { k++; } @@ -23,7 +23,7 @@ int PapulinaYCountOfLettersSEQ::CountOfLetters() { return k; } bool PapulinaYCountOfLettersSEQ::ValidationImpl() { - return GetInput().size() >= 0; + return true; } bool PapulinaYCountOfLettersSEQ::PreProcessingImpl() { diff --git a/tasks/papulina_y_count_of_letters/tests/performance/main.cpp b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp index 4044612c5e..e48438927b 100644 --- a/tasks/papulina_y_count_of_letters/tests/performance/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp @@ -11,17 +11,17 @@ class PapulinaYRunPerfTestProcesses : public ppc::util::BaseRunPerfTests Date: Thu, 30 Oct 2025 09:28:42 +0300 Subject: [PATCH 05/40] some fixes for clang-format --- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index c7200b882c..ed7795d270 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -15,7 +15,7 @@ PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { } int PapulinaYCountOfLettersSEQ::CountOfLetters() { int k = 0; - for (site_t i = 0; i < GetInput().size(); i++) { + for (size_t i = 0; i < GetInput().size(); i++) { if (isalpha(GetInput()[i])) { k++; } From d86ba064262b964e378d66ace93f006b2e6827ce Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 11:02:21 +0300 Subject: [PATCH 06/40] function countofletters is changed --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 6 +++++- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index a02ce4739e..6063f41a01 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -18,7 +18,8 @@ PapulinaYCountOfLettersMPI::PapulinaYCountOfLettersMPI(const InType &in) { int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { int k = 0; for (int i = 0; i < n; i++) { - if (isalpha(s[i])) { + char c = GetInput()[i]; + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { k++; } } @@ -41,10 +42,13 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { unsigned int trueLen = 0; // реальная длина обрабатываемой части MPI_Comm_size(MPI_COMM_WORLD, &procNum_); MPI_Comm_rank(MPI_COMM_WORLD, &procRank); + if (procRank == 0) { std::string s = GetInput(); + len = s.size() / procNum_; MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + for (int i = 1; i < procNum_; i++) { int begin = i * len; int end = (i == procNum_ - 1) ? s.size() : begin + len; // таким образом, если потоков, сильно больше, чем diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index ed7795d270..08251824de 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -16,7 +16,8 @@ PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { int PapulinaYCountOfLettersSEQ::CountOfLetters() { int k = 0; for (size_t i = 0; i < GetInput().size(); i++) { - if (isalpha(GetInput()[i])) { + char c = GetInput()[i]; + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { k++; } } From ecb46f8330302b4d2ccf2ce74828d6a8b8e4f2ad Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 11:08:24 +0300 Subject: [PATCH 07/40] clang-format fixes --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 6063f41a01..8a059ed33b 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -18,7 +18,7 @@ PapulinaYCountOfLettersMPI::PapulinaYCountOfLettersMPI(const InType &in) { int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { int k = 0; for (int i = 0; i < n; i++) { - char c = GetInput()[i]; + char c = s[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { k++; } From ef4a17974c9fe976cbd935fd8f5da1b91c283185 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 11:41:30 +0300 Subject: [PATCH 08/40] fixed some bugs in the mpi version --- tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp | 1 - tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp index 418cb8ba6e..b9ba88c209 100644 --- a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp +++ b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp @@ -7,7 +7,6 @@ namespace papulina_y_count_of_letters { class PapulinaYCountOfLettersMPI : public BaseTask { - int procNum_ = 0; public: static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 8a059ed33b..d1094d4647 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -26,8 +26,7 @@ int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { return k; } bool PapulinaYCountOfLettersMPI::ValidationImpl() { - MPI_Comm_size(MPI_COMM_WORLD, &procNum_); - return procNum_ > 0; + return true; } bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { @@ -35,6 +34,7 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { + int procNum_ = 0; int procRank = 0; int result = 0; std::string partOfString = ""; // части строки, которая будет обрабатываться потоком From c765324a1a5e2000d6058a1e43478cd26104ccf1 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 11:47:57 +0300 Subject: [PATCH 09/40] some fixes for clang-format --- tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp | 1 - tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp index b9ba88c209..b6a28a92e8 100644 --- a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp +++ b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp @@ -7,7 +7,6 @@ namespace papulina_y_count_of_letters { class PapulinaYCountOfLettersMPI : public BaseTask { - public: static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { return ppc::task::TypeOfTask::kMPI; diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index d1094d4647..10b07d20f2 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -34,7 +34,7 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { - int procNum_ = 0; + int procNum_ = 0; int procRank = 0; int result = 0; std::string partOfString = ""; // части строки, которая будет обрабатываться потоком From fa4d6d713459c3b346f0a4cb211ca78307f7d629 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 30 Oct 2025 12:59:58 +0300 Subject: [PATCH 10/40] fixed some bugs in the mpi version of task --- tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp | 2 ++ tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp index b6a28a92e8..0849e180b6 100644 --- a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp +++ b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp @@ -19,6 +19,8 @@ class PapulinaYCountOfLettersMPI : public BaseTask { bool RunImpl() override; bool PostProcessingImpl() override; int CountOfLetters(const char *s, const int &n); + + int procNum_ = 0; }; } // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 10b07d20f2..2266133f45 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -14,6 +14,7 @@ PapulinaYCountOfLettersMPI::PapulinaYCountOfLettersMPI(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); GetInput() = in; GetOutput() = 0; + MPI_Comm_size(MPI_COMM_WORLD, &procNum_); } int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { int k = 0; @@ -26,7 +27,7 @@ int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { return k; } bool PapulinaYCountOfLettersMPI::ValidationImpl() { - return true; + return procNum_ > 0; } bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { @@ -34,13 +35,11 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { - int procNum_ = 0; int procRank = 0; int result = 0; std::string partOfString = ""; // части строки, которая будет обрабатываться потоком unsigned int len = 0; // предполагаемая длина обрабатываемой части unsigned int trueLen = 0; // реальная длина обрабатываемой части - MPI_Comm_size(MPI_COMM_WORLD, &procNum_); MPI_Comm_rank(MPI_COMM_WORLD, &procRank); if (procRank == 0) { From 2569936166e141ab0ef736337bf204acc3dee5f9 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sun, 2 Nov 2025 17:05:56 +0300 Subject: [PATCH 11/40] added cout for mpi --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 2266133f45..b3968c7fda 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -35,6 +35,7 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { + std::cout << GetInput() << std::endl; int procRank = 0; int result = 0; std::string partOfString = ""; // части строки, которая будет обрабатываться потоком @@ -72,6 +73,7 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; + std::cout << GetOutput() << std::endl; return true; } From d0285a264353ecc717ac98b8d59fa62efe557ef2 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sun, 2 Nov 2025 18:07:13 +0300 Subject: [PATCH 12/40] changed names of tests --- .../common/include/common.hpp | 2 +- .../tests/functional/main.cpp | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/common/include/common.hpp b/tasks/papulina_y_count_of_letters/common/include/common.hpp index 3834e885d9..e03acdc9b8 100644 --- a/tasks/papulina_y_count_of_letters/common/include/common.hpp +++ b/tasks/papulina_y_count_of_letters/common/include/common.hpp @@ -9,7 +9,7 @@ namespace papulina_y_count_of_letters { using InType = std::string; using OutType = int; -using TestType = std::tuple; // патерн + длина строки +using TestType = std::tuple,std::string>; // патерн + длина строки using BaseTask = ppc::task::Task; } // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index 8330ded93d..d22aa87198 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -23,14 +23,14 @@ namespace papulina_y_count_of_letters { class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::get<0>(test_param) + "_" + std::to_string(std::get<1>(test_param)); + return std::get<1>(test_param); } protected: void SetUp() override { TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - input_data_ = std::string(std::get<0>(params)); - expectedResult_ = std::get<1>(params); + input_data_ = std::string(std::get<0>(std::get<0>(params))); + expectedResult_ = std::get<1>(std::get<0>(params)); } bool CheckTestOutputData(OutType &output_data) final { @@ -52,13 +52,13 @@ TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple("", 0), - std::make_tuple("abcd", 4), - std::make_tuple("aabcd123abcd123abcd", 13), - std::make_tuple("abcd_____________123abcd", 8), - std::make_tuple("a", 1), - std::make_tuple("1243356", 0), - std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12)}; +const std::array kTestParam = {std::make_tuple(std::make_tuple("", 0),"test1"), + std::make_tuple(std::make_tuple("abcd", 4),"test2"), + std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13),"test3"), + std::make_tuple(std::make_tuple("abcd_____________123abcd", 8),"test4"), + std::make_tuple(std::make_tuple("a", 1),"test5"), + std::make_tuple(std::make_tuple("1243356", 0),"test6"), + std::make_tuple(std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12),"test7")}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), From 150e3167e7d90f0e95d48f9036aea0e9e55302f8 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sun, 2 Nov 2025 18:11:53 +0300 Subject: [PATCH 13/40] fixed clang-format --- .../common/include/common.hpp | 2 +- .../tests/functional/main.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/common/include/common.hpp b/tasks/papulina_y_count_of_letters/common/include/common.hpp index e03acdc9b8..87cdb26d97 100644 --- a/tasks/papulina_y_count_of_letters/common/include/common.hpp +++ b/tasks/papulina_y_count_of_letters/common/include/common.hpp @@ -9,7 +9,7 @@ namespace papulina_y_count_of_letters { using InType = std::string; using OutType = int; -using TestType = std::tuple,std::string>; // патерн + длина строки +using TestType = std::tuple, std::string>; // патерн + длина строки using BaseTask = ppc::task::Task; } // namespace papulina_y_count_of_letters diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index d22aa87198..fd352154d3 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -52,13 +52,13 @@ TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(std::make_tuple("", 0),"test1"), - std::make_tuple(std::make_tuple("abcd", 4),"test2"), - std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13),"test3"), - std::make_tuple(std::make_tuple("abcd_____________123abcd", 8),"test4"), - std::make_tuple(std::make_tuple("a", 1),"test5"), - std::make_tuple(std::make_tuple("1243356", 0),"test6"), - std::make_tuple(std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12),"test7")}; +const std::array kTestParam = {std::make_tuple(std::make_tuple("", 0), "test1"), + std::make_tuple(std::make_tuple("abcd", 4), "test2"), + std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13), "test3"), + std::make_tuple(std::make_tuple("abcd_____________123abcd", 8), "test4"), + std::make_tuple(std::make_tuple("a", 1), "test5"), + std::make_tuple(std::make_tuple("1243356", 0), "test6"), + std::make_tuple(std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12), "test7")}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), From eb56fe51e3d95e84628551a364075cb0f12f3adf Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sun, 2 Nov 2025 18:49:27 +0300 Subject: [PATCH 14/40] added some tests for checking results --- .../tests/functional/main.cpp | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index fd352154d3..5946fcee15 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -52,13 +52,21 @@ TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(std::make_tuple("", 0), "test1"), - std::make_tuple(std::make_tuple("abcd", 4), "test2"), - std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13), "test3"), - std::make_tuple(std::make_tuple("abcd_____________123abcd", 8), "test4"), - std::make_tuple(std::make_tuple("a", 1), "test5"), - std::make_tuple(std::make_tuple("1243356", 0), "test6"), - std::make_tuple(std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12), "test7")}; +const std::array kTestParam = { + std::make_tuple(std::make_tuple("", 0), "test1"), + std::make_tuple(std::make_tuple("abcd", 4), "test2"), + std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13), "test3"), + std::make_tuple(std::make_tuple("abcd_____________123abcd", 8), "test4"), + std::make_tuple(std::make_tuple("a", 1), "test5"), + std::make_tuple(std::make_tuple("1243356", 0), "test6"), + std::make_tuple(std::make_tuple("a1a1a1a1a1a1a1a1a1a1a1a1", 12), "test7"), + std::make_tuple(std::make_tuple("!@345678&*()", 0), "test8"), + std::make_tuple(std::make_tuple("aaaaaaaaaaaaaaaaaaaa", 20), "test9"), + std::make_tuple(std::make_tuple("tatatatatatatatatatatatatatatatatatatatata", 42), "test10"), + std::make_tuple(std::make_tuple("er11er11er11er11", 8), "test11"), + std::make_tuple(std::make_tuple("eee___eee__", 6), "test12"), + std::make_tuple(std::make_tuple("eee___eee__EEE", 9), "test13"), + std::make_tuple(std::make_tuple("EEEE___EEEE", 8), "test14")}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), From d35e56c4de5a963a7f66824e551e45aa0887e4f6 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 00:06:34 +0300 Subject: [PATCH 15/40] added some tests --- .../seq/include/ops_seq.hpp | 2 +- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 8 ++++---- .../tests/functional/main.cpp | 11 +++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp index c74c9825ae..3bc14b0338 100644 --- a/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp +++ b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp @@ -13,7 +13,7 @@ class PapulinaYCountOfLettersSEQ : public BaseTask { explicit PapulinaYCountOfLettersSEQ(const InType &in); private: - int CountOfLetters(); + int CountOfLetters(const char *s, const int &n); bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index 08251824de..c05c44d915 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -13,10 +13,10 @@ PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { GetInput() = in; GetOutput() = 0; } -int PapulinaYCountOfLettersSEQ::CountOfLetters() { +int PapulinaYCountOfLettersSEQ::CountOfLetters(const char *s, const int &n) { int k = 0; - for (size_t i = 0; i < GetInput().size(); i++) { - char c = GetInput()[i]; + for (int i = 0; i < n; i++) { + char c = s[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { k++; } @@ -33,7 +33,7 @@ bool PapulinaYCountOfLettersSEQ::PreProcessingImpl() { } bool PapulinaYCountOfLettersSEQ::RunImpl() { - GetOutput() = CountOfLetters(); + GetOutput() = CountOfLetters(GetInput().data(), GetInput().size()); return true; } diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index 5946fcee15..5003be0fc1 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -52,7 +52,7 @@ TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { ExecuteTest(GetParam()); } -const std::array kTestParam = { +const std::array kTestParam = { std::make_tuple(std::make_tuple("", 0), "test1"), std::make_tuple(std::make_tuple("abcd", 4), "test2"), std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13), "test3"), @@ -66,7 +66,14 @@ const std::array kTestParam = { std::make_tuple(std::make_tuple("er11er11er11er11", 8), "test11"), std::make_tuple(std::make_tuple("eee___eee__", 6), "test12"), std::make_tuple(std::make_tuple("eee___eee__EEE", 9), "test13"), - std::make_tuple(std::make_tuple("EEEE___EEEE", 8), "test14")}; + std::make_tuple(std::make_tuple("EEEE___EEEE", 8), "test14"), + std::make_tuple( + std::make_tuple( + "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", + 100), + "test15"), + std::make_tuple(std::make_tuple("фбсдуащуо", 0), "test16"), +}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), From 0452e06e7c79ee2dc7a3faa20ef7252a58876a49 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 00:50:02 +0300 Subject: [PATCH 16/40] added output info --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 4 ++-- tasks/papulina_y_count_of_letters/tests/functional/main.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index b3968c7fda..5bcc0eab81 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -35,7 +35,7 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { - std::cout << GetInput() << std::endl; + std::cout << "Input data in RunImpl: " << GetInput() << std::endl; int procRank = 0; int result = 0; std::string partOfString = ""; // части строки, которая будет обрабатываться потоком @@ -73,7 +73,7 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; - std::cout << GetOutput() << std::endl; + std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; } diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index 5003be0fc1..f207b856f9 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -29,11 +29,15 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + std::cout << "SetUp for " << std::get<1>(params) << std::endl; input_data_ = std::string(std::get<0>(std::get<0>(params))); + std::cout << "We set input data: " << input_data_ << std::endl; expectedResult_ = std::get<1>(std::get<0>(params)); + std::cout << "We set expected result: " << expectedResult_ << std::endl; } bool CheckTestOutputData(OutType &output_data) final { + std::cout << "CheckTestOutputData for " << std::get<1>(params) << std::endl; return (expectedResult_ == output_data); } From 8e118e67d90bab73ab75b1ed57e38d8f7f98817b Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 00:59:27 +0300 Subject: [PATCH 17/40] clang-format is fixed --- tasks/papulina_y_count_of_letters/tests/functional/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index f207b856f9..07c5c28c8c 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -37,7 +37,9 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests(params) << std::endl; + std::cout << "CheckTestOutputData for " + << std::get<1>(std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam())) + << std::endl; return (expectedResult_ == output_data); } From a4a1309e384c2f3cbb2d073561f734055390defb Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 01:19:39 +0300 Subject: [PATCH 18/40] added some fixes in MPI version --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 5bcc0eab81..6af82b7c34 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -71,8 +71,10 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { } int localResult = CountOfLetters(partOfString.data(), trueLen); MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); - GetOutput() = result; + // MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); + if (procRank == 0) { + GetOutput() = result; + } std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; } From b37727cd0014296300b8fa9be9eb7433c805222e Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 01:33:24 +0300 Subject: [PATCH 19/40] fixed some bugs in MPI --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 6af82b7c34..5bcc0eab81 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -71,10 +71,8 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { } int localResult = CountOfLetters(partOfString.data(), trueLen); MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - // MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); - if (procRank == 0) { - GetOutput() = result; - } + MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); + GetOutput() = result; std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; } From 2a9a2b9ab62a32c75ba9d202b807c5d28cdba97c Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 01:52:59 +0300 Subject: [PATCH 20/40] new MPI version checking --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 5bcc0eab81..786c99a439 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -71,8 +71,10 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { } int localResult = CountOfLetters(partOfString.data(), trueLen); MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); - GetOutput() = result; + if (procRank == 0) { + GetOutput() = result; + } + MPI_Barrier(MPI_COMM_WORLD); std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; } From 77ba7757c49b5fe7c888a368dddd03de243eff23 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 02:05:53 +0300 Subject: [PATCH 21/40] trying to use Barrier --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 786c99a439..f17e9c073d 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -71,9 +71,8 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { } int localResult = CountOfLetters(partOfString.data(), trueLen); MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - if (procRank == 0) { - GetOutput() = result; - } + MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); + GetOutput() = result; MPI_Barrier(MPI_COMM_WORLD); std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; From 1de2e37b897973128c7535e891ac53c4e014b3e3 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Thu, 6 Nov 2025 11:56:48 +0300 Subject: [PATCH 22/40] some fixes for coverage --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 3 +++ tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index f17e9c073d..bb4511e50e 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -18,6 +18,9 @@ PapulinaYCountOfLettersMPI::PapulinaYCountOfLettersMPI(const InType &in) { } int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { int k = 0; + if (n <= 0) { + return 0; + } for (int i = 0; i < n; i++) { char c = s[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index c05c44d915..c51d189409 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -15,6 +15,9 @@ PapulinaYCountOfLettersSEQ::PapulinaYCountOfLettersSEQ(const InType &in) { } int PapulinaYCountOfLettersSEQ::CountOfLetters(const char *s, const int &n) { int k = 0; + if (n <= 0) { + return 0; + } for (int i = 0; i < n; i++) { char c = s[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { From 8f3ff920ba99af57ca50101316cc3c5179246b25 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:46:13 +0000 Subject: [PATCH 23/40] [pre-commit] Update hooks versions --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b70f3d31c9..15335ea208 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: # C++ formatting with clang-format - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.2 + rev: v21.1.5 hooks: - id: clang-format files: \.(cpp|hpp|c|h)$ @@ -22,7 +22,7 @@ repos: # Ruff Python linter - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.14.0 + rev: v0.14.4 hooks: - id: ruff args: [--fix] From 8a7dcc415492c573d453cc0d436c33420ee878e6 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Fri, 7 Nov 2025 21:08:56 +0300 Subject: [PATCH 24/40] added fixes in function countofletters --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 +- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index bb4511e50e..52b648e248 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -23,7 +23,7 @@ int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { } for (int i = 0; i < n; i++) { char c = s[i]; - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { + if (isalpha(c)) { k++; } } diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index c51d189409..9b65dc94aa 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -20,7 +20,7 @@ int PapulinaYCountOfLettersSEQ::CountOfLetters(const char *s, const int &n) { } for (int i = 0; i < n; i++) { char c = s[i]; - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { + if (isalpha(c)) { k++; } } From 9f850a50135e2d44e65b1588be75faeebdcb7cc1 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sat, 8 Nov 2025 00:06:13 +0300 Subject: [PATCH 25/40] fixes for clang-tidy and romeved output info --- .../mpi/include/ops_mpi.hpp | 3 +- .../mpi/src/ops_mpi.cpp | 48 +++++++++---------- .../seq/include/ops_seq.hpp | 2 +- .../seq/src/ops_seq.cpp | 11 +++-- .../tests/functional/main.cpp | 18 +++---- .../tests/performance/main.cpp | 8 ++-- 6 files changed, 44 insertions(+), 46 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp index 0849e180b6..71a1d03ad6 100644 --- a/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp +++ b/tasks/papulina_y_count_of_letters/mpi/include/ops_mpi.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include "papulina_y_count_of_letters/common/include/common.hpp" #include "task/include/task.hpp" @@ -18,7 +17,7 @@ class PapulinaYCountOfLettersMPI : public BaseTask { bool PreProcessingImpl() override; bool RunImpl() override; bool PostProcessingImpl() override; - int CountOfLetters(const char *s, const int &n); + static int CountOfLetters(const char *s, const int &n); int procNum_ = 0; }; diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 52b648e248..5e5e39ae26 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -2,8 +2,9 @@ #include -#include -#include +#include +#include +#include #include "papulina_y_count_of_letters/common/include/common.hpp" #include "util/include/util.hpp" @@ -23,7 +24,7 @@ int PapulinaYCountOfLettersMPI::CountOfLetters(const char *s, const int &n) { } for (int i = 0; i < n; i++) { char c = s[i]; - if (isalpha(c)) { + if (isalpha(c) != 0) { k++; } } @@ -38,46 +39,45 @@ bool PapulinaYCountOfLettersMPI::PreProcessingImpl() { } bool PapulinaYCountOfLettersMPI::RunImpl() { - std::cout << "Input data in RunImpl: " << GetInput() << std::endl; - int procRank = 0; + int proc_rank = 0; int result = 0; - std::string partOfString = ""; // части строки, которая будет обрабатываться потоком - unsigned int len = 0; // предполагаемая длина обрабатываемой части - unsigned int trueLen = 0; // реальная длина обрабатываемой части - MPI_Comm_rank(MPI_COMM_WORLD, &procRank); + std::string part_of_string; // части строки, которая будет обрабатываться потоком + unsigned int len = 0; // предполагаемая длина обрабатываемой части + unsigned int true_len = 0; // реальная длина обрабатываемой части + MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank); - if (procRank == 0) { + if (proc_rank == 0) { std::string s = GetInput(); len = s.size() / procNum_; MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); for (int i = 1; i < procNum_; i++) { - int begin = i * len; - int end = (i == procNum_ - 1) ? s.size() : begin + len; // таким образом, если потоков, сильно больше, чем - // длина строки, то последнему уйдет вся работа - trueLen = end - begin; - MPI_Send(&trueLen, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); + unsigned int begin = i * len; + unsigned int end = + (i == procNum_ - 1) ? s.size() : begin + len; // таким образом, если потоков, сильно больше, чем + // длина строки, то последнему уйдет вся работа + true_len = end - begin; + MPI_Send(&true_len, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); if (end - begin != 0) { - MPI_Send(s.substr(begin, end).data(), end - begin, MPI_CHAR, i, 1, MPI_COMM_WORLD); + MPI_Send(s.substr(begin, end).data(), static_cast(end - begin), MPI_CHAR, i, 1, MPI_COMM_WORLD); } else { MPI_Send("", 0, MPI_CHAR, i, 1, MPI_COMM_WORLD); } } - trueLen = std::min(len, (unsigned int)s.size()); - partOfString = s.substr(0, trueLen); + true_len = std::min(len, static_cast(s.size())); + part_of_string = s.substr(0, true_len); } else { MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); - MPI_Recv(&trueLen, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - partOfString.resize(trueLen); - MPI_Recv(&partOfString[0], trueLen, MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(&true_len, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + part_of_string.resize(true_len); + MPI_Recv(part_of_string.data(), static_cast(true_len), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - int localResult = CountOfLetters(partOfString.data(), trueLen); - MPI_Reduce(&localResult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + int local_result = CountOfLetters(part_of_string.data(), static_cast(true_len)); + MPI_Reduce(&local_result, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; MPI_Barrier(MPI_COMM_WORLD); - std::cout << "Output data in RunImpl: " << GetOutput() << std::endl; return true; } diff --git a/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp index 3bc14b0338..84e8eb8a8e 100644 --- a/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp +++ b/tasks/papulina_y_count_of_letters/seq/include/ops_seq.hpp @@ -13,7 +13,7 @@ class PapulinaYCountOfLettersSEQ : public BaseTask { explicit PapulinaYCountOfLettersSEQ(const InType &in); private: - int CountOfLetters(const char *s, const int &n); + static int CountOfLetters(const char *s, const int &n); bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index 9b65dc94aa..4cd94862bd 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -1,7 +1,8 @@ #include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" -#include -#include +#include +// #include +// #include #include "papulina_y_count_of_letters/common/include/common.hpp" #include "util/include/util.hpp" @@ -19,8 +20,8 @@ int PapulinaYCountOfLettersSEQ::CountOfLetters(const char *s, const int &n) { return 0; } for (int i = 0; i < n; i++) { - char c = s[i]; - if (isalpha(c)) { + unsigned char c = s[i]; + if (isalpha(c) != 0) { k++; } } @@ -36,7 +37,7 @@ bool PapulinaYCountOfLettersSEQ::PreProcessingImpl() { } bool PapulinaYCountOfLettersSEQ::RunImpl() { - GetOutput() = CountOfLetters(GetInput().data(), GetInput().size()); + GetOutput() = CountOfLetters(GetInput().data(), static_cast(GetInput().size())); return true; } diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index 07c5c28c8c..b8b0c2c12c 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -1,16 +1,12 @@ #include #include -#include #include #include -#include -#include -#include +#include #include #include -#include -#include +// #include #include "papulina_y_count_of_letters/common/include/common.hpp" #include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" @@ -29,17 +25,17 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - std::cout << "SetUp for " << std::get<1>(params) << std::endl; + std::cout << "SetUp for " << std::get<1>(params) << '\n'; input_data_ = std::string(std::get<0>(std::get<0>(params))); - std::cout << "We set input data: " << input_data_ << std::endl; + std::cout << "We set input data: " << input_data_ << '\n'; expectedResult_ = std::get<1>(std::get<0>(params)); - std::cout << "We set expected result: " << expectedResult_ << std::endl; + std::cout << "We set expected result: " << expectedResult_ << '\n'; } bool CheckTestOutputData(OutType &output_data) final { std::cout << "CheckTestOutputData for " << std::get<1>(std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam())) - << std::endl; + << '\n'; return (expectedResult_ == output_data); } @@ -48,7 +44,7 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests +#include + #include "papulina_y_count_of_letters/common/include/common.hpp" #include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" #include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" @@ -9,15 +11,15 @@ namespace papulina_y_count_of_letters { class PapulinaYRunPerfTestProcesses : public ppc::util::BaseRunPerfTests { const int kCount_ = 10000000; - const std::string s = "abcdabcd"; + const std::string s_ = "abcdabcd"; InType input_data_{}; OutType expectedResult_ = 0; void SetUp() override { for (int i = 0; i < kCount_; i++) { - input_data_ += s; + input_data_ += s_; } - expectedResult_ = kCount_ * s.size(); + expectedResult_ = static_cast(kCount_ * s_.size()); } bool CheckTestOutputData(OutType &output_data) final { From 57a9d79ae950c9aa3c1b8133ce812a981aea5e1a Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sat, 8 Nov 2025 01:37:06 +0300 Subject: [PATCH 26/40] merge with update pre-commit-hooks --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 +- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 2 +- tasks/papulina_y_count_of_letters/tests/performance/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 5e5e39ae26..6c33b26d99 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -7,7 +7,7 @@ #include #include "papulina_y_count_of_letters/common/include/common.hpp" -#include "util/include/util.hpp" +//#include "util/include/util.hpp" namespace papulina_y_count_of_letters { diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index 4cd94862bd..3eee452357 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -5,7 +5,7 @@ // #include #include "papulina_y_count_of_letters/common/include/common.hpp" -#include "util/include/util.hpp" +//#include "util/include/util.hpp" namespace papulina_y_count_of_letters { diff --git a/tasks/papulina_y_count_of_letters/tests/performance/main.cpp b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp index 1398039a08..b0dd93a9ca 100644 --- a/tasks/papulina_y_count_of_letters/tests/performance/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/performance/main.cpp @@ -12,7 +12,7 @@ namespace papulina_y_count_of_letters { class PapulinaYRunPerfTestProcesses : public ppc::util::BaseRunPerfTests { const int kCount_ = 10000000; const std::string s_ = "abcdabcd"; - InType input_data_{}; + InType input_data_; OutType expectedResult_ = 0; void SetUp() override { From 07fe6f521bd5d97a96909fc56d2c70e8062fcbc2 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sat, 8 Nov 2025 01:43:05 +0300 Subject: [PATCH 27/40] clang-format....... --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 2 +- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 6c33b26d99..2e149f2826 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -7,7 +7,7 @@ #include #include "papulina_y_count_of_letters/common/include/common.hpp" -//#include "util/include/util.hpp" +// #include "util/include/util.hpp" namespace papulina_y_count_of_letters { diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index 3eee452357..6a51cb5828 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -5,7 +5,7 @@ // #include #include "papulina_y_count_of_letters/common/include/common.hpp" -//#include "util/include/util.hpp" +// #include "util/include/util.hpp" namespace papulina_y_count_of_letters { From b1f96a6c97b53eccdabefe8745ab588f1032709a Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sat, 8 Nov 2025 01:58:41 +0300 Subject: [PATCH 28/40] empty commit --- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index 6a51cb5828..b273f06039 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -2,7 +2,7 @@ #include // #include -// #include +// #include комментарий #include "papulina_y_count_of_letters/common/include/common.hpp" // #include "util/include/util.hpp" From 68c267b21ba81e8a7525946050aedf8d001dde17 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Sat, 8 Nov 2025 08:59:51 +0300 Subject: [PATCH 29/40] deleted strange file --- .../tests/performance/llvm.sh | 233 ------------------ 1 file changed, 233 deletions(-) delete mode 100644 tasks/papulina_y_count_of_letters/tests/performance/llvm.sh diff --git a/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh b/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh deleted file mode 100644 index b596680923..0000000000 --- a/tasks/papulina_y_count_of_letters/tests/performance/llvm.sh +++ /dev/null @@ -1,233 +0,0 @@ -#!/bin/bash -################################################################################ -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -################################################################################ -# -# This script will install the llvm toolchain on the different -# Debian and Ubuntu versions - -set -eux - -usage() { - set +x - echo "Usage: $0 [llvm_major_version] [all] [OPTIONS]" 1>&2 - echo -e "all\t\t\tInstall all packages." 1>&2 - echo -e "-n=code_name\t\tSpecifies the distro codename, for example bionic" 1>&2 - echo -e "-h\t\t\tPrints this help." 1>&2 - echo -e "-m=repo_base_url\tSpecifies the base URL from which to download." 1>&2 - exit 1; -} - -CURRENT_LLVM_STABLE=20 -BASE_URL="http://apt.llvm.org" - -NEW_DEBIAN_DISTROS=("trixie" "unstable") -# Set default values for commandline arguments -# We default to the current stable branch of LLVM -LLVM_VERSION=$CURRENT_LLVM_STABLE -ALL=0 -DISTRO=$(lsb_release -is) -VERSION_CODENAME=$(lsb_release -cs) -VERSION=$(lsb_release -sr) -UBUNTU_CODENAME="" -CODENAME_FROM_ARGUMENTS="" -# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives) -source /etc/os-release -DISTRO=${DISTRO,,} - -# Check for required tools - -# Check if this is a new Debian distro -is_new_debian=0 -if [[ "${DISTRO}" == "debian" ]]; then - for new_distro in "${NEW_DEBIAN_DISTROS[@]}"; do - if [[ "${VERSION_CODENAME}" == "${new_distro}" ]]; then - is_new_debian=1 - break - fi - done -fi - -# Check for required tools -needed_binaries=(lsb_release wget gpg) -# add-apt-repository is not needed for newer Debian distros -if [[ $is_new_debian -eq 0 ]]; then - needed_binaries+=(add-apt-repository) -fi - -missing_binaries=() -using_curl= -for binary in "${needed_binaries[@]}"; do - if ! command -v $binary &>/dev/null ; then - if [[ "$binary" == "wget" ]] && command -v curl &>/dev/null; then - using_curl=1 - continue - fi - missing_binaries+=($binary) - fi -done - -if [[ ${#missing_binaries[@]} -gt 0 ]] ; then - echo "You are missing some tools this script requires: ${missing_binaries[@]}" - echo "(hint: apt install lsb-release wget software-properties-common gnupg)" - echo "curl is also supported" - exit 4 -fi - -case ${DISTRO} in - debian) - # Debian Trixie has a workaround because of - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1038383 - if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "trixie" ]]; then - CODENAME=unstable - LINKNAME= - else - # "stable" Debian release - CODENAME=${VERSION_CODENAME} - LINKNAME=-${CODENAME} - fi - ;; - *) - # ubuntu and its derivatives - if [[ -n "${UBUNTU_CODENAME}" ]]; then - CODENAME=${UBUNTU_CODENAME} - if [[ -n "${CODENAME}" ]]; then - LINKNAME=-${CODENAME} - fi - fi - ;; -esac - -# read optional command line arguments -if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then - if [ "$1" != "all" ]; then - LLVM_VERSION=$1 - else - # special case for ./llvm.sh all - ALL=1 - fi - OPTIND=2 - if [ "$#" -ge 2 ]; then - if [ "$2" == "all" ]; then - # Install all packages - ALL=1 - OPTIND=3 - fi - fi -fi - -while getopts ":hm:n:" arg; do - case $arg in - h) - usage - ;; - m) - BASE_URL=${OPTARG} - ;; - n) - CODENAME=${OPTARG} - if [[ "${CODENAME}" == "unstable" ]]; then - # link name does not apply to unstable repository - LINKNAME= - else - LINKNAME=-${CODENAME} - fi - CODENAME_FROM_ARGUMENTS="true" - ;; - esac -done - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root!" - exit 1 -fi - -declare -A LLVM_VERSION_PATTERNS -LLVM_VERSION_PATTERNS[9]="-9" -LLVM_VERSION_PATTERNS[10]="-10" -LLVM_VERSION_PATTERNS[11]="-11" -LLVM_VERSION_PATTERNS[12]="-12" -LLVM_VERSION_PATTERNS[13]="-13" -LLVM_VERSION_PATTERNS[14]="-14" -LLVM_VERSION_PATTERNS[15]="-15" -LLVM_VERSION_PATTERNS[16]="-16" -LLVM_VERSION_PATTERNS[17]="-17" -LLVM_VERSION_PATTERNS[18]="-18" -LLVM_VERSION_PATTERNS[19]="-19" -LLVM_VERSION_PATTERNS[20]="-20" -LLVM_VERSION_PATTERNS[21]="-21" -LLVM_VERSION_PATTERNS[22]="" - -if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then - echo "This script does not support LLVM version $LLVM_VERSION" - exit 3 -fi - -LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} - -# join the repository name -if [[ -n "${CODENAME}" ]]; then - REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main" - # check if the repository exists for the distro and version - if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} &> /dev/null && \ - ! curl -sSLI -XHEAD ${BASE_URL}/${CODENAME} &> /dev/null; then - if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then - echo "Specified codename '${CODENAME}' is not supported by this script." - else - echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script." - fi - exit 2 - fi -fi - - -# install everything - -if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then - # download GPG key once - if [[ -z "$using_curl" ]]; then - wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - else - curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - fi -fi - -if [[ -z "`apt-key list 2> /dev/null | grep -i llvm`" ]]; then - # Delete the key in the old format - apt-key del AF4F7421 || true -fi - - -# Add repository based on distribution -if [[ "${VERSION_CODENAME}" == "bookworm" ]]; then - # add it twice to workaround: - # https://github.com/llvm/llvm-project/issues/62475 - add-apt-repository -y "${REPO_NAME}" - add-apt-repository -y "${REPO_NAME}" -elif [[ $is_new_debian -eq 1 ]]; then - # workaround missing add-apt-repository in newer Debian and use new source.list format - SOURCES_FILE="/etc/apt/sources.list.d/http_apt_llvm_org_${CODENAME}_-${VERSION_CODENAME}.sources" - TEXT_TO_ADD="Types: deb -Architectures: amd64 arm64 -Signed-By: /etc/apt/trusted.gpg.d/apt.llvm.org.asc -URIs: ${BASE_URL}/${CODENAME}/ -Suites: llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} -Components: main" - echo "$TEXT_TO_ADD" | tee -a "$SOURCES_FILE" > /dev/null -else - add-apt-repository -y "${REPO_NAME}" -fi - -apt-get update -PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION" -if [[ $ALL -eq 1 ]]; then - # same as in test-install.sh - # No worries if we have dups - PKG="$PKG clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION llvm-$LLVM_VERSION-dev lld-$LLVM_VERSION lldb-$LLVM_VERSION llvm-$LLVM_VERSION-tools libomp-$LLVM_VERSION-dev libc++-$LLVM_VERSION-dev libc++abi-$LLVM_VERSION-dev libclang-common-$LLVM_VERSION-dev libclang-$LLVM_VERSION-dev libclang-cpp$LLVM_VERSION-dev liblldb-$LLVM_VERSION-dev libunwind-$LLVM_VERSION-dev" - if test $LLVM_VERSION -gt 14; then - PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev" - fi -fi -apt-get install -y $PKG From 6b2ca94a371ee417059a5acbda5ca91c51230901 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Mon, 17 Nov 2025 16:15:25 +0300 Subject: [PATCH 30/40] some fixes in mpi version and added generating of string --- .../mpi/src/ops_mpi.cpp | 30 +++++++---- .../tests/functional/main.cpp | 53 +++++++++++++++---- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 2e149f2826..8ab3eff57e 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include "papulina_y_count_of_letters/common/include/common.hpp" @@ -43,6 +44,7 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { int result = 0; std::string part_of_string; // части строки, которая будет обрабатываться потоком unsigned int len = 0; // предполагаемая длина обрабатываемой части + unsigned int remainder = 0; // остаток, если длина строки не кратна числу потоков unsigned int true_len = 0; // реальная длина обрабатываемой части MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank); @@ -50,30 +52,38 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { std::string s = GetInput(); len = s.size() / procNum_; + remainder = s.size() % procNum_; MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + MPI_Bcast(&remainder, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + + unsigned int begin_0 = 0 * len + std::min(static_cast(0), remainder); + unsigned int end_0 = (0 + 1) * len + std::min(static_cast(0 + 1), remainder); + true_len = end_0 - begin_0; + part_of_string = (true_len > 0) ? s.substr(begin_0, true_len) : ""; for (int i = 1; i < procNum_; i++) { - unsigned int begin = i * len; - unsigned int end = - (i == procNum_ - 1) ? s.size() : begin + len; // таким образом, если потоков, сильно больше, чем - // длина строки, то последнему уйдет вся работа - true_len = end - begin; - MPI_Send(&true_len, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); + unsigned int begin = i * len + std::min(static_cast(i), remainder); + unsigned int end = (i + 1) * len + std::min(static_cast(i + 1), remainder); + unsigned int pre_true_len = end - begin; // предварительная длина обрабатываемой части + + MPI_Send(&pre_true_len, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); if (end - begin != 0) { - MPI_Send(s.substr(begin, end).data(), static_cast(end - begin), MPI_CHAR, i, 1, MPI_COMM_WORLD); + MPI_Send(s.substr(begin, pre_true_len).data(), static_cast(pre_true_len), MPI_CHAR, i, 1, MPI_COMM_WORLD); } else { MPI_Send("", 0, MPI_CHAR, i, 1, MPI_COMM_WORLD); } } - true_len = std::min(len, static_cast(s.size())); - part_of_string = s.substr(0, true_len); } else { MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); + MPI_Bcast(&remainder, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); MPI_Recv(&true_len, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); part_of_string.resize(true_len); MPI_Recv(part_of_string.data(), static_cast(true_len), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - int local_result = CountOfLetters(part_of_string.data(), static_cast(true_len)); + std::cout << "part_of_string for " << proc_rank << " :" << part_of_string << '\n'; + std::cout << "true_len for " << proc_rank << " :" << true_len << '\n'; + int local_result = CountOfLetters(part_of_string.data(), static_cast(part_of_string.size())); + std::cout << "local_result for " << proc_rank << " :" << local_result << '\n'; MPI_Reduce(&local_result, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index b8b0c2c12c..a0066c0bc5 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -1,9 +1,11 @@ #include #include +#include #include #include #include +#include #include #include // #include @@ -25,17 +27,20 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - std::cout << "SetUp for " << std::get<1>(params) << '\n'; - input_data_ = std::string(std::get<0>(std::get<0>(params))); - std::cout << "We set input data: " << input_data_ << '\n'; - expectedResult_ = std::get<1>(std::get<0>(params)); - std::cout << "We set expected result: " << expectedResult_ << '\n'; + std::string s = std::string(std::get<0>(std::get<0>(params))); + if (s != "generate") { + input_data_ = std::string(std::get<0>(std::get<0>(params))); + expectedResult_ = std::get<1>(std::get<0>(params)); + } else { + std::string data = GenerateData(100); // будет генерироваться строка, в которой буквенных символов ровно 100 + input_data_ = data; + expectedResult_ = 100; + std::cout << "Generated string: " << input_data_ << "\n"; + std::cout << "Expected result: " << expectedResult_ << "\n"; + } } bool CheckTestOutputData(OutType &output_data) final { - std::cout << "CheckTestOutputData for " - << std::get<1>(std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam())) - << '\n'; return (expectedResult_ == output_data); } @@ -46,6 +51,31 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests length_dist(100, 500); + std::uniform_int_distribution char_dist(32, 126); + + size_t length = length_dist(gen); + std::string generated_string; + generated_string.reserve(length); + + std::string all_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + std::uniform_int_distribution letter_dist(0, all_letters.size() - 1); + // добавляем все буквы + for (size_t i = 0; i < count; i++) { + char c = all_letters[letter_dist(gen)]; + generated_string += c; + } + std::uniform_int_distribution<> non_letter_dist(48, 57); // цифры 0-9 + for (size_t i = count; i < length; ++i) { + char c = static_cast(non_letter_dist(gen)); + generated_string += c; + } + std::shuffle(generated_string.begin(), generated_string.end(), gen); + return generated_string; + } }; namespace { @@ -54,7 +84,7 @@ TEST_P(PapulinaYRunFuncTestsProcesses, CountOfLetters) { ExecuteTest(GetParam()); } -const std::array kTestParam = { +const std::array kTestParam = { std::make_tuple(std::make_tuple("", 0), "test1"), std::make_tuple(std::make_tuple("abcd", 4), "test2"), std::make_tuple(std::make_tuple("aabcd123abcd123abcd", 13), "test3"), @@ -75,7 +105,10 @@ const std::array kTestParam = { 100), "test15"), std::make_tuple(std::make_tuple("фбсдуащуо", 0), "test16"), -}; + std::make_tuple(std::make_tuple("aa", 2), "test17"), + std::make_tuple(std::make_tuple("aaa", 3), "test18"), + std::make_tuple(std::make_tuple("aabb0123456789", 4), "test19"), + std::make_tuple(std::make_tuple("generate", 4), "test20")}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_papulina_y_count_of_letters), From d683313db4cbc5dcf4678f065de1edbde225332e Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Mon, 17 Nov 2025 16:24:15 +0300 Subject: [PATCH 31/40] fixed clang-tidy --- tasks/papulina_y_count_of_letters/tests/functional/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index a0066c0bc5..374297272f 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -52,7 +52,6 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests length_dist(100, 500); std::uniform_int_distribution char_dist(32, 126); From ad052468df48cd892e01cec629008d1f9dd48f31 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Mon, 17 Nov 2025 16:53:55 +0300 Subject: [PATCH 32/40] deleted output info for perf tests --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 8ab3eff57e..89ebbc57b9 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -80,10 +80,10 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { part_of_string.resize(true_len); MPI_Recv(part_of_string.data(), static_cast(true_len), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - std::cout << "part_of_string for " << proc_rank << " :" << part_of_string << '\n'; - std::cout << "true_len for " << proc_rank << " :" << true_len << '\n'; + // std::cout << "part_of_string for " << proc_rank << " :" << part_of_string << '\n'; + // std::cout << "true_len for " << proc_rank << " :" << true_len << '\n'; int local_result = CountOfLetters(part_of_string.data(), static_cast(part_of_string.size())); - std::cout << "local_result for " << proc_rank << " :" << local_result << '\n'; + // std::cout << "local_result for " << proc_rank << " :" << local_result << '\n'; MPI_Reduce(&local_result, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; From c5a188aa8308e72abf1948d3d869fced36d6923b Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Tue, 18 Nov 2025 00:37:27 +0300 Subject: [PATCH 33/40] report is added --- tasks/papulina_y_count_of_letters/report.md | 168 ++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/tasks/papulina_y_count_of_letters/report.md b/tasks/papulina_y_count_of_letters/report.md index e69de29bb2..dd9dd9c486 100644 --- a/tasks/papulina_y_count_of_letters/report.md +++ b/tasks/papulina_y_count_of_letters/report.md @@ -0,0 +1,168 @@ +# <Подсчет числа буквенных символов в строке> + +- Student: Папулина Юлия Андреевна, group 3823Б1ФИ3 +- Technology: SEQ | MPI +- Variant: 22 + +## 1. Введение +Задача подсчета буквенных символов в строке является одной из базовых операций в обработке текстовых данных и представляет собой идеальный пример для освоения принципов параллельного программирования. Сейчас, когда объемы обрабатываемой текстовой информации постоянно растут, эффективная реализация таких операций становится особенно важной. В рамках данной работы реализован MPI-алгоритм, демонстрирующий ключевые аспекты параллельного программирования: декомпозицию задачи, балансировку нагрузки и коллективные операции. + +## 2. Постановка задачи +**Формальная постановка:** для заданной строки S длиной N подсчитать количество символов, являющихся буквами латинского алфавита. +**Входные данные:** строка S произвольной длины +**Выходные данные:** целое число - количество буквенных символов +**Ограничения:** +- Решение должно быть масштабируемым для различного числа процессов + +## 3. Последовательная версия(Baseline) +Алгоритм последовательно проверяет каждый символ строки, определяя принадлежность к латинскому алфавиту с помощью функции int isalpha( int ch ) +```cpp +int result = 0; + if (n <= 0) { + return 0; + } + for (int i = 0; i < n; i++) { + unsigned char c = s[i]; + if (isalpha(c) != 0) { + result++; + } + } + return result; +``` + +## 4. Параллельная версия + +**Разделение данных:** используется блочное распределение данных с равномерным распределением остатка: + - базовый размер блока: len = length / num_processes + - остаток: remainder = length % num_processes + - процесс i получает: len + (i < remainder ? 1 : 0) символов (таким образом, все ramainder процессов получат + дополнительный символ к обработке) +**Взаимодействие процессов:** +Процесс 0 (координатор): + - читает входную строку + - рассылает базовый размер блока(len) и остаток(reminder) остальным потокам(MPI_Bcast) + - инициализирует свою часть обработки строки + - отправка данных(часть строки) для обработки другим процессам через for (MPI_Send) + - cобирает результаты (MPI_Reduce) + +Процессы 1..N-1 (рабочие): +- получают параметры: размер блока, остаток(MPI_Bcast) +- получают свою часть строки для обработки(MPI_Recv) +- выполняют подсчет на своей части +- отправляют результат (MPI_Reduce) +**Псевдокод:** +FUNCTION: + │ + ├─ INITIALIZATION + │ • Get process rank + │ • Initialize variables + │ + ├─ DATA DISTRIBUTION PHASE + │ │ + │ ├─ IF rank = 0 (MASTER): + │ │ • Read input string + │ │ • Calculate base_len = length / procNum + │ │ • Calculate remainder = length % procNum + │ │ • Broadcast base_len, remainder + │ │ • Counting the processed part for master + │ │ • For each worker i: + │ │ - Calculate chunk boundaries + │ │ - Send chunk_size + │ │ - Send chunk_data + │ │ + │ └─ ELSE (WORKER): + │ • Receive broadcast base_len, remainder + │ • Receive chunk_size + │ • Receive chunk_data + │ + ├─ COMPUTATION PHASE + │ • Each process: Count letters in local_data + │ + ├─ RESULT COLLECTION PHASE + │ • MPI_Reduce: SUM all local_count → process 0 + │ • Broadcast result + │ • Set result + | + └─ RETURN success + +## 5. Детали реализации + +**Файловая структура:** +papulina_y_count_of_letters/ +├── common/include/common.hpp +├── seq/include/ops_seq.hpp +├── seq/src/ops_seq.cpp +├── mpi/include/ops_mpi.hpp +├── mpi/src/ops_mpi.cpp +├── tests/functional/main.cpp +├── tests/performance/main.cpp +└── data/ +**Ключевые классы и функции:** +- InType = std::string - тип входных данных (строка) +- OutType = int - тип выходных данных (количество букв) +- CountOfLetters(const char* s, const int& n) - базовый алгоритм подсчета +- RunImpl() - основная логика последовательного выполнения +- ValidationImpl() - проверка валидности входных данных +- PreProcessingImpl(), PostProcessingImpl() - подготовка и завершение +- class PapulinaYRunFuncTestsProcesses - параметрические функциональные тесты +- class PapulinaYRunPerfTestsProcesses - параметрические тесты на производительность +**Использование памяти:** +SEQ версия: +- хранит всю входную строку в памяти +- O(N) память, где N - длина строки +- минимальные накладные расходы(отсутствуют затраты на синхронизацию между потоками/процессами) +MPI версия: +- процесс 0: хранит всю строку + буферы для коммуникации +- рабочие процессы: хранят только свою часть строки +- дополнительная память для MPI буферов сообщений +- эффективное распределение памяти при больших N + +## 6. Экспериментальное окружение +**Hardware/OS:** +- **CPU:** Intel Core i5-11400H (6 cores, 12 threads, 2.70 GHz base frequency) +- **RAM:** 16.0 GB DDR4 +- **Storage:** SSD 512 GB +- **OS:** Windows 10 +**Toolchain:** +- **Compiler:** Microsoft Visual C++ 2019 (MSVC 19.29.30153) +- **MPI Implementation:** Microsoft MPI Version10.1.12498.52 +- **Build System:** CMake 3.30.3 +- **Build Type:** Release +**Environment:** +- **PPC_NUM_PROC:** 1, 2, 4, 6 +**Data:** строка из 40 000 000 латинских символов + +## 7. Результаты + +### 7.1 Корректность +Корректность реализации была проверена через комплексную систему тестирования, включающую: +- 20 функциональных тестов(пустая строка, строка из одного символа, строка с генерированными символами) +- тест на производительность на стабильных данных +Струкутра параметра теста: +- строка (generate - если тест на генерацию) +- ожидаемый результат +- название теста(его номер) +### 7.2 Performance +Время выполнения для строки длиной 40 000 000 символов: + +| Mode | Count | Time, s | Speedup | Efficiency | +|-------------|-------|---------|---------|------------| +| seq | 1 | 0.0951 | 1.00 | N/A | +| mpi | 2 | 0.0937 | 1.01 | 50.5% | +| mpi | 3 | 0.0718 | 1.32 | 44.0% | +| mpi | 4 | 0.0737 | 1.29 | 32.3% | +| mpi | 6 | 0.0778 | 1.22 | 20.3% | + +Анализ результатов: +- минимальное ускорение: наблюдается незначительное ускорение (1.01-1.32x) даже при использовании нескольких процессов +- низкая эффективность: эффективность варьируется от 20.3% до 50.5%, что указывает на значительные накладные расходы +- оптимальная конфигурация: максимальное ускорение достигается при 3 процессах (1.32x) +Анализ узких мест: +- коммуникационные затраты: Время передачи данных между процессами превышает время вычислений для данного объема данных +- неидеальное распределение: Алгоритм распределения данных создает дополнительную нагрузку + +## 8. Заключение +В результате работы в учебных целях разработаны последовательная (SEQ) и параллельная (MPI) версии программы, подсчитывающей число латинских символов в строке. Несмотря на ограниченную практическую эффективность для конкретной задачи подсчета символов, реализация успешно демонстрирует принципы распределенных вычислений и может служить основой для более сложных алгоритмов обработки текста. + +## 9. Источники +1. Microsoft MPI : документация [Электронный ресурс] // Microsoft Learn. – URL: https://learn.microsoft.com/ru-ru/message-passing-interface/microsoft-mpi (дата обращения: 03.11.2025). +2. Сысоев А. В. Курс лекций по параллельному программированию From fdbdfe6598ed3f565b17eb139659ef90ca011476 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Tue, 18 Nov 2025 00:48:46 +0300 Subject: [PATCH 34/40] report is improved --- tasks/papulina_y_count_of_letters/report.md | 61 +++++++++++++-------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/report.md b/tasks/papulina_y_count_of_letters/report.md index dd9dd9c486..bef7667aed 100644 --- a/tasks/papulina_y_count_of_letters/report.md +++ b/tasks/papulina_y_count_of_letters/report.md @@ -1,4 +1,4 @@ -# <Подсчет числа буквенных символов в строке> +# <Подсчет числа буквенных символов в строке - Student: Папулина Юлия Андреевна, group 3823Б1ФИ3 - Technology: SEQ | MPI @@ -32,24 +32,27 @@ int result = 0; ## 4. Параллельная версия -**Разделение данных:** используется блочное распределение данных с равномерным распределением остатка: +### 4.1. Разделение данных + Используется блочное распределение данных с равномерным распределением остатка: - базовый размер блока: len = length / num_processes - остаток: remainder = length % num_processes - процесс i получает: len + (i < remainder ? 1 : 0) символов (таким образом, все ramainder процессов получат + дополнительный символ к обработке) -**Взаимодействие процессов:** -Процесс 0 (координатор): + +### 4.2. Взаимодействие процессов +#### Процесс 0 (Координатор) - читает входную строку - рассылает базовый размер блока(len) и остаток(reminder) остальным потокам(MPI_Bcast) - инициализирует свою часть обработки строки - отправка данных(часть строки) для обработки другим процессам через for (MPI_Send) - cобирает результаты (MPI_Reduce) -Процессы 1..N-1 (рабочие): +#### Процессы 1..N-1 (Рабочие процессы) - получают параметры: размер блока, остаток(MPI_Bcast) - получают свою часть строки для обработки(MPI_Recv) - выполняют подсчет на своей части - отправляют результат (MPI_Reduce) -**Псевдокод:** + +### 4.3. Псевдокод алгоритма FUNCTION: │ ├─ INITIALIZATION @@ -86,7 +89,7 @@ FUNCTION: ## 5. Детали реализации -**Файловая структура:** +### 5.1. Файловая структура проекта papulina_y_count_of_letters/ ├── common/include/common.hpp ├── seq/include/ops_seq.hpp @@ -96,37 +99,46 @@ papulina_y_count_of_letters/ ├── tests/functional/main.cpp ├── tests/performance/main.cpp └── data/ -**Ключевые классы и функции:** -- InType = std::string - тип входных данных (строка) -- OutType = int - тип выходных данных (количество букв) -- CountOfLetters(const char* s, const int& n) - базовый алгоритм подсчета -- RunImpl() - основная логика последовательного выполнения -- ValidationImpl() - проверка валидности входных данных -- PreProcessingImpl(), PostProcessingImpl() - подготовка и завершение -- class PapulinaYRunFuncTestsProcesses - параметрические функциональные тесты -- class PapulinaYRunPerfTestsProcesses - параметрические тесты на производительность -**Использование памяти:** -SEQ версия: + +### 5.2. Ключевые классы и функции + +- `InType = std::string` - тип входных данных (строка) +- `OutType = int` - тип выходных данных (количество букв) +- `CountOfLetters(const char* s, const int& n)` - функция подсчета символов +- `RunImpl()` - основная логика последовательного выполнения +- `ValidationImpl()` - проверка валидности входных данных +- `PreProcessingImpl()` - подготовительные операции +- `PostProcessingImpl()` - завершающие операции +- `class PapulinaYRunFuncTestsProcesses` - параметрические функциональные тесты +- `class PapulinaYRunPerfTestsProcesses` - параметрические тесты производительности + +### 5.3. Использование памяти + +**SEQ версия:** - хранит всю входную строку в памяти - O(N) память, где N - длина строки - минимальные накладные расходы(отсутствуют затраты на синхронизацию между потоками/процессами) -MPI версия: + +**MPI версия:** - процесс 0: хранит всю строку + буферы для коммуникации - рабочие процессы: хранят только свою часть строки - дополнительная память для MPI буферов сообщений - эффективное распределение памяти при больших N ## 6. Экспериментальное окружение + **Hardware/OS:** - **CPU:** Intel Core i5-11400H (6 cores, 12 threads, 2.70 GHz base frequency) - **RAM:** 16.0 GB DDR4 - **Storage:** SSD 512 GB - **OS:** Windows 10 + **Toolchain:** - **Compiler:** Microsoft Visual C++ 2019 (MSVC 19.29.30153) - **MPI Implementation:** Microsoft MPI Version10.1.12498.52 - **Build System:** CMake 3.30.3 - **Build Type:** Release + **Environment:** - **PPC_NUM_PROC:** 1, 2, 4, 6 **Data:** строка из 40 000 000 латинских символов @@ -137,11 +149,13 @@ MPI версия: Корректность реализации была проверена через комплексную систему тестирования, включающую: - 20 функциональных тестов(пустая строка, строка из одного символа, строка с генерированными символами) - тест на производительность на стабильных данных -Струкутра параметра теста: + +**Структура параметров теста:** - строка (generate - если тест на генерацию) - ожидаемый результат - название теста(его номер) -### 7.2 Performance + +### 7.2 Производительность Время выполнения для строки длиной 40 000 000 символов: | Mode | Count | Time, s | Speedup | Efficiency | @@ -152,11 +166,12 @@ MPI версия: | mpi | 4 | 0.0737 | 1.29 | 32.3% | | mpi | 6 | 0.0778 | 1.22 | 20.3% | -Анализ результатов: +**Анализ результатов:** - минимальное ускорение: наблюдается незначительное ускорение (1.01-1.32x) даже при использовании нескольких процессов - низкая эффективность: эффективность варьируется от 20.3% до 50.5%, что указывает на значительные накладные расходы - оптимальная конфигурация: максимальное ускорение достигается при 3 процессах (1.32x) -Анализ узких мест: + +**Анализ узких мест:** - коммуникационные затраты: Время передачи данных между процессами превышает время вычислений для данного объема данных - неидеальное распределение: Алгоритм распределения данных создает дополнительную нагрузку From e2bdd8249fb0142595a8d7de32b02da42b4e4fff Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Tue, 18 Nov 2025 00:51:18 +0300 Subject: [PATCH 35/40] fixes in report --- tasks/papulina_y_count_of_letters/report.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/report.md b/tasks/papulina_y_count_of_letters/report.md index bef7667aed..9fc9ead968 100644 --- a/tasks/papulina_y_count_of_letters/report.md +++ b/tasks/papulina_y_count_of_letters/report.md @@ -1,4 +1,4 @@ -# <Подсчет числа буквенных символов в строке +# Подсчет числа буквенных символов в строке - Student: Папулина Юлия Андреевна, group 3823Б1ФИ3 - Technology: SEQ | MPI @@ -9,8 +9,11 @@ ## 2. Постановка задачи **Формальная постановка:** для заданной строки S длиной N подсчитать количество символов, являющихся буквами латинского алфавита. + **Входные данные:** строка S произвольной длины + **Выходные данные:** целое число - количество буквенных символов + **Ограничения:** - Решение должно быть масштабируемым для различного числа процессов @@ -53,6 +56,7 @@ int result = 0; - отправляют результат (MPI_Reduce) ### 4.3. Псевдокод алгоритма +```pseudocode FUNCTION: │ ├─ INITIALIZATION @@ -84,9 +88,9 @@ FUNCTION: │ • MPI_Reduce: SUM all local_count → process 0 │ • Broadcast result │ • Set result - | + │ └─ RETURN success - +``` ## 5. Детали реализации ### 5.1. Файловая структура проекта From 94756967df7e0b7d0f8bcfa175bb0ff6d570e2ec Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Tue, 18 Nov 2025 00:52:52 +0300 Subject: [PATCH 36/40] last fixes in report --- tasks/papulina_y_count_of_letters/report.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/report.md b/tasks/papulina_y_count_of_letters/report.md index 9fc9ead968..677be1d2b5 100644 --- a/tasks/papulina_y_count_of_letters/report.md +++ b/tasks/papulina_y_count_of_letters/report.md @@ -145,6 +145,7 @@ papulina_y_count_of_letters/ **Environment:** - **PPC_NUM_PROC:** 1, 2, 4, 6 + **Data:** строка из 40 000 000 латинских символов ## 7. Результаты @@ -176,8 +177,8 @@ papulina_y_count_of_letters/ - оптимальная конфигурация: максимальное ускорение достигается при 3 процессах (1.32x) **Анализ узких мест:** -- коммуникационные затраты: Время передачи данных между процессами превышает время вычислений для данного объема данных -- неидеальное распределение: Алгоритм распределения данных создает дополнительную нагрузку +- коммуникационные затраты: время передачи данных между процессами превышает время вычислений для данного объема данных +- неидеальное распределение: алгоритм распределения данных создает дополнительную нагрузку ## 8. Заключение В результате работы в учебных целях разработаны последовательная (SEQ) и параллельная (MPI) версии программы, подсчитывающей число латинских символов в строке. Несмотря на ограниченную практическую эффективность для конкретной задачи подсчета символов, реализация успешно демонстрирует принципы распределенных вычислений и может служить основой для более сложных алгоритмов обработки текста. From 9cb7e17902c8812aad885f95a94656f10287a7f1 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Tue, 18 Nov 2025 08:20:13 +0300 Subject: [PATCH 37/40] some fixes for clang-tidy --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 89ebbc57b9..1c35a3a174 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include "papulina_y_count_of_letters/common/include/common.hpp" @@ -56,14 +55,14 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); MPI_Bcast(&remainder, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); - unsigned int begin_0 = 0 * len + std::min(static_cast(0), remainder); - unsigned int end_0 = (0 + 1) * len + std::min(static_cast(0 + 1), remainder); + unsigned int begin_0 = (0 * len) + std::min(static_cast(0), remainder); + unsigned int end_0 = ((0 + 1) * len) + std::min(static_cast(0 + 1), remainder); true_len = end_0 - begin_0; part_of_string = (true_len > 0) ? s.substr(begin_0, true_len) : ""; for (int i = 1; i < procNum_; i++) { - unsigned int begin = i * len + std::min(static_cast(i), remainder); - unsigned int end = (i + 1) * len + std::min(static_cast(i + 1), remainder); + unsigned int begin = (i * len) + std::min(static_cast(i), remainder); + unsigned int end = ((i + 1) * len) + std::min(static_cast(i + 1), remainder); unsigned int pre_true_len = end - begin; // предварительная длина обрабатываемой части MPI_Send(&pre_true_len, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD); From 6436e841971aad8066d9e514f4aff624d9e2cd99 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Mon, 24 Nov 2025 01:02:34 +0300 Subject: [PATCH 38/40] comments deleted --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 4 ---- tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp | 3 --- tasks/papulina_y_count_of_letters/tests/functional/main.cpp | 1 - 3 files changed, 8 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 1c35a3a174..34e23cd4e6 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -7,7 +7,6 @@ #include #include "papulina_y_count_of_letters/common/include/common.hpp" -// #include "util/include/util.hpp" namespace papulina_y_count_of_letters { @@ -79,10 +78,7 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { part_of_string.resize(true_len); MPI_Recv(part_of_string.data(), static_cast(true_len), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } - // std::cout << "part_of_string for " << proc_rank << " :" << part_of_string << '\n'; - // std::cout << "true_len for " << proc_rank << " :" << true_len << '\n'; int local_result = CountOfLetters(part_of_string.data(), static_cast(part_of_string.size())); - // std::cout << "local_result for " << proc_rank << " :" << local_result << '\n'; MPI_Reduce(&local_result, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(&result, 1, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = result; diff --git a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp index b273f06039..9897c68b35 100644 --- a/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp +++ b/tasks/papulina_y_count_of_letters/seq/src/ops_seq.cpp @@ -1,11 +1,8 @@ #include "papulina_y_count_of_letters/seq/include/ops_seq.hpp" #include -// #include -// #include комментарий #include "papulina_y_count_of_letters/common/include/common.hpp" -// #include "util/include/util.hpp" namespace papulina_y_count_of_letters { diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index 374297272f..d38bd76bc0 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -8,7 +8,6 @@ #include #include #include -// #include #include "papulina_y_count_of_letters/common/include/common.hpp" #include "papulina_y_count_of_letters/mpi/include/ops_mpi.hpp" From 30a8a3231646f40675b2466d13bfd9d5a90205e4 Mon Sep 17 00:00:00 2001 From: YuliyaPapulina Date: Mon, 24 Nov 2025 09:19:02 +0300 Subject: [PATCH 39/40] checking on the empty string before resize --- tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp | 4 +++- tasks/papulina_y_count_of_letters/tests/functional/main.cpp | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp index 34e23cd4e6..d7ff546e57 100644 --- a/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp +++ b/tasks/papulina_y_count_of_letters/mpi/src/ops_mpi.cpp @@ -75,7 +75,9 @@ bool PapulinaYCountOfLettersMPI::RunImpl() { MPI_Bcast(&len, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); MPI_Bcast(&remainder, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); MPI_Recv(&true_len, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - part_of_string.resize(true_len); + if (true_len > 0) { + part_of_string.resize(true_len); + } MPI_Recv(part_of_string.data(), static_cast(true_len), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } int local_result = CountOfLetters(part_of_string.data(), static_cast(part_of_string.size())); diff --git a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp index d38bd76bc0..38b4b68cfb 100644 --- a/tasks/papulina_y_count_of_letters/tests/functional/main.cpp +++ b/tasks/papulina_y_count_of_letters/tests/functional/main.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -34,8 +33,6 @@ class PapulinaYRunFuncTestsProcesses : public ppc::util::BaseRunFuncTests Date: Mon, 24 Nov 2025 12:05:25 +0300 Subject: [PATCH 40/40] accidental file pre-commit-config.yaml corrections are deleted --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 15335ea208..e8751bf609 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: # C++ formatting with clang-format - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.5 + rev: v21.1.2 hooks: - id: clang-format files: \.(cpp|hpp|c|h)$