Skip to content

Commit 7b9ac0a

Browse files
committed
Make readability-function-cognitive-complexity threshold more strict
1 parent 7e9c38d commit 7b9ac0a

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ CheckOptions:
8585
value: lower_case
8686
- key: readability-identifier-naming.IgnoreMainLikeFunctions
8787
value: 1
88+
# Functions with scores beyond 15 are typically flagged as potentially problematic (empirically)
8889
- key: readability-function-cognitive-complexity.Threshold
89-
value: 25 # default: 25
90+
value: 15 # default: 25
9091
- key: misc-include-cleaner.IgnoreHeaders
9192
value: '(opencv2/.*|__chrono/.*)'

tasks/mpi/example/src/ops_mpi.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,22 @@ bool nesterov_a_test_task_mpi::TestTaskMPI::ValidationImpl() {
2727
bool nesterov_a_test_task_mpi::TestTaskMPI::RunImpl() {
2828
int rank = -1;
2929
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30-
if (rank == 0) {
31-
// Multiply matrices
30+
31+
auto multiply = [this](bool row_major) {
3232
for (int i = 0; i < rc_size_; ++i) {
3333
for (int j = 0; j < rc_size_; ++j) {
34+
int sum = 0;
3435
for (int k = 0; k < rc_size_; ++k) {
35-
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
36-
}
37-
}
38-
}
39-
} else {
40-
// Multiply matrices
41-
for (int j = 0; j < rc_size_; ++j) {
42-
for (int k = 0; k < rc_size_; ++k) {
43-
for (int i = 0; i < rc_size_; ++i) {
44-
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
36+
int a = input_[(row_major ? i : k) * rc_size_ + (row_major ? k : i)];
37+
int b = input_[(row_major ? k : j) * rc_size_ + (row_major ? j : k)];
38+
sum += a * b;
4539
}
40+
output_[(i * rc_size_) + j] += sum;
4641
}
4742
}
48-
}
43+
};
44+
45+
multiply(rank == 0);
4946
MPI_Barrier(MPI_COMM_WORLD);
5047
return true;
5148
}

0 commit comments

Comments
 (0)