# Integral in parallel

**URL:** https://community.freefem.org/t/integral-in-parallel/1649
**Category:** General Discussion
**Created:** [April 6, 2022, 11:21am UTC](https://community.freefem.org/t/integral-in-parallel/1649 "2022-04-06T11:21:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)
#### Post date: [April 6, 2022, 11:21am UTC](https://community.freefem.org/t/integral-in-parallel/1649/1 "2022-04-06T11:21:37Z")

</div>

Hello,

When computing an integral in parallel, I know one needs to scale things and do a global reduction. There are examples in previous posts (for example [here](https://community.freefem.org/t/slepc-complex-eigenmodes/913)) with the integral of 2 vectors, say:

```auto
Vh<complex> scaledVecu = Vecu;
for[i, v : A.D] scaledVecu[] *= v;
complex wrong = int2d(Th)(scaledVecu*AnotherVec);
complex reduce;
mpiAllReduce(wrong, reduce, mpiCommWorld, mpiSUM);
if(mpirank == 0)
        cout << reduce << endl;

```

My question is: if there are more than 2 vectors in the integral, should the rescaling still apply to only one of them?

Thank you.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 7, 2022, 6:30am UTC](https://community.freefem.org/t/integral-in-parallel/1649/2 "2022-04-07T06:30:58Z")

</div>

This is in fact independent of the number of components. Keep in mind that in FreeFEM, whenever you do `u[]`, it selects _all_ degrees of freedom. So whether `u` is a function defined on a `fespace Vh(Th, [Pk, Qk, Tk, Zk, Wk])` or `fespace Vh(Th, Pk)`, the syntax from your snippet will indeed scale all values of `scaledVecu` (proper things to do).

---

<div class="post-metadata">

### Author: ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)
#### Post date: [April 7, 2022, 6:53am UTC](https://community.freefem.org/t/integral-in-parallel/1649/3 "2022-04-07T06:53:55Z")

</div>

Thank you for your reply. Sorry, my question was not clear: I was not talking of the number of components (for instance `[ux]` vs `[ux,uy]` vs `[ux,uy,uz]` etc.), but the number of terms that are multiplied in the integrand: `int2d(Th)(u*v)` vs `int2d(Th)(u*v*w)`.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [April 7, 2022, 7:07am UTC](https://community.freefem.org/t/integral-in-parallel/1649/4 "2022-04-07T07:07:34Z")

</div>

I see. Only one of the term has to be scaled.

---

<div class="post-metadata">

### Author: ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)
#### Post date: [April 7, 2022, 7:26am UTC](https://community.freefem.org/t/integral-in-parallel/1649/5 "2022-04-07T07:26:53Z")

</div>

Great. Thank you very much.
