131
132
133
134
135
136 IMPLICIT NONE
137
138
139 CHARACTER UPLO
140 INTEGER N, NRHS, LDA, LDB, LWORK, INFO
141
142
143 INTEGER IPIV( * )
144 COMPLEX A( LDA, * ), B( LDB, * ), WORK( * )
145
146
147
148
149 COMPLEX ONE
150 parameter( one = 1.0e+0 )
151
152
153 LOGICAL LQUERY, UPPER
154 INTEGER K, KP, LWKOPT
155
156
157 LOGICAL LSAME
158 REAL SROUNDUP_LWORK
160
161
163
164
165 INTRINSIC max
166
167
168
169 info = 0
170 upper =
lsame( uplo,
'U' )
171 lquery = ( lwork.EQ.-1 )
172 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
173 info = -1
174 ELSE IF( n.LT.0 ) THEN
175 info = -2
176 ELSE IF( nrhs.LT.0 ) THEN
177 info = -3
178 ELSE IF( lda.LT.max( 1, n ) ) THEN
179 info = -5
180 ELSE IF( ldb.LT.max( 1, n ) ) THEN
181 info = -8
182 ELSE IF( lwork.LT.max( 1, 3*n-2 ) .AND. .NOT.lquery ) THEN
183 info = -10
184 END IF
185 IF( info.NE.0 ) THEN
186 CALL xerbla(
'CHETRS_AA', -info )
187 RETURN
188 ELSE IF( lquery ) THEN
189 lwkopt = (3*n-2)
191 RETURN
192 END IF
193
194
195
196 IF( n.EQ.0 .OR. nrhs.EQ.0 )
197 $ RETURN
198
199 IF( upper ) THEN
200
201
202
203
204
205 IF( n.GT.1 ) THEN
206
207
208
209 k = 1
210 DO WHILE ( k.LE.n )
211 kp = ipiv( k )
212 IF( kp.NE.k )
213 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
214 k = k + 1
215 END DO
216
217
218
219 CALL ctrsm(
'L',
'U',
'C',
'U', n-1, nrhs, one, a( 1, 2 ),
220 $ lda, b( 2, 1 ), ldb)
221 END IF
222
223
224
225
226
227 CALL clacpy(
'F', 1, n, a(1, 1), lda+1, work(n), 1)
228 IF( n.GT.1 ) THEN
229 CALL clacpy(
'F', 1, n-1, a( 1, 2 ), lda+1, work( 2*n ), 1)
230 CALL clacpy(
'F', 1, n-1, a( 1, 2 ), lda+1, work( 1 ), 1)
231 CALL clacgv( n-1, work( 1 ), 1 )
232 END IF
233 CALL cgtsv(n, nrhs, work(1), work(n), work(2*n), b, ldb,
234 $ info)
235
236
237
238 IF( n.GT.1 ) THEN
239
240
241
242 CALL ctrsm(
'L',
'U',
'N',
'U', n-1, nrhs, one, a( 1, 2 ),
243 $ lda, b(2, 1), ldb)
244
245
246
247 k = n
248 DO WHILE ( k.GE.1 )
249 kp = ipiv( k )
250 IF( kp.NE.k )
251 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
252 k = k - 1
253 END DO
254 END IF
255
256 ELSE
257
258
259
260
261
262 IF( n.GT.1 ) THEN
263
264
265
266 k = 1
267 DO WHILE ( k.LE.n )
268 kp = ipiv( k )
269 IF( kp.NE.k )
270 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
271 k = k + 1
272 END DO
273
274
275
276 CALL ctrsm(
'L',
'L',
'N',
'U', n-1, nrhs, one, a( 2, 1),
277 $ lda, b(2, 1), ldb )
278 END IF
279
280
281
282
283
284 CALL clacpy(
'F', 1, n, a(1, 1), lda+1, work(n), 1)
285 IF( n.GT.1 ) THEN
286 CALL clacpy(
'F', 1, n-1, a( 2, 1 ), lda+1, work( 1 ), 1 )
287 CALL clacpy(
'F', 1, n-1, a( 2, 1 ), lda+1, work( 2*n ), 1)
288 CALL clacgv( n-1, work( 2*n ), 1 )
289 END IF
290 CALL cgtsv(n, nrhs, work(1), work(n), work(2*n), b, ldb,
291 $ info)
292
293
294
295 IF( n.GT.1 ) THEN
296
297
298
299 CALL ctrsm(
'L',
'L',
'C',
'U', n-1, nrhs, one, a( 2, 1 ),
300 $ lda, b( 2, 1 ), ldb )
301
302
303
304 k = n
305 DO WHILE ( k.GE.1 )
306 kp = ipiv( k )
307 IF( kp.NE.k )
308 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
309 k = k - 1
310 END DO
311 END IF
312
313 END IF
314
315 RETURN
316
317
318
subroutine xerbla(srname, info)
subroutine cgtsv(n, nrhs, dl, d, du, b, ldb, info)
CGTSV computes the solution to system of linear equations A * X = B for GT matrices
subroutine clacgv(n, x, incx)
CLACGV conjugates a complex vector.
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
logical function lsame(ca, cb)
LSAME
real function sroundup_lwork(lwork)
SROUNDUP_LWORK
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
subroutine ctrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRSM