Actual source code: slepc-interface.c
slepc-3.22.2 2024-12-02
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-, 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: BV bv = (BV)sample;
24: Vec v;
25: PetscInt i,l,k,nc,useconstr=PETSC_FALSE,flg;
26: mv_TempMultiVector *x;
27: mv_InterfaceInterpreter *ii = (mv_InterfaceInterpreter*)ii_;
29: x = (mv_TempMultiVector*)malloc(sizeof(mv_TempMultiVector));
30: if (!x) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x failed");
32: x->interpreter = ii;
33: x->numVectors = n;
35: x->vector = (void**)calloc(n,sizeof(void*));
36: if (!x->vector) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x->vector failed");
38: x->ownsVectors = 1;
39: x->mask = NULL;
40: x->ownsMask = 0;
42: PetscCallAbort(PETSC_COMM_SELF,BVGetActiveColumns(bv,&l,&k));
43: PetscCallAbort(PETSC_COMM_SELF,PetscObjectComposedDataGetInt((PetscObject)bv,slepc_blopex_useconstr,useconstr,flg));
44: if (!l && flg && useconstr) {
45: PetscCallAbort(PETSC_COMM_SELF,BVGetNumConstraints(bv,&nc));
46: l = -nc;
47: }
48: if (n != k-l) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"BV active columns plus constraints do not match argument n");
49: for (i=0;i<n;i++) {
50: PetscCallAbort(PETSC_COMM_SELF,BVGetColumn(bv,l+i,&v));
51: PetscCallAbort(PETSC_COMM_SELF,PetscObjectReference((PetscObject)v));
52: x->vector[i] = (void*)v;
53: PetscCallAbort(PETSC_COMM_SELF,BVRestoreColumn(bv,l+i,&v));
54: }
55: return x;
56: }
58: /*
59: Create an InterfaceInterpreter using the PETSc implementation
60: but overloading CreateMultiVector that doesn't create any
61: new vector.
62: */
63: int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i)
64: {
65: PETSCSetupInterpreter(i);
66: i->CreateMultiVector = mv_TempMultiVectorCreateFromBV;
68: return 0;
69: }