Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krllvv committed Dec 21, 2023
1 parent 46eed66 commit d1309b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tasks/task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
#include <boost/mpi/collectives.hpp>
#include "task_1/kirillov_m_max_by_columns_matrix/matrix_column_max.h"

std::pair<int, int> getColIndexAndCount(size_t columns, int rank);
std::pair<int, int> 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<int> getRandomMatrix(int rows, int columns) {
std::random_device dev;
Expand Down Expand Up @@ -67,15 +78,4 @@ std::vector<int> getParallelMaxInColumns(const std::vector<int>&matrixc,
return {};
}

std::pair<int, int> 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);
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <vector>
#include <iostream>
#include <utility>

std::pair<int, int> getColIndexAndCount(size_t columns, int rank);

std::vector<int> getRandomMatrix(int rows, int columns);

Expand Down

0 comments on commit d1309b4

Please sign in to comment.