| 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 | 8 | program ex1f | |
| 23 | 6 | 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, one, two, three | ||
| 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 | 6 | one = 1 | |
| 46 | 6 | two = 2 | |
| 47 | 6 | three = 3 | |
| 48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER, "ex1f test"//c_new_line, ierr)) |
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 50 | 6 | n = 30 | |
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr)) |
| 52 | |||
| 53 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 54 | 6 | write (*, '(/a,i4,a)') '1-D Laplacian Eigenproblem, n =', n, ' (Fortran)' | |
| 55 | end if | ||
| 56 | |||
| 57 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 58 | ! Compute the operator matrix that defines the eigensystem, Ax=kx | ||
| 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, n, n, 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 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Istart == 0) then |
| 67 | 6 | row(1) = 0 | |
| 68 | 6 | col(1) = 0 | |
| 69 | 6 | col(2) = 1 | |
| 70 | 6 | val(1) = 2.0 | |
| 71 | 6 | val(2) = -1.0 | |
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetValues(A, one, row, two, col, val, INSERT_VALUES, ierr)) |
| 73 | 6 | Istart = Istart + 1 | |
| 74 | end if | ||
| 75 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (Iend == n) then |
| 76 | 6 | row(1) = n - 1 | |
| 77 | 6 | col(1) = n - 2 | |
| 78 | 6 | col(2) = n - 1 | |
| 79 | 6 | val(1) = -1.0 | |
| 80 | 6 | val(2) = 2.0 | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatSetValues(A, one, row, two, col, val, INSERT_VALUES, ierr)) |
| 82 | 6 | Iend = Iend - 1 | |
| 83 | end if | ||
| 84 | 6 | val(1) = -1.0 | |
| 85 | 6 | val(2) = 2.0 | |
| 86 | 6 | val(3) = -1.0 | |
| 87 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
174 | do i = Istart, Iend - 1 |
| 88 | 168 | row(1) = i | |
| 89 | 168 | col(1) = i - 1 | |
| 90 | 168 | col(2) = i | |
| 91 | 168 | col(3) = i + 1 | |
| 92 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
174 | PetscCallA(MatSetValues(A, one, row, three, col, val, INSERT_VALUES, ierr)) |
| 93 | end do | ||
| 94 | |||
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY, ierr)) |
| 97 | |||
| 98 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 99 | ! Create the eigensolver and display info | ||
| 100 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 101 | |||
| 102 | ! ** Create eigensolver context | ||
| 103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSCreate(PETSC_COMM_WORLD, eps, ierr)) |
| 104 | |||
| 105 | ! ** Set operators. In this case, it is a standard eigenvalue problem | ||
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetOperators(eps, A, PETSC_NULL_MAT, ierr)) |
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetProblemType(eps, EPS_HEP, ierr)) |
| 108 | |||
| 109 | ! ** Set solver parameters at runtime | ||
| 110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSetFromOptions(eps, ierr)) |
| 111 | |||
| 112 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 113 | ! Solve the eigensystem | ||
| 114 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 115 | |||
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSSolve(eps, ierr)) |
| 117 | |||
| 118 | ! ** Optional: Get some information from the solver and display it | ||
| 119 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetType(eps, tname, ierr)) |
| 120 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 121 | 6 | write (*, '(a,a)') ' Solution method: ', tname | |
| 122 | end if | ||
| 123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSGetDimensions(eps, nev, PETSC_NULL_INTEGER, PETSC_NULL_INTEGER, ierr)) |
| 124 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (rank == 0) then |
| 125 | 6 | write (*, '(a,i4)') ' Number of requested eigenvalues:', nev | |
| 126 | end if | ||
| 127 | |||
| 128 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 129 | ! Display solution and clean up | ||
| 130 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 131 | |||
| 132 | ! ** show detailed info unless -terse option is given by user | ||
| 133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(PetscOptionsHasName(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-terse', terse, ierr)) |
| 134 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (terse) then |
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_NULL_VIEWER, ierr)) |
| 136 | else | ||
| 137 | ✗ | PetscCallA(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_INFO_DETAIL, ierr)) | |
| 138 | ✗ | PetscCallA(EPSConvergedReasonView(eps, PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 139 | ✗ | PetscCallA(EPSErrorView(eps, EPS_ERROR_RELATIVE, PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 140 | ✗ | PetscCallA(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD, ierr)) | |
| 141 | end if | ||
| 142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(EPSDestroy(eps, ierr)) |
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | PetscCallA(MatDestroy(A, ierr)) |
| 144 | |||
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
6 | PetscCallA(SlepcFinalize(ierr)) |
| 146 | 1 | end program ex1f | |
| 147 | |||
| 148 | !/*TEST | ||
| 149 | ! | ||
| 150 | ! test: | ||
| 151 | ! args: -eps_nev 4 -terse | ||
| 152 | ! filter: sed -e "s/3.83791/3.83792/" | ||
| 153 | ! | ||
| 154 | !TEST*/ | ||
| 155 |