From d1309b48b5e2ab06401de13f06f79c561b0eb22c Mon Sep 17 00:00:00 2001 From: krllvv Date: Fri, 22 Dec 2023 00:47:24 +0300 Subject: [PATCH] Some fixes --- .../matrix_column_max.cpp | 26 +++++++++---------- .../matrix_column_max.h | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.cpp b/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.cpp index 71a45cf84..cf04469a8 100644 --- a/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.cpp +++ b/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.cpp @@ -8,7 +8,18 @@ #include #include "task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h" -std::pair getColIndexAndCount(size_t columns, int rank); +std::pair getColIndexAndCount(size_t columns, int rank) { + boost::mpi::communicator world; + int size = world.size(); + int colsPerProcess = columns / size; + int reminder = columns % size; + int colsCount = colsPerProcess + (rank < reminder ? 1 : 0); + int colIndex = colsPerProcess * rank + (rank < reminder ? rank : reminder); + if (rank >= columns) { + colIndex = 0; + } + return std::make_pair(colsCount, colIndex); +} std::vector getRandomMatrix(int rows, int columns) { std::random_device dev; @@ -67,15 +78,4 @@ std::vector getParallelMaxInColumns(const std::vector&matrixc, return {}; } -std::pair getColIndexAndCount(size_t columns, int rank) { - boost::mpi::communicator world; - int size = world.size(); - int colsPerProcess = columns / size; - int reminder = columns % size; - int colsCount = colsPerProcess + (rank < reminder ? 1 : 0); - int colIndex = colsPerProcess * rank + (rank < reminder ? rank : reminder); - if (rank >= columns) { - colIndex = 0; - } - return std::make_pair(colsCount, colIndex); -} + diff --git a/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h b/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h index 9caf77fb1..5c0f6c0fe 100644 --- a/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h +++ b/tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h @@ -3,6 +3,9 @@ #include #include +#include + +std::pair getColIndexAndCount(size_t columns, int rank); std::vector getRandomMatrix(int rows, int columns);