| 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 | 24 | subroutine MyEPSMonitor(eps, its, nconv, eigr, eigi, errest, nest, dummy, ierr) | |
| 42 | use slepceps | ||
| 43 | implicit none | ||
| 44 | |||
| 45 | EPS :: eps | ||
| 46 | PetscErrorCode :: ierr | ||
| 47 | PetscInt :: its, nconv, nest, dummy | ||
| 48 | PetscScalar :: eigr(*), eigi(*) | ||
| 49 | PetscReal :: re, errest(*) | ||
| 50 | PetscMPIInt :: rank | ||
| 51 | |||
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
24 | PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 53 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
24 | if (its > 0 .and. rank == 0) then |
| 54 | 24 | re = PetscRealPart(eigr(nconv + 1)) | |
| 55 | 24 | 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 | 24 | ierr = 0 | |
| 58 | end subroutine | ||
| 59 | |||
| 60 | end module test15fmodule | ||
| 61 | |||
| 62 | 8 | program test15f | |
| 63 | 6 | 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 | ||
| 75 | PetscInt nev | ||
| 76 | PetscInt col(3) | ||
| 77 | PetscInt i1, i2, i3 | ||
| 78 | PetscMPIInt rank | ||
| 79 | PetscErrorCode ierr | ||
| 80 | PetscBool flg | ||
| 81 | PetscScalar value(3) | ||
| 82 | |||
| 83 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 84 | ! Beginning of program | ||
| 85 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 86 | |||
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER, ierr)) |
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 89 | 6 | n = 30 | |
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr)) |
| 91 | |||
| 92 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 93 | 6 | write (*, '(/a,i3,a)') '1-D Laplacian Eigenproblem, n =', n, ' (Fortran)' | |
| 94 | end if | ||
| 95 | |||
| 96 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 97 | ! Compute the operator matrix that defines the eigensystem, Ax=kx | ||
| 98 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 99 | |||
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatCreate(PETSC_COMM_WORLD, A, ierr)) |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n, ierr)) |
| 102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetFromOptions(A, ierr)) |
| 103 | |||
| 104 | 6 | i1 = 1 | |
| 105 | 6 | i2 = 2 | |
| 106 | 6 | i3 = 3 | |
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatGetOwnershipRange(A, Istart, Iend, ierr)) |
| 108 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Istart == 0) then |
| 109 | 6 | i = 0 | |
| 110 | 6 | col(1) = 0 | |
| 111 | 6 | col(2) = 1 | |
| 112 | 6 | value(1) = 2.0 | |
| 113 | 6 | value(2) = -1.0 | |
| 114 |
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)) |
| 115 | 6 | Istart = Istart + 1 | |
| 116 | end if | ||
| 117 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Iend == n) then |
| 118 | 6 | i = n - 1 | |
| 119 | 6 | col(1) = n - 2 | |
| 120 | 6 | col(2) = n - 1 | |
| 121 | 6 | value(1) = -1.0 | |
| 122 | 6 | value(2) = 2.0 | |
| 123 |
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)) |
| 124 | 6 | Iend = Iend - 1 | |
| 125 | end if | ||
| 126 | 6 | value(1) = -1.0 | |
| 127 | 6 | value(2) = 2.0 | |
| 128 | 6 | value(3) = -1.0 | |
| 129 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
174 | do i = Istart, Iend - 1 |
| 130 | 168 | col(1) = i - 1 | |
| 131 | 168 | col(2) = i | |
| 132 | 168 | col(3) = i + 1 | |
| 133 |
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)) |
| 134 | end do | ||
| 135 | |||
| 136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 138 | |||
| 139 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 140 | ! Create the eigensolver and display info | ||
| 141 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 142 | |||
| 143 | ! ** Create eigensolver context | ||
| 144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSCreate(PETSC_COMM_WORLD, eps, ierr)) |
| 145 | |||
| 146 | ! ** Set operators. In this case, it is a standard eigenvalue problem | ||
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetOperators(eps, A, PETSC_NULL_MAT, ierr)) |
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetProblemType(eps, EPS_HEP, ierr)) |
| 149 | |||
| 150 | ! ** Set user-defined monitor | ||
| 151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(PetscOptionsHasName(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-my_eps_monitor', flg, ierr)) |
| 152 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (flg) then |
| 153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSMonitorSet(eps, MyEPSMonitor, 0, PETSC_NULL_FUNCTION, ierr)) |
| 154 | end if | ||
| 155 | |||
| 156 | ! ** Set solver parameters at runtime | ||
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetFromOptions(eps, ierr)) |
| 158 | |||
| 159 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 160 | ! Solve the eigensystem | ||
| 161 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 162 | |||
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSolve(eps, ierr)) |
| 164 | |||
| 165 | ! ** Optional: Get some information from the solver and display it | ||
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetType(eps, tname, ierr)) |
| 167 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 168 | 6 | write (*, '(a,a)') ' Solution method: ', tname | |
| 169 | end if | ||
| 170 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetDimensions(eps, nev, PETSC_NULL_INTEGER, PETSC_NULL_INTEGER, ierr)) |
| 171 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 172 | 6 | write (*, '(a,i2)') ' Number of requested eigenvalues:', nev | |
| 173 | end if | ||
| 174 | |||
| 175 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 176 | ! Display solution and clean up | ||
| 177 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 178 | |||
| 179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_NULL_VIEWER, ierr)) |
| 180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSDestroy(eps, ierr)) |
| 181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatDestroy(A, ierr)) |
| 182 | |||
| 183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
6 | PetscCallA(SlepcFinalize(ierr)) |
| 184 | 1 | end program test15f | |
| 185 | |||
| 186 | !/*TEST | ||
| 187 | ! | ||
| 188 | ! test: | ||
| 189 | ! suffix: 1 | ||
| 190 | ! args: -my_eps_monitor | ||
| 191 | ! requires: double | ||
| 192 | ! | ||
| 193 | !TEST*/ | ||
| 194 |