# Broadcast fespace in MPI

**URL:** https://community.freefem.org/t/broadcast-fespace-in-mpi/1041
**Category:** General Discussion
**Created:** [June 16, 2021, 12:15pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041 "2021-06-16T12:15:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adrienrvr](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@adrienrvr](https://community.freefem.org/u/adrienrvr)
#### Post date: [June 16, 2021, 12:15pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/1 "2021-06-16T12:15:02Z")

</div>

Hi everybody,

I would like to be able to broadcast an fespace of the processor(0) to all the other processors. However, the _broadcast_ function does not seem to take fespace into account.

I would like a single processor to calculate the boundary condition on the global mesh (which is a Blasius profile in my case) then broadcast it to everyone.

I would like a single processor to calculate the entry limit condition on the global mesh (which is a Blasius profile in my case) then broadcast it to everyone.

Here is the snippet of my code that calculates the input boundary condition:

```auto
/* Import de la solution de l'equation de Blasius 2f'''+ff''=0' */
    int mbl, nbl;
    ifstream Input(".../Profil_Blasius_RK4.txt");
        Input >> mbl >> nbl; // Nbr lignes & Nbr colonnes
        real[int,int] fblasius(mbl,nbl);
        for(int i=0; i<mbl; i++){
            for(int j=0; j<nbl; j++){
                Input >> fblasius(i,j); // Tableau [eta f f' f"]
            }
        }
    real etamax = fblasius(mbl-1,0); // Eta max (derniere entree du tableau)

/* Interpolation du profil de similitude */
    int nbs = fblasius.n-1;
    mesh Thb = square(1,nbs/2,[x,y*etamax]);
    fespace Vhb(Thb,P2);
    Vhb fbx, fby, xx = x, yy = y*(nbs)/etamax;
    for(int i=0; i< fbx[].n; ++i){
        int k = yy[][i];
        if(xx[][i] < 0.1)
            fbx[][i] = fblasius(k,2); // u/Uinf = f'(eta)
            fby[][i] = (fblasius(k,0)*fblasius(k,2))-fblasius(k,1); // v/sqrt(nu*Uinf/2x) = eta*f'(eta)-f(eta)
    }
    fbx = fbx(0,y)*Uinf;
    fby = fby(0,y)*sqrt(nu*Uinf/(2*xentree));

/* Adaptation du profil au maillage pour le bon delta1 */
    fespace Uhglobal(Thglobal, Pu);
    Uhglobal Ublasius, Vblasius;
    Ublasius = fbx(x,y/delta1*1.7208);
    Vblasius = fby(x,y/delta1*1.7208);

/* CL d'entree */
    func uIn = Ublasius(0,y); // Condition limite d'entree selon x
    func vIn = Vblasius(0,y); // Condition limite d'entree selon y

```

Thanks !

---

<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: [June 16, 2021, 1:13pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/2 "2021-06-16T13:13:51Z")

</div>

It doesn’t make sense to broadcast a `fespace`, just broadcast the underlying `mesh`, or broadcast whatever your compute on it, e.g., matrix or function.

---

<div class="post-metadata">

### Author: ![adrienrvr](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@adrienrvr](https://community.freefem.org/u/adrienrvr)
#### Post date: [June 16, 2021, 2:30pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/3 "2021-06-16T14:30:56Z")

</div>

But a function can’t be broadcast either, can it?

I would like to be able to broadcast either the `uIn` function or the `Ublasius` field because I noticed that when I calculate the boundary condition with several processors, it is not well calculated.

---

<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: [June 16, 2021, 2:34pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/4 "2021-06-16T14:34:24Z")

</div>

Sure, you can broadcast `Ublasius[]` no problem (or any _vector_ for that matter). What do you mean by “not well calculated”?

---

<div class="post-metadata">

### Author: ![adrienrvr](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@adrienrvr](https://community.freefem.org/u/adrienrvr)
#### Post date: [June 16, 2021, 2:55pm UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/5 "2021-06-16T14:55:14Z")

</div>

I don’t quite understand where the error came from. I have put below images of my velocity fields. The first shows the boundary layer calculated with 1 single processor (same result as in sequential) and the 2nd image shows the same field calculated with 50 processors. The calculation of the input boundary condition is done by the code I published in my first post above.

 ![Ux_1proc](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/892caf981fec4b8540fd4488295a67d64783d535.png)  
 ![Ux_50procs](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/fc67f3bf1760701ed431b58f41c5596ee34006ae.png)

---

<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: [June 17, 2021, 8:04am UTC](https://community.freefem.org/t/broadcast-fespace-in-mpi/1041/6 "2021-06-17T08:04:13Z")

</div>

> The calculation of the input boundary condition is done by the code I published in my first post above.

No, I don’t see any parallelism in the above snippet, so I guess that’s not how you compute it with 50 processes (unless you compute it redundantly, in which case it means one of the input data is not synchronized among processes).
