FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
796 stars 193 forks source link

CG solver get slow in new version #71

Closed zhaog6 closed 5 years ago

zhaog6 commented 5 years ago

Dear professor, I compared CG solver in old version(v3.62) with CG in new version(v4.0), noticing that the later(v4.0) is slower than the former(v3.62) in term of solve time. As solve Poisson equations with homogeneous in tutorial, I have done test as following:

int nn = 320;
int[int] L = [1, 2, 3, 4];
func f = 1;

border bd1(t = 0, 1) {x = t;   y = 0;   label=1;}
border bd2(t = 0, 1) {x = 1;   y = t;   label=2;}
border bd3(t = 0, 1) {x = 1-t; y = 1;   label=3;}
border bd4(t = 0, 1) {x = 0;   y = 1-t; label=4;}
mesh Th = buildmesh(bd1(nn) + bd2(nn) + bd3(nn) + bd4(nn));
fespace Vh(Th, P1);
Vh uh;

varf vA(u, v) = int2d(Th) ( dx(u)*dx(v) + dy(u)*dy(v) ) + on(L, u=0);
varf vl(unused, v) = int2d(Th) (f * v) + on(L, unused=0);
matrix A = vA(Vh, Vh);
real[int] b = vl(0,Vh);
real start = clock();
set(A, solver=CG);
cout << "Set solver time is " << clock()-start << endl;
start = clock();
uh[] = A^-1 * b;
cout << "Solve system time is " << clock()-start << endl;

then using command "FreeFem++/FreeFem++-mpi filename.edp" to compile and run. when calculating the total time of "Set solver time" and "Solve system time", I find that the total time consumption solved by CG in v4.0 is beyond the total time of CG in v3.62. I don't understand why?

frederichecht commented 5 years ago

I will try. Best Regards,

Frédéric Hecht.


Laboratoire Jacques-Louis Lions, UPMC Sorbonne Université BC187, 4 Place Jussieu, 75252 PARIS cedex 05, France Campus Jussieu, Barre 15-25, 3 etage Bureau 307 Projet Alpines , Inria de Paris, 2 rue Simone Iff Voie DQ12 75012 Paris tel: +33 1 44274411, mob: +33 6 62198986, fax: +33 1 44277200 frederic.hecht@sorbonne-universite.fr https://www.ljll.math.upmc.fr/hecht software: FreeFem++ web site: http://www.freefem.org/ff++

Le 8 févr. 2019 à 17:20, zhaog6 notifications@github.com a écrit :

Dear professor, I compared CG solver in old version(v3.62) with CG in new version(v4.0), noticing that the later(v4.0) is slower than the former(v3.62) in term of solve time. As solve Poisson equations with homogeneous in tutorial, I have done test as following:

int nn = 320; int[int] L = [1, 2, 3, 4]; func f = 1;

border bd1(t = 0, 1) {x = t; y = 0; label=1;} border bd2(t = 0, 1) {x = 1; y = t; label=2;} border bd3(t = 0, 1) {x = 1-t; y = 1; label=3;} border bd4(t = 0, 1) {x = 0; y = 1-t; label=4;} mesh Th = buildmesh(bd1(nn) + bd2(nn) + bd3(nn) + bd4(nn)); fespace Vh(Th, P1); Vh uh;

varf vA(u, v) = int2d(Th) ( dx(u)dx(v) + dy(u)dy(v) ) + on(L, u=0); varf vl(unused, v) = int2d(Th) (f v) + on(L, unused=0); matrix A = vA(Vh, Vh); real[int] b = vl(0,Vh); real start = clock(); set(A, solver=CG); cout << "Set solver time is " << clock()-start << endl; start = clock(); uh[] = A^-1 b; cout << "Solve system time is " << clock()-start << endl; then using command "FreeFem++/FreeFem++-mpi filename.edp" to compile and run. when calculating the total time of "Set solver time" and "Solve system time", I find that the total time consumption solved by CG in v4.0 is beyond the total time of CG in v3.62. I don't understand why?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FreeFem/FreeFem-sources/issues/71, or mute the thread https://github.com/notifications/unsubscribe-auth/AFb2jCdUqy9pBrbzHpjsdxusYLLEYCPNks5vLaPLgaJpZM4awbYk.

frederichecht commented 5 years ago

Effectively, I will try to see where GC lose time.

MBP-FH5:modern-metal hecht$ /usr/local/ff++/openmpi-2.1/3.60/bin/FreeFem++ /Users/hecht/Desktop/u.edp -- FreeFem++ v 3.610000 (date Ven 22 jui 2018 09:25:36 CEST) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : int nn = 320; 2 : int[int] L = [1, 2, 3, 4]; 3 : func f = 1; 4 : 5 : border bd1(t = 0, 1) {x = t; y = 0; label=1;} 6 : border bd2(t = 0, 1) {x = 1; y = t; label=2;} 7 : border bd3(t = 0, 1) {x = 1-t; y = 1; label=3;} 8 : border bd4(t = 0, 1) {x = 0; y = 1-t; label=4;} 9 : mesh Th = buildmesh(bd1(nn) + bd2(nn) + bd3(nn) + bd4(nn)); 10 : fespace Vh(Th, P1); 11 : Vh uh; 12 : 13 : varf vA(u, v) = int2d(Th) ( dx(u)dx(v) + dy(u)dy(v) ) + on(L, u=0); 14 : varf vl(unused, v) = int2d(Th) (f v) + on(L, unused=0); 15 : matrix A = vA(Vh, Vh); 16 : real[int] b = vl(0,Vh); 17 : real start = clock(); 18 : set(A, solver=CG); 19 : cout << "Set solver time is " << clock()-start << endl; 20 : start = clock(); 21 : uh[] = A^-1 b; 22 : cout << "Solve system time is " << clock()-start << endl; 23 : sizestack + 1024 =1672 ( 648 )

