Segfault when plotting FE function

Hello,
I used FreeFem for a while and today when I tried to run a simple script which involved plotting a function, it segfaulted. Here is the code :

int npoints = 100; // Number of points on the circonference of the disk
real radius = sqrt(1/pi); // The radius of the disk of area 1

border circle(t=0,2*pi){
  x = radius*cos(t);
  y = radius*sin(t);
}

mesh Th = buildmesh(circle(npoints));

fespace Vh(Th,P1);
Vh f = x;

plot(f, wait=true);

and the error i get :

 -- FreeFem++ v4.6 (Thu Apr  2 15:47:38 CEST 2020 - git v4.6)
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue 
    1 : int eigCount = 10; // the number of eigenvalues to compute
    2 : int npoints = 100; // Number of points on the circonference of the disk
    3 : real radius = sqrt(1/pi); // The radius of the disk of area 1
    4 : 
    5 : border circle(t=0,2*pi){
    6 :   x = radius*cos(t);
    7 :   y = radius*sin(t);
    8 : }
    9 : 
   10 : mesh Th = buildmesh(circle(npoints));
   11 : 
   12 : fespace Vh(Th,P1);
   13 : Vh uh,vh;
   14 : Vh f = x;
   15 : 
   16 : plot(f, wait=true);
   17 :  sizestack + 1024 =1504  ( 480 )

  --  mesh:  Nb of Triangles =   1766, Nb of Vertices 934
times: compile 0.00399s, execution 0.009392s,  mpirank:0
Segmentation fault (core dumped)
 CodeAlloc : nb ptr  3473,  size :469344 mpirank: 0
Ok: Normal End

I don’t know what would be the cause of it, I hope you will be able to help me. I already tried to uninstall and reinstall freefem with no success.

Best,
Eloi.

I see no errors in the code. Must be a problem with your setup. Did you check that all of the necessary packages are available on your system before installing?

You use a very very old version of FreeFem++

first see if due to the graphic part (ffglut)

launch without graphique (with flag -nw)

  1. reinstall freefem++ (lot of bug are corrected).

Hello,
I have réinstalled FreeFem with version 4.12 and now the previous code works. However, the thing that i want to do still segfault and I don’t know with (it doesn’t happens in nw mode) :

int eigCount = 10; // the number of eigenvalues to compute
int npoints = 100; // Number of points on the circonference of the disk
real radius = sqrt(1/pi); // The radius of the disk of area 1

border circle(t=0,2*pi){
  x = radius*cos(t);
  y = radius*sin(t);
}

mesh Th = buildmesh(circle(npoints));

fespace Vh(Th,P1);
Vh uh,vh;

varf va(uh, vh) = int2d(Th)( dx(uh)*dx(vh)+dy(uh)*dy(vh));
varf vb(uh, vh) = int2d(Th)(uh*vh);

matrix A = va(Vh, Vh ,solver = sparsesolver); // Matrix A on left side
matrix B = vb(Vh, Vh);                        // Matrix B on right side

// Get first Eigenvalues
real[int] ev(eigCount); // Holds Eigenvalues
Vh[int] eV(eigCount);   // Holds Eigenfunctions

int numEigs = EigenValue(A,B,sym=true,sigma=0,value=ev,vector=eV);

plot(eV[1], wait=true);

and the trace in the command-line :

-- FreeFem++ v4.12 (Tue Dec  6 19:14:11 CET 2022 - git v4.12)
   file : neumann_disk.edp
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue 
    1 : int eigCount = 10; // the number of eigenvalues to compute
    2 : int npoints = 100; // Number of points on the circonference of the disk
    3 : real radius = sqrt(1/pi); // The radius of the disk of area 1
    4 : 
    5 : border circle(t=0,2*pi){
    6 :   x = radius*cos(t);
    7 :   y = radius*sin(t);
    8 : }
    9 : 
   10 : mesh Th = buildmesh(circle(npoints));
   11 : 
   12 : fespace Vh(Th,P1);
   13 : Vh uh,vh;
   14 : 
   15 : varf va(uh, vh) = int2d(Th)( dx(uh)*dx(vh)+dy(uh)*dy(vh));
   16 : varf vb(uh, vh) = int2d(Th)(uh*vh);
   17 : 
   18 : matrix A = va(Vh, Vh ,solver = sparsesolver); // Matrix A on left side
   19 : matrix B = vb(Vh, Vh);                        // Matrix B on right side
   20 : 
   21 : // Get first Eigenvalues
   22 : real[int] ev(eigCount); // Holds Eigenvalues
   23 : Vh[int] eV(eigCount);   // Holds Eigenfunctions
   24 : 
   25 : int numEigs = EigenValue(A,B,sym=true,sigma=0,value=ev,vector=eV);
   26 : 
   27 : plot(eV[1], wait=true);
   28 :  sizestack + 1024 =1688  ( 664 )

  --  mesh:  Nb of Triangles =   1766, Nb of Vertices 934
Real symmetric eigenvalue problem: A*x - B*x*lambda
times: compile 0.016681s, execution 0.038446s,  mpirank:0
Segmentation fault (core dumped)
 CodeAlloc : nb ptr  3791,  size :506664 mpirank: 0
