14 #include "../PBpblas.h"
15 #include "../PBtools.h"
16 #include "../PBblacs.h"
17 #include "../PBblas.h"
22 char * A,
int IA,
int JA,
int * DESCA,
char * AROC,
24 char * B,
int IB,
int JB,
int * DESCB,
char * BROC )
26 void PB_CpaxpbyND(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA, AROC,
27 BETA, B, IB, JB, DESCB, BROC )
31 char * AROC, * BROC, * CONJUG;
32 int IA, IB, JA, JB, M, N;
218 char * one, * top, * zero;
219 int Acol, Aii, AisR, AisRow, Ajj, Ald, AmyprocD, AmyprocR,
220 AnprocsD, AprocR, Aroc, Arow, Bcol, Bii, Binb1D, BisR, BisRow,
221 Bjj, Bld, BmyprocD, BmyprocR, BnD, BnbD, BnpD, BnprocsD,
222 BprocD, BprocR, Broc, Brow, RRorCC, ctxt, k, kbb, kk, kn,
223 ktmp, mycol, mydist, myproc, myrow, npcol, nprow, p, size;
240 PB_Cinfog2l( IA, JA, DESCA, nprow, npcol, myrow, mycol, &Aii, &Ajj,
242 if( ( AisRow = (
Mupcase( AROC[0] ) ==
CROW ) ) != 0 )
244 BnD = N; Ald = DESCA[
LLD_];
245 AmyprocD = mycol; AnprocsD = npcol; AmyprocR = myrow; AprocR = Arow;
246 AisR = ( ( Arow == -1 ) || ( nprow == 1 ) );
250 BnD = M; Ald = DESCA[
LLD_];
251 AmyprocD = myrow; AnprocsD = nprow; AmyprocR = mycol; AprocR = Acol;
252 AisR = ( ( Acol == -1 ) || ( npcol == 1 ) );
257 PB_Cinfog2l( IB, JB, DESCB, nprow, npcol, myrow, mycol, &Bii, &Bjj,
259 if( ( BisRow = (
Mupcase( BROC[0] ) ==
CROW ) ) != 0 )
261 BnbD = DESCB[
NB_]; Bld = DESCB[
LLD_];
262 BprocD = Bcol; BmyprocD = mycol; BnprocsD = npcol;
263 BprocR = Brow; BmyprocR = myrow;
264 BisR = ( ( BprocR == -1 ) || ( nprow == 1 ) );
269 BnbD = DESCB[
MB_]; Bld = DESCB[
LLD_];
270 BprocD = Brow; BmyprocD = myrow; BnprocsD = nprow;
271 BprocR = Bcol; BmyprocR = mycol;
272 BisR = ( ( BprocR == -1 ) || ( npcol == 1 ) );
278 RRorCC = ( ( AisRow && BisRow ) || ( !( AisRow ) && !( BisRow ) ) );
289 if( BisR ) { BprocR = ( ( RRorCC ) ? AprocR : 0 ); }
296 if( ( AmyprocR == AprocR ) || ( BmyprocR == BprocR ) )
305 else add =
TYPE->Fmmadd;
307 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, BmyprocD, BprocD,
312 if( AprocR == BprocR )
320 if( AisRow ) { kk = Bjj; ktmp = JA + N; kn = JA + Binb1D; }
321 else { kk = Bii; ktmp = IA + M; kn = IA + Binb1D; }
323 if( BmyprocD == Broc )
326 add( &M, &Binb1D, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ),
327 &Ald, BETA,
Mptr( B, Bii, Bjj, Bld, size ), &Bld );
329 add( &Binb1D, &N, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ),
330 &Ald, BETA,
Mptr( B, Bii, Bjj, Bld, size ), &Bld );
335 for( k = kn; k < ktmp; k += BnbD )
337 kbb = ktmp - k; kbb =
MIN( kbb, BnbD );
339 if( BmyprocD == Broc )
342 add( &M, &kbb, ALPHA,
Mptr( A, Aii, k, Ald, size ),
343 &Ald, BETA,
Mptr( B, Bii, kk, Bld, size ),
346 add( &kbb, &N, ALPHA,
Mptr( A, k, Ajj, Ald, size ),
347 &Ald, BETA,
Mptr( B, kk, Bjj, Bld, size ),
360 if( BmyprocR == BprocR )
371 TYPE->Cgerv2d( ctxt, M, BnpD, buf, M, AprocR,
373 add( &M, &BnpD, ALPHA, buf, &M, BETA,
Mptr( B, Bii, Bjj,
375 if( buf ) free( buf );
380 TYPE->Cgerv2d( ctxt, BnpD, N, buf, BnpD, BmyprocD,
382 add( &BnpD, &N, ALPHA, buf, &BnpD, BETA,
Mptr( B, Bii,
383 Bjj, Bld, size ), &Bld );
384 if( buf ) free( buf );
389 if( AmyprocR == AprocR )
412 if( BmyprocD == Broc )
415 add( &M, &Binb1D, one,
Mptr( A, Aii, Ajj, Ald,
416 size ), &Ald, zero, buf, &M );
418 add( &Binb1D, &N, one,
Mptr( A, Aii, Ajj, Ald,
419 size ), &Ald, zero, buf, &BnpD );
424 for( k = kn; k < ktmp; k += BnbD )
426 kbb = ktmp - k; kbb =
MIN( kbb, BnbD );
428 if( BmyprocD == Broc )
431 add( &M, &kbb, one,
Mptr( A, Aii, k, Ald, size ),
432 &Ald, zero,
Mptr( buf, 0, kk, M, size ),
435 add( &kbb, &N, one,
Mptr( A, k, Ajj, Ald, size ),
436 &Ald, zero,
Mptr( buf, kk, 0, BnpD, size ),
444 TYPE->Cgesd2d( ctxt, M, BnpD, buf, M, BprocR,
447 TYPE->Cgesd2d( ctxt, BnpD, N, buf, BnpD, AmyprocD,
449 if( buf ) free( buf );
460 else add =
TYPE->Fmmtadd;
463 if( AisRow ) { ktmp = JA + N; kn = JA + Binb1D; }
464 else { ktmp = IA + M; kn = IA + Binb1D; }
469 for( p = 0; p < BnprocsD; p++ )
471 mydist =
MModSub( p, BprocD, BnprocsD );
472 myproc =
MModAdd( BprocD, mydist, BnprocsD );
474 if( ( AprocR == p ) && ( BprocR == Aroc ) )
476 if( ( AmyprocR == p ) && ( AmyprocD == Aroc ) )
481 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, p, BprocD,
486 kk = ( AisRow ? Bii : Bjj );
491 add( &M, &Binb1D, ALPHA,
Mptr( A, Aii, Ajj, Ald,
492 size ), &Ald, BETA,
Mptr( B, Bii, Bjj, Bld,
495 add( &Binb1D, &N, ALPHA,
Mptr( A, Aii, Ajj, Ald,
496 size ), &Ald, BETA,
Mptr( B, Bii, Bjj, Bld,
502 for( k = kn; k < ktmp; k += BnbD )
504 kbb = ktmp - k; kbb =
MIN( kbb, BnbD );
508 add( &M, &kbb, ALPHA,
Mptr( A, Aii, k, Ald,
509 size ), &Ald, BETA,
Mptr( B, kk, Bjj, Bld,
512 add( &kbb, &N, ALPHA,
Mptr( A, k, Ajj, Ald,
513 size ), &Ald, BETA,
Mptr( B, Bii, kk, Bld,
527 if( ( BmyprocR == BprocR ) && ( BmyprocD == p ) )
529 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, p, BprocD,
536 TYPE->Cgerv2d( ctxt, BnpD, M, buf, BnpD, AprocR,
538 TYPE->Fmmadd( &BnpD, &M, ALPHA, buf, &BnpD, BETA,
539 Mptr( B, Bii, Bjj, Bld, size ), &Bld );
544 TYPE->Cgerv2d( ctxt, N, BnpD, buf, N, Aroc, AprocR );
545 TYPE->Fmmadd( &N, &BnpD, ALPHA, buf, &N, BETA,
546 Mptr( B, Bii, Bjj, Bld, size ), &Bld );
548 if( buf ) free( buf );
552 if( ( AmyprocR == AprocR ) && ( AmyprocD == Aroc ) )
554 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, p, BprocD,
568 add( &M, &Binb1D, one,
Mptr( A, Aii, Ajj, Ald,
569 size ), &Ald, zero, buf, &BnpD );
571 add( &Binb1D, &N, one,
Mptr( A, Aii, Ajj, Ald,
572 size ), &Ald, zero, buf, &N );
577 for( k = kn; k < ktmp; k += BnbD )
579 kbb = ktmp - k; kbb =
MIN( kbb, BnbD );
583 add( &M, &kbb, one,
Mptr( A, Aii, k, Ald,
584 size ), &Ald, zero,
Mptr( buf, kk, 0,
585 BnpD, size ), &BnpD );
587 add( &kbb, &N, one,
Mptr( A, k, Ajj, Ald,
588 size ), &Ald, zero,
Mptr( buf, 0, kk,
595 TYPE->Cgesd2d( ctxt, BnpD, M, buf, BnpD, p, BprocR );
597 TYPE->Cgesd2d( ctxt, N, BnpD, buf, N, BprocR, p );
598 if( buf ) free( buf );
612 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, BmyprocD, BprocD, BnprocsD );
618 if( BmyprocR == BprocR )
619 TYPE->Cgebs2d( ctxt,
COLUMN, top, ( AisRow ? M : N ), BnpD,
620 Mptr( B, Bii, Bjj, Bld, size ), Bld );
622 TYPE->Cgebr2d( ctxt,
COLUMN, top, ( AisRow ? M : N ), BnpD,
623 Mptr( B, Bii, Bjj, Bld, size ), Bld, BprocR,
629 if( BmyprocR == BprocR )
630 TYPE->Cgebs2d( ctxt,
ROW, top, BnpD, ( AisRow ? M : N ),
631 Mptr( B, Bii, Bjj, Bld, size ), Bld );
633 TYPE->Cgebr2d( ctxt,
ROW, top, BnpD, ( AisRow ? M : N ),
634 Mptr( B, Bii, Bjj, Bld, size ), Bld, BmyprocD,
646 if( !( BisR ) && ( BmyprocR != BprocR ) )
return;
653 else add =
TYPE->Fmmadd;
658 else add =
TYPE->Fmmtadd;
662 kk = ( BisRow ? Bjj : Bii );
663 if( AisRow ) { ktmp = JA + N; kn = JA + Binb1D; }
664 else { ktmp = IA + M; kn = IA + Binb1D; }
666 if( BmyprocD == Broc )
669 add( &M, &Binb1D, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ), &Ald, BETA,
670 Mptr( B, Bii, Bjj, Bld, size ), &Bld );
672 add( &Binb1D, &N, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ), &Ald, BETA,
673 Mptr( B, Bii, Bjj, Bld, size ), &Bld );
678 for( k = kn; k < ktmp; k += BnbD )
680 kbb = ktmp - k; kbb =
MIN( kbb, BnbD );
681 if( BmyprocD == Broc )
683 if( BisRow ) { buf =
Mptr( B, Bii, kk, Bld, size ); }
684 else { buf =
Mptr( B, kk, Bjj, Bld, size ); }
686 add( &M, &kbb, ALPHA,
Mptr( A, Aii, k, Ald, size ), &Ald, BETA,
689 add( &kbb, &N, ALPHA,
Mptr( A, k, Ajj, Ald, size ), &Ald, BETA,