| 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 |
|
| 2283 |
jroman |
25 |
#include <petscsys.h>
|
|
|
26 |
#include <petscvec.h>
|
| 1499 |
slepc |
27 |
#include <assert.h>
|
| 1524 |
slepc |
28 |
#include <stdlib.h>
|
| 2423 |
jroman |
29 |
#include <blopex_interpreter.h>
|
|
|
30 |
#include <blopex_temp_multivector.h>
|
| 1499 |
slepc |
31 |
#include "slepc-interface.h"
|
|
|
32 |
|
| 2331 |
jroman |
33 |
static void* mv_TempMultiVectorCreateFromPETScVector(void* ii_,int n,void* sample)
|
| 1499 |
slepc |
34 |
{
|
|
|
35 |
int i;
|
|
|
36 |
Vec *vecs = (Vec*)sample;
|
|
|
37 |
|
|
|
38 |
mv_TempMultiVector* x;
|
|
|
39 |
mv_InterfaceInterpreter* ii = (mv_InterfaceInterpreter*)ii_;
|
|
|
40 |
|
| 2331 |
jroman |
41 |
x = (mv_TempMultiVector*)malloc(sizeof(mv_TempMultiVector));
|
|
|
42 |
assert(x!=NULL);
|
| 1499 |
slepc |
43 |
|
|
|
44 |
x->interpreter = ii;
|
|
|
45 |
x->numVectors = n;
|
|
|
46 |
|
| 2331 |
jroman |
47 |
x->vector = (void**)calloc(n,sizeof(void*));
|
|
|
48 |
assert(x->vector!=NULL);
|
| 1499 |
slepc |
49 |
|
|
|
50 |
x->ownsVectors = 1;
|
|
|
51 |
x->mask = NULL;
|
|
|
52 |
x->ownsMask = 0;
|
|
|
53 |
|
| 2331 |
jroman |
54 |
for (i=0;i<n;i++) {
|
| 1499 |
slepc |
55 |
x->vector[i] = (void*)vecs[i];
|
|
|
56 |
}
|
|
|
57 |
return x;
|
|
|
58 |
}
|
|
|
59 |
|
| 2331 |
jroman |
60 |
static void mv_TempMultiPETSCVectorDestroy(void* x_)
|
| 1499 |
slepc |
61 |
{
|
|
|
62 |
mv_TempMultiVector* x = (mv_TempMultiVector*)x_;
|
|
|
63 |
|
| 2331 |
jroman |
64 |
if (x==NULL)
|
| 1499 |
slepc |
65 |
return;
|
|
|
66 |
|
| 2331 |
jroman |
67 |
if (x->ownsVectors && x->vector!=NULL) free(x->vector);
|
|
|
68 |
if (x->mask && x->ownsMask) free(x->mask);
|
| 1499 |
slepc |
69 |
free(x);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/*
|
|
|
73 |
Create an InterfaceInterpreter using the PETSc implementation
|
| 1974 |
eromero |
74 |
but overloading CreateMultiVector that doesn't create any
|
| 1499 |
slepc |
75 |
new vector.
|
|
|
76 |
*/
|
| 2331 |
jroman |
77 |
int SLEPCSetupInterpreter(mv_InterfaceInterpreter *i)
|
| 1499 |
slepc |
78 |
{
|
| 1974 |
eromero |
79 |
PETSCSetupInterpreter(i);
|
| 1499 |
slepc |
80 |
i->CreateMultiVector = mv_TempMultiVectorCreateFromPETScVector;
|
|
|
81 |
|
|
|
82 |
return 0;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/*
|
|
|
86 |
Change the multivector destructor in order to destroy the multivector
|
|
|
87 |
structure without destroy the PETSc vectors.
|
|
|
88 |
*/
|
| 2331 |
jroman |
89 |
void SLEPCSetupInterpreterForDignifiedDeath(mv_InterfaceInterpreter *i)
|
| 1499 |
slepc |
90 |
{
|
|
|
91 |
i->DestroyMultiVector = mv_TempMultiPETSCVectorDestroy;
|
|
|
92 |
}
|
|
|
93 |
|