| 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> ./test15f [-help] [-n <n>] [all SLEPc options] | ||
| 11 | ! | ||
| 12 | ! Description: Tests custom monitors from Fortran. | ||
| 13 | ! | ||
| 14 | ! The command line options are: | ||
| 15 | ! -n <n>, where <n> = number of grid points = matrix size | ||
| 16 | ! -my_eps_monitor, activates the custom monitor | ||
| 17 | ! | ||
| 18 | ! ---------------------------------------------------------------------- | ||
| 19 | ! | ||
| 20 | #include <slepc/finclude/slepceps.h> | ||
| 21 | |||
| 22 | module test15fmodule | ||
| 23 | use slepceps | ||
| 24 | implicit none | ||
| 25 | |||
| 26 | contains | ||
| 27 | ! -------------------------------------------------------------- | ||
| 28 | ! MyEPSMonitor - This is a user-defined routine for monitoring | ||
| 29 | ! the EPS iterative solvers. | ||
| 30 | ! | ||
| 31 | ! Input Parameters: | ||
| 32 | ! eps - eigensolver context | ||
| 33 | ! its - iteration number | ||
| 34 | ! nconv - number of converged eigenpairs | ||
| 35 | ! eigr - real part of the eigenvalues | ||
| 36 | ! eigi - imaginary part of the eigenvalues | ||
| 37 | ! errest- relative error estimates for each eigenpair | ||
| 38 | ! nest - number of error estimates | ||
| 39 | ! dummy - optional user-defined monitor context (unused here) | ||
| 40 | ! | ||
| 41 | 20 | subroutine MyEPSMonitor(eps, its, nconv, eigr, eigi, errest, nest, dummy, ierr) | |
| 42 | use slepceps | ||
| 43 | implicit none | ||
| 44 | |||
| 45 | EPS :: eps | ||
| 46 | PetscInt :: its, nconv, nest, dummy | ||
| 47 | PetscScalar :: eigr(*), eigi(*) | ||
| 48 | PetscReal :: re, errest(*) | ||
| 49 | PetscMPIInt :: rank | ||
| 50 | PetscErrorCode, intent(out) :: ierr | ||
| 51 | |||
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
20 | PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 53 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
20 | if (its > 0 .and. rank == 0) then |
| 54 | 20 | re = PetscRealPart(eigr(nconv + 1)) | |
| 55 | 20 | write (6, '(i3,a,i2,a,f7.4,a,g10.3,a)') its, ' EPS nconv=', nconv, ' first unconverged value (error) ', re, ' (', errest(nconv + 1), ')' | |
| 56 | end if | ||
| 57 | 20 | ierr = 0 | |
| 58 | end subroutine | ||
| 59 | |||
| 60 | end module test15fmodule | ||
| 61 | |||
| 62 | 62 | program test15f | |
| 63 | 5 | use slepceps | |
| 64 | use test15fmodule | ||
| 65 | implicit none | ||
| 66 | |||
| 67 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 68 | ! Declarations | ||
| 69 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 70 | ! | ||
| 71 | Mat :: A ! operator matrix | ||
| 72 | EPS :: eps ! eigenproblem solver context | ||
| 73 | EPSType :: tname | ||
| 74 | PetscInt :: n, i, Istart, Iend, nev | ||
| 75 | PetscInt :: col(3) | ||
| 76 | PetscInt :: i1, i2, i3 | ||
| 77 | PetscMPIInt :: rank | ||
| 78 | PetscErrorCode :: ierr | ||
| 79 | PetscBool :: flg | ||
| 80 | PetscScalar :: val(3) | ||
| 81 | |||
| 82 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 83 | ! Beginning of program | ||
| 84 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 85 | |||
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER, ierr)) |
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 88 | 5 | n = 30 | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr)) |
| 90 | |||
| 91 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 92 | 5 | write (*, '(/a,i3,a)') '1-D Laplacian Eigenproblem, n =', n, ' (Fortran)' | |
| 93 | end if | ||
| 94 | |||
| 95 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 96 | ! Compute the operator matrix that defines the eigensystem, Ax=kx | ||
| 97 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 98 | |||
| 99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatCreate(PETSC_COMM_WORLD, A, ierr)) |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n, ierr)) |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetFromOptions(A, ierr)) |
| 102 | |||
| 103 | 5 | i1 = 1 | |
| 104 | 5 | i2 = 2 | |
| 105 | 5 | i3 = 3 | |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatGetOwnershipRange(A, Istart, Iend, ierr)) |
| 107 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (Istart == 0) then |
| 108 | 5 | i = 0 | |
| 109 | 5 | col(1) = 0 | |
| 110 | 5 | col(2) = 1 | |
| 111 | 5 | val(1) = 2.0 | |
| 112 | 5 | val(2) = -1.0 | |
| 113 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
10 | PetscCallA(MatSetValues(A, i1, [i], i2, col, val, INSERT_VALUES, ierr)) |
| 114 | 5 | Istart = Istart + 1 | |
| 115 | end if | ||
| 116 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (Iend == n) then |
| 117 | 5 | i = n - 1 | |
| 118 | 5 | col(1) = n - 2 | |
| 119 | 5 | col(2) = n - 1 | |
| 120 | 5 | val(1) = -1.0 | |
| 121 | 5 | val(2) = 2.0 | |
| 122 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
10 | PetscCallA(MatSetValues(A, i1, [i], i2, col, val, INSERT_VALUES, ierr)) |
| 123 | 5 | Iend = Iend - 1 | |
| 124 | end if | ||
| 125 | 5 | val(1) = -1.0 | |
| 126 | 5 | val(2) = 2.0 | |
| 127 | 5 | val(3) = -1.0 | |
| 128 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
145 | do i = Istart, Iend - 1 |
| 129 | 140 | col(1) = i - 1 | |
| 130 | 140 | col(2) = i | |
| 131 | 140 | col(3) = i + 1 | |
| 132 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
285 | PetscCallA(MatSetValues(A, i1, [i], i3, col, val, INSERT_VALUES, ierr)) |
| 133 | end do | ||
| 134 | |||
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 137 | |||
| 138 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 139 | ! Create the eigensolver and display info | ||
| 140 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 141 | |||
| 142 | ! ** Create eigensolver context | ||
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSCreate(PETSC_COMM_WORLD, eps, ierr)) |
| 144 | |||
| 145 | ! ** Set operators. In this case, it is a standard eigenvalue problem | ||
| 146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetOperators(eps, A, PETSC_NULL_MAT, ierr)) |
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetProblemType(eps, EPS_HEP, ierr)) |
| 148 | |||
| 149 | ! ** Set user-defined monitor | ||
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(PetscOptionsHasName(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-my_eps_monitor', flg, ierr)) |
| 151 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (flg) then |
| 152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSMonitorSet(eps, MyEPSMonitor, 0, PETSC_NULL_FUNCTION, ierr)) |
| 153 | end if | ||
| 154 | |||
| 155 | ! ** Set solver parameters at runtime | ||
| 156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetFromOptions(eps, ierr)) |
| 157 | |||
| 158 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 159 | ! Solve the eigensystem | ||
| 160 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 161 | |||
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSolve(eps, ierr)) |
| 163 | |||
| 164 | ! ** Optional: Get some information from the solver and display it | ||
| 165 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSGetType(eps, tname, ierr)) |
| 166 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 167 | 5 | write (*, '(a,a)') ' Solution method: ', tname | |
| 168 | end if | ||
| 169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSGetDimensions(eps, nev, PETSC_NULL_INTEGER, PETSC_NULL_INTEGER, ierr)) |
| 170 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 171 | 5 | write (*, '(a,i2)') ' Number of requested eigenvalues:', nev | |
| 172 | end if | ||
| 173 | |||
| 174 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 175 | ! Display solution and clean up | ||
| 176 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 177 | |||
| 178 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_NULL_VIEWER, ierr)) |
| 179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSDestroy(eps, ierr)) |
| 180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatDestroy(A, ierr)) |
| 181 | |||
| 182 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
5 | PetscCallA(SlepcFinalize(ierr)) |
| 183 | ✗ | end program test15f | |
| 184 | |||
| 185 | !/*TEST | ||
| 186 | ! | ||
| 187 | ! test: | ||
| 188 | ! suffix: 1 | ||
| 189 | ! args: -my_eps_monitor | ||
| 190 | ! requires: double | ||
| 191 | ! | ||
| 192 | !TEST*/ | ||
| 193 |