1 REAL FUNCTION PCLANHS( NORM, N, A, IA, JA, DESCA,
143 INTEGER block_cyclic_2d, csrc_, ctxt_, dlen_, dtype_,
144 $ lld_, mb_, m_, nb_, n_, rsrc_
145 parameter( block_cyclic_2d = 1, dlen_ = 9, dtype_ = 1,
146 $ ctxt_ = 2, m_ = 3, n_ = 4, mb_ = 5, nb_ = 6,
147 $ rsrc_ = 7, csrc_ = 8, lld_ = 9 )
149 parameter( one = 1.0e+0, zero = 0.0e+0 )
152 INTEGER iacol, iarow, ictxt, ii, iia, icoff, inxtrow,
153 $ ioffa, iroff, j, jb, jj, jja, jn, kk, lda, ll,
154 $ mycol, myrow, np, npcol, nprow, nq
155 REAL scale, sum, value
171 INTRINSIC abs,
max,
min, mod, sqrt
177 ictxt = desca( ctxt_ )
178 CALL blacs_gridinfo( ictxt, nprow, npcol, myrow, mycol )
180 CALL infog2l( ia, ja, desca, nprow, npcol, myrow, mycol, iia, jja,
182 iroff = mod( ia-1, desca( mb_ ) )
183 icoff = mod( ja-1, desca( nb_ ) )
184 np =
numroc( n+iroff, desca( mb_ ), myrow, iarow, nprow )
185 nq =
numroc( n+icoff, desca( nb_ ), mycol, iacol, npcol )
191 ioffa = ( jja - 1 ) * lda
197 ELSE IF(
lsame( norm,
'M' ) )
THEN
205 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
210 IF( nprow.EQ.1 )
THEN
214 IF( mycol.EQ.iacol )
THEN
215 DO 20 ll = jj, jj+jb-1
216 DO 10 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
217 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
224 iacol = mod( iacol+1, npcol )
228 DO 50 j = jn+1, ja+n-1, desca( nb_ )
229 jb =
min( ja+n-j, desca( nb_ ) )
231 IF( mycol.EQ.iacol )
THEN
232 DO 40 ll = jj, jj+jb-1
233 DO 30 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
234 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
242 iacol = mod( iacol+1, npcol )
250 inxtrow = mod( iarow+1, nprow )
251 IF( mycol.EQ.iacol )
THEN
252 IF( myrow.EQ.iarow )
THEN
253 DO 70 ll = jj, jj + jb -1
254 DO 60 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
255 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
260 DO 90 ll = jj, jj+jb-1
261 DO 80 kk = iia,
min( ii-1, iia+np-1 )
262 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
266 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
267 $
VALUE =
max(
VALUE, abs( a( ii+(jj+jb-2)*lda ) ) )
275 iarow = mod( iarow+1, nprow )
276 iacol = mod( iacol+1, npcol )
280 DO 140 j = jn+1, ja+n-1, desca( nb_ )
281 jb =
min( ja+n-j, desca( nb_ ) )
283 IF( mycol.EQ.iacol )
THEN
284 IF( myrow.EQ.iarow )
THEN
285 DO 110 ll = jj, jj + jb -1
286 DO 100 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
287 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
292 DO 130 ll = jj, jj + jb -1
293 DO 120 kk = iia,
min( ii-1, iia+np-1 )
294 VALUE =
max(
VALUE, abs( a( ioffa+kk ) ) )
298 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
299 $
VALUE =
max(
VALUE,
300 $ abs( a( ii+(jj+jb-2)*lda ) ) )
308 iarow = mod( iarow+1, nprow )
309 iacol = mod( iacol+1, npcol )
317 CALL sgamx2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1, kk, ll, -1,
320 ELSE IF(
lsame( norm,
'O' ) .OR. norm.EQ.
'1' )
THEN
325 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
330 IF( nprow.EQ.1 )
THEN
334 IF( mycol.EQ.iacol )
THEN
335 DO 160 ll = jj, jj+jb-1
337 DO 150 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
338 sum = sum + abs( a( ioffa+kk ) )
341 work( ll-jja+1 ) = sum
346 iacol = mod( iacol+1, npcol )
350 DO 190 j = jn+1, ja+n-1, desca( nb_ )
351 jb =
min( ja+n-j, desca( nb_ ) )
353 IF( mycol.EQ.iacol )
THEN
354 DO 180 ll = jj, jj+jb-1
356 DO 170 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
357 sum = sum + abs( a( ioffa+kk ) )
360 work( ll-jja+1 ) = sum
366 iacol = mod( iacol+1, npcol )
374 inxtrow = mod( iarow+1, nprow )
375 IF( mycol.EQ.iacol )
THEN
376 IF( myrow.EQ.iarow )
THEN
377 DO 210 ll = jj, jj + jb -1
379 DO 200 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
380 sum = sum + abs( a( ioffa+kk ) )
383 work( ll-jja+1 ) = sum
386 DO 230 ll = jj, jj + jb -1
388 DO 220 kk = iia,
min( ii-1, iia+np-1 )
389 sum = sum + abs( a( ioffa+kk ) )
392 work( ll-jja+1 ) = sum
394 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
395 $ work( jj+jb-jja ) = work( jj+jb-jja ) +
396 $ abs( a( ii+(jj+jb-2)*lda ) )
404 iarow = mod( iarow+1, nprow )
405 iacol = mod( iacol+1, npcol )
409 DO 280 j = jn+1, ja+n-1, desca( nb_ )
410 jb =
min( ja+n-j, desca( nb_ ) )
412 IF( mycol.EQ.iacol )
THEN
413 IF( myrow.EQ.iarow )
THEN
414 DO 250 ll = jj, jj + jb -1
416 DO 240 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
417 sum = sum + abs( a( ioffa+kk ) )
420 work( ll-jja+1 ) = sum
423 DO 270 ll = jj, jj + jb -1
425 DO 260 kk = iia,
min( ii-1, iia+np-1 )
426 sum = sum + abs( a( ioffa+kk ) )
429 work( ll-jja+1 ) = sum
431 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
432 $ work( jj+jb-jja ) = work( jj+jb-jja ) +
433 $ abs( a( ii+(jj+jb-2)*lda ) )
441 iarow = mod( iarow+1, nprow )
442 iacol = mod( iacol+1, npcol )
451 CALL sgsum2d( ictxt,
'Columnwise',
' ', 1, nq, work, 1,
456 IF( myrow.EQ.0 )
THEN
458 VALUE = work( isamax( nq, work, 1 ) )
462 CALL sgamx2d( ictxt,
'Rowwise',
' ', 1, 1,
VALUE, 1, kk, ll,
466 ELSE IF(
lsame( norm,
'I' ) )
THEN
468 DO 290 kk = iia, iia+np-1
474 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
479 IF( nprow.EQ.1 )
THEN
483 IF( mycol.EQ.iacol )
THEN
484 DO 310 ll = jj, jj+jb-1
485 DO 300 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
486 work( kk-iia+1 ) = work( kk-iia+1 ) +
487 $ abs( a( ioffa+kk ) )
494 iacol = mod( iacol+1, npcol )
498 DO 340 j = jn+1, ja+n-1, desca( nb_ )
499 jb =
min( ja+n-j, desca( nb_ ) )
501 IF( mycol.EQ.iacol )
THEN
502 DO 330 ll = jj, jj+jb-1
503 DO 320 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
504 work( kk-iia+1 ) = work( kk-iia+1 ) +
505 $ abs( a( ioffa+kk ) )
513 iacol = mod( iacol+1, npcol )
521 inxtrow = mod( iarow+1, nprow )
522 IF( mycol.EQ.iacol )
THEN
523 IF( myrow.EQ.iarow )
THEN
524 DO 360 ll = jj, jj + jb -1
525 DO 350 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
526 work( kk-iia+1 ) = work( kk-iia+1 ) +
527 $ abs( a( ioffa+kk ) )
532 DO 380 ll = jj, jj + jb -1
533 DO 370 kk = iia,
min( ii-1, iia+np-1 )
534 work( kk-iia+1 ) = work( kk-iia+1 ) +
535 $ abs( a( ioffa+kk ) )
539 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
540 $ work( ii-iia+1 ) = work( ii-iia+1 ) +
541 $ abs( a( ii+(jj+jb-2)*lda ) )
549 iarow = mod( iarow+1, nprow )
550 iacol = mod( iacol+1, npcol )
554 DO 430 j = jn+1, ja+n-1, desca( nb_ )
555 jb =
min( ja+n-j, desca( nb_ ) )
557 IF( mycol.EQ.iacol )
THEN
558 IF( myrow.EQ.iarow )
THEN
559 DO 400 ll = jj, jj + jb -1
560 DO 390 kk = iia,
min( ii+ll-jj+1, iia+np-1 )
561 work( kk-iia+1 ) = work( kk-iia+1 ) +
562 $ abs( a( ioffa+kk ) )
567 DO 420 ll = jj, jj + jb -1
568 DO 410 kk = iia,
min( ii-1, iia+np-1 )
569 work( kk-iia+1 ) = work( kk-iia+1 ) +
574 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
575 $ work( ii-iia+1 ) = work( ii-iia+1 ) +
576 $ abs( a( ii+(jj+jb-2)*lda ) )
584 iarow = mod( iarow+1, nprow )
585 iacol = mod( iacol+1, npcol )
594 CALL sgsum2d( ictxt,
'Rowwise',
' ', np, 1, work,
max( 1, np ),
599 IF( mycol.EQ.0 )
THEN
601 VALUE = work( isamax( np, work, 1 ) )
605 CALL sgamx2d( ictxt,
'Columnwise',
' ', 1, 1,
VALUE, 1, kk,
609 ELSE IF(
lsame( norm,
'F' ) .OR.
lsame( norm,
'E' ) )
THEN
615 jn =
min(
iceil( ja, desca( nb_ ) ) * desca( nb_ ), ja+n-1 )
620 IF( nprow.EQ.1 )
THEN
624 IF( mycol.EQ.iacol )
THEN
625 DO 440 ll = jj, jj+jb-1
626 CALL classq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
627 $ a( iia+ioffa ), 1, scale, sum )
633 iacol = mod( iacol+1, npcol )
637 DO 460 j = jn+1, ja+n-1, desca( nb_ )
638 jb =
min( ja+n-j, desca( nb_ ) )
640 IF( mycol.EQ.iacol )
THEN
641 DO 450 ll = jj, jj+jb-1
642 CALL classq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
643 $ a( iia+ioffa ), 1, scale, sum )
650 iacol = mod( iacol+1, npcol )
658 inxtrow = mod( iarow+1, nprow )
659 IF( mycol.EQ.iacol )
THEN
660 IF( myrow.EQ.iarow )
THEN
661 DO 470 ll = jj, jj + jb -1
662 CALL classq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
663 $ a( iia+ioffa ), 1, scale, sum )
667 DO 480 ll = jj, jj + jb -1
668 CALL classq(
min( ii-1, iia+np-1 )-iia+1,
669 $ a( iia+ioffa ), 1, scale, sum )
672 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
673 $
CALL classq( 1, a( ii+(jj+jb-2)*lda ), 1,
682 iarow = mod( iarow+1, nprow )
683 iacol = mod( iacol+1, npcol )
687 DO 510 j = jn+1, ja+n-1, desca( nb_ )
688 jb =
min( ja+n-j, desca( nb_ ) )
690 IF( mycol.EQ.iacol )
THEN
691 IF( myrow.EQ.iarow )
THEN
692 DO 490 ll = jj, jj + jb -1
693 CALL classq(
min( ii+ll-jj+1, iia+np-1 )-iia+1,
694 $ a( iia+ioffa ), 1, scale, sum )
698 DO 500 ll = jj, jj + jb -1
699 CALL classq(
min( ii-1, iia+np-1 )-iia+1,
700 $ a( iia+ioffa ), 1, scale, sum )
703 IF( myrow.EQ.inxtrow .AND. ii.LE.iia+np-1 )
704 $
CALL classq( 1, a( ii+(jj+jb-2)*lda ), 1,
713 iarow = mod( iarow+1, nprow )
714 iacol = mod( iacol+1, npcol )
725 VALUE = rwork( 1 ) * sqrt( rwork( 2 ) )
729 IF( myrow.EQ.0 .AND. mycol.EQ.0 )
THEN
730 CALL sgebs2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1 )
732 CALL sgebr2d( ictxt,
'All',
' ', 1, 1,
VALUE, 1, 0, 0 )