# My computer keeps freezing when running FreeFEM

**URL:** <https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648>\
**Category:** FreeFEM installation\
**Created:** [November 11, 2020, 2:47am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648 "2020-11-11T02:47:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 11, 2020, 2:47am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/1 "2020-11-11T02:47:44Z")

</div>

Hello,

Whenever I run more intensive code my computer freezes. I am trying to solve an eigebvalue problem on geometry, and need to get to like 1000 eigenvalues with a couple hundred nodes on each side, so I expect it to take some time. When I run it with less accuracy or fewer eigenvales it’s goes through fine, but currently whenever it hits the couple hour mark everything just locks up.

Currently I edit code in the online compiler and the. Download the .edp file to run it locallly. Does anyone have any suggestions as to what is going on? I can also post code if that will help.

I have a pretty decent pc (16gb of RAM for example) and am not doing anything else. This could be machine side but it’s so consistent in how if fails I feel like something else is up.

Thank you for the help

---

<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:** [November 11, 2020, 7:44am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/2 "2020-11-11T07:44:58Z")

</div>

Do you use parallel computing?

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 11, 2020, 10:33pm UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/3 "2020-11-11T22:33:12Z")

</div>

I don’t think so. How would I tell

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 11, 2020, 10:33pm UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/4 "2020-11-11T22:33:25Z")

</div>

Thank you for the response as well

---

<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:** [November 12, 2020, 6:26am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/5 "2020-11-12T06:26:04Z")

</div>

If you use `FreeFem++-mpi` instead of `FreeFem++`, you do parallel computing.  
The cost of the operations in an eigensolve increase nonlinearly. So it can be highly beneficial to use `FreeFem++-mpi` + `EPSSolve` (parallel eigensolver from SLEPc), instead of `FreeFem++` and `EigenValue`.  
If you share a minimalist script I can show you how easy it is to go parallel.

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 12, 2020, 8:48am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/6 "2020-11-12T08:48:22Z")

</div>

```auto
// Parameters
real sigma = 1; //value of the shift (ignore)
real a = 1./sqrt(3); //length of bottom side
string lengthName = "306090";
int n = 25; //numer of mesh points on each side
int nev = 1; //number of computed eigen values

// Mesh
border a0(t=0., .5){x=0; y=1.-t;} //top half of left side
border a1(t=0., .5){x=0; y=.5-t;} //bottom half of left side
border a2(t=0., .5){x=a*(1.-t); y=t;} //bottom half of hypotenuse
border a3(t=0., .5){x= a*(.5-t); y=.5+t;}//top half of hypotenuse
border a4(t=0., .5){x=a*t; y=0.;} //left half of bottom side
border a5(t=0., .5){x=a*(.5+t); y=0.;} //right half of bottom side

//Freefem stuff. Builds mesh and declares function space. Stuff in this section from example.
mesh Th = buildmesh(a0(n) + a1(n) + a2(n)+ a3(n)+ a4(n)+ a5(n));
fespace Vh(Th, P2);
Vh u1, u2;

// Problem
// OP = A - sigma B ; // the shifted matrix
varf op (u1, u2)
	= int2d(Th)(
    dx(u1)*dx(u2)
	+ dy(u1)*dy(u2)
	- sigma* u1*u2
   )
+ on(a0,a1,a2,a3,a4,a5, u1=0)
;

varf b ([u1], [u2]) = int2d(Th)(u1*u2); //no boundary condition

matrix OP = op(Vh, Vh, solver=Crout, factorize=1); //crout solver because the matrix in not positive
 matrix B = b(Vh, Vh, solver=CG, eps=1e-20);

// important remark:
// the boundary condition is make with exact penalization:
// we put 1e30=tgv on the diagonal term of the lock degree of freedom.
// So take Dirichlet boundary condition just on $a$ variational form
// and not on $b$ variational form.
// because we solve $ w=OP^-1*B*v $

// Solve
real[int] ev(nev); //to store the nev eigenvalue

Vh[int] eV(nev); //to store the nev eigenvector

int k = EigenValue(OP, B, sym=true, sigma=sigma, value=ev, vector=eV,
	tol=1e-10, maxit=0, ncv=0);

// Display & Plot
for (int i = 0; i < k; i++){
	u1 = eV[i];

    real gg = int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1));
    real mm = int2d(Th)(u1*u1) ;
	cout << "lambda[" << i << "] = " << ev[i] << ", err= " << int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1) - (ev[i])*u1*u1) << endl;
	plot(eV[i], cmm="Eigen Vector "+i+" value ="+ev[i], wait=true, value=true);
}

```

---

<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:** [November 12, 2020, 8:53am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/7 "2020-11-12T08:53:36Z")

</div>

Please put your _whole_ code between brackets otherwise I can’t copy/paste it. It should look like this:

```auto
some FreeFEM script easily copy/paste-able;

```

Also, you may want to switch from `Crout` to `sparsesolver` in your definition of A.

---

<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:** [November 12, 2020, 9:17am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/10 "2020-11-12T09:17:00Z")

</div>

