From 7b9ac0a6a1964e02f28697feb3bdb54233acea7e Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Mon, 14 Apr 2025 13:22:08 +0200 Subject: [PATCH] Make readability-function-cognitive-complexity threshold more strict --- .clang-tidy | 3 ++- tasks/mpi/example/src/ops_mpi.cpp | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9bcc1ab5e..e1a1781df 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -85,7 +85,8 @@ CheckOptions: value: lower_case - key: readability-identifier-naming.IgnoreMainLikeFunctions value: 1 + # Functions with scores beyond 15 are typically flagged as potentially problematic (empirically) - key: readability-function-cognitive-complexity.Threshold - value: 25 # default: 25 + value: 15 # default: 25 - key: misc-include-cleaner.IgnoreHeaders value: '(opencv2/.*|__chrono/.*)' diff --git a/tasks/mpi/example/src/ops_mpi.cpp b/tasks/mpi/example/src/ops_mpi.cpp index bf5eb26e3..3c5af2805 100644 --- a/tasks/mpi/example/src/ops_mpi.cpp +++ b/tasks/mpi/example/src/ops_mpi.cpp @@ -27,25 +27,22 @@ bool nesterov_a_test_task_mpi::TestTaskMPI::ValidationImpl() { bool nesterov_a_test_task_mpi::TestTaskMPI::RunImpl() { int rank = -1; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (rank == 0) { - // Multiply matrices + + auto multiply = [this](bool row_major) { for (int i = 0; i < rc_size_; ++i) { for (int j = 0; j < rc_size_; ++j) { + int sum = 0; for (int k = 0; k < rc_size_; ++k) { - output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j]; - } - } - } - } else { - // Multiply matrices - for (int j = 0; j < rc_size_; ++j) { - for (int k = 0; k < rc_size_; ++k) { - for (int i = 0; i < rc_size_; ++i) { - output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j]; + int a = input_[(row_major ? i : k) * rc_size_ + (row_major ? k : i)]; + int b = input_[(row_major ? k : j) * rc_size_ + (row_major ? j : k)]; + sum += a * b; } + output_[(i * rc_size_) + j] += sum; } } - } + }; + + multiply(rank == 0); MPI_Barrier(MPI_COMM_WORLD); return true; }