# Computing numerical solution with parallel version

**URL:** https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567
**Category:** General Discussion
**Created:** [March 2, 2022, 1:16pm UTC](https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567 "2022-03-02T13:16:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)
#### Post date: [March 2, 2022, 1:16pm UTC](https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567/1 "2022-03-02T13:16:18Z")

</div>

Trying to write a parallel version, in fact, is it wrong?

> load “PETSc-complex” // PETSc plugin  
> macro dimension()2// EOM // 2D or 3D  
> include “macro\_ddm.idp”  
> real omega=1,lambda=0.5;//  
> real Tf=0.5;  
> real t0=0;  
> int m1=4,n1=4;  
> mesh Th=square(m1,n1,[x,y]);  
> fespace Xhf(Th,P2);  
> real dt=Tf/b(mm-1);  
> Xhf psai2,u,F,F1,F2;  
> Xhf psai0=(exp(-2_x^2-2_y^2))_(x+1i_y)/(x^2+y^2+1);  
> Xhf psait0=1i_psai0;  
> Xhfpsai1=psai0+dt_psait0；  
> real m=abs(psai1);  
> varf va(psai2, u)= int2d(Th)(2_psai1_u/(dt^2))  
> +int2d(Th)(0.5_dx(psai2)dx(u)+0.5dy(psai2)dy(u))  
> +int2d(Th)(0.5psai2_u)+on(1,2,3,4,psai2=0);  
> varf rhs(psai1,u)=int2d(Th)(2_psai1_u/(dt^2));  
> varf rhs1(psai0,u)=-int2d(Th)(psai0_u/(dt^2))  
> -int2d(Th)(0.5_dx(psai0)_dx(u)+0.5_dy(psai0)_dy(u))；  
> Mat A;  
> createMat(Th, A, P2); //  
> A = va(Xhf, Xhf);  
> Mat B;  
> createMat(Th, B, P2); //  
> B = rhs1(Xhf, Xhf);  
> Mat C;  
> createMat(Th, C, P2); //  
> C= rhs(Xhf, Xhf);  
> for ( real t=0+2_dt; t\<=Tf ; t+=dt)  
> {  
> F1= B \* psai0;  
> F2=C \* psai1;  
> F=F1+F2;  
> set(A, sparams ="-pc\_factor\_mat\_solver\_type mumps ");  
> psai2=A^-1 \* F;  
> psai0=psai1;  
> psai1=psai2;  
> }

---

<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: [March 2, 2022, 1:30pm UTC](https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567/2 "2022-03-02T13:30:30Z")

</div>

We cannot copy/paste your code. Try it and you’ll see it does not run.

---

<div class="post-metadata">

### Author: ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)
#### Post date: [March 3, 2022, 10:54am UTC](https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567/4 "2022-03-03T10:54:41Z")

</div>

Sorry, I uploaded the wrong code yesterday. This is the original code. It is a small program for calculating the convergence order of time written by

> load “PETSc- complex”

, but it is different from the result I wrote by

> load “mumps\_mpi”

. Am I thinking because the former is wrong?  
[example.edp](https://community.freefem.org/uploads/short-url/aI73dGBZB1Po69mPtVNnenn9ijy.edp) (2.2 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: [March 4, 2022, 6:09am UTC](https://community.freefem.org/t/computing-numerical-solution-with-parallel-version/1567/5 "2022-03-04T06:09:42Z")

</div>

Start with something simple, e.g., Poisson equation, instead of going directly for your full model. It’s near impossible to debug otherwise (at least I can’t help you).
