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 0x7fd4c8ba22d0>
The jupyter magic %%px will run the following cells on the ipyparallel cluster.
%%px
import dolfinx.mesh # 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 = dolfinx.mesh.create_unit_square(comm_world, 6, 6)
Plot the mesh defined on MPI_COMM_WORLD. Each rank will plot its local cells, and their neighbors (called ghosts in dolfinx).
%%px
viskex.dolfinx.plot_mesh(square_world)
[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 = dolfinx.mesh.create_unit_square(comm_self, 6, 6)
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.dolfinx.plot_mesh(square_self)
[output:0]
[output:1]
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': 3130, 'identifier': 'ipcontroller-1770016982-7o9s-3111'}
Stopping engine(s): 1770016983
Output for ipengine-1770016982-7o9s-1770016983-3111: 2026-02-02 07:23:04.129 [IPEngine] Loading connection info from $IPP_CONNECTION_INFO 2026-02-02 07:23:04.130 [IPEngine] WARNING | Not using CurveZMQ security 2026-02-02 07:23:04.131 [IPEngine] Loading connection info from $IPP_CONNECTION_INFO 2026-02-02 07:23:04.131 [IPEngine] WARNING | Not using CurveZMQ security 2026-02-02 07:23:04.148 [IPEngine.0] Registering with controller at tcp://127.0.0.1:60087 2026-02-02 07:23:04.148 [IPEngine.1] Registering with controller at tcp://127.0.0.1:60087 2026-02-02 07:23:04.148 [IPEngine.0] Requesting id: 0 2026-02-02 07:23:04.148 [IPEngine.1] Requesting id: 1 2026-02-02 07:23:04.150 [IPEngine.1.1] Shell_addrs: ['tcp://127.0.0.1:49713', 'tcp://127.0.0.1:48049', 'tcp://127.0.0.1:48829'] 2026-02-02 07:23:04.150 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:49713 2026-02-02 07:23:04.150 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:48049 2026-02-02 07:23:04.150 [IPEngine.1.1] Connecting shell to tcp://127.0.0.1:48829 2026-02-02 07:23:04.151 [IPEngine.1.1] Starting nanny 2026-02-02 07:23:04.152 [IPEngine.0.0] Shell_addrs: ['tcp://127.0.0.1:49713', 'tcp://127.0.0.1:48049', 'tcp://127.0.0.1:57903'] 2026-02-02 07:23:04.152 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:49713 2026-02-02 07:23:04.152 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:48049 2026-02-02 07:23:04.152 [IPEngine.0.0] Connecting shell to tcp://127.0.0.1:57903 2026-02-02 07:23:04.152 [IPEngine.0.0] Starting nanny 2026-02-02 07:23:04.562 [KernelNanny.0] Starting kernel nanny for engine 0, pid=3163, nanny pid=3176 2026-02-02 07:23:04.563 [KernelNanny.0] Nanny watching parent pid 3163. 2026-02-02 07:23:04.563 [KernelNanny.1] Starting kernel nanny for engine 1, pid=3164, nanny pid=3175 2026-02-02 07:23:04.563 [KernelNanny.1] Nanny watching parent pid 3164. 2026-02-02 07:23:04.627 [IPEngine.0.0] Loading IPython extension: storemagic 2026-02-02 07:23:04.628 [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-02-02 07:23:04.628 [IPEngine.1.1] Loading IPython extension: storemagic 2026-02-02 07:23:04.628 [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-02-02 07:23:04.629 [IPEngine.0.0] WARNING | debugpy_stream undefined, debugging will not be enabled 2026-02-02 07:23:04.630 [IPEngine.1.1] WARNING | debugpy_stream undefined, debugging will not be enabled 2026-02-02 07:23:04.636 [IPEngine.0.0] Starting to monitor the heartbeat signal from the hub every 3500 ms. 2026-02-02 07:23:04.636 [IPEngine.0.0] Completed registration with id 0 2026-02-02 07:23:04.636 [IPEngine.1.1] Starting to monitor the heartbeat signal from the hub every 3500 ms. 2026-02-02 07:23:04.636 [IPEngine.1.1] Completed registration with id 1 2026-02-02 07:23:09.402 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_1 2026-02-02 07:23:09.402 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_2 2026-02-02 07:23:09.753 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_3 2026-02-02 07:23:09.753 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_4 2026-02-02 07:23:10.743 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_5 2026-02-02 07:23:10.743 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_6 2026-02-02 07:23:10.754 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_7 2026-02-02 07:23:10.754 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_8 2026-02-02 07:23:10.766 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_9 2026-02-02 07:23:10.766 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_10 2026-02-02 07:23:11.061 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_11 2026-02-02 07:23:11.062 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_12 2026-02-02 07:23:11.071 [IPEngine.0.0] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_13 2026-02-02 07:23:11.072 [IPEngine.1.1] Handling execute_request: 2c41fb81-6e0547f3e7899db0498c0666_3111_14 2026-02-02 07:23:11.845 [KernelNanny.1] Pipe closed, parent 3164 has status: zombie 2026-02-02 07:23:11.845 [KernelNanny.1] Parent 3164 exited with status None. 2026-02-02 07:23:11.845 [KernelNanny.1] Notifying Hub that our parent has shut down 2026-02-02 07:23:11.853 [KernelNanny.0] Pipe closed, parent 3163 has status: zombie 2026-02-02 07:23:11.853 [KernelNanny.0] Parent 3163 exited with status None. 2026-02-02 07:23:11.853 [KernelNanny.0] Notifying Hub that our parent has shut down
engine set stopped 1770016983: {'exit_code': 1, 'pid': 3158, 'identifier': 'ipengine-1770016982-7o9s-1770016983-3111'}