This commit is contained in:
kai
2025-06-15 15:58:41 +02:00
parent 94ddd5cc75
commit a121a42bbf
3 changed files with 17 additions and 17 deletions

View File

@@ -1,7 +1,8 @@
#include "patterns.h"
Pattern::Pattern(int rows, int cols, MPIGridSize mpiProcs)
: mpiProcs_(mpiProcs), grid_(SuperGrid::zeros(rows / np0(), cols / np1(), nullptr)) {
: mpiProcs_(mpiProcs),
grid_(SuperGrid::zeros(rows / np0(), cols / np1(), nullptr)) {
if (rows <= 0 || cols <= 0) {
throw std::invalid_argument("Rows and columns must be positive");
}
@@ -19,7 +20,7 @@ Pattern::Pattern(int rows, int cols, MPIGridSize mpiProcs)
std::array<int, 2> periods = {1, 1};
MPI_Cart_create(MPI_COMM_WORLD, 2, mpiProcs.data(), periods.data(), true,
&comm_);
grid_.set_communicator(&comm_);
grid_.set_communicator(comm_);
}
int Pattern::np0() const { return mpiProcs_[0]; }

View File

@@ -6,7 +6,7 @@
class SuperGrid {
public:
static SuperGrid zeros(int rows, int cols, MPI_Comm communicator);
static SuperGrid zeros(int rows, int cols, MPI_Comm communicator);
SuperGrid(const Matrix &other);
@@ -18,8 +18,10 @@ public:
int rows() const;
int cols() const;
MPI_Comm& get_communicator();
void set_communicator(MPI_Comm &communicator);
void find_neighbors();
MPI_Comm &get_communicator();
void set_communicator(MPI_Comm communicator);
private:
Matrix grid_;
@@ -67,12 +69,9 @@ inline const Matrix SuperGrid::get_matrix() const {
return mat;
}
inline MPI_Comm& SuperGrid::get_communicator() {
return this->comm_;
}
inline MPI_Comm &SuperGrid::get_communicator() { return this->comm_; }
void SuperGrid::set_communicator(MPI_Comm& communicator)
{
inline void SuperGrid::set_communicator(MPI_Comm communicator) {
this->comm_ = communicator;
}

View File

@@ -12,14 +12,14 @@ Matrix init_step(SuperGrid start) {
}
TEST(test_underpopulation) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(0, 0) = 1;
Matrix end = init_step(start);
check(end(0, 0), 0);
}
TEST(test_survive_2) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(0, 0) = 1;
start(0, 1) = 1;
start(1, 0) = 1;
@@ -28,7 +28,7 @@ TEST(test_survive_2) {
}
TEST(test_survive_3) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(0, 0) = 1;
start(1, 1) = 1;
start(0, 1) = 1;
@@ -38,7 +38,7 @@ TEST(test_survive_3) {
}
TEST(test_overpopulation) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(1, 1) = 1;
start(0, 1) = 1;
start(1, 0) = 1;
@@ -49,7 +49,7 @@ TEST(test_overpopulation) {
}
TEST(test_reproduction) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(0, 1) = 1;
start(1, 0) = 1;
start(2, 1) = 1;
@@ -58,7 +58,7 @@ TEST(test_reproduction) {
}
TEST(test_survive_edge) {
SuperGrid start = SuperGrid::zeros(10, 10);
SuperGrid start = SuperGrid::zeros(10, 10, nullptr);
start(0, 0) = 1;
start(9, 0) = 1;
start(0, 9) = 1;
@@ -67,7 +67,7 @@ TEST(test_survive_edge) {
}
TEST(test_super_grid) {
SuperGrid su_grid = SuperGrid::zeros(10, 10);
SuperGrid su_grid = SuperGrid::zeros(10, 10, nullptr);
check(su_grid.rows(), 10);
check(su_grid.cols(), 10);
}