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

Actual source code: ex17.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[] = "Solves a polynomial eigenproblem P(l)x = 0 with matrices loaded from a file.\n\n"
     12:   "The command line options are:\n"
     13:   "-A <filename1,filename2, ...> , where <filename1,.. > = matrices A0 ... files in PETSc binary form.\n\n";

     15: #include <slepcpep.h>

     17: #define MAX_MATRICES 40

     19: int main(int argc,char **argv)
     20: {
     21:   Mat            A[MAX_MATRICES]; /* problem matrices */
     22:   PEP            pep;             /* polynomial eigenproblem solver context */
     23:   PetscReal      tol;
     24:   PetscInt       nev,maxit,its,nmat=MAX_MATRICES,i;
     25:   char*          filenames[MAX_MATRICES];
     26:   PetscViewer    viewer;
     27:   PetscBool      flg,terse;

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

     32:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     33:         Load the matrices that define the polynomial eigenproblem
     34:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     36:   PetscPrintf(PETSC_COMM_WORLD,"\nPolynomial eigenproblem stored in file.\n\n");
     37: #if defined(PETSC_USE_COMPLEX)
     38:   PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrices from binary files...\n");
     39: #else
     40:   PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrices from binary files...\n");
     41: #endif
     42:   PetscOptionsGetStringArray(NULL,NULL,"-A",filenames,&nmat,&flg);
     43:   if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate a comma-separated list of file names with the -A option");
     44:   for (i=0;i<nmat;i++) {
     45:     PetscViewerBinaryOpen(PETSC_COMM_WORLD,filenames[i],FILE_MODE_READ,&viewer);
     46:     MatCreate(PETSC_COMM_WORLD,&A[i]);
     47:     MatSetFromOptions(A[i]);
     48:     MatLoad(A[i],viewer);
     49:     PetscViewerDestroy(&viewer);
     50:   }
     51:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     52:                 Create the eigensolver and set various options
     53:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     55:   /*
     56:      Create eigensolver context
     57:   */
     58:   PEPCreate(PETSC_COMM_WORLD,&pep);

     60:   /*
     61:      Set matrices
     62:   */
     63:   PEPSetOperators(pep,nmat,A);
     64:   /*
     65:      Set solver parameters at runtime
     66:   */
     67:   PEPSetFromOptions(pep);

     69:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     70:                       Solve the eigensystem
     71:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     73:   PEPSolve(pep);
     74:   PEPGetIterationNumber(pep,&its);
     75:   PetscPrintf(PETSC_COMM_WORLD," Number of iterations of the method: %D\n",its);

     77:   /*
     78:      Optional: Get some information from the solver and display it
     79:   */
     80:   PEPGetDimensions(pep,&nev,NULL,NULL);
     81:   PetscPrintf(PETSC_COMM_WORLD," Number of requested eigenvalues: %D\n",nev);
     82:   PEPGetTolerances(pep,&tol,&maxit);
     83:   PetscPrintf(PETSC_COMM_WORLD," Stopping condition: tol=%.4g, maxit=%D\n",(double)tol,maxit);

     85:   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     86:                     Display solution and clean up
     87:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

     89:   /* show detailed info unless -terse option is given by user */
     90:   PetscOptionsHasName(NULL,NULL,"-terse",&terse);
     91:   if (terse) {
     92:     PEPErrorView(pep,PEP_ERROR_BACKWARD,NULL);
     93:   } else {
     94:     PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
     95:     PEPConvergedReasonView(pep,PETSC_VIEWER_STDOUT_WORLD);
     96:     PEPErrorView(pep,PEP_ERROR_BACKWARD,PETSC_VIEWER_STDOUT_WORLD);
     97:     PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
     98:   }
     99:   PEPDestroy(&pep);
    100:   for (i=0;i<nmat;i++) {
    101:     MatDestroy(&A[i]);
    102:     PetscFree(filenames[i]);
    103:   }
    104:   SlepcFinalize();
    105:   return ierr;
    106: }

    108: /*TEST

    110:    test:
    111:       suffix: 1
    112:       args: -A ${SLEPC_DIR}/share/slepc/datafiles/matrices/speaker107k.petsc,${SLEPC_DIR}/share/slepc/datafiles/matrices/speaker107c.petsc,${SLEPC_DIR}/share/slepc/datafiles/matrices/speaker107m.petsc -pep_type {{toar qarnoldi linear}} -pep_nev 4 -pep_ncv 20 -pep_scale scalar -terse
    113:       requires: double !complex !define(PETSC_USE_64BIT_INDICES)

    115: TEST*/