# Transient elasticity problem: sequential vs parallel

**URL:** <https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186>\
**Category:** General Discussion\
**Created:** [September 1, 2021, 10:59am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186 "2021-09-01T10:59:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 1, 2021, 10:59am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/1 "2021-09-01T10:59:40Z")

</div>

Hello,

I am trying to solve the transient elasticity equation using the New-Mark Beta algorithm. The code is able to yield correct results when I run it on a single proc, however when switching to parallel the results become weird. I did not have any issue with the static problem both is sequential and parallel. For info I use the scotch library to decompose the domain and the simple mpi method (no libraries involved such as ffddm and hpddm).

---

<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:** [September 1, 2021, 11:11am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/2 "2021-09-01T11:11:26Z")

</div>

Why not use PETSc? You can simply use the same script, and just switch between `matrix` and `Mat`. You can put the sequential script here if you want.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 1, 2021, 11:48am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/3 "2021-09-01T11:48:36Z")

</div>

Hello,

Thanks for your reply. I have not looked into PETSc yet. The code is attached below, when running it on 1 proc the results are correct however when I run it in parallel I get weird results[NM\_seq&par.edp](https://community.freefem.org/uploads/short-url/u0D4Yk23HdpaH83bg6E7pXjR2Xf.edp) (7.0 KB)

---

<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:** [September 1, 2021, 6:17pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/4 "2021-09-01T18:17:45Z")

</div>

Actually, you can just save into a file each vector and see where it starts diverging between the sequential and the parallel code.  
My guess is that you don’t enforce properly the boundary conditions, because you compute sum of vectors, but never enforce the Dirichlet conditions. You see this error only appear in parallel because it’s more sensitive to round-off errors.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 1, 2021, 7:24pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/5 "2021-09-01T19:24:22Z")

</div>

I see, this is weird but the results that I am getting let’s say the displacement vector has its entries multiplied by the number of procs. I didn’t encounter this type of problem in the static problem, do you have any idea where should I look? Thank you again

---

<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:** [September 2, 2021, 7:30am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/6 "2021-09-02T07:30:57Z")

</div>

Where do you see that the displacement vector is being multiplied in the first place (which line)?

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 2, 2021, 7:43am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/7 "2021-09-02T07:43:04Z")

</div>

starting from line 177 ( dummy5) all these vectors have their entries multiplied by the nb of procs

---

<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:** [September 2, 2021, 7:56am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/8 "2021-09-02T07:56:46Z")

</div>

Have you checked whether Dirichlet boundary conditions are properly enforced or not?

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 2, 2021, 10:17am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/9 "2021-09-02T10:17:58Z")

</div>

boundary conditions are enforced on lines 86 92 96 then I compute the opposite of the linear form by multiplying by -1 on line 125. There is also a fixed boundary that I enforce when defining the stiffness matrix on line 65

---

<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:** [September 2, 2021, 11:59am UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/10 "2021-09-02T11:59:15Z")

</div>

Right, but during the time-stepping, the condition may not be enforced properly since you sum vectors.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 2, 2021, 3:36pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/11 "2021-09-02T15:36:20Z")

</div>

I think I found the problem, on line 161 I integrate the force on a 2d surface using int2d. Apparently that’s what is causing the problem, because when I switch to int3d and run the code on a single vs multi proc I get the same correct result however I want to apply the force on a specific surface. Honestly I did not quite understand why this error happens.

---

<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:** [September 2, 2021, 3:43pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/12 "2021-09-02T15:43:37Z")

</div>

Good catch, just remove `mpirank` from the integral and I think you should be good to go.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 3, 2021, 12:20pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/13 "2021-09-03T12:20:15Z")

</div>

removing mpirank from this line would yield wrong results. I tried removing mpirank from all integrals, it worked but there would be no difference between running the code in sequential or parallel (same execution time)

---

<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:** [September 3, 2021, 12:42pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/14 "2021-09-03T12:42:32Z")

</div>

Ah, correct, because of `master = -1`. Sorry, I don’t like this interface and don’t use it anymore, so it’s hard for me to help you out. I’d encourage you to switch to PETSc, where you don’t need all those `mpirank` in the integrals. It would definitely be easier for me to figure things out.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 3, 2021, 12:47pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/15 "2021-09-03T12:47:59Z")

</div>

I started converting the code to PETSc, how can I define the the same matrices on lines 86, 92 and 96? is it set(K, sparams = " -ksp\_type gmres -ksp\_max\_it 200 "); what about the others.  
Thank you again for your input

---

<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:** [September 3, 2021, 12:50pm UTC](https://community.freefem.org/t/transient-elasticity-problem-sequential-vs-parallel/1186/16 "2021-09-03T12:50:33Z")

</div>

If you’ve never used PETSc in FreeFEM, please have a look at the following tutorial [Pierre Jolivet introduction to parallel FreeFEM part 1 - YouTube](https://www.youtube.com/watch?v=-Aw2O46V2bo). You’ll see that very little adjustments are needed to your original sequential script (without all the `mpirank` mess in the integrals).
