Debian Codegraph @

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

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