Line | Branch | Exec | Source |
---|---|---|---|
1 | ! | ||
2 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
3 | ! SLEPc - Scalable Library for Eigenvalue Problem Computations | ||
4 | ! Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain | ||
5 | ! | ||
6 | ! This file is part of SLEPc. | ||
7 | ! SLEPc is distributed under a 2-clause BSD license (see LICENSE). | ||
8 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
9 | ! | ||
10 | ! Program usage: mpiexec -n <np> ./test7f [-help] [-n <n>] [all SLEPc options] | ||
11 | ! | ||
12 | ! Description: Simple example that solves an eigensystem with the EPS object. | ||
13 | ! Same problem as ex1f but with simplified output. | ||
14 | ! | ||
15 | ! The command line options are: | ||
16 | ! -n <n>, where <n> = number of grid points = matrix size | ||
17 | ! | ||
18 | ! ---------------------------------------------------------------------- | ||
19 | ! | ||
20 | 6 | program main | |
21 | #include <slepc/finclude/slepceps.h> | ||
22 | 6 | use slepceps | |
23 | implicit none | ||
24 | |||
25 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
26 | ! Declarations | ||
27 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
28 | ! | ||
29 | ! Variables: | ||
30 | ! A operator matrix | ||
31 | ! eps eigenproblem solver context | ||
32 | |||
33 | Mat A | ||
34 | EPS eps | ||
35 | EPSType tname | ||
36 | PetscInt n, i, Istart, Iend | ||
37 | PetscInt nev, nini | ||
38 | PetscInt col(3) | ||
39 | PetscInt i0, i1, i2, i3 | ||
40 | PetscMPIInt rank | ||
41 | PetscErrorCode ierr | ||
42 | PetscBool flg | ||
43 | PetscScalar value(3), one | ||
44 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | Vec v(1) |
45 | |||
46 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
47 | ! Beginning of program | ||
48 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
49 | |||
50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER,ierr)) |
51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)) |
52 | 6 | n = 30 | |
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr)) |
54 | |||
55 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank .eq. 0) then |
56 | 6 | write(*,100) n | |
57 | endif | ||
58 | 100 format (/'1-D Laplacian Eigenproblem, n =',I3,' (Fortran)') | ||
59 | |||
60 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
61 | ! Compute the operator matrix that defines the eigensystem, Ax=kx | ||
62 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
63 | |||
64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatCreate(PETSC_COMM_WORLD,A,ierr)) |
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n,ierr)) |
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetFromOptions(A,ierr)) |
67 | |||
68 | 6 | i0 = 0 | |
69 | 6 | i1 = 1 | |
70 | 6 | i2 = 2 | |
71 | 6 | i3 = 3 | |
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatGetOwnershipRange(A,Istart,Iend,ierr)) |
73 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Istart .eq. 0) then |
74 | 6 | i = 0 | |
75 | 6 | col(1) = 0 | |
76 | 6 | col(2) = 1 | |
77 | 6 | value(1) = 2.0 | |
78 | 6 | value(2) = -1.0 | |
79 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 | PetscCallA(MatSetValues(A,i1,[i],i2,col,value,INSERT_VALUES,ierr)) |
80 | 6 | Istart = Istart+1 | |
81 | endif | ||
82 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Iend .eq. n) then |
83 | 6 | i = n-1 | |
84 | 6 | col(1) = n-2 | |
85 | 6 | col(2) = n-1 | |
86 | 6 | value(1) = -1.0 | |
87 | 6 | value(2) = 2.0 | |
88 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 | PetscCallA(MatSetValues(A,i1,[i],i2,col,value,INSERT_VALUES,ierr)) |
89 | 6 | Iend = Iend-1 | |
90 | endif | ||
91 | 6 | value(1) = -1.0 | |
92 | 6 | value(2) = 2.0 | |
93 | 6 | value(3) = -1.0 | |
94 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
174 | do i=Istart,Iend-1 |
95 | 168 | col(1) = i-1 | |
96 | 168 | col(2) = i | |
97 | 168 | col(3) = i+1 | |
98 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
342 | PetscCallA(MatSetValues(A,i1,[i],i3,col,value,INSERT_VALUES,ierr)) |
99 | enddo | ||
100 | |||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)) |
102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)) |
103 | |||
104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatCreateVecs(A,v(1),PETSC_NULL_VEC,ierr)) |
105 | 6 | one = 1.0 | |
106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (Istart .eq. 0) then |
107 | ✗ | PetscCallA(VecSetValue(v(1),i0,one,INSERT_VALUES,ierr)) | |
108 | endif | ||
109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(VecAssemblyBegin(v(1),ierr)) |
110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(VecAssemblyEnd(v(1),ierr)) |
111 | |||
112 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
113 | ! Create the eigensolver and display info | ||
114 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
115 | |||
116 | ! ** Create eigensolver context | ||
117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSCreate(PETSC_COMM_WORLD,eps,ierr)) |
118 | |||
119 | ! ** Set operators. In this case, it is a standard eigenvalue problem | ||
120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetOperators(eps,A,PETSC_NULL_MAT,ierr)) |
121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetProblemType(eps,EPS_HEP,ierr)) |
122 | |||
123 | ! ** Set solver parameters at runtime | ||
124 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetFromOptions(eps,ierr)) |
125 | |||
126 | ! ** Set initial vectors | ||
127 | 6 | nini = 1 | |
128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetInitialSpace(eps,nini,v,ierr)) |
129 | |||
130 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
131 | ! Solve the eigensystem | ||
132 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
133 | |||
134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSolve(eps,ierr)) |
135 | |||
136 | ! ** Optional: Get some information from the solver and display it | ||
137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetType(eps,tname,ierr)) |
138 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank .eq. 0) then |
139 | 6 | write(*,120) tname | |
140 | endif | ||
141 | 120 format (' Solution method: ',A) | ||
142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetDimensions(eps,nev,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,ierr)) |
143 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank .eq. 0) then |
144 | 6 | write(*,130) nev | |
145 | endif | ||
146 | 130 format (' Number of requested eigenvalues:',I2) | ||
147 | |||
148 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
149 | ! Display solution and clean up | ||
150 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
151 | |||
152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_NULL_VIEWER,ierr)) |
153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSDestroy(eps,ierr)) |
154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatDestroy(A,ierr)) |
155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(VecDestroy(v(1),ierr)) |
156 | |||
157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
6 | PetscCallA(SlepcFinalize(ierr)) |
158 | 1 | end | |
159 | |||
160 | !/*TEST | ||
161 | ! | ||
162 | ! test: | ||
163 | ! suffix: 1 | ||
164 | ! args: -eps_nev 4 -eps_ncv 19 | ||
165 | ! filter: sed -e "s/83791/83792/" | ||
166 | ! | ||
167 | !TEST*/ | ||
168 |