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 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
|
/* ---------------------------------------------------------------------
*
* -- PBLAS 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 pcdotc_( Int * N,
float * DOT,
float * X, Int * IX, Int * JX, Int * DESCX, Int * INCX,
float * Y, Int * IY, Int * JY, Int * DESCY, Int * INCY )
#else
void pcdotc_( N, DOT, X, IX, JX, DESCX, INCX, Y, IY, JY, DESCY, INCY )
/*
* .. Scalar Arguments ..
*/
Int * INCX, * INCY, * IX, * IY, * JX, * JY, * N;
float * DOT;
/*
* .. Array Arguments ..
*/
Int * DESCX, * DESCY;
float * X, * Y;
#endif
{
/*
* Purpose
* =======
*
* PCDOTC forms the dot product of two subvectors,
*
* DOT := sub( X )**H * sub( Y ),
*
* where
*
* sub( X ) denotes X(IX,JX:JX+N-1) if INCX = M_X,
* X(IX:IX+N-1,JX) if INCX = 1 and INCX <> M_X, and,
*
* sub( Y ) denotes Y(IY,JY:JY+N-1) if INCY = M_Y,
* Y(IY:IY+N-1,JY) if INCY = 1 and INCY <> M_Y.
*
* 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
* =========
*
* N (global input) INTEGER
* On entry, N specifies the length of the subvectors to be
* multiplied. N must be at least zero.
*
* DOT (local output) COMPLEX array
* On exit, DOT specifies the dot product of the two subvectors
* sub( X ) and sub( Y ) only in their scope (See below for fur-
* ther details).
*
* X (local input) COMPLEX array
* On entry, X is an array of dimension (LLD_X, Kx), where LLD_X
* is at least MAX( 1, Lr( 1, IX ) ) when INCX = M_X and
* MAX( 1, Lr( 1, IX+N-1 ) ) otherwise, and, Kx is at least
* Lc( 1, JX+N-1 ) when INCX = M_X and Lc( 1, JX ) otherwise.
* Before entry, this array contains the local entries of the
* matrix X.
*
* IX (global input) INTEGER
* On entry, IX specifies X's global row index, which points to
* the beginning of the submatrix sub( X ).
*
* JX (global input) INTEGER
* On entry, JX specifies X's global column index, which points
* to the beginning of the submatrix sub( X ).
*
* DESCX (global and local input) INTEGER array
* On entry, DESCX is an integer array of dimension DLEN_. This
* is the array descriptor for the matrix X.
*
* INCX (global input) INTEGER
* On entry, INCX specifies the global increment for the
* elements of X. Only two values of INCX are supported in
* this version, namely 1 and M_X. INCX must not be zero.
*
* Y (local input) COMPLEX array
* On entry, Y is an array of dimension (LLD_Y, Ky), where LLD_Y
* is at least MAX( 1, Lr( 1, IY ) ) when INCY = M_Y and
* MAX( 1, Lr( 1, IY+N-1 ) ) otherwise, and, Ky is at least
* Lc( 1, JY+N-1 ) when INCY = M_Y and Lc( 1, JY ) otherwise.
* Before entry, this array contains the local entries of the
* matrix Y.
*
* IY (global input) INTEGER
* On entry, IY specifies Y's global row index, which points to
* the beginning of the submatrix sub( Y ).
*
* JY (global input) INTEGER
* On entry, JY specifies Y's global column index, which points
* to the beginning of the submatrix sub( Y ).
*
* DESCY (global and local input) INTEGER array
* On entry, DESCY is an integer array of dimension DLEN_. This
* is the array descriptor for the matrix Y.
*
* INCY (global input) INTEGER
* On entry, INCY specifies the global increment for the
* elements of Y. Only two values of INCY are supported in
* this version, namely 1 and M_Y. INCY must not be zero.
*
* Further Details
* ===============
*
* When the result of a vector-oriented PBLAS call is a scalar, this
* scalar is set only within the process scope which owns the vector(s)
* being operated on. Let sub( X ) be a generic term for the input vec-
* tor(s). Then, the processes owning the correct the answer is determi-
* ned as follows: if an operation involves more than one vector, the
* processes receiving the result will be the union of the following set
* of processes for each vector:
*
* If N = 1, M_X = 1 and INCX = 1, then one cannot determine if a pro-
* cess row or process column owns the vector operand, therefore only
* the process owning sub( X ) receives the correct result;
*
* If INCX = M_X, then sub( X ) is a vector distributed over a process
* row. Each process in this row receives the result;
*
* If INCX = 1, then sub( X ) is a vector distributed over a process
* column. Each process in this column receives the result;
*
* -- Written on April 1, 1998 by
* Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
* ---------------------------------------------------------------------
*/
/*
* .. Local Scalars ..
*/
char scope, * top;
Int OneBlock, OneDgrid, RRorCC, Square, Xcol, Xi, Xii, XinbD,
Xinb1D, XisD, XisR, XisRow, Xj, Xjj, Xld, Xlinc, XmyprocD,
XmyprocR, XnbD, XnpD, XnprocsD, XnprocsR, XprocD, XprocR,
Xrow, Ycol, Yi, Yii, YinbD, Yinb1D, YisD, YisR, YisRow, Yj,
Yjj, Yld, Ylinc, YmyprocD, YmyprocR, YnbD, YnpD, YnprocsD,
YnprocsR, YprocD, YprocR, Yrow, cdst, csrc, ctxt, dst, info,
ione=1, mycol, myrow, npcol, nprow, rdst, rsrc, size, src;
PBTYP_T * type;
VVDOT_T dot;
/*
* .. Local Arrays ..
*/
char * buf = NULL;
Int Xd[DLEN_], Yd[DLEN_], dbuf[ DLEN_ ];
/* ..
* .. Executable Statements ..
*
*/
PB_CargFtoC( *IX, *JX, DESCX, &Xi, &Xj, Xd );
PB_CargFtoC( *IY, *JY, DESCY, &Yi, &Yj, Yd );
#ifndef NO_ARGCHK
/*
* Test the input parameters
*/
Cblacs_gridinfo( ( ctxt = Xd[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
if( !( info = ( ( nprow == -1 ) ? -( 601 + CTXT_ ) : 0 ) ) )
{
PB_Cchkvec( ctxt, "PCDOTC", "X", *N, 1, Xi, Xj, Xd, *INCX, 6, &info );
PB_Cchkvec( ctxt, "PCDOTC", "Y", *N, 1, Yi, Yj, Yd, *INCY, 11, &info );
}
if( info ) { PB_Cabort( ctxt, "PCDOTC", info ); return; }
#endif
DOT[REAL_PART] = ZERO;
DOT[IMAG_PART] = ZERO;
/*
* Quick return if possible
*/
if( *N == 0 ) return;
/*
* Handle degenerate case
*/
if( ( *N == 1 ) && ( ( Xd[ M_ ] == 1 ) || ( Yd[ M_ ] == 1 ) ) )
{
type = PB_Cctypeset();
PB_Cpdot11( type, *N, ((char *) DOT), ((char *) X), Xi, Xj, Xd, *INCX,
((char *) Y), Yi, Yj, Yd, *INCY, type->Fvvdotc );
return;
}
/*
* Start the operations
*/
#ifdef NO_ARGCHK
Cblacs_gridinfo( ( ctxt = Xd[ CTXT_ ] ), &nprow, &npcol, &myrow, &mycol );
#endif
/*
* Determine if sub( X ) is distributed or not
*/
if( ( XisRow = ( *INCX == Xd[M_] ) ) != 0 )
XisD = ( ( Xd[CSRC_] >= 0 ) && ( ( XnprocsD = npcol ) > 1 ) );
else
XisD = ( ( Xd[RSRC_] >= 0 ) && ( ( XnprocsD = nprow ) > 1 ) );
/*
* Determine if sub( Y ) is distributed or not
*/
if( ( YisRow = ( *INCY == Yd[M_] ) ) != 0 )
YisD = ( ( Yd[CSRC_] >= 0 ) && ( ( YnprocsD = npcol ) > 1 ) );
else
YisD = ( ( Yd[RSRC_] >= 0 ) && ( ( YnprocsD = nprow ) > 1 ) );
/*
* Are sub( X ) and sub( Y ) both row or column vectors ?
*/
RRorCC = ( ( XisRow && YisRow ) || ( !( XisRow ) && !( YisRow ) ) );
/*
* XisD && YisD <=> both vector operands are indeed distributed
*/
if( XisD && YisD )
{
/*
* Retrieve sub( X )'s local information: Xii, Xjj, Xrow, Xcol
*/
PB_Cinfog2l( Xi, Xj, Xd, nprow, npcol, myrow, mycol, &Xii, &Xjj,
&Xrow, &Xcol );
if( XisRow )
{
XinbD = Xd[INB_]; XnbD = Xd[NB_];
Xld = Xd[LLD_]; Xlinc = Xld;
XprocD = Xcol; XmyprocD = mycol;
XprocR = Xrow; XmyprocR = myrow; XnprocsR = nprow;
XisR = ( ( Xrow == -1 ) || ( XnprocsR == 1 ) );
Mfirstnb( Xinb1D, *N, Xj, XinbD, XnbD );
}
else
{
XinbD = Xd[IMB_]; XnbD = Xd[MB_];
Xld = Xd[LLD_]; Xlinc = 1;
XprocD = Xrow; XmyprocD = myrow;
XprocR = Xcol; XmyprocR = mycol; XnprocsR = npcol;
XisR = ( ( Xcol == -1 ) || ( XnprocsR == 1 ) );
Mfirstnb( Xinb1D, *N, Xi, XinbD, XnbD );
}
/*
* Retrieve sub( Y )'s local information: Yii, Yjj, Yrow, Ycol
*/
PB_Cinfog2l( Yi, Yj, Yd, nprow, npcol, myrow, mycol, &Yii, &Yjj,
&Yrow, &Ycol );
if( YisRow )
{
YinbD = Yd[INB_]; YnbD = Yd[NB_];
Yld = Yd[LLD_]; Ylinc = Yld;
YprocD = Ycol; YmyprocD = mycol;
YprocR = Yrow; YmyprocR = myrow; YnprocsR = nprow;
YisR = ( ( Yrow == -1 ) || ( YnprocsR == 1 ) );
Mfirstnb( Yinb1D, *N, Yj, YinbD, YnbD );
}
else
{
YinbD = Yd[IMB_]; YnbD = Yd[MB_];
Yld = Yd[LLD_]; Ylinc = 1;
YprocD = Yrow; YmyprocD = myrow;
YprocR = Ycol; YmyprocR = mycol; YnprocsR = npcol;
YisR = ( ( Ycol == -1 ) || ( YnprocsR == 1 ) );
Mfirstnb( Yinb1D, *N, Yi, YinbD, YnbD );
}
/*
* Do sub( X ) and sub( Y ) span more than one process ?
*/
OneDgrid = ( ( XnprocsD == 1 ) && ( YnprocsD == 1 ) );
OneBlock = ( ( Xinb1D >= *N ) && ( Yinb1D >= *N ) );
/*
* Are sub( X ) and sub( Y ) distributed in the same manner ?
*/
Square = ( ( Xinb1D == Yinb1D ) && ( XnbD == YnbD ) &&
( XnprocsD == YnprocsD ) );
if( !( XisR ) )
{
/*
* sub( X ) is not replicated
*/
if( YisR )
{
/*
* If sub( X ) is not replicated, but sub( Y ) is, a process row or column
* YprocR need to be selected. It will contain the non-replicated vector used
* to perform the dot product computation.
*/
if( RRorCC )
{
/*
* sub( X ) and sub( Y ) are both row or column vectors
*/
if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
{
/*
* sub( X ) and sub( Y ) start in the same process row or column XprocD=YprocD.
* Enforce a purely local operation by choosing YprocR to be equal to XprocR.
*/
YprocR = XprocR;
}
else
{
/*
* Otherwise, communication has to occur, so choose the next process row or
* column for YprocR to maximize the number of links, i.e reduce contention.
*/
YprocR = MModAdd1( XprocR, XnprocsR );
}
}
else
{
/*
* sub( X ) and sub( Y ) are distributed in orthogonal directions, what is
* chosen for YprocR does not really matter. Select the process origin.
*/
YprocR = XprocD;
}
}
else
{
/*
* Neither sub( X ) nor sub( Y ) are replicated. If I am not in process row or
* column XprocR and not in process row or column YprocR, then quick return.
*/
if( ( XmyprocR != XprocR ) && ( YmyprocR != YprocR ) )
return;
}
}
else
{
/*
* sub( X ) is distributed and replicated (so no quick return possible)
*/
if( YisR )
{
/*
* sub( Y ) is distributed and replicated as well
*/
if( RRorCC )
{
/*
* sub( X ) and sub( Y ) are both row or column vectors
*/
if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
{
/*
* sub( X ) and sub( Y ) start in the same process row or column XprocD=YprocD.
* Enforce a purely local operation by choosing XprocR and YprocR to be equal
* to zero.
*/
XprocR = YprocR = 0;
}
else
{
/*
* Otherwise, communication has to occur, so select YprocR to be zero and the
* next process row or column for XprocR in order to maximize the number of
* used links, i.e reduce contention.
*/
YprocR = 0;
XprocR = MModAdd1( YprocR, YnprocsR );
}
}
else
{
/*
* sub( X ) and sub( Y ) are distributed in orthogonal directions, select the
* origin processes.
*/
XprocR = YprocD;
YprocR = XprocD;
}
}
else
{
/*
* sub( Y ) is distributed, but not replicated
*/
if( RRorCC )
{
/*
* sub( X ) and sub( Y ) are both row or column vectors
*/
if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
{
/*
* sub( X ) and sub( Y ) start in the same process row or column XprocD=YprocD.
* Enforce a purely local operation by choosing XprocR to be equal to YprocR.
*/
XprocR = YprocR;
}
else
{
/*
* Otherwise, communication has to occur, so choose the next process row or
* column for XprocR to maximize the number of links, i.e reduce contention.
*/
XprocR = MModAdd1( YprocR, YnprocsR );
}
}
else
{
/*
* sub( X ) and sub( Y ) are distributed in orthogonal directions, what is
* chosen for XprocR does not really matter. Select the origin process.
*/
XprocR = YprocD;
}
}
}
/*
* Even if sub( X ) and/or sub( Y ) are replicated, only two process row or
* column are active, namely XprocR and YprocR. If any of those operands is
* replicated, broadcast will occur (unless there is an easy way out).
*/
type = PB_Cctypeset(); size = type->size; dot = type->Fvvdotc;
/*
* A purely operation occurs iff the operands start in the same process and if
* either the grid is mono-dimensional or there is a single local block to be
* operated with or if both operands are aligned.
*/
if( ( ( RRorCC && ( XprocD == YprocD ) && ( XprocR == YprocR ) ) ||
( !( RRorCC ) && ( XprocD == YprocR ) && ( XprocR == YprocD ) ) ) &&
( OneDgrid || OneBlock || ( RRorCC && Square ) ) )
{
if( ( !XisR && ( XmyprocR == XprocR ) &&
!YisR && ( YmyprocR == YprocR ) ) ||
( !XisR && YisR && ( YmyprocR == YprocR ) ) ||
( !YisR && XisR && ( XmyprocR == XprocR ) ) ||
( XisR && YisR ) )
{
XnpD = PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD,
XnprocsD );
YnpD = PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD,
YnprocsD );
if( ( XnpD > 0 ) && ( YnpD > 0 ) )
{
dot( &XnpD, ((char *) DOT), Mptr( ((char *) X), Xii, Xjj, Xld,
size ), &Xlinc, Mptr( ((char *) Y), Yii, Yjj, Yld, size ),
&Ylinc );
}
}
/*
* Combine the local results in sub( X )'s scope
*/
if( ( XisR && YisR ) || ( XmyprocR == XprocR ) )
{
scope = ( XisRow ? CROW : CCOLUMN );
top = PB_Ctop( &ctxt, COMBINE, &scope, TOP_GET );
Ccgsum2d( ctxt, &scope, top, 1, 1, ((char *) DOT), 1, -1, 0 );
}
if( RRorCC && XisR && YisR ) return;
}
else if( ( RRorCC && OneDgrid ) || OneBlock || Square )
{
/*
* Otherwise, it may be possible to compute the desired dot-product in a single
* message exchange iff the grid is mono-dimensional and the operands are
* distributed in the same direction, or there is just one block to be exchanged
* or if both operands are similarly distributed in their respective direction.
*/
if( YmyprocR == YprocR )
{
/*
* The processes owning a piece of sub( Y ) send it to the corresponding
* process owning s piece of sub ( X ).
*/
YnpD = PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD,
YnprocsD );
if( YnpD > 0 )
{
dst = XprocD + MModSub( YmyprocD, YprocD, YnprocsD );
dst = MPosMod( dst, XnprocsD );
if( XisRow ) { rdst = XprocR; cdst = dst; }
else { rdst = dst; cdst = XprocR; }
if( ( myrow == rdst ) && ( mycol == cdst ) )
{
dot( &YnpD, ((char *) DOT), Mptr( ((char *) X), Xii, Xjj, Xld,
size ), &Xlinc, Mptr( ((char *) Y), Yii, Yjj, Yld,
size ), &Ylinc );
}
else
{
if( YisRow )
Ccgesd2d( ctxt, 1, YnpD, Mptr( ((char *) Y), Yii, Yjj,
Yld, size ), Yld, rdst, cdst );
else
Ccgesd2d( ctxt, YnpD, 1, Mptr( ((char *) Y), Yii, Yjj,
Yld, size ), Yld, rdst, cdst );
}
}
}
if( XmyprocR == XprocR )
{
/*
* The processes owning a piece of sub( X ) receive the corresponding local
* piece of sub( Y ), compute the local dot product and combine the results
* within sub( X )'s scope.
*/
XnpD = PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD,
XnprocsD );
if( XnpD > 0 )
{
src = YprocD + MModSub( XmyprocD, XprocD, XnprocsD );
src = MPosMod( src, YnprocsD );
if( YisRow ) { rsrc = YprocR; csrc = src; }
else { rsrc = src; csrc = YprocR; }
if( ( myrow != rsrc ) || ( mycol != csrc ) )
{
buf = PB_Cmalloc( XnpD * size );
if( YisRow )
Ccgerv2d( ctxt, 1, XnpD, buf, 1, rsrc, csrc );
else
Ccgerv2d( ctxt, XnpD, 1, buf, XnpD, rsrc, csrc );
dot( &XnpD, ((char *) DOT), Mptr( ((char *) X), Xii, Xjj, Xld,
size ), &Xlinc, buf, &ione );
if( buf ) free( buf );
}
}
if( XisRow )
{
top = PB_Ctop( &ctxt, COMBINE, ROW, TOP_GET );
Ccgsum2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1, -1, 0 );
}
else
{
top = PB_Ctop( &ctxt, COMBINE, COLUMN, TOP_GET );
Ccgsum2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1, -1, 0 );
}
}
}
else
{
/*
* General case, copy sub( Y ) within sub( X )'s scope, compute the local
* results and combine them within sub( X )'s scope.
*/
XnpD = PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD, XnprocsD );
if( XisRow )
{
PB_Cdescset( dbuf, 1, *N, 1, Xinb1D, 1, XnbD, XprocR, XprocD, ctxt,
1 );
}
else
{
PB_Cdescset( dbuf, *N, 1, Xinb1D, 1, XnbD, 1, XprocD, XprocR, ctxt,
MAX( 1, XnpD ) );
}
if( ( XmyprocR == XprocR ) && ( XnpD > 0 ) )
buf = PB_Cmalloc( XnpD * size );
if( YisRow )
{
PB_Cpaxpby( type, NOCONJG, 1, *N, type->one, ((char *) Y), Yi, Yj,
Yd, ROW, type->zero, buf, 0, 0, dbuf, ( XisRow ? ROW :
COLUMN ) );
}
else
{
PB_Cpaxpby( type, NOCONJG, *N, 1, type->one, ((char *) Y), Yi, Yj,
Yd, COLUMN, type->zero, buf, 0, 0, dbuf, ( XisRow ?
ROW : COLUMN ) );
}
if( XmyprocR == XprocR )
{
if( XnpD > 0 )
{
dot( &XnpD, ((char *) DOT), Mptr( ((char *) X), Xii, Xjj, Xld,
size ), &Xlinc, buf, &ione );
if( buf ) free( buf );
}
if( XisRow )
{
top = PB_Ctop( &ctxt, COMBINE, ROW, TOP_GET );
Ccgsum2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1, -1, 0 );
}
else
{
top = PB_Ctop( &ctxt, COMBINE, COLUMN, TOP_GET );
Ccgsum2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1, -1, 0 );
}
}
}
/*
* Send the DOT product result within sub( Y )'s scope
*/
if( XisR || YisR )
{
/*
* Either sub( X ) or sub( Y ) are replicated, so that every process should have
* the result -> broadcast it orthogonally from sub( X )'s direction.
*/
if( XisRow )
{
top = PB_Ctop( &ctxt, BCAST, COLUMN, TOP_GET );
if( XmyprocR == XprocR )
Ccgebs2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1 );
else
Ccgebr2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1, XprocR,
XmyprocD );
}
else
{
top = PB_Ctop( &ctxt, BCAST, ROW, TOP_GET );
if( XmyprocR == XprocR )
Ccgebs2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1 );
else
Ccgebr2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1, XmyprocD,
XprocR );
}
}
else
{
/*
* Neither sub( X ) nor sub( Y ) are replicated
*/
if( RRorCC )
{
/*
* Both sub( X ) are distributed in the same direction -> the process row or
* column XprocR sends the result to the process row or column YprocR.
*/
if( XprocR != YprocR )
{
if( XmyprocR == XprocR )
{
if( XisRow )
Ccgesd2d( ctxt, 1, 1, ((char *) DOT), 1, YprocR,
YmyprocD );
else
Ccgesd2d( ctxt, 1, 1, ((char *) DOT), 1, YmyprocD,
YprocR );
}
else if( YmyprocR == YprocR )
{
if( XisRow )
Ccgerv2d( ctxt, 1, 1, ((char *) DOT), 1, XprocR,
XmyprocD );
else
Ccgerv2d( ctxt, 1, 1, ((char *) DOT), 1, XmyprocD,
XprocR );
}
}
}
else
{
/*
* Otherwise, the process at the intersection of sub( X )'s and sub( Y )'s
* scope, broadcast the result within sub( Y )'s scope.
*/
if( YmyprocR == YprocR )
{
if( YisRow )
{
top = PB_Ctop( &ctxt, BCAST, ROW, TOP_GET );
if( YmyprocD == XprocR )
Ccgebs2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1 );
else
Ccgebr2d( ctxt, ROW, top, 1, 1, ((char*)DOT), 1,
YprocR, XprocR );
}
else
{
top = PB_Ctop( &ctxt, BCAST, COLUMN, TOP_GET );
if( YmyprocD == XprocR )
Ccgebs2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1 );
else
Ccgebr2d( ctxt, COLUMN, top, 1, 1, ((char*)DOT), 1,
XprocR, YprocR );
}
}
}
}
}
else if( !( XisD ) && YisD )
{
/*
* sub( X ) is not distributed and sub( Y ) is distributed.
*/
type = PB_Cctypeset();
PB_CpdotND( type, *N, ((char *) DOT), ((char *) X), Xi, Xj, Xd, *INCX,
((char *) Y), Yi, Yj, Yd, *INCY, type->Fvvdotc );
}
else if( XisD && !( YisD ) )
{
/*
* sub( X ) is distributed and sub( Y ) is not distributed.
*/
type = PB_Cctypeset();
/*
* Compute DOT := sub( Y )**H * sub( X )
*/
PB_CpdotND( type, *N, ((char *) DOT), ((char *) Y), Yi, Yj, Yd, *INCY,
((char *) X), Xi, Xj, Xd, *INCX, type->Fvvdotc );
/*
* Conjugate the result
*/
DOT[IMAG_PART] = -DOT[IMAG_PART];
}
else
{
/*
* Neither sub( X ) nor sub( Y ) are distributed
*/
type = PB_Cctypeset();
PB_CpdotNN( type, *N, ((char *) DOT), ((char *) X), Xi, Xj, Xd, *INCX,
((char *) Y), Yi, Yj, Yd, *INCY, type->Fvvdotc );
}
/*
* End of PCDOTC
*/
}
|