From 44a3fcb94384b9480f197ac65a18e50adacc801a Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Mon, 16 Jun 2025 22:01:29 +0200 Subject: [PATCH] x --- lab11/game_of_life/game_of_life.cpp | 2 +- lab11/game_of_life/patterns.cpp | 5 +++-- lab11/game_of_life/super_grid.cpp | 6 +++--- lab11/game_of_life/super_grid.h | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lab11/game_of_life/game_of_life.cpp b/lab11/game_of_life/game_of_life.cpp index 7eb73a6..672f843 100644 --- a/lab11/game_of_life/game_of_life.cpp +++ b/lab11/game_of_life/game_of_life.cpp @@ -7,7 +7,7 @@ void GameOfLife::step() { SuperGrid next = SuperGrid::zeros(grid_.rows(), grid_.cols(), grid_.get_communicator()); const int rows = grid_.rows(); const int cols = grid_.cols(); - //grid_.update(); + grid_.update(); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { const int numLiveNeighbors = countLiveNeighbors(i, j); diff --git a/lab11/game_of_life/patterns.cpp b/lab11/game_of_life/patterns.cpp index feea455..1992cd0 100644 --- a/lab11/game_of_life/patterns.cpp +++ b/lab11/game_of_life/patterns.cpp @@ -1,8 +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(Matrix::zeros(rows / np0(), cols / np1()))) { if (rows <= 0 || cols <= 0) { throw std::invalid_argument("Rows and columns must be positive"); } @@ -21,6 +21,7 @@ Pattern::Pattern(int rows, int cols, MPIGridSize mpiProcs) MPI_Cart_create(MPI_COMM_WORLD, 2, mpiProcs.data(), periods.data(), true, &comm_); grid_.set_communicator(comm_); + grid_.find_neighbors(); } int Pattern::np0() const { return mpiProcs_[0]; } diff --git a/lab11/game_of_life/super_grid.cpp b/lab11/game_of_life/super_grid.cpp index a025cea..19c043f 100644 --- a/lab11/game_of_life/super_grid.cpp +++ b/lab11/game_of_life/super_grid.cpp @@ -1,10 +1,10 @@ #include #include "super_grid.h" -std::vector SuperGrid::receive_halos(HaloLayers halo_layers) +std::vector SuperGrid::receive_halos(HaloLayers& halo_layers) { std::vector recv_requests(8); - std::cout << halo_layers.top_halo.size() << std::endl; + std::cout << halo_layers.top_halo.size() << "top halo size" << std::endl; MPI_Irecv(halo_layers.top_halo.data(), halo_layers.top_halo.size(), MPI_DOUBLE, neighbors_.top, neighbors_.top, comm_, &recv_requests[0]); MPI_Irecv(halo_layers.right_halo.data(), halo_layers.right_halo.size(), MPI_DOUBLE, neighbors_.right, neighbors_.right, comm_, &recv_requests[1]); MPI_Irecv(halo_layers.bottom_halo.data(), halo_layers.bottom_halo.size(), MPI_DOUBLE, neighbors_.bottom, neighbors_.bottom, comm_, &recv_requests[2]); @@ -96,7 +96,7 @@ std::vector SuperGrid::inform_neighbors() } std::vector send_requests(8); - std::cout << inner_top_row.size() << "inform_neighbors" << std::endl; + std::cout << inner_bottom_row.size() << "inner_bottom_row" << std::endl; MPI_Isend(inner_top_row.data(), inner_top_row.size(), MPI_DOUBLE, neighbors_.top, rank_, comm_, &send_requests[0]); MPI_Isend(inner_right_column.data(), inner_right_column.size(), MPI_DOUBLE, neighbors_.right, rank_, comm_, &send_requests[1]); MPI_Isend(inner_bottom_row.data(), inner_bottom_row.size(), MPI_DOUBLE, neighbors_.bottom, rank_, comm_, &send_requests[2]); diff --git a/lab11/game_of_life/super_grid.h b/lab11/game_of_life/super_grid.h index de0601c..de1413f 100644 --- a/lab11/game_of_life/super_grid.h +++ b/lab11/game_of_life/super_grid.h @@ -79,7 +79,7 @@ public: void set_communicator(MPI_Comm communicator); void update(); - std::vector receive_halos(HaloLayers halo_layers); + std::vector receive_halos(HaloLayers& halo_layers); std::vector inform_neighbors(); std::vector get_inner_top_row(); @@ -113,13 +113,13 @@ inline SuperGrid::SuperGrid(const Matrix &other) grid_(i + 1, j + 1) = other(i, j); // copy into grid_ directly } } - MPI_Comm_rank(MPI_COMM_WORLD, &rank_); } inline SuperGrid SuperGrid::zeros(int rows, int cols, MPI_Comm communicator) { SuperGrid grid = SuperGrid(Matrix::zeros(rows, cols)); grid.set_communicator(communicator); + MPI_Comm_rank(MPI_COMM_WORLD, &grid.rank_); grid.find_neighbors(); return grid; } @@ -167,7 +167,7 @@ inline void SuperGrid::find_neighbors() std::cerr << "Communicator is NULL!\n"; } int rank; - MPI_Comm_rank(this->comm_, &rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); int coords[2]; MPI_Cart_coords(this->comm_, rank, 2, coords); for (int dx = -1; dx <= 1; ++dx)