| 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> ./test1f [-help] | ||
| 11 | ! | ||
| 12 | ! Description: Simple example that tests BV interface functions. | ||
| 13 | ! | ||
| 14 | ! ---------------------------------------------------------------------- | ||
| 15 | ! | ||
| 16 | #include <slepc/finclude/slepcbv.h> | ||
| 17 | 96 | program test1f | |
| 18 | 72 | use slepcbv | |
| 19 | implicit none | ||
| 20 | |||
| 21 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 22 | ! Declarations | ||
| 23 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 24 | |||
| 25 | #define KMAX 35 | ||
| 26 | |||
| 27 | Vec :: t, v | ||
| 28 | Mat :: Q, M | ||
| 29 | BV :: X, Y | ||
| 30 | PetscMPIInt :: rank | ||
| 31 | PetscInt :: i, j, n, k, l, izero, ione | ||
| 32 | PetscScalar :: z(KMAX), val | ||
| 33 | 60 | PetscScalar, pointer :: qq(:, :) | |
| 34 | PetscScalar :: one, mone, two, zero | ||
| 35 | PetscReal :: nrm | ||
| 36 | PetscBool :: flg | ||
| 37 | PetscErrorCode :: ierr | ||
| 38 | |||
| 39 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 40 | ! Beginning of program | ||
| 41 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 42 | |||
| 43 | 72 | n = 10 | |
| 44 | 72 | k = 5 | |
| 45 | 72 | l = 3 | |
| 46 | 72 | one = 1.0 | |
| 47 | 72 | mone = -1.0 | |
| 48 | 72 | two = 2.0 | |
| 49 | 72 | zero = 0.0 | |
| 50 | 72 | izero = 0 | |
| 51 | 72 | ione = 1 | |
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(SlepcInitialize(PETSC_NULL_CHARACTER, ierr)) |
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr)) |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr)) |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-k', k, flg, ierr)) |
| 56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-l', l, flg, ierr)) |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCheckA(k <= KMAX, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, 'Program currently limited to k=35') |
| 58 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
72 | if (rank == 0) then |
| 59 | 48 | write (*, '(/a,i3,a,i3,a)') 'Test BV with', k, ' columns of length', n, ' (Fortran)' | |
| 60 | end if | ||
| 61 | |||
| 62 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 63 | ! Initialize data | ||
| 64 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 65 | |||
| 66 | ! ** Create template vector | ||
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(VecCreate(PETSC_COMM_WORLD, t, ierr)) |
| 68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(VecSetSizes(t, PETSC_DECIDE, n, ierr)) |
| 69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(VecSetFromOptions(t, ierr)) |
| 70 | |||
| 71 | ! ** Create BV object X | ||
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVCreate(PETSC_COMM_WORLD, X, ierr)) |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVSetSizesFromVec(X, t, k, ierr)) |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVSetFromOptions(X, ierr)) |
| 75 | |||
| 76 | ! ** Fill X entries | ||
| 77 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
432 | do j = 0, k - 1 |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
360 | PetscCallA(BVGetColumn(X, j, v, ierr)) |
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
360 | PetscCallA(VecSet(v, zero, ierr)) |
| 80 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
1800 | do i = 0, 3 |
| 81 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
1800 | if (i + j < n) then |
| 82 | 1440 | val = 3*i + j - 2 | |
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
1440 | PetscCallA(VecSetValue(v, i + j, val, INSERT_VALUES, ierr)) |
| 84 | end if | ||
| 85 | end do | ||
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
360 | PetscCallA(VecAssemblyBegin(v, ierr)) |
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
360 | PetscCallA(VecAssemblyEnd(v, ierr)) |
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
432 | PetscCallA(BVRestoreColumn(X, j, v, ierr)) |
| 89 | end do | ||
| 90 | |||
| 91 | ! ** Create BV object Y | ||
| 92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVCreate(PETSC_COMM_WORLD, Y, ierr)) |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVSetSizesFromVec(Y, t, l, ierr)) |
| 94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVSetFromOptions(Y, ierr)) |
| 95 | |||
| 96 | ! ** Fill Y entries | ||
| 97 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
288 | do j = 0, l - 1 |
| 98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
216 | PetscCallA(BVGetColumn(Y, j, v, ierr)) |
| 99 | 216 | val = real(j + 1)/4.0 | |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
216 | PetscCallA(VecSet(v, val, ierr)) |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
288 | PetscCallA(BVRestoreColumn(Y, j, v, ierr)) |
| 102 | end do | ||
| 103 | |||
| 104 | ! ** Create Mat | ||
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatCreateSeqDense(PETSC_COMM_SELF, k, l, PETSC_NULL_SCALAR_ARRAY, Q, ierr)) |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatDenseGetArray(Q, qq, ierr)) |
| 107 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
432 | do i = 1, k |
| 108 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
1512 | do j = 1, l |
| 109 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
1440 | if (i < j) then |
| 110 | 216 | qq(i, j) = 2.0 | |
| 111 | else | ||
| 112 | 864 | qq(i, j) = -0.5 | |
| 113 | end if | ||
| 114 | end do | ||
| 115 | end do | ||
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatDenseRestoreArray(Q, qq, ierr)) |
| 117 | |||
| 118 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 119 | ! Test several operations | ||
| 120 | ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 121 | |||
| 122 | ! ** Test BVMult | ||
| 123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVMult(Y, two, one, X, Q, ierr)) |
| 124 | |||
| 125 | ! ** Test BVMultVec | ||
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVGetColumn(Y, izero, v, ierr)) |
| 127 | 72 | z(1) = 2.0 | |
| 128 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
360 | do i = 2, k |
| 129 | 360 | z(i) = -0.5*z(i - 1) | |
| 130 | end do | ||
| 131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVMultVec(X, mone, one, v, z, ierr)) |
| 132 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVRestoreColumn(Y, izero, v, ierr)) |
| 133 | |||
| 134 | ! ** Test BVDot | ||
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatCreateSeqDense(PETSC_COMM_SELF, l, k, PETSC_NULL_SCALAR_ARRAY, M, ierr)) |
| 136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVDot(X, Y, M, ierr)) |
| 137 | |||
| 138 | ! ** Test BVDotVec | ||
| 139 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVGetColumn(Y, izero, v, ierr)) |
| 140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVDotVec(X, v, z, ierr)) |
| 141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVRestoreColumn(Y, izero, v, ierr)) |
| 142 | |||
| 143 | ! ** Test BVMultInPlace and BVScale | ||
| 144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVMultInPlace(X, Q, ione, l, ierr)) |
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVScale(X, two, ierr)) |
| 146 | |||
| 147 | ! ** Test BVNorm | ||
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVNormColumn(X, izero, NORM_2, nrm, ierr)) |
| 149 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
72 | if (rank == 0) then |
| 150 | 48 | write (*, '(a,f8.4)') '2-Norm of X[0] = ', nrm | |
| 151 | end if | ||
| 152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVNorm(X, NORM_FROBENIUS, nrm, ierr)) |
| 153 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
72 | if (rank == 0) then |
| 154 | 48 | write (*, '(a,f8.4)') 'Frobenius Norm of X = ', nrm | |
| 155 | end if | ||
| 156 | |||
| 157 | ! *** Clean up | ||
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVDestroy(X, ierr)) |
| 159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(BVDestroy(Y, ierr)) |
| 160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(VecDestroy(t, ierr)) |
| 161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatDestroy(Q, ierr)) |
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
72 | PetscCallA(MatDestroy(M, ierr)) |
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
72 | PetscCallA(SlepcFinalize(ierr)) |
| 164 | 72 | end program test1f | |
| 165 | |||
| 166 | !/*TEST | ||
| 167 | ! | ||
| 168 | ! test: | ||
| 169 | ! suffix: 1 | ||
| 170 | ! nsize: 1 | ||
| 171 | ! args: -bv_type {{vecs contiguous svec mat}separate output} | ||
| 172 | ! output_file: output/test1f_1.out | ||
| 173 | ! | ||
| 174 | ! test: | ||
| 175 | ! suffix: 2 | ||
| 176 | ! nsize: 2 | ||
| 177 | ! args: -bv_type {{vecs contiguous svec mat}separate output} | ||
| 178 | ! output_file: output/test1f_1.out | ||
| 179 | ! | ||
| 180 | !TEST*/ | ||
| 181 |