PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
sqrt02.f
Go to the documentation of this file.
1  SUBROUTINE sqrt02( M, N, K, A, AF, Q, R, LDA, T, WORK, LWORK,
2  $ rwork, result )
3 *
4  include 'plasmaf.h'
5 *
6 * -- LAPACK test routine (version 3.1) --
7 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
8 * November 2006
9 *
10 * .. Scalar Arguments ..
11  INTEGER k, lda, lwork, m, n
12  INTEGER t(2)
13 * ..
14 * .. Array Arguments ..
15  REAL a( lda, * ), af( lda, * ), q( lda, * ),
16  $ r( lda, * ), result( * ), rwork( * ),
17  $ work( lwork )
18 * ..
19 *
20 * Purpose
21 * =======
22 *
23 * SQRT02 tests SORGQR, which generates an m-by-n matrix Q with
24 * orthonornmal columns that is defined as the product of k elementary
25 * reflectors.
26 *
27 * Given the QR factorization of an m-by-n matrix A, SQRT02 generates
28 * the orthogonal matrix Q defined by the factorization of the first k
29 * columns of A; it compares R(1:n,1:k) with Q(1:m,1:n)'*A(1:m,1:k),
30 * and checks that the columns of Q are orthonormal.
31 *
32 * Arguments
33 * =========
34 *
35 * M (input) INTEGER
36 * The number of rows of the matrix Q to be generated. M >= 0.
37 *
38 * N (input) INTEGER
39 * The number of columns of the matrix Q to be generated.
40 * M >= N >= 0.
41 *
42 * K (input) INTEGER
43 * The number of elementary reflectors whose product defines the
44 * matrix Q. N >= K >= 0.
45 *
46 * A (input) REAL array, dimension (LDA,N)
47 * The m-by-n matrix A which was factorized by SQRT01.
48 *
49 * AF (input) REAL array, dimension (LDA,N)
50 * Details of the QR factorization of A, as returned by SGEQRF.
51 * See SGEQRF for further details.
52 *
53 * Q (workspace) REAL array, dimension (LDA,N)
54 *
55 * R (workspace) REAL array, dimension (LDA,N)
56 *
57 * LDA (input) INTEGER
58 * The leading dimension of the arrays A, AF, Q and R. LDA >= M.
59 *
60 * TAU (input) REAL array, dimension (N)
61 * The scalar factors of the elementary reflectors corresponding
62 * to the QR factorization in AF.
63 *
64 * WORK (workspace) REAL array, dimension (LWORK)
65 *
66 * LWORK (input) INTEGER
67 * The dimension of the array WORK.
68 *
69 * RWORK (workspace) REAL array, dimension (M)
70 *
71 * RESULT (output) REAL array, dimension (2)
72 * The test ratios:
73 * RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS )
74 * RESULT(2) = norm( I - Q'*Q ) / ( M * EPS )
75 *
76 * =====================================================================
77 *
78 * .. Parameters ..
79  REAL zero, one
80  parameter( zero = 0.0e+0, one = 1.0e+0 )
81  REAL rogue
82  parameter( rogue = -1.0e+10 )
83 * ..
84 * .. Local Scalars ..
85  INTEGER info
86  REAL anorm, eps, resid
87 * ..
88 * .. External Functions ..
89  REAL slamch, slange, slansy
90  EXTERNAL slamch, slange, slansy
91 * ..
92 * .. External Subroutines ..
93  EXTERNAL sgemm, slacpy, slaset, sorgqr, ssyrk
94 * ..
95 * .. Intrinsic Functions ..
96  INTRINSIC max, real
97 * ..
98 * .. Scalars in Common ..
99  CHARACTER*32 srnamt
100 * ..
101 * .. Common blocks ..
102  common / srnamc / srnamt
103 * ..
104 * .. Executable Statements ..
105 *
106  eps = slamch( 'Epsilon' )
107 *
108 * Copy the first k columns of the factorization to the array Q
109 *
110  CALL slaset( 'Full', m, n, zero, one, q, lda )
111 *
112 * Generate the first n columns of the matrix Q
113 *
114  srnamt = 'SORGQR'
115  CALL plasma_sorgqr( m, n, k, af, lda, t, q, lda, info )
116 *
117 * Copy R(1:n,1:k)
118 *
119  CALL slaset( 'Full', n, k, zero, zero, r, lda )
120  CALL slacpy( 'Upper', n, k, af, lda, r, lda )
121 *
122 * Compute R(1:n,1:k) - Q(1:m,1:n)' * A(1:m,1:k)
123 *
124  CALL sgemm( 'Transpose', 'No transpose', n, k, m, -one, q, lda, a,
125  $ lda, one, r, lda )
126 *
127 * Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) .
128 *
129  anorm = slange( '1', m, k, a, lda, rwork )
130  resid = slange( '1', n, k, r, lda, rwork )
131  IF( anorm.GT.zero ) THEN
132  result( 1 ) = ( ( resid / REAL( MAX( 1, M ) ) ) / anorm ) / eps
133  ELSE
134  result( 1 ) = zero
135  END IF
136 *
137 * Compute I - Q'*Q
138 *
139  CALL slaset( 'Full', n, n, zero, one, r, lda )
140  CALL ssyrk( 'Upper', 'Transpose', n, m, -one, q, lda, one, r,
141  $ lda )
142 *
143 * Compute norm( I - Q'*Q ) / ( M * EPS ) .
144 *
145  resid = slansy( '1', 'Upper', n, r, lda, rwork )
146 *
147  result( 2 ) = ( resid / REAL( MAX( 1, M ) ) ) / eps
148 *
149  return
150 *
151 * End of SQRT02
152 *
153  END