From 11614b4a2dd326c7c1e8a0d771dea0fa77339387 Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Sun, 29 Jun 2025 21:45:29 +0200 Subject: [PATCH] . --- lab12/exc4/jacobi.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lab12/exc4/jacobi.cpp b/lab12/exc4/jacobi.cpp index 62ce24c..f976d49 100644 --- a/lab12/exc4/jacobi.cpp +++ b/lab12/exc4/jacobi.cpp @@ -104,25 +104,25 @@ void Jacobi::exchangeHaloLayersNodeMPIProcSecond(Matrix &phi) // communication with second rank on same node via shared memory // We write our send row to shared memory row 0 - while (states->shmStates[0] == SharedmemState::Unread) + while (states->shmStates[1] == SharedmemState::Unread) { MPI_Win_sync(win_); } for (int j = 0; j < sendSize; ++j) - shm0[j] = phi(1, j); - states->shmStates[0] = SharedmemState::Unread; + shm1[j] = phi(1, j); + states->shmStates[1] = 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->shmStates[1] == SharedmemState::Read) + while (states->shmStates[0] == SharedmemState::Read) { MPI_Win_sync(win_); } for (int j = 0; j < sendSize; ++j) - phi(0, j) = shm1[j]; // halo from second proc - states->shmStates[1] = SharedmemState::Read; + phi(0, j) = shm0[j]; // halo from second proc + states->shmStates[0] = SharedmemState::Read; MPI_Win_sync(win_); } @@ -157,7 +157,7 @@ void Jacobi::exchangeHaloLayersNodeMPIProcFirst(Matrix &phi) // communication with second rank on same node via shared memory // We write our send row to shared memory row 0 - while (states->shmStates[1] == SharedmemState::Unread) + while (states->shmStates[0] == SharedmemState::Unread) { MPI_Win_sync(win_); } @@ -167,14 +167,13 @@ void Jacobi::exchangeHaloLayersNodeMPIProcFirst(Matrix &phi) } for (int j = 0; j < sendSize; ++j) - shm1[j] = phi(n - 2, j); // our last inner row - states->shmStates[1] = SharedmemState::Unread; + shm0[j] = phi(n - 2, j); // our last inner row + states->shmStates[0] = 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->shmStates[0] == SharedmemState::Read) + while (states->shmStates[1] == SharedmemState::Read) { - MPI_Win_sync(win_); } if (rank_ == (numProc_ - 2)) @@ -182,12 +181,12 @@ void Jacobi::exchangeHaloLayersNodeMPIProcFirst(Matrix &phi) std::cout << "t2" << std::endl; } for (int j = 0; j < sendSize; ++j) - phi(n - 1, j) = shm0[j]; // halo from first proc + phi(n - 1, j) = shm1[j]; // halo from second proc if (rank_ == (numProc_ - 2)) { std::cout << "t3" << std::endl; } - states->shmStates[0] = SharedmemState::Read; + states->shmStates[1] = SharedmemState::Read; MPI_Win_sync(win_); }