ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pdzasum_.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 pdzasum_( int * N, double * ASUM,
21  double * X, int * IX, int * JX, int * DESCX, int * INCX )
22 #else
23 void pdzasum_( N, ASUM, X, IX, JX, DESCX, INCX )
24 /*
25 * .. Scalar Arguments ..
26 */
27  int * INCX, * IX, * JX, * N;
28  double * ASUM;
29 /*
30 * .. Array Arguments ..
31 */
32  int * DESCX;
33  double * X;
34 #endif
35 {
36 /*
37 * Purpose
38 * =======
39 *
40 * PDZASUM returns the sum of absolute values of the entries of a sub-
41 * vector sub( X ),
42 *
43 * where
44 *
45 * sub( X ) denotes X(IX,JX:JX+N-1) if INCX = M_X,
46 * X(IX:IX+N-1,JX) if INCX = 1 and INCX <> M_X.
47 *
48 * Notes
49 * =====
50 *
51 * A description vector is associated with each 2D block-cyclicly dis-
52 * tributed matrix. This vector stores the information required to
53 * establish the mapping between a matrix entry and its corresponding
54 * process and memory location.
55 *
56 * In the following comments, the character _ should be read as
57 * "of the distributed matrix". Let A be a generic term for any 2D
58 * block cyclicly distributed matrix. Its description vector is DESC_A:
59 *
60 * NOTATION STORED IN EXPLANATION
61 * ---------------- --------------- ------------------------------------
62 * DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
63 * CTXT_A (global) DESCA[ CTXT_ ] The BLACS context handle, indicating
64 * the NPROW x NPCOL BLACS process grid
65 * A is distributed over. The context
66 * itself is global, but the handle
67 * (the integer value) may vary.
68 * M_A (global) DESCA[ M_ ] The number of rows in the distribu-
69 * ted matrix A, M_A >= 0.
70 * N_A (global) DESCA[ N_ ] The number of columns in the distri-
71 * buted matrix A, N_A >= 0.
72 * IMB_A (global) DESCA[ IMB_ ] The number of rows of the upper left
73 * block of the matrix A, IMB_A > 0.
74 * INB_A (global) DESCA[ INB_ ] The number of columns of the upper
75 * left block of the matrix A,
76 * INB_A > 0.
77 * MB_A (global) DESCA[ MB_ ] The blocking factor used to distri-
78 * bute the last M_A-IMB_A rows of A,
79 * MB_A > 0.
80 * NB_A (global) DESCA[ NB_ ] The blocking factor used to distri-
81 * bute the last N_A-INB_A columns of
82 * A, NB_A > 0.
83 * RSRC_A (global) DESCA[ RSRC_ ] The process row over which the first
84 * row of the matrix A is distributed,
85 * NPROW > RSRC_A >= 0.
86 * CSRC_A (global) DESCA[ CSRC_ ] The process column over which the
87 * first column of A is distributed.
88 * NPCOL > CSRC_A >= 0.
89 * LLD_A (local) DESCA[ LLD_ ] The leading dimension of the local
90 * array storing the local blocks of
91 * the distributed matrix A,
92 * IF( Lc( 1, N_A ) > 0 )
93 * LLD_A >= MAX( 1, Lr( 1, M_A ) )
94 * ELSE
95 * LLD_A >= 1.
96 *
97 * Let K be the number of rows of a matrix A starting at the global in-
98 * dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
99 * that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
100 * receive if these K rows were distributed over NPROW processes. If K
101 * is the number of columns of a matrix A starting at the global index
102 * JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number of co-
103 * lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would receive if
104 * these K columns were distributed over NPCOL processes.
105 *
106 * The values of Lr() and Lc() may be determined via a call to the func-
107 * tion PB_Cnumroc:
108 * Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
109 * Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
110 *
111 * Arguments
112 * =========
113 *
114 * N (global input) INTEGER
115 * On entry, N specifies the length of the subvector sub( X ).
116 * N must be at least zero.
117 *
118 * ASUM (local output) DOUBLE PRECISION
119 * On exit, ASUM specifies the sum of absolute values of the
120 * subvector sub( X ) only in its scope (See below for further
121 * details).
122 *
123 * X (local input) COMPLEX*16 array
124 * On entry, X is an array of dimension (LLD_X, Kx), where LLD_X
125 * is at least MAX( 1, Lr( 1, IX ) ) when INCX = M_X and
126 * MAX( 1, Lr( 1, IX+N-1 ) ) otherwise, and, Kx is at least
127 * Lc( 1, JX+N-1 ) when INCX = M_X and Lc( 1, JX ) otherwise.
128 * Before entry, this array contains the local entries of the
129 * matrix X.
130 *
131 * IX (global input) INTEGER
132 * On entry, IX specifies X's global row index, which points to
133 * the beginning of the submatrix sub( X ).
134 *
135 * JX (global input) INTEGER
136 * On entry, JX specifies X's global column index, which points
137 * to the beginning of the submatrix sub( X ).
138 *
139 * DESCX (global and local input) INTEGER array
140 * On entry, DESCX is an integer array of dimension DLEN_. This
141 * is the array descriptor for the matrix X.
142 *
143 * INCX (global input) INTEGER
144 * On entry, INCX specifies the global increment for the
145 * elements of X. Only two values of INCX are supported in
146 * this version, namely 1 and M_X. INCX must not be zero.
147 *
148 * Further Details
149 * ===============
150 *
151 * When the result of a vector-oriented PBLAS call is a scalar, this
152 * scalar is set only within the process scope which owns the vector(s)
153 * being operated on. Let sub( X ) be a generic term for the input vec-
154 * tor(s). Then, the processes owning the correct the answer is determi-
155 * ned as follows: if an operation involves more than one vector, the
156 * processes receiving the result will be the union of the following set
157 * of processes for each vector:
158 *
159 * If N = 1, M_X = 1 and INCX = 1, then one cannot determine if a pro-
160 * cess row or process column owns the vector operand, therefore only
161 * the process owning sub( X ) receives the correct result;
162 *
163 * If INCX = M_X, then sub( X ) is a vector distributed over a process
164 * row. Each process in this row receives the result;
165 *
166 * If INCX = 1, then sub( X ) is a vector distributed over a process
167 * column. Each process in this column receives the result;
168 *
169 * -- Written on April 1, 1998 by
170 * Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
171 *
172 * ---------------------------------------------------------------------
173 */
174 /*
175 * .. Local Scalars ..
176 */
177  char * Xptr = NULL, top;
178  int Xcol, Xi, Xii, Xj, Xjj, Xld, Xnp, Xnq, Xrow, ctxt, info,
179  mycol, myrow, npcol, nprow;
180  PBTYP_T * type;
181 /*
182 * .. Local Arrays ..
183 */
184  int Xd[DLEN_];
185 /* ..
186 * .. Executable Statements ..
187 *
188 */
189  PB_CargFtoC( *IX, *JX, DESCX, &Xi, &Xj, Xd );
190 #ifndef NO_ARGCHK
191 /*
192 * Test the input parameters
193 */
194  Cblacs_gridinfo( ( ctxt = Xd[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
195  if( !( info = ( ( nprow == -1 ) ? -( 601 + CTXT_ ) : 0 ) ) )
196  PB_Cchkvec( ctxt, "PDZASUM", "X", *N, 1, Xi, Xj, Xd, *INCX, 6, &info );
197  if( info ) { PB_Cabort( ctxt, "PDZASUM", info ); return; }
198 #endif
199 /*
200 * Initialize ASUM
201 */
202  *ASUM = ZERO;
203 /*
204 * Quick return if possible
205 */
206  if( *N == 0 ) return;
207 /*
208 * Retrieve process grid information
209 */
210 #ifdef NO_ARGCHK
211  Cblacs_gridinfo( ( ctxt = Xd[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
212 #endif
213 /*
214 * Retrieve sub( X )'s local information: Xii, Xjj, Xrow, Xcol
215 */
216  PB_Cinfog2l( Xi, Xj, Xd, nprow, npcol, myrow, mycol, &Xii, &Xjj,
217  &Xrow, &Xcol );
218 /*
219 * Handle degenerate case separately, sub( X )'s scope is just one process
220 */
221  if( ( *N == 1 ) && ( *INCX == 1 ) && ( Xd[M_] == 1 ) )
222  {
223 /*
224 * Make sure I own some data and compute ASUM
225 */
226  if( ( ( myrow == Xrow ) || ( Xrow < 0 ) ) &&
227  ( ( mycol == Xcol ) || ( Xcol < 0 ) ) )
228  {
229  type = PB_Cztypeset();
230  Xptr = Mptr( ((char *) X), Xii, Xjj, Xd[LLD_], type->size );
231  *ASUM = ABS( ((double *) Xptr)[REAL_PART] ) +
232  ABS( ((double *) Xptr)[IMAG_PART] );
233  }
234  return;
235  }
236  else if( *INCX == Xd[M_] )
237  {
238 /*
239 * sub( X ) resides in (a) process row(s)
240 */
241  if( ( myrow == Xrow ) || ( Xrow < 0 ) )
242  {
243 /*
244 * Make sure I own some data and compute the local sum
245 */
246  Xnq = PB_Cnumroc( *N, Xj, Xd[INB_], Xd[NB_], mycol, Xd[CSRC_], npcol );
247  if( Xnq > 0 )
248  {
249  Xld = Xd[LLD_];
250  type = PB_Cztypeset();
251  dzvasum_( &Xnq, ((char *) ASUM), Mptr( ((char *) X), Xii,
252  Xjj, Xld, type->size ), &Xld );
253  }
254 /*
255 * If Xnq <= 0, ASUM is zero (see initialization above)
256 */
257  if( ( npcol > 1 ) && ( Xcol >= 0 ) )
258  {
259 /*
260 * Combine the local results if npcol > 1 and Xcol >= 0, i.e sub( X ) is
261 * distributed.
262 */
263  top = *PB_Ctop( &ctxt, COMBINE, ROW, TOP_GET );
264  Cdgsum2d( ctxt, ROW, &top, 1, 1, ((char *)ASUM), 1, -1,
265  mycol );
266  }
267  }
268  return;
269  }
270  else
271  {
272 /*
273 * sub( X ) resides in (a) process column(s)
274 */
275  if( ( mycol == Xcol ) || ( Xcol < 0 ) )
276  {
277 /*
278 * Make sure I own some data and compute the local sum
279 */
280  Xnp = PB_Cnumroc( *N, Xi, Xd[IMB_], Xd[MB_], myrow, Xd[RSRC_], nprow );
281  if( Xnp > 0 )
282  {
283  type = PB_Cztypeset();
284  dzvasum_( &Xnp, ((char *) ASUM), Mptr( ((char *) X), Xii,
285  Xjj, Xd[LLD_], type->size ), INCX );
286  }
287 /*
288 * If Xnp <= 0, ASUM is zero (see initialization above)
289 */
290  if( ( nprow > 1 ) && ( Xrow >= 0 ) )
291  {
292 /*
293 * Combine the local results if nprow > 1 and Xrow >= 0, i.e sub( X ) is
294 * distributed.
295 */
296  top = *PB_Ctop( &ctxt, COMBINE, COLUMN, TOP_GET );
297  Cdgsum2d( ctxt, COLUMN, &top, 1, 1, ((char *)ASUM), 1, -1,
298  mycol );
299  }
300  }
301  return;
302  }
303 /*
304 * End of PDZASUM
305 */
306 }
M_
#define M_
Definition: PBtools.h:39
ROW
#define ROW
Definition: PBblacs.h:46
MB_
#define MB_
Definition: PBtools.h:43
NB_
#define NB_
Definition: PBtools.h:44
COLUMN
#define COLUMN
Definition: PBblacs.h:45
CSRC_
#define CSRC_
Definition: PBtools.h:46
PBblacs.h
PBtools.h
PBblas.h
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
ZERO
#define ZERO
Definition: PBtools.h:66
PB_Cchkvec
void PB_Cchkvec()
IMB_
#define IMB_
Definition: PBtools.h:41
PB_Cabort
void PB_Cabort()
TOP_GET
#define TOP_GET
Definition: PBblacs.h:50
PB_Ctop
char * PB_Ctop()
RSRC_
#define RSRC_
Definition: PBtools.h:45
PB_CargFtoC
void PB_CargFtoC()
COMBINE
#define COMBINE
Definition: PBblacs.h:49
PBTYP_T::size
int size
Definition: pblas.h:329
PB_Cinfog2l
void PB_Cinfog2l()
PB_Cnumroc
int PB_Cnumroc()
dzvasum_
F_VOID_FCT dzvasum_()
Cdgsum2d
void Cdgsum2d()
ABS
#define ABS(a_)
Definition: PBtools.h:75
INB_
#define INB_
Definition: PBtools.h:42
Cblacs_gridinfo
void Cblacs_gridinfo()
PBTYP_T
Definition: pblas.h:325
pdzasum_
void pdzasum_(int *N, double *ASUM, double *X, int *IX, int *JX, int *DESCX, int *INCX)
Definition: pdzasum_.c:23
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