From f9a1248740f09fbab97f714d29b4476fd747006f Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Sun, 29 Jun 2025 22:34:59 +0200 Subject: [PATCH] . --- lab12/exc4/jacobi.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lab12/exc4/jacobi.cpp b/lab12/exc4/jacobi.cpp index df40e6f..df2c4b4 100644 --- a/lab12/exc4/jacobi.cpp +++ b/lab12/exc4/jacobi.cpp @@ -240,7 +240,7 @@ Jacobi::Result Jacobi::run(const Matrix &init, double eps, int maxNumIter) int t0 = 0; // array index of current timestep int t1 = 1; // array index of next timestep -#pragma omp parallel firstprivate(t0, t1) lastprivate(nIter) +#pragma omp parallel while (dist > eps && nIter < maxNumIter) { dist = 0; @@ -262,10 +262,12 @@ Jacobi::Result Jacobi::run(const Matrix &init, double eps, int maxNumIter) } #pragma omp single - MPI_Allreduce(MPI_IN_PLACE, &dist, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + { + MPI_Allreduce(MPI_IN_PLACE, &dist, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - nIter++; - std::swap(t0, t1); + nIter++; + std::swap(t0, t1); + } } return {removeHaloLayers(phi[t0]), dist, nIter};