Debian Codegraph @

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

raw
1 /* ./src_f77/sgetv0.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_;
15
16 #define debug_1 debug_
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_;
25
26 #define timing_1 timing_
27
28 /* Table of constant values */
29
30 static integer c__1 = 1;
31 static real c_b24 = 1.f;
32 static real c_b26 = 0.f;
33 static real c_b29 = -1.f;
34
35 /* ----------------------------------------------------------------------- */
36 /* \BeginDoc */
37
38 /* \Name: sgetv0 */
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 sgetv0 */
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 sgetv0. */
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 sgetv0 is called. */
74 /* It should be set to 1 on the initial call to sgetv0. */
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 Real 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 Real 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 Real scalar. (OUTPUT) */
100 /* B-norm of the generated residual. */
101
102 /* IPNTR Integer array of length 3. (OUTPUT) */
103
104 /* WORKD Real 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 /* svout ARPACK utility routine for vector output. */
132 /* slarnv LAPACK routine for generating a random vector. */
133 /* sgemv Level 2 BLAS routine for matrix vector multiplication. */
134 /* scopy Level 1 BLAS that copies one vector to another. */
135 /* sdot Level 1 BLAS that computes the scalar product of two vectors. */
136 /* snrm2 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 sgetv0_(integer *ido, char *bmat, integer *itry, logical
154 *initv, integer *n, integer *j, real *v, integer *ldv, real *resid,
155 real *rnorm, integer *ipntr, real *workd, integer *ierr, ftnlen
156 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, iter;
171 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
172 static logical orth;
173 extern doublereal snrm2_(integer *, real *, integer *);
174 static integer iseed[4], idist;
175 extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
176 real *, integer *, real *, integer *, real *, real *, integer *,
177 ftnlen);
178 static logical first;
179 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
180 integer *), svout_(integer *, integer *, real *, integer *, char *
181 , ftnlen);
182 static real rnorm0;
183 extern /* Subroutine */ int second_(real *);
184 static integer msglvl;
185 extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real
186 *);
187
188
189 /* %----------------------------------------------------% */
190 /* | Include files for debugging and timing information | */
191 /* %----------------------------------------------------% */
192
193
194 /* \SCCS Information: @(#) */
195 /* FILE: debug.h SID: 2.3 DATE OF SID: 11/16/95 RELEASE: 2 */
196
197 /* %---------------------------------% */
198 /* | See debug.doc for documentation | */
199 /* %---------------------------------% */
200
201 /* %------------------% */
202 /* | Scalar Arguments | */
203 /* %------------------% */
204
205 /* %--------------------------------% */
206 /* | See stat.doc for documentation | */
207 /* %--------------------------------% */
208
209 /* \SCCS Information: @(#) */
210 /* FILE: stat.h SID: 2.2 DATE OF SID: 11/16/95 RELEASE: 2 */
211
212
213
214 /* %-----------------% */
215 /* | Array Arguments | */
216 /* %-----------------% */
217
218
219 /* %------------% */
220 /* | Parameters | */
221 /* %------------% */
222
223
224 /* %------------------------% */
225 /* | Local Scalars & Arrays | */
226 /* %------------------------% */
227
228
229 /* %----------------------% */
230 /* | External Subroutines | */
231 /* %----------------------% */
232
233
234 /* %--------------------% */
235 /* | External Functions | */
236 /* %--------------------% */
237
238
239 /* %---------------------% */
240 /* | Intrinsic Functions | */
241 /* %---------------------% */
242
243
244 /* %-----------------% */
245 /* | Data Statements | */
246 /* %-----------------% */
247
248 /* Parameter adjustments */
249 --workd;
250 --resid;
251 v_dim1 = *ldv;
252 v_offset = 1 + v_dim1;
253 v -= v_offset;
254 --ipntr;
255
256 /* Function Body */
257
258 /* %-----------------------% */
259 /* | Executable Statements | */
260 /* %-----------------------% */
261
262
263 /* %-----------------------------------% */
264 /* | Initialize the seed of the LAPACK | */
265 /* | random number generator | */
266 /* %-----------------------------------% */
267
268 if (inits) {
269 iseed[0] = 1;
270 iseed[1] = 3;
271 iseed[2] = 5;
272 iseed[3] = 7;
273 inits = FALSE_;
274 }
275
276 if (*ido == 0) {
277
278 /* %-------------------------------% */
279 /* | Initialize timing statistics | */
280 /* | & message level for debugging | */
281 /* %-------------------------------% */
282
283 second_(&t0);
284 msglvl = debug_1.mgetv0;
285
286 *ierr = 0;
287 iter = 0;
288 first = FALSE_;
289 orth = FALSE_;
290
291 /* %-----------------------------------------------------% */
292 /* | Possibly generate a random starting vector in RESID | */
293 /* | Use a LAPACK random number generator used by the | */
294 /* | matrix generation routines. | */
295 /* | idist = 1: uniform (0,1) distribution; | */
296 /* | idist = 2: uniform (-1,1) distribution; | */
297 /* | idist = 3: normal (0,1) distribution; | */
298 /* %-----------------------------------------------------% */
299
300 if (! (*initv)) {
301 idist = 2;
302 slarnv_(&idist, iseed, n, &resid[1]);
303 }
304
305 /* %----------------------------------------------------------% */
306 /* | Force the starting vector into the range of OP to handle | */
307 /* | the generalized problem when B is possibly (singular). | */
308 /* %----------------------------------------------------------% */
309
310 second_(&t2);
311 if (*(unsigned char *)bmat == 'G') {
312 ++timing_1.nopx;
313 ipntr[1] = 1;
314 ipntr[2] = *n + 1;
315 scopy_(n, &resid[1], &c__1, &workd[1], &c__1);
316 *ido = -1;
317 goto L9000;
318 }
319 }
320
321 /* %-----------------------------------------% */
322 /* | Back from computing OP*(initial-vector) | */
323 /* %-----------------------------------------% */
324
325 if (first) {
326 goto L20;
327 }
328
329 /* %-----------------------------------------------% */
330 /* | Back from computing B*(orthogonalized-vector) | */
331 /* %-----------------------------------------------% */
332
333 if (orth) {
334 goto L40;
335 }
336
337 if (*(unsigned char *)bmat == 'G') {
338 second_(&t3);
339 timing_1.tmvopx += t3 - t2;
340 }
341
342 /* %------------------------------------------------------% */
343 /* | Starting vector is now in the range of OP; r = OP*r; | */
344 /* | Compute B-norm of starting vector. | */
345 /* %------------------------------------------------------% */
346
347 second_(&t2);
348 first = TRUE_;
349 if (*(unsigned char *)bmat == 'G') {
350 ++timing_1.nbx;
351 scopy_(n, &workd[*n + 1], &c__1, &resid[1], &c__1);
352 ipntr[1] = *n + 1;
353 ipntr[2] = 1;
354 *ido = 2;
355 goto L9000;
356 } else if (*(unsigned char *)bmat == 'I') {
357 scopy_(n, &resid[1], &c__1, &workd[1], &c__1);
358 }
359
360 L20:
361
362 if (*(unsigned char *)bmat == 'G') {
363 second_(&t3);
364 timing_1.tmvbx += t3 - t2;
365 }
366
367 first = FALSE_;
368 if (*(unsigned char *)bmat == 'G') {
369 rnorm0 = sdot_(n, &resid[1], &c__1, &workd[1], &c__1);
370 rnorm0 = sqrt((dabs(rnorm0)));
371 } else if (*(unsigned char *)bmat == 'I') {
372 rnorm0 = snrm2_(n, &resid[1], &c__1);
373 }
374 *rnorm = rnorm0;
375
376 /* %---------------------------------------------% */
377 /* | Exit if this is the very first Arnoldi step | */
378 /* %---------------------------------------------% */
379
380 if (*j == 1) {
381 goto L50;
382 }
383
384 /* %---------------------------------------------------------------- */
385 /* | Otherwise need to B-orthogonalize the starting vector against | */
386 /* | the current Arnoldi basis using Gram-Schmidt with iter. ref. | */
387 /* | This is the case where an invariant subspace is encountered | */
388 /* | in the middle of the Arnoldi factorization. | */
389 /* | | */
390 /* | s = V^{T}*B*r; r = r - V*s; | */
391 /* | | */
392 /* | Stopping criteria used for iter. ref. is discussed in | */
393 /* | Parlett's book, page 107 and in Gragg & Reichel TOMS paper. | */
394 /* %---------------------------------------------------------------% */
395
396 orth = TRUE_;
397 L30:
398
399 i__1 = *j - 1;
400 sgemv_("T", n, &i__1, &c_b24, &v[v_offset], ldv, &workd[1], &c__1, &c_b26,
401 &workd[*n + 1], &c__1, (ftnlen)1);
402 i__1 = *j - 1;
403 sgemv_("N", n, &i__1, &c_b29, &v[v_offset], ldv, &workd[*n + 1], &c__1, &
404 c_b24, &resid[1], &c__1, (ftnlen)1);
405
406 /* %----------------------------------------------------------% */
407 /* | Compute the B-norm of the orthogonalized starting vector | */
408 /* %----------------------------------------------------------% */
409
410 second_(&t2);
411 if (*(unsigned char *)bmat == 'G') {
412 ++timing_1.nbx;
413 scopy_(n, &resid[1], &c__1, &workd[*n + 1], &c__1);
414 ipntr[1] = *n + 1;
415 ipntr[2] = 1;
416 *ido = 2;
417 goto L9000;
418 } else if (*(unsigned char *)bmat == 'I') {
419 scopy_(n, &resid[1], &c__1, &workd[1], &c__1);
420 }
421
422 L40:
423
424 if (*(unsigned char *)bmat == 'G') {
425 second_(&t3);
426 timing_1.tmvbx += t3 - t2;
427 }
428
429 if (*(unsigned char *)bmat == 'G') {
430 *rnorm = sdot_(n, &resid[1], &c__1, &workd[1], &c__1);
431 *rnorm = sqrt((dabs(*rnorm)));
432 } else if (*(unsigned char *)bmat == 'I') {
433 *rnorm = snrm2_(n, &resid[1], &c__1);
434 }
435
436 /* %--------------------------------------% */
437 /* | Check for further orthogonalization. | */
438 /* %--------------------------------------% */
439
440 if (msglvl > 2) {
441 svout_(&debug_1.logfil, &c__1, &rnorm0, &debug_1.ndigit, "_getv0: re"
442 "-orthonalization ; rnorm0 is", (ftnlen)38);
443 svout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: re-o"
444 "rthonalization ; rnorm is", (ftnlen)37);
445 }
446
447 if (*rnorm > rnorm0 * .717f) {
448 goto L50;
449 }
450
451 ++iter;
452 if (iter <= 5) {
453
454 /* %-----------------------------------% */
455 /* | Perform iterative refinement step | */
456 /* %-----------------------------------% */
457
458 rnorm0 = *rnorm;
459 goto L30;
460 } else {
461
462 /* %------------------------------------% */
463 /* | Iterative refinement step "failed" | */
464 /* %------------------------------------% */
465
466 i__1 = *n;
467 for (jj = 1; jj <= i__1; ++jj) {
468 resid[jj] = 0.f;
469 /* L45: */
470 }
471 *rnorm = 0.f;
472 *ierr = -1;
473 }
474
475 L50:
476
477 if (msglvl > 0) {
478 svout_(&debug_1.logfil, &c__1, rnorm, &debug_1.ndigit, "_getv0: B-no"
479 "rm of initial / restarted starting vector", (ftnlen)53);
480 }
481 if (msglvl > 3) {
482 svout_(&debug_1.logfil, n, &resid[1], &debug_1.ndigit, "_getv0: init"
483 "ial / restarted starting vector", (ftnlen)43);
484 }
485 *ido = 99;
486
487 second_(&t1);
488 timing_1.tgetv0 += t1 - t0;
489
490 L9000:
491 return 0;
492
493 /* %---------------% */
494 /* | End of sgetv0 | */
495 /* %---------------% */
496
497 } /* sgetv0_ */
498