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_Cpaxpby(
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;
216 char ascope, bscope, * buf = NULL, * one, * top, tran, * zero;
217 int Acol, Aii, AinbD, Ainb1D, AisD, AisR, AisRow, AiD, Ajj, Ald,
218 AmyprocD, AmyprocR, AnbD, AnD, AnR, AnpD, AnprocsD, AnprocsR,
219 AprocD, AprocR, Aroc, Arow, Bcol, Bii, BinbD, Binb1D, BisD,
220 BisR, BisRow, BiD, Bjj, Bld, BmyprocD, BmyprocR, BnbD, BnD,
221 BnR, BnpD, BnprocsD, BnprocsR, BprocD, BprocR, Broc, Brow,
222 BsrcD, OneBlock, OneDgrid, RRorCC, Square, cdst, csrc, ctxt,
223 dst, gcdPQ, k, l, lcmPQ, lcmb, ma, mb, mycol, myrow, na, nb,
224 npcol, npq, nprow, p, q, rdst, rsrc, size, src;
234 if( ( M <= 0 ) || ( N <= 0 ) )
return;
242 if( ( AisRow = (
Mupcase( AROC[0] ) ==
CROW ) ) != 0 )
243 AisD = ( ( DESCA[
CSRC_] >= 0 ) && ( ( AnprocsD = npcol ) > 1 ) );
245 AisD = ( ( DESCA[
RSRC_] >= 0 ) && ( ( AnprocsD = nprow ) > 1 ) );
249 if( ( BisRow = (
Mupcase( BROC[0] ) ==
CROW ) ) != 0 )
250 BisD = ( ( DESCB[
CSRC_] >= 0 ) && ( ( BnprocsD = npcol ) > 1 ) );
252 BisD = ( ( DESCB[
RSRC_] >= 0 ) && ( ( BnprocsD = nprow ) > 1 ) );
261 PB_Cinfog2l( IA, JA, DESCA, nprow, npcol, myrow, mycol, &Aii, &Ajj, &Arow,
265 AinbD = DESCA[
INB_]; AnbD = DESCA[
NB_]; Ald = DESCA[
LLD_];
266 AiD = JA; AnD = N; AnR = M;
267 AprocD = Acol; AmyprocD = mycol;
268 AprocR = Arow; AmyprocR = myrow; AnprocsR = nprow;
269 AisR = ( ( DESCA[
RSRC_ ] == -1 ) || ( AnprocsR == 1 ) );
273 AinbD = DESCA[
IMB_]; AnbD = DESCA[
MB_]; Ald = DESCA[
LLD_];
274 AiD = IA; AnD = M; AnR = N;
275 AprocD = Arow; AmyprocD = myrow;
276 AprocR = Acol; AmyprocR = mycol; AnprocsR = npcol;
277 AisR = ( ( DESCA[
CSRC_ ] == -1 ) || ( AnprocsR == 1 ) );
283 PB_Cinfog2l( IB, JB, DESCB, nprow, npcol, myrow, mycol, &Bii, &Bjj, &Brow,
287 BinbD = DESCB[
INB_ ]; BnbD = DESCB[
NB_ ];
288 BsrcD = DESCB[
CSRC_ ]; Bld = DESCB[
LLD_ ];
290 if( AisRow ) { BnD = N; BnR = M; }
else { BnD = M; BnR = N; }
291 BprocD = Bcol; BmyprocD = mycol;
292 BprocR = Brow; BmyprocR = myrow; BnprocsR = nprow;
293 BisR = ( ( DESCB[
RSRC_ ] == -1 ) || ( BnprocsR == 1 ) );
297 BinbD = DESCB[
IMB_ ]; BnbD = DESCB[
MB_ ];
298 BsrcD = DESCB[
RSRC_ ]; Bld = DESCB[
LLD_ ];
300 if( AisRow ) { BnD = N; BnR = M; }
else { BnD = M; BnR = N; }
301 BprocD = Brow; BmyprocD = myrow;
302 BprocR = Bcol; BmyprocR = mycol; BnprocsR = npcol;
303 BisR = ( ( DESCB[
CSRC_ ] == -1 ) || ( BnprocsR == 1 ) );
309 RRorCC = ( ( AisRow && BisRow ) || ( !( AisRow ) && !( BisRow ) ) );
313 OneDgrid = ( ( AnprocsD == 1 ) && ( BnprocsD == 1 ) );
314 OneBlock = ( ( Ainb1D >= AnD ) && ( Binb1D >= BnD ) );
318 Square = ( ( Ainb1D == Binb1D ) && ( AnbD == BnbD ) &&
319 ( AnprocsD == BnprocsD ) );
338 if( ( OneDgrid || OneBlock || Square ) && ( AprocD == BprocD ) )
352 BprocR =
MModAdd1( AprocR, AnprocsR );
370 if( ( AmyprocR != AprocR ) && ( BmyprocR != BprocR ) )
389 if( ( OneDgrid || OneBlock || Square ) && ( AprocD == BprocD ) )
406 AprocR =
MModAdd1( BprocR, BnprocsR );
429 if( ( OneDgrid || OneBlock || Square ) && ( AprocD == BprocD ) )
436 if( ( AmyprocR != AprocR ) && ( BmyprocR != BprocR ) )
return;
444 AprocR =
MModAdd1( BprocR, BnprocsR );
454 if( ( OneDgrid || OneBlock || Square ) &&
455 ( AmyprocR != AprocR ) && ( BmyprocR != BprocR ) )
return;
470 if( ( ( RRorCC && ( AprocD == BprocD ) &&
471 ( AisR || BisR || ( AprocR == BprocR ) ) ) ||
472 ( !( RRorCC ) && ( BisR || ( AprocD == BprocR ) ) &&
473 ( AisR || ( AprocR == BprocD ) ) ) ) &&
474 ( OneDgrid || OneBlock || ( RRorCC && Square ) ) )
476 if( ( !AisR && ( AmyprocR == AprocR ) ) ||
477 ( AisR && ( BisR || BmyprocR == BprocR ) ) )
479 AnpD =
PB_Cnumroc( AnD, 0, Ainb1D, AnbD, AmyprocD, AprocD,
481 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, BmyprocD, BprocD,
483 if( ( AnpD > 0 ) && ( BnpD > 0 ) )
491 else add =
TYPE->Fmmadd;
496 else add =
TYPE->Fmmtadd;
502 add( &AnR, &AnpD, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ), &Ald,
503 BETA,
Mptr( B, Bii, Bjj, Bld, size ), &Bld );
505 add( &AnpD, &AnR, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ), &Ald,
506 BETA,
Mptr( B, Bii, Bjj, Bld, size ), &Bld );
509 if( RRorCC && AisR && BisR )
return;
511 else if( ( RRorCC && OneDgrid ) || OneBlock || Square )
522 else add =
TYPE->Fmmadd;
527 else add =
TYPE->Fmmtadd;
530 if( ( AisR && BisR ) || ( AmyprocR == AprocR ) )
533 AnpD =
PB_Cnumroc( AnD, 0, Ainb1D, AnbD, AmyprocD, AprocD,
537 dst = BprocD +
MModSub( AmyprocD, AprocD, AnprocsD );
538 dst =
MPosMod( dst, BnprocsD );
539 if( AisRow ) { ma = AnR; na = AnpD; }
540 else { ma = AnpD; na = AnR; }
541 if( !( AisR && BisR ) )
543 if( BisRow ) { rdst = BprocR; cdst = dst; }
544 else { rdst = dst; cdst = BprocR; }
550 if( !AisRow ) { rdst = AmyprocR; }
551 else { rdst =
MModAdd1( BmyprocR, BnprocsR ); }
557 if( AisRow ) { cdst = AmyprocR; }
558 else { cdst =
MModAdd1( BmyprocR, BnprocsR ); }
561 if( ( myrow == rdst ) && ( mycol == cdst ) )
563 add( &ma, &na, ALPHA,
Mptr( A, Aii, Ajj, Ald, size ), &Ald,
564 BETA,
Mptr( B, Bii, Bjj, Bld, size ), &Bld );
568 TYPE->Cgesd2d( ctxt, ma, na,
Mptr( A, Aii, Ajj, Ald, size ),
574 if( ( AisR && BisR ) || ( BmyprocR == BprocR ) )
576 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, BmyprocD, BprocD,
580 src = AprocD +
MModSub( BmyprocD, BprocD, BnprocsD );
581 src =
MPosMod( src, AnprocsD );
582 if( AisRow ) { ma = BnR; na = BnpD; }
583 else { ma = BnpD; na = BnR; }
584 if( !( AisR && BisR ) )
586 if( AisRow ) { rsrc = AprocR; csrc = src; }
587 else { rsrc = src; csrc = AprocR; }
593 if( !BisRow ) { rsrc = BmyprocR; }
594 else { rsrc =
MModSub1( AmyprocR, AnprocsR ); }
600 if( BisRow ) { csrc = BmyprocR; }
601 else { csrc =
MModSub1( AmyprocR, AnprocsR ); }
604 if( ( myrow != rsrc ) || ( mycol != csrc ) )
607 TYPE->Cgerv2d( ctxt, ma, na, buf, ma, rsrc, csrc );
608 add( &ma, &na, ALPHA, buf, &ma, BETA,
Mptr( B, Bii, Bjj, Bld,
610 if( buf ) free( buf );
614 if( AisR && BisR )
return;
632 if( AisRow ) { ascope =
CCOLUMN; ma = AnR; }
633 else { ascope =
CROW; na = AnR; }
635 lcmb =
PB_Clcm( AnprocsD * AnbD, BnprocsD * BnbD );
637 gcdPQ =
PB_Cgcd( AnprocsD, BnprocsD );
638 lcmPQ = ( AnprocsD / gcdPQ ) * BnprocsD;
640 for( k = 0; k < gcdPQ; k++ )
644 for( l = 0; l < lcmPQ; l++ )
646 Aroc =
MModAdd( AprocD, p, AnprocsD );
647 Broc =
MModAdd( BprocD, q, BnprocsD );
649 if( ( AmyprocD == Aroc ) || ( BmyprocD == Broc ) )
651 AnpD =
PB_Cnumroc( AnD, 0, Ainb1D, AnbD, Aroc, AprocD,
653 BnpD =
PB_Cnumroc( BnD, 0, Binb1D, BnbD, Broc, BprocD,
655 PB_CVMinit( &VM, 0, AnpD, BnpD, Ainb1D, Binb1D, AnbD, BnbD,
656 p, q, AnprocsD, BnprocsD, lcmb );
659 if( ( RRorCC && ( Aroc == Broc ) &&
660 ( AisR || ( AprocR == BprocR ) ) ) ||
661 ( !( RRorCC ) && ( Aroc == BprocR ) &&
662 ( AisR || ( AprocR == Broc ) ) ) )
664 if( ( BmyprocD == Broc ) && ( BmyprocR == BprocR ) )
667 npq, AnR, ALPHA,
Mptr( A, Aii, Ajj, Ald,
668 size ), Ald, BETA,
Mptr( B, Bii, Bjj, Bld,
674 if( ( AmyprocR == AprocR ) && ( AmyprocD == Aroc ) )
676 if( AisRow ) { na = npq; }
else { ma = npq; }
679 npq, AnR, one,
Mptr( A, Aii, Ajj, Ald,
680 size ), Ald, zero, buf, ma );
681 if( BisRow ) { rdst = BprocR; cdst = Broc; }
682 else { rdst = Broc; cdst = BprocR; }
683 TYPE->Cgesd2d( ctxt, ma, na, buf, ma, rdst, cdst );
684 if( buf ) free ( buf );
686 if( ( BmyprocR == BprocR ) && ( BmyprocD == Broc ) )
689 { na = npq; rsrc = AprocR; csrc = Aroc; }
691 { ma = npq; rsrc = Aroc; csrc = AprocR; }
693 TYPE->Cgerv2d( ctxt, ma, na, buf, ma, rsrc, csrc );
695 &tran, npq, AnR, BETA,
Mptr( B, Bii, Bjj,
696 Bld, size ), Bld, ALPHA, buf, ma );
697 if( buf ) free ( buf );
705 if( AisR ) AprocR =
MModAdd1( AprocR, AnprocsR );
714 BnpD =
PB_Cnumroc( BnD, BiD, BinbD, BnbD, BmyprocD, BsrcD, BnprocsD );
719 bscope =
CCOLUMN; mb = BnR; nb = BnpD;
720 rsrc = BprocR; csrc = BmyprocD;
724 bscope =
CROW; mb = BnpD; nb = BnR;
725 rsrc = BmyprocD; csrc = BprocR;
728 if( BmyprocR == BprocR )
730 TYPE->Cgebs2d( ctxt, &bscope, top, mb, nb,
Mptr( B, Bii, Bjj,
735 TYPE->Cgebr2d( ctxt, &bscope, top, mb, nb,
Mptr( B, Bii, Bjj,
736 Bld, size ), Bld, rsrc, csrc );
741 else if( !( AisD ) && BisD )
746 PB_CpaxpbyND(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA, AROC, BETA, B,
747 IB, JB, DESCB, BROC );
749 else if( AisD && !( BisD ) )
754 PB_CpaxpbyDN(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA, AROC, BETA, B,
755 IB, JB, DESCB, BROC );
762 PB_CpaxpbyNN(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA, AROC, BETA, B,
763 IB, JB, DESCB, BROC );