diff --git a/.clang-tidy b/.clang-tidy index 46f7b558d..4562d8293 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,6 +27,7 @@ Checks: > readability-*, -bugprone-casting-through-void, -bugprone-easily-swappable-parameters, + -bugprone-throwing-static-initialization, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, @@ -37,9 +38,12 @@ Checks: > -misc-const-correctness, -misc-non-private-member-variables-in-classes, -modernize-avoid-c-arrays, + -misc-override-with-different-visibility, + -misc-use-internal-linkage, -modernize-use-trailing-return-type, -portability-avoid-pragma-once, -portability-template-virtual-member-function, + -readability-inconsistent-ifelse-braces, -readability-magic-numbers HeaderFilterRegex: '.*/(modules|tasks)/.*' diff --git a/modules/performance/tests/perf_tests.cpp b/modules/performance/tests/perf_tests.cpp index 9a4ce9e36..a2e836af9 100644 --- a/modules/performance/tests/perf_tests.cpp +++ b/modules/performance/tests/perf_tests.cpp @@ -39,8 +39,8 @@ class TestPerfTask : public ppc::task::Task { } bool RunImpl() override { - for (unsigned i = 0; i < this->GetInput().size(); i++) { - this->GetOutput() += this->GetInput()[i]; + for (const auto &value : this->GetInput()) { + this->GetOutput() += value; } return true; } @@ -201,12 +201,7 @@ class GetStringTaskTypeTest : public ::testing::TestWithParam void SetUp() override { temp_path = (std::filesystem::temp_directory_path() / "test_settings.json").string(); auto j = ppc::util::InitJSONPtr(); - (*j)["tasks"]["all"] = "ALL"; - (*j)["tasks"]["stl"] = "STL"; - (*j)["tasks"]["omp"] = "OMP"; - (*j)["tasks"]["mpi"] = "MPI"; - (*j)["tasks"]["tbb"] = "TBB"; - (*j)["tasks"]["seq"] = "SEQ"; + *j = {{"tasks", {{"all", "ALL"}, {"stl", "STL"}, {"omp", "OMP"}, {"mpi", "MPI"}, {"tbb", "TBB"}, {"seq", "SEQ"}}}}; std::ofstream(temp_path) << j->dump(); } diff --git a/modules/task/include/task.hpp b/modules/task/include/task.hpp index d20e8e5e0..1b1512371 100644 --- a/modules/task/include/task.hpp +++ b/modules/task/include/task.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -37,17 +38,17 @@ enum class TypeOfTask : uint8_t { kUnknown, }; -using TaskMapping = std::pair; +using TaskMapping = std::pair; using TaskMappingArray = std::array; -const TaskMappingArray kTaskTypeMappings = {{{TypeOfTask::kALL, "all"}, - {TypeOfTask::kMPI, "mpi"}, - {TypeOfTask::kOMP, "omp"}, - {TypeOfTask::kSEQ, "seq"}, - {TypeOfTask::kSTL, "stl"}, - {TypeOfTask::kTBB, "tbb"}}}; +inline constexpr TaskMappingArray kTaskTypeMappings = {{{TypeOfTask::kALL, "all"}, + {TypeOfTask::kMPI, "mpi"}, + {TypeOfTask::kOMP, "omp"}, + {TypeOfTask::kSEQ, "seq"}, + {TypeOfTask::kSTL, "stl"}, + {TypeOfTask::kTBB, "tbb"}}}; -inline std::string TypeOfTaskToString(TypeOfTask type) { +constexpr std::string_view TypeOfTaskToString(TypeOfTask type) { for (const auto &[key, value] : kTaskTypeMappings) { if (key == type) { return value; @@ -88,12 +89,13 @@ inline std::string GetStringTaskType(TypeOfTask type_of_task, const std::string auto list_settings = ppc::util::InitJSONPtr(); file >> *list_settings; - std::string type_str = TypeOfTaskToString(type_of_task); + const std::string_view type_str = TypeOfTaskToString(type_of_task); if (type_str == "unknown") { - return type_str; + return std::string(type_str); } - return type_str + "_" + std::string((*list_settings)["tasks"][type_str]); + const auto &tasks = list_settings->at("tasks"); + return std::string(type_str) + "_" + std::string(tasks.at(std::string(type_str))); } enum class StateOfTesting : uint8_t { diff --git a/modules/task/tests/task_tests.cpp b/modules/task/tests/task_tests.cpp index 843ed7d6a..a374b1df1 100644 --- a/modules/task/tests/task_tests.cpp +++ b/modules/task/tests/task_tests.cpp @@ -26,14 +26,14 @@ using ppc::task::TypeOfTask; class ScopedFile { public: - explicit ScopedFile(std::string path) : path_(std::move(path)) {} - ~ScopedFile() { + explicit ScopedFile(std::filesystem::path path) : path_(std::move(path)) {} + ~ScopedFile() noexcept { std::error_code ec; std::filesystem::remove(path_, ec); } private: - std::string path_; + std::filesystem::path path_; }; namespace ppc::test { @@ -55,8 +55,8 @@ class TestTask : public ppc::task::Task { } bool RunImpl() override { - for (unsigned i = 0; i < this->GetInput().size(); i++) { - this->GetOutput() += this->GetInput()[i]; + for (const auto &value : this->GetInput()) { + this->GetOutput() += value; } return true; } diff --git a/modules/util/include/func_test_util.hpp b/modules/util/include/func_test_util.hpp index 6cae30288..c892bf902 100644 --- a/modules/util/include/func_test_util.hpp +++ b/modules/util/include/func_test_util.hpp @@ -76,17 +76,15 @@ class BaseRunFuncTests : public ::testing::TestWithParam, std::string(GetNamespace()) + "_" + ppc::task::GetStringTaskType(Task::GetStaticTypeOfTask(), settings_path), - sizes[Is])...); + std::get(sizes))...); } template diff --git a/tasks/example_processes/mpi/include/ops_mpi.hpp b/tasks/example_processes/mpi/include/ops_mpi.hpp index 02b612af1..c85254560 100644 --- a/tasks/example_processes/mpi/include/ops_mpi.hpp +++ b/tasks/example_processes/mpi/include/ops_mpi.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskMPI : public BaseTask { } explicit NesterovATestTaskMPI(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_processes/seq/include/ops_seq.hpp b/tasks/example_processes/seq/include/ops_seq.hpp index f264b4fd7..c9608cf0d 100644 --- a/tasks/example_processes/seq/include/ops_seq.hpp +++ b/tasks/example_processes/seq/include/ops_seq.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskSEQ : public BaseTask { } explicit NesterovATestTaskSEQ(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_processes_2/mpi/include/ops_mpi.hpp b/tasks/example_processes_2/mpi/include/ops_mpi.hpp index febfb30ee..f39ac9489 100644 --- a/tasks/example_processes_2/mpi/include/ops_mpi.hpp +++ b/tasks/example_processes_2/mpi/include/ops_mpi.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskMPI : public BaseTask { } explicit NesterovATestTaskMPI(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_processes_2/seq/include/ops_seq.hpp b/tasks/example_processes_2/seq/include/ops_seq.hpp index ac1ad6944..33e2311bf 100644 --- a/tasks/example_processes_2/seq/include/ops_seq.hpp +++ b/tasks/example_processes_2/seq/include/ops_seq.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskSEQ : public BaseTask { } explicit NesterovATestTaskSEQ(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_processes_3/mpi/include/ops_mpi.hpp b/tasks/example_processes_3/mpi/include/ops_mpi.hpp index 080e96585..a1433dc8f 100644 --- a/tasks/example_processes_3/mpi/include/ops_mpi.hpp +++ b/tasks/example_processes_3/mpi/include/ops_mpi.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskMPI : public BaseTask { } explicit NesterovATestTaskMPI(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_processes_3/seq/include/ops_seq.hpp b/tasks/example_processes_3/seq/include/ops_seq.hpp index 5a7b33677..df27f2273 100644 --- a/tasks/example_processes_3/seq/include/ops_seq.hpp +++ b/tasks/example_processes_3/seq/include/ops_seq.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskSEQ : public BaseTask { } explicit NesterovATestTaskSEQ(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_threads/all/include/ops_all.hpp b/tasks/example_threads/all/include/ops_all.hpp index c2d44989d..d4638d337 100644 --- a/tasks/example_threads/all/include/ops_all.hpp +++ b/tasks/example_threads/all/include/ops_all.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskALL : public BaseTask { } explicit NesterovATestTaskALL(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_threads/all/src/ops_all.cpp b/tasks/example_threads/all/src/ops_all.cpp index 92a438555..2f6995878 100644 --- a/tasks/example_threads/all/src/ops_all.cpp +++ b/tasks/example_threads/all/src/ops_all.cpp @@ -60,9 +60,9 @@ bool NesterovATestTaskALL::RunImpl() { GetOutput() *= num_threads; std::vector threads(num_threads); std::atomic counter(0); - for (int i = 0; i < num_threads; i++) { - threads[i] = std::thread([&]() { counter++; }); - threads[i].join(); + for (std::thread &thread : threads) { + thread = std::thread([&counter]() { counter++; }); + thread.join(); } GetOutput() /= counter; } diff --git a/tasks/example_threads/omp/include/ops_omp.hpp b/tasks/example_threads/omp/include/ops_omp.hpp index 4cea6b0e5..2e857114e 100644 --- a/tasks/example_threads/omp/include/ops_omp.hpp +++ b/tasks/example_threads/omp/include/ops_omp.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskOMP : public BaseTask { } explicit NesterovATestTaskOMP(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_threads/seq/include/ops_seq.hpp b/tasks/example_threads/seq/include/ops_seq.hpp index a16e3a390..16eac94de 100644 --- a/tasks/example_threads/seq/include/ops_seq.hpp +++ b/tasks/example_threads/seq/include/ops_seq.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskSEQ : public BaseTask { } explicit NesterovATestTaskSEQ(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_threads/stl/include/ops_stl.hpp b/tasks/example_threads/stl/include/ops_stl.hpp index f33b8b8be..fb153a3e0 100644 --- a/tasks/example_threads/stl/include/ops_stl.hpp +++ b/tasks/example_threads/stl/include/ops_stl.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskSTL : public BaseTask { } explicit NesterovATestTaskSTL(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override; diff --git a/tasks/example_threads/stl/src/ops_stl.cpp b/tasks/example_threads/stl/src/ops_stl.cpp index 33fcaec2b..1dcf1201d 100644 --- a/tasks/example_threads/stl/src/ops_stl.cpp +++ b/tasks/example_threads/stl/src/ops_stl.cpp @@ -41,9 +41,9 @@ bool NesterovATestTaskSTL::RunImpl() { GetOutput() *= num_threads; std::atomic counter(0); - for (int i = 0; i < num_threads; i++) { - threads[i] = std::thread([&]() { counter++; }); - threads[i].join(); + for (std::thread &thread : threads) { + thread = std::thread([&counter]() { counter++; }); + thread.join(); } GetOutput() /= counter; diff --git a/tasks/example_threads/tbb/include/ops_tbb.hpp b/tasks/example_threads/tbb/include/ops_tbb.hpp index dabe985b4..c6160094c 100644 --- a/tasks/example_threads/tbb/include/ops_tbb.hpp +++ b/tasks/example_threads/tbb/include/ops_tbb.hpp @@ -12,7 +12,7 @@ class NesterovATestTaskTBB : public BaseTask { } explicit NesterovATestTaskTBB(const InType &in); - private: + protected: bool ValidationImpl() override; bool PreProcessingImpl() override; bool RunImpl() override;