# MPI demo in dolfinx

**URL:** <https://fenicsproject.discourse.group/t/mpi-demo-in-dolfinx/10623>\
**Category:** Uncategorized\
**Created:** [March 7, 2023, 10:59pm UTC](https://fenicsproject.discourse.group/t/mpi-demo-in-dolfinx/10623 "2023-03-07T22:59:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruyue\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/ruyue_fang/32/4745_2.png) [@Ruyue\_Fang](https://fenicsproject.discourse.group/u/Ruyue_Fang)\
**Post date:** [March 7, 2023, 10:59pm UTC](https://fenicsproject.discourse.group/t/mpi-demo-in-dolfinx/10623/1 "2023-03-07T22:59:32Z")

</div>

Hello there,

I’m new to dolfinx and trying to reproduce the tutorial ([DOLFINx in Parallel with MPI — NewFrac FEniCSx Training](https://newfrac.gitlab.io/newfrac-fenicsx-training/05-dolfinx-parallel/dolfinx-parallel.html)) in the latest version, but cannot get through the example 04-mpi-dolfinx.py.

I couldn’t find the alternative of “mesh.topology.create\_connectivity\_all()” so I deleted this line. When I run

```auto
mpirun -n 2 python3 04-mpi-dolfinx.py

```

I have the results

```auto
Rank 0: Number of local cells: 2
Rank 0: Number of global cells: 2
Rank 0: Number of local vertices: 4
Rank 0: Cell (dim = 2) to vertex (dim = 0) connectivity
Rank 0: <AdjacencyList> with 2 nodes
  0: [0 1 2]
  1: [0 3 2]

Rank 1: Number of local cells: 0
Rank 1: Number of global cells: 2
Rank 1: Number of local vertices: 0
Rank 1: Cell (dim = 2) to vertex (dim = 0) connectivity
Rank 1: <AdjacencyList> with 0 nodes

```

which is different from the tutorial where two nodes assemble the mesh cooperatively.  
Here is my code (just minimal changes from the tutorial).

```auto
from mpi4py import MPI
import dolfinx
import dolfinx.io

comm = MPI.COMM_WORLD

def mpi_print(s):
    print(f"Rank {comm.rank}: {s}")

mesh = dolfinx.mesh.create_unit_square(comm=comm, nx=1, ny=1, ghost_mode=dolfinx.mesh.GhostMode.none, diagonal=dolfinx.mesh.DiagonalType.right)
#mesh.topology.create_connectivity_all()

mpi_print(f"Number of local cells: {mesh.topology.index_map(2).size_local}")
mpi_print(f"Number of global cells: {mesh.topology.index_map(2).size_global}")
mpi_print(f"Number of local vertices: {mesh.topology.index_map(0).size_local}")
mpi_print("Cell (dim = 2) to vertex (dim = 0) connectivity")
mpi_print(mesh.topology.connectivity(2, 0))

```

Could you help me out? Thanks!

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 8, 2023, 11:42am UTC](https://fenicsproject.discourse.group/t/mpi-demo-in-dolfinx/10623/2 "2023-03-08T11:42:58Z")

</div>

I cannot reproduce this locally.  
I get:

```python
Rank 0: Number of local cells: 1
Rank 0: Number of global cells: 2
Rank 0: Number of local vertices: 2
Rank 0: Cell (dim = 2) to vertex (dim = 0) connectivity
Rank 0: <AdjacencyList> with 1 nodes
  0: [2 0 1]

Rank 1: Number of local cells: 1
Rank 1: Number of global cells: 2
Rank 1: Number of local vertices: 2
Rank 1: Cell (dim = 2) to vertex (dim = 0) connectivity
Rank 1: <AdjacencyList> with 1 nodes
  0: [0 1 2]

```

How did you install DOLFINx?

What happens if you use a bigger mesh (say 5x5)?

---

<div class="post-metadata">

**Author:** ![Ruyue\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/ruyue_fang/32/4745_2.png) [@Ruyue\_Fang](https://fenicsproject.discourse.group/u/Ruyue_Fang)\
**Post date:** [March 9, 2023, 6:25am UTC](https://fenicsproject.discourse.group/t/mpi-demo-in-dolfinx/10623/3 "2023-03-09T06:25:07Z")

</div>

Hi dokken, thanks for your reply. I installed DOLFINx by conda following [GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment](https://github.com/FEniCS/dolfinx). If I use a 5x5 mesh, it works fine! Rank 0 and 1 have 25 local cells each.
