# Attempt to find max value on mesh in parallel

**URL:** <https://fenicsproject.discourse.group/t/attempt-to-find-max-value-on-mesh-in-parallel/4314>\
**Category:** Uncategorized\
**Created:** [October 13, 2020, 12:09pm UTC](https://fenicsproject.discourse.group/t/attempt-to-find-max-value-on-mesh-in-parallel/4314 "2020-10-13T12:09:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 13, 2020, 12:35pm UTC](https://fenicsproject.discourse.group/t/attempt-to-find-max-value-on-mesh-in-parallel/4314/2 "2020-10-13T12:35:01Z")

</div>

Dear @CoE2845,  
Next time, please encapsulate your code with 3x` to ensure proper formatting.  
You simply need to use MPI communicators for the problem at hand:

```auto
from dolfin import *
from mpi4py import MPI
mesh = UnitSquareMesh(10,10)
Space = FunctionSpace(mesh, "CG", 1)
T = project(Expression("10*x[0]+100*x[1]", degree=2), Space)
max_T = max(T.vector())

print("T_max is : {0:.2e} on Proc {1:d}".format(max_T, MPI.COMM_WORLD.rank))
MPI.COMM_WORLD.barrier()
max_T = mesh.mpi_comm().allreduce(max_T, op=MPI.MAX)
if MPI.COMM_WORLD.rank ==0:
    with open("test.txt", "w") as f:
        f.write(str(max_T))
    print("Global max is {0:.2e} on Proc {1:d}".format(max_T, MPI.COMM_WORLD.rank))

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/attempt-to-find-max-value-on-mesh-in-parallel/4314)._
