Date: 2021-02-01T14:42:00+00:00

Actual source code: test6.c
slepc-3.14.2 2021-02-01
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-2020, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: static char help[] = "Diagonal eigenproblem.\n\n"
     12:   "The command line options are:\n"
     13:   "  -n <n>, where <n> = matrix dimension.\n"
     14:   "  -seed <s>, where <s> = seed for random number generation.\n\n";

     16: #include <slepceps.h>

     18: int main(int argc,char **argv)
     19: {
     20:   Mat            A;           /* problem matrix */
     21:   EPS            eps;         /* eigenproblem solver context */
     22:   Vec            v0;          /* initial vector */
     23:   PetscRandom    rand;
     24:   PetscReal      tol=1000*PETSC_MACHINE_EPSILON;
     25:   PetscInt       n=30,i,Istart,Iend,seed=0x12345678;

     28:   SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

     30:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     31:   PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%D\n\n",n);

     33:   MatCreate(PETSC_COMM_WORLD,&A);
     34:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);
     35:   MatSetFromOptions(A);
     36:   MatSetUp(A);
     37:   MatGetOwnershipRange(A,&Istart,&Iend);
     38:   for (i=Istart;i<Iend;i++) {
     39:     MatSetValue(A,i,i,i+1,INSERT_VALUES);
     40:   }
     41:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     42:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

     44:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     45:                       Solve the eigensystem
     46:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     47:   EPSCreate(PETSC_COMM_WORLD,&eps);
     48:   EPSSetOperators(eps,A,NULL);
     49:   EPSSetProblemType(eps,EPS_HEP);
     50:   EPSSetTolerances(eps,tol,PETSC_DEFAULT);
     51:   EPSSetFromOptions(eps);
     52:   /* set random initial vector */
     53:   MatCreateVecs(A,&v0,NULL);
     54:   PetscRandomCreate(PETSC_COMM_WORLD,&rand);
     55:   PetscRandomSetFromOptions(rand);
     56:   PetscOptionsGetInt(NULL,NULL,"-seed",&seed,NULL);
     57:   PetscRandomSetSeed(rand,seed);
     58:   PetscRandomSeed(rand);
     59:   VecSetRandom(v0,rand);
     60:   EPSSetInitialSpace(eps,1,&v0);
     61:   /* call the solver */
     62:   EPSSolve(eps);

     64:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     65:                     Display solution and clean up
     66:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     67:   EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL);
     68:   EPSDestroy(&eps);
     69:   MatDestroy(&A);
     70:   VecDestroy(&v0);
     71:   PetscRandomDestroy(&rand);
     72:   SlepcFinalize();
     73:   return ierr;
     74: }

     76: /*TEST

     78:    testset:
     79:       args: -eps_nev 4
     80:       requires: !single
     81:       output_file: output/test6_1.out
     82:       test:
     83:          suffix: 1
     84:          args: -eps_type {{krylovschur subspace arnoldi gd}}
     85:       test:
     86:          suffix: 1_power
     87:          args: -eps_type power -eps_max_it 20000
     88:       test:
     89:          suffix: 1_gd2
     90:          args: -eps_type gd -eps_gd_double_expansion
     91:       test:
     92:          suffix: 1_arpack
     93:          args: -eps_type arpack
     94:          requires: arpack
     95:       test:
     96:          suffix: 1_trlan
     97:          args: -eps_type trlan
     98:          requires: trlan

    100: TEST*/