Ok: Normal End

I really don’t understand what is goind on.

Thank you for your help !
Best,
Eloi.

P.S.: in the installation guide Installation guide, the page given for the binary packages is Download. However the latest versions are said to be 4.6. Personally I used the github repo FreeFem/FreeFem-sources/releases but I don’t know if it is the right thing to do.

Hello,
I allow myself to up this thread.
I guess the issue comes from ffglut, is it possible to reinstall this only ?
Have a good day.
Best,
Eloi.

I ran your second set of code and it ran ok AFAICT
You can try running it under gdb. Just type "gdb --args FreeFem++ file.edp
type run and when it segfailts type “bt” and copy that to this forum.

int eigCount = 10; // the number of eigenvalues to compute
int npoints = 100; // Number of points on the circonference of the disk
real radius = sqrt(1/pi); // The radius of the disk of area 1

border circle(t=0,2pi){
x = radius
cos(t);
y = radius*sin(t);
}

mesh Th = buildmesh(circle(npoints));

fespace Vh(Th,P1);
Vh uh,vh;

varf va(uh, vh) = int2d(Th)( dx(uh)*dx(vh)+dy(uh)dy(vh));
varf vb(uh, vh) = int2d(Th)(uh
vh);

matrix A = va(Vh, Vh ,solver = sparsesolver); // Matrix A on left side
matrix B = vb(Vh, Vh); // Matrix B on right side

// Get first Eigenvalues
real[int] ev(eigCount); // Holds Eigenvalues
Vh[int] eV(eigCount); // Holds Eigenfunctions

int numEigs = EigenValue(A,B,sym=true,sigma=0,value=ev,vector=eV);

plot(eV[1], wait=true);

Hello,
Sorry for the late reply. Here is the trace :

(gdb) run
Starting program: /usr/local/bin/FreeFem++ neumann_disk.edp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 125864]
-- FreeFem++ v4.12 (Tue Dec  6 19:14:11 CET 2022 - git v4.12)
   file : neumann_disk.edp
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue 
    1 : load "medit"
    2 : int eigCount = 10; // the number of eigenvalues to compute
    3 : int npoints = 400; // Number of points on the circonference of the disk
    4 : real radius = sqrt(1/pi); // The radius of the disk of area 1
    5 : 
    6 : border circle(t=0,2*pi){
    7 :   x = radius*cos(t);
    8 :   y = radius*sin(t);
    9 : }
   10 : 
   11 : /* Save scalar function u as a .sol file */
   12 : func int printsol(string sout, real[int] & u) {
   13 : 
   14 :   int n = u.n;
   15 :   ofstream fout(sout);
   16 : 
   17 :   /* Header */
   18 :   fout << "MeshVersionFormatted 1\n\nDimension 2\n\nSolAtVer
  ... : tices\n"<<n<<"\n1 1\n"<<endl;
   19 : 
   20 :   /* Print values */
   21 :   for (int k=0; k<n; k++)
   22 :     fout<<u[k]<<endl;
   23 : 
   24 :   /* End keyword */
   25 :   fout<<"End"<<endl;
   26 : 
   27 :   return(1);
   28 : }
   29 : 
   30 : mesh Th = buildmesh(circle(npoints));
   31 : 
   32 : fespace Vh(Th,P1);
   33 : Vh uh,vh;
   34 : 
   35 : varf va(uh, vh) = int2d(Th)( dx(uh)*dx(vh)+dy(uh)*dy(vh));
   36 : varf vb(uh, vh) = int2d(Th)(uh*vh);
   37 : 
   38 : matrix A = va(Vh, Vh ,solver = sparsesolver); // Matrix A on left side
   39 : matrix B = vb(Vh, Vh);                        // Matrix B on right side
   40 : 
   41 : // Get first Eigenvalues
   42 : real[int] ev(eigCount); // Holds Eigenvalues
   43 : Vh[int] eV(eigCount);   // Holds Eigenfunctions
   44 : 
   45 : int numEigs = EigenValue(A,B,sym=true,sigma=0,value=ev,vector=eV);
   46 : 
   47 : plot(eV[1], wait=1);
   48 :  sizestack + 1024 =1984  ( 960 )

  --  mesh:  Nb of Triangles =  27650, Nb of Vertices 14026
Real symmetric eigenvalue problem: A*x - B*x*lambda
times: compile 0.003337s, execution 0.511229s,  mpirank:0
Segmentation fault (core dumped)
 CodeAlloc : nb ptr  3853,  size :509688 mpirank: 0
Ok: Normal End
[Inferior 1 (process 125860) exited normally]
(gdb) bt
No stack.

Usually gdb catches the segfault before the app but I guess if its launching a new
process for ffglut that is not attached to gdb.

There are a couple of ideas here, I would imagine FF invokes the fflglut in
the FF bin dir but maybe you could replace that with a script to help attach
or see if the follow process thing works,

https://stackoverflow.com/questions/15126925/debugging-child-process-after-fork-follow-fork-mode-child-configured