Actual source code: bvimpl.h
slepc-3.13.1 2020-04-12
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2020, Universitat Politecnica de Valencia, Spain
6: This file is part of SLEPc.
7: SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9: */
11: #if !defined(SLEPCBVIMPL_H)
12: #define SLEPCBVIMPL_H
14: #include <slepcbv.h>
15: #include <slepc/private/slepcimpl.h>
17: SLEPC_EXTERN PetscBool BVRegisterAllCalled;
18: SLEPC_EXTERN PetscErrorCode BVRegisterAll(void);
20: 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_SetRandom,BV_MatMult,BV_MatMultVec,BV_MatProject;
22: typedef struct _BVOps *BVOps;
24: struct _BVOps {
25: PetscErrorCode (*mult)(BV,PetscScalar,PetscScalar,BV,Mat);
26: PetscErrorCode (*multvec)(BV,PetscScalar,PetscScalar,Vec,PetscScalar*);
27: PetscErrorCode (*multinplace)(BV,Mat,PetscInt,PetscInt);
28: PetscErrorCode (*multinplacetrans)(BV,Mat,PetscInt,PetscInt);
29: PetscErrorCode (*dot)(BV,BV,Mat);
30: PetscErrorCode (*dotvec)(BV,Vec,PetscScalar*);
31: PetscErrorCode (*dotvec_local)(BV,Vec,PetscScalar*);
32: PetscErrorCode (*dotvec_begin)(BV,Vec,PetscScalar*);
33: PetscErrorCode (*dotvec_end)(BV,Vec,PetscScalar*);
34: PetscErrorCode (*scale)(BV,PetscInt,PetscScalar);
35: PetscErrorCode (*norm)(BV,PetscInt,NormType,PetscReal*);
36: PetscErrorCode (*norm_local)(BV,PetscInt,NormType,PetscReal*);
37: PetscErrorCode (*norm_begin)(BV,PetscInt,NormType,PetscReal*);
38: PetscErrorCode (*norm_end)(BV,PetscInt,NormType,PetscReal*);
39: PetscErrorCode (*matmult)(BV,Mat,BV);
40: PetscErrorCode (*copy)(BV,BV);
41: PetscErrorCode (*copycolumn)(BV,PetscInt,PetscInt);
42: PetscErrorCode (*resize)(BV,PetscInt,PetscBool);
43: PetscErrorCode (*getcolumn)(BV,PetscInt,Vec*);
44: PetscErrorCode (*restorecolumn)(BV,PetscInt,Vec*);
45: PetscErrorCode (*getarray)(BV,PetscScalar**);
46: PetscErrorCode (*restorearray)(BV,PetscScalar**);
47: PetscErrorCode (*getarrayread)(BV,const PetscScalar**);
48: PetscErrorCode (*restorearrayread)(BV,const PetscScalar**);
49: PetscErrorCode (*restoresplit)(BV,BV*,BV*);
50: PetscErrorCode (*gramschmidt)(BV,PetscInt,Vec,PetscBool*,PetscScalar*,PetscScalar*,PetscReal*,PetscReal*);
51: PetscErrorCode (*duplicate)(BV,BV);
52: PetscErrorCode (*create)(BV);
53: PetscErrorCode (*setfromoptions)(PetscOptionItems*,BV);
54: PetscErrorCode (*view)(BV,PetscViewer);
55: PetscErrorCode (*destroy)(BV);
56: };
58: struct _p_BV {
59: PETSCHEADER(struct _BVOps);
60: /*------------------------- User parameters --------------------------*/
61: Vec t; /* template vector */
62: PetscInt n,N; /* dimensions of vectors (local, global) */
63: PetscInt m; /* number of vectors */
64: PetscInt l; /* number of leading columns */
65: PetscInt k; /* number of active columns */
66: PetscInt nc; /* number of constraints */
67: BVOrthogType orthog_type; /* the method of vector orthogonalization */
68: BVOrthogRefineType orthog_ref; /* refinement method */
69: PetscReal orthog_eta; /* refinement threshold */
70: BVOrthogBlockType orthog_block; /* the method of block orthogonalization */
71: Mat matrix; /* inner product matrix */
72: PetscBool indef; /* matrix is indefinite */
73: BVMatMultType vmm; /* version of matmult operation */
74: PetscBool rrandom; /* reproducible random vectors */
76: /*---------------------- Cached data and workspace -------------------*/
77: Vec buffer; /* buffer vector used in orthogonalization */
78: Mat Abuffer; /* auxiliary seqdense matrix that wraps the buffer */
79: Vec Bx; /* result of matrix times a vector x */
80: PetscObjectId xid; /* object id of vector x */
81: PetscObjectState xstate; /* state of vector x */
82: Vec cv[2]; /* column vectors obtained with BVGetColumn() */
83: PetscInt ci[2]; /* column indices of obtained vectors */
84: PetscObjectState st[2]; /* state of obtained vectors */
85: PetscObjectId id[2]; /* object id of obtained vectors */
86: PetscScalar *h,*c; /* orthogonalization coefficients */
87: Vec omega; /* signature matrix values for indefinite case */
88: PetscBool defersfo; /* deferred call to setfromoptions */
89: BV cached; /* cached BV to store result of matrix times BV */
90: PetscObjectState bvstate; /* state of BV when BVApplyMatrixBV() was called */
91: BV L,R; /* BV objects obtained with BVGetSplit() */
92: PetscObjectState lstate,rstate;/* state of L and R when BVGetSplit() was called */
93: PetscInt lsplit; /* the value of l when BVGetSplit() was called */
94: PetscInt issplit; /* >0 if this BV has been created by splitting (1=left, 2=right) */
95: BV splitparent; /* my parent if I am a split BV */
96: PetscRandom rand; /* random number generator */
97: Mat Acreate; /* matrix given at BVCreateFromMat() */
98: Mat Aget; /* matrix returned for BVGetMat() */
99: PetscBool cuda; /* true if GPU must be used in SVEC */
100: PetscScalar *work;
101: PetscInt lwork;
102: void *data;
103: };
105: /*
106: BV_SafeSqrt - Computes the square root of a scalar value alpha, which is
107: assumed to be z'*B*z. The result is
108: if definite inner product: res = sqrt(alpha)
109: if indefinite inner product: res = sgn(alpha)*sqrt(abs(alpha))
110: */
111: PETSC_STATIC_INLINE PetscErrorCode BV_SafeSqrt(BV bv,PetscScalar alpha,PetscReal *res)
112: {
114: PetscReal absal,realp;
117: absal = PetscAbsScalar(alpha);
118: realp = PetscRealPart(alpha);
119: if (absal<PETSC_MACHINE_EPSILON) {
120: PetscInfo(bv,"Zero norm, either the vector is zero or a semi-inner product is being used\n");
121: }
122: #if defined(PETSC_USE_COMPLEX)
123: if (PetscAbsReal(PetscImaginaryPart(alpha))>10*PETSC_MACHINE_EPSILON && PetscAbsReal(PetscImaginaryPart(alpha))/absal>100*PETSC_MACHINE_EPSILON) SETERRQ1(PetscObjectComm((PetscObject)bv),1,"The inner product is not well defined: nonzero imaginary part %g",PetscImaginaryPart(alpha));
124: #endif
125: if (bv->indef) {
126: *res = (realp<0.0)? -PetscSqrtReal(-realp): PetscSqrtReal(realp);
127: } else {
128: if (realp<-10*PETSC_MACHINE_EPSILON) SETERRQ(PetscObjectComm((PetscObject)bv),1,"The inner product is not well defined: indefinite matrix");
129: *res = (realp<0.0)? 0.0: PetscSqrtReal(realp);
130: }
131: return(0);
132: }
134: /*
135: BV_IPMatMult - Multiply a vector x by the inner-product matrix, cache the
136: result in Bx.
137: */
138: PETSC_STATIC_INLINE PetscErrorCode BV_IPMatMult(BV bv,Vec x)
139: {
143: if (((PetscObject)x)->id != bv->xid || ((PetscObject)x)->state != bv->xstate) {
144: if (!bv->Bx) {
145: MatCreateVecs(bv->matrix,&bv->Bx,NULL);
146: PetscLogObjectParent((PetscObject)bv,(PetscObject)bv->Bx);
147: }
148: MatMult(bv->matrix,x,bv->Bx);
149: PetscObjectGetId((PetscObject)x,&bv->xid);
150: PetscObjectStateGet((PetscObject)x,&bv->xstate);
151: }
152: return(0);
153: }
155: /*
156: BV_IPMatMultBV - Multiply BV by the inner-product matrix, cache the
157: result internally in bv->cached.
158: */
159: PETSC_STATIC_INLINE PetscErrorCode BV_IPMatMultBV(BV bv)
160: {
164: BVGetCachedBV(bv,&bv->cached);
165: if (((PetscObject)bv)->state != bv->bvstate || bv->l != bv->cached->l || bv->k != bv->cached->k) {
166: BVSetActiveColumns(bv->cached,bv->l,bv->k);
167: if (bv->matrix) {
168: BVMatMult(bv,bv->matrix,bv->cached);
169: } else {
170: BVCopy(bv,bv->cached);
171: }
172: bv->bvstate = ((PetscObject)bv)->state;
173: }
174: return(0);
175: }
177: /*
178: BV_AllocateCoeffs - Allocate orthogonalization coefficients if not done already.
179: */
180: PETSC_STATIC_INLINE PetscErrorCode BV_AllocateCoeffs(BV bv)
181: {
185: if (!bv->h) {
186: PetscMalloc2(bv->nc+bv->m,&bv->h,bv->nc+bv->m,&bv->c);
187: PetscLogObjectMemory((PetscObject)bv,2*bv->m*sizeof(PetscScalar));
188: }
189: return(0);
190: }
192: /*
193: BV_AllocateSignature - Allocate signature coefficients if not done already.
194: */
195: PETSC_STATIC_INLINE PetscErrorCode BV_AllocateSignature(BV bv)
196: {
200: if (bv->indef && !bv->omega) {
201: if (bv->cuda) {
202: #if defined(PETSC_HAVE_CUDA)
203: VecCreateSeqCUDA(PETSC_COMM_SELF,bv->nc+bv->m,&bv->omega);
204: #else
205: SETERRQ(PetscObjectComm((PetscObject)bv),1,"Something wrong happened");
206: #endif
207: } else {
208: VecCreateSeq(PETSC_COMM_SELF,bv->nc+bv->m,&bv->omega);
209: }
210: PetscLogObjectParent((PetscObject)bv,(PetscObject)bv->omega);
211: VecSet(bv->omega,1.0);
212: }
213: return(0);
214: }
216: /*
217: BVAvailableVec: First (0) or second (1) vector available for
218: getcolumn operation (or -1 if both vectors already fetched).
219: */
220: #define BVAvailableVec (((bv->ci[0]==-bv->nc-1)? 0: (bv->ci[1]==-bv->nc-1)? 1: -1))
222: /*
223: Macros to test valid BV arguments
224: */
225: #if !defined(PETSC_USE_DEBUG)
227: #define BVCheckSizes(h,arg) do {} while (0)
228: #define BVCheckOp(h,arg,op) do {} while (0)
230: #else
232: #define BVCheckSizes(h,arg) \
233: do { \
234: if (!(h)->m) SETERRQ1(PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"BV sizes have not been defined: Parameter #%d",arg); \
235: } while (0)
237: #define BVCheckOp(h,arg,op) \
238: do { \
239: if (!(h)->ops->op) SETERRQ1(PetscObjectComm((PetscObject)(h)),PETSC_ERR_SUP,"Operation not implemented in this BV type: Parameter #%d",arg); \
240: } while (0)
242: #endif
244: SLEPC_INTERN PetscErrorCode BVView_Vecs(BV,PetscViewer);
246: SLEPC_INTERN PetscErrorCode BVAllocateWork_Private(BV,PetscInt);
248: SLEPC_INTERN PetscErrorCode BVMult_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar,const PetscScalar*,const PetscScalar*,PetscScalar,PetscScalar*);
249: SLEPC_INTERN PetscErrorCode BVMultVec_BLAS_Private(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,const PetscScalar*,PetscScalar,PetscScalar*);
250: SLEPC_INTERN PetscErrorCode BVMultInPlace_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar*,const PetscScalar*,PetscBool);
251: SLEPC_INTERN PetscErrorCode BVMultInPlace_Vecs_Private(BV,PetscInt,PetscInt,PetscInt,Vec*,const PetscScalar*,PetscBool);
252: SLEPC_INTERN PetscErrorCode BVAXPY_BLAS_Private(BV,PetscInt,PetscInt,PetscScalar,const PetscScalar*,PetscScalar,PetscScalar*);
253: SLEPC_INTERN PetscErrorCode BVDot_BLAS_Private(BV,PetscInt,PetscInt,PetscInt,PetscInt,const PetscScalar*,const PetscScalar*,PetscScalar*,PetscBool);
254: SLEPC_INTERN PetscErrorCode BVDotVec_BLAS_Private(BV,PetscInt,PetscInt,const PetscScalar*,const PetscScalar*,PetscScalar*,PetscBool);
255: SLEPC_INTERN PetscErrorCode BVScale_BLAS_Private(BV,PetscInt,PetscScalar*,PetscScalar);
256: SLEPC_INTERN PetscErrorCode BVNorm_LAPACK_Private(BV,PetscInt,PetscInt,const PetscScalar*,NormType,PetscReal*,PetscBool);
257: SLEPC_INTERN PetscErrorCode BVMatCholInv_LAPACK_Private(BV,Mat,Mat);
258: SLEPC_INTERN PetscErrorCode BVMatTriInv_LAPACK_Private(BV,Mat,Mat);
259: SLEPC_INTERN PetscErrorCode BVMatSVQB_LAPACK_Private(BV,Mat,Mat);
260: SLEPC_INTERN PetscErrorCode BVOrthogonalize_LAPACK_TSQR(BV,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscInt);
261: SLEPC_INTERN PetscErrorCode BVOrthogonalize_LAPACK_TSQR_OnlyR(BV,PetscInt,PetscInt,PetscScalar*,PetscScalar*,PetscInt);
263: /* reduction operation used in BVOrthogonalize */
264: SLEPC_EXTERN MPI_Op MPIU_TSQR;
265: SLEPC_EXTERN void MPIAPI SlepcGivensPacked(void*,void*,PetscMPIInt*,MPI_Datatype*);
267: #if defined(PETSC_HAVE_CUDA)
269: /* complex single */
270: #if defined(PETSC_USE_COMPLEX)
271: #if defined(PETSC_USE_REAL_SINGLE)
272: #define cublasXgemm(a,b,c,d,e,f,g,h,i,j,k,l,m,n) cublasCgemm((a),(b),(c),(d),(e),(f),(cuComplex*)(g),(cuComplex*)(h),(i),(cuComplex*)(j),(k),(cuComplex*)(l),(cuComplex*)(m),(n))
273: #define cublasXgemv(a,b,c,d,e,f,g,h,i,j,k,l) cublasCgemv((a),(b),(c),(d),(cuComplex*)(e),(cuComplex*)(f),(g),(cuComplex*)(h),(i),(cuComplex*)(j),(cuComplex*)(k),(l))
274: #define cublasXscal(a,b,c,d,e) cublasCscal(a,b,(const cuComplex*)(c),(cuComplex*)(d),e)
275: #define cublasXnrm2(a,b,c,d,e) cublasScnrm2(a,b,(const cuComplex*)(c),d,e)
276: #define cublasXaxpy(a,b,c,d,e,f,g) cublasCaxpy((a),(b),(cuComplex*)(c),(cuComplex*)(d),(e),(cuComplex*)(f),(g))
277: #define cublasXdotc(a,b,c,d,e,f,g) cublasCdotc((a),(b),(const cuComplex *)(c),(d),(const cuComplex *)(e),(f),(cuComplex *)(g))
278: #else /* complex double */
279: #define cublasXgemm(a,b,c,d,e,f,g,h,i,j,k,l,m,n) cublasZgemm((a),(b),(c),(d),(e),(f),(cuDoubleComplex*)(g),(cuDoubleComplex*)(h),(i),(cuDoubleComplex*)(j),(k),(cuDoubleComplex*)(l),(cuDoubleComplex*)(m),(n))
280: #define cublasXgemv(a,b,c,d,e,f,g,h,i,j,k,l) cublasZgemv((a),(b),(c),(d),(cuDoubleComplex*)(e),(cuDoubleComplex*)(f),(g),(cuDoubleComplex*)(h),(i),(cuDoubleComplex*)(j),(cuDoubleComplex*)(k),(l))
281: #define cublasXscal(a,b,c,d,e) cublasZscal(a,b,(const cuDoubleComplex*)(c),(cuDoubleComplex*)(d),e)
282: #define cublasXnrm2(a,b,c,d,e) cublasDznrm2(a,b,(const cuDoubleComplex*)(c),d,e)
283: #define cublasXaxpy(a,b,c,d,e,f,g) cublasZaxpy((a),(b),(cuDoubleComplex*)(c),(cuDoubleComplex*)(d),(e),(cuDoubleComplex*)(f),(g))
284: #define cublasXdotc(a,b,c,d,e,f,g) cublasZdotc((a),(b),(const cuDoubleComplex *)(c),(d),(const cuDoubleComplex *)(e),(f),(cuDoubleComplex *)(g))
285: #endif
286: #else /* real single */
287: #if defined(PETSC_USE_REAL_SINGLE)
288: #define cublasXgemm cublasSgemm
289: #define cublasXgemv cublasSgemv
290: #define cublasXscal cublasSscal
291: #define cublasXnrm2 cublasSnrm2
292: #define cublasXaxpy cublasSaxpy
293: #define cublasXdotc cublasSdot
294: #else /* real double */
295: #define cublasXgemm cublasDgemm
296: #define cublasXgemv cublasDgemv
297: #define cublasXscal cublasDscal
298: #define cublasXnrm2 cublasDnrm2
299: #define cublasXaxpy cublasDaxpy
300: #define cublasXdotc cublasDdot
301: #endif
302: #endif
304: SLEPC_INTERN PetscErrorCode BV_CleanCoefficients_CUDA(BV,PetscInt,PetscScalar*);
305: SLEPC_INTERN PetscErrorCode BV_AddCoefficients_CUDA(BV,PetscInt,PetscScalar*,PetscScalar*);
306: SLEPC_INTERN PetscErrorCode BV_SetValue_CUDA(BV,PetscInt,PetscInt,PetscScalar*,PetscScalar);
307: SLEPC_INTERN PetscErrorCode BV_SquareSum_CUDA(BV,PetscInt,PetscScalar*,PetscReal*);
308: SLEPC_INTERN PetscErrorCode BV_ApplySignature_CUDA(BV,PetscInt,PetscScalar*,PetscBool);
309: SLEPC_INTERN PetscErrorCode BV_SquareRoot_CUDA(BV,PetscInt,PetscScalar*,PetscReal*);
310: SLEPC_INTERN PetscErrorCode BV_StoreCoefficients_CUDA(BV,PetscInt,PetscScalar*,PetscScalar*);
312: #endif /* PETSC_HAVE_CUDA */
314: /*
315: BV_CleanCoefficients_Default - Sets to zero all entries of column j of the bv buffer
316: */
317: PETSC_STATIC_INLINE PetscErrorCode BV_CleanCoefficients_Default(BV bv,PetscInt j,PetscScalar *h)
318: {
320: PetscScalar *hh=h,*a;
321: PetscInt i;
324: if (!h) {
325: VecGetArray(bv->buffer,&a);
326: hh = a + j*(bv->nc+bv->m);
327: }
328: for (i=0;i<bv->nc+j;i++) hh[i] = 0.0;
329: if (!h) { VecRestoreArray(bv->buffer,&a); }
330: return(0);
331: }
333: /*
334: BV_AddCoefficients_Default - Add the contents of the scratch (0-th column) of the bv buffer
335: into column j of the bv buffer
336: */
337: PETSC_STATIC_INLINE PetscErrorCode BV_AddCoefficients_Default(BV bv,PetscInt j,PetscScalar *h,PetscScalar *c)
338: {
340: PetscScalar *hh=h,*cc=c;
341: PetscInt i;
344: if (!h) {
345: VecGetArray(bv->buffer,&cc);
346: hh = cc + j*(bv->nc+bv->m);
347: }
348: for (i=0;i<bv->nc+j;i++) hh[i] += cc[i];
349: if (!h) { VecRestoreArray(bv->buffer,&cc); }
350: return(0);
351: }
353: /*
354: BV_SetValue_Default - Sets value in row j (counted after the constraints) of column k
355: of the coefficients array
356: */
357: PETSC_STATIC_INLINE PetscErrorCode BV_SetValue_Default(BV bv,PetscInt j,PetscInt k,PetscScalar *h,PetscScalar value)
358: {
360: PetscScalar *hh=h,*a;
363: if (!h) {
364: VecGetArray(bv->buffer,&a);
365: hh = a + k*(bv->nc+bv->m);
366: }
367: hh[bv->nc+j] = value;
368: if (!h) { VecRestoreArray(bv->buffer,&a); }
369: return(0);
370: }
372: /*
373: BV_SquareSum_Default - Returns the value h'*h, where h represents the contents of the
374: coefficients array (up to position j)
375: */
376: PETSC_STATIC_INLINE PetscErrorCode BV_SquareSum_Default(BV bv,PetscInt j,PetscScalar *h,PetscReal *sum)
377: {
379: PetscScalar *hh=h;
380: PetscInt i;
383: *sum = 0.0;
384: if (!h) { VecGetArray(bv->buffer,&hh); }
385: for (i=0;i<bv->nc+j;i++) *sum += PetscRealPart(hh[i]*PetscConj(hh[i]));
386: if (!h) { VecRestoreArray(bv->buffer,&hh); }
387: return(0);
388: }
390: /*
391: BV_ApplySignature_Default - Computes the pointwise product h*omega, where h represents
392: the contents of the coefficients array (up to position j) and omega is the signature;
393: if inverse=TRUE then the operation is h/omega
394: */
395: PETSC_STATIC_INLINE PetscErrorCode BV_ApplySignature_Default(BV bv,PetscInt j,PetscScalar *h,PetscBool inverse)
396: {
397: PetscErrorCode ierr;
398: PetscScalar *hh=h;
399: PetscInt i;
400: const PetscScalar *omega;
403: if (!(bv->nc+j)) return(0);
404: if (!h) { VecGetArray(bv->buffer,&hh); }
405: VecGetArrayRead(bv->omega,&omega);
406: if (inverse) for (i=0;i<bv->nc+j;i++) hh[i] /= PetscRealPart(omega[i]);
407: else for (i=0;i<bv->nc+j;i++) hh[i] *= PetscRealPart(omega[i]);
408: VecRestoreArrayRead(bv->omega,&omega);
409: if (!h) { VecRestoreArray(bv->buffer,&hh); }
410: return(0);
411: }
413: /*
414: BV_SquareRoot_Default - Returns the square root of position j (counted after the constraints)
415: of the coefficients array
416: */
417: PETSC_STATIC_INLINE PetscErrorCode BV_SquareRoot_Default(BV bv,PetscInt j,PetscScalar *h,PetscReal *beta)
418: {
420: PetscScalar *hh=h;
423: if (!h) { VecGetArray(bv->buffer,&hh); }
424: BV_SafeSqrt(bv,hh[bv->nc+j],beta);
425: if (!h) { VecRestoreArray(bv->buffer,&hh); }
426: return(0);
427: }
429: /*
430: BV_StoreCoefficients_Default - Copy the contents of the coefficients array to an array dest
431: provided by the caller (only values from l to j are copied)
432: */
433: PETSC_STATIC_INLINE PetscErrorCode BV_StoreCoefficients_Default(BV bv,PetscInt j,PetscScalar *h,PetscScalar *dest)
434: {
436: PetscScalar *hh=h,*a;
437: PetscInt i;
440: if (!h) {
441: VecGetArray(bv->buffer,&a);
442: hh = a + j*(bv->nc+bv->m);
443: }
444: for (i=bv->l;i<j;i++) dest[i-bv->l] = hh[bv->nc+i];
445: if (!h) { VecRestoreArray(bv->buffer,&a); }
446: return(0);
447: }
449: /*
450: BV_GetEigenvector - retrieves k-th eigenvector from basis vectors V.
451: The argument eigi is the imaginary part of the corresponding eigenvalue.
452: */
453: PETSC_STATIC_INLINE PetscErrorCode BV_GetEigenvector(BV V,PetscInt k,PetscScalar eigi,Vec Vr,Vec Vi)
454: {
458: #if defined(PETSC_USE_COMPLEX)
459: if (Vr) { BVCopyVec(V,k,Vr); }
460: if (Vi) { VecSet(Vi,0.0); }
461: #else
462: if (eigi > 0.0) { /* first value of conjugate pair */
463: if (Vr) { BVCopyVec(V,k,Vr); }
464: if (Vi) { BVCopyVec(V,k+1,Vi); }
465: } else if (eigi < 0.0) { /* second value of conjugate pair */
466: if (Vr) { BVCopyVec(V,k-1,Vr); }
467: if (Vi) {
468: BVCopyVec(V,k,Vi);
469: VecScale(Vi,-1.0);
470: }
471: } else { /* real eigenvalue */
472: if (Vr) { BVCopyVec(V,k,Vr); }
473: if (Vi) { VecSet(Vi,0.0); }
474: }
475: #endif
476: return(0);
477: }
479: #if defined(PETSC_HAVE_CUDA)
480: #define BV_CleanCoefficients(a,b,c) ((a)->cuda?BV_CleanCoefficients_CUDA:BV_CleanCoefficients_Default)((a),(b),(c))
481: #define BV_AddCoefficients(a,b,c,d) ((a)->cuda?BV_AddCoefficients_CUDA:BV_AddCoefficients_Default)((a),(b),(c),(d))
482: #define BV_SetValue(a,b,c,d,e) ((a)->cuda?BV_SetValue_CUDA:BV_SetValue_Default)((a),(b),(c),(d),(e))
483: #define BV_SquareSum(a,b,c,d) ((a)->cuda?BV_SquareSum_CUDA:BV_SquareSum_Default)((a),(b),(c),(d))
484: #define BV_ApplySignature(a,b,c,d) ((a)->cuda?BV_ApplySignature_CUDA:BV_ApplySignature_Default)((a),(b),(c),(d))
485: #define BV_SquareRoot(a,b,c,d) ((a)->cuda?BV_SquareRoot_CUDA:BV_SquareRoot_Default)((a),(b),(c),(d))
486: #define BV_StoreCoefficients(a,b,c,d) ((a)->cuda?BV_StoreCoefficients_CUDA:BV_StoreCoefficients_Default)((a),(b),(c),(d))
487: #else
488: #define BV_CleanCoefficients(a,b,c) BV_CleanCoefficients_Default((a),(b),(c))
489: #define BV_AddCoefficients(a,b,c,d) BV_AddCoefficients_Default((a),(b),(c),(d))
490: #define BV_SetValue(a,b,c,d,e) BV_SetValue_Default((a),(b),(c),(d),(e))
491: #define BV_SquareSum(a,b,c,d) BV_SquareSum_Default((a),(b),(c),(d))
492: #define BV_ApplySignature(a,b,c,d) BV_ApplySignature_Default((a),(b),(c),(d))
493: #define BV_SquareRoot(a,b,c,d) BV_SquareRoot_Default((a),(b),(c),(d))
494: #define BV_StoreCoefficients(a,b,c,d) BV_StoreCoefficients_Default((a),(b),(c),(d))
495: #endif /* PETSC_HAVE_CUDA */
497: #endif