GCC Code Coverage Report


Directory: ./
File: src/mfn/tests/test3f.F90
Date: 2025-10-03 04:28:47
Exec Total Coverage
Lines: 77 77 100.0%
Functions: 2 2 100.0%
Branches: 59 108 54.6%

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> ./test3f [-help] [-n <n>] [all SLEPc options]
11 !
12 ! Description: square root of the 2-D Laplacian.
13 !
14 ! The command line options are:
15 ! -n <n>, where <n> = matrix rows and columns
16 !
17 ! ----------------------------------------------------------------------
18 !
19 8 program main
20 #include <slepc/finclude/slepcmfn.h>
21 6 use slepcmfn
22 implicit none
23
24 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 ! Declarations
26 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27 !
28 Mat A, B
29 MFN mfn
30 FN f
31 MFNConvergedReason reason
32 Vec v, y
33 PetscInt Nt, n, i, j, II
34 PetscInt Istart, maxit, ncv
35 PetscInt col, its, Iend
36 PetscScalar val
37 PetscReal tol, norm
38 PetscMPIInt rank
39 PetscErrorCode ierr
40 PetscBool flg
41
42 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 ! Beginning of program
44 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER,ierr))
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr))
48 6 n = 4
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr))
50 6 Nt = n*n
51
52
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (rank .eq. 0) then
53 6 write(*,100) n
54 endif
55 100 format (/'nSquare root of Laplacian, n=',I3,' (Fortran)')
56
57 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 ! Compute the discrete 2-D Laplacian
59 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatCreate(PETSC_COMM_WORLD,A,ierr))
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,Nt,Nt,ierr))
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatSetFromOptions(A,ierr))
64
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatGetOwnershipRange(A,Istart,Iend,ierr))
66
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
102 do II=Istart,Iend-1
67 96 i = II/n
68 96 j = II-i*n
69 96 val = -1.0
70
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
96 if (i .gt. 0) then
71 72 col = II-n
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
72 PetscCallA(MatSetValue(A,II,col,val,INSERT_VALUES,ierr))
73 end if
74
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
96 if (i .lt. n-1) then
75 72 col = II+n
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
72 PetscCallA(MatSetValue(A,II,col,val,INSERT_VALUES,ierr))
77 end if
78
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
96 if (j .gt. 0) then
79 72 col = II-1
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
72 PetscCallA(MatSetValue(A,II,col,val,INSERT_VALUES,ierr))
81 end if
82
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
96 if (j .lt. n-1) then
83 72 col = II+1
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
72 PetscCallA(MatSetValue(A,II,col,val,INSERT_VALUES,ierr))
85 end if
86 96 val = 4.0
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
102 PetscCallA(MatSetValue(A,II,II,val,INSERT_VALUES,ierr))
88 enddo
89
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))
92
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatCreateVecs(A,PETSC_NULL_VEC,v,ierr))
94 6 i = 0
95 6 val = 1.0
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecSetValue(v,i,val,INSERT_VALUES,ierr))
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecAssemblyBegin(v,ierr))
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecAssemblyEnd(v,ierr))
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecDuplicate(v,y,ierr))
100
101 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 ! Compute singular values
103 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNCreate(PETSC_COMM_WORLD,mfn,ierr))
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetOperator(mfn,A,ierr))
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetFN(mfn,f,ierr))
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(FNSetType(f,FNSQRT,ierr))
109
110 ! ** test some interface functions
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetOperator(mfn,B,ierr))
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatView(B,PETSC_VIEWER_STDOUT_WORLD,ierr))
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetOptionsPrefix(mfn,'myprefix_',ierr))
114 6 tol = 1e-4
115 6 maxit = 500
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetTolerances(mfn,tol,maxit,ierr))
117 6 ncv = 6
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetDimensions(mfn,ncv,ierr))
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetErrorIfNotConverged(mfn,PETSC_TRUE,ierr))
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSetFromOptions(mfn,ierr))
121
122 ! ** query properties and print them
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetTolerances(mfn,tol,maxit,ierr))
124
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (rank .eq. 0) then
125 6 write(*,110) tol,maxit
126 endif
127 110 format (/' Tolerance: ',F7.4,', maxit: ',I4)
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetDimensions(mfn,ncv,ierr))
129
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (rank .eq. 0) then
130 6 write(*,120) ncv
131 endif
132 120 format (' Subspace dimension: ',I3)
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetErrorIfNotConverged(mfn,flg,ierr))
134
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (rank .eq. 0 .and. flg) then
135 6 write(*,*) 'Erroring out if convergence fails'
136 endif
137
138 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
139 ! Call the solver
140 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNSolve(mfn,v,y,ierr))
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetConvergedReason(mfn,reason,ierr))
144
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (rank .eq. 0) then
145 6 write(*,130) reason
146 endif
147 130 format (' Converged reason:',I2)
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNGetIterationNumber(mfn,its,ierr))
149 ! if (rank .eq. 0) then
150 ! write(*,140) its
151 ! endif
152 !140 format (' Number of iterations of the method:',I4)
153
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecNorm(y,NORM_2,norm,ierr))
155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (rank .eq. 0) then
156 6 write(*,150) norm
157 endif
158 150 format (' sqrt(A)*v has norm ',F7.4)
159
160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MFNDestroy(mfn,ierr))
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(MatDestroy(A,ierr))
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecDestroy(v,ierr))
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 PetscCallA(VecDestroy(y,ierr))
164
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
6 PetscCallA(SlepcFinalize(ierr))
166 1 end
167
168 !/*TEST
169 !
170 ! test:
171 ! suffix: 1
172 ! args: -log_exclude mfn
173 !
174 !TEST*/
175