Debian Codegraph @

debian/external_deps/fetk/punc/src/arpack/dgetv0.c

raw
1 /* ./src_f77/dgetv0.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* Common Block Declarations */
9
10 struct {
11 integer logfil, ndigit, mgetv0, msaupd, msaup2, msaitr, mseigt, msapps,
12 msgets, mseupd, mnaupd, mnaup2, mnaitr, mneigh, mnapps, mngets,
13 mneupd, mcaupd, mcaup2, mcaitr, mceigh, mcapps, mcgets, mceupd;
14 } debug_DGETV0;
15
16 #define debug_1 debug_DGETV0
17
18 struct {
19 integer nopx, nbx, nrorth, nitref, nrstrt;
20 real tsaupd, tsaup2, tsaitr, tseigt, tsgets, tsapps, tsconv, tnaupd,
21 tnaup2, tnaitr, tneigh, tngets, tnapps, tnconv, tcaupd, tcaup2,
22 tcaitr, tceigh, tcgets, tcapps, tcconv, tmvopx, tmvbx, tgetv0,
23 titref, trvec;
24 } timing_DGETV0;
25
26 #define timing_1 timing_DGETV0
27
28 /* Table of constant values */
29
30 static integer c__1 = 1;
31 static doublereal c_b24 = 1.;
32 static doublereal c_b26 = 0.;
33 static doublereal c_b29 = -1.;
34
35 /* ----------------------------------------------------------------------- */
36 /* \BeginDoc */
37
38 /* \Name: dgetv0 */
39
40 /* \Description: */
41 /* Generate a random initial residual vector for the Arnoldi process. */
42 /* Force the residual vector to be in the range of the operator OP. */
43
44 /* \Usage: */
45 /* call dgetv0 */
46 /* ( IDO, BMAT, ITRY, INITV, N, J, V, LDV, RESID, RNORM, */
47 /* IPNTR, WORKD, IERR ) */
48
49 /* \Arguments */
50 /* IDO Integer. (INPUT/OUTPUT) */
51 /* Reverse communication flag. IDO must be zero on the first */
52 /* call to dgetv0. */
53 /* ------------------------------------------------------------- */
54 /* IDO = 0: first call to the reverse communication interface */
55 /* IDO = -1: compute Y = OP * X where */
56 /* IPNTR(1) is the pointer into WORKD for X, */
57 /* IPNTR(2) is the pointer into WORKD for Y. */
58 /* This is for the initialization phase to force the */
59 /* starting vector into the range of OP. */
60 /* IDO = 2: compute Y = B * X where */
61 /* IPNTR(1) is the pointer into WORKD for X, */
62 /* IPNTR(2) is the pointer into WORKD for Y. */
63 /* IDO = 99: done */
64 /* ------------------------------------------------------------- */
65
66 /* BMAT Character*1. (INPUT) */
67 /* BMAT specifies the type of the matrix B in the (generalized) */
68 /* eigenvalue problem A*x = lambda*B*x. */
69 /* B = 'I' -> standard eigenvalue problem A*x = lambda*x */
70 /* B = 'G' -> generalized eigenvalue problem A*x = lambda*B*x */
71
72 /* ITRY Integer. (INPUT) */
73 /* ITRY counts the number of times that dgetv0 is called. */
74 /* It should be set to 1 on the initial call to dgetv0. */
75
76 /* INITV Logical variable. (INPUT) */
77 /* .TRUE. => the initial residual vector is given in RESID. */
78 /* .FALSE. => generate a random initial residual vector. */
79
80 /* N Integer. (INPUT) */
81 /* Dimension of the problem. */
82
83 /* J Integer. (INPUT) */
84 /* Index of the residual vector to be generated, with respect to */
85 /* the Arnoldi process. J > 1 in case of a "restart". */
86
87 /* V Double precision N by J array. (INPUT) */
88 /* The first J-1 columns of V contain the current Arnoldi basis */
89 /* if this is a "restart". */
90
91 /* LDV Integer. (INPUT) */
92 /* Leading dimension of V exactly as declared in the calling */
93 /* program. */
94
95 /* RESID Double precision array of length N. (INPUT/OUTPUT) */
96 /* Initial residual vector to be generated. If RESID is */
97 /* provided, force RESID into the range of the operator OP. */
98
99 /* RNORM Double precision scalar. (OUTPUT) */
100 /* B-norm of the generated residual. */
101
102 /* IPNTR Integer array of length 3. (OUTPUT) */
103
104 /* WORKD Double precision work array of length 2*N. (REVERSE COMMUNICATION). */
105 /* On exit, WORK(1:N) = B*RESID to be used in SSAITR. */
106
107 /* IERR Integer. (OUTPUT) */
108 /* = 0: Normal exit. */
109 /* = -1: Cannot generate a nontrivial restarted residual vector */
110 /* in the range of the operator OP. */
111
112 /* \EndDoc */
113
114 /* ----------------------------------------------------------------------- */
115
116 /* \BeginLib */
117
118 /* \Local variables: */
119 /* xxxxxx real */
120
121 /* \References: */
122 /* 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in */
123 /* a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), */
124 /* pp 357-385. */
125 /* 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly */
126 /* Restarted Arnoldi Iteration", Rice University Technical Report */
127 /* TR95-13, Department of Computational and Applied Mathematics. */
128
129 /* \Routines called: */
130 /* second ARPACK utility routine for timing. */
131 /* dvout ARPACK utility routine for vector output. */
132 /* dlarnv LAPACK routine for generating a random vector. */
133 /* dgemv Level 2 BLAS routine for matrix vector multiplication. */
134 /* dcopy Level 1 BLAS that copies one vector to another. */
135 /* ddot Level 1 BLAS that computes the scalar product of two vectors. */
136 /* dnrm2 Level 1 BLAS that computes the norm of a vector. */
137
138 /* \Author */
139 /* Danny Sorensen Phuong Vu */
140 /* Richard Lehoucq CRPC / Rice University */
141 /* Dept. of Computational & Houston, Texas */
142 /* Applied Mathematics */
143 /* Rice University */
144 /* Houston, Texas */
145
146 /* \SCCS Information: @(#) */
147 /* FILE: getv0.F SID: 2.7 DATE OF SID: 04/07/99 RELEASE: 2 */
148
149 /* \EndLib */
150
151 /* ----------------------------------------------------------------------- */
152
153 /* Subroutine */ int dgetv0_(integer *ido, char *bmat, integer *itry, logical
154 *initv, integer *n, integer *j, doublereal *v, integer *ldv,
155 doublereal *resid, doublereal *rnorm, integer *ipntr, doublereal *
156 workd, integer *ierr, ftnlen bmat_len)
157 {
158 /* Initialized data */
159
160 static logical inits = TRUE_;
161
162 /* System generated locals */
163 integer v_dim1, v_offset, i__1;
164
165 /* Builtin functions */
166 double sqrt(doublereal);
167
168 /* Local variables */
169 static real t0, t1, t2, t3;
170 static integer jj;
171 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
172 integer *);
173 static integer iter;
174 static logical orth;
175 extern doublereal dnrm2_(integer *, doublereal *, integer *);
176 static integer iseed[4];
177 extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
178 doublereal *, doublereal *, integer *, doublereal *, integer *,
179 doublereal *, doublereal *, integer *, ftnlen);
180 static integer idist;
181 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
182 doublereal *, integer *);
183 static logical first;
184 extern /* Subroutine */ int dvout_(integer *, integer *, doublereal *,
185 integer *, char *, ftnlen);
186 static doublereal rnorm0;
187 extern /* Subroutine */ int second_(real *);
188 static integer msglvl;
189 extern /* Subroutine */ int dlarnv_(integer *, integer *, integer *,
190 doublereal *);
191
192
193 /* %----------------------------------------------------% */
194 /* | Include files for debugging and timing information | */
195 /* %----------------------------------------------------% */
196
197
198 /* \SCCS Information: @(#) */
199 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
200
201 /* %---------------------------------% */
202 /* | See debug.doc for documentation | */
203 /* %---------------------------------% */
204
205 /* %------------------% */
206 /* | Scalar Arguments | */
207 /* %------------------% */
208
209 /* %--------------------------------% */
210 /* | See stat.doc for documentation | */
211 /* %--------------------------------% */
212
213 /* \SCCS Information: @(#) */
214 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
215
216
217
218 /* %-----------------% */
219 /* | Array Arguments | */
220 /* %-----------------% */
221
222
223 /* %------------% */
224 /* | Parameters | */
225 /* %------------% */
226
227
228 /* %------------------------% */
229 /* | Local Scalars & Arrays | */
230 /* %------------------------% */
231
232
233 /* %----------------------% */
234 /* | External Subroutines | */
235 /* %----------------------% */
236
237
238 /* %--------------------% */
239 /* | External Functions | */
240 /* %--------------------% */
241
242
243 /* %---------------------% */
244 /* | Intrinsic Functions | */
245 /* %---------------------% */
246
247
248 /* %-----------------% */
249 /* | Data Statements | */
250 /* %-----------------% */
251
252 /* Parameter adjustments */
253 --workd;
254 --resid;
255 v_dim1 = *ldv;
256 v_offset = 1 + v_dim1;
257 v -= v_offset;
258 --ipntr;
259
260 /* Function Body */
261
262 /* %-----------------------% */
263 /* | Executable Statements | */
264 /* %-----------------------% */
265
266
267 /* %-----------------------------------% */
268 /* | Initialize the seed of the LAPACK | */
269 /* | random number generator | */
270 /* %-----------------------------------% */
271
272 if (inits) {
273 iseed[0] = 1;
274 iseed[1] = 3;
275 iseed[2] = 5;
276 iseed[3] = 7;
277 inits = FALSE_;
278 }
279
280 if (*ido == 0) {
281
282 /* %-------------------------------% */
283 /* | Initialize timing statistics | */
284 /* | & message level for debugging | */
285 /* %-------------------------------% */
286
287 second_(&t0);
288 msglvl = debug_1.mgetv0;
289
290 *ierr = 0;
291 iter = 0;
292 first = FALSE_;
293 orth = FALSE_;
294
295 /* %-----------------------------------------------------% */
296 /* | Possibly generate a random starting vector in RESID | */
297 /* | Use a LAPACK random number generator used by the | */
298 /* | matrix generation routines. | */
299 /* | idist = 1: uniform (0,1) distribution; | */
300 /* | idist = 2: uniform (-1,1) distribution; | */
301 /* | idist = 3: normal (0,1) distribution; | */
302 /* %-----------------------------------------------------% */
303
304 if (! (*initv)) {
305 idist = 2;
306 dlarnv_(&idist, iseed, n, &resid[1]);
307 }
308
309 /* %----------------------------------------------------------% */
310 /* | Force the starting vector into the range of OP to handle | */
311 /* | the generalized problem when B is possibly (singular). | */
312 /* %----------------------------------------------------------% */
313
314 second_(&t2);
315 if (*(unsigned char *)bmat == 'G') {
316 ++timing_1.nopx;
317 ipntr[1] = 1;
318 ipntr[2] = *n + 1;
319 dcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
320 *ido = -1;
321 goto L9000;
322 }
323 }
324
325 /* %-----------------------------------------% */
326 /* | Back from computing OP*(initial-vector) | */
327 /* %-----------------------------------------% */
328
329 if (first) {
330 goto L20;
331 }
332
333 /* %-----------------------------------------------% */
334 /* | Back from computing B*(orthogonalized-vector) | */
335 /* %-----------------------------------------------% */
336
337 if (orth) {
338 goto L40;
339 }
340
341 if (*(unsigned char *)bmat == 'G') {
342 second_(&t3);
343 timing_1.tmvopx += t3 - t2;
344 }
345
346 /* %------------------------------------------------------% */
347 /* | Starting vector is now in the range of OP; r = OP*r; | */
348 /* | Compute B-norm of starting vector. | */
349 /* %------------------------------------------------------% */
350
351 second_(&t2);
352 first = TRUE_;
353 if (*(unsigned char *)bmat == 'G') {
354 ++timing_1.nbx;
355 dcopy_(n, &workd[*n + 1], &c__1, &resid[1], &c__1);
356 ipntr[1] = *n + 1;
357 ipntr[2] = 1;
358 *ido = 2;
359 goto L9000;
360 } else if (*(unsigned char *)bmat == 'I') {
361 dcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
362 }
363
364 L20:
365
366 if (*(unsigned char *)bmat == 'G') {
367 second_(&t3);
368 timing_1.tmvbx += t3 - t2;
369 }
370
371 first = FALSE_;
372 if (*(unsigned char *)bmat == 'G') {
373 rnorm0 = ddot_(n, &resid[1], &c__1, &workd[1], &c__1);
374 rnorm0 = sqrt((abs(rnorm0)));
375 } else if (*(unsigned char *)bmat == 'I') {
376 rnorm0 = dnrm2_(n, &resid[1], &c__1);
377 }
378 *rnorm = rnorm0;
379
380 /* %---------------------------------------------% */
381 /* | Exit if this is the very first Arnoldi step | */
382 /* %---------------------------------------------% */
383
384 if (*j == 1) {
385 goto L50;
386 }
387
388 /* %---------------------------------------------------------------- */
389 /* | Otherwise need to B-orthogonalize the starting vector against | */
390 /* | the current Arnoldi basis using Gram-Schmidt with iter. ref. | */
391 /* | This is the case where an invariant subspace is encountered | */
392 /* | in the middle of the Arnoldi factorization. | */
393 /* | | */
394 /* | s = V^{T}*B*r; r = r - V*s; | */
395 /* | | */
396 /* | Stopping criteria used for iter. ref. is discussed in | */
397 /* | Parlett's book, page 107 and in Gragg & Reichel TOMS paper. | */
398 /* %---------------------------------------------------------------% */
399
400 orth = TRUE_;
401 L30:
402
403 i__1 = *j - 1;
404 dgemv_("T", n, &i__1, &c_b24, &v[v_offset], ldv, &workd[1], &c__1, &c_b26,
405 &workd[*n + 1], &c__1, (ftnlen)1);
406 i__1 = *j - 1;
407 dgemv_("N", n, &i__1, &c_b29, &v[v_offset], ldv, &workd[*n + 1], &c__1, &
408 c_b24, &resid[1], &c__1, (ftnlen)1);
409
410 /* %----------------------------------------------------------% */
411 /* | Compute the B-norm of the orthogonalized starting vector | */
412 /* %----------------------------------------------------------% */
413
414 second_(&t2);
415 if (*(unsigned char *)bmat == 'G') {
416 ++timing_1.nbx;
417 dcopy_(n, &resid[1], &c__1, &workd[*n + 1], &c__1);
418 ipntr[1] = *n + 1;
419 ipntr[2] = 1;
420 *ido = 2;
421 goto L9000;
422 } else if (*(unsigned char *)bmat == 'I') {
423 dcopy_(n, &resid[1], &c__1, &workd[1], &c__1);
424 }
425
426 L40:
427
428 if (*(unsigned char *)bmat == 'G') {
429 second_(&t3);
430 timing_1.tmvbx += t3 - t2;
431 }
432
433 if (*(unsigned char *)bmat == 'G') {
434 *rnorm = ddot_(n, &resid[1], &c__1, &workd[1], &c__1);
435 *rnorm = sqrt((abs(*rnorm)));
436 } else if (*(unsigned char *)bmat == 'I') {
437 *rnorm = dnrm2_(n, &resid[1], &c__1);
438 }
439
440 /* %--------------------------------------% */
441 /* | Check for further orthogonalization. | */
442 /* %--------------------------------------% */
443
444 if (msglvl > 2) {
445 dvout_(&debug_1.logfil, &c__1, &rnorm0, &debug_1.ndigit, "_getv0: re"
446 "-orthonalization ; rnorm0 is", (ftnlen)38);
447 dvout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: re-o"
448 "rthonalization ; rnorm is", (ftnlen)37);
449 }
450
451 if (*rnorm > rnorm0 * .717f) {
452 goto L50;
453 }
454
455 ++iter;
456 if (iter <= 5) {
457
458 /* %-----------------------------------% */
459 /* | Perform iterative refinement step | */
460 /* %-----------------------------------% */
461
462 rnorm0 = *rnorm;
463 goto L30;
464 } else {
465
466 /* %------------------------------------% */
467 /* | Iterative refinement step "failed" | */
468 /* %------------------------------------% */
469
470 i__1 = *n;
471 for (jj = 1; jj <= i__1; ++jj) {
472 resid[jj] = 0.;
473 /* L45: */
474 }
475 *rnorm = 0.;
476 *ierr = -1;
477 }
478
479 L50:
480
481 if (msglvl > 0) {
482 dvout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: B-no"
483 "rm of initial / restarted starting vector", (ftnlen)53);
484 }
485 if (msglvl > 3) {
486 dvout_(&debug_1.logfil, n, &resid[1], &debug_1.ndigit, "_getv0: init"
487 "ial / restarted starting vector", (ftnlen)43);
488 }
489 *ido = 99;
490
491 second_(&t1);
492 timing_1.tgetv0 += t1 - t0;
493
494 L9000:
495 return 0;
496
497 /* %---------------% */
498 /* | End of dgetv0 | */
499 /* %---------------% */
500
501 } /* dgetv0_ */
502