# Evaluating an integral when using parallel computing

**URL:** <https://fenicsproject.discourse.group/t/evaluating-an-integral-when-using-parallel-computing/10072>\
**Category:** dolfinx\
**Created:** [January 1, 2023, 8:21pm UTC](https://fenicsproject.discourse.group/t/evaluating-an-integral-when-using-parallel-computing/10072 "2023-01-01T20:21:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![femur](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/femur/32/4558_2.png) [@femur](https://fenicsproject.discourse.group/u/femur)\
**Post date:** [January 1, 2023, 8:21pm UTC](https://fenicsproject.discourse.group/t/evaluating-an-integral-when-using-parallel-computing/10072/1 "2023-01-01T20:21:14Z")

</div>

After solving the variational problem a(u,v) = L(v), I want to evaluate the integral of the quantity u over the domain \Omega, i.e. I want to calculate \alpha(u) = \int\_\Omega u \,dx.  
Because my problem is quite large, I use:

```auto
mpirun -n 4 python3 test.py

```

Then I calculate the integral via:

```auto
alpha = dolfinx.fem.assemble_scalar(dolfinx.fem.form(uh*ufl.dx))
print(alpha)

```

The problem is that this is evaluated for each processor separately, so the result is not correct. I tried:

```auto
if mpi4py.MPI.COMM_WORLD.rank == 0:
   alpha = dolfinx.fem.assemble_scalar(dolfinx.fem.form(uh*ufl.dx))
   print(alpha)

```

This creates a sort of infinite loop, the computation never ends.

Any idea how to compute the integral correctly?

---

<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:** [January 2, 2023, 7:48am UTC](https://fenicsproject.discourse.group/t/evaluating-an-integral-when-using-parallel-computing/10072/2 "2023-01-02T07:48:36Z")

</div>

See for instance: [Implementation — FEniCSx tutorial](https://jsdokken.com/dolfinx-tutorial/chapter1/fundamentals_code.html?highlight=mpi%20sum#computing-the-error)
