From a4c64016c7a17486d6768bf38d17712e60a77e6b Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Thu, 14 Jan 2016 20:18:59 +0100 Subject: [PATCH] various fixes and improvements to SLEPc unit tests some fiddling with solver settings (preconditioner, tolerance, etc) to produce the same output on OS-X and Linux. /slepc/step-36_parallel still needs two different outputs, though. fixed an uninitialised initial vector bug in slepc/step-36 unit test --- tests/slepc/solve_01.cc | 24 ++++++++------ tests/slepc/solve_01.output | 19 +++++------- tests/slepc/solve_04.cc | 22 ++++++++----- tests/slepc/solve_04.output | 20 +++++------- tests/slepc/step-36_parallel.cc | 31 ++++++++++--------- ...petsc=true.with_slepc=true.mpirun=3.output | 14 ++++----- ...tsc=true.with_slepc=true.mpirun=3.output.2 | 30 ++++++++++++++++++ 7 files changed, 97 insertions(+), 63 deletions(-) create mode 100644 tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output.2 diff --git a/tests/slepc/solve_01.cc b/tests/slepc/solve_01.cc index a41aca5a8e..eaacd3949c 100644 --- a/tests/slepc/solve_01.cc +++ b/tests/slepc/solve_01.cc @@ -48,12 +48,11 @@ check_solve( SolverType &solver, { solver.set_problem_type(EPS_GHEP); // reset vectors and set them as initial space - // to avoid dependency on random numbers: + // to avoid dependency on SLEPc random numbers: for (unsigned int i = 0; i < u.size(); i++) - { - u[i] = 0.0; - u[i][i] = 1.0; - } + for (unsigned int j=0; j(Testing::rand())/static_cast(RAND_MAX); + solver.set_initial_space(u); solver.solve(A,B,v,u,v.size()); @@ -86,7 +85,7 @@ int main(int argc, char **argv) Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1); { - SolverControl control(1000, 1000*PETSC_MACHINE_EPSILON); + SolverControl control(5000, 1e-11 /*1000*PETSC_MACHINE_EPSILON*/,false,false); const unsigned int size = 46; unsigned int dim = (size-1)*(size-1); @@ -109,6 +108,10 @@ int main(int argc, char **argv) PETScWrappers::Vector(dim)); std::vector v(n_eigenvalues); + PetscOptionsSetValue("-st_ksp_type","cg"); + PetscOptionsSetValue("-st_pc_type", "jacobi"); + PetscOptionsSetValue("-st_ksp_tol", "1e-15"); + { SLEPcWrappers::SolverKrylovSchur solver(control); check_solve (solver, control, A,B,u,v); @@ -124,19 +127,22 @@ int main(int argc, char **argv) check_solve (solver, control, A,B,u,v); } + PetscOptionsSetValue("-st_ksp_type","preonly"); { SLEPcWrappers::SolverGeneralizedDavidson solver(control); check_solve (solver, control, A,B,u,v); } { - SLEPcWrappers::SolverJacobiDavidson solver(control); + SLEPcWrappers::SolverGeneralizedDavidson::AdditionalData data(true); + SLEPcWrappers::SolverGeneralizedDavidson solver(control,PETSC_COMM_SELF,data); check_solve (solver, control, A,B,u,v); } + PetscOptionsSetValue("-st_ksp_type","cg"); + PetscOptionsSetValue("-st_ksp_max_it", "10"); { - SLEPcWrappers::SolverGeneralizedDavidson::AdditionalData data(true); - SLEPcWrappers::SolverGeneralizedDavidson solver(control,PETSC_COMM_SELF,data); + SLEPcWrappers::SolverJacobiDavidson solver(control); check_solve (solver, control, A,B,u,v); } } diff --git a/tests/slepc/solve_01.output b/tests/slepc/solve_01.output index 635bea8a23..9208eccc98 100644 --- a/tests/slepc/solve_01.output +++ b/tests/slepc/solve_01.output @@ -2,29 +2,26 @@ DEAL::Size 46 Unknowns 2025 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers17SolverKrylovSchurE -DEAL::Convergence step 23 value 0 -DEAL::Solver stopped after 23 iterations +DEAL::Solver stopped after 18 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers13SolverArnoldiE -DEAL::Convergence step 80 value 0 -DEAL::Solver stopped after 80 iterations +DEAL::Solver stopped after 63 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers13SolverLanczosE -DEAL::Convergence step 79 value 0 -DEAL::Solver stopped after 79 iterations +DEAL::Solver stopped after 60 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE -DEAL::Solver stopped after 278 iterations +DEAL::Solver stopped after 334 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: -DEAL::Solver type: N6dealii13SLEPcWrappers20SolverJacobiDavidsonE -DEAL::Solver stopped after 40 iterations +DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE +DEAL::Solver stopped after 504 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: -DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE -DEAL::Solver stopped after 581 iterations +DEAL::Solver type: N6dealii13SLEPcWrappers20SolverJacobiDavidsonE +DEAL::Solver stopped after 58 iterations DEAL::Eigenvalues: 29.73524, 29.67536, 29.58873, 29.46785 DEAL:: diff --git a/tests/slepc/solve_04.cc b/tests/slepc/solve_04.cc index f0f7d368a2..e22dcb382a 100644 --- a/tests/slepc/solve_04.cc +++ b/tests/slepc/solve_04.cc @@ -50,10 +50,9 @@ check_solve( SolverType &solver, // reset vectors and set them as initial space // to avoid dependency on random numbers: for (unsigned int i = 0; i < u.size(); i++) - { - u[i] = 0.0; - u[i][i] = 1.0; - } + for (unsigned int j=0; j(Testing::rand())/static_cast(RAND_MAX); + solver.set_initial_space(u); // solve solver.solve(A,v,u,v.size()); @@ -86,7 +85,8 @@ int main(int argc, char **argv) Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1); { - SolverControl control(500, 1000*PETSC_MACHINE_EPSILON); + SolverControl control(500,1e-12 /*1000*PETSC_MACHINE_EPSILON*/,false,false); + const unsigned int size = 31; unsigned int dim = (size-1); @@ -126,15 +126,21 @@ int main(int argc, char **argv) } { - SLEPcWrappers::SolverJacobiDavidson solver(control); + SLEPcWrappers::SolverGeneralizedDavidson::AdditionalData data(true); + SLEPcWrappers::SolverGeneralizedDavidson solver(control,PETSC_COMM_SELF,data); check_solve (solver, control, A,u,v); } + // set extra settings for JD; Otherwise, at least on OSX, + // the number of eigensolver iterations is different between debug and release modes! + PetscOptionsSetValue("-st_ksp_type","cg"); + PetscOptionsSetValue("-st_pc_type", "jacobi"); + PetscOptionsSetValue("-st_ksp_max_it", "10"); { - SLEPcWrappers::SolverGeneralizedDavidson::AdditionalData data(true); - SLEPcWrappers::SolverGeneralizedDavidson solver(control,PETSC_COMM_SELF,data); + SLEPcWrappers::SolverJacobiDavidson solver(control); check_solve (solver, control, A,u,v); } + } } diff --git a/tests/slepc/solve_04.output b/tests/slepc/solve_04.output index 2f8efd4c1f..ef11b2948d 100644 --- a/tests/slepc/solve_04.output +++ b/tests/slepc/solve_04.output @@ -2,32 +2,26 @@ DEAL::Size 31 Unknowns 30 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers17SolverKrylovSchurE -DEAL::Convergence step 5 value 0 DEAL::Solver stopped after 5 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers13SolverArnoldiE -DEAL::Convergence step 21 value 0 -DEAL::Solver stopped after 21 iterations +DEAL::Solver stopped after 24 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers13SolverLanczosE -DEAL::Convergence step 23 value 0 -DEAL::Solver stopped after 23 iterations +DEAL::Solver stopped after 21 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE -DEAL::Convergence step 120 value 0 -DEAL::Solver stopped after 120 iterations +DEAL::Solver stopped after 123 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: -DEAL::Solver type: N6dealii13SLEPcWrappers20SolverJacobiDavidsonE -DEAL::Convergence step 399 value 0 -DEAL::Solver stopped after 399 iterations +DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE +DEAL::Solver stopped after 138 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: -DEAL::Solver type: N6dealii13SLEPcWrappers25SolverGeneralizedDavidsonE -DEAL::Convergence step 145 value 0 -DEAL::Solver stopped after 145 iterations +DEAL::Solver type: N6dealii13SLEPcWrappers20SolverJacobiDavidsonE +DEAL::Solver stopped after 50 iterations DEAL::Eigenvalues: 3.98974, 3.95906, 3.90828, 3.83792 DEAL:: diff --git a/tests/slepc/step-36_parallel.cc b/tests/slepc/step-36_parallel.cc index a675833b29..c7764521db 100644 --- a/tests/slepc/step-36_parallel.cc +++ b/tests/slepc/step-36_parallel.cc @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -99,7 +99,7 @@ void test (std::string solver_name, constraints); constraints.close (); - dealii::CompressedSimpleSparsityPattern csp (locally_relevant_dofs); + dealii::DynamicSparsityPattern csp (locally_relevant_dofs); // Fill in ignoring all cells that are not locally owned dealii::DoFTools::make_sparsity_pattern (dof_handler, csp, constraints, @@ -127,7 +127,13 @@ void test (std::string solver_name, eigenfunctions.resize (5); for (unsigned int i=0; i(Testing::rand())/static_cast(RAND_MAX); + + eigenfunctions[i].compress(dealii::VectorOperation::insert); + } eigenvalues.resize (eigenfunctions.size ()); @@ -220,14 +226,11 @@ void test (std::string solver_name, preconditioner = new PETScWrappers::PreconditionJacobi(mpi_communicator); } - dealii::SolverControl linear_solver_control (dof_handler.n_dofs(), 1e-12,/*log_history*/false,/*log_results*/false); + dealii::SolverControl linear_solver_control (dof_handler.n_dofs(), 1e-15,/*log_history*/false,/*log_results*/false); PETScWrappers::SolverCG linear_solver(linear_solver_control,mpi_communicator); linear_solver.initialize(*preconditioner); - for (unsigned int i=0; i < eigenvalues.size(); i++) - eigenfunctions[i] = PetscScalar(); - - dealii::SolverControl solver_control (dof_handler.n_dofs(), 1e-9,/*log_history*/false,/*log_results*/false); + dealii::SolverControl solver_control (100, 1e-11,/*log_history*/false,/*log_results*/false); dealii::SLEPcWrappers::SolverBase *eigensolver; @@ -264,18 +267,16 @@ void test (std::string solver_name, mpi_communicator); } - SLEPcWrappers::TransformationShift spectral_transformation(mpi_communicator); + SLEPcWrappers::TransformationShiftInvert::AdditionalData additional_data(4.0); + SLEPcWrappers::TransformationShiftInvert spectral_transformation(mpi_communicator,additional_data); spectral_transformation.set_solver(linear_solver); eigensolver->set_transformation(spectral_transformation); - eigensolver->set_initial_vector(eigenfunctions[0]); + // Set the initial vector. This is optional, if not done the initial vector is set to random values + eigensolver->set_initial_space(eigenfunctions); eigensolver->set_which_eigenpairs (EPS_SMALLEST_REAL); eigensolver->set_problem_type (EPS_GHEP); - //zero constrained DoFs - for (unsigned int i=0; isolve (stiffness_matrix, mass_matrix, eigenvalues, @@ -294,7 +295,7 @@ void test (std::string solver_name, // a) (A*x_i-\lambda*B*x_i).L2() == 0 // b) x_j*B*x_i=\delta_{ij} { - const double precision = 1e-5; // ridiculously small... + const double precision = 1e-5; PETScWrappers::MPI::Vector Ax(eigenfunctions[0]), Bx(eigenfunctions[0]); for (unsigned int i=0; i < eigenfunctions.size(); ++i) { diff --git a/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output b/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output index 1da79e5f3c..0b44ab8366 100644 --- a/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output +++ b/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output @@ -1,7 +1,7 @@ DEAL::Jacobi DEAL::KrylovSchur -DEAL::outer iterations: 69 -DEAL::last inner iterations: 13 +DEAL::outer iterations: 3 +DEAL::last inner iterations: 33 DEAL::4.93877 DEAL::12.3707 DEAL::12.3707 @@ -10,8 +10,8 @@ DEAL::24.8370 DEAL::Ok DEAL::BlockJacobi DEAL::KrylovSchur -DEAL::outer iterations: 64 -DEAL::last inner iterations: 5 +DEAL::outer iterations: 3 +DEAL::last inner iterations: 58 DEAL::4.93877 DEAL::12.3707 DEAL::12.3707 @@ -20,11 +20,11 @@ DEAL::24.8370 DEAL::Ok DEAL::Boomer DEAL::KrylovSchur -DEAL::outer iterations: 63 -DEAL::last inner iterations: 19 +DEAL::outer iterations: 3 +DEAL::last inner iterations: 13 DEAL::4.93877 DEAL::12.3707 DEAL::12.3707 DEAL::19.8027 DEAL::24.8370 -DEAL::Ok +DEAL::Ok \ No newline at end of file diff --git a/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output.2 b/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output.2 new file mode 100644 index 0000000000..fa3f55b4e5 --- /dev/null +++ b/tests/slepc/step-36_parallel.with_mpi=true.with_petsc=true.with_slepc=true.mpirun=3.output.2 @@ -0,0 +1,30 @@ +DEAL::Jacobi +DEAL::KrylovSchur +DEAL::outer iterations: 3 +DEAL::last inner iterations: 28 +DEAL::4.93877 +DEAL::12.3707 +DEAL::12.3707 +DEAL::19.8027 +DEAL::24.8370 +DEAL::Ok +DEAL::BlockJacobi +DEAL::KrylovSchur +DEAL::outer iterations: 3 +DEAL::last inner iterations: 58 +DEAL::4.93877 +DEAL::12.3707 +DEAL::12.3707 +DEAL::19.8027 +DEAL::24.8370 +DEAL::Ok +DEAL::Boomer +DEAL::KrylovSchur +DEAL::outer iterations: 2 +DEAL::last inner iterations: 13 +DEAL::4.93877 +DEAL::12.3707 +DEAL::12.3707 +DEAL::19.8027 +DEAL::24.8370 +DEAL::Ok \ No newline at end of file -- 2.39.5