From 314d82dc4812d359cface0cac3bec76b7516d7e5 Mon Sep 17 00:00:00 2001 From: WickedJack99 Date: Sun, 29 Jun 2025 22:53:25 +0200 Subject: [PATCH] . --- lab12/exc4/jacobi.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lab12/exc4/jacobi.cpp b/lab12/exc4/jacobi.cpp index 579b086..9db71cf 100644 --- a/lab12/exc4/jacobi.cpp +++ b/lab12/exc4/jacobi.cpp @@ -244,14 +244,16 @@ Jacobi::Result Jacobi::run(const Matrix &init, double eps, int maxNumIter) { while (dist > eps && nIter < maxNumIter) { - double local_dist = 0; - + #pragma omp single - exchangeHaloLayers(phi[t0]); + { + dist = 0; + exchangeHaloLayers(phi[t0]); + } #pragma omp barrier -#pragma omp for reduction(max : local_dist) schedule(static) +#pragma omp for reduction(max : dist) schedule(static) for (int i = 1; i < numRows - 1; ++i) { for (int j = 1; j < numCols - 1; ++j) @@ -260,14 +262,13 @@ Jacobi::Result Jacobi::run(const Matrix &init, double eps, int maxNumIter) phi[t0](i, j + 1) + phi[t0](i, j - 1)); const double diff = phi[t1](i, j) - phi[t0](i, j); - local_dist = std::max(local_dist, std::abs(diff)); + dist = std::max(dist, std::abs(diff)); } } #pragma omp single { MPI_Allreduce(MPI_IN_PLACE, &dist, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - dist = local_dist; nIter++; std::swap(t0, t1); }