From 508617ad41704ce539eb32a0d2c79d46174289ee Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Sun, 29 Jun 2025 20:12:50 +0200 Subject: [PATCH] . --- lab12/exc4/jacobi.cpp | 32 ++++++++++++++++---------------- lab12/exc4/jacobi.h | 23 +++++++++++------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/lab12/exc4/jacobi.cpp b/lab12/exc4/jacobi.cpp index e32aa71..2c7488e 100644 --- a/lab12/exc4/jacobi.cpp +++ b/lab12/exc4/jacobi.cpp @@ -92,28 +92,28 @@ void Jacobi::exchangeHaloLayersNodeMPIProcFirst(Matrix &phi) // Communication with lower partner if (!isFirstRank()) { - SharedmemStates *states = reinterpret_cast(baseptr); + SharedmemStates *states = reinterpret_cast(baseptr_); double *shm0 = reinterpret_cast(states + 1); // row 0 - double *shm1 = shm0 + cols; // row 1 + double *shm1 = shm0 + sendSize; // row 1 // communication with second rank on same node via shared memory // We write our send row to shared memory row 0 - while (states[0] == SharedmemState::Unread) + while (states.shmStates[0] == SharedmemState::Unread) {MPI_Win_sync(win_);} for (int j = 0; j < sendSize; ++j) - shm0[j] = phi(n - 2, j); // our last inner row - states[0] = SharedmemState::Unread; + shm0[j] = phi(1, j); + states.shmStates[0] = SharedmemState::Unread; MPI_Win_sync(win_); // ensure memory visibility // Wait for second proc to write its row back to shared memory row 1 - while (states[1] == SharedmemState::Read) + while (states.shmStates[1] == SharedmemState::Read) {MPI_Win_sync(win_);} for (int j = 0; j < sendSize; ++j) - phi(n - 1, j) = shm1[j]; // halo from second proc - states[1] = SharedmemState::Read; + phi(0, j) = shm1[j]; // halo from second proc + states.shmStates[1] = SharedmemState::Read; } // Wait for communication to finish @@ -132,28 +132,28 @@ void Jacobi::exchangeHaloLayersNodeMPIProcSecond(Matrix &phi) // Communication with upper partner if (!isLastRank()) { - SharedmemStates *states = reinterpret_cast(baseptr); + SharedmemStates *states = reinterpret_cast(baseptr_); double *shm0 = reinterpret_cast(states + 1); // row 0 - double *shm1 = shm0 + cols; // row 1 + double *shm1 = shm0 + sendSize; // row 1 // communication with second rank on same node via shared memory // We write our send row to shared memory row 0 - while (states[1] == SharedmemState::Unread) + while (states.shmStates[1] == SharedmemState::Unread) {MPI_Win_sync(win_);} for (int j = 0; j < sendSize; ++j) - shm1[j] = phi(1, j); // our last inner row - states[1] = SharedmemState::Unread; + shm1[j] = phi(n - 2, j); // our last inner row + states.shmStates[1] = SharedmemState::Unread; MPI_Win_sync(win_); // ensure memory visibility // Wait for first proc to write its row back to shared memory row 0 - while (states[0] == SharedmemState::Read) + while (states.shmStates[0] == SharedmemState::Read) {MPI_Win_sync(win_);} for (int j = 0; j < sendSize; ++j) - phi(0, j) = shm0[j]; // halo from first proc - states[0] = SharedmemState::Read; + phi(n - 1, j) = shm0[j]; // halo from first proc + states.shmStates[0] = SharedmemState::Read; } // Communication with lower partner diff --git a/lab12/exc4/jacobi.h b/lab12/exc4/jacobi.h index e7a95d6..f03007a 100644 --- a/lab12/exc4/jacobi.h +++ b/lab12/exc4/jacobi.h @@ -3,6 +3,17 @@ #include "matrix.h" +enum SharedmemState +{ + Unread = 0, + Read = 1 +}; + +struct SharedmemStates +{ + SharedmemState shmStates[2]; // Flags: one for each row +}; + /** * Base class for Jacobi algorithms. * Defines a struct result which is returned by the algorithm. @@ -70,18 +81,6 @@ class Jacobi { }; }; -enum SharedmemState -{ - Unread = 0, - Read = 1 -}; - -struct SharedmemStates -{ - SharedmemState shmStates[2]; // Flags: one for each row -}; - - // 4 times horizontal split | with mpi // 12 times vertical split - with openmp