From 0ac8965a3f6bb35b2f59fc93e39505925a51dfc2 Mon Sep 17 00:00:00 2001 From: Jorgen Schartum Dokken Date: Tue, 7 Jul 2026 14:11:38 +0200 Subject: [PATCH 1/2] Resolve #324 --- chapter1/complex_mode.ipynb | 3 ++- chapter1/complex_mode.py | 3 ++- chapter1/fundamentals_code.ipynb | 1 + chapter1/fundamentals_code.py | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/chapter1/complex_mode.ipynb b/chapter1/complex_mode.ipynb index 0fb38eed..78a6efbb 100644 --- a/chapter1/complex_mode.ipynb +++ b/chapter1/complex_mode.ipynb @@ -249,7 +249,8 @@ "local_error = dolfinx.fem.assemble_scalar(L2_error)\n", "global_error = np.sqrt(mesh.comm.allreduce(local_error, op=MPI.SUM))\n", "max_error = mesh.comm.allreduce(np.max(np.abs(u_c.x.array - uh.x.array)))\n", - "print(global_error, max_error)" + "if mesh.comm.rank == 0:\n", + " print(f\"{global_error=:.2e}, {max_error=:.2e}\", flush=True)" ] }, { diff --git a/chapter1/complex_mode.py b/chapter1/complex_mode.py index 6349163a..27a80ed6 100644 --- a/chapter1/complex_mode.py +++ b/chapter1/complex_mode.py @@ -172,7 +172,8 @@ local_error = dolfinx.fem.assemble_scalar(L2_error) global_error = np.sqrt(mesh.comm.allreduce(local_error, op=MPI.SUM)) max_error = mesh.comm.allreduce(np.max(np.abs(u_c.x.array - uh.x.array))) -print(global_error, max_error) +if mesh.comm.rank == 0: + print(f"{global_error=:.2e}, {max_error=:.2e}", flush=True) # ## Plotting # diff --git a/chapter1/fundamentals_code.ipynb b/chapter1/fundamentals_code.ipynb index a8e7a586..75bb9405 100644 --- a/chapter1/fundamentals_code.ipynb +++ b/chapter1/fundamentals_code.ipynb @@ -459,6 +459,7 @@ "outputs": [], "source": [ "error_max = numpy.max(numpy.abs(uD.x.array - uh.x.array))\n", + "vertex_max = domain.comm.allreduce(error_max, op=MPI.MAX)\n", "if domain.comm.rank == 0: # Only print the error on one process\n", " print(f\"Error_L2 : {error_L2:.2e}\")\n", " print(f\"Error_max : {error_max:.2e}\")" diff --git a/chapter1/fundamentals_code.py b/chapter1/fundamentals_code.py index 2e8b57aa..b63db43e 100644 --- a/chapter1/fundamentals_code.py +++ b/chapter1/fundamentals_code.py @@ -301,6 +301,7 @@ # we can compare the maximum values at any degree of freedom of the approximation space. error_max = numpy.max(numpy.abs(uD.x.array - uh.x.array)) +vertex_max = domain.comm.allreduce(error_max, op=MPI.MAX) if domain.comm.rank == 0: # Only print the error on one process print(f"Error_L2 : {error_L2:.2e}") print(f"Error_max : {error_max:.2e}") From d6dab178866573eee81fd667013b102e52187870 Mon Sep 17 00:00:00 2001 From: Jorgen Schartum Dokken Date: Tue, 7 Jul 2026 14:11:50 +0200 Subject: [PATCH 2/2] Further fix --- chapter1/fundamentals_code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter1/fundamentals_code.py b/chapter1/fundamentals_code.py index b63db43e..4775bb47 100644 --- a/chapter1/fundamentals_code.py +++ b/chapter1/fundamentals_code.py @@ -304,7 +304,7 @@ vertex_max = domain.comm.allreduce(error_max, op=MPI.MAX) if domain.comm.rank == 0: # Only print the error on one process print(f"Error_L2 : {error_L2:.2e}") - print(f"Error_max : {error_max:.2e}") + print(f"Error_max : {vertex_max:.2e}") # ## Plotting the mesh using pyvista # We will visualizing the mesh using [pyvista](https://docs.pyvista.org/), an interface to the VTK toolkit.