| 1499 |
slepc |
1 |
/*
|
|
|
2 |
Modification of the *temp* implementation of the BLOPEX multivector in order
|
|
|
3 |
to wrap created PETSc vectors as multivectors.
|
|
|
4 |
|
|
|
5 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1672 |
slepc |
6 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
| 2116 |
eromero |
7 |
Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
|
| 1499 |
slepc |
8 |
|
| 1672 |
slepc |
9 |
This file is part of SLEPc.
|
|
|
10 |
|
|
|
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.
|
|
|
14 |
|
|
|
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.
|
|
|
19 |
|
|
|
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/>.
|
| 1499 |
slepc |
22 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
#include "petscsys.h"
|
|
|
26 |
#include "petscvec.h"
|
|
|
27 |
#include "petscmat.h"
|
|
|
28 |
#include <assert.h>
|
| 1524 |
slepc |
29 |
#include <stdlib.h>
|
| 1499 |
slepc |
30 |
#include "petscblaslapack.h"
|
|
|
31 |
#include "interpreter.h"
|
|
|
32 |
#include "temp_multivector.h"
|
|
|
33 |
#include "slepc-interface.h"
|
|
|
34 |
|
|
|
35 |
static void* mv_TempMultiVectorCreateFromPETScVector( void* ii_, int n, void* sample )
|
|
|
36 |
{
|
|
|
37 |
int i;
|
|
|
38 |
Vec *vecs = (Vec*)sample;
|
|
|
39 |
|
|
|
40 |
mv_TempMultiVector* x;
|
|
|
41 |
mv_InterfaceInterpreter* ii = (mv_InterfaceInterpreter*)ii_;
|
|
|
42 |
|
|
|
43 |
x = (mv_TempMultiVector*) malloc(sizeof(mv_TempMultiVector));
|
|
|
44 |
assert( x != NULL );
|
|
|
45 |
|
|
|
46 |
x->interpreter = ii;
|
|
|
47 |
x->numVectors = n;
|
|
|
48 |
|
|
|
49 |
x->vector = (void**) calloc( n, sizeof(void*) );
|
|
|
50 |
assert( x->vector != NULL );
|
|
|
51 |
|
|
|
52 |
x->ownsVectors = 1;
|
|
|
53 |
x->mask = NULL;
|
|
|
54 |
x->ownsMask = 0;
|
|
|
55 |
|
|
|
56 |
for ( i = 0; i < n; i++ ) {
|
|
|
57 |
x->vector[i] = (void*)vecs[i];
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
return x;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
static void mv_TempMultiPETSCVectorDestroy( void* x_ )
|
|
|
64 |
{
|
|
|
65 |
mv_TempMultiVector* x = (mv_TempMultiVector*)x_;
|
|
|
66 |
|
|
|
67 |
if ( x == NULL )
|
|
|
68 |
return;
|
|
|
69 |
|
|
|
70 |
if ( x->ownsVectors && x->vector != NULL ) {
|
|
|
71 |
free(x->vector);
|
|
|
72 |
}
|
|
|
73 |
if ( x->mask && x->ownsMask )
|
|
|
74 |
free(x->mask);
|
|
|
75 |
free(x);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
/*
|
|
|
80 |
Create an InterfaceInterpreter using the PETSc implementation
|
| 1974 |
eromero |
81 |
but overloading CreateMultiVector that doesn't create any
|
| 1499 |
slepc |
82 |
new vector.
|
|
|
83 |
*/
|
|
|
84 |
int SLEPCSetupInterpreter( mv_InterfaceInterpreter *i )
|
|
|
85 |
{
|
| 1974 |
eromero |
86 |
PETSCSetupInterpreter(i);
|
| 1499 |
slepc |
87 |
i->CreateMultiVector = mv_TempMultiVectorCreateFromPETScVector;
|
|
|
88 |
|
|
|
89 |
return 0;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/*
|
|
|
93 |
Change the multivector destructor in order to destroy the multivector
|
|
|
94 |
structure without destroy the PETSc vectors.
|
|
|
95 |
*/
|
|
|
96 |
void SLEPCSetupInterpreterForDignifiedDeath( mv_InterfaceInterpreter *i )
|
|
|
97 |
{
|
|
|
98 |
i->DestroyMultiVector = mv_TempMultiPETSCVectorDestroy;
|
|
|
99 |
}
|
|
|
100 |
|