1. still not copy/paste-able, I meant to say three single quotes ``` ` `, not bracket {
2. please just edit your post instead of adding a new one to the thread
3. once you think you are done, please double check by copy/paste-ing what you have on your browser and make sure that it runs on your machine, then it mean it will run on mine as well! 😄

Edit: I can see you are using the wrong symbol: ’ instead of `

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 12, 2020, 9:21am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/11 "2020-11-12T09:21:19Z")

</div>

Yep it runs on my machine. I usually crank up n and number of evalues and have a bunch of compuations, but it should put out a graph of an eigenfunction on the triangle

There it is lmao

---

<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:** [November 12, 2020, 9:40am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/12 "2020-11-12T09:40:03Z")

</div>

Does the following script run on your machine?  
It should if you have a _complete_ FreeFEM installation, that is FreeFEM + PETSc.  
It is parallel, but first, it’s best to check that it runs using the command:

```auto
FreeFem++-mpi script.edp -v 0 -wg

```

You should get the desired results, for example, here with `n = 100` in the screenshot.

 ![Screenshot 2020-11-12 at 10.38.51 AM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/75771accdfa1e73a753e280e9ddae16f3b0b8e05.png)

```auto
// Parameters
real sigma = 1; //value of the shift (ignore)
real a = 1./sqrt(3); //length of bottom side
string lengthName = "306090";
int n = 25; //numer of mesh points on each side
int nev = 1; //number of computed eigen values

// Mesh
border a0(t=0., .5){x=0; y=1.-t;} //top half of left side
border a1(t=0., .5){x=0; y=.5-t;} //bottom half of left side
border a2(t=0., .5){x=a*(1.-t); y=t;} //bottom half of hypotenuse
border a3(t=0., .5){x= a*(.5-t); y=.5+t;}//top half of hypotenuse
border a4(t=0., .5){x=a*t; y=0.;} //left half of bottom side
border a5(t=0., .5){x=a*(.5+t); y=0.;} //right half of bottom side

//Freefem stuff. Builds mesh and declares function space. Stuff in this section from example.
mesh Th = buildmesh(a0(n) + a1(n) + a2(n)+ a3(n)+ a4(n)+ a5(n));
plot(Th);
func Pk = P2;
fespace Vh(Th, Pk);
Vh u1, u2;

// Problem
// OP = A - sigma B ; // the shifted matrix
varf op (u1, u2)
	= int2d(Th)(
    dx(u1)*dx(u2)
	+ dy(u1)*dy(u2)
   )
+ on(a0,a1,a2,a3,a4,a5, u1=0)
;

varf b ([u1], [u2]) = int2d(Th)(u1*u2)
+ on(a0,a1,a2,a3,a4,a5, u1=0)
; //no boundary condition

load "SLEPc"
Mat OP;
include "macro_ddm.idp"
createMat(Th, OP, Pk)
OP = op(Vh, Vh, tgv = -2,sym=1); //crout solver because the matrix in not positive
 matrix loc = b(Vh, Vh, tgv = -20, sym =1);
Mat B(OP, loc);

// important remark:
// the boundary condition is make with exact penalization:
// we put 1e30=tgv on the diagonal term of the lock degree of freedom.
// So take Dirichlet boundary condition just on $a$ variational form
// and not on $b$ variational form.
// because we solve $ w=OP^-1*B*v $

// Solve
real[int] ev(nev); //to store the nev eigenvalue

Vh[int] eV(nev); //to store the nev eigenvector

int k = EPSSolve(OP, B, values=ev, vectors=eV,sparams = "-st_type sinvert -eps_nev " + nev + " -eps_target " + sigma);

// Display & Plot
for (int i = 0; i < k; i++){
	u1 = eV[i];

    real gg = int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1));
    real mm = int2d(Th)(u1*u1) ;
	cout << "lambda[" << i << "] = " << ev[i] << ", err= " << int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1) - (ev[i])*u1*u1) << endl;
	plot(eV[i], cmm="Eigen Vector "+i+" value ="+ev[i], wait=true, value=true);
}

```

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 12, 2020, 9:44am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/13 "2020-11-12T09:44:41Z")

</div>

I dont think I have the complete installation. Mine just says FreeFem ++ 4.6 \> I also could not get the script to run.

---

<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:** [November 12, 2020, 9:47am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/14 "2020-11-12T09:47:37Z")

</div>

OK, then you’ll have to update or at least make sure you have FreeFEM installed with PETSc (if you use the `.exe` or `.deb` from GitHub it is there by default). Can’t really help you otherwise.  
Maybe just try to replace `Crout` by `sparsesolver`, this may be a small first improvement.

---

<div class="post-metadata">

**Author:** ![dajopez](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dajopez](https://community.freefem.org/u/dajopez)\
**Post date:** [November 12, 2020, 9:49am UTC](https://community.freefem.org/t/my-computer-keeps-freezing-when-running-freefem/648/15 "2020-11-12T09:49:13Z")

</div>

Ok i will go try and update that and see what happens. If after that the the code you gave me didnt work ill ping this thread again.

Thank you so much for the help
