Actual source code: slepc-interface.c
slepc-3.15.0 2021-03-31
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2021, 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: */
10: /*
11: Modification of the *temp* implementation of the BLOPEX multivector in order
12: to wrap created PETSc vectors as multivectors.
13: */
15: #include <slepc/private/bvimpl.h>
16: #include <stdlib.h>
17: #include <interpreter.h>
18: #include <temp_multivector.h>
19: #include "blopex.h"
21: static void* mv_TempMultiVectorCreateFromBV(void* ii_,BlopexInt n,void* sample)
22: {
23: PetscErrorCode ierr;
24: BV bv = (BV)sample;
25: Vec v;
26: PetscInt i,l,k,nc,useconstr=PETSC_FALSE,flg;
27: mv_TempMultiVector *x;
28: mv_InterfaceInterpreter *ii = (mv_InterfaceInterpreter*)ii_;
30: x = (mv_TempMultiVector*)malloc(sizeof(mv_TempMultiVector));
31: if (!x) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x failed");
33: x->interpreter = ii;
34: x->numVectors = n;
36: x->vector = (void**)calloc(n,sizeof(void*));
37: if (!x->vector) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x->vector failed");
39: x->ownsVectors = 1;
40: x->mask = NULL;
41: x->ownsMask = 0;
43: BVGetActiveColumns(bv,&l,&k);CHKERRABORT(PETSC_COMM_SELF,ierr);
44: PetscObjectComposedDataGetInt((PetscObject)bv,slepc_blopex_useconstr,useconstr,flg);CHKERRABORT(PETSC_COMM_SELF,ierr);
45: if (!l && flg && useconstr) {
46: BVGetNumConstraints(bv,&nc);CHKERRABORT(PETSC_COMM_SELF,ierr);
47: l = -nc;
48: }
49: if (n != k-l) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"BV active columns plus constraints do not match argument n");
50: for (i=0;i<n;i++) {
51: BVGetColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
52: PetscObjectReference((PetscObject)v);CHKERRABORT(PETSC_COMM_SELF,ierr);
53: x->vector[i] = (void*)v;
54: BVRestoreColumn(bv,l+i,&v);CHKERRABORT(PETSC_COMM_SELF,ierr);
55: }
56: return x;
57: }
59: /*
60: Create an InterfaceInterpreter using the PETSc implementation
61: but overloading CreateMultiVector that doesn't create any
62: new vector.
63: */
64: int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i)
65: {
66: PETSCSetupInterpreter(i);
67: i->CreateMultiVector = mv_TempMultiVectorCreateFromBV;
69: return 0;
70: }