21 double * X,
int * IX,
int * JX,
int * DESCX,
int * INCX,
22 double * Y,
int * IY,
int * JY,
int * DESCY,
int * INCY )
24 void pdswap_( N, X, IX, JX, DESCX, INCX, Y, IY, JY, DESCY, INCY )
28 int * INCX, * INCY, * IX, * IY, * JX, * JY, * N;
178 char Xscope, Yscope, * one, * top, tran, * zero;
179 int OneBlock, OneDgrid, RRorCC, Square, Xcol, Xi, XisD, XisR,
180 Xinb1D, XinbD, XisRow, Xii, Xj, Xjj, Xld, Xlinc, Xm, XmyprocD,
181 XmyprocR, Xn, XnbD, XnpD, XnprocsD, XnprocsR, XprocD, XprocR,
182 Xroc, Xrow, Ycol, Yi, Yii, Yinb1D, YinbD, YisD, YisR, YisRow,
183 Yj, Yjj, Yld, Ylinc, Ym, YmyprocD, YmyprocR, Yn, YnbD, YnpD,
184 YnprocsD, YnprocsR, YprocD, YprocR, Yroc, Yrow, cdst, csrc,
185 ctxt, dst, gcdPQ, info, ione=1, k, l, lcmPQ, lcmb, mycol,
186 myrow, npcol, npq, nprow, p, q, rdst, rsrc, src, size;
205 if( !( info = ( ( nprow == -1 ) ? -( 501 +
CTXT_ ) : 0 ) ) )
207 PB_Cchkvec( ctxt,
"PDSWAP",
"X", *N, 1, Xi, Xj, Xd, *INCX, 5, &info );
208 PB_Cchkvec( ctxt,
"PDSWAP",
"Y", *N, 1, Yi, Yj, Yd, *INCY, 10, &info );
210 if( info ) {
PB_Cabort( ctxt,
"PDSWAP", info );
return; }
215 if( *N == 0 )
return;
225 if( ( XisRow = ( *INCX == Xd[
M_] ) ) != 0 )
226 XisD = ( ( Xd[
CSRC_] >= 0 ) && ( ( XnprocsD = npcol ) > 1 ) );
228 XisD = ( ( Xd[
RSRC_] >= 0 ) && ( ( XnprocsD = nprow ) > 1 ) );
232 if( ( YisRow = ( *INCY == Yd[
M_] ) ) != 0 )
233 YisD = ( ( Yd[
CSRC_] >= 0 ) && ( ( YnprocsD = npcol ) > 1 ) );
235 YisD = ( ( Yd[
RSRC_] >= 0 ) && ( ( YnprocsD = nprow ) > 1 ) );
239 RRorCC = ( ( XisRow && YisRow ) || ( !( XisRow ) && !( YisRow ) ) );
248 PB_Cinfog2l( Xi, Xj, Xd, nprow, npcol, myrow, mycol, &Xii, &Xjj,
252 XinbD = Xd[
INB_ ]; XnbD = Xd[
NB_ ]; Xld = Xd[
LLD_];
254 XprocD = Xcol; XmyprocD = mycol;
255 XprocR = Xrow; XmyprocR = myrow; XnprocsR = nprow;
256 XisR = ( ( Xrow == -1 ) || ( XnprocsR == 1 ) );
257 Mfirstnb( Xinb1D, *N, Xj, XinbD, XnbD );
261 XinbD = Xd[
IMB_ ]; XnbD = Xd[
MB_ ]; Xld = Xd[
LLD_];
263 XprocD = Xrow; XmyprocD = myrow;
264 XprocR = Xcol; XmyprocR = mycol; XnprocsR = npcol;
265 XisR = ( ( Xcol == -1 ) || ( XnprocsR == 1 ) );
266 Mfirstnb( Xinb1D, *N, Xi, XinbD, XnbD );
271 PB_Cinfog2l( Yi, Yj, Yd, nprow, npcol, myrow, mycol, &Yii, &Yjj,
275 YinbD = Yd[
INB_ ]; YnbD = Yd[
NB_ ]; Yld = Yd[
LLD_];
277 YprocD = Ycol; YmyprocD = mycol;
278 YprocR = Yrow; YmyprocR = myrow; YnprocsR = nprow;
279 YisR = ( ( Yrow == -1 ) || ( YnprocsR == 1 ) );
280 Mfirstnb( Yinb1D, *N, Yj, YinbD, YnbD );
284 YinbD = Yd[
IMB_ ]; YnbD = Yd[
MB_ ]; Yld = Yd[
LLD_];
286 YprocD = Yrow; YmyprocD = myrow;
287 YprocR = Ycol; YmyprocR = mycol; YnprocsR = npcol;
288 YisR = ( ( Ycol == -1 ) || ( YnprocsR == 1 ) );
289 Mfirstnb( Yinb1D, *N, Yi, YinbD, YnbD );
294 OneDgrid = ( ( XnprocsD == 1 ) && ( YnprocsD == 1 ) );
295 OneBlock = ( ( Xinb1D >= *N ) && ( Yinb1D >= *N ) );
299 Square = ( ( Xinb1D == Yinb1D ) && ( XnbD == YnbD ) &&
300 ( XnprocsD == YnprocsD ) );
319 if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
333 YprocR =
MModAdd1( XprocR, XnprocsR );
351 if( ( XmyprocR != XprocR ) && ( YmyprocR != YprocR ) )
370 if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
387 XprocR =
MModAdd1( YprocR, YnprocsR );
410 if( ( OneDgrid || OneBlock || Square ) && ( XprocD == YprocD ) )
424 XprocR =
MModAdd1( YprocR, YnprocsR );
448 if( ( ( RRorCC && ( XprocD == YprocD ) && ( XprocR == YprocR ) ) ||
449 ( !( RRorCC ) && ( XprocD == YprocR ) && ( XprocR == YprocD ) ) ) &&
450 ( OneDgrid || OneBlock || ( RRorCC && Square ) ) )
452 if( ( !XisR && ( XmyprocR == XprocR ) &&
453 !YisR && ( YmyprocR == YprocR ) ) ||
454 ( !XisR && YisR && ( YmyprocR == YprocR ) ) ||
455 ( !YisR && XisR && ( XmyprocR == XprocR ) ) ||
458 XnpD =
PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD,
460 YnpD =
PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD,
462 if( ( XnpD > 0 ) && ( YnpD > 0 ) )
465 Mptr( ((
char *) X), Xii, Xjj, Xld, size ), &Xlinc,
466 Mptr( ((
char *) Y), Yii, Yjj, Yld, size ), &Ylinc );
468 if( RRorCC && XisR && YisR )
return;
471 else if( ( RRorCC && OneDgrid ) || OneBlock || Square )
479 if( RRorCC && ( XprocR != YprocR ) )
485 if( XmyprocR == XprocR )
487 XnpD =
PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD,
491 dst = YprocD +
MModSub( XmyprocD, XprocD, XnprocsD );
492 dst =
MPosMod( dst, YnprocsD );
496 Xld, size ), Xld, YprocR, dst );
498 Xld, size ), Xld, YprocR, dst );
504 Xld, size ), Xld, dst, YprocR );
506 Xld, size ), Xld, dst, YprocR );
510 if( YmyprocR == YprocR )
512 YnpD =
PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD,
516 dst = XprocD +
MModSub( YmyprocD, YprocD, YnprocsD );
517 dst =
MPosMod( dst, XnprocsD );
521 Yld, size ), Yld, XprocR, dst );
523 Yld, size ), Yld, XprocR, dst );
528 Yld, size ), Yld, dst, XprocR );
530 Yld, size ), Yld, dst, XprocR );
540 if( XmyprocR == XprocR )
546 XnpD =
PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD,
550 dst = YprocD +
MModSub( XmyprocD, XprocD, XnprocsD );
551 dst =
MPosMod( dst, YnprocsD );
552 if( YisRow ) { rdst = YprocR; cdst = dst; }
553 else { rdst = dst; cdst = YprocR; }
555 if( ( myrow == rdst ) && ( mycol == cdst ) )
557 dswap_( &XnpD,
Mptr( ((
char *) X), Xii, Xjj, Xld,
558 size ), &Xlinc,
Mptr( ((
char *) Y), Yii, Yjj, Yld,
565 Xjj, Xld, size ), Xld, rdst, cdst );
568 Xjj, Xld, size ), Xld, rdst, cdst );
572 if( YmyprocR == YprocR )
578 YnpD =
PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD,
582 src = XprocD +
MModSub( YmyprocD, YprocD, YnprocsD );
583 src =
MPosMod( src, XnprocsD );
584 if( XisRow ) { rsrc = XprocR; csrc = src; }
585 else { rsrc = src; csrc = XprocR; }
587 if( ( myrow != rsrc ) || ( mycol != csrc ) )
591 Cdgerv2d( ctxt, 1, YnpD, buf, 1, rsrc, csrc );
593 Cdgerv2d( ctxt, YnpD, 1, buf, YnpD, rsrc, csrc );
596 Yjj, Yld, size ), Yld, rsrc, csrc );
599 Yjj, Yld, size ), Yld, rsrc, csrc );
600 dcopy_( &YnpD, buf, &ione,
Mptr( ((
char *) Y), Yii,
601 Yjj, Yld, size ), &Ylinc );
602 if( buf ) free( buf );
606 if( XmyprocR == XprocR )
614 if( ( myrow != rdst ) || ( mycol != cdst ) )
618 Cdgerv2d( ctxt, 1, XnpD, buf, 1, rdst, cdst );
620 Cdgerv2d( ctxt, XnpD, 1, buf, XnpD, rdst, cdst );
621 dcopy_( &XnpD, buf, &ione,
Mptr( ((
char *) X), Xii,
622 Xjj, Xld, size ), &Xlinc );
623 if( buf ) free( buf );
629 else if( ( XmyprocR == XprocR ) || ( YmyprocR == YprocR ) )
635 if( XisRow ) { Xscope =
CCOLUMN; Xm = 1; rsrc = XprocR; }
636 else { Xscope =
CROW; Xn = 1; csrc = XprocR; }
637 if( YisRow ) { Yscope =
CCOLUMN; Ym = 1; rdst = YprocR; }
638 else { Yscope =
CROW; Yn = 1; cdst = YprocR; }
639 lcmb =
PB_Clcm( XnprocsD * XnbD, YnprocsD * YnbD );
640 one = type->
one; zero = type->
zero;
641 gcdPQ =
PB_Cgcd( XnprocsD, YnprocsD );
642 lcmPQ = ( XnprocsD / gcdPQ ) * YnprocsD;
644 for( k = 0; k < gcdPQ; k++ )
648 for( l = 0; l < lcmPQ; l++ )
650 Xroc =
MModAdd( XprocD, p, XnprocsD );
651 Yroc =
MModAdd( YprocD, q, YnprocsD );
653 if( ( XmyprocD == Xroc ) || ( YmyprocD == Yroc ) )
655 XnpD =
PB_Cnumroc( *N, 0, Xinb1D, XnbD, Xroc, XprocD,
657 YnpD =
PB_Cnumroc( *N, 0, Yinb1D, YnbD, Yroc, YprocD,
659 PB_CVMinit( &VM, 0, XnpD, YnpD, Xinb1D, Yinb1D, XnbD, YnbD,
660 p, q, XnprocsD, YnprocsD, lcmb );
663 if( ( RRorCC && ( Xroc == Yroc ) &&
664 ( XprocR == YprocR ) ) ||
665 ( !( RRorCC ) && ( Xroc == YprocR ) &&
666 ( XprocR == Yroc ) ) )
672 if( ( YmyprocD == Yroc ) && ( YmyprocR == YprocR ) )
675 Mptr( ((
char *) X), Xii, Xjj, Xld, size ),
676 Xlinc,
Mptr( ((
char *) Y), Yii, Yjj, Yld,
686 if( ( XmyprocR == XprocR ) && ( XmyprocD == Xroc ) )
688 if( XisRow ) { Xn = npq; }
690 if( YisRow ) { Yn = npq; cdst = Yroc; }
691 else { Ym = npq; rdst = Yroc; }
694 npq, 1, one,
Mptr( ((
char *) X), Xii,
695 Xjj, Xld, size ), Xld, zero, buf, Xm );
696 Cdgesd2d( ctxt, Xm, Xn, buf, Xm, rdst, cdst );
697 Cdgerv2d( ctxt, Ym, Yn, buf, Ym, rdst, cdst );
699 &tran, npq, 1, zero,
Mptr( ((
char *) X),
700 Xii, Xjj, Xld, size ), Xld, one, buf,
702 if( buf ) free ( buf );
704 if( ( YmyprocR == YprocR ) && ( YmyprocD == Yroc ) )
706 if( XisRow ) { Xn = npq; csrc = Xroc; }
707 else { Xm = npq; rsrc = Xroc; }
708 if( YisRow ) { Yn = npq; }
713 Yii, Yjj, Yld, size ), Yld, zero, buf,
715 Cdgesd2d( ctxt, Ym, Yn, buf, Ym, rsrc, csrc );
716 Cdgerv2d( ctxt, Xm, Xn, buf, Xm, rsrc, csrc );
718 &tran, npq, 1, zero,
Mptr( ((
char *) Y),
719 Yii, Yjj, Yld, size ), Yld, one, buf,
721 if( buf ) free ( buf );
737 XnpD =
PB_Cnumroc( *N, 0, Xinb1D, XnbD, XmyprocD, XprocD, XnprocsD );
743 if( XmyprocR == XprocR )
745 Xii, Xjj, Xld, size ), Xld );
748 Xii, Xjj, Xld, size ), Xld, XprocR, XmyprocD );
753 if( XmyprocR == XprocR )
755 Xii, Xjj, Xld, size ), Xld );
758 Xii, Xjj, Xld, size ), Xld, XmyprocD, XprocR );
768 YnpD =
PB_Cnumroc( *N, 0, Yinb1D, YnbD, YmyprocD, YprocD, YnprocsD );
774 if( YmyprocR == YprocR )
776 Yii, Yjj, Yld, size ), Yld );
779 Yii, Yjj, Yld, size ), Yld, YprocR, YmyprocD );
784 if( YmyprocR == YprocR )
786 Yii, Yjj, Yld, size ), Yld );
789 Yii, Yjj, Yld, size ), Yld, YmyprocD, YprocR );
794 else if( !( XisD ) && YisD )
800 ((
char *) Y), Yi, Yj, Yd, *INCY );
802 else if( XisD && !( YisD ) )
808 ((
char *) X), Xi, Xj, Xd, *INCX );
816 ((
char *) Y), Yi, Yj, Yd, *INCY );