1 REAL FUNCTION PSLANHS( NORM, N, A, IA, JA, DESCA,
15 REAL a( * ), work( * )
142 INTEGER block_cyclic_2d, csrc_, ctxt_, dlen_, dtype_,
143 $ lld_, mb_, m_, nb_, n_, rsrc_
144 parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
145 $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
146 $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
148 parameter( one = 1.0e+0, zero = 0.0e+0 )
151 INTEGER iacol, iarow, ictxt, ii, iia, icoff, inxtrow,
152 $ ioffa, iroff, j, jb, jj, jja, jn, kk, lda, ll,
153 $ mycol, myrow, np, npcol, nprow, nq
154 REAL scale, sum, value
162 $ sgamx2d, sgsum2d, slassq
170 INTRINSIC abs,
max,
min, mod, sqrt
176 ictxt = desca( ctxt_ )
177 CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
179 CALL infog2l( ia, ja, desca, nprow, npcol, myrow, mycol, iia, jja,
181 iroff = mod( ia-1, desca( mb_ ) )
182 icoff = mod( ja-1, desca( nb_ ) )
183 np =
numroc( n+iroff, desca( mb_ ), myrow, iarow, nprow )
184 nq =
numroc( n+icoff, desca( nb_ ), mycol, iacol, npcol )
190 ioffa = ( jja - 1 ) * lda
196 ELSE IF(
lsame( norm,
'M' ) )
THEN
204 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
209 IF( nprow.EQ.1 )
THEN
213 IF( mycol.EQ.iacol )
THEN
214 DO 20 ll = jj, jj+jb-1
215 DO 10 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
216 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
223 iacol = mod( iacol+1, npcol )
227 DO 50 j = jn+1, ja+n-1, desca( nb_ )
228 jb =
min( ja+n-j, desca( nb_ ) )
230 IF( mycol.EQ.iacol )
THEN
231 DO 40 ll = jj, jj+jb-1
232 DO 30 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
233 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
241 iacol = mod( iacol+1, npcol )
249 inxtrow = mod( iarow+1, nprow )
250 IF( mycol.EQ.iacol )
THEN
251 IF( myrow.EQ.iarow )
THEN
252 DO 70 ll = jj, jj + jb -1
253 DO 60 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
254 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
259 DO 90 ll = jj, jj+jb-1
260 DO 80 kk = iia,
min( ii-1, iia+np-1 )
261 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
265 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
266 $
VALUE =
max(
VALUE, abs( a( ii+(jj+jb-2)*lda ) ) )
274 iarow = mod( iarow+1, nprow )
275 iacol = mod( iacol+1, npcol )
279 DO 140 j = jn+1, ja+n-1, desca( nb_ )
280 jb =
min( ja+n-j, desca( nb_ ) )
282 IF( mycol.EQ.iacol )
THEN
283 IF( myrow.EQ.iarow )
THEN
284 DO 110 ll = jj, jj + jb -1
285 DO 100 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
286 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
291 DO 130 ll = jj, jj + jb -1
292 DO 120 kk = iia,
min( ii-1, iia+np-1 )
293 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
297 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
298 $
VALUE =
max(
VALUE,
299 $ abs( a( ii+(jj+jb-2)*lda ) ) )
307 iarow = mod( iarow+1, nprow )
308 iacol = mod( iacol+1, npcol )
316 CALL sgamx2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1, kk, ll, -1,
319 ELSE IF(
lsame( norm,
'O' ) .OR. norm.EQ.
'1' )
THEN
324 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
329 IF( nprow.EQ.1 )
THEN
333 IF( mycol.EQ.iacol )
THEN
334 DO 160 ll = jj, jj+jb-1
336 DO 150 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
337 sum = sum + abs( a( ioffa+kk ) )
340 work( ll-jja+1 ) = sum
345 iacol = mod( iacol+1, npcol )
349 DO 190 j = jn+1, ja+n-1, desca( nb_ )
350 jb =
min( ja+n-j, desca( nb_ ) )
352 IF( mycol.EQ.iacol )
THEN
353 DO 180 ll = jj, jj+jb-1
355 DO 170 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
356 sum = sum + abs( a( ioffa+kk ) )
359 work( ll-jja+1 ) = sum
365 iacol = mod( iacol+1, npcol )
373 inxtrow = mod( iarow+1, nprow )
374 IF( mycol.EQ.iacol )
THEN
375 IF( myrow.EQ.iarow )
THEN
376 DO 210 ll = jj, jj + jb -1
378 DO 200 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
379 sum = sum + abs( a( ioffa+kk ) )
382 work( ll-jja+1 ) = sum
385 DO 230 ll = jj, jj + jb -1
387 DO 220 kk = iia,
min( ii-1, iia+np-1 )
388 sum = sum + abs( a( ioffa+kk ) )
391 work( ll-jja+1 ) = sum
393 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
394 $ work( jj+jb-jja ) = work( jj+jb-jja ) +
395 $ abs( a( ii+(jj+jb-2)*lda ) )
403 iarow = mod( iarow+1, nprow )
404 iacol = mod( iacol+1, npcol )
408 DO 280 j = jn+1, ja+n-1, desca( nb_ )
409 jb =
min( ja+n-j, desca( nb_ ) )
411 IF( mycol.EQ.iacol )
THEN
412 IF( myrow.EQ.iarow )
THEN
413 DO 250 ll = jj, jj + jb -1
415 DO 240 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
416 sum = sum + abs( a( ioffa+kk ) )
419 work( ll-jja+1 ) = sum
422 DO 270 ll = jj, jj + jb -1
424 DO 260 kk = iia,
min( ii-1, iia+np-1 )
425 sum = sum + abs( a( ioffa+kk ) )
428 work( ll-jja+1 ) = sum
430 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
431 $ work( jj+jb-jja ) = work( jj+jb-jja ) +
432 $ abs( a( ii+(jj+jb-2)*lda ) )
440 iarow = mod( iarow+1, nprow )
441 iacol = mod( iacol+1, npcol )
450 CALL sgsum2d( ictxt,
'Columnwise',
' ', 1, nq, work, 1,
455 IF( myrow.EQ.0 )
THEN
457 VALUE = work( isamax( nq, work, 1 ) )
461 CALL sgamx2d( ictxt,
'Rowwise',
' ', 1, 1,
VALUE, 1, kk, ll,
465 ELSE IF(
lsame( norm,
'I' ) )
THEN
467 DO 290 kk = iia, iia+np-1
473 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
478 IF( nprow.EQ.1 )
THEN
482 IF( mycol.EQ.iacol )
THEN
483 DO 310 ll = jj, jj+jb-1
484 DO 300 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
485 work( kk-iia+1 ) = work( kk-iia+1 ) +
486 $ abs( a( ioffa+kk ) )
493 iacol = mod( iacol+1, npcol )
497 DO 340 j = jn+1, ja+n-1, desca( nb_ )
498 jb =
min( ja+n-j, desca( nb_ ) )
500 IF( mycol.EQ.iacol )
THEN
501 DO 330 ll = jj, jj+jb-1
502 DO 320 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
503 work( kk-iia+1 ) = work( kk-iia+1 ) +
504 $ abs( a( ioffa+kk ) )
512 iacol = mod( iacol+1, npcol )
520 inxtrow = mod( iarow+1, nprow )
521 IF( mycol.EQ.iacol )
THEN
522 IF( myrow.EQ.iarow )
THEN
523 DO 360 ll = jj, jj + jb -1
524 DO 350 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
525 work( kk-iia+1 ) = work( kk-iia+1 ) +
526 $ abs( a( ioffa+kk ) )
531 DO 380 ll = jj, jj + jb -1
532 DO 370 kk = iia,
min( ii-1, iia+np-1 )
533 work( kk-iia+1 ) = work( kk-iia+1 ) +
534 $ abs( a( ioffa+kk ) )
538 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
539 $ work( ii-iia+1 ) = work( ii-iia+1 ) +
540 $ abs( a( ii+(jj+jb-2)*lda ) )
548 iarow = mod( iarow+1, nprow )
549 iacol = mod( iacol+1, npcol )
553 DO 430 j = jn+1, ja+n-1, desca( nb_ )
554 jb =
min( ja+n-j, desca( nb_ ) )
556 IF( mycol.EQ.iacol )
THEN
557 IF( myrow.EQ.iarow )
THEN
558 DO 400 ll = jj, jj + jb -1
559 DO 390 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
560 work( kk-iia+1 ) = work( kk-iia+1 ) +
561 $ abs( a( ioffa+kk ) )
566 DO 420 ll = jj, jj + jb -1
567 DO 410 kk = iia,
min( ii-1, iia+np-1 )
568 work( kk-iia+1 ) = work( kk-iia+1 ) +
573 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
574 $ work( ii-iia+1 ) = work( ii-iia+1 ) +
575 $ abs( a( ii+(jj+jb-2)*lda ) )
583 iarow = mod( iarow+1, nprow )
584 iacol = mod( iacol+1, npcol )
593 CALL sgsum2d( ictxt,
'Rowwise',
' ', np, 1, work,
max( 1, np ),
598 IF( mycol.EQ.0 )
THEN
600 VALUE = work( isamax( np, work, 1 ) )
604 CALL sgamx2d( ictxt,
'Columnwise',
' ', 1, 1,
VALUE, 1, kk,
608 ELSE IF(
lsame( norm,
'F' ) .OR.
lsame( norm,
'E' ) )
THEN
614 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
619 IF( nprow.EQ.1 )
THEN
623 IF( mycol.EQ.iacol )
THEN
624 DO 440 ll = jj, jj+jb-1
625 CALL slassq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
626 $ a( iia+ioffa ), 1, scale, sum )
632 iacol = mod( iacol+1, npcol )
636 DO 460 j = jn+1, ja+n-1, desca( nb_ )
637 jb =
min( ja+n-j, desca( nb_ ) )
639 IF( mycol.EQ.iacol )
THEN
640 DO 450 ll = jj, jj+jb-1
641 CALL slassq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
642 $ a( iia+ioffa ), 1, scale, sum )
649 iacol = mod( iacol+1, npcol )
657 inxtrow = mod( iarow+1, nprow )
658 IF( mycol.EQ.iacol )
THEN
659 IF( myrow.EQ.iarow )
THEN
660 DO 470 ll = jj, jj + jb -1
661 CALL slassq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
662 $ a( iia+ioffa ), 1, scale, sum )
666 DO 480 ll = jj, jj + jb -1
667 CALL slassq(
min( ii-1, iia+np-1 )-iia+1,
668 $ a( iia+ioffa ), 1, scale, sum )
671 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
672 $
CALL slassq( 1, a( ii+(jj+jb-2)*lda ), 1,
681 iarow = mod( iarow+1, nprow )
682 iacol = mod( iacol+1, npcol )
686 DO 510 j = jn+1, ja+n-1, desca( nb_ )
687 jb =
min( ja+n-j, desca( nb_ ) )
689 IF( mycol.EQ.iacol )
THEN
690 IF( myrow.EQ.iarow )
THEN
691 DO 490 ll = jj, jj + jb -1
692 CALL slassq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
693 $ a( iia+ioffa ), 1, scale, sum )
697 DO 500 ll = jj, jj + jb -1
698 CALL slassq(
min( ii-1, iia+np-1 )-iia+1,
699 $ a( iia+ioffa ), 1, scale, sum )
702 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
703 $
CALL slassq( 1, a( ii+(jj+jb-2)*lda ), 1,
712 iarow = mod( iarow+1, nprow )
713 iacol = mod( iacol+1, npcol )
724 VALUE = rwork( 1 ) * sqrt( rwork( 2 ) )
728 IF( myrow.EQ.0 .AND. mycol.EQ.0 )
THEN
729 CALL sgebs2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1 )
731 CALL sgebr2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1, 0, 0 )