Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen problem #116

Closed
pmollo opened this issue Nov 12, 2019 · 11 comments
Closed

Eigen problem #116

pmollo opened this issue Nov 12, 2019 · 11 comments

Comments

@pmollo
Copy link

pmollo commented Nov 12, 2019

Hi,
I have to solve eigen value problems, so I first try to solve a validation example... But it does not work.

** Expected behavior **
I take a diagonal matrix (4x4) with 4 distinct integers on diagonal, then I use the "EigenValue" function following the help page (https://doc.freefem.org/models/eigen-value-problems.html).
So I expect to find 4 eigen values/vectors, but the function only returns the 3 highest ones.
I try to grow in dimension, but the function always returns the (n-1) highest eigen values.

The code for the example :
`matrix A =
[ [4, 0, 0, 0],
[0, 3 ,0 ,0],
[0, 0, 2, 0],
[0, 0, 0, 5] ];
set(A, solver=UMFPACK);

cout << A << endl;
matrix B =
[ [1, 0, 0, 0],
[0, 1 ,0 ,0],
[0, 0, 1, 0],
[0, 0, 0, 1] ];
set(B, solver=UMFPACK);

// Solve
int Nev = 4 ;
real[int] ev(Nev); //to store eigen values
real[int,int] Vec(Nev,Nev); //to store eigen vectors

int k = EigenValue(A, B, sym=true, value=ev, rawvector=Vec, nev=Nev, maxit=0, ncv=0);
cout << k ;
cout << " vp : " << ev << endl;
cout << " Vp : " << Vec << endl;
`

I try multiple parameters, but I still don't know why it is not working.

** Desktop : **

  • OS: Ubuntu 18.04
  • Freefem version : v4.4.2

Thank you for your help,
Pierre.

@prj-
Copy link
Member

prj- commented Nov 12, 2019

You should not use the EigenValue routine, it's based on an old interface to ARPACK.
Here are two different options:

  1. using SLEPc (useful for sparse problems)
  2. using LAPACK (useful for dense linear systems)
load "SLEPc"
matrix A =
[ [4, 0, 0, 0],
[0, 3 ,0 ,0],
[0, 0, 2, 0],
[0, 0, 0, 5] ];
matrix B =
[ [1, 0, 0, 0],
[0, 1 ,0 ,0],
[0, 0, 1, 0],
[0, 0, 0, 1] ];
Mat dA(A);
Mat dB(B);
real[int] nev(4);
real[int, int] neV(4, 4);
EPSSolve(dA, dB, values = nev, array = neV);
cout << nev << endl;

load "lapack"
real[int, int] fullA = [ [4, 0, 0, 0],
[0, 3 ,0 ,0],
[0, 0, 2, 0],
[0, 0, 0, 5] ];
real[int, int] fullB = [ [1, 0, 0, 0],
[0, 1 ,0 ,0],
[0, 0, 1, 0],
[0, 0, 0, 1] ];
complex[int] cnev(4);
complex[int, int] cneV(4, 4);
dggev(fullA, fullB, cnev, nev, cneV);
cout << cnev << endl;

You can run this program using, for example, mpirun -np 1 FreeFem++-mpi ev.edp -eps_view_values ::ascii_matlab -v 0. Expected output:

Lambda_EPS_0x84000000_0 = [
5.0000000000000027e+00
4.0000000000000044e+00
3.0000000000000027e+00
2.0000000000000000e+00
];
4
	  5	  4	  3	  2
4
	(4,0)	(3,0)	(2,0)	(5,0)

@pmollo
Copy link
Author

pmollo commented Nov 12, 2019

Hi,
Thank you for your help !
It will be useful to update the help page about eigen values :)

@prj-
Copy link
Member

prj- commented Nov 12, 2019

There are some available informations at this URL. All SLEPc examples are available there. If you don't have any further issue, could you please close the issue when you get the chance to? Thanks.

@frederichecht
Copy link
Contributor

frederichecht commented Nov 12, 2019 via email

@pmollo pmollo closed this as completed Nov 12, 2019
@pmollo pmollo reopened this Nov 12, 2019
@pmollo pmollo closed this as completed Nov 12, 2019
@pmollo
Copy link
Author

pmollo commented Nov 12, 2019

