// ff-mpirun -np 4 MPIGMRES2D.edp -glut ffglut -n 11 -k 1 -d 1 -ns -gmres 1 /* a first true parallele example fisrt freefem++ Ok up to 200 proc for a Poisson equation.. See the Doc for full explaiantion F Hecht Dec. 2010. ------------------- usage : ff-mpirun [mpi parameter] MPIGMRES2d.edp [-glut ffglut] [-n N] [-k K] [-d D] [-ns] [-gmres [0|1] argument: -glut ffglut : to see graphicaly the process -n N: set the mesh cube split NxNxN -d D: set debug flag D must be one for mpiplot -k K: to refined by K all elemnt -ns: reomove script dump -gmres 0 : use iterative schwarz algo. 1 : Algo GMRES on residu of schwarz algo. 2 : DDM GMRES 3 : DDM GMRES with coarse grid preconditionner (Good one) */ load "MPICG" load "medit" load "metis" include "getARGV.idp" include "MPIplot.idp" include "MPIGMRESmacro.idp" //include "AddLayer2d.idp" searchMethod=0; // more safe seach algo (warning can be very expensive in case lot of ouside point) assert(version >=3.11); real[int] ttt(10);int ittt=0; macro settt {ttt[ittt++]=mpiWtime();}// verbosity=getARGV("-vv",0); int vdebug=getARGV("-d",1); int ksplit=getARGV("-k",3); int nloc = getARGV("-n",11); string sff=getARGV("-p,",""); int gmres=getARGV("-gmres",2); bool dplot=getARGV("-dp",0); int nC = getARGV("-N" ,max(nloc/10,4)); if(mpirank==0 && verbosity) { cout << "ARGV : "; for(int i=0;i0,label=10); // non-overlapping mesh, interfaces have label 10 int nnn = sizeoverlaps*2;// to be sure AddLayers(Thg,suppi[],nnn,unssd[]); // see above ! suppi and unssd are modified unssd[] *= nnn; // to put value nnn a 0 real nnn0 = nnn - sizeoverlaps + 0.001 ; Thi=trunc(Thg,unssd>nnn0 ,label=10); // overlapping mesh, interfaces have label 10 settt fespace Vhi(Thi,P1); int npij=npart; Vhi[int] pij(npij);// local partition of unit + pii Vhi pii; real nnn1= + 0.001 ; { /* construction of the partition of the unit, let phi_i P1 FE function 1 on Thin and zero ouside of Thi and positive the partition is build with $$ p_i = phi_i/ \sum phi_i to build the partition of one domain i we nned to find all j such that supp(phi_j) \cap supp(phi_j) is not empty <=> int phi_j */ // build a local mesh of thii such that all compuation of the unit partition are // exact in thii mesh Thii=trunc(Thg,unssd>nnn1 ,label=10); // overlapping mesh, interfaces have label 10 { // find all j mes (supp(p_j) \cap supp(p_i)) >0 // compute all phi_j on Thii // remark supp p_i include in Thi // fespace Phii(Thii,P0); fespace Vhii(Thii,P1); Vhi sumphi=0; jpart=0; njpart=0; int nlayer=RAS?1:sizeoverlaps; if(ipart==0) cout <<" nlayer=" << nlayer << endl; pii= max(unssd-nnn+nlayer,0.)/nlayer; if(dplot) plot(pii,wait=1,cmm=" 0000"); sumphi[] += pii[]; if(dplot) plot(sumphi,wait=1,cmm=" summ 0000"); Vhii phii=0; real epsmes=1e-10*Thii.area; for (int i=0;i 0.5) { AddLayers(Thii,suppii[],nlayer,phii[]); assert(phii[].min >=0); real interij = int2d(Thi)( phii); if(interij>epsmes) { pij[njpart]=abs(phii); if(vdebug>2) cout << " ***** " << int2d(Thi)(real(pij[njpart])<0) << " " <2) cout << " sum min " < 1.-1e-6 && sumphi[].max< 1.+1e-6); // verification }}// (Thii is remove here) // end of the construction of the local partition of the unity ... // on Thi ... // ----------------------------------------------------------------- if(ipart==0) cout << " *** end build partition " << endl; // computation of number of intersection .. // ------------------------------------------ // here pii and the pij is the locate partition of the unite on // Thi ( mesh with overlap ).... //Thi=splitmesh(Thi,2); if(dplot ) { plot(Thi,wait=1); for(int j=0;j we have to recive // data on intersection of the support of pij[0] and pij[j] settt if(vdebug) plotMPIall(Thi,pii[],"pi_i"); mesh[int] aThij(njpart); matrix Pii; matrix[int] sMj(njpart); // M of send to j matrix[int] rMj(njpart); // M to recv from j fespace Whi(Thi,Pk); mesh Thij=Thi; fespace Whij(Thij,Pk);// // construction of the mesh intersect i,j part for(int jp=0;jp1e-6,label=10); // mesh of the supp of pij for(int jp=0;jp s Whij rMj[jp] = interpolate(Whij,Whi,t=1); // Whji -> Whi if(vdebug>10) { {Whi uuu=1;Whij vvv=-1; vvv[]+=I*uuu[]; cout << jp << " %%% " << vvv[].linfty << endl; assert(vvv[].linfty < 1e-6);} {Whi uuu=1;Whij vvv=-1; vvv[]+=rMj[jp]'*uuu[]; cout << jp << " ### " << vvv[].linfty << endl; assert(vvv[].linfty < 1e-6);}} }} if(ipart==0) cout << " *** end build transfert matrix " << endl; // alloc array of send and recv data .. InitU(njpart,Whij,Thij,aThij,Usend) // initU(n,Vh,Th,aTh,U) InitU(njpart,Whij,Thij,aThij,Vrecv) // ... if(ipart==0) cout << " *** end init data for send/revc " << endl; Whi ui,vi; func bool Update(real[int] &ui, real[int] &vi) { for(int j=0;j I ~ - C1AC2A +C1A +C2A // New Prec P= C1+C2 - C1AC2 = C1(I- A C2) +C2 // ( C1(I- A C2) +C2 ) Uo // V = - C2*Uo // .... real[int] V(U.n); CoarseSolve(V,U,comm); V = -V; // -C2*Uo U += Ai*V; // U = (I-A C2) Uo real[int] b= onG10 ? 0. : U; U = Ai^-1*b; // ( C1( I -A C2) Uo V = U -V; // Update(V,U); return U; } func real[int] DJ0(real[int]& U) { ++kiter; real[int] V(U.n); real[int] b= onG .* U; b = onG ? b : Bi ; V = Ai^-1*b; Update(V,U); V -= U; return V; } Whi u=0,v; { // verification..... Whi u=1,v; Update(u[],v[]); u[]-=v[]; assert( u[].linfty<1e-6); } settt u[]=vBC(0,Whi,tgv=1); // set u with tge BC value ... real epss=1e-6; int rgmres=0; if(gmres==1) { rgmres=MPIAffineGMRES(DJ0,u[],veps=epss,nbiter=300,comm=comm,dimKrylov=100,verbosity=ipart ? 0: 50); real[int] b= onG .* u[]; b = onG ? b : Bi ; v[] = Ai^-1*b; Update(v[],u[]); } else if(gmres==2) rgmres= MPILinearGMRES(DJ,precon=PDJ,u[],Bi,veps=epss,nbiter=300,comm=comm,dimKrylov=100,verbosity=ipart ? 0: 50); else if(gmres==3) rgmres= MPILinearGMRES(DJ,precon=PDJC,u[],Bi,veps=epss,nbiter=300,comm=comm,dimKrylov=100,verbosity=ipart ? 0: 50); else // algo Shwarz for demo ... for(int iter=0;iter <10; ++iter) { real[int] b= onG .* u[]; b = onG ? b : Bi ; v[] = Ai^-1*b; Update(v[],u[]); if(vdebug) plotMPIall(Thi,u[],"u-"+iter); v[] -= u[]; real err = v[].linfty; real umax = u[].max; real[int] aa=[err,umax], bb(2); mpiAllReduce(aa,bb,comm,mpiMAX); real errg = bb[0]; real umaxg = bb[1]; if(ipart==0) cout << ipart << " err = " << errg << " u. max " << umaxg << endl; if(errg< 1e-5) break; } if(vdebug) plotMPIall(Thi,u[],"u-final"); settt real errg =1,umaxg; { real umax = u[].max,umaxg; real[int] aa=[umax], bb(1); mpiAllReduce(aa,bb,comm,mpiMAX); errg=bb[0]; if(ipart==0) cout << " umax global = " << bb[0] << " Wtime = " << (ttt[ittt-1]-ttt[ittt-2]) << " s " << " " << kiter << endl; } if(sff != "") { ofstream ff(sff+".txt",append); cout << " ++++ " ; cout << mpirank <<"/" << mpisize << " k=" << ksplit << " n= " << nloc << " " << sizeoverlaps << " it= " << kiter ; for (int i=1; i