ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pzgeru_.c
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------
2 *
3 * -- PBLAS routine (version 2.0) --
4 * University of Tennessee, Knoxville, Oak Ridge National Laboratory,
5 * and University of California, Berkeley.
6 * April 1, 1998
7 *
8 * ---------------------------------------------------------------------
9 */
10 /*
11 * Include files
12 */
13 #include "pblas.h"
14 #include "PBpblas.h"
15 #include "PBtools.h"
16 #include "PBblacs.h"
17 #include "PBblas.h"
18 
19 #ifdef __STDC__
20 void pzgeru_( int * M, int * N, double * ALPHA,
21  double * X, int * IX, int * JX, int * DESCX, int * INCX,
22  double * Y, int * IY, int * JY, int * DESCY, int * INCY,
23  double * A, int * IA, int * JA, int * DESCA )
24 #else
25 void pzgeru_( M, N, ALPHA, X, IX, JX, DESCX, INCX, Y, IY, JY, DESCY,
26  INCY, A, IA, JA, DESCA )
27 /*
28 * .. Scalar Arguments ..
29 */
30  int * IA, * INCX, * INCY, * IX, * IY, * JA, * JX, * JY,
31  * M, * N;
32  double * ALPHA;
33 /*
34 * .. Array Arguments ..
35 */
36  int * DESCA, * DESCX, * DESCY;
37  double * A, * X, * Y;
38 #endif
39 {
40 /*
41 * Purpose
42 * =======
43 *
44 * PZGERU performs the rank 1 operation
45 *
46 * sub( A ) := alpha*sub( X )*sub( Y )' + sub( A ),
47 *
48 * where
49 *
50 * sub( A ) denotes A(IA:IA+M-1,JA:JA+N-1),
51 *
52 * sub( X ) denotes X(IX,JX:JX+N-1) if INCX = M_X,
53 * X(IX:IX+N-1,JX) if INCX = 1 and INCX <> M_X, and,
54 *
55 * sub( Y ) denotes Y(IY,JY:JY+N-1) if INCY = M_Y,
56 * Y(IY:IY+N-1,JY) if INCY = 1 and INCY <> M_Y.
57 *
58 * Alpha is a scalar, sub( X ) is an m element subvector, sub( Y ) is
59 * an n element subvector and sub( A ) is an m by n submatrix.
60 *
61 * Notes
62 * =====
63 *
64 * A description vector is associated with each 2D block-cyclicly dis-
65 * tributed matrix. This vector stores the information required to
66 * establish the mapping between a matrix entry and its corresponding
67 * process and memory location.
68 *
69 * In the following comments, the character _ should be read as
70 * "of the distributed matrix". Let A be a generic term for any 2D
71 * block cyclicly distributed matrix. Its description vector is DESC_A:
72 *
73 * NOTATION STORED IN EXPLANATION
74 * ---------------- --------------- ------------------------------------
75 * DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
76 * CTXT_A (global) DESCA[ CTXT_ ] The BLACS context handle, indicating
77 * the NPROW x NPCOL BLACS process grid
78 * A is distributed over. The context
79 * itself is global, but the handle
80 * (the integer value) may vary.
81 * M_A (global) DESCA[ M_ ] The number of rows in the distribu-
82 * ted matrix A, M_A >= 0.
83 * N_A (global) DESCA[ N_ ] The number of columns in the distri-
84 * buted matrix A, N_A >= 0.
85 * IMB_A (global) DESCA[ IMB_ ] The number of rows of the upper left
86 * block of the matrix A, IMB_A > 0.
87 * INB_A (global) DESCA[ INB_ ] The number of columns of the upper
88 * left block of the matrix A,
89 * INB_A > 0.
90 * MB_A (global) DESCA[ MB_ ] The blocking factor used to distri-
91 * bute the last M_A-IMB_A rows of A,
92 * MB_A > 0.
93 * NB_A (global) DESCA[ NB_ ] The blocking factor used to distri-
94 * bute the last N_A-INB_A columns of
95 * A, NB_A > 0.
96 * RSRC_A (global) DESCA[ RSRC_ ] The process row over which the first
97 * row of the matrix A is distributed,
98 * NPROW > RSRC_A >= 0.
99 * CSRC_A (global) DESCA[ CSRC_ ] The process column over which the
100 * first column of A is distributed.
101 * NPCOL > CSRC_A >= 0.
102 * LLD_A (local) DESCA[ LLD_ ] The leading dimension of the local
103 * array storing the local blocks of
104 * the distributed matrix A,
105 * IF( Lc( 1, N_A ) > 0 )
106 * LLD_A >= MAX( 1, Lr( 1, M_A ) )
107 * ELSE
108 * LLD_A >= 1.
109 *
110 * Let K be the number of rows of a matrix A starting at the global in-
111 * dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
112 * that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
113 * receive if these K rows were distributed over NPROW processes. If K
114 * is the number of columns of a matrix A starting at the global index
115 * JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number of co-
116 * lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would receive if
117 * these K columns were distributed over NPCOL processes.
118 *
119 * The values of Lr() and Lc() may be determined via a call to the func-
120 * tion PB_Cnumroc:
121 * Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
122 * Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
123 *
124 * Arguments
125 * =========
126 *
127 * M (global input) INTEGER
128 * On entry, M specifies the number of rows of the submatrix
129 * sub( A ). M must be at least zero.
130 *
131 * N (global input) INTEGER
132 * On entry, N specifies the number of columns of the submatrix
133 * sub( A ). N must be at least zero.
134 *
135 * ALPHA (global input) COMPLEX*16
136 * On entry, ALPHA specifies the scalar alpha. When ALPHA is
137 * supplied as zero then the local entries of the arrays X
138 * and Y corresponding to the entries of the subvectors sub( X )
139 * and sub( Y ) respectively need not be set on input.
140 *
141 * X (local input) COMPLEX*16 array
142 * On entry, X is an array of dimension (LLD_X, Kx), where LLD_X
143 * is at least MAX( 1, Lr( 1, IX ) ) when INCX = M_X and
144 * MAX( 1, Lr( 1, IX+M-1 ) ) otherwise, and, Kx is at least
145 * Lc( 1, JX+M-1 ) when INCX = M_X and Lc( 1, JX ) otherwise.
146 * Before entry, this array contains the local entries of the
147 * matrix X.
148 *
149 * IX (global input) INTEGER
150 * On entry, IX specifies X's global row index, which points to
151 * the beginning of the submatrix sub( X ).
152 *
153 * JX (global input) INTEGER
154 * On entry, JX specifies X's global column index, which points
155 * to the beginning of the submatrix sub( X ).
156 *
157 * DESCX (global and local input) INTEGER array
158 * On entry, DESCX is an integer array of dimension DLEN_. This
159 * is the array descriptor for the matrix X.
160 *
161 * INCX (global input) INTEGER
162 * On entry, INCX specifies the global increment for the
163 * elements of X. Only two values of INCX are supported in
164 * this version, namely 1 and M_X. INCX must not be zero.
165 *
166 * Y (local input) COMPLEX*16 array
167 * On entry, Y is an array of dimension (LLD_Y, Ky), where LLD_Y
168 * is at least MAX( 1, Lr( 1, IY ) ) when INCY = M_Y and
169 * MAX( 1, Lr( 1, IY+N-1 ) ) otherwise, and, Ky is at least
170 * Lc( 1, JY+N-1 ) when INCY = M_Y and Lc( 1, JY ) otherwise.
171 * Before entry, this array contains the local entries of the
172 * matrix Y.
173 *
174 * IY (global input) INTEGER
175 * On entry, IY specifies Y's global row index, which points to
176 * the beginning of the submatrix sub( Y ).
177 *
178 * JY (global input) INTEGER
179 * On entry, JY specifies Y's global column index, which points
180 * to the beginning of the submatrix sub( Y ).
181 *
182 * DESCY (global and local input) INTEGER array
183 * On entry, DESCY is an integer array of dimension DLEN_. This
184 * is the array descriptor for the matrix Y.
185 *
186 * INCY (global input) INTEGER
187 * On entry, INCY specifies the global increment for the
188 * elements of Y. Only two values of INCY are supported in
189 * this version, namely 1 and M_Y. INCY must not be zero.
190 *
191 * A (local input/local output) COMPLEX*16 array
192 * On entry, A is an array of dimension (LLD_A, Ka), where Ka is
193 * at least Lc( 1, JA+N-1 ). Before entry, this array contains
194 * the local entries of the matrix A.
195 * On exit, the entries of this array corresponding to the local
196 * entries of the submatrix sub( A ) are overwritten by the
197 * local entries of the m by n updated submatrix.
198 *
199 * IA (global input) INTEGER
200 * On entry, IA specifies A's global row index, which points to
201 * the beginning of the submatrix sub( A ).
202 *
203 * JA (global input) INTEGER
204 * On entry, JA specifies A's global column index, which points
205 * to the beginning of the submatrix sub( A ).
206 *
207 * DESCA (global and local input) INTEGER array
208 * On entry, DESCA is an integer array of dimension DLEN_. This
209 * is the array descriptor for the matrix A.
210 *
211 * -- Written on April 1, 1998 by
212 * Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
213 *
214 * ---------------------------------------------------------------------
215 */
216 /*
217 * .. Local Scalars ..
218 */
219  int Acol, Ai, Aii, Aimb1, Ainb1, Aj, Ajj, Ald, Amb, Amp, Anb,
220  Anq, Arow, XAfr, Xi, Xj, YAfr, Yi, Yj, ctxt, info, ione=1,
221  mycol, myrow, npcol, nprow;
222  PBTYP_T * type;
223 /*
224 * .. Local Arrays ..
225 */
226  int Ad[DLEN_], Ad0[DLEN_], XAd[DLEN_], Xd[DLEN_], YAd[DLEN_],
227  Yd[DLEN_];
228  char * XA = NULL, * YA = NULL;
229 /* ..
230 * .. Executable Statements ..
231 *
232 */
233  PB_CargFtoC( *IA, *JA, DESCA, &Ai, &Aj, Ad );
234  PB_CargFtoC( *IX, *JX, DESCX, &Xi, &Xj, Xd );
235  PB_CargFtoC( *IY, *JY, DESCY, &Yi, &Yj, Yd );
236 #ifndef NO_ARGCHK
237 /*
238 * Test the input parameters
239 */
240  Cblacs_gridinfo( ( ctxt = Xd[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
241  if( !( info = ( ( nprow == -1 ) ? -( 701 + CTXT_ ) : 0 ) ) )
242  {
243  PB_Cchkvec( ctxt, "PZGERU", "X", *M, 1, Xi, Xj, Xd, *INCX, 7, &info );
244  PB_Cchkvec( ctxt, "PZGERU", "Y", *N, 2, Yi, Yj, Yd, *INCY, 12, &info );
245  PB_Cchkmat( ctxt, "PZGERU", "A", *M, 1, *N, 2, Ai, Aj, Ad, 17, &info );
246  }
247  if( info ) { PB_Cabort( ctxt, "PZGERU", info ); return; }
248 #endif
249 /*
250 * Quick return if possible
251 */
252  if( ( *M == 0 ) || ( *N == 0 ) ||
253  ( ( ALPHA[REAL_PART] == ZERO ) && ( ALPHA[IMAG_PART] == ZERO ) ) )
254  return;
255 /*
256 * Retrieve process grid information
257 */
258 #ifdef NO_ARGCHK
259  Cblacs_gridinfo( ( ctxt = Ad[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
260 #endif
261 /*
262 * Get type structure
263 */
264  type = PB_Cztypeset();
265 /*
266 * Compute descriptor Ad0 for sub( A )
267 */
268  PB_Cdescribe( *M, *N, Ai, Aj, Ad, nprow, npcol, myrow, mycol, &Aii, &Ajj,
269  &Ald, &Aimb1, &Ainb1, &Amb, &Anb, &Arow, &Acol, Ad0 );
270 
271 /*
272 * Replicate sub( X ) in process columns spanned by sub( A ) -> XA
273 */
274  PB_CInV( type, NOCONJG, COLUMN, *M, *N, Ad0, 1, ((char *) X), Xi, Xj, Xd,
275  ( *INCX == Xd[M_] ? ROW : COLUMN ), &XA, XAd, &XAfr );
276 /*
277 * Replicate sub( Y ) in process rows spanned by sub( A ) -> YA
278 */
279  PB_CInV( type, NOCONJG, ROW, *M, *N, Ad0, 1, ((char *) Y), Yi, Yj, Yd,
280  ( *INCY == Yd[M_] ? ROW : COLUMN ), &YA, YAd, &YAfr );
281 /*
282 * Local rank-1 update iff I own some data
283 */
284  Amp = PB_Cnumroc( *M, 0, Aimb1, Amb, myrow, Arow, nprow );
285  Anq = PB_Cnumroc( *N, 0, Ainb1, Anb, mycol, Acol, npcol );
286 
287  if( ( Amp > 0 ) && ( Anq > 0 ) )
288  {
289  zgeru_( &Amp, &Anq, ((char *) ALPHA), XA, &ione, YA, &YAd[LLD_],
290  Mptr( ((char *) A), Aii, Ajj, Ald, type->size ), &Ald );
291  }
292  if( XAfr ) free( XA );
293  if( YAfr ) free( YA );
294 /*
295 * End of PZGERU
296 */
297 }
M_
#define M_
Definition: PBtools.h:39
ROW
#define ROW
Definition: PBblacs.h:46
COLUMN
#define COLUMN
Definition: PBblacs.h:45
PBblacs.h
PBtools.h
PBblas.h
NOCONJG
#define NOCONJG
Definition: PBblas.h:45
REAL_PART
#define REAL_PART
Definition: pblas.h:135
PBpblas.h
PB_Cztypeset
PBTYP_T * PB_Cztypeset()
Definition: PB_Cztypeset.c:19
DLEN_
#define DLEN_
Definition: PBtools.h:48
LLD_
#define LLD_
Definition: PBtools.h:47
PB_Cdescribe
void PB_Cdescribe()
ZERO
#define ZERO
Definition: PBtools.h:66
PB_Cchkvec
void PB_Cchkvec()
zgeru_
F_VOID_FCT zgeru_()
pzgeru_
void pzgeru_(int *M, int *N, double *ALPHA, double *X, int *IX, int *JX, int *DESCX, int *INCX, double *Y, int *IY, int *JY, int *DESCY, int *INCY, double *A, int *IA, int *JA, int *DESCA)
Definition: pzgeru_.c:25
PB_Cabort
void PB_Cabort()
PB_CargFtoC
void PB_CargFtoC()
PBTYP_T::size
int size
Definition: pblas.h:329
PB_Cchkmat
void PB_Cchkmat()
PB_Cnumroc
int PB_Cnumroc()
PB_CInV
void PB_CInV()
Cblacs_gridinfo
void Cblacs_gridinfo()
PBTYP_T
Definition: pblas.h:325
pblas.h
Mptr
#define Mptr(a_, i_, j_, lda_, siz_)
Definition: PBtools.h:132
CTXT_
#define CTXT_
Definition: PBtools.h:38
IMAG_PART
#define IMAG_PART
Definition: pblas.h:136