From a121a42bbf369c3e69bfe6a8a4379bce84b9cea2 Mon Sep 17 00:00:00 2001 From: kai Date: Sun, 15 Jun 2025 15:58:41 +0200 Subject: [PATCH] fix --- lab11/game_of_life/patterns.cpp | 5 +++-- lab11/game_of_life/super_grid.h | 15 +++++++-------- lab11/game_of_life/test.cpp | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lab11/game_of_life/patterns.cpp b/lab11/game_of_life/patterns.cpp index 9a0f87f..feea455 100644 --- a/lab11/game_of_life/patterns.cpp +++ b/lab11/game_of_life/patterns.cpp @@ -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 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]; } diff --git a/lab11/game_of_life/super_grid.h b/lab11/game_of_life/super_grid.h index 769613a..65485ca 100644 --- a/lab11/game_of_life/super_grid.h +++ b/lab11/game_of_life/super_grid.h @@ -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; } diff --git a/lab11/game_of_life/test.cpp b/lab11/game_of_life/test.cpp index f2bea97..ac8e6ba 100644 --- a/lab11/game_of_life/test.cpp +++ b/lab11/game_of_life/test.cpp @@ -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); }