Issue with MPI and UnitSquareMesh in python

Hello,

I try to use using FEniCS in an MPI environment. the following code gives me errors:

import dolfin as dl
from mpi4py import MPI

mesh = dl.UnitSquareMesh(MPI.COMM_SELF, 127,  127)

and the error is

  File "/zhome/93/8/155259/Paper-PAT-RTO/applications/pat_2D/MAP_estimate.py", line 38, in run_MAP
    mesh = dl.UnitSquareMesh(MPI.COMM_SELF, N_points, N_points)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. dolfin.cpp.generation.UnitSquareMesh(nx: int, ny: int, diagonal: str = 'right')
    2. dolfin.cpp.generation.UnitSquareMesh(comm: dolfin.cpp.MPICommWrapper, nx: int, ny: int, diagonal: str = 'right')

I don’t know how to wrap the MPI communicator into a FEniCS format? Any ideas?

In legacy DOLFIN, you should use

dolfin.MPI.comm_self

rather than a mpi4py-communicator directly.

1 Like

Thank you! Solved the issue