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 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
|
/* ---------------------------------------------------------------------
*
* -- 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__
int PB_CVMpack( PBTYP_T * TYPE, PB_VM_T * VM, char * VROCS, char * ROCS,
char * UNPA, char * TRANS, int MN, int K,
char * ALPHA, char * A, int LDA,
char * BETA, char * B, int LDB )
#else
int PB_CVMpack( TYPE, VM, VROCS, ROCS, UNPA, TRANS, MN, K, ALPHA, A,
LDA, BETA, B, LDB )
/*
* .. Scalar Arguments ..
*/
int K, LDA, LDB, MN;
char * ALPHA, * BETA;
/*
* .. Array Arguments ..
*/
char * VROCS, * ROCS, * UNPA, * TRANS;
PBTYP_T * TYPE;
PB_VM_T * VM;
char * A, * B;
#endif
{
/*
* Purpose
* =======
*
* PB_CVMpack packs a one-dimensional distributed array A into B, or
* unpacks an array B into a one-dimensional distributed array A. This
* operation is triggered by a virtual distributed array.
*
* 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).
*
* VM (local input) pointer to a VM structure
* On entry, VM is a pointer to a structure of type PB_VM_T,
* that contains the virtual matrix information (see pblas.h).
*
* VROCS (local input) pointer to CHAR
* On entry, VROCS specifies if the rows or columns of the vir-
* tual distributed array grid should be used for the packing or
* unpacking operation as follows:
* VROCS = 'R' or 'r', the rows should be used,
* VROCS = 'C' or 'c', the columns should be used.
*
* ROCS (local input) pointer to CHAR
* On entry, ROCS specifies if rows or columns should be used
* packed or unpacked as follows:
* ROCS = 'R' or 'r', rows should be (un)packed,
* ROCS = 'C' or 'c', columns should be (un)packed.
*
* UNPA (local input) pointer to CHAR
* On entry, UNPA specifies if the data should be packed or un-
* packed as follows:
* UNPA = 'P' or 'p', packing,
* UNPA = 'U' or 'u', unpacking.
*
* TRANS (local input) pointer to CHAR
* On entry, TRANS specifies if conjugation, transposition or
* conjugate transposition should occur during the (un)packing
* operation as follows:
* TRANS = 'N' or 'n', natural (un)packing,
* TRANS = 'Z' or 'z', conjugated (un)packing,
* TRANS = 'T' or 't', transposed (un)packing,
* TRANS = 'C' or 'c', conjugate transposed (un)packing.
*
* MN (local input) INTEGER
* On entry, MN specifies the length of the distributed dimen-
* sion to be (un)packed. MN must be at least zero.
*
* K (local input) INTEGER
* On entry, K specifies the length of the non-distributed di-
* mension to be (un)packed. K must be at least zero.
*
* ALPHA (local input) pointer to CHAR
* On entry, ALPHA specifies the scalar alpha.
*
* A (local input/local output) pointer to CHAR
* On entry, A points to an array of dimension (LDA, Ka), where
* Ka is K when ROCS is 'R' or 'r' and when ROCS is 'C' or 'c',
* Ka is IMBLOC+(MBLKS-2)*MB+LMB when VROCS is 'R' or 'r' and
* when VROCS is 'C' or 'c', Ka is INBLOC+(NBLKS-2)*NB+LNB. This
* array contains unpacked data.
*
* LDA (local input) INTEGER
* On entry, LDA specifies the leading dimension of the array A.
* LDA must be at least MAX( 1, K ) when ROCS = 'C' or 'c' and
* MAX( 1, IMBLOC+(MBLKS-2)*MB+LMB ) when ROCS is 'R' or 'r' and
* VROCS is 'R' or 'r', and MAX( 1, INBLOC+(NBLKS-2)*NB+LNB )
* when ROCS is 'R' or 'r' and VROCS is 'C' or 'c'.
*
* BETA (local input) pointer to CHAR
* On entry, BETA specifies the scalar beta.
*
* B (local input/local output) pointer to CHAR
* On entry, B points to an array of dimension (LDB,*). When
* ROCS is 'C' or 'c', and TRANS is 'N', 'n', 'Z' or 'Z', B
* points to an K by MN array. When TRANS is 'T', 't', 'C' or
* 'c', B points to an MN by K array. When ROCS is 'R' or 'r',
* and TRANS is 'T', 't', 'C' or 'c', B points to an K by MN ar-
* ray. When TRANS is 'N', 'n', 'Z' or 'z', B points to an MN by
* K array. This array contains the packed data.
*
* LDB (local input) INTEGER
* On entry, LDB specifies the leading dimension of the array B.
*
* -- Written on April 1, 1998 by
* Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
* ---------------------------------------------------------------------
*/
/*
* .. Local Scalars ..
*/
int GoEast, GoSouth, ilow, imbloc, inbloc, inca, incb, iupp, kb,
lcmt, lcmt00, lmbloc, lnbloc, low, mb, mblkd, mblks, mbloc,
* m, * n, nb, nblkd, nblks, nbloc, notran, npcol, npq=0,
nprow, pmb, qnb, rows, size, tmp1, tmp2, upp;
char * aptrd;
MMADD_T add;
/* ..
* .. Executable Statements ..
*
*/
mblks = VM->mblks; nblks = VM->nblks;
/*
* Quick return if I don't own any blocks.
*/
if( ( mblks == 0 ) || ( nblks == 0 ) ) return( 0 );
/*
* Retrieve the contents of VM structure fields
*/
lcmt00 = VM->lcmt00;
imbloc = VM->imbloc; mb = VM->mb; lmbloc = VM->lmbloc; upp = VM->upp;
iupp = VM->iupp; nprow = VM->nprow;
inbloc = VM->inbloc; nb = VM->nb; lnbloc = VM->lnbloc; low = VM->low;
ilow = VM->ilow; npcol = VM->npcol;
if( Mupcase( UNPA[0] ) == CPACKING )
{
/*
* B is the target packed buffer, A is the distributed source
*/
if( Mupcase( TRANS[0] ) == CNOTRAN )
{
/*
* Add A to B
*/
notran = 1; add = TYPE->Fmmadd;
}
else if( Mupcase( TRANS[0] ) == CCONJG )
{
/*
* Add the conjugate of A to B
*/
notran = 1; add = TYPE->Fmmcadd;
}
else if( Mupcase( TRANS[0] ) == CTRAN )
{
/*
* Add the tranpose of A to B
*/
notran = 0; add = TYPE->Fmmtadd;
}
else
{
/*
* Add the conjugate tranpose of A to B
*/
notran = 0; add = TYPE->Fmmtcadd;
}
}
else
{
/*
* B is the source packed buffer, A is the distributed target
*/
if( Mupcase( TRANS[0] ) == CNOTRAN )
{
/*
* Add B to A
*/
notran = 1; add = TYPE->Fmmdda;
}
else if( Mupcase( TRANS[0] ) == CCONJG )
{
/*
* Add the conjugate of B to A
*/
notran = 1; add = TYPE->Fmmddac;
}
else if( Mupcase( TRANS[0] ) == CTRAN )
{
/*
* Add the tranpose of B to A
*/
notran = 0; add = TYPE->Fmmddat;
}
else
{
/*
* Add the conjugate tranpose of B to A
*/
notran = 0; add = TYPE->Fmmddact;
}
}
size = TYPE->size;
rows = ( Mupcase( ROCS[0] ) == CROW );
if( Mupcase( VROCS[0] ) == CROW )
{
/*
* (un)packing using rows of virtual matrix
*/
if( rows )
{
/*
* (un)packing rows of mn by k array A.
*/
inca = size;
incb = ( notran ? size : LDB * size );
m = &tmp2;
n = &K;
}
else
{
/*
* (un)packing columns of k by mn array A
*/
inca = LDA * size;
incb = ( notran ? LDB * size : size );
m = &K;
n = &tmp2;
}
kb = MN;
/*
* From the (un)packing point of view the only valuable shortcut is when the
* virtual grid and the blocks are square, and the offset is zero or the grid
* is 1x1.
*/
if( ( ( lcmt00 == 0 ) && ( VM->imb1 == VM->inb1 ) && ( mb == nb ) &&
( nprow == npcol ) ) || ( ( nprow == 1 ) && ( npcol == 1 ) ) )
{
if( VM->prow == VM->pcol )
{
npq = ( ( mblks < 2 ) ? imbloc :
imbloc + ( mblks - 2 ) * mb + lmbloc );
npq = MIN( npq, kb );
if( rows ) add( &npq, &K, ALPHA, A, &LDA, BETA, B, &LDB );
else add( &K, &npq, ALPHA, A, &LDA, BETA, B, &LDB );
}
return( npq );
}
pmb = nprow * mb;
qnb = npcol * nb;
/*
* Handle separately the first row and/or column of the LCM table. Update the
* LCM value of the curent block lcmt00, as well as the number of rows and
* columns mblks and nblks remaining in the LCM table.
*/
GoSouth = ( lcmt00 > iupp );
GoEast = ( lcmt00 < ilow );
if( !( GoSouth ) && !( GoEast ) )
{
/*
* The upper left block owns diagonal entries lcmt00 >= ilow && lcmt00 <= iupp
*/
if( lcmt00 >= 0 )
{
tmp1 = imbloc - lcmt00; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, inbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A+lcmt00*inca, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = inbloc + lcmt00; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, imbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
B += tmp2 * incb;
/*
* Decide whether one should go south or east in the table: Go east if
* the block below the current one only owns lower entries. If this block,
* however, owns diagonals, then go south.
*/
GoSouth = !( GoEast = ( ( lcmt00 - ( iupp - upp + pmb ) ) < ilow ) );
}
if( GoSouth )
{
/*
* Go one step south in the LCM table. Adjust the current LCM value as well as
* the pointer to A. The pointer to B remains unchanged.
*/
lcmt00 -= iupp - upp + pmb; mblks--; A += imbloc * inca;
/*
* While there are blocks remaining that own upper entries, keep going south.
* Adjust the current LCM value as well as the pointer to A accordingly.
*/
while( mblks && ( lcmt00 > upp ) )
{ lcmt00 -= pmb; mblks--; A += mb * inca; }
/*
* Return if no more row in the LCM table.
*/
if( mblks <= 0 ) return( npq );
/*
* lcmt00 <= upp. The current block owns either diagonals or lower entries.
* Save the current position in the LCM table. After this column has been
* completely taken care of, re-start from this row and the next column of
* the LCM table.
*/
lcmt = lcmt00; mblkd = mblks; aptrd = A;
while( mblkd && ( lcmt >= ilow ) )
{
/*
* A block owning diagonals lcmt00 >= ilow && lcmt00 <= upp has been found.
*/
mbloc = ( ( mblkd == 1 ) ? lmbloc : mb );
if( lcmt >= 0 )
{
tmp1 = mbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, inbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd+lcmt*inca, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = inbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, mbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going south until there are no more blocks owning diagonals
*/
lcmt -= pmb; mblkd--; aptrd += mbloc * inca; B += tmp2 * incb;
}
/*
* I am done with the first column of the LCM table. Go to the next column.
*/
lcmt00 += low - ilow + qnb; nblks--;
}
else if( GoEast )
{
/*
* Go one step east in the LCM table. Adjust the current LCM value as
* well as the pointer to B. The pointer to A remains unchanged.
*/
lcmt00 += low - ilow + qnb; nblks--;
/*
* While there are blocks remaining that own lower entries, keep going east
* in the LCM table. Adjust the current LCM value as well as the pointer to
* B accordingly.
*/
while( nblks && ( lcmt00 < low ) ) { lcmt00 += qnb; nblks--; }
/*
* Return if no more column in the LCM table.
*/
if( nblks <= 0 ) return( npq );
/*
* lcmt00 >= low. The current block owns either diagonals or upper entries. Save
* the current position in the LCM table. After this row has been completely
* taken care of, re-start from this column and the next row of the LCM table.
*/
lcmt = lcmt00; nblkd = nblks;
while( nblkd && ( lcmt <= iupp ) )
{
/*
* A block owning diagonals lcmt00 >= low && lcmt00 <= iupp has been found.
*/
nbloc = ( ( nblkd == 1 ) ? lnbloc : nb );
if( lcmt >= 0 )
{
tmp1 = imbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, nbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A+lcmt*inca, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = nbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, imbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going east until there are no more blocks owning diagonals.
*/
lcmt += qnb; nblkd--; B += tmp2 * incb;
}
/*
* I am done with the first row of the LCM table. Go to the next row.
*/
lcmt00 -= iupp - upp + pmb; mblks--; A += imbloc * inca;
}
/*
* Loop over the remaining columns of the LCM table.
*/
do
{
/*
* If the current block does not have diagonal elements, find the closest one in
* the LCM table having some.
*/
if( ( lcmt00 < low ) || ( lcmt00 > upp ) )
{
while( mblks && nblks )
{
while( mblks && ( lcmt00 > upp ) )
{ lcmt00 -= pmb; mblks--; A += mb*inca; }
if( lcmt00 >= low ) break;
while( nblks && ( lcmt00 < low ) )
{ lcmt00 += qnb; nblks--; }
if( lcmt00 <= upp ) break;
}
}
if( !( mblks ) || !( nblks ) ) return( npq );
/*
* The current block owns diagonals. Save the current position in the LCM table.
* After this column has been completely taken care of, re-start from this row
* and the next column in the LCM table.
*/
nbloc = ( ( nblks == 1 ) ? lnbloc : nb );
lcmt = lcmt00; mblkd = mblks; aptrd = A;
while( mblkd && ( lcmt >= low ) )
{
/*
* A block owning diagonals lcmt00 >= low && lcmt00 <= upp has been found.
*/
mbloc = ( ( mblkd == 1 ) ? lmbloc : mb );
if( lcmt >= 0 )
{
tmp1 = mbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, nbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd+lcmt*inca, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = nbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, mbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going south until there are no more blocks owning diagonals
*/
lcmt -= pmb; mblkd--; aptrd += mbloc * inca; B += tmp2 * incb;
}
/*
* I am done with this column of the LCM table. Go to the next column ...
*/
lcmt00 += qnb; nblks--;
/*
* ... until there are no more columns.
*/
} while( nblks > 0 );
/*
* Return the number of diagonals found.
*/
return( npq );
}
else
{
/*
* (un)packing using columns of virtual matrix
*/
if( rows )
{
/*
* (un)packing rows of mn by k array A
*/
inca = size;
incb = ( notran ? size : LDB * size );
m = &tmp2;
n = &K;
}
else
{
/*
* (un)packing columns of k by mn array A
*/
inca = LDA * size;
incb = ( notran ? LDB * size : size );
m = &K;
n = &tmp2;
}
kb = MN;
/*
* From the (un)packing point of view the only valuable shortcut is when the
* virtual grid and the blocks are square, and the offset is zero or the grid
* is 1x1.
*/
if( ( ( lcmt00 == 0 ) && ( VM->imb1 == VM->inb1 ) && ( mb == nb ) &&
( nprow == npcol ) ) || ( ( nprow == 1 ) && ( npcol == 1 ) ) )
{
if( VM->prow == VM->pcol )
{
npq = ( ( nblks < 2 ) ? inbloc :
inbloc + ( nblks - 2 ) * nb + lnbloc );
npq = MIN( npq, kb );
if( rows ) add( &npq, &K, ALPHA, A, &LDA, BETA, B, &LDB );
else add( &K, &npq, ALPHA, A, &LDA, BETA, B, &LDB );
}
return( npq );
}
pmb = nprow * mb;
qnb = npcol * nb;
/*
* Handle separately the first row and/or column of the LCM table. Update the
* LCM value of the curent block lcmt00, as well as the number of rows and
* columns mblks and nblks remaining in the LCM table.
*/
GoSouth = ( lcmt00 > iupp );
GoEast = ( lcmt00 < ilow );
if( !( GoSouth ) && !( GoEast ) )
{
/*
* The upper left block owns diagonal entries lcmt00 >= ilow && lcmt00 <= iupp
*/
if( lcmt00 >= 0 )
{
tmp1 = imbloc - lcmt00; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, inbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = inbloc + lcmt00; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, imbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A-lcmt00*inca, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
B += tmp2 * incb;
/*
* Decide whether one should go south or east in the table: Go east if
* the block below the current one only owns lower entries. If this block,
* however, owns diagonals, then go south.
*/
GoSouth = !( GoEast = ( ( lcmt00 - ( iupp - upp + pmb ) ) < ilow ) );
}
if( GoSouth )
{
/*
* Go one step south in the LCM table. Adjust the current LCM value as well as
* the pointer to B. The pointer to A remains unchanged.
*/
lcmt00 -= iupp - upp + pmb; mblks--;
/*
* While there are blocks remaining that own upper entries, keep going south.
* Adjust the current LCM value as well as the pointer to B accordingly.
*/
while( mblks && ( lcmt00 > upp ) ) { lcmt00 -= pmb; mblks--; }
/*
* Return if no more row in the LCM table.
*/
if( mblks <= 0 ) return( npq );
/*
* lcmt00 <= upp. The current block owns either diagonals or lower entries.
* Save the current position in the LCM table. After this column has been
* completely taken care of, re-start from this row and the next column of
* the LCM table.
*/
lcmt = lcmt00; mblkd = mblks;
while( mblkd && ( lcmt >= ilow ) )
{
/*
* A block owning diagonals lcmt00 >= ilow && lcmt00 <= upp has been found.
*/
mbloc = ( ( mblkd == 1 ) ? lmbloc : mb );
if( lcmt >= 0 )
{
tmp1 = mbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, inbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = inbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, mbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A-lcmt*inca, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going south until there are no more blocks owning diagonals
*/
lcmt -= pmb; mblkd--; B += tmp2 * incb;
}
/*
* I am done with the first column of the LCM table. Go to the next column.
*/
lcmt00 += low - ilow + qnb; nblks--; A += inbloc * inca;
}
else if( GoEast )
{
/*
* Go one step east in the LCM table. Adjust the current LCM value as
* well as the pointer to A. The pointer to B remains unchanged.
*/
lcmt00 += low - ilow + qnb; nblks--; A += inbloc * inca;
/*
* While there are blocks remaining that own lower entries, keep going east
* in the LCM table. Adjust the current LCM value as well as the pointer to
* A accordingly.
*/
while( nblks && ( lcmt00 < low ) )
{ lcmt00 += qnb; nblks--; A += nb * inca; }
/*
* Return if no more column in the LCM table.
*/
if( nblks <= 0 ) return( npq );
/*
* lcmt00 >= low. The current block owns either diagonals or upper entries. Save
* the current position in the LCM table. After this row has been completely
* taken care of, re-start from this column and the next row of the LCM table.
*/
lcmt = lcmt00; nblkd = nblks; aptrd = A;
while( nblkd && ( lcmt <= iupp ) )
{
/*
* A block owning diagonals lcmt00 >= low && lcmt00 <= iupp has been found.
*/
nbloc = ( ( nblkd == 1 ) ? lnbloc : nb );
if( lcmt >= 0 )
{
tmp1 = imbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, nbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = nbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, imbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, aptrd-lcmt*inca, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going east until there are no more blocks owning diagonals.
*/
lcmt += qnb; nblkd--; aptrd += nbloc * inca; B += tmp2 * incb;
}
/*
* I am done with the first row of the LCM table. Go to the next row.
*/
lcmt00 -= iupp - upp + pmb; mblks--;
}
/*
* Loop over the remaining columns of the LCM table.
*/
do
{
/*
* If the current block does not have diagonal elements, find the closest one in
* the LCM table having some.
*/
if( ( lcmt00 < low ) || ( lcmt00 > upp ) )
{
while( mblks && nblks )
{
while( mblks && ( lcmt00 > upp ) )
{ lcmt00 -= pmb; mblks--; }
if( lcmt00 >= low ) break;
while( nblks && ( lcmt00 < low ) )
{ lcmt00 += qnb; nblks--; A += nb*inca; }
if( lcmt00 <= upp ) break;
}
}
if( !( mblks ) || !( nblks ) ) return( npq );
/*
* The current block owns diagonals. Save the current position in the LCM table.
* After this column has been completely taken care of, re-start from this row
* and the next column in the LCM table.
*/
nbloc = ( ( nblks == 1 ) ? lnbloc : nb );
lcmt = lcmt00; mblkd = mblks;
while( mblkd && ( lcmt >= low ) )
{
/*
* A block owning diagonals lcmt00 >= low && lcmt00 <= upp has been found.
*/
mbloc = ( ( mblkd == 1 ) ? lmbloc : mb );
if( lcmt >= 0 )
{
tmp1 = mbloc - lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, nbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A, &LDA, BETA, B, &LDB );
}
else
{
tmp1 = nbloc + lcmt; tmp1 = MAX( 0, tmp1 );
tmp2 = MIN( tmp1, mbloc ); npq += ( tmp2 = MIN( tmp2, kb ) );
add( m, n, ALPHA, A-lcmt*inca, &LDA, BETA, B, &LDB );
}
if( ( kb -= tmp2 ) == 0 ) return( npq );
/*
* Keep going south until there are no more blocks owning diagonals
*/
lcmt -= pmb; mblkd--; B += tmp2 * incb;
}
/*
* I am done with this column of the LCM table. Go to the next column ...
*/
lcmt00 += qnb; nblks--; A += nbloc * inca;
/*
* ... until there are no more columns.
*/
} while( nblks > 0 );
/*
* Return the number of diagonals found.
*/
return( npq );
}
/*
* End of PB_CVMpack
*/
}
|