| 1288 |
slepc |
1 |
/*
|
|
|
2 |
SVD routines related to monitors.
|
| 1376 |
slepc |
3 |
|
|
|
4 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
5 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
|
|
6 |
Copyright (c) 2002-2007, Universidad Politecnica de Valencia, Spain
|
|
|
7 |
|
|
|
8 |
This file is part of SLEPc. See the README file for conditions of use
|
|
|
9 |
and additional information.
|
|
|
10 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1288 |
slepc |
11 |
*/
|
| 1376 |
slepc |
12 |
|
| 1288 |
slepc |
13 |
#include "src/svd/svdimpl.h" /*I "slepcsvd.h" I*/
|
|
|
14 |
|
|
|
15 |
#undef __FUNCT__
|
| 1331 |
slepc |
16 |
#define __FUNCT__ "SVDMonitorSet"
|
| 1288 |
slepc |
17 |
/*@C
|
| 1331 |
slepc |
18 |
SVDMonitorSet - Sets an ADDITIONAL function to be called at every
|
| 1288 |
slepc |
19 |
iteration to monitor the error estimates for each requested singular triplet.
|
|
|
20 |
|
|
|
21 |
Collective on SVD
|
|
|
22 |
|
|
|
23 |
Input Parameters:
|
|
|
24 |
+ svd - singular value solver context obtained from SVDCreate()
|
|
|
25 |
. monitor - pointer to function (if this is PETSC_NULL, it turns off monitoring)
|
|
|
26 |
- mctx - [optional] context for private data for the
|
|
|
27 |
monitor routine (use PETSC_NULL if no context is desired)
|
|
|
28 |
|
|
|
29 |
Calling Sequence of monitor:
|
| 1504 |
slepc |
30 |
$ monitor (SVD svd, PetscInt its, PetscInt nconv, PetscReal *sigma, PetscReal* errest, PetscInt nest, void *mctx)
|
| 1288 |
slepc |
31 |
|
|
|
32 |
+ svd - singular value solver context obtained from SVDCreate()
|
|
|
33 |
. its - iteration number
|
|
|
34 |
. nconv - number of converged singular triplets
|
|
|
35 |
. sigma - singular values
|
|
|
36 |
. errest - relative error estimates for each singular triplet
|
|
|
37 |
. nest - number of error estimates
|
| 1331 |
slepc |
38 |
- mctx - optional monitoring context, as set by SVDMonitorSet()
|
| 1288 |
slepc |
39 |
|
|
|
40 |
Options Database Keys:
|
|
|
41 |
+ -svd_monitor - print error estimates at each iteration
|
| 1332 |
slepc |
42 |
. -svd_monitor_draw - sets line graph monitor
|
| 1331 |
slepc |
43 |
- -svd_monitor_cancel - cancels all monitors that have been hardwired into
|
|
|
44 |
a code by calls to SVDMonitorSet(), but does not cancel those set via
|
| 1288 |
slepc |
45 |
the options database.
|
|
|
46 |
|
|
|
47 |
Notes:
|
|
|
48 |
Several different monitoring routines may be set by calling
|
| 1331 |
slepc |
49 |
SVDMonitorSet() multiple times; all will be called in the
|
| 1288 |
slepc |
50 |
order in which they were set.
|
|
|
51 |
|
|
|
52 |
Level: intermediate
|
|
|
53 |
|
| 1331 |
slepc |
54 |
.seealso: SVDMonitorDefault(), SVDMonitorCancel()
|
| 1288 |
slepc |
55 |
@*/
|
| 1504 |
slepc |
56 |
PetscErrorCode SVDMonitorSet(SVD svd,PetscErrorCode (*monitor)(SVD,PetscInt,PetscInt,PetscReal*,PetscReal*,PetscInt,void*),
|
| 1288 |
slepc |
57 |
void *mctx,PetscErrorCode (*monitordestroy)(void*))
|
|
|
58 |
{
|
|
|
59 |
PetscFunctionBegin;
|
|
|
60 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
61 |
if (svd->numbermonitors >= MAXSVDMONITORS) {
|
|
|
62 |
SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many SVD monitors set");
|
|
|
63 |
}
|
|
|
64 |
svd->monitor[svd->numbermonitors] = monitor;
|
|
|
65 |
svd->monitorcontext[svd->numbermonitors] = (void*)mctx;
|
|
|
66 |
svd->monitordestroy[svd->numbermonitors++] = monitordestroy;
|
|
|
67 |
PetscFunctionReturn(0);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
#undef __FUNCT__
|
| 1331 |
slepc |
71 |
#define __FUNCT__ "SVDMonitorCancel"
|
| 1288 |
slepc |
72 |
/*@
|
| 1331 |
slepc |
73 |
SVDMonitorCancel - Clears all monitors for an SVD object.
|
| 1288 |
slepc |
74 |
|
|
|
75 |
Collective on SVD
|
|
|
76 |
|
|
|
77 |
Input Parameters:
|
|
|
78 |
. svd - singular value solver context obtained from SVDCreate()
|
|
|
79 |
|
|
|
80 |
Options Database Key:
|
| 1331 |
slepc |
81 |
. -svd_monitor_cancel - Cancels all monitors that have been hardwired
|
|
|
82 |
into a code by calls to SVDMonitorSet(),
|
| 1288 |
slepc |
83 |
but does not cancel those set via the options database.
|
|
|
84 |
|
|
|
85 |
Level: intermediate
|
|
|
86 |
|
| 1331 |
slepc |
87 |
.seealso: SVDMonitorCancel()
|
| 1288 |
slepc |
88 |
@*/
|
| 1331 |
slepc |
89 |
PetscErrorCode SVDMonitorCancel(SVD svd)
|
| 1288 |
slepc |
90 |
{
|
|
|
91 |
PetscErrorCode ierr;
|
|
|
92 |
PetscInt i;
|
|
|
93 |
|
|
|
94 |
PetscFunctionBegin;
|
|
|
95 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
96 |
for (i=0; i<svd->numbermonitors; i++) {
|
|
|
97 |
if (svd->monitordestroy[i]) {
|
|
|
98 |
ierr = (*svd->monitordestroy[i])(svd->monitorcontext[i]);CHKERRQ(ierr);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
svd->numbermonitors = 0;
|
|
|
102 |
PetscFunctionReturn(0);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
#undef __FUNCT__
|
|
|
106 |
#define __FUNCT__ "SVDGetMonitorContext"
|
|
|
107 |
/*@C
|
|
|
108 |
SVDGetMonitorContext - Gets the monitor context, as set by
|
| 1331 |
slepc |
109 |
SVDMonitorSet() for the FIRST monitor only.
|
| 1288 |
slepc |
110 |
|
|
|
111 |
Not Collective
|
|
|
112 |
|
|
|
113 |
Input Parameter:
|
|
|
114 |
. svd - singular value solver context obtained from SVDCreate()
|
|
|
115 |
|
|
|
116 |
Output Parameter:
|
|
|
117 |
. ctx - monitor context
|
|
|
118 |
|
|
|
119 |
Level: intermediate
|
|
|
120 |
|
| 1331 |
slepc |
121 |
.seealso: SVDMonitorSet(), SVDMonitorDefault()
|
| 1288 |
slepc |
122 |
@*/
|
|
|
123 |
PetscErrorCode SVDGetMonitorContext(SVD svd, void **ctx)
|
|
|
124 |
{
|
|
|
125 |
PetscFunctionBegin;
|
|
|
126 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
127 |
*ctx = (svd->monitorcontext[0]);
|
|
|
128 |
PetscFunctionReturn(0);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
#undef __FUNCT__
|
| 1331 |
slepc |
132 |
#define __FUNCT__ "SVDMonitorDefault"
|
| 1288 |
slepc |
133 |
/*@C
|
|
|
134 |
SVDDefaultMonitor - Print the current approximate values and
|
|
|
135 |
error estimates at each iteration of the singular value solver.
|
|
|
136 |
|
|
|
137 |
Collective on SVD
|
|
|
138 |
|
|
|
139 |
Input Parameters:
|
|
|
140 |
+ svd - singular value solver context
|
|
|
141 |
. its - iteration number
|
|
|
142 |
. nconv - number of converged singular triplets so far
|
|
|
143 |
. sigma - singular values
|
|
|
144 |
. errest - error estimates
|
|
|
145 |
. nest - number of error estimates to display
|
|
|
146 |
- dummy - unused monitor context
|
|
|
147 |
|
|
|
148 |
Level: intermediate
|
|
|
149 |
|
| 1331 |
slepc |
150 |
.seealso: SVDMonitorSet()
|
| 1288 |
slepc |
151 |
@*/
|
| 1504 |
slepc |
152 |
PetscErrorCode SVDMonitorDefault(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,void *dummy)
|
| 1288 |
slepc |
153 |
{
|
|
|
154 |
PetscErrorCode ierr;
|
| 1504 |
slepc |
155 |
PetscInt i;
|
| 1288 |
slepc |
156 |
PetscViewer viewer = (PetscViewer) dummy;
|
|
|
157 |
|
|
|
158 |
PetscFunctionBegin;
|
|
|
159 |
if (its) {
|
| 1422 |
slepc |
160 |
if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)svd)->comm);
|
| 1288 |
slepc |
161 |
ierr = PetscViewerASCIIPrintf(viewer,"%3d SVD nconv=%d Values (Errors)",its,nconv);CHKERRQ(ierr);
|
|
|
162 |
for (i=0;i<nest;i++) {
|
|
|
163 |
ierr = PetscViewerASCIIPrintf(viewer," %g (%10.8e)",sigma[i],errest[i]);CHKERRQ(ierr);
|
|
|
164 |
}
|
|
|
165 |
ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
|
|
|
166 |
}
|
|
|
167 |
PetscFunctionReturn(0);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
#undef __FUNCT__
|
| 1331 |
slepc |
171 |
#define __FUNCT__ "SVDMonitorLG"
|
| 1504 |
slepc |
172 |
PetscErrorCode SVDMonitorLG(SVD svd,PetscInt its,PetscInt nconv,PetscReal *sigma,PetscReal *errest,PetscInt nest,void *monctx)
|
| 1288 |
slepc |
173 |
{
|
|
|
174 |
PetscViewer viewer = (PetscViewer) monctx;
|
|
|
175 |
PetscDraw draw;
|
|
|
176 |
PetscDrawLG lg;
|
|
|
177 |
PetscErrorCode ierr;
|
|
|
178 |
PetscReal *x,*y;
|
| 1504 |
slepc |
179 |
int p,n = svd->nsv;
|
|
|
180 |
PetscInt i;
|
| 1288 |
slepc |
181 |
PetscDraw draw1;
|
|
|
182 |
PetscDrawLG lg1;
|
|
|
183 |
|
|
|
184 |
PetscFunctionBegin;
|
|
|
185 |
|
| 1422 |
slepc |
186 |
if (!viewer) { viewer = PETSC_VIEWER_DRAW_(((PetscObject)svd)->comm); }
|
| 1288 |
slepc |
187 |
|
|
|
188 |
ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
|
|
|
189 |
ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr);
|
|
|
190 |
ierr = PetscViewerDrawGetDraw(viewer,1,&draw1);CHKERRQ(ierr);
|
|
|
191 |
ierr = PetscViewerDrawGetDrawLG(viewer,1,&lg1);CHKERRQ(ierr);
|
|
|
192 |
|
|
|
193 |
if (!its) {
|
|
|
194 |
ierr = PetscDrawSetTitle(draw,"Error estimates");CHKERRQ(ierr);
|
|
|
195 |
ierr = PetscDrawSetDoubleBuffer(draw);CHKERRQ(ierr);
|
|
|
196 |
ierr = PetscDrawLGSetDimension(lg,n);CHKERRQ(ierr);
|
|
|
197 |
ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
|
|
|
198 |
ierr = PetscDrawLGSetLimits(lg,0,1.0,log10(svd->tol)-2,0.0);CHKERRQ(ierr);
|
|
|
199 |
|
|
|
200 |
ierr = PetscDrawSetTitle(draw1,"Approximate singular values");CHKERRQ(ierr);
|
|
|
201 |
ierr = PetscDrawSetDoubleBuffer(draw1);CHKERRQ(ierr);
|
|
|
202 |
ierr = PetscDrawLGSetDimension(lg1,n);CHKERRQ(ierr);
|
|
|
203 |
ierr = PetscDrawLGReset(lg1);CHKERRQ(ierr);
|
|
|
204 |
ierr = PetscDrawLGSetLimits(lg1,0,1.0,1.e20,-1.e20);CHKERRQ(ierr);
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
ierr = PetscMalloc(sizeof(PetscReal)*n,&x);CHKERRQ(ierr);
|
|
|
208 |
ierr = PetscMalloc(sizeof(PetscReal)*n,&y);CHKERRQ(ierr);
|
|
|
209 |
for (i=0;i<n;i++) {
|
|
|
210 |
x[i] = (PetscReal) its;
|
|
|
211 |
if (errest[i] > 0.0) y[i] = log10(errest[i]); else y[i] = 0.0;
|
|
|
212 |
}
|
|
|
213 |
ierr = PetscDrawLGAddPoint(lg,x,y);CHKERRQ(ierr);
|
|
|
214 |
|
|
|
215 |
ierr = PetscDrawLGAddPoint(lg1,x,svd->sigma);CHKERRQ(ierr);
|
|
|
216 |
ierr = PetscDrawGetPause(draw1,&p);CHKERRQ(ierr);
|
|
|
217 |
ierr = PetscDrawSetPause(draw1,0);CHKERRQ(ierr);
|
|
|
218 |
ierr = PetscDrawLGDraw(lg1);CHKERRQ(ierr);
|
|
|
219 |
ierr = PetscDrawSetPause(draw1,p);CHKERRQ(ierr);
|
|
|
220 |
|
|
|
221 |
ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
|
|
|
222 |
ierr = PetscFree(x);CHKERRQ(ierr);
|
|
|
223 |
ierr = PetscFree(y);CHKERRQ(ierr);
|
|
|
224 |
PetscFunctionReturn(0);
|
|
|
225 |
}
|
|
|
226 |
|