14 #include "../PBpblas.h"
15 #include "../PBtools.h"
16 #include "../PBblacs.h"
17 #include "../PBblas.h"
21 char * ALPHA,
char * A,
int IA,
int JA,
int * DESCA,
22 char * BETA,
char * C,
int IC,
int JC,
int * DESCC )
24 void PB_Cptran(
TYPE, CONJUG, M, N, ALPHA, A, IA, JA, DESCA, BETA,
30 int IA, IC, JA, JC, M, N;
204 char Aroc, Croc, * one, * talpha, * tbeta, * zero;
205 int ACnD, ACnR, Abufld, AcurrocR, Afr, AiD, AiR, AiiD, AiiR,
206 AinbD, AinbR, Ainb1D, Ainb1R, AisR, Akk, Ald, AmyprocD,
207 AmyprocR, AnbD, AnbR, AnpD, AnpR, AnprocsD, AnprocsR, Aoff,
208 ArocD, ArocR, AsrcR, Cbufld, CcurrocR, Cfr, CiD, CiR, CiiD,
209 CiiR, CinbD, CinbR, Cinb1D, Cinb1R, CisR, Ckk, Cld, CmyprocD,
210 CmyprocR, CnbD, CnbR, CnpD, CnpR, CnprocsD, CnprocsR, Coff,
211 CrocD, CrocR, CsrcR, ctxt, col2row, gcdPQ, k, kb, kbb, l,
212 lcmPQ, lcmb, maxp, maxq, mycol, myrow, ncpq, npcol, npq,
213 nprow, nrpq, p, q, size;
219 char * Abuf = NULL, * Cbuf = NULL;
232 col2row = ( ( M <= N ) || ( nprow == 1 ) || ( DESCA[
RSRC_] == -1 ) );
236 AinbR = DESCA[
INB_]; AnbR = DESCA[
NB_]; AsrcR = DESCA[
CSRC_];
237 CinbR = DESCC[
IMB_]; CnbR = DESCC[
MB_]; CsrcR = DESCC[
RSRC_];
242 if( !(
PB_Cspan( M, JA, AinbR, AnbR, AsrcR, npcol ) ) &&
243 !(
PB_Cspan( M, IC, CinbR, CnbR, CsrcR, nprow ) ) )
245 PB_Cpaxpby(
TYPE, CONJUG, N, M, ALPHA, A, IA, JA, DESCA,
COLUMN, BETA,
246 C, IC, JC, DESCC,
ROW );
253 AmyprocD = CmyprocR = myrow; AnprocsD = CnprocsR = nprow;
254 AmyprocR = CmyprocD = mycol; CnprocsD = AnprocsR = npcol;
255 AiD = IA; AiR = JA; Aroc =
CCOLUMN;
256 AinbD = DESCA[
IMB_]; AnbD = DESCA[
MB_]; Ald = DESCA[
LLD_];
257 PB_Cinfog2l( IA, JA, DESCA, AnprocsD, AnprocsR, AmyprocD, AmyprocR,
258 &AiiD, &AiiR, &ArocD, &ArocR );
259 CiD = JC; CiR = IC; Croc =
CROW;
260 CinbD = DESCC[
INB_]; CnbD = DESCC[
NB_]; Cld = DESCC[
LLD_];
261 PB_Cinfog2l( IC, JC, DESCC, CnprocsR, CnprocsD, CmyprocR, CmyprocD,
262 &CiiR, &CiiD, &CrocR, &CrocD );
266 AinbR = DESCA[
IMB_]; AnbR = DESCA[
MB_]; AsrcR = DESCA[
RSRC_];
267 CinbR = DESCC[
INB_]; CnbR = DESCC[
NB_]; CsrcR = DESCC[
CSRC_];
272 if( !(
PB_Cspan( N, IA, AinbR, AnbR, AsrcR, nprow ) ) &&
273 !(
PB_Cspan( N, JC, CinbR, CnbR, CsrcR, npcol ) ) )
275 PB_Cpaxpby(
TYPE, CONJUG, N, M, ALPHA, A, IA, JA, DESCA,
ROW, BETA, C,
283 AmyprocR = CmyprocD = myrow; AnprocsR = CnprocsD = nprow;
284 AmyprocD = CmyprocR = mycol; AnprocsD = CnprocsR = npcol;
286 AiD = JA; AiR = IA; Aroc =
CROW;
287 AinbD = DESCA[
INB_]; AnbD = DESCA[
NB_]; Ald = DESCA[
LLD_];
288 PB_Cinfog2l( IA, JA, DESCA, AnprocsR, AnprocsD, AmyprocR, AmyprocD,
289 &AiiR, &AiiD, &ArocR, &ArocD );
290 CiD = IC; CiR = JC; Croc =
CCOLUMN;
291 CinbD = DESCC[
IMB_]; CnbD = DESCC[
MB_]; Cld = DESCC[
LLD_];
292 PB_Cinfog2l( IC, JC, DESCC, CnprocsD, CnprocsR, CmyprocD, CmyprocR,
293 &CiiD, &CiiR, &CrocD, &CrocR );
300 AnpD =
PB_Cnumroc( ACnD, 0, Ainb1D, AnbD, AmyprocD, ArocD, AnprocsD );
302 AisR = ( ( AsrcR < 0 ) || ( AnprocsR == 1 ) );
305 CnpD =
PB_Cnumroc( ACnD, 0, Cinb1D, CnbD, CmyprocD, CrocD, CnprocsD );
307 CisR = ( ( CsrcR < 0 ) || ( CnprocsR == 1 ) );
309 lcmb =
PB_Clcm( ( maxp = ( CisR ? 1 : CnprocsR ) ) * CnbR,
310 ( maxq = ( AisR ? 1 : AnprocsR ) ) * AnbR );
312 lcmPQ = ( maxp / gcdPQ ) * maxq;
316 for( k = 0; k < gcdPQ; k++ )
320 for( l = 0; l < lcmPQ; l++ )
322 AcurrocR = ( AisR ? -1 :
MModAdd( ArocR, q, AnprocsR ) );
323 CcurrocR = ( CisR ? -1 :
MModAdd( CrocR, p, CnprocsR ) );
325 if( ( AisR || ( AmyprocR == AcurrocR ) ) ||
326 ( CisR || ( CmyprocR == CcurrocR ) ) )
328 Ckk = CiiR; Akk = AiiR;
332 CnpR =
PB_Cnumroc( ACnR, 0, Cinb1R, CnbR, CcurrocR, CrocR,
334 AnpR =
PB_Cnumroc( ACnR, 0, Ainb1R, AnbR, AcurrocR, ArocR,
336 PB_CVMinit( &VM, 0, CnpR, AnpR, Cinb1R, Ainb1R, CnbR, AnbR, p, q,
346 if( npq ) kbb = npq / ( ( npq - 1 ) / kb + 1 );
352 kbb =
MIN( kbb, npq );
361 if( ( Afr = ( ncpq < kbb ) ) != 0 )
367 Abufld =
MAX( 1, AnpD );
368 if( AisR || ( AmyprocR == AcurrocR ) )
372 kbb, AnpD, one,
Mptr( A, AiiD, Akk, Ald,
373 size ), Ald, zero, Abuf, Abufld );
382 if( AisR || ( AmyprocR == AcurrocR ) )
383 Abuf =
Mptr( A, AiiD, Akk+Aoff, Ald, size );
385 PB_Cdescset( DBUFA, ACnD, kbb, Ainb1D, kbb, AnbD, kbb, ArocD,
386 AcurrocR, ctxt, Abufld );
391 if( ( Cfr = ( nrpq < kbb ) ) != 0 )
396 Cbufld = kbb; talpha = one; tbeta = zero;
397 if( CisR || ( CmyprocR == CcurrocR ) )
405 Cbufld = Cld; talpha = ALPHA; tbeta = BETA;
406 if( CisR || ( CmyprocR == CcurrocR ) )
407 Cbuf =
Mptr( C, Ckk+Coff, CiiD, Cld, size );
409 PB_Cdescset( DBUFC, kbb, ACnD, kbb, Cinb1D, kbb, CnbD,
410 CcurrocR, CrocD, ctxt, Cbufld );
415 DBUFA, &Aroc, tbeta, Cbuf, 0, 0, DBUFC, &Croc );
419 if( Afr && ( AisR || ( AmyprocR == AcurrocR ) ) )
420 if( Abuf ) free( Abuf );
424 if( Cfr && ( CisR || ( CmyprocR == CcurrocR ) ) )
427 kbb, CnpD, BETA,
Mptr( C, Ckk, CiiD, Cld,
428 size ), Cld, ALPHA, Cbuf, Cbufld );
429 if( Cbuf ) free( Cbuf );
442 kbb =
MIN( kbb, npq );
451 if( ( Afr = ( ncpq < kbb ) ) != 0 )
458 if( AisR || ( AmyprocR == AcurrocR ) )
462 kbb, AnpD, one,
Mptr( A, Akk, AiiD, Ald,
463 size ), Ald, zero, Abuf, Abufld );
472 if( AisR || ( AmyprocR == AcurrocR ) )
473 Abuf =
Mptr( A, Akk+Aoff, AiiD, Ald, size );
475 PB_Cdescset( DBUFA, kbb, ACnD, kbb, Ainb1D, kbb, AnbD,
476 AcurrocR, ArocD, ctxt, Abufld );
481 if( ( Cfr = ( nrpq < kbb ) ) != 0 )
486 Cbufld =
MAX( 1, CnpD ); talpha = one; tbeta = zero;
487 if( CisR || ( CmyprocR == CcurrocR ) )
492 Cbufld = Cld; talpha = ALPHA; tbeta = BETA;
493 if( CisR || ( CmyprocR == CcurrocR ) )
494 Cbuf =
Mptr( C, CiiD, Ckk+Coff, Cld, size );
496 PB_Cdescset( DBUFC, ACnD, kbb, Cinb1D, kbb, CnbD, kbb, CrocD,
497 CcurrocR, ctxt, Cbufld );
502 DBUFA, &Aroc, tbeta, Cbuf, 0, 0, DBUFC, &Croc );
506 if( Afr && ( AisR || ( AmyprocR == AcurrocR ) ) )
507 if( Abuf ) free( Abuf );
511 if( Cfr && ( CisR || ( CmyprocR == CcurrocR ) ) )
514 kbb, CnpD, BETA,
Mptr( C, CiiD, Ckk, Cld,
515 size ), Cld, ALPHA, Cbuf, Cbufld );
516 if( Cbuf ) free( Cbuf );