-- mesh: Nb of Triangles = 242460, Nb of Vertices 121871 Set solver time is 0.000766 Solve system time is 1.44298 times: compile 0.00892s, execution 2.65622s, mpirank:0 ######## We forget of deleting 0 Nb pointer, 0Bytes , mpirank 0, memory leak =146560 CodeAlloc : nb ptr 2926, size :362432 mpirank: 0 Ok: Normal End MBP-FH5:modern-metal hecht$ FreeFem++ /Users/hecht/Desktop/u.edp -- FreeFem++ v 4.000000 (date Ven 1 fév 2019 19:05:59 CET) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : int nn = 320; 2 : int[int] L = [1, 2, 3, 4]; 3 : func f = 1; 4 : 5 : border bd1(t = 0, 1) {x = t; y = 0; label=1;} 6 : border bd2(t = 0, 1) {x = 1; y = t; label=2;} 7 : border bd3(t = 0, 1) {x = 1-t; y = 1; label=3;} 8 : border bd4(t = 0, 1) {x = 0; y = 1-t; label=4;} 9 : mesh Th = buildmesh(bd1(nn) + bd2(nn) + bd3(nn) + bd4(nn)); 10 : fespace Vh(Th, P1); 11 : Vh uh; 12 : 13 : varf vA(u, v) = int2d(Th) ( dx(u)dx(v) + dy(u)dy(v) ) + on(L, u=0); 14 : varf vl(unused, v) = int2d(Th) (f v) + on(L, unused=0); 15 : matrix A = vA(Vh, Vh); 16 : real[int] b = vl(0,Vh); 17 : real start = clock(); 18 : set(A, solver=CG); 19 : cout << "Set solver time is " << clock()-start << endl; 20 : start = clock(); 21 : uh[] = A^-1 b; 22 : cout << "Solve system time is " << clock()-start << endl; 23 : sizestack + 1024 =1672 ( 648 )

-- mesh: Nb of Triangles = 242460, Nb of Vertices 121871 Set solver time is 0.015942 GC: converge in 924 g=2.22486e-18 rho= 2.14944 gamma= 0.957787 Solve system time is 16.3895 times: compile 0.00518s, execution 17.7248s, mpirank:0 ######## We forget of deleting 0 Nb pointer, 0Bytes , mpirank 0, memory leak =117216 CodeAlloc : nb ptr 3040, size :377192 mpirank: 0 Ok: Normal End MBP-FH5:modern-metal hecht$

Le 8 févr. 2019 à 17:20, zhaog6 notifications@github.com a écrit :

Dear professor, I compared CG solver in old version(v3.62) with CG in new version(v4.0), noticing that the later(v4.0) is slower than the former(v3.62) in term of solve time. As solve Poisson equations with homogeneous in tutorial, I have done test as following:

int nn = 320; int[int] L = [1, 2, 3, 4]; func f = 1;

border bd1(t = 0, 1) {x = t; y = 0; label=1;} border bd2(t = 0, 1) {x = 1; y = t; label=2;} border bd3(t = 0, 1) {x = 1-t; y = 1; label=3;} border bd4(t = 0, 1) {x = 0; y = 1-t; label=4;} mesh Th = buildmesh(bd1(nn) + bd2(nn) + bd3(nn) + bd4(nn)); fespace Vh(Th, P1); Vh uh;

varf vA(u, v) = int2d(Th) ( dx(u)dx(v) + dy(u)dy(v) ) + on(L, u=0); varf vl(unused, v) = int2d(Th) (f v) + on(L, unused=0); matrix A = vA(Vh, Vh); real[int] b = vl(0,Vh); real start = clock(); set(A, solver=CG); cout << "Set solver time is " << clock()-start << endl; start = clock(); uh[] = A^-1 b; cout << "Solve system time is " << clock()-start << endl; then using command "FreeFem++/FreeFem++-mpi filename.edp" to compile and run. when calculating the total time of "Set solver time" and "Solve system time", I find that the total time consumption solved by CG in v4.0 is beyond the total time of CG in v3.62. I don't understand why?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FreeFem/FreeFem-sources/issues/71, or mute the thread https://github.com/notifications/unsubscribe-auth/AFb2jCdUqy9pBrbzHpjsdxusYLLEYCPNks5vLaPLgaJpZM4awbYk.

zhaog6 commented 5 years ago

I will try. Best Regards, Frédéric Hecht.

Thanks, Professor, Additionally, GMRES solver in new version is seemingly get slow also. ( I take "nn = 160 or 320" in the first line of code when testing it ).

— Best Regards, Gang Zhao

frederichecht commented 5 years ago

Thank I find the mistake, I have correct now the speed is the same the preconditioner was badly connect before.