File: CpcatrmvUT.c

package info (click to toggle)
scalapack 1.6-13
  • links: PTS
  • area: main
  • in suites: potato
  • size: 30,476 kB
  • ctags: 25,789
  • sloc: fortran: 296,718; ansic: 51,265; makefile: 1,541; sh: 4
file content (176 lines) | stat: -rw-r--r-- 4,840 bytes parent folder | download
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
#include "tools.h"
void CpcatrmvUT(UNIT, N, alpha, A, IA, JA, descA, X, IX, JX, descX, incX, beta, 
                Y, IY, JY, descY, incY)
int UNIT;
int N;
float alpha;
float *A;
int IA;
int JA;
int *descA;
float *X;
int IX;
int JX;
int *descX;
int incX;
float beta;
float *Y;
int IY;
int JY;
int *descY;
int  incY;
/*
 *
 *             ======(Yr)======
 *
 *                    N
 *              ---------------
 *       |     |\_             |          A - N x N
 *       |     |  \_           |          Y - N x 1
 *       |     |    \_  (A)    |          X - 1 x N
 *      (Xc) N |      \_       |
 *       |     |        \_     |          X will be replicated on every
 *       |     |          \_   |            process column
 *       |     |            \  |          Y will have space on every
 *       |     |             \_|            process row
 *              ---------------
 */
{
/*
 * .. External routines ..
 */
   char *ptop();
   void pberror_();
   void Cinfog2l();
   int Cnumroc2();
   void Cblacs_gridinfo();
   void Csgebs2d();
   void Csgebr2d();
   void Csgsum2d();
   F_INTG_FCT sgemv_();
     void Cpcsvabs1();
   void Cpsscal1();
   void Cpscopy1();
   void Cpsaxpy1();

   F_CHAR trans;
   char *top;
   int Ir, Jr, Ic, Jc, i, j, k, kb, nb, lld, LOCp, LOCq, one=1, I=0;
   int ctxt, nprow, npcol, myrow, mycol, arow, acol, currow, curcol;
   int descX1[DLEN_], descXc[DLEN_], descYr[DLEN_], IX1, JX1, incX1;
   float *a, *aa, *ac, *absA, *X1, *Xc, *Yr, *xc, *yr, *yr2, zero=0.0;

   trans = C2F_CHAR("T");
   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
 */
   Cpsscal1(N, beta, Y, IY, JY, descY, incY);
/*
 * Collapse complex X down to real X1
 */
   Cpcsvabs1(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);
   ac = &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 Xc, Yr, and absA
 */
   Ir = Jc = 0;
   Ic = IA % nb;
   Jr = JA % nb;
   i = Ic + LOCp;
   j = Jr + LOCq;
   Mmalloc(Yr, float, i+j+nb*LOCp, kb, ctxt);
   Xc = &Yr[j];
   absA = &Xc[i];
   Mdescset(descXc, N+Ic, 1, nb, nb, arow,
            MCindxg2p(JX, descX[NB_], descX[CSRC_], npcol), ctxt, MAX(1,i));
   Mdescset(descYr, 1, N+Jr, nb, nb,
            MCindxg2p(IY, descY[MB_], descY[RSRC_], nprow), acol, ctxt, 1);
   if (myrow == arow) xc = &Xc[Ic];
   else xc = Xc;
   if (mycol == acol) yr2 = yr = &Yr[Jr];
   else yr2 = yr = Yr;
/*
 * Copy X and broadcast it to all process columns
 */
   Cpscopy1(N, X1, IX1, JX1, descX1, incX1, Xc, Ic, Jc, descXc, one);
   free(X1);
   top = ptop("B", "R", "!");
   if (mycol == descXc[CSRC_]) Csgebs2d(ctxt, "r", top, LOCp, 1, xc, LOCp);
   else Csgebr2d(ctxt, "r", top, LOCp, 1, xc, LOCp, myrow, descXc[CSRC_]);

   kb = nb - Ic;
   kb = MIN(kb, N);
   currow = arow;
   curcol = acol;
   LOCp = 0;
   do
   {
      if (mycol == curcol)
      {
         aa = absA;
         a = ac;
         if (myrow == currow) /* I have diagonal block */
         {
            for (j=0; j != kb; j++)
            {
               k = LOCp + j;
               for (i=0; i != k; 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] );
               k = LOCp + kb;
               for (i++; i < k; i++) aa[i] = 0.0;
               a += 2*lld;
               aa += k;
            }
            LOCp += kb;
            sgemv_(trans, &LOCp, &kb, &alpha, absA, &LOCp, xc, &one, &zero,
                   yr, &one);
         }
         else if (LOCp)
         {
            for (j=kb; j; j--)
            {
               for (i=0; i != LOCp; i++) aa[i] = ABS( a[2*i] ) + ABS( a[2*i+1] );
               aa += LOCp;
               a += 2*lld;
            }
            sgemv_(trans, &LOCp, &kb, &alpha, absA, &LOCp, xc, &one, &zero,
                   yr, &one);
         }
         else for (i=0; i != kb; i++) yr[i] = 0.0;

         ac += 2*kb*lld;
         yr += kb;
      }
      else if (myrow == currow) LOCp += kb;
      I += kb;
      kb = MIN(nb, N-I);
      if (++currow == nprow) currow=0;
      if (++curcol == npcol) curcol=0;
   }
   while (I != N);
/*
 * Collect distributed Y
 */
   if (LOCq)
   {
      top = ptop("C", "C", "!");
      Csgsum2d(ctxt, "col", top, LOCq, 1, yr2, LOCq, descYr[RSRC_], mycol);
   }
/*
 * Set y = A*x + beta*y (Y has beta*y, and Yr has A*x)
 */
   Cpsaxpy1(N, 1.0, Yr, Ir, Jr, descYr, one, Y, IY, JY, descY, incY);
   if (Yr) free(Yr);
}