1: /*
2: Modification of the *temp* implementation of the BLOPEX multivector in order
3: to wrap created PETSc vectors as multivectors.
5: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6: SLEPc - Scalable Library for Eigenvalue Problem Computations
7: Copyright (c) 2002-2014, Universitat Politecnica de Valencia, Spain
9: This file is part of SLEPc.
11: SLEPc is free software: you can redistribute it and/or modify it under the
12: terms of version 3 of the GNU Lesser General Public License as published by
13: the Free Software Foundation.
15: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
16: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
18: more details.
20: You should have received a copy of the GNU Lesser General Public License
21: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
22: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23: */
25: #include <slepcbv.h>
26: #include <petscvec.h>
27: #include <stdlib.h>
28: #include <blopex_interpreter.h>
29: #include <blopex_temp_multivector.h>
30: #include "slepc-interface.h"
32: static void* mv_TempMultiVectorCreateFromBV(void* ii_,BlopexInt n,void* sample) 33: {
34: int i;
35: BV bv = (BV)sample;
36: Vec v;
38: mv_TempMultiVector* x;
39: mv_InterfaceInterpreter* ii = (mv_InterfaceInterpreter*)ii_;
41: x = (mv_TempMultiVector*)malloc(sizeof(mv_TempMultiVector));
42: if (!x) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x failed");
44: x->interpreter = ii;
45: x->numVectors = n;
47: x->vector = (void**)calloc(n,sizeof(void*));
48: if (!x->vector) SETERRABORT(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Allocation for x->vector failed");
50: x->ownsVectors = 1;
51: x->mask = NULL;
52: x->ownsMask = 0;
54: for (i=0;i<n;i++) {
55: BVGetColumn(bv,i,&v);
56: PetscObjectReference((PetscObject)v);
57: x->vector[i] = (void*)v;
58: BVRestoreColumn(bv,i,&v);
59: }
60: return x;
61: }
63: static void mv_TempMultiPETSCVectorDestroy(void* x_) 64: {
65: mv_TempMultiVector* x = (mv_TempMultiVector*)x_;
67: if (!x) return;
69: if (x->ownsVectors && x->vector) free(x->vector);
70: if (x->mask && x->ownsMask) free(x->mask);
71: free(x);
72: }
74: /*
75: Create an InterfaceInterpreter using the PETSc implementation
76: but overloading CreateMultiVector that doesn't create any
77: new vector.
78: */
79: int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i) 80: {
81: PETSCSetupInterpreter(i);
82: i->CreateMultiVector = mv_TempMultiVectorCreateFromBV;
84: return 0;
85: }
87: /*
88: Change the multivector destructor in order to destroy the multivector
89: structure without destroy the PETSc vectors.
90: */
91: void SLEPCSetupInterpreterForDignifiedDeath(mv_InterfaceInterpreter *i) 92: {
93: i->DestroyMultiVector = mv_TempMultiPETSCVectorDestroy;
94: }