1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
|
/* ---------------------------------------------------------------------
*
* -- PBLAS auxiliary routine (version 2.0) --
* University of Tennessee, Knoxville, Oak Ridge National Laboratory,
* and University of California, Berkeley.
* April 1, 1998
*
* ---------------------------------------------------------------------
*/
/*
* Include files
*/
#include "../pblas.h"
#include "../PBpblas.h"
#include "../PBtools.h"
#include "../PBblacs.h"
#include "../PBblas.h"
#ifdef __STDC__
void PB_CpgemmAB( PBTYP_T * TYPE, char * DIRECA, char * DIRECB,
char * TRANSA, char * TRANSB, int M, int N, int K,
char * ALPHA, char * A, int IA, int JA, int * DESCA,
char * B, int IB, int JB, int * DESCB, char * BETA,
char * C, int IC, int JC, int * DESCC )
#else
void PB_CpgemmAB( TYPE, DIRECA, DIRECB, TRANSA, TRANSB, M, N, K, ALPHA,
A, IA, JA, DESCA, B, IB, JB, DESCB, BETA, C, IC, JC,
DESCC )
/*
* .. Scalar Arguments ..
*/
char * DIRECA, * DIRECB, * TRANSA, * TRANSB;
int IA, IB, IC, JA, JB, JC, K, M, N;
char * ALPHA, * BETA;
PBTYP_T * TYPE;
/*
* .. Array Arguments ..
*/
int * DESCA, * DESCB, * DESCC;
char * A, * B, * C;
#endif
{
/*
* Purpose
* =======
*
* PB_CpgemmAB performs one of the matrix-matrix operations
*
* sub( C ) := alpha*op( sub( A ) )*op( sub( B ) ) + beta*sub( C ),
*
* where
*
* sub( C ) denotes C(IC:IC+M-1,JC:JC+N-1), and, op( X ) is one of
* op( X ) = X or op( X ) = X' or op( X ) = conjg( X' ).
*
* Thus, op( sub( A ) ) denotes A(IA:IA+M-1,JA:JA+K-1) if TRANSA = 'N',
* A(IA:IA+K-1,JA:JA+M-1)' if TRANSA = 'T',
* conjg(A(IA:IA+K-1,JA:JA+M-1)') if TRANSA = 'C',
*
* and, op( sub( B ) ) denotes B(IB:IB+K-1,JB:JB+N-1) if TRANSB = 'N',
* B(IB:IB+N-1,JB:JB+K-1)' if TRANSB = 'T',
* conjg(B(IB:IB+N-1,JB:JB+K-1)') if TRANSB = 'C'.
*
* Alpha and beta are scalars. A, B and C are matrices; op( sub( A ) )
* is an m by k submatrix, op( sub( B ) ) is an k by n submatrix and
* sub( C ) is an m by n submatrix.
*
* This is the outer-product algorithm using the logical LCM hybrid
* algorithmic blocking technique. The submatrix operand sub( C ) stays
* in place.
*
* Notes
* =====
*
* A description vector is associated with each 2D block-cyclicly dis-
* tributed matrix. This vector stores the information required to
* establish the mapping between a matrix entry and its corresponding
* process and memory location.
*
* In the following comments, the character _ should be read as
* "of the distributed matrix". Let A be a generic term for any 2D
* block cyclicly distributed matrix. Its description vector is DESC_A:
*
* NOTATION STORED IN EXPLANATION
* ---------------- --------------- ------------------------------------
* DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
* CTXT_A (global) DESCA[ CTXT_ ] The BLACS context handle, indicating
* the NPROW x NPCOL BLACS process grid
* A is distributed over. The context
* itself is global, but the handle
* (the integer value) may vary.
* M_A (global) DESCA[ M_ ] The number of rows in the distribu-
* ted matrix A, M_A >= 0.
* N_A (global) DESCA[ N_ ] The number of columns in the distri-
* buted matrix A, N_A >= 0.
* IMB_A (global) DESCA[ IMB_ ] The number of rows of the upper left
* block of the matrix A, IMB_A > 0.
* INB_A (global) DESCA[ INB_ ] The number of columns of the upper
* left block of the matrix A,
* INB_A > 0.
* MB_A (global) DESCA[ MB_ ] The blocking factor used to distri-
* bute the last M_A-IMB_A rows of A,
* MB_A > 0.
* NB_A (global) DESCA[ NB_ ] The blocking factor used to distri-
* bute the last N_A-INB_A columns of
* A, NB_A > 0.
* RSRC_A (global) DESCA[ RSRC_ ] The process row over which the first
* row of the matrix A is distributed,
* NPROW > RSRC_A >= 0.
* CSRC_A (global) DESCA[ CSRC_ ] The process column over which the
* first column of A is distributed.
* NPCOL > CSRC_A >= 0.
* LLD_A (local) DESCA[ LLD_ ] The leading dimension of the local
* array storing the local blocks of
* the distributed matrix A,
* IF( Lc( 1, N_A ) > 0 )
* LLD_A >= MAX( 1, Lr( 1, M_A ) )
* ELSE
* LLD_A >= 1.
*
* Let K be the number of rows of a matrix A starting at the global in-
* dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
* that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
* receive if these K rows were distributed over NPROW processes. If K
* is the number of columns of a matrix A starting at the global index
* JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number of co-
* lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would receive if
* these K columns were distributed over NPCOL processes.
*
* The values of Lr() and Lc() may be determined via a call to the func-
* tion PB_Cnumroc:
* Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
* Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
*
* Arguments
* =========
*
* TYPE (local input) pointer to a PBTYP_T structure
* On entry, TYPE is a pointer to a structure of type PBTYP_T,
* that contains type information (See pblas.h).
*
* DIRECA (global input) pointer to CHAR
* On entry, DIRECA specifies the direction in which the rows
* or columns of sub( A ) should be looped over as follows:
* DIRECA = 'F' or 'f' forward or increasing,
* DIRECA = 'B' or 'b' backward or decreasing.
*
* DIRECB (global input) pointer to CHAR
* On entry, DIRECB specifies the direction in which the rows
* or columns of sub( B ) should be looped over as follows:
* DIRECB = 'F' or 'f' forward or increasing,
* DIRECB = 'B' or 'b' backward or decreasing.
*
* TRANSA (global input) pointer to CHAR
* On entry, TRANSA specifies the form of op( sub( A ) ) to be
* used in the matrix multiplication as follows:
*
* TRANSA = 'N' or 'n' op( sub( A ) ) = sub( A ),
* TRANSA = 'T' or 't' op( sub( A ) ) = sub( A )',
* TRANSA = 'C' or 'c' op( sub( A ) ) = conjg( sub( A )' ).
*
* TRANSB (global input) pointer to CHAR
* On entry, TRANSB specifies the form of op( sub( B ) ) to be
* used in the matrix multiplication as follows:
*
* TRANSB = 'N' or 'n' op( sub( B ) ) = sub( B ),
* TRANSB = 'T' or 't' op( sub( B ) ) = sub( B )',
* TRANSB = 'C' or 'c' op( sub( B ) ) = conjg( sub( B )' ).
*
* M (global input) INTEGER
* On entry, M specifies the number of rows of the submatrix
* op( sub( A ) ) and of the submatrix sub( C ). M must be at
* least zero.
*
* N (global input) INTEGER
* On entry, N specifies the number of columns of the submatrix
* op( sub( B ) ) and the number of columns of the submatrix
* sub( C ). N must be at least zero.
*
* K (global input) INTEGER
* On entry, K specifies the number of columns of the submatrix
* op( sub( A ) ) and the number of rows of the submatrix
* op( sub( B ) ). K must be at least zero.
*
* ALPHA (global input) pointer to CHAR
* On entry, ALPHA specifies the scalar alpha. When ALPHA is
* supplied as zero then the local entries of the arrays A and
* B corresponding to the entries of the submatrices sub( A )
* and sub( B ) respectively need not be set on input.
*
* A (local input) pointer to CHAR
* On entry, A is an array of dimension (LLD_A, Ka), where Ka is
* at least Lc( 1, JA+K-1 ) when TRANSA = 'N' or 'n', and is at
* least Lc( 1, JA+M-1 ) otherwise. Before entry, this array
* contains the local entries of the matrix A.
*
* IA (global input) INTEGER
* On entry, IA specifies A's global row index, which points to
* the beginning of the submatrix sub( A ).
*
* JA (global input) INTEGER
* On entry, JA specifies A's global column index, which points
* to the beginning of the submatrix sub( A ).
*
* DESCA (global and local input) INTEGER array
* On entry, DESCA is an integer array of dimension DLEN_. This
* is the array descriptor for the matrix A.
*
* B (local input) pointer to CHAR
* On entry, B is an array of dimension (LLD_B, Kb), where Kb is
* at least Lc( 1, JB+N-1 ) when TRANSB = 'N' or 'n', and is at
* least Lc( 1, JB+K-1 ) otherwise. Before entry, this array
* contains the local entries of the matrix B.
*
* IB (global input) INTEGER
* On entry, IB specifies B's global row index, which points to
* the beginning of the submatrix sub( B ).
*
* JB (global input) INTEGER
* On entry, JB specifies B's global column index, which points
* to the beginning of the submatrix sub( B ).
*
* DESCB (global and local input) INTEGER array
* On entry, DESCB is an integer array of dimension DLEN_. This
* is the array descriptor for the matrix B.
*
* BETA (global input) pointer to CHAR
* On entry, BETA specifies the scalar beta. When BETA is
* supplied as zero then the local entries of the array C
* corresponding to the entries of the submatrix sub( C ) need
* not be set on input.
*
* C (local input/local output) pointer to CHAR
* On entry, C is an array of dimension (LLD_C, Kc), where Kc is
* at least Lc( 1, JC+N-1 ). Before entry, this array contains
* the local entries of the matrix C.
* On exit, the entries of this array corresponding to the local
* entries of the submatrix sub( C ) are overwritten by the
* local entries of the m by n updated submatrix.
*
* IC (global input) INTEGER
* On entry, IC specifies C's global row index, which points to
* the beginning of the submatrix sub( C ).
*
* JC (global input) INTEGER
* On entry, JC specifies C's global column index, which points
* to the beginning of the submatrix sub( C ).
*
* DESCC (global and local input) INTEGER array
* On entry, DESCC is an integer array of dimension DLEN_. This
* is the array descriptor for the matrix C.
*
* -- Written on April 1, 1998 by
* Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
* ---------------------------------------------------------------------
*/
/*
* .. Local Scalars ..
*/
char Aroc, Broc, TrA, TrB, * one, * tbeta, * zero;
int ABrocs, Abufld, AcurrocR, Afr, Afwd, AiD, AiR, AiiD, AiiR,
AinbD, AinbR, Ainb1D, Ainb1R, AisR, AkkR, Ald, AmyprocD,
AmyprocR, AnbD, AnbR, AnpD, AnpR, AnprocsD, AnprocsR, Aoff,
ArocD, ArocR, AsrcR, Bbufld, BcurrocR, Bfr, Bfwd, BiD, BiR,
BiiD, BiiR, BinbD, BinbR, Binb1D, Binb1R, BisR, BkkR, Bld,
BmyprocD, BmyprocR, BnbD, BnbR, BnpD, BnpR, BnprocsD,
BnprocsR, Boff, BrocD, BrocR, BsrcR, Ccol, Cii, Cimb1, Cinb1,
Cjj, Cld, Cmb, Cmp, Cnb, Cnq, Crow, WAfr, WAsum, WBfr, WBsum,
Wkbb=0, ctxt, k, kb, kbb, lcmb, maxp, maxpm1, maxq, mycol,
myrow, ncpq, nota, notb, npcol, npq=0, nprow, nrpq, p=0, q=0,
size, tmp;
GEMM_T gemm;
/*
* .. Local Arrays ..
*/
PB_VM_T VM;
int Cd0[DLEN_], DBUFA[DLEN_], DBUFB[DLEN_], WAd0[DLEN_],
WBd0[DLEN_];
char * Abuf = NULL, * Bbuf = NULL, * Cptr = NULL, * WA = NULL,
* WB = NULL;
/* ..
* .. Executable Statements ..
*
*/
/*
* Retrieve process grid information
*/
Cblacs_gridinfo( ( ctxt = DESCC[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
nota = ( ( TrA = Mupcase( TRANSA[0] ) ) == CNOTRAN );
notb = ( ( TrB = Mupcase( TRANSB[0] ) ) == CNOTRAN );
TrA = ( ( TrA == CCOTRAN ) ? CCONJG : CNOCONJG );
TrB = ( ( TrB == CCOTRAN ) ? CCONJG : CNOCONJG );
size = TYPE->size;
/*
* Retrieve local information for sub( A ), sub( B ) and sub( C )
*/
if( nota )
{
AiR = JA; Aroc = CCOLUMN; AnprocsR = npcol;
AinbR = DESCA[INB_]; AnbR = DESCA[NB_ ]; AsrcR = DESCA[CSRC_];
}
else
{
AiR = IA; Aroc = CROW; AnprocsR = nprow;
AinbR = DESCA[IMB_]; AnbR = DESCA[MB_ ]; AsrcR = DESCA[RSRC_];
}
if( notb )
{
BiR = IB; Broc = CROW; BnprocsR = nprow;
BinbR = DESCB[IMB_]; BnbR = DESCB[MB_ ]; BsrcR = DESCB[RSRC_];
}
else
{
BiR = JB; Broc = CCOLUMN; BnprocsR = npcol;
BinbR = DESCB[INB_]; BnbR = DESCB[NB_ ]; BsrcR = DESCB[CSRC_];
}
/*
* Retrieve sub( C )'s local information: Aii, Ajj, Arow, Acol ...
*/
PB_Cdescribe( M, N, IC, JC, DESCC, nprow, npcol, myrow, mycol, &Cii, &Cjj,
&Cld, &Cimb1, &Cinb1, &Cmb, &Cnb, &Crow, &Ccol, Cd0 );
Cmp = PB_Cnumroc( M, 0, Cimb1, Cmb, myrow, Crow, nprow );
Cnq = PB_Cnumroc( N, 0, Cinb1, Cnb, mycol, Ccol, npcol );
/*
* When sub( A ) and sub( B ) do not span more than one process row or column,
* there is no need to pack the data.
*/
if( !( PB_Cspan( K, AiR, AinbR, AnbR, AsrcR, AnprocsR ) ) &&
!( PB_Cspan( K, BiR, BinbR, BnbR, BsrcR, BnprocsR ) ) )
{
PB_CInV( TYPE, &TrA, COLUMN, M, N, Cd0, K, A, IA, JA, DESCA, &Aroc, &WA,
WAd0, &WAfr );
PB_CInV( TYPE, &TrB, ROW, M, N, Cd0, K, B, IB, JB, DESCB, &Broc, &WB,
WBd0, &WBfr );
if( ( Cmp > 0 ) && ( Cnq > 0 ) )
{
/*
* Perform the local update if I own some of sub( C )
*/
TYPE->Fgemm( C2F_CHAR( NOTRAN ), C2F_CHAR( NOTRAN ), &Cmp, &Cnq, &K,
ALPHA, WA, &WAd0[LLD_], WB, &WBd0[LLD_], BETA, Mptr( C,
Cii, Cjj, Cld, size ), &Cld );
}
if( WAfr ) free( WA );
if( WBfr ) free( WB );
return;
}
/*
* sub( A ) and sub( B ) span more than one process row or column.
*/
Afwd = ( Mupcase( DIRECA[0] ) == CFORWARD );
Bfwd = ( Mupcase( DIRECB[0] ) == CFORWARD );
one = TYPE->one; zero = TYPE->zero; tbeta = BETA; gemm = TYPE->Fgemm;
kb = pilaenv_( &ctxt, C2F_CHAR( &TYPE->type ) );
/*
* Compute local information for sub( A ) and sub( B )
*/
if( nota )
{
AiD = IA; AinbD = DESCA[IMB_]; AnbD = DESCA[MB_];
Ald = DESCA[LLD_]; AmyprocD = myrow; AmyprocR = mycol;
AnprocsD = nprow;
PB_Cinfog2l( IA, JA, DESCA, AnprocsD, AnprocsR, AmyprocD, AmyprocR,
&AiiD, &AiiR, &ArocD, &ArocR );
}
else
{
AiD = JA; AinbD = DESCA[INB_]; AnbD = DESCA[NB_];
Ald = DESCA[LLD_]; AmyprocD = mycol; AmyprocR = myrow;
AnprocsD = npcol;
PB_Cinfog2l( IA, JA, DESCA, AnprocsR, AnprocsD, AmyprocR, AmyprocD,
&AiiR, &AiiD, &ArocR, &ArocD );
}
Ainb1D = PB_Cfirstnb( M, AiD, AinbD, AnbD );
AnpD = PB_Cnumroc( M, 0, Ainb1D, AnbD, AmyprocD, ArocD, AnprocsD );
Ainb1R = PB_Cfirstnb( K, AiR, AinbR, AnbR );
AisR = ( ( AsrcR < 0 ) || ( AnprocsR == 1 ) );
if( notb )
{
BiD = JB; BinbD = DESCB[INB_]; BnbD = DESCB[NB_];
Bld = DESCB[LLD_]; BmyprocD = mycol; BmyprocR = myrow;
BnprocsD = npcol;
PB_Cinfog2l( IB, JB, DESCB, BnprocsR, BnprocsD, BmyprocR, BmyprocD,
&BiiR, &BiiD, &BrocR, &BrocD );
}
else
{
BiD = IB; BinbD = DESCB[IMB_]; BnbD = DESCB[MB_];
Bld = DESCB[LLD_]; BmyprocD = myrow; BmyprocR = mycol;
BnprocsD = nprow;
PB_Cinfog2l( IB, JB, DESCB, BnprocsD, BnprocsR, BmyprocD, BmyprocR,
&BiiD, &BiiR, &BrocD, &BrocR );
}
Binb1D = PB_Cfirstnb( N, BiD, BinbD, BnbD );
BnpD = PB_Cnumroc( N, 0, Binb1D, BnbD, BmyprocD, BrocD, BnprocsD );
Binb1R = PB_Cfirstnb( K, BiR, BinbR, BnbR );
BisR = ( ( BsrcR < 0 ) || ( BnprocsR == 1 ) );
/*
* When sub( A ) is not replicated and backward pass on sub( A ), find the
* virtual process q owning the last row or column of sub( A ).
*/
if( !( AisR ) && !( Afwd ) )
{
tmp = PB_Cindxg2p( K - 1, Ainb1R, AnbR, ArocR, ArocR, AnprocsR );
q = MModSub( tmp, ArocR, AnprocsR );
}
/*
* When sub( B ) is not replicated and backward pass on sub( B ), find the
* virtual process p owning the last row or column of sub( B ).
*/
if( !( BisR ) && !( Bfwd ) )
{
tmp = PB_Cindxg2p( K - 1, Binb1R, BnbR, BrocR, BrocR, BnprocsR );
p = MModSub( tmp, BrocR, BnprocsR );
}
if( Cmp > 0 && Cnq > 0 ) Cptr = Mptr( C, Cii, Cjj, Cld, size );
/*
* Allocate work space in process rows and columns spanned by sub( C )
*/
PB_COutV( TYPE, COLUMN, NOINIT, M, N, Cd0, kb, &WA, WAd0, &WAfr, &WAsum );
PB_COutV( TYPE, ROW, NOINIT, M, N, Cd0, kb, &WB, WBd0, &WBfr, &WBsum );
/*
* Loop over the virtual process grid induced by the sub( A ) and sub( B )
*/
lcmb = PB_Clcm( ( maxp = ( BisR ? 1 : BnprocsR ) ) * BnbR,
( maxq = ( AisR ? 1 : AnprocsR ) ) * AnbR );
maxpm1 = maxp - 1;
/*
* Find out process coordinates corresponding to first virtual process (p,q)
*/
AcurrocR = ( AisR ? -1 : MModAdd( ArocR, q, AnprocsR ) );
AkkR = PB_Cg2lrem( AiR, AinbR, AnbR, AcurrocR, AsrcR, AnprocsR );
AnpR = PB_Cnumroc( K, 0, Ainb1R, AnbR, AcurrocR, ArocR, AnprocsR );
BcurrocR = ( BisR ? -1 : MModAdd( BrocR, p, BnprocsR ) );
BkkR = PB_Cg2lrem( BiR, BinbR, BnbR, BcurrocR, BsrcR, BnprocsR );
BnpR = PB_Cnumroc( K, 0, Binb1R, BnbR, BcurrocR, BrocR, BnprocsR );
/*
* Find out how many diagonals this virtual process (p,q) has
*/
PB_CVMinit( &VM, 0, BnpR, AnpR, Binb1R, Ainb1R, BnbR, AnbR, p, q,
maxp, maxq, lcmb );
npq = PB_CVMnpq( &VM );
for( k = 0; k < K; k += kb )
{
kbb = K - k; kbb = MIN( kbb, kb );
while( Wkbb != kbb )
{
/*
* Ensure that the current virtual process (p,q) has something to contribute
* to the replicated buffers WA and WB.
*/
while( npq == 0 )
{
if( ( Bfwd && ( p == maxpm1 ) ) ||
( !( Bfwd ) && ( p == 0 ) ) )
q = ( Afwd ? MModAdd1( q, maxq ) : MModSub1( q, maxq ) );
p = ( Bfwd ? MModAdd1( p, maxp ) : MModSub1( p, maxp ) );
AcurrocR = ( AisR ? -1 : MModAdd( ArocR, q, AnprocsR ) );
AkkR = PB_Cg2lrem( AiR, AinbR, AnbR, AcurrocR, AsrcR,
AnprocsR );
AnpR = PB_Cnumroc( K, 0, Ainb1R, AnbR, AcurrocR, ArocR,
AnprocsR );
BcurrocR = ( BisR ? -1 : MModAdd( BrocR, p, BnprocsR ) );
BkkR = PB_Cg2lrem( BiR, BinbR, BnbR, BcurrocR, BsrcR,
BnprocsR );
BnpR = PB_Cnumroc( K, 0, Binb1R, BnbR, BcurrocR, BrocR,
BnprocsR );
PB_CVMinit( &VM, 0, BnpR, AnpR, Binb1R, Ainb1R, BnbR, AnbR,
p, q, maxp, maxq, lcmb );
npq = PB_CVMnpq( &VM );
}
/*
* Current virtual process (p,q) has something, find out how many rows or
* columns could be used: ABrocs.
*/
if( Wkbb == 0 ) { ABrocs = ( npq < kbb ? npq : kbb ); }
else { ABrocs = kbb - Wkbb; ABrocs = MIN( ABrocs, npq ); }
/*
* Find out how many rows or columns of sub( A ) and sub( B ) are contiguous
*/
PB_CVMcontig( &VM, &nrpq, &ncpq, &Boff, &Aoff );
if( nota )
{
/*
* Compute the descriptor DBUFA for the buffer that will contained the packed
* columns of sub( A ).
*/
if( ( Afr = ( ncpq < ABrocs ) ) != 0 )
{
/*
* If columns of sub( A ) are not contiguous, then allocate the buffer and
* pack the ABrocs columns of sub( A ).
*/
Abufld = MAX( 1, AnpD );
if( AisR || ( AmyprocR == AcurrocR ) )
{
Abuf = PB_Cmalloc( AnpD * ABrocs * size );
PB_CVMpack( TYPE, &VM, COLUMN, &Aroc, PACKING, NOTRAN,
ABrocs, AnpD, one, Mptr( A, AiiD, AkkR, Ald,
size ), Ald, zero, Abuf, Abufld );
}
}
else
{
/*
* Otherwise, re-use sub( A ) directly.
*/
Abufld = Ald;
if( AisR || ( AmyprocR == AcurrocR ) )
Abuf = Mptr( A, AiiD, AkkR + Aoff, Ald, size );
}
PB_Cdescset( DBUFA, M, ABrocs, Ainb1D, ABrocs, AnbD, ABrocs,
ArocD, AcurrocR, ctxt, Abufld );
}
else
{
/*
* Compute the descriptor DBUFA for the buffer that will contained the packed
* rows of sub( A ).
*/
if( ( Afr = ( ncpq < ABrocs ) ) != 0 )
{
/*
* If rows of sub( A ) are not contiguous, then allocate the buffer and
* pack the ABrocs rows of sub( A ).
*/
Abufld = ABrocs;
if( AisR || ( AmyprocR == AcurrocR ) )
{
Abuf = PB_Cmalloc( AnpD * ABrocs * size );
PB_CVMpack( TYPE, &VM, COLUMN, &Aroc, PACKING, NOTRAN,
ABrocs, AnpD, one, Mptr( A, AkkR, AiiD, Ald,
size ), Ald, zero, Abuf, Abufld );
}
}
else
{
/*
* Otherwise, re-use sub( A ) directly.
*/
Abufld = Ald;
if( AisR || ( AmyprocR == AcurrocR ) )
Abuf = Mptr( A, AkkR + Aoff, AiiD, Ald, size );
}
PB_Cdescset( DBUFA, ABrocs, M, ABrocs, Ainb1D, ABrocs, AnbD,
AcurrocR, ArocD, ctxt, Abufld );
}
if( notb )
{
/*
* Compute the descriptor DBUFB for the buffer that will contained the packed
* rows of sub( B ).
*/
if( ( Bfr = ( nrpq < ABrocs ) ) != 0 )
{
/*
* If rows of sub( B ) are not contiguous, then allocate the buffer and
* pack the ABrocs rows of sub( B ).
*/
Bbufld = ABrocs;
if( BisR || ( BmyprocR == BcurrocR ) )
{
Bbuf = PB_Cmalloc( BnpD * ABrocs * size );
PB_CVMpack( TYPE, &VM, ROW, &Broc, PACKING, NOTRAN,
ABrocs, BnpD, one, Mptr( B, BkkR, BiiD, Bld,
size ), Bld, zero, Bbuf, Bbufld );
}
}
else
{
/*
* Otherwise, re-use sub( B ) directly.
*/
Bbufld = Bld;
if( BisR || ( BmyprocR == BcurrocR ) )
Bbuf = Mptr( B, BkkR + Boff, BiiD, Bld, size );
}
PB_Cdescset( DBUFB, ABrocs, N, ABrocs, Binb1D, ABrocs, BnbD,
BcurrocR, BrocD, ctxt, Bbufld );
}
else
{
/*
* Compute the descriptor DBUFB for the buffer that will contained the packed
* columns of sub( B ).
*/
if( ( Bfr = ( nrpq < ABrocs ) ) != 0 )
{
/*
* If columns of sub( B ) are not contiguous, then allocate the buffer and
* pack the ABrocs columns of sub( B ).
*/
Bbufld = MAX( 1, BnpD );
if( BisR || ( BmyprocR == BcurrocR ) )
{
Bbuf = PB_Cmalloc( BnpD * ABrocs * size );
PB_CVMpack( TYPE, &VM, ROW, &Broc, PACKING, NOTRAN,
ABrocs, BnpD, one, Mptr( B, BiiD, BkkR, Bld,
size ), Bld, zero, Bbuf, Bbufld );
}
}
else
{
/*
* Otherwise, re-use sub( B ) directly.
*/
Bbufld = Bld;
if( BisR || ( BmyprocR == BcurrocR ) )
Bbuf = Mptr( B, BiiD, BkkR + Boff, Bld, size );
}
PB_Cdescset( DBUFB, N, ABrocs, Binb1D, ABrocs, BnbD, ABrocs,
BrocD, BcurrocR, ctxt, Bbufld );
}
/*
* Update the local indexes of sub( A ) and sub( B )
*/
PB_CVMupdate( &VM, ABrocs, &BkkR, &AkkR );
/*
* Replicate panels of rows or columns of sub( A ) and sub( B ) over sub( C )
* -> WA, WB
*/
PB_CInV2( TYPE, &TrA, COLUMN, M, N, Cd0, ABrocs, Abuf, 0, 0,
DBUFA, &Aroc, WA, Wkbb, WAd0 );
PB_CInV2( TYPE, &TrB, ROW, M, N, Cd0, ABrocs, Bbuf, 0, 0,
DBUFB, &Broc, WB, Wkbb, WBd0 );
if( Afr & ( AisR || ( AmyprocR == AcurrocR ) ) )
if( Abuf ) free( Abuf );
if( Bfr & ( BisR || ( BmyprocR == BcurrocR ) ) )
if( Bbuf ) free( Bbuf );
/*
* ABrocs rows or columns of sub( A ) and sub( B ) have been replicated,
* update the number of diagonals in this virtual process as well as the
* number of rows or columns of sub( A ) and sub( B ) that are in WA, WB.
*/
npq -= ABrocs;
Wkbb += ABrocs;
}
/*
* Perform local update
*/
if( Cmp > 0 && Cnq > 0 )
{
gemm( C2F_CHAR( NOTRAN ), C2F_CHAR( NOTRAN ), &Cmp, &Cnq, &kbb,
ALPHA, WA, &WAd0[LLD_], WB, &WBd0[LLD_], tbeta, Cptr, &Cld );
tbeta = one;
}
Wkbb = 0;
}
if( WAfr ) free( WA );
if( WBfr ) free( WB );
/*
* End of PB_CpgemmAB
*/
}
|