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
|
#include "tools.h"
void CpzatrmvUN(UNIT, N, alpha, A, IA, JA, descA, X, IX, JX, descX, incX, beta,
Y, IY, JY, descY, incY)
int UNIT;
int N;
double alpha;
double *A;
int IA;
int JA;
int *descA;
double *X;
int IX;
int JX;
int *descX;
int incX;
double beta;
double *Y;
int IY;
int JY;
int *descY;
int incY;
/*
*
* ======(Xr)======
*
* N
* ---------------
* | |\_ | A - N x N
* | | \_ (A) | Y - N x 1
* | | \_ | X - 1 x N
* (Yc) N | \_ |
* | | \_ | X will be replicated on every
* | | \_ | process row
* | | \ | Y will have space on every
* | | \_| process column
* ---------------
*/
{
/*
* .. External routines ..
*/
char *ptop();
void pberror_();
void Cinfog2l();
int Cnumroc2();
void Cblacs_gridinfo();
void Cdgebs2d();
void Cdgebr2d();
void Cdgsum2d();
F_INTG_FCT dgemv_();
void Cpzdvabs1();
void Cpdscal1();
void Cpdcopy1();
void Cpdaxpy1();
F_CHAR trans;
char *top;
int Ir, Jr, Ic, Jc, i, j, kb, nb, lld, LOCp, LOCq, one=1, I=0;
int ctxt, nprow, npcol, myrow, mycol, arow, acol, currow, curcol;
int descX1[DLEN_], descXr[DLEN_], descYc[DLEN_], IX1, JX1, incX1;
double *a, *aa, *ar, *absA, *X1, *Xr, *Yc, *xr, *yc, *yc2, zero=0.0;
trans = C2F_CHAR("N");
ctxt = descA[CTXT_];
Cblacs_gridinfo(descA[CTXT_], &nprow, &npcol, &myrow, &mycol);
/*
* Scale Y by beta: Y = beta * Y; this allows us to later add in
* alpha*A*x to get Y = alpha*A*x + Y*beta
*/
Cpdscal1(N, beta, Y, IY, JY, descY, incY);
/*
* Collapse complex X down to real X1
*/
Cpzdvabs1(N, X, IX, JX, descX, incX, &X1, &IX1, &JX1, descX1, &incX1);
/*
* Get local information about our matrix
*/
Cinfog2l(IA, JA, descA, nprow, npcol, myrow, mycol, &i, &j, &arow, &acol);
ar = &A[ 2*(i+j*descA[LLD_]) ];
nb = descA[NB_];
lld = descA[LLD_];
LOCp = Cnumroc2(N, IA, nb, myrow, descA[RSRC_], nprow);
LOCq = Cnumroc2(N, JA, nb, mycol, descA[CSRC_], npcol);
/*
* Set up Xr, Yc, and absA
*/
Ir = Jc = 0;
Ic = IA % nb;
Jr = JA % nb;
i = Ic + LOCp;
j = Jr + LOCq;
Mmalloc(Yc, double, i+j+nb*LOCq, kb, ctxt);
Xr = &Yc[i];
absA = &Xr[j];
Mdescset(descXr, 1, N+Jr, nb, nb,
MCindxg2p(IX, descX[MB_], descX[RSRC_], nprow), acol, ctxt, 1);
Mdescset(descYc, N+Ic, 1, nb, nb, arow,
MCindxg2p(JY, descY[NB_], descY[CSRC_], npcol), ctxt, MAX(1,i));
if (mycol == acol) xr = &Xr[Jr];
else xr = Xr;
if (myrow == arow) yc2 = yc = &Yc[Ic];
else yc2 = yc = Yc;
/*
* Copy X and broadcast it to all process rows
*/
Cpdcopy1(N, X1, IX1, JX1, descX1, incX1, Xr, Ir, Jr, descXr, one);
free(X1);
top = ptop("B", "C", "!");
if (myrow == descXr[RSRC_]) Cdgebs2d(ctxt, "c", top, LOCq, 1, xr, LOCq);
else Cdgebr2d(ctxt, "c", top, LOCq, 1, xr, LOCq, descXr[RSRC_], mycol);
kb = nb - Ic;
kb = MIN(kb, N);
currow = arow;
curcol = acol;
do
{
if (myrow == currow)
{
aa = absA;
a = ar;
if (mycol == curcol) /* I have diagonal block */
{
for (j=0; j != kb; j++) /* copy diagonal block */
{
for (i=0; i != j; i++) aa[i] = ABS( a[2*i] ) + ABS( a[2*i+1] );
if (UNIT) aa[i] = 1.0;
else aa[i] = ABS( a[2*i] ) + ABS( a[2*i+1] );
for (i++; i < kb; i++) aa[i] = 0.0;
a += 2*lld;
aa += kb;
}
for (j=LOCq-kb; j; j--)
{
for (i=0; i != kb; i++) aa[i] = ABS( a[2*i] ) + ABS( a[2*i+1] );
a += 2*lld;
aa += kb;
}
dgemv_(trans, &kb, &LOCq, &alpha, absA, &kb, xr, &one, &zero,
yc, &one);
LOCq -= kb;
ar += 2*kb*(lld + 1);
xr += kb;
}
else
{
if (LOCq)
{
for (j=LOCq; j; j--)
{
for (i=0; i != kb; i++) aa[i] = ABS( a[2*i] ) + ABS( a[2*i+1] );
a += 2*lld;
aa += kb;
}
dgemv_(trans, &kb, &LOCq, &alpha, absA, &kb, xr, &one, &zero,
yc, &one);
}
else for (i=0; i != kb; i++) yc[i] = 0.0;
ar += 2*kb;
}
yc += kb;
}
else if (mycol == curcol)
{
LOCq -= kb;
xr += kb;
ar += 2*kb*lld;
}
I += kb;
kb = MIN(nb, N-I);
if (++currow == nprow) currow=0;
if (++curcol == npcol) curcol=0;
}
while (I != N);
/*
* Collect distributed Y
*/
if (LOCp)
{
top = ptop("C", "R", "!");
Cdgsum2d(ctxt, "row", top, LOCp, 1, yc2, LOCp, myrow, descYc[CSRC_]);
}
/*
* Set y = A*x + beta*y (Y has beta*y, and Yc has A*x)
*/
Cpdaxpy1(N, 1.0, Yc, Ic, Jc, descYc, one, Y, IY, JY, descY, incY);
if (Yc) free(Yc);
}
|