X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/GMRES2stage.git/blobdiff_plain/12958908db074a04fed4200e347802c16b3c0c01..89ef73268fc9f6d2955ed7abe987ea691174d95e:/code/ex15.c diff --git a/code/ex15.c b/code/ex15.c index 1fffcbe..04f08f1 100644 --- a/code/ex15.c +++ b/code/ex15.c @@ -1,3 +1,5 @@ +// /home/couturie/work/petsc-3.5.1_old/arch-linux2-c-debug/bin/mpirun -np 4 -machinefile archi ./ex15 -m 1000 -n 1000 -ksp_type fgmres -pc_type mg + // /home/couturie/work/petsc-3.5.1/arch-linux2-c-debug/bin/mpirun -np 4 ./ex15 -m 400 -n 400 -ksp_type fgmres @@ -56,7 +58,7 @@ int KrylovMinimize(Mat A, Vec b, Vec x) { //Variables PetscScalar gamma, alpha, oldgamma, beta; - PetscReal norm=20, Eprecision=1e-6, cgprec=1e-40; + PetscReal norm=20, Eprecision=1e-3, cgprec=1e-40; PetscInt giter=0, ColS=12, col=0, Emaxiter=50000000, iter=0, iterations=15, Iiter=0; PetscErrorCode ierr; PetscScalar T1, T2; @@ -120,13 +122,14 @@ int KrylovMinimize(Mat A, Vec b, Vec x) { //Initializations // ierr = KSPGMRESSetRestart(ksp, 16); CHKERRQ(ierr); - ierr = KSPSetTolerances(ksp, 1e-13, 1e-13, PETSC_DEFAULT, 16); CHKERRQ(ierr); + ierr = KSPSetTolerances(ksp, 1e-13, 1e-13, PETSC_DEFAULT, 30); CHKERRQ(ierr); ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE); CHKERRQ(ierr); //GMRES WITH MINIMIZATION T1 = MPI_Wtime(); + ierr = KSPSetUp(ksp); CHKERRQ(ierr); while(giterEprecision ){ for(col=0; colEprecision; col++){ @@ -233,7 +236,7 @@ int KrylovMinimizeLSQR(Mat A, Vec b, Vec x) { //Variables PetscScalar alpha, beta; - PetscReal norm=20, Eprecision=1e-6, tol=1e-40; + PetscReal norm=20, Eprecision=1e-3, tol=1e-40; PetscInt giter=0, ColS=12, col=0, Emaxiter=50000000, iter=0, iterations=20, Iiter=0; PetscErrorCode ierr; PetscScalar T1, T2; @@ -310,7 +313,7 @@ int KrylovMinimizeLSQR(Mat A, Vec b, Vec x) { //Initializations // ierr = KSPGMRESSetRestart(ksp, 16); CHKERRQ(ierr); - ierr = KSPSetTolerances(ksp, 1e-13, 1e-13, PETSC_DEFAULT, 16); CHKERRQ(ierr); + ierr = KSPSetTolerances(ksp, 1e-13, 1e-13, PETSC_DEFAULT, 30); CHKERRQ(ierr); ierr = KSPSetInitialGuessNonzero(ksp, PETSC_TRUE); CHKERRQ(ierr); @@ -318,6 +321,7 @@ int KrylovMinimizeLSQR(Mat A, Vec b, Vec x) { //GMRES WITH MINIMIZATION T1 = MPI_Wtime(); + ierr = KSPSetUp(ksp); CHKERRQ(ierr); while(giterEprecision ){ for(col=0; colEprecision; col++){ @@ -515,7 +519,8 @@ int main(int argc,char **args) */ for (Ii=Istart; Ii0) {J = Ii - n; ierr = MatSetValues(A,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} + PetscScalar v2=-1.; + if (i>0) {J = Ii - n; ierr = MatSetValues(A,1,&Ii,1,&J,&v2,INSERT_VALUES);CHKERRQ(ierr);} if (i0) {J = Ii - 1; ierr = MatSetValues(A,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} if (j1e-3) { + ierr = KSPSolve(ksp,b,x2);CHKERRQ(ierr); + KSPGetResidualNorm(ksp,&norm); + ierr = KSPGetIterationNumber(ksp, &its); CHKERRQ(ierr); + total += its; + ierr = PetscPrintf(PETSC_COMM_WORLD, "Norm of error %g\n", norm); CHKERRQ(ierr); + } + T2 = MPI_Wtime(); + MatMult(A,x2,sol); + VecAXPY(sol,-1,b); + VecNorm(sol, NORM_2, &norm); + ierr = PetscPrintf(PETSC_COMM_WORLD,"Computed norm of error %g iterations %D\n",(double)norm,total);CHKERRQ(ierr); + ierr = PetscPrintf(PETSC_COMM_WORLD, "\t\t\t -- Execution time NORMAL GMRES : %g (s)\n\n\n", T2-T1); CHKERRQ(ierr); + } + { Vec x2; @@ -649,9 +695,8 @@ int main(int argc,char **args) ierr = PetscPrintf(PETSC_COMM_WORLD, "\t\t\t -- Error Krylov Minimization LSQR %g\n",norm); } - + - /* Free work space. All PETSc objects should be destroyed when they are no longer needed.