While these tutorials are typically meant to be visualized in serial, viskex also runs in parallel. To exemplify this, we will show a parallel case using ipyparallel.
First of all, we start a ipyparallel MPI cluster with 2 processes.
import ipyparallel as ipp
cluster = ipp.Cluster(engines="MPI", profile="mpi", n=2)
cluster.start_and_connect_sync()
Starting 2 engines with <class 'ipyparallel.cluster.launcher.MPIEngineSetLauncher'>
<ipyparallel.client.client.Client at 0x7ff864cfb650>
The jupyter magic %%px will run the following cells on the ipyparallel cluster.
%%px
import firedrake # noqa: E402
import mpi4py.MPI # noqa: E402
%%px
import viskex # noqa: E402
To confirm that we are running in parallel, we can print the rank of the current process and the total number of processes.
%%px
comm_world = mpi4py.MPI.COMM_WORLD
print(f"rank = {comm_world.rank}, size = {comm_world.size}")
[stdout:0] rank = 0, size = 2
[stdout:1] rank = 1, size = 2
Generate a mesh on MPI_COMM_WORLD of the unit square by dividing each edge of the square in 6 segments.
%%px
square_world = firedrake.UnitSquareMesh(
6, 6, comm=comm_world, distribution_parameters={"partitioner_type": "simple"})
Plot the mesh defined on MPI_COMM_WORLD. Each rank will plot its local cells, and their neighbors (called halos in firedrake).
%%px
viskex.firedrake.plot_mesh(square_world)
[stderr:0] 2026-09-14 09:36:24.856 ( 1.155s) [ 7FF6B4A79080]vtkXOpenGLRenderWindow.:1450 WARN| bad X server connection. DISPLAY=
[stderr:1] 2026-09-14 09:36:24.856 ( 1.155s) [ 7F2F2475A080]vtkXOpenGLRenderWindow.:1450 WARN| bad X server connection. DISPLAY=
[output:0]
[output:1]
For comparison, we can generate a similar mesh on MPI_COMM_SELF. Each rank will have its own copy of the whole mesh.
%%px
comm_self = mpi4py.MPI.COMM_SELF
square_self = firedrake.UnitSquareMesh(
6, 6, comm=comm_self, distribution_parameters={"partitioner_type": "simple"})
Plot the mesh defined on MPI_COMM_SELF. Each rank will produce a plot which is visually the same, since each rank has its own copy of the same mesh.
%%px
viskex.firedrake.plot_mesh(square_self)
[output:1]
[output:0]
We finally stop the ipyparallel cluster. Note that when running with Run -> Run all cells all interactive plots will be closed when the kernel executes this cell.
cluster.stop_cluster_sync()
Stopping controller
Controller stopped: {'exit_code': 0, 'pid': 925, 'identifier': 'ipcontroller-1789374976-szui-906'}
Stopping engine(s): 1789374977
Output for ipengine-1789374976-szui-1789374977-906: 2026-09-14 09:36:17.421 [IPEngine] Loading connection info from $IPP_CONNECTION_INFO 2026-09-14 09:36:17.421 [IPEngine] WARNING | Not using CurveZMQ security 2026-09-14 09:36:17.433 [IPEngine] Loading connection info from $IPP_CONNECTION_INFO 2026-09-14 09:36:17.433 [IPEngine] WARNING | Not using CurveZMQ security 2026-09-14 09:36:17.669 [IPEngine.1] Registering with controller at tcp://127.0.0.1:59455 2026-09-14 09:36:17.669 [IPEngine.0] Registering with controller at tcp://127.0.0.1:59455 2026-09-14 09:36:17.669 [IPEngine.1] Requesting id: 1 2026-09-14 09:36:17.669 [IPEngine.0] Requesting id: 0 2026-09-14 09:36:17.672 [IPEngine.1.1] Shell_addrs: ['tcp://127.0.0.1:33515', 'tcp://127.0.0.1:34701', 'tcp://127.0.0.1:32937'] 2026-09-14 09:36:17.672 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:33515 2026-09-14 09:36:17.672 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:34701 2026-09-14 09:36:17.672 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:32937 2026-09-14 09:36:17.672 [IPEngine.1.1] Starting nanny 2026-09-14 09:36:17.675 [IPEngine.0.0] Shell_addrs: ['tcp://127.0.0.1:33515', 'tcp://127.0.0.1:34701', 'tcp://127.0.0.1:53939'] 2026-09-14 09:36:17.675 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:33515 2026-09-14 09:36:17.675 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:34701 2026-09-14 09:36:17.675 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:53939 2026-09-14 09:36:17.675 [IPEngine.0.0] Starting nanny 2026-09-14 09:36:17.933 [KernelNanny.0] Starting kernel nanny for engine 0, pid=960, nanny pid=972 2026-09-14 09:36:17.933 [KernelNanny.0] Nanny watching parent pid 960. 2026-09-14 09:36:17.933 [KernelNanny.1] Starting kernel nanny for engine 1, pid=961, nanny pid=971 2026-09-14 09:36:17.934 [KernelNanny.1] Nanny watching parent pid 961. 2026-09-14 09:36:18.022 [IPEngine.0.0] Loading IPython extension: storemagic 2026-09-14 09:36:18.022 [IPEngine.1.1] Loading IPython extension: storemagic 2026-09-14 09:36:18.024 [IPEngine.0.0] Running code in user namespace: from mpi4py import MPI mpi_rank = MPI.COMM_WORLD.Get_rank() mpi_size = MPI.COMM_WORLD.Get_size() 2026-09-14 09:36:18.024 [IPEngine.1.1] Running code in user namespace: from mpi4py import MPI mpi_rank = MPI.COMM_WORLD.Get_rank() mpi_size = MPI.COMM_WORLD.Get_size() 2026-09-14 09:36:18.026 [IPEngine.0.0] WARNING | debugpy_stream undefined, debugging will not be enabled 2026-09-14 09:36:18.026 [IPEngine.1.1] WARNING | debugpy_stream undefined, debugging will not be enabled 2026-09-14 09:36:18.028 [IPEngine.0.0] Starting to monitor the heartbeat signal from the hub every 3500 ms. 2026-09-14 09:36:18.028 [IPEngine.0.0] Completed registration with id 0 2026-09-14 09:36:18.028 [IPEngine.1.1] Starting to monitor the heartbeat signal from the hub every 3500 ms. 2026-09-14 09:36:18.028 [IPEngine.1.1] Completed registration with id 1 2026-09-14 09:36:22.682 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_2 2026-09-14 09:36:22.682 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_1 2026-09-14 09:36:24.206 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_3 2026-09-14 09:36:24.207 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_4 2026-09-14 09:36:24.816 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_5 2026-09-14 09:36:24.817 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_6 2026-09-14 09:36:24.829 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_7 2026-09-14 09:36:24.830 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_8 2026-09-14 09:36:24.851 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_9 2026-09-14 09:36:24.851 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_10 2026-09-14 09:36:24.856 ( 1.155s) [ 7F2F2475A080]vtkXOpenGLRenderWindow.:1450 WARN| bad X server connection. DISPLAY= 2026-09-14 09:36:24.856 ( 1.155s) [ 7FF6B4A79080]vtkXOpenGLRenderWindow.:1450 WARN| bad X server connection. DISPLAY= 2026-09-14 09:36:25.705 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_12 2026-09-14 09:36:25.705 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_11 2026-09-14 09:36:25.722 [IPEngine.0.0] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_13 2026-09-14 09:36:25.722 [IPEngine.1.1] Handling execute_request: 2f9ee255-49051e537b914fec0d9d75de_906_14
engine set stopped 1789374977: {'exit_code': 1, 'pid': 953, 'identifier': 'ipengine-1789374976-szui-1789374977-906'}