SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
pbchkvect.c
Go to the documentation of this file.
1/* ---------------------------------------------------------------------
2*
3* -- PBLAS routine (version 1.5) --
4* University of Tennessee, Knoxville, Oak Ridge National Laboratory,
5* and University of California, Berkeley.
6* March 17, 1995
7*
8* ---------------------------------------------------------------------
9*/
10/*
11* Include files
12*/
13#include "tools.h"
14
15void pbchkvect( Int n, Int npos0, Int ix, Int jx, Int desc_X[], Int incx, Int dpos0, Int *iix, Int *jjx, Int *ixrow,
16 Int *ixcol, Int nprow, Int npcol, Int myrow, Int mycol, Int *info )
17{
18/*
19*
20* Purpose
21* =======
22*
23* pbchkvect checks the validity of a descriptor vector DESCX, the
24* related global indexes IX, JX and the global increment INCX. It also
25* computes the starting local indexes (IIX,JJX) corresponding to the
26* submatrix starting globally at the entry pointed by (IX,JX).
27* Moreover, this routine returns the coordinates in the grid of the
28* process owning the global matrix entry of indexes (IX,JX), namely
29* (IXROW,IXCOL). The routine prevents out-of-bound memory access
30* by performing the appropriate MIN operation on iix and JJX. Finally,
31* if an inconsistency is found among its parameters IX, JX, DESCX and
32* INCX, the routine returns an error code in info.
33*
34* Arguments
35* =========
36*
37* N (global input) INTEGER
38* The length of the vector X being operated on.
39*
40* NPOS0 (global input) INTEGER
41* Where in the calling routine's parameter list N appears.
42*
43* IX (global input) INTEGER
44* X's global row index, which points to the beginning of the
45* submatrix which is to be operated on.
46*
47* JX (global input) INTEGER
48* X's global column index, which points to the beginning of
49* the submatrix which is to be operated on.
50*
51* DESCX (global and local input) INTEGER array of dimension DLEN_.
52* The array descriptor for the distributed matrix X.
53*
54* INCX (global input) INTEGER
55* The global increment for the elements of X. Only two values
56* of INCX are supported in this version, namely 1 and M_X.
57* INCX must not be zero.
58*
59* DPOS0 (global input) INTEGER
60* Where in the calling routine's parameter list DESCX
61* appears. Note that we assume IX and JX are respectively 2
62* and 1 entries behind DESCX, and INCX is 1 entry after DESCX.
63*
64* IIX (local output) pointer to INTEGER
65* The local rows starting index of the submatrix.
66*
67* JJX (local output) pointer to INTEGER
68* The local columns starting index of the submatrix.
69*
70* IXROW (global output) pointer to INTEGER
71* The row coordinate of the process that possesses the first
72* row and column of the submatrix.
73*
74* IXCOL (global output) pointer to INTEGER
75* The column coordinate of the process that possesses the
76* first row and column of the submatrix.
77*
78* NPROW (global input) INTEGER
79* The total number of process rows over which the distributed
80* matrix is distributed.
81*
82* NPCOL (global input) INTEGER
83* The total number of process columns over which the
84* distributed matrix is distributed.
85*
86* MYROW (local input) INTEGER
87* The row coordinate of the process calling this routine.
88*
89* MYCOL (local input) INTEGER
90* The column coordinate of the process calling this routine.
91*
92* INFO (local input/local output) INTEGER
93* = 0: successful exit
94* < 0: If the i-th argument is an array and the j-entry had
95* an illegal value, then INFO = -(i*100+j), if the i-th
96* argument is a scalar and had an illegal value, then
97* INFO = -i.
98*
99* =====================================================================
100*
101* .. Parameters ..
102*/
103#define DESCMULT 100
104#define BIGNUM 10000
105/* ..
106* .. Local Scalars ..
107*/
108 Int descpos, ExtraColBlock, ExtraRowBlock, icpos, ixpos,
109 jxpos, MyColBlock, MyColDist, MyRowBlock, MyRowDist,
110 NColBlock, np, npos, nq, NRowBlock;
111/* ..
112* .. External Functions ..
113*/
114 F_INTG_FCT numroc_();
115/*
116* .. Executable Statements ..
117*/
118 if( *info >= 0 )
119 *info = BIGNUM;
120 else if( *info < -DESCMULT )
121 *info = -(*info);
122 else
123 *info = -(*info) * DESCMULT;
124/*
125* Figure where in parameter list each parameter was, factoring in
126* descriptor multiplier
127*/
128 npos = npos0 * DESCMULT;
129 ixpos = ( dpos0 - 2 ) * DESCMULT;
130 jxpos = ( dpos0 - 1 ) * DESCMULT;
131 icpos = ( dpos0 + 1 ) * DESCMULT;
132 descpos = dpos0 * DESCMULT + 1;
133/*
134 * Check that we have a legal descriptor type
135 */
136 if(desc_X[DT_] != BLOCK_CYCLIC_2D) *info = MIN( *info, descpos + DT_ );
137/*
138* Check that matrix values make sense from local viewpoint
139*/
140 if( n < 0 )
141 *info = MIN( *info, npos );
142 else if( ix < 1 )
143 *info = MIN( *info, ixpos );
144 else if( jx < 1 )
145 *info = MIN( *info, jxpos );
146 else if( desc_X[MB_] < 1 )
147 *info = MIN( *info, descpos + MB_ );
148 else if( desc_X[NB_] < 1 )
149 *info = MIN( *info, descpos + NB_ );
150 else if( ( desc_X[RSRC_] < 0 ) || ( desc_X[RSRC_] >= nprow ) )
151 *info = MIN( *info, descpos + RSRC_ );
152 else if( ( desc_X[CSRC_] < 0 ) || ( desc_X[CSRC_] >= npcol ) )
153 *info = MIN( *info, descpos + CSRC_ );
154 else if( incx != 1 && incx != desc_X[M_] )
155 *info = MIN( *info, icpos );
156 else if( desc_X[LLD_] < 1 )
157 *info = MIN( *info, descpos + LLD_ );
158
159 if( n == 0 )
160 {
161/*
162* NULL matrix, relax some checks
163*/
164 if( desc_X[M_] < 0 )
165 *info = MIN( *info, descpos + M_ );
166 if( desc_X[N_] < 0 )
167 *info = MIN( *info, descpos + N_ );
168 }
169 else
170 {
171/*
172* more rigorous checks for non-degenerate matrices
173*/
174 if( desc_X[M_] < 1 )
175 *info = MIN( *info, descpos + M_ );
176 else if( desc_X[N_] < 1 )
177 *info = MIN( *info, descpos + N_ );
178 else if( ( incx == desc_X[M_] ) && ( jx+n-1 > desc_X[N_] ) )
179 *info = MIN( *info, jxpos );
180 else if( ( incx == 1 ) && ( incx != desc_X[M_] ) &&
181 ( ix+n-1 > desc_X[M_] ) )
182 *info = MIN( *info, ixpos );
183 else
184 {
185 if( ix > desc_X[M_] )
186 *info = MIN( *info, ixpos );
187 else if( jx > desc_X[N_] )
188 *info = MIN( *info, jxpos );
189 }
190 }
191/*
192* Retrieve local information for vector X, and prepare output:
193* set info = 0 if no error, and divide by DESCMULT if error is not
194* in a descriptor entry.
195*/
196 if( *info == BIGNUM )
197 {
198 MyRowDist = ( myrow + nprow - desc_X[RSRC_] ) % nprow;
199 MyColDist = ( mycol + npcol - desc_X[CSRC_] ) % npcol;
200 NRowBlock = desc_X[M_] / desc_X[MB_];
201 NColBlock = desc_X[N_] / desc_X[NB_];
202 np = ( NRowBlock / nprow ) * desc_X[MB_];
203 nq = ( NColBlock / npcol ) * desc_X[NB_];
204 ExtraRowBlock = NRowBlock % nprow;
205 ExtraColBlock = NColBlock % npcol;
206
207 ix--;
208 jx--;
209 MyRowBlock = ix / desc_X[MB_];
210 MyColBlock = jx / desc_X[NB_];
211 *ixrow = ( MyRowBlock + desc_X[RSRC_] ) % nprow;
212 *ixcol = ( MyColBlock + desc_X[CSRC_] ) % npcol;
213
214 *iix = ( MyRowBlock / nprow + 1 ) * desc_X[MB_] + 1;
215 *jjx = ( MyColBlock / npcol + 1 ) * desc_X[NB_] + 1;
216
217 if( MyRowDist >= ( MyRowBlock % nprow ) )
218 {
219 if( myrow == *ixrow )
220 *iix += ix % desc_X[MB_];
221 *iix -= desc_X[MB_];
222 }
223 if( MyRowDist < ExtraRowBlock )
224 np += desc_X[MB_];
225 else if( MyRowDist == ExtraRowBlock )
226 np += ( desc_X[M_] % desc_X[MB_] );
227 np = MAX( 1, np );
228
229 if( MyColDist >= ( MyColBlock % npcol ) )
230 {
231 if( mycol == *ixcol )
232 *jjx += jx % desc_X[NB_];
233 *jjx -= desc_X[NB_];
234 }
235 if( MyColDist < ExtraColBlock )
236 nq += desc_X[NB_];
237 else if( MyColDist == ExtraColBlock )
238 nq += ( desc_X[N_] % desc_X[NB_] );
239 nq = MAX( 1, nq );
240
241 *iix = MIN( *iix, np );
242 *jjx = MIN( *jjx, nq );
243
244 if( desc_X[LLD_] < np )
245 {
246 if( numroc_(&desc_X[N_], &desc_X[NB_], &mycol, &desc_X[CSRC_], &npcol) )
247 *info = -( descpos + LLD_ );
248 else *info = 0;
249 }
250 else *info = 0;
251 }
252 else if( *info % DESCMULT == 0 )
253 {
254 *info = -(*info) / DESCMULT;
255 }
256 else
257 {
258 *info = -(*info);
259 }
260}
#define Int
Definition Bconfig.h:22
#define F_INTG_FCT
Definition pblas.h:128
#define MAX(a_, b_)
Definition PBtools.h:77
#define MB_
Definition PBtools.h:43
#define MIN(a_, b_)
Definition PBtools.h:76
#define LLD_
Definition PBtools.h:47
#define RSRC_
Definition PBtools.h:45
#define M_
Definition PBtools.h:39
#define CSRC_
Definition PBtools.h:46
#define BLOCK_CYCLIC_2D
Definition PBtools.h:20
#define NB_
Definition PBtools.h:44
#define N_
Definition PBtools.h:40
#define DT_
Definition pblas.h:130
#define BIGNUM
void pbchkvect(Int n, Int npos0, Int ix, Int jx, Int desc_X[], Int incx, Int dpos0, Int *iix, Int *jjx, Int *ixrow, Int *ixcol, Int nprow, Int npcol, Int myrow, Int mycol, Int *info)
Definition pbchkvect.c:15
#define DESCMULT