14 #include "../PBpblas.h"
15 #include "../PBtools.h"
16 #include "../PBblacs.h"
17 #include "../PBblas.h"
21 char * CONJUG,
int M,
int N,
char * ALPHA,
char * A,
22 int IA,
int JA,
int * DESCA,
char * BETA,
char * C,
23 int IC,
int JC,
int * DESCC )
25 void PB_Cpgeadd(
TYPE, DIRECA, DIRECC, CONJUG, M, N, ALPHA, A, IA, JA,
26 DESCA, BETA, C, IC, JC, DESCC )
30 char * CONJUG, * DIRECA, * DIRECC;
31 int IA, IC, JA, JC, M, N;
216 char ACroc, * one, * talpha, * tbeta, * zero;
217 int ACmyprocD, ACmyprocR, ACnD, ACnR, ACnprocsD, ACnprocsR,
218 Abufld, AcurrocR, Afr, Afwd, AiD, AiR, AiiD, AiiR, AinbD,
219 AinbR, Ainb1D, Ainb1R, AisR, Akk, Ald, AnbD, AnbR, AnpD,
220 AnpR, Aoff, ArocD, ArocR, AsrcR, Cbufld, CcurrocR, Cfr,
221 Cfwd, CiD, CiR, CiiD, CiiR, CinbD, CinbR, Cinb1D, Cinb1R,
222 CisR, Ckk, Cld, CnbD, CnbR, CnpD, CnpR, Coff, CrocD, CrocR,
223 CsrcR, ctxt, k, kb, kbb, lcmb, maxp, maxpm1, maxpq, maxq,
224 mycol, myrow, npcol, npq, nprow, ncpq, nrpq, p=0, q=0,
231 char * Abuf = NULL, * Cbuf = NULL;
244 row2row = ( ( M <= N ) || ( npcol == 1 ) || ( DESCA[
CSRC_] == -1 ) );
248 AinbR = DESCA[
IMB_]; AnbR = DESCA[
MB_]; AsrcR = DESCA[
RSRC_];
249 CinbR = DESCC[
IMB_]; CnbR = DESCC[
MB_]; CsrcR = DESCC[
RSRC_];
254 if( !(
PB_Cspan( M, IA, AinbR, AnbR, AsrcR, nprow ) ) &&
255 !(
PB_Cspan( M, IC, CinbR, CnbR, CsrcR, nprow ) ) )
257 PB_Cpaxpby(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA,
ROW, BETA,
258 C, IC, JC, DESCC,
ROW );
265 ACmyprocR = myrow; ACnprocsR = nprow;
266 ACmyprocD = mycol; ACnprocsD = npcol; ACroc =
CROW;
268 AinbD = DESCA[
INB_]; AnbD = DESCA[
NB_]; Ald = DESCA[
LLD_];
269 PB_Cinfog2l( IA, JA, DESCA, ACnprocsR, ACnprocsD, ACmyprocR, ACmyprocD,
270 &AiiR, &AiiD, &ArocR, &ArocD );
272 CinbD = DESCC[
INB_]; CnbD = DESCC[
NB_]; Cld = DESCC[
LLD_];
273 PB_Cinfog2l( IC, JC, DESCC, ACnprocsR, ACnprocsD, ACmyprocR, ACmyprocD,
274 &CiiR, &CiiD, &CrocR, &CrocD );
278 AinbR = DESCA[
INB_]; AnbR = DESCA[
NB_]; AsrcR = DESCA[
CSRC_];
279 CinbR = DESCC[
INB_]; CnbR = DESCC[
NB_]; CsrcR = DESCC[
CSRC_];
284 if( !(
PB_Cspan( N, JA, AinbR, AnbR, AsrcR, npcol ) ) &&
285 !(
PB_Cspan( N, JC, CinbR, CnbR, CsrcR, npcol ) ) )
287 PB_Cpaxpby(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA,
COLUMN, BETA,
288 C, IC, JC, DESCC,
COLUMN );
295 ACmyprocR = mycol; ACnprocsR = npcol;
296 ACmyprocD = myrow; ACnprocsD = nprow; ACroc =
CCOLUMN;
298 AinbD = DESCA[
IMB_]; AnbD = DESCA[
MB_]; Ald = DESCA[
LLD_];
299 PB_Cinfog2l( IA, JA, DESCA, ACnprocsD, ACnprocsR, ACmyprocD, ACmyprocR,
300 &AiiD, &AiiR, &ArocD, &ArocR );
302 CinbD = DESCC[
IMB_]; CnbD = DESCC[
MB_]; Cld = DESCC[
LLD_];
303 PB_Cinfog2l( IC, JC, DESCC, ACnprocsD, ACnprocsR, ACmyprocD, ACmyprocR,
304 &CiiD, &CiiR, &CrocD, &CrocR );
311 AnpD =
PB_Cnumroc( ACnD, 0, Ainb1D, AnbD, ACmyprocD, ArocD, ACnprocsD );
313 AisR = ( ( AsrcR < 0 ) || ( ACnprocsR == 1 ) );
316 CnpD =
PB_Cnumroc( ACnD, 0, Cinb1D, CnbD, ACmyprocD, CrocD, ACnprocsD );
318 CisR = ( ( CsrcR < 0 ) || ( ACnprocsR == 1 ) );
320 lcmb =
PB_Clcm( ( maxp = ( CisR ? 1 : ACnprocsR ) ) * CnbR,
321 ( maxq = ( AisR ? 1 : ACnprocsR ) ) * AnbR );
329 if( !( AisR ) && !( Afwd ) )
331 tmp =
PB_Cindxg2p( ACnR-1, Ainb1R, AnbR, ArocR, ArocR, ACnprocsR );
332 q =
MModSub( tmp, ArocR, ACnprocsR );
338 if( !( CisR ) && !( Cfwd ) )
340 tmp =
PB_Cindxg2p( ACnR-1, Cinb1R, CnbR, CrocR, CrocR, ACnprocsR );
341 p =
MModSub( tmp, CrocR, ACnprocsR );
346 maxpm1 = maxp - 1; maxpq = maxp * maxq;
348 for( k = 0; k < maxpq; k++ )
350 AcurrocR = ( AisR ? -1 :
MModAdd( ArocR, q, ACnprocsR ) );
351 CcurrocR = ( CisR ? -1 :
MModAdd( CrocR, p, ACnprocsR ) );
353 if( ( AisR || ( ACmyprocR == AcurrocR ) ) ||
354 ( CisR || ( ACmyprocR == CcurrocR ) ) )
356 Ckk = CiiR; Akk = AiiR;
360 AnpR =
PB_Cnumroc( ACnR, 0, Ainb1R, AnbR, AcurrocR, ArocR, ACnprocsR );
361 CnpR =
PB_Cnumroc( ACnR, 0, Cinb1R, CnbR, CcurrocR, CrocR, ACnprocsR );
362 PB_CVMinit( &VM, 0, CnpR, AnpR, Cinb1R, Ainb1R, CnbR, AnbR, p, q,
372 if( npq ) kbb = npq / ( ( npq - 1 ) / kb + 1 );
378 kbb =
MIN( kbb, npq );
387 if( ( Afr = ( ncpq < kbb ) ) != 0 )
394 if( AisR || ( ACmyprocR == AcurrocR ) )
398 kbb, AnpD, one,
Mptr( A, Akk, AiiD, Ald,
399 size ), Ald, zero, Abuf, Abufld );
408 if( AisR || ( ACmyprocR == AcurrocR ) )
409 Abuf =
Mptr( A, Akk+Aoff, AiiD, Ald, size );
411 PB_Cdescset( DBUFA, kbb, ACnD, kbb, Ainb1D, kbb, AnbD, AcurrocR,
412 ArocD, ctxt, Abufld );
417 if( ( Cfr = ( nrpq < kbb ) ) != 0 )
422 Cbufld = kbb; talpha = one; tbeta = zero;
423 if( CisR || ( ACmyprocR == CcurrocR ) )
431 Cbufld = Cld; talpha = ALPHA; tbeta = BETA;
432 if( CisR || ( ACmyprocR == CcurrocR ) )
433 Cbuf =
Mptr( C, Ckk+Coff, CiiD, Cld, size );
435 PB_Cdescset( DBUFC, kbb, ACnD, kbb, Cinb1D, kbb, CnbD, CcurrocR,
436 CrocD, ctxt, Cbufld );
441 &ACroc, tbeta, Cbuf, 0, 0, DBUFC, &ACroc );
445 if( Afr && ( AisR || ( ACmyprocR == AcurrocR ) ) )
446 if( Abuf ) free( Abuf );
450 if( Cfr && ( CisR || ( ACmyprocR == CcurrocR ) ) )
453 CnpD, BETA,
Mptr( C, Ckk, CiiD, Cld, size ), Cld,
454 ALPHA, Cbuf, Cbufld );
455 if( Cbuf ) free( Cbuf );
468 kbb =
MIN( kbb, npq );
477 if( ( Afr = ( ncpq < kbb ) ) != 0 )
483 Abufld =
MAX( 1, AnpD );
484 if( AisR || ( ACmyprocR == AcurrocR ) )
488 kbb, AnpD, one,
Mptr( A, AiiD, Akk, Ald,
489 size ), Ald, zero, Abuf, Abufld );
498 if( AisR || ( ACmyprocR == AcurrocR ) )
499 Abuf =
Mptr( A, AiiD, Akk+Aoff, Ald, size );
501 PB_Cdescset( DBUFA, ACnD, kbb, Ainb1D, kbb, AnbD, kbb, ArocD,
502 AcurrocR, ctxt, Abufld );
507 if( ( Cfr = ( nrpq < kbb ) ) != 0 )
512 Cbufld =
MAX( 1, CnpD ); talpha = one; tbeta = zero;
513 if( CisR || ( ACmyprocR == CcurrocR ) )
518 Cbufld = Cld; talpha = ALPHA; tbeta = BETA;
519 if( CisR || ( ACmyprocR == CcurrocR ) )
520 Cbuf =
Mptr( C, CiiD, Ckk+Coff, Cld, size );
522 PB_Cdescset( DBUFC, ACnD, kbb, Cinb1D, kbb, CnbD, kbb, CrocD,
523 CcurrocR, ctxt, Cbufld );
528 &ACroc, tbeta, Cbuf, 0, 0, DBUFC, &ACroc );
532 if( Afr && ( AisR || ( ACmyprocR == AcurrocR ) ) )
533 if( Abuf ) free( Abuf );
537 if( Cfr && ( CisR || ( ACmyprocR == CcurrocR ) ) )
540 CnpD, BETA,
Mptr( C, CiiD, Ckk, Cld, size ), Cld,
541 ALPHA, Cbuf, Cbufld );
542 if( Cbuf ) free( Cbuf );
555 if( ( Cfwd && ( p == maxpm1 ) ) || ( !( Cfwd ) && ( p == 0 ) ) )