Actual source code: mem.c
1: /*
2: EPS routines related to memory management.
4: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5: SLEPc - Scalable Library for Eigenvalue Problem Computations
6: Copyright (c) 2002-2012, Universitat Politecnica de Valencia, Spain
8: This file is part of SLEPc.
9:
10: SLEPc is free software: you can redistribute it and/or modify it under the
11: terms of version 3 of the GNU Lesser General Public License as published by
12: the Free Software Foundation.
14: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
15: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17: more details.
19: You should have received a copy of the GNU Lesser General Public License
20: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
21: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22: */
24: #include <slepc-private/epsimpl.h> /*I "slepceps.h" I*/
28: /*
29: EPSAllocateSolution - Allocate memory storage for common variables such
30: as eigenvalues and eigenvectors.
31: */
32: PetscErrorCode EPSAllocateSolution(EPS eps)
33: {
35: PetscInt newc,cnt;
36:
38: if (eps->allocated_ncv != eps->ncv) {
39: newc = PetscMax(0,eps->ncv-eps->allocated_ncv);
40: EPSFreeSolution(eps);
41: cnt = 0;
42: PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->eigr);
43: PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->eigi);
44: cnt += 2*newc*sizeof(PetscScalar);
45: PetscMalloc(eps->ncv*sizeof(PetscReal),&eps->errest);
46: PetscMalloc(eps->ncv*sizeof(PetscReal),&eps->errest_left);
47: cnt += 2*newc*sizeof(PetscReal);
48: PetscMalloc(eps->ncv*sizeof(PetscInt),&eps->perm);
49: cnt += newc*sizeof(PetscInt);
50: PetscLogObjectMemory(eps,cnt);
51: VecDuplicateVecs(eps->t,eps->ncv,&eps->V);
52: PetscLogObjectParents(eps,eps->ncv,eps->V);
53: if (eps->leftvecs) {
54: VecDuplicateVecs(eps->t,eps->ncv,&eps->W);
55: PetscLogObjectParents(eps,eps->ncv,eps->W);
56: }
57: eps->allocated_ncv = eps->ncv;
58: }
59: /* The following cannot go in the above if, to avoid crash when ncv did not change */
60: if (eps->arbit_func) {
61: PetscFree(eps->rr);
62: PetscFree(eps->ri);
63: PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->rr);
64: PetscMalloc(eps->ncv*sizeof(PetscScalar),&eps->ri);
65: PetscLogObjectMemory(eps,2*newc*sizeof(PetscScalar));
66: }
67: return(0);
68: }
72: /*
73: EPSFreeSolution - Free memory storage. This routine is related to
74: EPSAllocateSolution().
75: */
76: PetscErrorCode EPSFreeSolution(EPS eps)
77: {
79:
81: if (eps->allocated_ncv > 0) {
82: PetscFree(eps->eigr);
83: PetscFree(eps->eigi);
84: PetscFree(eps->errest);
85: PetscFree(eps->errest_left);
86: PetscFree(eps->perm);
87: PetscFree(eps->rr);
88: PetscFree(eps->ri);
89: VecDestroyVecs(eps->allocated_ncv,&eps->V);
90: VecDestroyVecs(eps->allocated_ncv,&eps->W);
91: eps->allocated_ncv = 0;
92: }
93: return(0);
94: }