Actual source code: test19.c
slepc-3.19.2 2023-09-05
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-, 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[] = "Tests the usage of object prefix.\n\n"
12: "The command line options are:\n"
13: " -n <n>, where <n> = matrix dimension.\n\n";
15: #include <slepceps.h>
17: int main(int argc,char **argv)
18: {
19: Mat A; /* problem matrix */
20: EPS eps; /* eigenproblem solver context */
21: PetscInt n=30,i,Istart,Iend;
22: const char *prefix;
24: PetscFunctionBeginUser;
25: PetscCall(SlepcInitialize(&argc,&argv,(char*)0,help));
27: PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL));
28: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%" PetscInt_FMT "\n\n",n));
30: PetscCall(MatCreate(PETSC_COMM_WORLD,&A));
31: PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n));
32: PetscCall(MatSetFromOptions(A));
33: PetscCall(MatSetUp(A));
34: PetscCall(MatGetOwnershipRange(A,&Istart,&Iend));
35: for (i=Istart;i<Iend;i++) PetscCall(MatSetValue(A,i,i,i+1,INSERT_VALUES));
36: PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY));
37: PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY));
39: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40: Create the eigensolver and mess up with the prefix
41: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
42: PetscCall(EPSCreate(PETSC_COMM_WORLD,&eps));
43: PetscCall(EPSSetOptionsPrefix(eps,"check_"));
44: PetscCall(EPSAppendOptionsPrefix(eps,"myprefix_"));
45: PetscCall(EPSGetOptionsPrefix(eps,&prefix));
46: PetscCall(PetscPrintf(PETSC_COMM_WORLD,"EPS prefix is currently: %s\n\n",prefix));
48: PetscCall(EPSSetOperators(eps,A,NULL));
49: PetscCall(EPSSetProblemType(eps,EPS_HEP));
50: PetscCall(EPSSetFromOptions(eps));
51: PetscCall(EPSSolve(eps));
53: /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54: Display solution and clean up
55: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
56: PetscCall(EPSErrorView(eps,EPS_ERROR_RELATIVE,NULL));
57: PetscCall(EPSDestroy(&eps));
58: PetscCall(MatDestroy(&A));
59: PetscCall(SlepcFinalize());
60: return 0;
61: }
63: /*TEST
65: test:
66: suffix: 1
67: args: -check_myprefix_eps_nev 2 -check_myprefix_st_type sinvert
69: TEST*/