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..4775bb47 100644 --- a/chapter1/fundamentals_code.py +++ b/chapter1/fundamentals_code.py @@ -301,9 +301,10 @@ # 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}") + 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.