| 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> ./ex1f [-help] [-n <n>] [all SLEPc options] | ||
| 11 | ! | ||
| 12 | ! Description: Simple example that solves an eigensystem with the EPS object. | ||
| 13 | ! The standard symmetric eigenvalue problem to be solved corresponds to the | ||
| 14 | ! Laplacian operator in 1 dimension. | ||
| 15 | ! | ||
| 16 | ! The command line options are: | ||
| 17 | ! -n <n>, where <n> = number of grid points = matrix size | ||
| 18 | ! | ||
| 19 | ! ---------------------------------------------------------------------- | ||
| 20 | ! | ||
| 21 | #include <slepc/finclude/slepceps.h> | ||
| 22 | 62 | program ex1f | |
| 23 | 5 | use slepceps | |
| 24 | implicit none | ||
| 25 | |||
| 26 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 27 | ! Declarations | ||
| 28 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 29 | ! | ||
| 30 | Mat :: A ! operator matrix | ||
| 31 | EPS :: eps ! eigenproblem solver context | ||
| 32 | EPSType :: tname | ||
| 33 | PetscInt :: n, i, Istart, Iend | ||
| 34 | PetscInt :: nev | ||
| 35 | PetscInt :: row(1), col(3) | ||
| 36 | PetscMPIInt :: rank | ||
| 37 | PetscErrorCode :: ierr | ||
| 38 | PetscBool :: flg, terse | ||
| 39 | PetscScalar :: val(3) | ||
| 40 | |||
| 41 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 42 | ! Beginning of program | ||
| 43 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 44 | |||
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER, "ex1f test"//c_new_line, ierr)) |
| 46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 47 | 5 | n = 30 | |
| 48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr)) |
| 49 | |||
| 50 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 51 | 5 | write (*, '(/a,i4,a)') '1-D Laplacian Eigenproblem, n =', n, ' (Fortran)' | |
| 52 | end if | ||
| 53 | |||
| 54 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 55 | ! Compute the operator matrix that defines the eigensystem, Ax=kx | ||
| 56 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 57 | |||
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatCreate(PETSC_COMM_WORLD, A, ierr)) |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, n, n, ierr)) |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetFromOptions(A, ierr)) |
| 61 | |||
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatGetOwnershipRange(A, Istart, Iend, ierr)) |
| 63 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (Istart == 0) then |
| 64 | 5 | row(1) = 0 | |
| 65 | 5 | col(1) = 0 | |
| 66 | 5 | col(2) = 1 | |
| 67 | 5 | val(1) = 2.0 | |
| 68 | 5 | val(2) = -1.0 | |
| 69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetValues(A, 1_PETSC_INT_KIND, row, 2_PETSC_INT_KIND, col, val, INSERT_VALUES, ierr)) |
| 70 | 5 | Istart = Istart + 1 | |
| 71 | end if | ||
| 72 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (Iend == n) then |
| 73 | 5 | row(1) = n - 1 | |
| 74 | 5 | col(1) = n - 2 | |
| 75 | 5 | col(2) = n - 1 | |
| 76 | 5 | val(1) = -1.0 | |
| 77 | 5 | val(2) = 2.0 | |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatSetValues(A, 1_PETSC_INT_KIND, row, 2_PETSC_INT_KIND, col, val, INSERT_VALUES, ierr)) |
| 79 | 5 | Iend = Iend - 1 | |
| 80 | end if | ||
| 81 | 5 | val(1) = -1.0 | |
| 82 | 5 | val(2) = 2.0 | |
| 83 | 5 | val(3) = -1.0 | |
| 84 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
145 | do i = Istart, Iend - 1 |
| 85 | 140 | row(1) = i | |
| 86 | 140 | col(1) = i - 1 | |
| 87 | 140 | col(2) = i | |
| 88 | 140 | col(3) = i + 1 | |
| 89 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
145 | PetscCallA(MatSetValues(A, 1_PETSC_INT_KIND, row, 3_PETSC_INT_KIND, col, val, INSERT_VALUES, ierr)) |
| 90 | end do | ||
| 91 | |||
| 92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 94 | |||
| 95 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 96 | ! Create the eigensolver and display info | ||
| 97 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 98 | |||
| 99 | ! ** Create eigensolver context | ||
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSCreate(PETSC_COMM_WORLD, eps, ierr)) |
| 101 | |||
| 102 | ! ** Set operators. In this case, it is a standard eigenvalue problem | ||
| 103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetOperators(eps, A, PETSC_NULL_MAT, ierr)) |
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetProblemType(eps, EPS_HEP, ierr)) |
| 105 | |||
| 106 | ! ** Set solver parameters at runtime | ||
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSetFromOptions(eps, ierr)) |
| 108 | |||
| 109 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 110 | ! Solve the eigensystem | ||
| 111 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 112 | |||
| 113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSSolve(eps, ierr)) |
| 114 | |||
| 115 | ! ** Optional: Get some information from the solver and display it | ||
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSGetType(eps, tname, ierr)) |
| 117 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 118 | 5 | write (*, '(a,a)') ' Solution method: ', tname | |
| 119 | end if | ||
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSGetDimensions(eps, nev, PETSC_NULL_INTEGER, PETSC_NULL_INTEGER, ierr)) |
| 121 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (rank == 0) then |
| 122 | 5 | write (*, '(a,i4)') ' Number of requested eigenvalues:', nev | |
| 123 | end if | ||
| 124 | |||
| 125 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 126 | ! Display solution and clean up | ||
| 127 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 128 | |||
| 129 | ! ** show detailed info unless -terse option is given by user | ||
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(PetscOptionsHasName(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-terse', terse, ierr)) |
| 131 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (terse) then |
| 132 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_NULL_VIEWER, ierr)) |
| 133 | else | ||
| 134 | ✗ | PetscCallA(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_INFO_DETAIL, ierr)) | |
| 135 | ✗ | PetscCallA(EPSConvergedReasonView(eps, PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 136 | ✗ | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 137 | ✗ | PetscCallA(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 138 | end if | ||
| 139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(EPSDestroy(eps, ierr)) |
| 140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | PetscCallA(MatDestroy(A, ierr)) |
| 141 | |||
| 142 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
5 | PetscCallA(SlepcFinalize(ierr)) |
| 143 | ✗ | end program ex1f | |
| 144 | |||
| 145 | !/*TEST | ||
| 146 | ! | ||
| 147 | ! test: | ||
| 148 | ! args: -eps_nev 4 -terse | ||
| 149 | ! filter: sed -e "s/3.83791/3.83792/" | ||
| 150 | ! | ||
| 151 | !TEST*/ | ||
| 152 |