# Instances of SubMesh and MeshView do not inherit the communicator of the original mesh

**URL:** <https://fenicsproject.discourse.group/t/instances-of-submesh-and-meshview-do-not-inherit-the-communicator-of-the-original-mesh/3602>\
**Category:** mesh\
**Created:** [June 21, 2020, 8:11pm UTC](https://fenicsproject.discourse.group/t/instances-of-submesh-and-meshview-do-not-inherit-the-communicator-of-the-original-mesh/3602 "2020-06-21T20:11:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukoshkin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lukoshkin/32/592_2.png) [@lukoshkin](https://fenicsproject.discourse.group/u/lukoshkin)\
**Post date:** [June 21, 2020, 8:11pm UTC](https://fenicsproject.discourse.group/t/instances-of-submesh-and-meshview-do-not-inherit-the-communicator-of-the-original-mesh/3602/1 "2020-06-21T20:11:18Z")

</div>

Hi, I use dolfin’s version 2019.2.0.dev0  
My MWE is:

```python
# aa.py
import numpy as np

from dolfin import *

comm = MPI.comm_world
rank = comm.Get_rank()

mesh = UnitSquareMesh(MPI.comm_self, 12, 12)
V = FunctionSpace(mesh, 'P', 1)

tol = 1e-8
subd = AutoSubDomain(lambda x: x[0] <= .5+tol)
markers = MeshFunction('size_t', mesh, 2, 0)
subd.mark(markers, 1)

subm1 = SubMesh(mesh, subd)
subm2 = MeshView.create(markers, 1)
subm3 = UnitSquareMesh(MPI.comm_self, 6, 12)

subV1 = FunctionSpace(subm1, 'P', 1)
subV2 = FunctionSpace(subm2, 'P', 1)
subV3 = FunctionSpace(subm3, 'P', 1)

mask1 = subm1.data().array("parent_vertex_indices", 0)
mask2 = subm2.topology().mapping()[mesh.id()].vertex_map()

k1 = Function(subV1)
k2 = Function(subV2)
k3 = Function(subV3)

try:
    k1.vector()[:] = np.random.rand(len(mask1))
except:
    if rank == 0: print('submesh error')
try:
    k2.vector()[:] = np.random.rand(len(mask2))
except:
    if rank == 0: print('meshview error')
try:
    k3.vector()[:] = np.random.rand(len(mask1))
except:
    if rank == 0: print('meshchunk error')

```

If I run it in parallel with `mpirun -n 4 python3 aa.py`, I will get the output:

```cpp
submesh error
meshview error

```

That is, only the last one out of 3 assignment operations does not raise an error: the error of a size mismatch - left-hand side and right-hand side arrays. (_ **The thing is, that some parts of the original mesh are distributed among processes** _). But if the code snippets with `SubMesh` and `MeshView` do meaningfully the same things, the last approach (a.k.a. “meshchunk” as I called it) is different. To make it similar to its two counterparts I could save the instance of `SubMesh` or `MeshView` to a file and then recreate it via via setting an appropriate communicator in `Mesh` class and reading the mesh from the file. However, I find this ‘workaround’ unreliable. Thus, I’d like to know if I am mistaken and there is a way to do it right (to resolve the issue I marked in bold italic)? Or it is a bug and it was fixed in some other versions?