Hi again,
I still can't solve my eigen problems :

  • I'm unable to install/load SLEPc module. I try to reinstall FF and compile src codes, but it does not work.
  • LAPACK works & the function dggev finds e.v. but the eigen vectors are wrong (full of zeros or 1e-310). Beside that, the help page about LAPACK is empty (https://doc.freefem.org/references/external-libraries.html#dggev).

Thank you for your help
(Sorry for the re-opened/closed before)

@pmollo pmollo reopened this Nov 12, 2019
@prj-
Copy link
Member

prj- commented Nov 12, 2019

What is the problem with SLEPc install? You can also call LAPACK directly from SLEPc. Here is what I get with -eps_view_vectors ::ascii_matlab -eps_type lapack.

%Vec Object: X0_EPS_0x84000000_0 1 MPI processes
%  type: seq
X0_EPS_0x84000000_0 = [
0.0000000000000000e+00
0.0000000000000000e+00
0.0000000000000000e+00
-1.0000000000000000e+00
];
%Vec Object: X1_EPS_0x84000000_0 1 MPI processes
%  type: seq
X1_EPS_0x84000000_0 = [
1.0000000000000000e+00
0.0000000000000000e+00
0.0000000000000000e+00
0.0000000000000000e+00
];
%Vec Object: X2_EPS_0x84000000_0 1 MPI processes
%  type: seq
X2_EPS_0x84000000_0 = [
0.0000000000000000e+00
1.0000000000000000e+00
0.0000000000000000e+00
0.0000000000000000e+00
];
%Vec Object: X3_EPS_0x84000000_0 1 MPI processes
%  type: seq
X3_EPS_0x84000000_0 = [
0.0000000000000000e+00
0.0000000000000000e+00
1.0000000000000000e+00
0.0000000000000000e+00
];

@pmollo
Copy link
Author

pmollo commented Nov 12, 2019

  • This is what I've got when I try to compile PETSc :
    "
    ===============================================================================
    Configuring PETSc to compile on your system
    ===============================================================================
    TESTING: checkCCompiler from config.setCompilers(config/BuildSystem/config/setCompilers.py:620) *******************************************************************************
    UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):

C compiler you provided with -with-cc= does not work.


Makefile:245: recipe for target 'petsc-3.12.0/tag-conf-real' failed
make: *** [petsc-3.12.0/tag-conf-real] Error 1
"

  • And this is what I've got when I use "mpirun -np 1 FreeFem++-mpi test.edp -eps_view_values ::ascii_matlab -eps_type lapack -ne" :

"
~/Documents$ mpirun -np 1 FreeFem++-mpi test.edp -eps_view_values ::ascii_matlab -eps_type lapack -ne
-- FreeFem++ v4.400002 (Fri Oct 25 11:37:05 CEST 2019 - git v4.4.2)
Load: lg_fem lg_mesh lg_mesh3 eigenvalue parallelempi
Add lapack interface ... sizestack + 1024 =1456 ( 432 )

4 4
(6.902534736e-310,0) (0,0) (0,0) (0,0)
(6.902534736e-310,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)

times: compile 0.002496s, execution 0.000117s, mpirank:0
CodeAlloc : nb ptr 3460, size :462648 mpirank: 0
Ok: Normal End
"

And with "mpirun -np 1 FreeFem++-mpi test.edp -eps_view_vectors ::ascii_matlab -eps_type lapack -ne":
"
~/Documents$ mpirun -np 1 FreeFem++-mpi test.edp -eps_view_vectors ::ascii_matlab -eps_type lapack -ne
-- FreeFem++ v4.400002 (Fri Oct 25 11:37:05 CEST 2019 - git v4.4.2)
Load: lg_fem lg_mesh lg_mesh3 eigenvalue parallelempi
Add lapack interface ... sizestack + 1024 =1456 ( 432 )

4 4
(6.913082725e-310,0) (0,0) (0,0) (0,0)
(6.913082725e-310,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)

times: compile 0.00245s, execution 0.00011s, mpirank:0
CodeAlloc : nb ptr 3460, size :462648 mpirank: 0
Ok: Normal End
"

The code is :
`
real[int] nev(4);
real[int, int] neV(4, 4);

load "lapack"
real[int, int] fullA = [ [4, 0, 0, 0],
[0, pi ,0 ,0],
[0, 0, 2, 0],
[0, 0, 0, 5] ];
real[int, int] fullB = [ [1, 0, 0, 0],
[0, 1 ,0 ,0],
[0, 0, 1, 0],
[0, 0, 0, 1] ];
complex[int] cnev(4);
complex[int, int] cneV(4, 4);
cneV=0.;
dggev(fullA, fullB, cnev, nev, cneV);
cout << cneV << endl;
`

@prj-
Copy link
Member

prj- commented Nov 12, 2019

FreeFEM configure does not find any MPI wrapper. Do you have MPI installed on your machine? Could you share your configure.log, please?

@pmollo
Copy link
Author

pmollo commented Nov 12, 2019

Here my config.log file :
config.txt

@prj-
Copy link
Member

prj- commented Nov 12, 2019

Could you please follow this procedure and let me know if things still don't work out?

$ ./configure --enable-download --enable-optim --prefix=${PWD}
$ ./3rdparty/getall -a
$ cd 3rdparty/ff-petsc
$ make petsc-slepc
$ cd -
$ ./reconfigure
$ make

You are missing a couple of flags in your initial ./configure, so this may explain this issue. All this is detailed here, I've added the --prefix option because it is a bad idea to have to use sudo for installing FreeFEM.

@pmollo
Copy link
Author

pmollo commented Nov 12, 2019

Ok, I think that something went wrong during my first attempt, but I tried in a VM and it's working.

Thank you again for your time & help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants