| 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 | |||
| 11 | #pragma once | ||
| 12 | |||
| 13 | #include <slepcbv.h> | ||
| 14 | #include <slepc/private/slepcimpl.h> | ||
| 15 | |||
| 16 | /* SUBMANSEC = BV */ | ||
| 17 | |||
| 18 | SLEPC_EXTERN PetscBool BVRegisterAllCalled; | ||
| 19 | SLEPC_EXTERN PetscErrorCode BVRegisterAll(void); | ||
| 20 | |||
| 21 | SLEPC_EXTERN PetscLogEvent BV_Create,BV_Copy,BV_Mult,BV_MultVec,BV_MultInPlace,BV_Dot,BV_DotVec,BV_Orthogonalize,BV_OrthogonalizeVec,BV_Scale,BV_Norm,BV_NormVec,BV_Normalize,BV_SetRandom,BV_MatMult,BV_MatMultVec,BV_MatProject,BV_SVDAndRank; | ||
| 22 | |||
| 23 | typedef struct _BVOps *BVOps; | ||
| 24 | |||
| 25 | struct _BVOps { | ||
| 26 | PetscErrorCode (*mult)(BV,PetscScalar,PetscScalar,BV,Mat); | ||
| 27 | PetscErrorCode (*multvec)(BV,PetscScalar,PetscScalar,Vec,PetscScalar*); | ||
| 28 | PetscErrorCode (*multinplace)(BV,Mat,PetscInt,PetscInt); | ||
| 29 | PetscErrorCode (*multinplacetrans)(BV,Mat,PetscInt,PetscInt); | ||
| 30 | PetscErrorCode (*dot)(BV,BV,Mat); | ||
| 31 | PetscErrorCode (*dotvec)(BV,Vec,PetscScalar*); | ||
| 32 | PetscErrorCode (*dotvec_local)(BV,Vec,PetscScalar*); | ||
| 33 | PetscErrorCode (*dotvec_begin)(BV,Vec,PetscScalar*); | ||
| 34 | PetscErrorCode (*dotvec_end)(BV,Vec,PetscScalar*); | ||
| 35 | PetscErrorCode (*scale)(BV,PetscInt,PetscScalar); | ||
| 36 | PetscErrorCode (*norm)(BV,PetscInt,NormType,PetscReal*); | ||
| 37 | PetscErrorCode (*norm_local)(BV,PetscInt,NormType,PetscReal*); | ||
| 38 | PetscErrorCode (*norm_begin)(BV,PetscInt,NormType,PetscReal*); | ||
| 39 | PetscErrorCode (*norm_end)(BV,PetscInt,NormType,PetscReal*); | ||
| 40 | PetscErrorCode (*normalize)(BV,PetscScalar*); | ||
| 41 | PetscErrorCode (*matmult)(BV,Mat,BV); | ||
| 42 | PetscErrorCode (*copy)(BV,BV); | ||
| 43 | PetscErrorCode (*copycolumn)(BV,PetscInt,PetscInt); | ||
| 44 | PetscErrorCode (*resize)(BV,PetscInt,PetscBool); | ||
| 45 | PetscErrorCode (*getcolumn)(BV,PetscInt,Vec*); | ||
| 46 | PetscErrorCode (*restorecolumn)(BV,PetscInt,Vec*); | ||
| 47 | PetscErrorCode (*getarray)(BV,PetscScalar**); | ||
| 48 | PetscErrorCode (*restorearray)(BV,PetscScalar**); | ||
| 49 | PetscErrorCode (*getarrayread)(BV,const PetscScalar**); | ||
| 50 | PetscErrorCode (*restorearrayread)(BV,const PetscScalar**); | ||
| 51 | PetscErrorCode (*restoresplit)(BV,BV*,BV*); | ||
| 52 | PetscErrorCode (*restoresplitrows)(BV,IS,IS,BV*,BV*); | ||
| 53 | PetscErrorCode (*gramschmidt)(BV,PetscInt,Vec,PetscBool*,PetscScalar*,PetscScalar*,PetscReal*,PetscReal*); | ||
| 54 | PetscErrorCode (*getmat)(BV,Mat*); | ||
| 55 | PetscErrorCode (*restoremat)(BV,Mat*); | ||
| 56 | PetscErrorCode (*duplicate)(BV,BV); | ||
| 57 | PetscErrorCode (*create)(BV); | ||
| 58 | PetscErrorCode (*setfromoptions)(BV,PetscOptionItems); | ||
| 59 | PetscErrorCode (*view)(BV,PetscViewer); | ||
| 60 | PetscErrorCode (*destroy)(BV); | ||
| 61 | }; | ||
| 62 | |||
| 63 | struct _p_BV { | ||
| 64 | PETSCHEADER(struct _BVOps); | ||
| 65 | /*------------------------- User parameters --------------------------*/ | ||
| 66 | PetscLayout map; /* layout of columns */ | ||
| 67 | VecType vtype; /* vector type */ | ||
| 68 | PetscInt n,N; /* dimensions of vectors (local, global) */ | ||
| 69 | PetscInt m; /* number of vectors */ | ||
| 70 | PetscInt l; /* number of leading columns */ | ||
| 71 | PetscInt k; /* number of active columns */ | ||
| 72 | PetscInt nc; /* number of constraints */ | ||
| 73 | PetscInt ld; /* leading dimension */ | ||
| 74 | BVOrthogType orthog_type; /* the method of vector orthogonalization */ | ||
| 75 | BVOrthogRefineType orthog_ref; /* refinement method */ | ||
| 76 | PetscReal orthog_eta; /* refinement threshold */ | ||
| 77 | BVOrthogBlockType orthog_block; /* the method of block orthogonalization */ | ||
| 78 | Mat matrix; /* inner product matrix */ | ||
| 79 | PetscBool indef; /* matrix is indefinite */ | ||
| 80 | BVMatMultType vmm; /* version of matmult operation */ | ||
| 81 | PetscBool rrandom; /* reproducible random vectors */ | ||
| 82 | PetscReal deftol; /* tolerance for BV_SafeSqrt */ | ||
| 83 | |||
| 84 | /*---------------------- Cached data and workspace -------------------*/ | ||
| 85 | Vec buffer; /* buffer vector used in orthogonalization */ | ||
| 86 | Mat Abuffer; /* auxiliary seqdense matrix that wraps the buffer */ | ||
| 87 | Vec Bx; /* result of matrix times a vector x */ | ||
| 88 | VecState xstate; /* state of vector x */ | ||
| 89 | Vec cv[2]; /* column vectors obtained with BVGetColumn() */ | ||
| 90 | PetscInt ci[2]; /* column indices of obtained vectors */ | ||
| 91 | VecState st[2]; /* state of obtained vectors */ | ||
| 92 | PetscScalar *h,*c; /* orthogonalization coefficients */ | ||
| 93 | Vec omega; /* signature matrix values for indefinite case */ | ||
| 94 | PetscBool defersfo; /* deferred call to setfromoptions */ | ||
| 95 | BV cached; /* cached BV to store result of matrix times BV */ | ||
| 96 | PetscObjectState bvstate; /* state of BV when BVApplyMatrixBV() was called */ | ||
| 97 | BV L,R; /* BV objects obtained with BVGetSplit/Rows() */ | ||
| 98 | PetscObjectState lstate,rstate;/* state of L and R when BVGetSplit/Rows() was called */ | ||
| 99 | PetscInt lsplit; /* value of l when BVGetSplit() was called (-1 if BVGetSplitRows()) */ | ||
| 100 | PetscInt issplit; /* !=0 if BV is from split (1=left, 2=right, -1=top, -2=bottom) */ | ||
| 101 | BV splitparent; /* my parent if I am a split BV */ | ||
| 102 | PetscRandom rand; /* random number generator */ | ||
| 103 | Mat Acreate; /* matrix given at BVCreateFromMat() */ | ||
| 104 | Mat Aget; /* matrix returned for BVGetMat() */ | ||
| 105 | PetscBool cuda; /* true if NVIDIA GPU must be used */ | ||
| 106 | PetscBool hip; /* true if AMD GPU must be used */ | ||
| 107 | PetscBool kokkos; /* true if Kokkos vectors are being used */ | ||
| 108 | PetscBool sfocalled; /* setfromoptions has been called */ | ||
| 109 | PetscScalar *work; | ||
| 110 | PetscInt lwork; | ||
| 111 | void *data; | ||
| 112 | }; | ||
| 113 | |||
| 114 | /* | ||
| 115 | BV_SafeSqrt - Computes the square root of a scalar value alpha, which is | ||
| 116 | assumed to be z'*B*z. The result is | ||
| 117 | if definite inner product: res = sqrt(alpha) | ||
| 118 | if indefinite inner product: res = sgn(alpha)*sqrt(abs(alpha)) | ||
| 119 | */ | ||
| 120 | 3188398 | static inline PetscErrorCode BV_SafeSqrt(BV bv,PetscScalar alpha,PetscReal *res) | |
| 121 | { | ||
| 122 | 3188398 | PetscReal absal,realp; | |
| 123 | 3188398 | const char *msg; | |
| 124 | |||
| 125 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
3188398 | PetscFunctionBegin; |
| 126 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
3188398 | absal = PetscAbsScalar(alpha); |
| 127 | 3188398 | realp = PetscRealPart(alpha); | |
| 128 |
6/8✓ Branch 0 taken 22 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
3188398 | if (PetscUnlikely(absal<PETSC_MACHINE_EPSILON)) PetscCall(PetscInfo(bv,"Zero norm %g, either the vector is zero or a semi-inner product is being used\n",(double)absal)); |
| 129 | #if PetscDefined(USE_COMPLEX) | ||
| 130 |
3/6✓ Branch 0 taken 11 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1408446 | PetscCheck(PetscAbsReal(PetscImaginaryPart(alpha))<bv->deftol || PetscAbsReal(PetscImaginaryPart(alpha))/absal<10*bv->deftol,PetscObjectComm((PetscObject)bv),PETSC_ERR_USER_INPUT,"The inner product is not well defined: nonzero imaginary part %g",(double)PetscImaginaryPart(alpha)); |
| 131 | #endif | ||
| 132 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 22 times.
|
3188398 | if (PetscUnlikely(bv->indef)) { |
| 133 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
|
302991 | *res = (realp<0.0)? -PetscSqrtReal(-realp): PetscSqrtReal(realp); |
| 134 | } else { | ||
| 135 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 22 times.
|
2885407 | msg = bv->matrix? "The inner product is not well defined: indefinite matrix %g": "Invalid inner product: %g"; |
| 136 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2885407 | PetscCheck(realp>-bv->deftol,PetscObjectComm((PetscObject)bv),PETSC_ERR_USER_INPUT,msg,(double)realp); |
| 137 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
2885407 | *res = (realp<0.0)? 0.0: PetscSqrtReal(realp); |
| 138 | } | ||
| 139 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
626740 | PetscFunctionReturn(PETSC_SUCCESS); |
| 140 | } | ||
| 141 | |||
| 142 | /* | ||
| 143 | BV_IPMatMult - Multiply a vector x by the inner-product matrix, cache the | ||
| 144 | result in Bx. | ||
| 145 | */ | ||
| 146 | 878761 | static inline PetscErrorCode BV_IPMatMult(BV bv,Vec x) | |
| 147 | { | ||
| 148 | 878761 | VecState xstate; | |
| 149 | 878761 | PetscBool same; | |
| 150 | |||
| 151 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
878761 | PetscFunctionBegin; |
| 152 |
4/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
|
878761 | PetscCall(VecGetState(x,&xstate)); |
| 153 |
4/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
|
878761 | PetscCall(VecStateCompare(xstate,bv->xstate,&same)); |
| 154 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 40 times.
|
878761 | if (!same) { |
| 155 |
6/8✓ Branch 0 taken 54 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 44 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
|
812076 | if (PetscUnlikely(!bv->Bx)) PetscCall(MatCreateVecs(bv->matrix,&bv->Bx,NULL)); |
| 156 |
4/6✓ Branch 0 taken 15 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
|
812076 | PetscCall(MatMult(bv->matrix,x,bv->Bx)); |
| 157 | 812075 | bv->xstate = xstate; | |
| 158 | } | ||
| 159 |
7/14✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 14 times.
|
181261 | PetscFunctionReturn(PETSC_SUCCESS); |
| 160 | } | ||
| 161 | |||
| 162 | /* | ||
| 163 | BV_IPMatMultBV - Multiply BV by the inner-product matrix, cache the | ||
| 164 | result internally in bv->cached. | ||
| 165 | */ | ||
| 166 | 3579 | static inline PetscErrorCode BV_IPMatMultBV(BV bv) | |
| 167 | { | ||
| 168 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
3579 | PetscFunctionBegin; |
| 169 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
3579 | PetscCall(BVGetCachedBV(bv,&bv->cached)); |
| 170 |
3/6✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3579 | if (((PetscObject)bv)->state != bv->bvstate || bv->l != bv->cached->l || bv->k != bv->cached->k) { |
| 171 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
3579 | PetscCall(BVSetActiveColumns(bv->cached,bv->l,bv->k)); |
| 172 |
5/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
3579 | if (bv->matrix) PetscCall(BVMatMult(bv,bv->matrix,bv->cached)); |
| 173 | ✗ | else PetscCall(BVCopy(bv,bv->cached)); | |
| 174 | 3579 | bv->bvstate = ((PetscObject)bv)->state; | |
| 175 | } | ||
| 176 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
605 | PetscFunctionReturn(PETSC_SUCCESS); |
| 177 | } | ||
| 178 | |||
| 179 | /* | ||
| 180 | BV_AllocateCoeffs - Allocate orthogonalization coefficients if not done already. | ||
| 181 | */ | ||
| 182 | 465219 | static inline PetscErrorCode BV_AllocateCoeffs(BV bv) | |
| 183 | { | ||
| 184 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
465219 | PetscFunctionBegin; |
| 185 |
6/8✓ Branch 0 taken 30 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
|
465219 | if (!bv->h) PetscCall(PetscMalloc2(bv->nc+bv->m,&bv->h,bv->nc+bv->m,&bv->c)); |
| 186 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
91089 | PetscFunctionReturn(PETSC_SUCCESS); |
| 187 | } | ||
| 188 | |||
| 189 | /* | ||
| 190 | BV_AllocateSignature - Allocate signature coefficients if not done already. | ||
| 191 | */ | ||
| 192 | 2617413 | static inline PetscErrorCode BV_AllocateSignature(BV bv) | |
| 193 | { | ||
| 194 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
2617413 | PetscFunctionBegin; |
| 195 |
4/4✓ Branch 0 taken 30 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 20 times.
|
2617413 | if (bv->indef && !bv->omega) { |
| 196 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 30 times.
|
874 | if (bv->cuda) { |
| 197 | #if PetscDefined(HAVE_CUDA) | ||
| 198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
18 | PetscCall(VecCreateSeqCUDA(PETSC_COMM_SELF,bv->nc+bv->m,&bv->omega)); |
| 199 | #else | ||
| 200 | − | SETERRQ(PetscObjectComm((PetscObject)bv),PETSC_ERR_PLIB,"Something wrong happened"); | |
| 201 | #endif | ||
| 202 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 30 times.
|
856 | } else if (bv->hip) { |
| 203 | #if PetscDefined(HAVE_HIP) | ||
| 204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
18 | PetscCall(VecCreateSeqHIP(PETSC_COMM_SELF,bv->nc+bv->m,&bv->omega)); |
| 205 | #else | ||
| 206 | − | SETERRQ(PetscObjectComm((PetscObject)bv),PETSC_ERR_PLIB,"Something wrong happened"); | |
| 207 | #endif | ||
| 208 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
838 | } else PetscCall(VecCreateSeq(PETSC_COMM_SELF,bv->nc+bv->m,&bv->omega)); |
| 209 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
874 | PetscCall(VecSet(bv->omega,1.0)); |
| 210 | } | ||
| 211 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
508610 | PetscFunctionReturn(PETSC_SUCCESS); |
| 212 | } | ||
| 213 | |||
| 214 | /* | ||
| 215 | BV_SetMatrixDiagonal - sets the inner product matrix for BV as a diagonal matrix | ||
| 216 | with the diagonal specified by vector vomega, using the same matrix type as matrix M | ||
| 217 | */ | ||
| 218 | 233 | static inline PetscErrorCode BV_SetMatrixDiagonal(BV bv,Vec vomega,Mat M) | |
| 219 | { | ||
| 220 | 233 | Mat Omega; | |
| 221 | 233 | MatType Mtype; | |
| 222 | |||
| 223 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
233 | PetscFunctionBegin; |
| 224 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatGetType(M,&Mtype)); |
| 225 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatCreate(PetscObjectComm((PetscObject)bv),&Omega)); |
| 226 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatSetSizes(Omega,bv->n,bv->n,bv->N,bv->N)); |
| 227 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatSetType(Omega,Mtype)); |
| 228 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatDiagonalSet(Omega,vomega,INSERT_VALUES)); |
| 229 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(BVSetMatrix(bv,Omega,PETSC_TRUE)); |
| 230 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
233 | PetscCall(MatDestroy(&Omega)); |
| 231 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
57 | PetscFunctionReturn(PETSC_SUCCESS); |
| 232 | } | ||
| 233 | |||
| 234 | /* | ||
| 235 | BVAvailableVec: First (0) or second (1) vector available for | ||
| 236 | getcolumn operation (or -1 if both vectors already fetched). | ||
| 237 | */ | ||
| 238 | #define BVAvailableVec (((bv->ci[0]==-bv->nc-1)? 0: (bv->ci[1]==-bv->nc-1)? 1: -1)) | ||
| 239 | |||
| 240 | /* | ||
| 241 | Macros to test valid BV arguments | ||
| 242 | */ | ||
| 243 | #if !PetscDefined(USE_DEBUG) | ||
| 244 | |||
| 245 | #define BVCheckSizes(h,arg) do {(void)(h);} while (0) | ||
| 246 | #define BVCheckOp(h,arg,op) do {(void)(h);} while (0) | ||
| 247 | |||
| 248 | #else | ||
| 249 | |||
| 250 | #define BVCheckSizes(h,arg) \ | ||
| 251 | do { \ | ||
| 252 | PetscCheck((h)->m,PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"BV sizes have not been defined: Parameter #%d",arg); \ | ||
| 253 | } while (0) | ||
| 254 | |||
| 255 | #define BVCheckOp(h,arg,op) \ | ||
| 256 | do { \ | ||
| 257 | PetscCheck((h)->ops->op,PetscObjectComm((PetscObject)(h)),PETSC_ERR_SUP,"Operation not implemented in this BV type: Parameter #%d",arg); \ | ||
| 258 | } while (0) | ||
| 259 | |||
| 260 | #endif | ||
| 261 | |||
| 262 | SLEPC_INTERN PetscErrorCode BVView_Vecs(BV,PetscViewer); | ||
| 263 | |||
| 264 | SLEPC_INTERN PetscErrorCode BVAllocateWork_Private(BV,PetscInt); | ||
| 265 | |||
| 266 | SLEPC_INTERN PetscErrorCode BVMult_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 267 | SLEPC_INTERN PetscErrorCode BVMultVec_BLAS_Private(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar,PetscScalar*); | ||
| 268 | SLEPC_INTERN PetscErrorCode BVMultInPlace_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscBool); | ||
| 269 | SLEPC_INTERN PetscErrorCode BVMultInPlace_Vecs_Private(BV,PetscInt,PetscInt,PetscInt,Vec*,const PetscScalar*,PetscBool); | ||
| 270 | SLEPC_INTERN PetscErrorCode BVAXPY_BLAS_Private(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 271 | SLEPC_INTERN PetscErrorCode BVDot_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar*,PetscInt,PetscBool); | ||
| 272 | SLEPC_INTERN PetscErrorCode BVDotVec_BLAS_Private(BV,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar*,PetscBool); | ||
| 273 | SLEPC_INTERN PetscErrorCode BVScale_BLAS_Private(BV,PetscInt,PetscScalar*,PetscScalar); | ||
| 274 | SLEPC_INTERN PetscErrorCode BVNorm_LAPACK_Private(BV,PetscInt,PetscInt,const PetscScalar*,PetscInt,NormType,PetscReal*,PetscBool); | ||
| 275 | SLEPC_INTERN PetscErrorCode BVNormalize_LAPACK_Private(BV,PetscInt,PetscInt,const PetscScalar*,PetscInt,PetscScalar*,PetscBool); | ||
| 276 | SLEPC_INTERN PetscErrorCode BVGetMat_Default(BV,Mat*); | ||
| 277 | SLEPC_INTERN PetscErrorCode BVRestoreMat_Default(BV,Mat*); | ||
| 278 | SLEPC_INTERN PetscErrorCode BVMatCholInv_LAPACK_Private(BV,Mat,Mat); | ||
| 279 | SLEPC_INTERN PetscErrorCode BVMatTriInv_LAPACK_Private(BV,Mat,Mat); | ||
| 280 | SLEPC_INTERN PetscErrorCode BVMatSVQB_LAPACK_Private(BV,Mat,Mat); | ||
| 281 | SLEPC_INTERN PetscErrorCode BVOrthogonalize_LAPACK_TSQR(BV,PetscInt,PetscInt,PetscScalar*,PetscInt,PetscScalar*,PetscInt); | ||
| 282 | SLEPC_INTERN PetscErrorCode BVOrthogonalize_LAPACK_TSQR_OnlyR(BV,PetscInt,PetscInt,PetscScalar*,PetscInt,PetscScalar*,PetscInt); | ||
| 283 | |||
| 284 | /* reduction operations used in BVOrthogonalize and BVNormalize */ | ||
| 285 | SLEPC_EXTERN MPI_Op MPIU_TSQR, MPIU_LAPY2; | ||
| 286 | SLEPC_EXTERN void MPIAPI SlepcGivensPacked(void*,void*,PetscMPIInt*,MPI_Datatype*); | ||
| 287 | SLEPC_EXTERN void MPIAPI SlepcPythag(void*,void*,PetscMPIInt*,MPI_Datatype*); | ||
| 288 | |||
| 289 | /* | ||
| 290 | BV_CleanCoefficients_Default - Sets to zero all entries of column j of the bv buffer | ||
| 291 | */ | ||
| 292 | 2561008 | static inline PetscErrorCode BV_CleanCoefficients_Default(BV bv,PetscInt j,PetscScalar *h) | |
| 293 | { | ||
| 294 | 2561008 | PetscScalar *hh=h,*a; | |
| 295 | 2561008 | PetscInt i; | |
| 296 | |||
| 297 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
2561008 | PetscFunctionBegin; |
| 298 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
|
2561008 | if (!h) { |
| 299 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2101853 | PetscCall(VecGetArray(bv->buffer,&a)); |
| 300 | 2101853 | hh = a + j*(bv->nc+bv->m); | |
| 301 | } | ||
| 302 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
34122918 | for (i=0;i<bv->nc+j;i++) hh[i] = 0.0; |
| 303 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2561008 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&a)); |
| 304 |
7/14✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
|
507826 | PetscFunctionReturn(PETSC_SUCCESS); |
| 305 | } | ||
| 306 | |||
| 307 | /* | ||
| 308 | BV_AddCoefficients_Default - Add the contents of the scratch (0-th column) of the bv buffer | ||
| 309 | into column j of the bv buffer | ||
| 310 | */ | ||
| 311 | 3978527 | static inline PetscErrorCode BV_AddCoefficients_Default(BV bv,PetscInt j,PetscScalar *h,PetscScalar *c) | |
| 312 | { | ||
| 313 | 3978527 | PetscScalar *hh=h,*cc=c; | |
| 314 | 3978527 | PetscInt i; | |
| 315 | |||
| 316 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
3978527 | PetscFunctionBegin; |
| 317 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
3978527 | if (!h) { |
| 318 |
4/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
|
3463680 | PetscCall(VecGetArray(bv->buffer,&cc)); |
| 319 | 3463680 | hh = cc + j*(bv->nc+bv->m); | |
| 320 | } | ||
| 321 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
|
60011291 | for (i=0;i<bv->nc+j;i++) hh[i] += cc[i]; |
| 322 |
6/8✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
3978527 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&cc)); |
| 323 |
3/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
3978527 | PetscCall(PetscLogFlops(1.0*(bv->nc+j))); |
| 324 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
3978527 | PetscFunctionReturn(PETSC_SUCCESS); |
| 325 | } | ||
| 326 | |||
| 327 | /* | ||
| 328 | BV_SetValue_Default - Sets value in row j (counted after the constraints) of column k | ||
| 329 | of the coefficients array | ||
| 330 | */ | ||
| 331 | 2954694 | static inline PetscErrorCode BV_SetValue_Default(BV bv,PetscInt j,PetscInt k,PetscScalar *h,PetscScalar value) | |
| 332 | { | ||
| 333 | 2954694 | PetscScalar *hh=h,*a; | |
| 334 | |||
| 335 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
2954694 | PetscFunctionBegin; |
| 336 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 30 times.
|
2954694 | if (!h) { |
| 337 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2932674 | PetscCall(VecGetArray(bv->buffer,&a)); |
| 338 | 2932674 | hh = a + k*(bv->nc+bv->m); | |
| 339 | } | ||
| 340 | 2954694 | hh[bv->nc+j] = value; | |
| 341 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2954694 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&a)); |
| 342 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
587692 | PetscFunctionReturn(PETSC_SUCCESS); |
| 343 | } | ||
| 344 | |||
| 345 | /* | ||
| 346 | BV_SquareSum_Default - Returns the value h'*h, where h represents the contents of the | ||
| 347 | coefficients array (up to position j) | ||
| 348 | */ | ||
| 349 | 3248178 | static inline PetscErrorCode BV_SquareSum_Default(BV bv,PetscInt j,PetscScalar *h,PetscReal *sum) | |
| 350 | { | ||
| 351 | 3248178 | PetscScalar *hh=h; | |
| 352 | 3248178 | PetscInt i; | |
| 353 | |||
| 354 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
3248178 | PetscFunctionBegin; |
| 355 | 3248178 | *sum = 0.0; | |
| 356 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
3248178 | if (!h) PetscCall(VecGetArray(bv->buffer,&hh)); |
| 357 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
43547184 | for (i=0;i<bv->nc+j;i++) *sum += PetscRealPart(hh[i]*PetscConj(hh[i])); |
| 358 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
3248178 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&hh)); |
| 359 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
3248178 | PetscCall(PetscLogFlops(2.0*(bv->nc+j))); |
| 360 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
3248178 | PetscFunctionReturn(PETSC_SUCCESS); |
| 361 | } | ||
| 362 | |||
| 363 | /* | ||
| 364 | BV_ApplySignature_Default - Computes the pointwise product h*omega, where h represents | ||
| 365 | the contents of the coefficients array (up to position j) and omega is the signature; | ||
| 366 | if inverse=TRUE then the operation is h/omega | ||
| 367 | */ | ||
| 368 | 611964 | static inline PetscErrorCode BV_ApplySignature_Default(BV bv,PetscInt j,PetscScalar *h,PetscBool inverse) | |
| 369 | { | ||
| 370 | 611964 | PetscScalar *hh=h; | |
| 371 | 611964 | PetscInt i; | |
| 372 | 611964 | const PetscScalar *omega; | |
| 373 | |||
| 374 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
611964 | PetscFunctionBegin; |
| 375 |
9/16✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 4 times.
|
611964 | if (PetscUnlikely(!(bv->nc+j))) PetscFunctionReturn(PETSC_SUCCESS); |
| 376 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
610560 | if (!h) PetscCall(VecGetArray(bv->buffer,&hh)); |
| 377 |
4/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
|
610560 | PetscCall(VecGetArrayRead(bv->omega,&omega)); |
| 378 |
4/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 20 times.
|
10951817 | if (inverse) for (i=0;i<bv->nc+j;i++) hh[i] /= PetscRealPart(omega[i]); |
| 379 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
10646537 | else for (i=0;i<bv->nc+j;i++) hh[i] *= PetscRealPart(omega[i]); |
| 380 |
4/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
|
610560 | PetscCall(VecRestoreArrayRead(bv->omega,&omega)); |
| 381 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
610560 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&hh)); |
| 382 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
|
610560 | PetscCall(PetscLogFlops(1.0*(bv->nc+j))); |
| 383 |
7/14✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
|
610560 | PetscFunctionReturn(PETSC_SUCCESS); |
| 384 | } | ||
| 385 | |||
| 386 | /* | ||
| 387 | BV_SquareRoot_Default - Returns the square root of position j (counted after the constraints) | ||
| 388 | of the coefficients array | ||
| 389 | */ | ||
| 390 | 2880940 | static inline PetscErrorCode BV_SquareRoot_Default(BV bv,PetscInt j,PetscScalar *h,PetscReal *beta) | |
| 391 | { | ||
| 392 | 2880940 | PetscScalar *hh=h; | |
| 393 | |||
| 394 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2880940 | PetscFunctionBegin; |
| 395 |
5/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2880940 | if (!h) PetscCall(VecGetArray(bv->buffer,&hh)); |
| 396 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2880940 | PetscCall(BV_SafeSqrt(bv,hh[bv->nc+j],beta)); |
| 397 |
5/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2880940 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&hh)); |
| 398 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
571197 | PetscFunctionReturn(PETSC_SUCCESS); |
| 399 | } | ||
| 400 | |||
| 401 | /* | ||
| 402 | BV_StoreCoefficients_Default - Copy the contents of the coefficients array to an array dest | ||
| 403 | provided by the caller (only values from l to j are copied) | ||
| 404 | */ | ||
| 405 | 815434 | static inline PetscErrorCode BV_StoreCoefficients_Default(BV bv,PetscInt j,PetscScalar *h,PetscScalar *dest) | |
| 406 | { | ||
| 407 | 815434 | PetscScalar *hh=h,*a; | |
| 408 | 815434 | PetscInt i; | |
| 409 | |||
| 410 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
815434 | PetscFunctionBegin; |
| 411 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
815434 | if (!h) { |
| 412 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
545187 | PetscCall(VecGetArray(bv->buffer,&a)); |
| 413 | 545187 | hh = a + j*(bv->nc+bv->m); | |
| 414 | } | ||
| 415 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
12920611 | for (i=bv->l;i<j;i++) dest[i-bv->l] = hh[bv->nc+i]; |
| 416 |
6/8✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
815434 | if (!h) PetscCall(VecRestoreArray(bv->buffer,&a)); |
| 417 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
161341 | PetscFunctionReturn(PETSC_SUCCESS); |
| 418 | } | ||
| 419 | |||
| 420 | /* | ||
| 421 | BV_GetEigenvector - retrieves k-th eigenvector from basis vectors V. | ||
| 422 | The argument eigi is the imaginary part of the corresponding eigenvalue. | ||
| 423 | */ | ||
| 424 | 125760 | static inline PetscErrorCode BV_GetEigenvector(BV V,PetscInt k,PetscScalar eigi,Vec Vr,Vec Vi) | |
| 425 | { | ||
| 426 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
125760 | PetscFunctionBegin; |
| 427 | #if PetscDefined(USE_COMPLEX) | ||
| 428 | 54857 | (void)eigi; | |
| 429 |
6/8✓ Branch 0 taken 25 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
|
54857 | if (Vr) PetscCall(BVCopyVec(V,k,Vr)); |
| 430 |
6/8✓ Branch 0 taken 15 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
54857 | if (Vi) PetscCall(VecSet(Vi,0.0)); |
| 431 | #else | ||
| 432 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 25 times.
|
70903 | if (eigi > 0.0) { /* first value of conjugate pair */ |
| 433 |
5/8✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
1224 | if (Vr) PetscCall(BVCopyVec(V,k,Vr)); |
| 434 |
5/8✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
1224 | if (Vi) PetscCall(BVCopyVec(V,k+1,Vi)); |
| 435 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 20 times.
|
69679 | } else if (eigi < 0.0) { /* second value of conjugate pair */ |
| 436 |
5/8✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
934 | if (Vr) PetscCall(BVCopyVec(V,k-1,Vr)); |
| 437 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
934 | if (Vi) { |
| 438 |
4/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
934 | PetscCall(BVCopyVec(V,k,Vi)); |
| 439 |
4/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
934 | PetscCall(VecScale(Vi,-1.0)); |
| 440 | } | ||
| 441 | } else { /* real eigenvalue */ | ||
| 442 |
6/8✓ Branch 0 taken 20 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
68745 | if (Vr) PetscCall(BVCopyVec(V,k,Vr)); |
| 443 |
6/8✓ Branch 0 taken 20 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
68745 | if (Vi) PetscCall(VecSet(Vi,0.0)); |
| 444 | } | ||
| 445 | #endif | ||
| 446 |
7/14✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 10 times.
|
22765 | PetscFunctionReturn(PETSC_SUCCESS); |
| 447 | } | ||
| 448 | |||
| 449 | /* | ||
| 450 | BV_OrthogonalizeColumn_Safe - this is intended for cases where we know that | ||
| 451 | the resulting vector is going to be numerically zero, so normalization or | ||
| 452 | iterative refinement may cause problems in parallel (collective operation | ||
| 453 | not being called by all processes) | ||
| 454 | */ | ||
| 455 | 1414 | static inline PetscErrorCode BV_OrthogonalizeColumn_Safe(BV bv,PetscInt j,PetscScalar *H,PetscReal *norm,PetscBool *lindep) | |
| 456 | { | ||
| 457 | 1414 | BVOrthogRefineType orthog_ref; | |
| 458 | |||
| 459 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
1414 | PetscFunctionBegin; |
| 460 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
1414 | PetscCall(PetscInfo(bv,"Orthogonalizing column %" PetscInt_FMT " without refinement\n",j)); |
| 461 | 1414 | orthog_ref = bv->orthog_ref; | |
| 462 | 1414 | bv->orthog_ref = BV_ORTHOG_REFINE_NEVER; /* avoid refinement */ | |
| 463 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
1414 | PetscCall(BVOrthogonalizeColumn(bv,j,H,NULL,NULL)); |
| 464 | 1414 | bv->orthog_ref = orthog_ref; /* restore refinement setting */ | |
| 465 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
1414 | if (norm) *norm = 0.0; |
| 466 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
1414 | if (lindep) *lindep = PETSC_TRUE; |
| 467 |
7/14✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
|
266 | PetscFunctionReturn(PETSC_SUCCESS); |
| 468 | } | ||
| 469 | |||
| 470 | /* | ||
| 471 | BV_SetDefaultLD - set the default value of the leading dimension, based on | ||
| 472 | the local size. | ||
| 473 | */ | ||
| 474 | 151215 | static inline PetscErrorCode BV_SetDefaultLD(BV bv,PetscInt nloc) | |
| 475 | { | ||
| 476 | 151215 | size_t bytes,align; | |
| 477 | |||
| 478 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
151215 | PetscFunctionBegin; |
| 479 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
|
151215 | if (bv->ld) { /* set by user */ |
| 480 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
127102 | PetscCheck(bv->ld>=nloc,PetscObjectComm((PetscObject)bv),PETSC_ERR_USER_INPUT,"The leading dimension %" PetscInt_FMT " should be larger or equal to the local number of rows %" PetscInt_FMT,bv->ld,nloc); |
| 481 | } else { | ||
| 482 | 24113 | align = PetscMax(PETSC_MEMALIGN,16); /* assume that CUDA requires 16-byte alignment */ | |
| 483 | 24113 | bytes = (nloc*sizeof(PetscScalar) + align - 1) & ~(align - 1); | |
| 484 |
4/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
24113 | PetscCall(PetscIntCast(bytes/sizeof(PetscScalar),&bv->ld)); |
| 485 | } | ||
| 486 |
7/14✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
|
29082 | PetscFunctionReturn(PETSC_SUCCESS); |
| 487 | } | ||
| 488 | |||
| 489 | #if PetscDefined(HAVE_CUDA) | ||
| 490 | /* | ||
| 491 | BV_MatDenseCUDAGetArrayRead - if Q is MATSEQDENSE it will allocate memory on the | ||
| 492 | GPU and copy the contents; otherwise, calls MatDenseCUDAGetArrayRead() | ||
| 493 | */ | ||
| 494 | 4321 | static inline PetscErrorCode BV_MatDenseCUDAGetArrayRead(PETSC_UNUSED BV bv,Mat Q,const PetscScalar **d_q) | |
| 495 | { | ||
| 496 | 4321 | const PetscScalar *q; | |
| 497 | 4321 | PetscInt ldq,mq; | |
| 498 | 4321 | PetscCuBLASInt ldq_=0; | |
| 499 | 4321 | PetscBool matiscuda; | |
| 500 | |||
| 501 | 4321 | PetscFunctionBegin; | |
| 502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4321 | PetscCall(MatGetSize(Q,NULL,&mq)); |
| 503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4321 | PetscCall(MatDenseGetLDA(Q,&ldq)); |
| 504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4321 | PetscCall(PetscCuBLASIntCast(ldq,&ldq_)); |
| 505 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4321 | PetscCall(PetscObjectTypeCompare((PetscObject)Q,MATSEQDENSECUDA,&matiscuda)); |
| 506 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4321 | if (matiscuda) PetscCall(MatDenseCUDAGetArrayRead(Q,d_q)); |
| 507 | else { | ||
| 508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4305 | PetscCall(MatDenseGetArrayRead(Q,&q)); |
| 509 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4305 | PetscCallCUDA(cudaMalloc((void**)d_q,ldq*mq*sizeof(PetscScalar))); |
| 510 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4305 | PetscCallCUDA(cudaMemcpy((void*)*d_q,q,ldq*mq*sizeof(PetscScalar),cudaMemcpyHostToDevice)); |
| 511 | 4305 | PetscCall(PetscLogCpuToGpu(ldq*mq*sizeof(PetscScalar))); | |
| 512 | } | ||
| 513 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 514 | } | ||
| 515 | |||
| 516 | /* | ||
| 517 | BV_MatDenseCUDARestoreArrayRead - restores the pointer obtained with BV_MatDenseCUDAGetArrayRead(), | ||
| 518 | freeing the GPU memory in case of MATSEQDENSE | ||
| 519 | */ | ||
| 520 | 4321 | static inline PetscErrorCode BV_MatDenseCUDARestoreArrayRead(PETSC_UNUSED BV bv,Mat Q,const PetscScalar **d_q) | |
| 521 | { | ||
| 522 | 4321 | PetscBool matiscuda; | |
| 523 | |||
| 524 | 4321 | PetscFunctionBegin; | |
| 525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4321 | PetscCall(PetscObjectTypeCompare((PetscObject)Q,MATSEQDENSECUDA,&matiscuda)); |
| 526 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4321 | if (matiscuda) PetscCall(MatDenseCUDARestoreArrayRead(Q,d_q)); |
| 527 | else { | ||
| 528 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4305 | PetscCall(MatDenseRestoreArrayRead(Q,NULL)); |
| 529 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4305 | PetscCallCUDA(cudaFree((void*)*d_q)); |
| 530 | 4305 | *d_q = NULL; | |
| 531 | } | ||
| 532 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 533 | } | ||
| 534 | |||
| 535 | /* | ||
| 536 | BV_VecPlaceArray - allows the user to replace the device array in a vector with a | ||
| 537 | device array provided by the caller, calling the accessor that corresponds to the | ||
| 538 | vector type being used by the BV object | ||
| 539 | */ | ||
| 540 | 169426 | static inline PetscErrorCode BV_VecPlaceArray(PETSC_UNUSED BV bv,Vec v,PetscScalar *a) | |
| 541 | { | ||
| 542 | 169426 | PetscFunctionBegin; | |
| 543 | #if PetscDefined(HAVE_KOKKOS_KERNELS) | ||
| 544 | if (bv->kokkos) { | ||
| 545 | PetscCall(VecKokkosPlaceArray(v,a)); | ||
| 546 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 547 | } | ||
| 548 | #endif | ||
| 549 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
169426 | PetscCall(VecCUDAPlaceArray(v,a)); |
| 550 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 551 | } | ||
| 552 | |||
| 553 | /* | ||
| 554 | BV_VecResetArray - resets the device array in a vector to the one it had before the | ||
| 555 | call to BV_VecPlaceArray() | ||
| 556 | */ | ||
| 557 | 169426 | static inline PetscErrorCode BV_VecResetArray(PETSC_UNUSED BV bv,Vec v) | |
| 558 | { | ||
| 559 | 169426 | PetscFunctionBegin; | |
| 560 | #if PetscDefined(HAVE_KOKKOS_KERNELS) | ||
| 561 | if (bv->kokkos) { | ||
| 562 | PetscCall(VecKokkosResetArray(v)); | ||
| 563 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 564 | } | ||
| 565 | #endif | ||
| 566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
169426 | PetscCall(VecCUDAResetArray(v)); |
| 567 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 568 | } | ||
| 569 | |||
| 570 | SLEPC_INTERN PetscErrorCode BVMult_BLAS_CUDA(BV,PetscInt,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 571 | SLEPC_INTERN PetscErrorCode BVMultVec_BLAS_CUDA(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar,PetscScalar*); | ||
| 572 | SLEPC_INTERN PetscErrorCode BVMultInPlace_BLAS_CUDA(BV,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscBool); | ||
| 573 | SLEPC_INTERN PetscErrorCode BVAXPY_BLAS_CUDA(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 574 | SLEPC_INTERN PetscErrorCode BVDot_BLAS_CUDA(BV,PetscInt,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar*,PetscInt,PetscBool); | ||
| 575 | SLEPC_INTERN PetscErrorCode BVDotVec_BLAS_CUDA(BV,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar*,PetscBool); | ||
| 576 | SLEPC_INTERN PetscErrorCode BVScale_BLAS_CUDA(BV,PetscInt,PetscScalar*,PetscScalar); | ||
| 577 | SLEPC_INTERN PetscErrorCode BVNorm_BLAS_CUDA(BV,PetscInt,const PetscScalar*,PetscReal*); | ||
| 578 | SLEPC_INTERN PetscErrorCode BVNormalize_BLAS_CUDA(BV,PetscInt,PetscInt,PetscScalar*,PetscInt,PetscScalar*); | ||
| 579 | |||
| 580 | SLEPC_INTERN PetscErrorCode BV_CleanCoefficients_CUDA(BV,PetscInt,PetscScalar*); | ||
| 581 | SLEPC_INTERN PetscErrorCode BV_AddCoefficients_CUDA(BV,PetscInt,PetscScalar*,PetscScalar*); | ||
| 582 | SLEPC_INTERN PetscErrorCode BV_SetValue_CUDA(BV,PetscInt,PetscInt,PetscScalar*,PetscScalar); | ||
| 583 | SLEPC_INTERN PetscErrorCode BV_SquareSum_CUDA(BV,PetscInt,PetscScalar*,PetscReal*); | ||
| 584 | SLEPC_INTERN PetscErrorCode BV_ApplySignature_CUDA(BV,PetscInt,PetscScalar*,PetscBool); | ||
| 585 | SLEPC_INTERN PetscErrorCode BV_SquareRoot_CUDA(BV,PetscInt,PetscScalar*,PetscReal*); | ||
| 586 | SLEPC_INTERN PetscErrorCode BV_StoreCoefficients_CUDA(BV,PetscInt,PetscScalar*,PetscScalar*); | ||
| 587 | #define BV_CleanCoefficients(a,b,c) ((a)->cuda?BV_CleanCoefficients_CUDA:BV_CleanCoefficients_Default)((a),(b),(c)) | ||
| 588 | #define BV_AddCoefficients(a,b,c,d) ((a)->cuda?BV_AddCoefficients_CUDA:BV_AddCoefficients_Default)((a),(b),(c),(d)) | ||
| 589 | #define BV_SetValue(a,b,c,d,e) ((a)->cuda?BV_SetValue_CUDA:BV_SetValue_Default)((a),(b),(c),(d),(e)) | ||
| 590 | #define BV_SquareSum(a,b,c,d) ((a)->cuda?BV_SquareSum_CUDA:BV_SquareSum_Default)((a),(b),(c),(d)) | ||
| 591 | #define BV_ApplySignature(a,b,c,d) ((a)->cuda?BV_ApplySignature_CUDA:BV_ApplySignature_Default)((a),(b),(c),(d)) | ||
| 592 | #define BV_SquareRoot(a,b,c,d) ((a)->cuda?BV_SquareRoot_CUDA:BV_SquareRoot_Default)((a),(b),(c),(d)) | ||
| 593 | #define BV_StoreCoefficients(a,b,c,d) ((a)->cuda?BV_StoreCoefficients_CUDA:BV_StoreCoefficients_Default)((a),(b),(c),(d)) | ||
| 594 | |||
| 595 | #elif PetscDefined(HAVE_HIP) | ||
| 596 | #include <petscdevice_cupm.h> | ||
| 597 | /* | ||
| 598 | BV_MatDenseHIPGetArrayRead - if Q is MATSEQDENSE it will allocate memory on the | ||
| 599 | GPU and copy the contents; otherwise, calls MatDenseHIPGetArrayRead() | ||
| 600 | */ | ||
| 601 | static inline PetscErrorCode BV_MatDenseHIPGetArrayRead(PETSC_UNUSED BV bv,Mat Q,const PetscScalar **d_q) | ||
| 602 | { | ||
| 603 | const PetscScalar *q; | ||
| 604 | PetscInt ldq,mq; | ||
| 605 | PetscCuBLASInt ldq_=0; | ||
| 606 | PetscBool matiship; | ||
| 607 | |||
| 608 | PetscFunctionBegin; | ||
| 609 | PetscCall(MatGetSize(Q,NULL,&mq)); | ||
| 610 | PetscCall(MatDenseGetLDA(Q,&ldq)); | ||
| 611 | PetscCall(PetscHipBLASIntCast(ldq,&ldq_)); | ||
| 612 | PetscCall(PetscObjectTypeCompare((PetscObject)Q,MATSEQDENSEHIP,&matiship)); | ||
| 613 | if (matiship) PetscCall(MatDenseHIPGetArrayRead(Q,d_q)); | ||
| 614 | else { | ||
| 615 | PetscCall(MatDenseGetArrayRead(Q,&q)); | ||
| 616 | PetscCallHIP(hipMalloc((void**)d_q,ldq*mq*sizeof(PetscScalar))); | ||
| 617 | PetscCallHIP(hipMemcpy((void*)*d_q,q,ldq*mq*sizeof(PetscScalar),hipMemcpyHostToDevice)); | ||
| 618 | PetscCall(PetscLogCpuToGpu(ldq*mq*sizeof(PetscScalar))); | ||
| 619 | } | ||
| 620 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 621 | } | ||
| 622 | |||
| 623 | /* | ||
| 624 | BV_MatDenseHIPRestoreArrayRead - restores the pointer obtained with BV_MatDenseHIPGetArrayRead(), | ||
| 625 | freeing the GPU memory in case of MATSEQDENSE | ||
| 626 | */ | ||
| 627 | static inline PetscErrorCode BV_MatDenseHIPRestoreArrayRead(PETSC_UNUSED BV bv,Mat Q,const PetscScalar **d_q) | ||
| 628 | { | ||
| 629 | PetscBool matiship; | ||
| 630 | |||
| 631 | PetscFunctionBegin; | ||
| 632 | PetscCall(PetscObjectTypeCompare((PetscObject)Q,MATSEQDENSEHIP,&matiship)); | ||
| 633 | if (matiship) PetscCall(MatDenseHIPRestoreArrayRead(Q,d_q)); | ||
| 634 | else { | ||
| 635 | PetscCall(MatDenseRestoreArrayRead(Q,NULL)); | ||
| 636 | PetscCallHIP(hipFree((void*)*d_q)); | ||
| 637 | *d_q = NULL; | ||
| 638 | } | ||
| 639 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 640 | } | ||
| 641 | |||
| 642 | /* | ||
| 643 | BV_VecPlaceArray - allows the user to replace the device array in a vector with a | ||
| 644 | device array provided by the caller, calling the accessor that corresponds to the | ||
| 645 | vector type being used by the BV object | ||
| 646 | */ | ||
| 647 | static inline PetscErrorCode BV_VecPlaceArray(PETSC_UNUSED BV bv,Vec v,PetscScalar *a) | ||
| 648 | { | ||
| 649 | PetscFunctionBegin; | ||
| 650 | #if PetscDefined(HAVE_KOKKOS_KERNELS) | ||
| 651 | if (bv->kokkos) { | ||
| 652 | PetscCall(VecKokkosPlaceArray(v,a)); | ||
| 653 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 654 | } | ||
| 655 | #endif | ||
| 656 | PetscCall(VecHIPPlaceArray(v,a)); | ||
| 657 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 658 | } | ||
| 659 | |||
| 660 | /* | ||
| 661 | BV_VecResetArray - resets the device array in a vector to the one it had before the | ||
| 662 | call to BV_VecPlaceArray() | ||
| 663 | */ | ||
| 664 | static inline PetscErrorCode BV_VecResetArray(PETSC_UNUSED BV bv,Vec v) | ||
| 665 | { | ||
| 666 | PetscFunctionBegin; | ||
| 667 | #if PetscDefined(HAVE_KOKKOS_KERNELS) | ||
| 668 | if (bv->kokkos) { | ||
| 669 | PetscCall(VecKokkosResetArray(v)); | ||
| 670 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 671 | } | ||
| 672 | #endif | ||
| 673 | PetscCall(VecHIPResetArray(v)); | ||
| 674 | PetscFunctionReturn(PETSC_SUCCESS); | ||
| 675 | } | ||
| 676 | |||
| 677 | SLEPC_INTERN PetscErrorCode BVMult_BLAS_HIP(BV,PetscInt,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 678 | SLEPC_INTERN PetscErrorCode BVMultVec_BLAS_HIP(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar,PetscScalar*); | ||
| 679 | SLEPC_INTERN PetscErrorCode BVMultInPlace_BLAS_HIP(BV,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscBool); | ||
| 680 | SLEPC_INTERN PetscErrorCode BVAXPY_BLAS_HIP(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscInt,PetscScalar,PetscScalar*,PetscInt); | ||
| 681 | SLEPC_INTERN PetscErrorCode BVDot_BLAS_HIP(BV,PetscInt,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscInt,PetscScalar*,PetscInt,PetscBool); | ||
| 682 | SLEPC_INTERN PetscErrorCode BVDotVec_BLAS_HIP(BV,PetscInt,PetscInt,const PetscScalar*,PetscInt,const PetscScalar*,PetscScalar*,PetscBool); | ||
| 683 | SLEPC_INTERN PetscErrorCode BVScale_BLAS_HIP(BV,PetscInt,PetscScalar*,PetscScalar); | ||
| 684 | SLEPC_INTERN PetscErrorCode BVNorm_BLAS_HIP(BV,PetscInt,const PetscScalar*,PetscReal*); | ||
| 685 | SLEPC_INTERN PetscErrorCode BVNormalize_BLAS_HIP(BV,PetscInt,PetscInt,PetscScalar*,PetscInt,PetscScalar*); | ||
| 686 | |||
| 687 | SLEPC_INTERN PetscErrorCode BV_CleanCoefficients_HIP(BV,PetscInt,PetscScalar*); | ||
| 688 | SLEPC_INTERN PetscErrorCode BV_AddCoefficients_HIP(BV,PetscInt,PetscScalar*,PetscScalar*); | ||
| 689 | SLEPC_INTERN PetscErrorCode BV_SetValue_HIP(BV,PetscInt,PetscInt,PetscScalar*,PetscScalar); | ||
| 690 | SLEPC_INTERN PetscErrorCode BV_SquareSum_HIP(BV,PetscInt,PetscScalar*,PetscReal*); | ||
| 691 | SLEPC_INTERN PetscErrorCode BV_ApplySignature_HIP(BV,PetscInt,PetscScalar*,PetscBool); | ||
| 692 | SLEPC_INTERN PetscErrorCode BV_SquareRoot_HIP(BV,PetscInt,PetscScalar*,PetscReal*); | ||
| 693 | SLEPC_INTERN PetscErrorCode BV_StoreCoefficients_HIP(BV,PetscInt,PetscScalar*,PetscScalar*); | ||
| 694 | #define BV_CleanCoefficients(a,b,c) ((a)->hip?BV_CleanCoefficients_HIP:BV_CleanCoefficients_Default)((a),(b),(c)) | ||
| 695 | #define BV_AddCoefficients(a,b,c,d) ((a)->hip?BV_AddCoefficients_HIP:BV_AddCoefficients_Default)((a),(b),(c),(d)) | ||
| 696 | #define BV_SetValue(a,b,c,d,e) ((a)->hip?BV_SetValue_HIP:BV_SetValue_Default)((a),(b),(c),(d),(e)) | ||
| 697 | #define BV_SquareSum(a,b,c,d) ((a)->hip?BV_SquareSum_HIP:BV_SquareSum_Default)((a),(b),(c),(d)) | ||
| 698 | #define BV_ApplySignature(a,b,c,d) ((a)->hip?BV_ApplySignature_HIP:BV_ApplySignature_Default)((a),(b),(c),(d)) | ||
| 699 | #define BV_SquareRoot(a,b,c,d) ((a)->hip?BV_SquareRoot_HIP:BV_SquareRoot_Default)((a),(b),(c),(d)) | ||
| 700 | #define BV_StoreCoefficients(a,b,c,d) ((a)->hip?BV_StoreCoefficients_HIP:BV_StoreCoefficients_Default)((a),(b),(c),(d)) | ||
| 701 | |||
| 702 | #else /* CPU */ | ||
| 703 | #define BV_CleanCoefficients(a,b,c) BV_CleanCoefficients_Default((a),(b),(c)) | ||
| 704 | #define BV_AddCoefficients(a,b,c,d) BV_AddCoefficients_Default((a),(b),(c),(d)) | ||
| 705 | #define BV_SetValue(a,b,c,d,e) BV_SetValue_Default((a),(b),(c),(d),(e)) | ||
| 706 | #define BV_SquareSum(a,b,c,d) BV_SquareSum_Default((a),(b),(c),(d)) | ||
| 707 | #define BV_ApplySignature(a,b,c,d) BV_ApplySignature_Default((a),(b),(c),(d)) | ||
| 708 | #define BV_SquareRoot(a,b,c,d) BV_SquareRoot_Default((a),(b),(c),(d)) | ||
| 709 | #define BV_StoreCoefficients(a,b,c,d) BV_StoreCoefficients_Default((a),(b),(c),(d)) | ||
| 710 | #endif /* PETSC_HAVE_CUDA */ | ||
| 711 |