<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi all, I am currently developing a code in C++ and I try to use SLEPC in conjunction with PETSC to solve an eigenvalue problem. Considering I have a set of similar matrices, my strategy was to solve one problem, and then reuse the starting vector to accelerate the resolution of the next problems. I tested this strategy with a rudimentary code to validate the process, but it does not seems to work. I am afraid I do not fully understand some of the particularities of SLEPC or PETSC. The main.cpp fille of my code goes like this: (see at the bottom of this message). You can see that I create a matrix (A) and two eigensolver contexts (eps and eps2). First a try to solve the problem using eps. I then recall the invariant subspace and use it as a starting vector in eps2. This code seems to work, but eps2 takes systematically more time to converge than eps. Is there something wrong with this code or my understanding of how SLEPC/PETSC works? Thank you,<div class=""><br class=""></div><div class="">Marc<br class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(0, 0, 128);" class="">#include</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">"slepceps.h"</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(128, 128, 0);" class="">int</span><span style="color: rgb(192, 192, 192);" class=""> </span>main(<span style="color: rgb(128, 128, 0);" class="">int</span><span style="color: rgb(192, 192, 192);" class=""> </span>argc,<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">char</span><span style="color: rgb(192, 192, 192);" class=""> </span>*argv[])</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class="">{</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">static</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">char</span><span style="color: rgb(192, 192, 192);" class=""> </span>help[]<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">"Simple</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">Hello</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">World</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">example</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">program</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">in</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">SLEPc\n"</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>Mat<span style="color: rgb(192, 192, 192);" class=""> </span>A;<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">/*</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">problem</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">matrix</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">*/</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPS<span style="color: rgb(192, 192, 192);" class=""> </span>eps;<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">/*</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">eigenproblem</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">solver</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">context</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">*/</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPS<span style="color: rgb(192, 192, 192);" class=""> </span>eps2;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSType<span style="color: rgb(192, 192, 192);" class=""> </span>type;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>PetscReal<span style="color: rgb(192, 192, 192);" class=""> </span>error,tol,re,im;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>PetscScalar<span style="color: rgb(192, 192, 192);" class=""> </span>kr,ki;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>Vec<span style="color: rgb(192, 192, 192);" class=""> </span>xr,xi;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>PetscInt<span style="color: rgb(192, 192, 192);" class=""> </span>n=<span style="color: rgb(0, 0, 128);" class="">30</span>,i,Istart,Iend,nev,maxit,its,nconv;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>PetscErrorCode<span style="color: rgb(192, 192, 192);" class=""> </span>ierr;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class="">PetscInt<span style="color: rgb(192, 192, 192);" class=""> </span>a,b,c;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>SlepcInitialize(&argc,&argv,(<span style="color: rgb(128, 128, 0);" class="">char</span>*)<span style="color: rgb(0, 0, 128);" class="">0</span>,help);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>PetscOptionsGetInt(NULL,<span style="color: rgb(0, 128, 0);" class="">"-n"</span>,&n,NULL);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">/*</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">Create</span><span style="color: rgb(192, 192, 192);" class=""> </span><font color="#008000" class="">matrix</font></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">*/</span></pre><div class=""><br class=""></div></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatCreateDense(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,n,n,NULL,&A);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">for</span><span style="color: rgb(192, 192, 192);" class=""> </span>(i=Istart;i<Iend;i++)<span style="color: rgb(192, 192, 192);" class=""> </span>{</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">if</span><span style="color: rgb(192, 192, 192);" class=""> </span>(i><span style="color: rgb(0, 0, 128);" class="">0</span>)<span style="color: rgb(192, 192, 192);" class=""> </span>{<span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatSetValue(A,i,i-<span style="color: rgb(0, 0, 128);" class="">1</span>,-<span style="color: rgb(0, 0, 128);" class="">1.0</span>,INSERT_VALUES);CHKERRQ(ierr);<span style="color: rgb(192, 192, 192);" class=""> </span>}</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">if</span><span style="color: rgb(192, 192, 192);" class=""> </span>(i<n-<span style="color: rgb(0, 0, 128);" class="">1</span>)<span style="color: rgb(192, 192, 192);" class=""> </span>{<span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatSetValue(A,i,i+<span style="color: rgb(0, 0, 128);" class="">1</span>,-<span style="color: rgb(0, 0, 128);" class="">1.0</span>,INSERT_VALUES);CHKERRQ(ierr);<span style="color: rgb(192, 192, 192);" class=""> </span>}</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatSetValue(A,i,i,<span style="color: rgb(0, 0, 128);" class="">2.0</span>,INSERT_VALUES);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>}</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatCreateVecs(A,NULL,&xr);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatCreateVecs(A,NULL,&xi);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">/*</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">Create</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">the</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">eigensolver</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">and</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">set</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">various</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">options</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">-</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">*/</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">/*</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">Create</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">eigensolver</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">context</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">*/</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSCreate(PETSC_COMM_WORLD,&eps);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetOperators(eps,A,NULL);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetProblemType(eps,EPS_HEP);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>its<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 0, 128);" class="">4000</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetTolerances(eps,PETSC_DEFAULT,its);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>nev<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>(<span style="color: rgb(128, 128, 0);" class="">int</span>)n/<span style="color: rgb(0, 0, 128);" class="">2</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetType(eps,EPSKRYLOVSCHUR);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetDimensions(eps,nev,n,n);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetWhichEigenpairs(eps,EPS_SMALLEST_MAGNITUDE);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetFromOptions(eps);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSolve(eps);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSGetConverged(eps,&nconv);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""> </pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class="">PetscInt<span style="color: rgb(192, 192, 192);" class=""> </span>nbr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>nconv;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>Vec<span style="color: rgb(192, 192, 192);" class=""> </span>subspace;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>VecCreate(PETSC_COMM_WORLD,&subspace);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>VecSetSizes(subspace,PETSC_DECIDE,n);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>VecSetFromOptions(subspace);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>Vec<span style="color: rgb(192, 192, 192);" class=""> </span>*sub;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>VecDuplicateVecs(subspace,nbr,&sub);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>EPSGetInvariantSubspace(eps,sub);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSDestroy(&eps);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSCreate(PETSC_COMM_WORLD,&eps2);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetInitialSpace(eps2,nbr,sub);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetOperators(eps2,A,NULL);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetProblemType(eps2,EPS_HEP);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>its<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 0, 128);" class="">4000</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetTolerances(eps2,PETSC_DEFAULT,its);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>nev<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>(<span style="color: rgb(128, 128, 0);" class="">int</span>)n/<span style="color: rgb(0, 0, 128);" class="">2</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetType(eps2,EPSKRYLOVSCHUR);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetDimensions(eps2,nev,n,n);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetWhichEigenpairs(eps2,EPS_SMALLEST_MAGNITUDE);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSetFromOptions(eps2);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSSolve(eps2);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">//</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">ierr</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">=</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 128, 0);" class="">EPSGetConverged(eps2,&nconv);CHKERRQ(ierr);</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class="">ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>EPSDestroy(&eps2);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>MatDestroy(&A);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>VecDestroy(&xr);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>VecDestroy(&xi);CHKERRQ(ierr);</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span>ierr<span style="color: rgb(192, 192, 192);" class=""> </span>=<span style="color: rgb(192, 192, 192);" class=""> </span>SlepcFinalize();</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(128, 128, 0);" class="">return</span><span style="color: rgb(192, 192, 192);" class=""> </span><span style="color: rgb(0, 0, 128);" class="">0</span>;</pre><pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></pre><pre style="margin-top: 0px; margin-bottom: 0px;" class="">}</pre></div><div class=""><br class=""></div></div></body></html>